Stefan Schuermans commited on 2016-12-21 09:47:41
Showing 3 changed files, with 73 additions and 8 deletions.
| ... | ... |
@@ -49,6 +49,7 @@ typedef struct flp_distri_s {
|
| 49 | 49 |
unsigned int distri; /**< number of this distributor */ |
| 50 | 50 |
unsigned int output_cnt; /**< number of outputs of this distributor */ |
| 51 | 51 |
unsigned int pixel_cnt; /**< number of pixels connected to every output */ |
| 52 |
+ struct sockaddr_in addr; /**< network address of distributor */ |
|
| 52 | 53 |
flp_mapping_t mapping[3]; /**< mapping information for red, green |
| 53 | 54 |
* and blue channel */ |
| 54 | 55 |
flp_pixel_t *p_pixels; /**< array with information about pixels |
| ... | ... |
@@ -108,6 +108,11 @@ int flp_config_proc_distri(flp_config_ctx_t *p_ctx, char *p_setting_part2, |
| 108 | 108 |
p_distri->distri = distri; |
| 109 | 109 |
p_distri->output_cnt = out; |
| 110 | 110 |
p_distri->pixel_cnt = pix; |
| 111 |
+ /* initialize address to default */ |
|
| 112 |
+ p_distri->addr.sin_family = AF_INET; |
|
| 113 |
+ p_distri->addr.sin_addr.s_addr = htonl(FLP_DEST_IP_BASE + |
|
| 114 |
+ p_distri->distri * FLP_DEST_IP_STEP); |
|
| 115 |
+ p_distri->addr.sin_port = htons(FLP_DEST_PORT); |
|
| 111 | 116 |
/* initialize mapping information */ |
| 112 | 117 |
for (i = 0; i < 3; i++) {
|
| 113 | 118 |
p_distri->mapping[i].base = 0.0; |
| ... | ... |
@@ -151,6 +156,68 @@ int flp_config_proc_distri(flp_config_ctx_t *p_ctx, char *p_setting_part2, |
| 151 | 156 |
return 0; |
| 152 | 157 |
} |
| 153 | 158 |
|
| 159 |
+/** |
|
| 160 |
+ * \brief process distributor address from config file |
|
| 161 |
+ * |
|
| 162 |
+ * \param[in,out] p_ctx context information |
|
| 163 |
+ * \param[in] p_setting_part2 second half of setting to process |
|
| 164 |
+ * \param[in] p_value value of setting |
|
| 165 |
+ * \return 0 in case of success, -1 in case of error |
|
| 166 |
+ */ |
|
| 167 |
+int flp_config_proc_distri_addr(flp_config_ctx_t *p_ctx, char *p_setting_part2, |
|
| 168 |
+ char *p_value) |
|
| 169 |
+{
|
|
| 170 |
+ char *ptr; |
|
| 171 |
+ unsigned long val; |
|
| 172 |
+ unsigned int distri; |
|
| 173 |
+ flp_distri_t *p_distri; |
|
| 174 |
+ |
|
| 175 |
+ /* get distributor number */ |
|
| 176 |
+ val = strtoul(p_setting_part2, &ptr, 0); |
|
| 177 |
+ if (ptr == p_setting_part2 |
|
| 178 |
+ || (*ptr != 0 && *ptr != ' ' && *ptr != '\t' |
|
| 179 |
+ && *ptr != '\r' && *ptr != '\n')) {
|
|
| 180 |
+ if (p_ctx->p_msg_func) |
|
| 181 |
+ p_ctx->p_msg_func(p_ctx->p_msg_ctx, flp_msg_type_err, |
|
| 182 |
+ "invalid mapping specifier \"%s\"" |
|
| 183 |
+ " in line %u of config file\n", |
|
| 184 |
+ p_setting_part2, p_ctx->line_no); |
|
| 185 |
+ return -1; |
|
| 186 |
+ } |
|
| 187 |
+ distri = (unsigned int)val; |
|
| 188 |
+ if (distri >= FLP_DISTRI_MAX_CNT) {
|
|
| 189 |
+ if (p_ctx->p_msg_func) |
|
| 190 |
+ p_ctx->p_msg_func(p_ctx->p_msg_ctx, flp_msg_type_err, |
|
| 191 |
+ "invalid distributor number \"%u\"" |
|
| 192 |
+ " in line %u of config file\n", |
|
| 193 |
+ distri, p_ctx->line_no); |
|
| 194 |
+ return -1; |
|
| 195 |
+ } |
|
| 196 |
+ |
|
| 197 |
+ /* get distributor */ |
|
| 198 |
+ p_distri = p_ctx->p_display->distri_ptrs[distri]; |
|
| 199 |
+ if (!p_distri) {
|
|
| 200 |
+ if (p_ctx->p_msg_func) |
|
| 201 |
+ p_ctx->p_msg_func(p_ctx->p_msg_ctx, flp_msg_type_err, |
|
| 202 |
+ "no distributor with number \"%u\"" |
|
| 203 |
+ " in line %u of config file\n", |
|
| 204 |
+ distri, p_ctx->line_no); |
|
| 205 |
+ return -1; |
|
| 206 |
+ } |
|
| 207 |
+ |
|
| 208 |
+ /* get address */ |
|
| 209 |
+ if (flp_parse_addr(p_value, &p_distri->addr)) {
|
|
| 210 |
+ if (p_ctx->p_msg_func) |
|
| 211 |
+ p_ctx->p_msg_func(p_ctx->p_msg_ctx, flp_msg_type_err, |
|
| 212 |
+ "invalid address \"%s\" for distributor with number" |
|
| 213 |
+ " \"%u\" in line %u of config file\n", |
|
| 214 |
+ p_value, distri, p_ctx->line_no); |
|
| 215 |
+ return -1; |
|
| 216 |
+ } |
|
| 217 |
+ |
|
| 218 |
+ return 0; |
|
| 219 |
+} |
|
| 220 |
+ |
|
| 154 | 221 |
/** |
| 155 | 222 |
* \brief process mapping from config file |
| 156 | 223 |
* |
| ... | ... |
@@ -488,6 +555,10 @@ int flp_config_proc_setting(flp_config_ctx_t *p_ctx, char *p_setting, |
| 488 | 555 |
if (!strncmp(p_setting, "distributor ", 12)) |
| 489 | 556 |
return flp_config_proc_distri(p_ctx, p_setting + 12, p_value); |
| 490 | 557 |
|
| 558 |
+ /* distributor address */ |
|
| 559 |
+ if (!strncmp(p_setting, "distributorAddr ", 16)) |
|
| 560 |
+ return flp_config_proc_distri_addr(p_ctx, p_setting + 16, p_value); |
|
| 561 |
+ |
|
| 491 | 562 |
/* mapping */ |
| 492 | 563 |
if (!strncmp(p_setting, "mapping ", 8)) |
| 493 | 564 |
return flp_config_proc_mapping(p_ctx, p_setting + 8, p_value); |
| ... | ... |
@@ -246,22 +246,15 @@ void flp_display_send(flp_display_t *p_display) |
| 246 | 246 |
{
|
| 247 | 247 |
unsigned int distri; |
| 248 | 248 |
flp_distri_t *p_distri; |
| 249 |
- struct sockaddr_in dest_addr; |
|
| 250 | 249 |
|
| 251 | 250 |
/* send data to all distributors */ |
| 252 | 251 |
for (distri = 0; distri < FLP_DISTRI_MAX_CNT; distri++) {
|
| 253 | 252 |
p_distri = p_display->distri_ptrs[distri]; |
| 254 | 253 |
if (p_distri) {
|
| 255 | 254 |
|
| 256 |
- /* assemble destination address of distributor */ |
|
| 257 |
- dest_addr.sin_family = AF_INET; |
|
| 258 |
- dest_addr.sin_port = htons(FLP_DEST_PORT); |
|
| 259 |
- dest_addr.sin_addr.s_addr = |
|
| 260 |
- htonl(FLP_DEST_IP_BASE + p_distri->distri * FLP_DEST_IP_STEP); |
|
| 261 |
- |
|
| 262 | 255 |
/* send message as UDP packet */ |
| 263 | 256 |
sendto(p_display->sock, (char *)p_distri->p_msg_buf, p_distri->msg_len, |
| 264 |
- 0, (struct sockaddr *)&dest_addr, sizeof (dest_addr)); |
|
| 257 |
+ 0, (struct sockaddr *)&p_distri->addr, sizeof (p_distri->addr)); |
|
| 265 | 258 |
|
| 266 | 259 |
} /* if (p_distri) */ |
| 267 | 260 |
} /* for (distri ...) */ |
| 268 | 261 |