This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
configuration:telephone-on-serial [2017/10/23 13:42] – [SDK-Script] gray | configuration:telephone-on-serial [2017/10/23 16:35] – [SDK-Script] fachet | ||
---|---|---|---|
Line 76: | Line 76: | ||
- | /* DESC: This script can be used to write a message | + | /* DESC: This script can be used to write calling phone numbers |
- | * Copyright (C) 2017 NetModule AG, Switzerland | + | * CR/LF terminated |
- | */ | + | * |
+ | * Copyright (C) 2017 NetModule AG, Switzerland | ||
+ | */ | ||
- | void usage() | + | DEV = "SERIAL1"; |
- | { | + | |
- | printf("usage: serial-write.are < | + | |
- | exit(1); | + | |
- | } | + | |
- | | + | /* open serial port */ |
- | usage(); | + | fd = nb_serial_open(DEV); |
- | | + | if (fd < 0) { |
- | | + | |
- | + | | |
- | DEV = " | + | } |
- | /* check serial port config */ | + | ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); |
- | st = nb_config_get(" | + | if (ret != 0) { |
- | if (st != " | + | nb_syslog(" |
- | | + | exit(3); |
- | | + | } |
- | } | + | |
- | ret = nb_serial_setattr(DEV, | ||
- | if (ret != 0) { | ||
- | | ||
- | | ||
- | } | ||
- | |||
- | while (true) { | ||
- | |||
- | MSG = nb_voice_event(1).call.calling; | ||
- | |||
- | if (!is_void(MSG)) { | ||
- | |||
- | MSG = left(MSG, | ||
- | MSG = right(MSG, | ||
- | |||
- | fd = nb_serial_open(DEV); | ||
- | if (fd < 0) { | ||
- | nb_syslog(" | ||
- | exit(4); | ||
- | } | ||
- | |||
- | | ||
- | ret = write(fd, message, strlen(message)); | ||
- | if (ret> 0) { | ||
- | nb_syslog(" | ||
- | } else { | ||
- | nb_syslog(" | ||
- | } | ||
- | |||
- | | ||
- | |||
- | } | ||
- | |||
- | } | ||
- | |||
- | | ||
+ | while (true) { | ||
+ | msg = nb_voice_event(1).call.calling; | ||
+ | if (!is_void(msg)) { | ||
+ | msg = left(msg, strlen(msg) - 5); // trim phone number | ||
+ | msg = right(msg, strlen(msg) - 6); | ||
+ | msg = strcat(msg, " | ||
+ | len = strlen(msg); | ||
+ | if (write(fd, msg, len) != len) { | ||
+ | nb_syslog(" | ||
+ | close(fd); | ||
+ | exit(4); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | /* not reached */ | ||
</ | </ | ||
- | The SDK command „nb_voice_event“ makes it possible to query the status of the voice call. At the address of the router | + | 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 |
- | 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.are > | + | |
- | + | ||
- | while(true) | + | |
- | { | + | |
- | dump(nb_voice_event(10)); | + | |
- | } | + | |
+ | < | ||
+ | dump(nb_voice_event(10)); | ||
</ | </ | ||
Line 156: | Line 127: | ||
< | < | ||
- | |||
- | void | ||
- | |||
struct(2): { | struct(2): { | ||
.call = struct(4): { | .call = struct(4): { | ||
Line 175: | Line 143: | ||
.state = string[6]: " | .state = string[6]: " | ||
} | } | ||
- | .type = string[6]: " | ||
} | } | ||