This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
configuration:telephone-on-serial [2017/10/23 13:17] gray [SDK-Script] |
configuration:telephone-on-serial [2017/10/23 16:20] fachet [SDK-Script] |
||
---|---|---|---|
Line 76: | Line 76: | ||
- | /* DESC: This script can be used to write a message to the serial port. | + | /* DESC: This script can be used to write a message to the serial port. |
- | * Copyright (C) 2017 NetModule AG, Switzerland | + | * Copyright (C) 2017 NetModule AG, Switzerland |
- | */ | + | */ |
- | void usage() | + | DEV = "SERIAL1"; |
- | { | + | |
- | printf("usage: serial-write.are <msg>\n"); | + | |
+ | void usage() | ||
+ | { | ||
+ | printf("usage: serial-write.are <MSG>\n"); | ||
exit(1); | exit(1); | ||
- | } | + | } |
- | if (argc < 1) { | + | if (argc < 1) |
- | usage(); | + | usage(); |
- | + | ||
- | } | + | |
- | DEV = "SERIAL1"; | ||
- | /* check serial port config */ | + | /* open serial port */ |
- | st = nb_config_get("serial.0.status"); | + | ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); |
- | if (st != "2") { | + | if (ret != 0) { |
- | nb_syslog("Serial port is not enabled for us\n"); | + | nb_syslog("Could not set serial attributes on %s return code %i", DEV, ret); |
- | exit(2); | + | exit(2); |
- | } | + | } |
+ | fd = nb_serial_open(DEV); | ||
+ | if (fd < 0) { | ||
+ | nb_syslog("Unable to open %s\n", DEV); | ||
+ | exit(3); | ||
+ | } | ||
+ | |||
+ | while (true) { | ||
+ | msg = nb_voice_event(1).call.calling; // check event with 1sec timeout | ||
+ | if (!is_void(msg)) { | ||
+ | msg = left(msg, strlen(msg) - 5); // trim phone number | ||
+ | msg = right(msg, strlen(msg) - 6); | ||
+ | msg = strcat(msg, "\r\n"); | ||
+ | len = strlen(msg); | ||
- | ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); | + | if (write(fd, msg, len) != len) { |
- | if (ret != 0) { | + | nb_syslog("Error on writing %d bytes to %s", len, DEV); |
- | nb_syslog("Could not set serial attributes: %i \n",ret); | + | close(fd); |
- | exit(3); | + | exit(4); |
} | } | ||
- | + | } | |
- | while (true) { | + | } |
- | + | /* not reached */ | |
- | MSG = nb_voice_event(1).call.calling; | + | |
- | + | ||
- | if (!is_void(MSG)) { | + | |
- | + | ||
- | MSG = left(MSG,strlen(MSG)-5); | + | |
- | MSG = right(MSG,strlen(MSG)-6); | + | |
- | + | ||
- | fd = nb_serial_open(DEV); | + | |
- | if (fd < 0) { | + | |
- | nb_syslog("Unable to open %s\n",DEV); | + | |
- | exit(4); | + | |
- | } | + | |
- | + | ||
- | message = strcat(MSG, "\r\n"); | + | |
- | ret = write(fd, message, strlen(message)); | + | |
- | if (ret> 0) { | + | |
- | nb_syslog("Wrote %d bytes to %s\n",ret,DEV); | + | |
- | } else { | + | |
- | nb_syslog("Unable to write to %s\n",DEV); | + | |
- | } | + | |
- | + | ||
- | close(fd); | + | |
- | + | ||
- | } | + | |
- | } | + | |
- | + | ||
- | exit(0); | + | |
- | + | ||
- | + | ||
- | exit(0); | + | |
</code> | </code> | ||
- | The SDK command „nb_voice_event“ makes it possible to query the status of the voice call. At the address of the router http://192.168.1.1/admin/sdk-api-functions.php#sec2.15 can get further information of the command. | + | The SDK command „nb_voice_event“ makes it possible to query the status of the voice call. For more information about the SDK-API, see please to the Weblink http://wiki.netmodule.com/documentation/start under the item Products under one of the router's model you have. |
- | With a loop and the SDK command, you get when a voice call comes in. | + | You can use the test window to see when a voice call comes in. |
- | + | ||
- | <code - voice_evenet.ads > | + | |
- | + | ||
- | while(true) | + | |
- | { | + | |
- | dump(nb_voice_event(10)); | + | |
- | } | + | |
+ | <code> | ||
+ | dump(nb_voice_event(10)); // wait 10secs for call | ||
</code> | </code> | ||
Line 157: | Line 134: | ||
<code> | <code> | ||
- | |||
- | void | ||
- | |||
struct(2): { | struct(2): { | ||
.call = struct(4): { | .call = struct(4): { | ||
Line 176: | Line 150: | ||
.state = string[6]: "hungup" | .state = string[6]: "hungup" | ||
} | } | ||
- | .type = string[6]: "hungup" | ||
} | } | ||