302 * DEVICE DEL uuid |
302 * DEVICE DEL uuid |
303 * DEVICE LIST |
303 * DEVICE LIST |
304 * DEVICE GET uuid |
304 * DEVICE GET uuid |
305 * DEVICE PUT uuid |
305 * DEVICE PUT uuid |
306 */ |
306 */ |
307 int cmd_device(char *buf) |
307 int cmd_device(int s, char *buf) |
308 { |
308 { |
309 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; |
309 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; |
310 devices_list *device, *tmpd; |
310 devices_list *device, *tmpd; |
311 int i, rc, rlen, ival; |
311 int i, rc, rlen, ival; |
312 uuid_t uu; |
312 uuid_t uu; |
313 |
313 |
314 opt = strtok(buf, " \0"); |
314 opt = strtok(buf, " \0"); |
315 opt = strtok(NULL, " \0"); |
315 opt = strtok(NULL, " \0"); |
316 |
316 |
317 if (opt == NULL) { |
317 if (opt == NULL) { |
318 srv_send((char *)"501 Subcommand missing"); |
318 srv_send(s, (char *)"501 Subcommand missing"); |
319 return 0; |
319 return 0; |
320 } |
320 } |
321 param = strtok(NULL, "\0"); |
321 param = strtok(NULL, "\0"); |
322 |
322 |
323 if (strcmp(opt, (char *)"HELP") == 0) { |
323 if (strcmp(opt, (char *)"HELP") == 0) { |
324 srv_send((char *)"100 Help text follows:"); |
324 srv_send(s, (char *)"100 Help text follows:"); |
325 srv_send((char *)"Recognized commands:"); |
325 srv_send(s, (char *)"Recognized commands:"); |
326 srv_send((char *)"DEVICE ADD type Add device (RC433/DHT/I2C/SPI)"); |
326 srv_send(s, (char *)"DEVICE ADD type Add device (RC433/DHT/I2C/SPI)"); |
327 srv_send((char *)"DEVICE DEL uuid Delete device by uuid"); |
327 srv_send(s, (char *)"DEVICE DEL uuid Delete device by uuid"); |
328 srv_send((char *)"DEVICE LIST List all devices"); |
328 srv_send(s, (char *)"DEVICE LIST List all devices"); |
329 srv_send((char *)"DEVICE GET uuid Read device by uuid parameters"); |
329 srv_send(s, (char *)"DEVICE GET uuid Read device by uuid parameters"); |
330 srv_send((char *)"DEVICE PUT uuid Write device by uuid parameters"); |
330 srv_send(s, (char *)"DEVICE PUT uuid Write device by uuid parameters"); |
331 srv_send((char *)"."); |
331 srv_send(s, (char *)"."); |
332 return 0; |
332 return 0; |
333 } |
333 } |
334 |
334 |
335 if (strcmp(opt, (char *)"LIST") == 0) { |
335 if (strcmp(opt, (char *)"LIST") == 0) { |
336 srv_send((char *)"212 Devices list follows:"); |
336 srv_send(s, (char *)"212 Devices list follows:"); |
337 for (device = Config.devices; device; device = device->next) { |
337 for (device = Config.devices; device; device = device->next) { |
338 srv_send((char *)"%s,%s,%d,%d,%s,%s,%d", device->uuid, device->address, device->subdevice, |
338 srv_send(s, (char *)"%s,%s,%d,%d,%s,%s,%d", device->uuid, device->address, device->subdevice, |
339 device->inuse, device->comment, DEVDIR[device->direction], device->value + device->offset); |
339 device->inuse, device->comment, DEVDIR[device->direction], device->value + device->offset); |
340 } |
340 } |
341 srv_send((char *)"."); |
341 srv_send(s, (char *)"."); |
342 return 0; |
342 return 0; |
343 } |
343 } |
344 |
344 |
345 if (param == NULL) { |
345 if (param == NULL) { |
346 srv_send((char *)"502 Parameter missing"); |
346 srv_send(s, (char *)"502 Parameter missing"); |
347 return 1; |
347 return 1; |
348 } |
348 } |
349 |
349 |
350 if (strcmp(opt, (char *)"ADD") == 0) { |
350 if (strcmp(opt, (char *)"ADD") == 0) { |
351 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) || |
351 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) || |
412 if (strcmp(device->uuid, param) == 0) { |
412 if (strcmp(device->uuid, param) == 0) { |
413 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
413 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
414 int my_value = device->value; |
414 int my_value = device->value; |
415 int my_timestamp = (int)device->timestamp; |
415 int my_timestamp = (int)device->timestamp; |
416 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
416 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
417 srv_send((char *)"213 Device record follows:"); |
417 srv_send(s, (char *)"213 Device record follows:"); |
418 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); |
418 srv_send(s, (char *)"TYPE,%s", DEVTYPE[device->type]); |
419 srv_send((char *)"ADDRESS,%s", device->address); |
419 srv_send(s, (char *)"ADDRESS,%s", device->address); |
420 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]); |
420 srv_send(s, (char *)"DIRECTION,%s", DEVDIR[device->direction]); |
421 srv_send((char *)"VALUE,%d", my_value); |
421 srv_send(s, (char *)"VALUE,%d", my_value); |
422 srv_send((char *)"OFFSET,%d", device->offset); |
422 srv_send(s, (char *)"OFFSET,%d", device->offset); |
423 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]); |
423 srv_send(s, (char *)"PRESENT,%s", DEVPRESENT[device->present]); |
424 srv_send((char *)"SUBDEVICE,%d", device->subdevice); |
424 srv_send(s, (char *)"SUBDEVICE,%d", device->subdevice); |
425 srv_send((char *)"GPIOPIN,%d", device->gpiopin); |
425 srv_send(s, (char *)"GPIOPIN,%d", device->gpiopin); |
426 srv_send((char *)"DESCRIPTION,%s", device->description); |
426 srv_send(s, (char *)"DESCRIPTION,%s", device->description); |
427 srv_send((char *)"INUSE,%d", device->inuse); |
427 srv_send(s, (char *)"INUSE,%d", device->inuse); |
428 srv_send((char *)"COMMENT,%s", device->comment); |
428 srv_send(s, (char *)"COMMENT,%s", device->comment); |
429 srv_send((char *)"TIMESTAMP,%d", my_timestamp); |
429 srv_send(s, (char *)"TIMESTAMP,%d", my_timestamp); |
430 srv_send((char *)"."); |
430 srv_send(s, (char *)"."); |
431 return 0; |
431 return 0; |
432 } |
432 } |
433 } |
433 } |
434 srv_send((char *)"440 No such device"); |
434 srv_send(s, (char *)"440 No such device"); |
435 return 0; |
435 return 0; |
436 } |
436 } |
437 |
437 |
438 if (strcmp(opt, (char *)"PUT") == 0) { |
438 if (strcmp(opt, (char *)"PUT") == 0) { |
439 for (device = Config.devices; device; device = device->next) { |
439 for (device = Config.devices; device; device = device->next) { |
440 if (strcmp(device->uuid, param) == 0) { |
440 if (strcmp(device->uuid, param) == 0) { |
441 while (1) { |
441 while (1) { |
442 rlen = srv_recv(ibuf); |
442 rlen = srv_recv(s, ibuf); |
443 if (rlen == -1) { |
443 if (rlen == -1) { |
444 return 0; |
444 return 0; |
445 } |
445 } |
446 if (strlen(ibuf)) { |
446 if (strlen(ibuf)) { |
447 if (strcmp(ibuf, (char *)".") == 0) { |
447 if (strcmp(ibuf, (char *)".") == 0) { |
448 srv_send((char *)"219 Accepted Device record"); |
448 srv_send(s, (char *)"219 Accepted Device record"); |
449 return 1; |
449 return 1; |
450 } |
450 } |
451 kwd = strtok(ibuf, ",\0"); |
451 kwd = strtok(ibuf, ",\0"); |
452 val = strtok(NULL, "\0"); |
452 val = strtok(NULL, "\0"); |
453 if (kwd && val) { |
453 if (kwd && val) { |
557 } |
557 } |
558 } |
558 } |
559 } |
559 } |
560 } |
560 } |
561 } |
561 } |
562 srv_send((char *)"440 No such device"); |
562 srv_send(s, (char *)"440 No such device"); |
563 return 0; |
563 return 0; |
564 } |
564 } |
565 |
565 |
566 srv_send((char *)"504 Subcommand error"); |
566 srv_send(s, (char *)"504 Subcommand error"); |
567 return 0; |
567 return 0; |
568 } |
568 } |
569 |
569 |
570 |
570 |
571 |
571 |
572 /* |
572 /* |
573 * GLOBAL GET |
573 * GLOBAL GET |
574 * GLOBAL PUT |
574 * GLOBAL PUT |
575 */ |
575 */ |
576 int cmd_global(char *buf) |
576 int cmd_global(int s, char *buf) |
577 { |
577 { |
578 char *opt, *kwd, *val, ibuf[SS_BUFSIZE]; |
578 char *opt, *kwd, *val, ibuf[SS_BUFSIZE]; |
579 int ival, rlen; |
579 int ival, rlen; |
580 |
580 |
581 opt = strtok(buf, " \0"); |
581 opt = strtok(buf, " \0"); |
582 opt = strtok(NULL, "\0"); |
582 opt = strtok(NULL, "\0"); |
583 |
583 |
584 if (opt == NULL) { |
584 if (opt == NULL) { |
585 srv_send((char *)"501 Subcommand missing"); |
585 srv_send(s, (char *)"501 Subcommand missing"); |
586 return 0; |
586 return 0; |
587 } |
587 } |
588 |
588 |
589 if (strcmp(opt, (char *)"HELP") == 0) { |
589 if (strcmp(opt, (char *)"HELP") == 0) { |
590 srv_send((char *)"100 Help text follows:"); |
590 srv_send(s, (char *)"100 Help text follows:"); |
591 srv_send((char *)"Recognized commands:"); |
591 srv_send(s, (char *)"Recognized commands:"); |
592 srv_send((char *)"GLOBAL GET Get global settings"); |
592 srv_send(s, (char *)"GLOBAL GET Get global settings"); |
593 srv_send((char *)"GLOBAL PUT Put global settings"); |
593 srv_send(s, (char *)"GLOBAL PUT Put global settings"); |
594 srv_send((char *)"."); |
594 srv_send(s, (char *)"."); |
595 return 0; |
595 return 0; |
596 } |
596 } |
597 |
597 |
598 if (strcmp(opt, (char *)"GET") == 0) { |
598 if (strcmp(opt, (char *)"GET") == 0) { |
599 srv_send((char *)"213 Global Settings record follows:"); |
599 srv_send(s, (char *)"213 Global Settings record follows:"); |
600 srv_send((char *)"RELEASE,%s", VERSION); |
600 srv_send(s, (char *)"RELEASE,%s", VERSION); |
601 srv_send((char *)"NAME,%s", Config.name); |
601 srv_send(s, (char *)"NAME,%s", Config.name); |
602 srv_send((char *)"PORT,%d", Config.my_port); |
602 srv_send(s, (char *)"PORT,%d", Config.my_port); |
603 srv_send((char *)"TEMPFORMAT,%c", Config.tempFormat); |
603 srv_send(s, (char *)"TEMPFORMAT,%c", Config.tempFormat); |
604 srv_send((char *)"TEMP_ADDRESS,%s", Config.temp_address); |
604 srv_send(s, (char *)"TEMP_ADDRESS,%s", Config.temp_address); |
605 srv_send((char *)"TEMP_STATE,%s", TEMPSTATE[Config.temp_state]); |
605 srv_send(s, (char *)"TEMP_STATE,%s", TEMPSTATE[Config.temp_state]); |
606 srv_send((char *)"TEMP_VALUE,%.1f", Config.temp_value / 1000.0); |
606 srv_send(s, (char *)"TEMP_VALUE,%.1f", Config.temp_value / 1000.0); |
607 srv_send((char *)"HUM_ADDRESS,%s", Config.hum_address); |
607 srv_send(s, (char *)"HUM_ADDRESS,%s", Config.hum_address); |
608 srv_send((char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]); |
608 srv_send(s, (char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]); |
609 srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); |
609 srv_send(s, (char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); |
610 srv_send((char *)"TEMP_HUM_IDX,%d", Config.temp_hum_idx); |
610 srv_send(s, (char *)"TEMP_HUM_IDX,%d", Config.temp_hum_idx); |
611 srv_send((char *)"LCD_COLS,%d", Config.lcd_cols); |
611 srv_send(s, (char *)"LCD_COLS,%d", Config.lcd_cols); |
612 srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows); |
612 srv_send(s, (char *)"LCD_ROWS,%d", Config.lcd_rows); |
613 srv_send((char *)"NEXT_UNIT,%d", Config.next_unit); |
613 srv_send(s, (char *)"NEXT_UNIT,%d", Config.next_unit); |
614 srv_send((char *)"MQTT_HOST,%s", Config.mqtt_host); |
614 srv_send(s, (char *)"MQTT_HOST,%s", Config.mqtt_host); |
615 srv_send((char *)"MQTT_PORT,%d", Config.mqtt_port); |
615 srv_send(s, (char *)"MQTT_PORT,%d", Config.mqtt_port); |
616 srv_send((char *)"MQTT_USER,%s", Config.mqtt_username); |
616 srv_send(s, (char *)"MQTT_USER,%s", Config.mqtt_username); |
617 srv_send((char *)"MQTT_PASS,%s", Config.mqtt_password); |
617 srv_send(s, (char *)"MQTT_PASS,%s", Config.mqtt_password); |
618 srv_send((char *)"."); |
618 srv_send(s, (char *)"."); |
619 return 0; |
619 return 0; |
620 } |
620 } |
621 |
621 |
622 if (strcmp(opt, (char *)"PUT") == 0) { |
622 if (strcmp(opt, (char *)"PUT") == 0) { |
623 int mqtt_reconnect = 0; |
623 int mqtt_reconnect = 0; |
624 while (1) { |
624 while (1) { |
625 rlen = srv_recv(ibuf); |
625 rlen = srv_recv(s, ibuf); |
626 if (rlen == -1) { |
626 if (rlen == -1) { |
627 return 0; |
627 return 0; |
628 } |
628 } |
629 if (strlen(ibuf)) { |
629 if (strlen(ibuf)) { |
630 if (strcmp(ibuf, (char *)".") == 0) { |
630 if (strcmp(ibuf, (char *)".") == 0) { |
631 srv_send((char *)"219 Accepted Global record"); |
631 srv_send(s, (char *)"219 Accepted Global record"); |
632 if (mqtt_reconnect) |
632 if (mqtt_reconnect) |
633 mqtt_connect(); |
633 mqtt_connect(); |
634 return 1; |
634 return 1; |
635 } |
635 } |
636 kwd = strtok(ibuf, ",\0"); |
636 kwd = strtok(ibuf, ",\0"); |
929 } |
929 } |
930 } |
930 } |
931 } |
931 } |
932 |
932 |
933 syslog(LOG_NOTICE, "Simulator %s added", simulator->uuid); |
933 syslog(LOG_NOTICE, "Simulator %s added", simulator->uuid); |
934 srv_send((char *)"211 Simulator %s added", simulator->uuid); |
934 srv_send(s, (char *)"211 Simulator %s added", simulator->uuid); |
935 return 1; |
935 return 1; |
936 } |
936 } |
937 |
937 |
938 if (strcmp(opt, (char *)"DEL") == 0) { |
938 if (strcmp(opt, (char *)"DEL") == 0) { |
939 rc = delete_Simulator(param); |
939 rc = delete_Simulator(param); |
940 if (rc) { |
940 if (rc) { |
941 syslog(LOG_NOTICE, "Simulator %s deleted", param); |
941 syslog(LOG_NOTICE, "Simulator %s deleted", param); |
942 srv_send((char *)"211 Simulator %s deleted", param); |
942 srv_send(s, (char *)"211 Simulator %s deleted", param); |
943 return 1; |
943 return 1; |
944 } else { |
944 } else { |
945 srv_send((char *)"440 No such simulator"); |
945 srv_send(s, (char *)"440 No such simulator"); |
946 return 0; |
946 return 0; |
947 } |
947 } |
948 } |
948 } |
949 |
949 |
950 if (strcmp(opt, (char *)"GET") == 0) { |
950 if (strcmp(opt, (char *)"GET") == 0) { |
951 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
951 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
952 if (strcmp(simulator->uuid, param) == 0) { |
952 if (strcmp(simulator->uuid, param) == 0) { |
953 srv_send((char *)"213 Simulator record follows:"); |
953 srv_send(s, (char *)"213 Simulator record follows:"); |
954 srv_send((char *)"NAME,%s", simulator->name); |
954 srv_send(s, (char *)"NAME,%s", simulator->name); |
955 srv_send((char *)"VOLUME_AIR,%d", simulator->volume_air); |
955 srv_send(s, (char *)"VOLUME_AIR,%d", simulator->volume_air); |
956 srv_send((char *)"VOLUME_BEER,%d", simulator->volume_beer); |
956 srv_send(s, (char *)"VOLUME_BEER,%d", simulator->volume_beer); |
957 srv_send((char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature); |
957 srv_send(s, (char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature); |
958 srv_send((char *)"ROOM_HUMIDITY,%.1f", simulator->room_humidity); |
958 srv_send(s, (char *)"ROOM_HUMIDITY,%.1f", simulator->room_humidity); |
959 srv_send((char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature); |
959 srv_send(s, (char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature); |
960 srv_send((char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature); |
960 srv_send(s, (char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature); |
961 srv_send((char *)"CHILLER_TEMPERATURE,%.3f", simulator->chiller_temperature); |
961 srv_send(s, (char *)"CHILLER_TEMPERATURE,%.3f", simulator->chiller_temperature); |
962 srv_send((char *)"COOLER_TEMP,%.1f", simulator->cooler_temp); |
962 srv_send(s, (char *)"COOLER_TEMP,%.1f", simulator->cooler_temp); |
963 srv_send((char *)"COOLER_TIME,%d", simulator->cooler_time); |
963 srv_send(s, (char *)"COOLER_TIME,%d", simulator->cooler_time); |
964 srv_send((char *)"COOLER_SIZE,%.3f", simulator->cooler_size); |
964 srv_send(s, (char *)"COOLER_SIZE,%.3f", simulator->cooler_size); |
965 srv_send((char *)"HEATER_TEMP,%.1f", simulator->heater_temp); |
965 srv_send(s, (char *)"HEATER_TEMP,%.1f", simulator->heater_temp); |
966 srv_send((char *)"HEATER_TIME,%d", simulator->heater_time); |
966 srv_send(s, (char *)"HEATER_TIME,%d", simulator->heater_time); |
967 srv_send((char *)"HEATER_SIZE,%.3f", simulator->heater_size); |
967 srv_send(s, (char *)"HEATER_SIZE,%.3f", simulator->heater_size); |
968 srv_send((char *)"HEATER_STATE,%d", simulator->heater_state); |
968 srv_send(s, (char *)"HEATER_STATE,%d", simulator->heater_state); |
969 srv_send((char *)"COOLER_STATE,%d", simulator->cooler_state); |
969 srv_send(s, (char *)"COOLER_STATE,%d", simulator->cooler_state); |
970 srv_send((char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation); |
970 srv_send(s, (char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation); |
971 srv_send((char *)"."); |
971 srv_send(s, (char *)"."); |
972 return 0; |
972 return 0; |
973 } |
973 } |
974 } |
974 } |
975 srv_send((char *)"440 No such simulator"); |
975 srv_send(s, (char *)"440 No such simulator"); |
976 return 0; |
976 return 0; |
977 } |
977 } |
978 |
978 |
979 if (strcmp(opt, (char *)"PUT") == 0) { |
979 if (strcmp(opt, (char *)"PUT") == 0) { |
980 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
980 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
981 if (strcmp(simulator->uuid, param) == 0) { |
981 if (strcmp(simulator->uuid, param) == 0) { |
982 while (1) { |
982 while (1) { |
983 rlen = srv_recv(ibuf); |
983 rlen = srv_recv(s, ibuf); |
984 if (rlen == -1) { |
984 if (rlen == -1) { |
985 return 0; |
985 return 0; |
986 } |
986 } |
987 if (strlen(ibuf)) { |
987 if (strlen(ibuf)) { |
988 if (strcmp(ibuf, (char *)".") == 0) { |
988 if (strcmp(ibuf, (char *)".") == 0) { |
989 srv_send((char *)"219 Accepted Simulator record"); |
989 srv_send(s, (char *)"219 Accepted Simulator record"); |
990 return 1; |
990 return 1; |
991 } |
991 } |
992 kwd = strtok(ibuf, ",\0"); |
992 kwd = strtok(ibuf, ",\0"); |
993 val = strtok(NULL, "\0"); |
993 val = strtok(NULL, "\0"); |
994 if (kwd && val) { |
994 if (kwd && val) { |
1415 lcd_buf_reset(); |
1415 lcd_buf_reset(); |
1416 run_pause = FALSE; |
1416 run_pause = FALSE; |
1417 |
1417 |
1418 if (rc) { |
1418 if (rc) { |
1419 syslog(LOG_NOTICE, "Unit %s deleted", param); |
1419 syslog(LOG_NOTICE, "Unit %s deleted", param); |
1420 srv_send((char *)"211 Unit %s deleted", param); |
1420 srv_send(s, (char *)"211 Unit %s deleted", param); |
1421 return 1; |
1421 return 1; |
1422 } else { |
1422 } else { |
1423 srv_send((char *)"440 No such unit"); |
1423 srv_send(s, (char *)"440 No such unit"); |
1424 return 0; |
1424 return 0; |
1425 } |
1425 } |
1426 } |
1426 } |
1427 |
1427 |
1428 if (strcmp(opt, (char *)"GET") == 0) { |
1428 if (strcmp(opt, (char *)"GET") == 0) { |
1429 for (unit = Config.units; unit; unit = unit->next) { |
1429 for (unit = Config.units; unit; unit = unit->next) { |
1430 if (strcmp(param, unit->uuid) == 0) { |
1430 if (strcmp(param, unit->uuid) == 0) { |
1431 srv_send((char *)"213 Unit listing follows:"); |
1431 srv_send(s, (char *)"213 Unit listing follows:"); |
1432 srv_send((char *)"UUID,%s", unit->uuid); |
1432 srv_send(s, (char *)"UUID,%s", unit->uuid); |
1433 srv_send((char *)"ALIAS,%s", unit->alias); |
1433 srv_send(s, (char *)"ALIAS,%s", unit->alias); |
1434 srv_send((char *)"PRODUCT_NAME,%s", unit->product_name); |
1434 srv_send(s, (char *)"PRODUCT_NAME,%s", unit->product_name); |
1435 srv_send((char *)"PRODUCT_CODE,%s", unit->product_code); |
1435 srv_send(s, (char *)"PRODUCT_CODE,%s", unit->product_code); |
1436 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
1436 srv_send(s, (char *)"MODE,%s", UNITMODE[unit->mode]); |
1437 srv_send((char *)"STAGE,%s", UNITSTAGE[unit->stage]); |
1437 srv_send(s, (char *)"STAGE,%s", UNITSTAGE[unit->stage]); |
1438 srv_send((char *)"VOLUME,%2f", unit->volume); |
1438 srv_send(s, (char *)"VOLUME,%2f", unit->volume); |
1439 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); |
1439 srv_send(s, (char *)"AIR_ADDRESS,%s", unit->air_address); |
1440 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); |
1440 srv_send(s, (char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); |
1441 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); |
1441 srv_send(s, (char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); |
1442 srv_send((char *)"AIR_IDX,%d", unit->air_idx); |
1442 srv_send(s, (char *)"AIR_IDX,%d", unit->air_idx); |
1443 srv_send((char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address)); |
1443 srv_send(s, (char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address)); |
1444 srv_send((char *)"BEER_ADDRESS2,%s", MBSE_SS(unit->beer_address2)); |
1444 srv_send(s, (char *)"BEER_ADDRESS2,%s", MBSE_SS(unit->beer_address2)); |
1445 srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]); |
1445 srv_send(s, (char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]); |
1446 srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); |
1446 srv_send(s, (char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); |
1447 srv_send((char *)"BEER_IDX,%d", unit->beer_idx); |
1447 srv_send(s, (char *)"BEER_IDX,%d", unit->beer_idx); |
1448 srv_send((char *)"CHILLER_ADDRESS,%s", MBSE_SS(unit->chiller_address)); |
1448 srv_send(s, (char *)"CHILLER_ADDRESS,%s", MBSE_SS(unit->chiller_address)); |
1449 srv_send((char *)"CHILLER_STATE,%s", TEMPSTATE[unit->chiller_state]); |
1449 srv_send(s, (char *)"CHILLER_STATE,%s", TEMPSTATE[unit->chiller_state]); |
1450 srv_send((char *)"CHILLER_TEMPERATURE,%.3f", unit->chiller_temperature / 1000.0); |
1450 srv_send(s, (char *)"CHILLER_TEMPERATURE,%.3f", unit->chiller_temperature / 1000.0); |
1451 srv_send((char *)"CHILLER_IDX,%d", unit->chiller_idx); |
1451 srv_send(s, (char *)"CHILLER_IDX,%d", unit->chiller_idx); |
1452 srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address); |
1452 srv_send(s, (char *)"HEATER_ADDRESS,%s", unit->heater_address); |
1453 srv_send((char *)"HEATER_STATE,%d", unit->heater_state); |
1453 srv_send(s, (char *)"HEATER_STATE,%d", unit->heater_state); |
1454 srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay); |
1454 srv_send(s, (char *)"HEATER_DELAY,%d", unit->heater_delay); |
1455 srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage); |
1455 srv_send(s, (char *)"HEATER_USAGE,%d", unit->heater_usage); |
1456 srv_send((char *)"HEATER_IDX,%d", unit->heater_idx); |
1456 srv_send(s, (char *)"HEATER_IDX,%d", unit->heater_idx); |
1457 if (unit->PID_heat) { |
1457 if (unit->PID_heat) { |
1458 srv_send((char *)"PIDH_IMAX,%.1f", unit->PID_heat->iMax); |
1458 srv_send(s, (char *)"PIDH_IMAX,%.1f", unit->PID_heat->iMax); |
1459 srv_send((char *)"PIDH_IDLERANGE,%.2f", unit->PID_heat->idleRange); |
1459 srv_send(s, (char *)"PIDH_IDLERANGE,%.2f", unit->PID_heat->idleRange); |
1460 srv_send((char *)"PIDH_PGAIN,%.3f", unit->PID_heat->pGain); |
1460 srv_send(s, (char *)"PIDH_PGAIN,%.3f", unit->PID_heat->pGain); |
1461 srv_send((char *)"PIDH_IGAIN,%.3f", unit->PID_heat->iGain); |
1461 srv_send(s, (char *)"PIDH_IGAIN,%.3f", unit->PID_heat->iGain); |
1462 srv_send((char *)"PIDH_DGAIN,%.3f", unit->PID_heat->dGain); |
1462 srv_send(s, (char *)"PIDH_DGAIN,%.3f", unit->PID_heat->dGain); |
1463 srv_send((char *)"PIDH_SV,%.2f", unit->PID_heat->SetP); |
1463 srv_send(s, (char *)"PIDH_SV,%.2f", unit->PID_heat->SetP); |
1464 } |
1464 } |
1465 srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address); |
1465 srv_send(s, (char *)"COOLER_ADDRESS,%s", unit->cooler_address); |
1466 srv_send((char *)"COOLER_STATE,%d", unit->cooler_state); |
1466 srv_send(s, (char *)"COOLER_STATE,%d", unit->cooler_state); |
1467 srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay); |
1467 srv_send(s, (char *)"COOLER_DELAY,%d", unit->cooler_delay); |
1468 srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage); |
1468 srv_send(s, (char *)"COOLER_USAGE,%d", unit->cooler_usage); |
1469 srv_send((char *)"COOLER_IDX,%d", unit->cooler_idx); |
1469 srv_send(s, (char *)"COOLER_IDX,%d", unit->cooler_idx); |
1470 if (unit->PID_cool) { |
1470 if (unit->PID_cool) { |
1471 srv_send((char *)"PIDC_IMAX,%.1f", unit->PID_cool->iMax); |
1471 srv_send(s, (char *)"PIDC_IMAX,%.1f", unit->PID_cool->iMax); |
1472 srv_send((char *)"PIDC_IDLERANGE,%.2f", unit->PID_cool->idleRange); |
1472 srv_send(s, (char *)"PIDC_IDLERANGE,%.2f", unit->PID_cool->idleRange); |
1473 srv_send((char *)"PIDC_PGAIN,%.3f", unit->PID_cool->pGain); |
1473 srv_send(s, (char *)"PIDC_PGAIN,%.3f", unit->PID_cool->pGain); |
1474 srv_send((char *)"PIDC_IGAIN,%.3f", unit->PID_cool->iGain); |
1474 srv_send(s, (char *)"PIDC_IGAIN,%.3f", unit->PID_cool->iGain); |
1475 srv_send((char *)"PIDC_DGAIN,%.3f", unit->PID_cool->dGain); |
1475 srv_send(s, (char *)"PIDC_DGAIN,%.3f", unit->PID_cool->dGain); |
1476 srv_send((char *)"PIDC_SV,%.2f", unit->PID_cool->SetP); |
1476 srv_send(s, (char *)"PIDC_SV,%.2f", unit->PID_cool->SetP); |
1477 } |
1477 } |
1478 srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address); |
1478 srv_send(s, (char *)"FAN_ADDRESS,%s", unit->fan_address); |
1479 srv_send((char *)"FAN_STATE,%d", unit->fan_state); |
1479 srv_send(s, (char *)"FAN_STATE,%d", unit->fan_state); |
1480 srv_send((char *)"FAN_DELAY,%d", unit->fan_delay); |
1480 srv_send(s, (char *)"FAN_DELAY,%d", unit->fan_delay); |
1481 srv_send((char *)"FAN_USAGE,%d", unit->fan_usage); |
1481 srv_send(s, (char *)"FAN_USAGE,%d", unit->fan_usage); |
1482 srv_send((char *)"FAN_IDX,%d", unit->fan_idx); |
1482 srv_send(s, (char *)"FAN_IDX,%d", unit->fan_idx); |
1483 srv_send((char *)"LIGHT_ADDRESS,%s", unit->light_address); |
1483 srv_send(s, (char *)"LIGHT_ADDRESS,%s", unit->light_address); |
1484 srv_send((char *)"LIGHT_STATE,%d", unit->light_state); |
1484 srv_send(s, (char *)"LIGHT_STATE,%d", unit->light_state); |
1485 srv_send((char *)"LIGHT_DELAY,%d", unit->light_delay); |
1485 srv_send(s, (char *)"LIGHT_DELAY,%d", unit->light_delay); |
1486 srv_send((char *)"LIGHT_USAGE,%d", unit->light_usage); |
1486 srv_send(s, (char *)"LIGHT_USAGE,%d", unit->light_usage); |
1487 srv_send((char *)"LIGHT_IDX,%d", unit->light_idx); |
1487 srv_send(s, (char *)"LIGHT_IDX,%d", unit->light_idx); |
1488 srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address); |
1488 srv_send(s, (char *)"DOOR_ADDRESS,%s", unit->door_address); |
1489 srv_send((char *)"DOOR_STATE,%d", unit->door_state); |
1489 srv_send(s, (char *)"DOOR_STATE,%d", unit->door_state); |
1490 srv_send((char *)"DOOR_IDX,%d", unit->door_idx); |
1490 srv_send(s, (char *)"DOOR_IDX,%d", unit->door_idx); |
1491 srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address); |
1491 srv_send(s, (char *)"PSU_ADDRESS,%s", unit->psu_address); |
1492 srv_send((char *)"PSU_STATE,%d", unit->psu_state); |
1492 srv_send(s, (char *)"PSU_STATE,%d", unit->psu_state); |
1493 srv_send((char *)"PSU_IDX,%d", unit->psu_idx); |
1493 srv_send(s, (char *)"PSU_IDX,%d", unit->psu_idx); |
1494 srv_send((char *)"FRIDGE_SET_LO,%.1f", unit->fridge_set_lo); |
1494 srv_send(s, (char *)"FRIDGE_SET_LO,%.1f", unit->fridge_set_lo); |
1495 srv_send((char *)"FRIDGE_SET_HI,%.1f", unit->fridge_set_hi); |
1495 srv_send(s, (char *)"FRIDGE_SET_HI,%.1f", unit->fridge_set_hi); |
1496 srv_send((char *)"BEER_SET_LO,%.1f", unit->beer_set_lo); |
1496 srv_send(s, (char *)"BEER_SET_LO,%.1f", unit->beer_set_lo); |
1497 srv_send((char *)"BEER_SET_HI,%.1f", unit->beer_set_hi); |
1497 srv_send(s, (char *)"BEER_SET_HI,%.1f", unit->beer_set_hi); |
1498 if (unit->profile_uuid) { |
1498 if (unit->profile_uuid) { |
1499 srv_send((char *)"PROFILE_UUID,%s", unit->profile_uuid); |
1499 srv_send(s, (char *)"PROFILE_UUID,%s", unit->profile_uuid); |
1500 srv_send((char *)"PROFILE_NAME,%s", unit->profile_name); |
1500 srv_send(s, (char *)"PROFILE_NAME,%s", unit->profile_name); |
1501 srv_send((char *)"PROFILE_INITTEMP_LO,%.1f", unit->profile_inittemp_lo); |
1501 srv_send(s, (char *)"PROFILE_INITTEMP_LO,%.1f", unit->profile_inittemp_lo); |
1502 srv_send((char *)"PROFILE_INITTEMP_HI,%.1f", unit->profile_inittemp_hi); |
1502 srv_send(s, (char *)"PROFILE_INITTEMP_HI,%.1f", unit->profile_inittemp_hi); |
1503 srv_send((char *)"PROFILE_FRIDGE_MODE,%d", unit->profile_fridge_mode); |
1503 srv_send(s, (char *)"PROFILE_FRIDGE_MODE,%d", unit->profile_fridge_mode); |
1504 srv_send((char *)"PROFILE_DURATION,%d", unit->profile_duration); |
1504 srv_send(s, (char *)"PROFILE_DURATION,%d", unit->profile_duration); |
1505 srv_send((char *)"PROFILE_TOTALSTEPS,%d", unit->profile_totalsteps); |
1505 srv_send(s, (char *)"PROFILE_TOTALSTEPS,%d", unit->profile_totalsteps); |
1506 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); |
1506 srv_send(s, (char *)"PROF_STARTED,%d", (int)unit->prof_started); |
1507 if (unit->prof_state == PROFILE_RUN) { |
1507 if (unit->prof_state == PROFILE_RUN) { |
1508 srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent); |
1508 srv_send(s, (char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent); |
1509 } else { |
1509 } else { |
1510 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); |
1510 srv_send(s, (char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); |
1511 } |
1511 } |
1512 srv_send((char *)"PROF_TARGET_LO,%.3f", unit->prof_target_lo); |
1512 srv_send(s, (char *)"PROF_TARGET_LO,%.3f", unit->prof_target_lo); |
1513 srv_send((char *)"PROF_TARGET_HI,%.3f", unit->prof_target_hi); |
1513 srv_send(s, (char *)"PROF_TARGET_HI,%.3f", unit->prof_target_hi); |
1514 srv_send((char *)"PROF_FRIDGE_MODE,%d", unit->prof_fridge_mode); |
1514 srv_send(s, (char *)"PROF_FRIDGE_MODE,%d", unit->prof_fridge_mode); |
1515 srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); |
1515 srv_send(s, (char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); |
1516 srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); |
1516 srv_send(s, (char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); |
1517 srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); |
1517 srv_send(s, (char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); |
1518 } |
1518 } |
1519 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
1519 srv_send(s, (char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
1520 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |
1520 srv_send(s, (char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |
1521 srv_send((char *)"ALARM,%d", unit->alarm_flag); |
1521 srv_send(s, (char *)"ALARM,%d", unit->alarm_flag); |
1522 srv_send((char *)"."); |
1522 srv_send(s, (char *)"."); |
1523 return 0; |
1523 return 0; |
1524 } |
1524 } |
1525 } |
1525 } |
1526 srv_send((char *)"440 No such unit"); |
1526 srv_send(s, (char *)"440 No such unit"); |
1527 return 0; |
1527 return 0; |
1528 } |
1528 } |
1529 |
1529 |
1530 if (strcmp(opt, (char *)"PUT") == 0) { |
1530 if (strcmp(opt, (char *)"PUT") == 0) { |
1531 /* |
1531 /* |
2066 } |
2066 } |
2067 } |
2067 } |
2068 } |
2068 } |
2069 } |
2069 } |
2070 } |
2070 } |
2071 srv_send((char *)"440 No such unit"); |
2071 srv_send(s, (char *)"440 No such unit"); |
2072 run_pause = FALSE; |
2072 run_pause = FALSE; |
2073 return 0; |
2073 return 0; |
2074 } |
2074 } |
2075 |
2075 |
2076 srv_send((char *)"504 Subcommand error"); |
2076 srv_send(s, (char *)"504 Subcommand error"); |
2077 return 0; |
2077 return 0; |
2078 } |
2078 } |
2079 |
2079 |
2080 |
2080 |
2081 |
2081 |
2082 void cmd_server(void) |
2082 void cmd_server(int s) |
2083 { |
2083 { |
2084 char buf[SS_BUFSIZE]; |
2084 char buf[SS_BUFSIZE]; |
2085 int rlen; |
2085 int rlen; |
2086 |
2086 |
2087 rlen = srv_recv(buf); |
2087 rlen = srv_recv(s, buf); |
2088 if (rlen != -1) { |
2088 if (rlen != -1) { |
2089 if (strlen(buf)) { |
2089 if (strlen(buf)) { |
2090 /* |
2090 /* |
2091 * Process commands from the client |
2091 * Process commands from the client |
2092 */ |
2092 */ |
2093 if (strncmp(buf, "DEVICE", 6) == 0) { |
2093 if (strncmp(buf, "DEVICE", 6) == 0) { |
2094 if (cmd_device(buf)) |
2094 if (cmd_device(s, buf)) |
2095 wrconfig(); |
2095 wrconfig(); |
2096 |
2096 |
2097 } else if (strncmp(buf, "GLOBAL", 6) == 0) { |
2097 } else if (strncmp(buf, "GLOBAL", 6) == 0) { |
2098 if (cmd_global(buf)) |
2098 if (cmd_global(s, buf)) |
2099 wrconfig(); |
2099 wrconfig(); |
2100 |
2100 |
2101 } else if (strncmp(buf, "HELP", 4) == 0) { |
2101 } else if (strncmp(buf, "HELP", 4) == 0) { |
2102 srv_send((char *)"100 Help text follows"); |
2102 srv_send(s, (char *)"100 Help text follows"); |
2103 srv_send((char *)"Recognized commands:"); |
2103 srv_send(s, (char *)"Recognized commands:"); |
2104 srv_send((char *)""); |
2104 srv_send(s, (char *)""); |
2105 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
2105 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
2106 srv_send((char *)"DEVICE <CMD> [parameters] Device commands"); |
2106 srv_send(s, (char *)"DEVICE <CMD> [parameters] Device commands"); |
2107 srv_send((char *)"DEVICE HELP Device help screen"); |
2107 srv_send(s, (char *)"DEVICE HELP Device help screen"); |
2108 srv_send((char *)"GLOBAL <CMD> [parameters] Global commands"); |
2108 srv_send(s, (char *)"GLOBAL <CMD> [parameters] Global commands"); |
2109 srv_send((char *)"GLOBAL HELP Global help screen"); |
2109 srv_send(s, (char *)"GLOBAL HELP Global help screen"); |
2110 srv_send((char *)"LIST <CMD> [parameters] List commands"); |
2110 srv_send(s, (char *)"LIST <CMD> [parameters] List commands"); |
2111 srv_send((char *)"LIST HELP List help screen"); |
2111 srv_send(s, (char *)"LIST HELP List help screen"); |
2112 srv_send((char *)"PING Check if server is alive"); |
2112 srv_send(s, (char *)"PING Check if server is alive"); |
2113 #ifdef USE_SIMULATOR |
2113 #ifdef USE_SIMULATOR |
2114 srv_send((char *)"SIMULATOR <CMD> [parameters] Simulator commands"); |
2114 srv_send(s, (char *)"SIMULATOR <CMD> [parameters] Simulator commands"); |
2115 srv_send((char *)"SIMULATOR HELP Simulator help screen"); |
2115 srv_send(s, (char *)"SIMULATOR HELP Simulator help screen"); |
2116 #endif |
2116 #endif |
2117 srv_send((char *)"UNIT <CMD> [parameters] Unit commands"); |
2117 srv_send(s, (char *)"UNIT <CMD> [parameters] Unit commands"); |
2118 srv_send((char *)"UNIT HELP Unit help screen"); |
2118 srv_send(s, (char *)"UNIT HELP Unit help screen"); |
2119 srv_send((char *)"."); |
2119 srv_send(s, (char *)"."); |
2120 |
2120 |
2121 } else if (strncmp(buf, "LIST", 4) == 0) { |
2121 } else if (strncmp(buf, "LIST", 4) == 0) { |
2122 cmd_list(buf); |
2122 cmd_list(s, buf); |
2123 |
2123 |
2124 } else if (strncmp(buf, "PING", 4) == 0) { |
2124 } else if (strncmp(buf, "PING", 4) == 0) { |
2125 srv_send((char *)"101 PONG"); |
2125 srv_send(s, (char *)"101 PONG"); |
2126 |
2126 |
2127 #ifdef USE_SIMULATOR |
2127 #ifdef USE_SIMULATOR |
2128 } else if (strncmp(buf, "SIMULATOR", 9) == 0) { |
2128 } else if (strncmp(buf, "SIMULATOR", 9) == 0) { |
2129 if (cmd_simulator(buf)) |
2129 if (cmd_simulator(s, buf)) |
2130 wrconfig(); |
2130 wrconfig(); |
2131 |
2131 |
2132 #endif |
2132 #endif |
2133 } else if (strncmp(buf, "UNIT", 4) == 0) { |
2133 } else if (strncmp(buf, "UNIT", 4) == 0) { |
2134 if (cmd_unit(buf)) |
2134 if (cmd_unit(s, buf)) |
2135 wrconfig(); |
2135 wrconfig(); |
2136 |
2136 |
2137 } else { |
2137 } else { |
2138 srv_send((char *)"500 Unknown command"); |
2138 srv_send(s, (char *)"500 Unknown command"); |
2139 } |
2139 } |
2140 } |
2140 } |
2141 } |
2141 } |
2142 |
2142 |
2143 close(s); |
2143 close(s); |
2144 } |
2144 } |
2145 |
2145 |
|
2146 |
|
2147 static void cleanup_handler(void *arg) |
|
2148 { |
|
2149 syslog(LOG_NOTICE, "Thread my_server_loop stopped (cleanup_handler)"); |
|
2150 close(ls); |
|
2151 my_server_state = 0; |
|
2152 } |
2146 |
2153 |
2147 |
2154 |
2148 void *my_server_loop(void *threadid) |
2155 void *my_server_loop(void *threadid) |
2149 { |
2156 { |
2150 socklen_t addrlen; |
2157 socklen_t addrlen; |
2151 int optval = 1; |
2158 int s, optval = 1; |
2152 |
2159 |
2153 my_server_state = 1; |
2160 my_server_state = 1; |
2154 syslog(LOG_NOTICE, "Thread my_server_loop started"); |
2161 syslog(LOG_NOTICE, "Thread my_server_loop started"); |
2155 if (debug) |
2162 if (debug) |
2156 fprintf(stdout, "Thread my_server_loop started\n"); |
2163 fprintf(stdout, "Thread my_server_loop started\n"); |
|
2164 |
|
2165 /* |
|
2166 * Prepare thread to stop in blocking accept() call. |
|
2167 */ |
|
2168 pthread_cleanup_push(cleanup_handler, NULL); |
|
2169 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); |
|
2170 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); |
2157 |
2171 |
2158 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
2172 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
2159 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); |
2173 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); |
2160 myaddr_in.sin_family = AF_INET; |
2174 myaddr_in.sin_family = AF_INET; |
2161 myaddr_in.sin_addr.s_addr = INADDR_ANY; |
2175 myaddr_in.sin_addr.s_addr = INADDR_ANY; |