Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
configuration:telephone-on-serial [2017/10/18 12:08]
gray [The output of a telephone number on the serial interface]
configuration:telephone-on-serial [2017/10/23 16:20]
fachet [SDK-Script]
Line 7: Line 7:
 ===== Router License Generator ===== ===== Router License Generator =====
  
-The voice gateway function must have a license in order to use it. Unter the „SYSTEM“ sub-item „Licensing“ you can see your existing licenses. If you need a license, you can get it via the support of netModule.+The voice gateway function must have a license in order to use it. Unter the „SYSTEM“ sub-item „Licensing“ you can see your existing licenses.
  
 {{:​configuration:​licensing_1.png?​direct&​900|}} {{:​configuration:​licensing_1.png?​direct&​900|}}
Line 44: Line 44:
 {{:​configuration:​sdk_10.png?​direct&​900|}} {{:​configuration:​sdk_10.png?​direct&​900|}}
  
-Next, we need to set the trigger for the script under the „Triggers“ option. Here again a name must be assigned for the function. Under the Type option, „evebt-based“ is selected. The function „system-startuo“ is used as an event.+Next, we need to set the trigger for the script under the „Triggers“ option. Here again a name must be assigned for the function. Under the Type option, „event-based“ is selected. The function „system-startup“ is used as an event.
  
 {{:​configuration:​trigger_11.png?​direct&​900|}} {{:​configuration:​trigger_11.png?​direct&​900|}}
Line 71: Line 71:
 ===== SDK-Script ===== ===== SDK-Script =====
  
-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 script ​serial-write.are“ us extended for output ​of the call number on the serial interface.
  
-With a loop and the SDK command, you get when a voice call comes in.+<code - serial-write.are   >
  
-<code - voice_evenet.ads > 
  
- while(true) +/* DESC: This script can be used to write a message to the serial port. 
- + * Copyright ​(C2017 NetModule AG, Switzerland 
- dump(nb_voice_event(10)); + */
- }+
  
 +DEV = "​SERIAL1";​
 +
 +
 +void usage()
 +{
 +  printf("​usage:​ serial-write.are <​MSG>​\n"​);​
 +  exit(1);
 +}
 +
 +if (argc < 1)
 +    usage(); ​
 +     
 +
 +/* open serial port  */
 +ret = nb_serial_setattr(DEV,​ 115200, 8, 1, 0, 0);
 +if (ret != 0) {
 +  nb_syslog("​Could not set serial attributes on %s return code %i", DEV, ret);
 +  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);​
 +
 +    if (write(fd, msg, len) != len) {
 + nb_syslog("​Error on writing %d bytes to %s", len, DEV);
 + close(fd);
 + exit(4);
 +    }
 +  }
 +}
 +/* not reached */
 </​code>​ </​code>​
  
-This structure ​of output, with the numberstatus and type output.+The SDK command „nb_voice_event“ makes it possible to query the status ​of the voice call. For more information about the SDK-APIsee please to the Weblink http://​wiki.netmodule.com/​documentation/​start under the item Products under one of the router'​s model you have. 
 + 
 +You can use the test window to see when a voice call comes in.
  
 <​code>​ <​code>​
 +dump(nb_voice_event(10));​ // wait 10secs for call
 +</​code>​
  
-void+This structure of output, with the number, status and type output.
  
 +<​code>​
 struct(2): { struct(2): {
   .call = struct(4): {   .call = struct(4): {
Line 106: Line 150:
             .state = string[6]: "​hungup"​             .state = string[6]: "​hungup"​
           }           }
-  .type = string[6]: "​hungup"​ 
 } }
  
Line 112: Line 155:
  
 </​code>​ </​code>​
- 
-The SDK script „serial-write.are“ us extended for output of the call number on the serial interface. 
- 
-<code - phone_number_on_serial_port.ads ​  > 
- 
- 
-/* DESC: This script can be used to write a message to the serial port. 
- * Copyright (C) 2017 NetModule AG, Switzerland 
- */ 
- 
-void usage() 
-{ 
-    printf("​usage:​ phone number on serial port.are <​msg>​\n"​);​ 
-    exit(1); 
-} 
- 
-if (argc < 1) { 
-    usage(); 
-} 
- 
-DEV = "​SERIAL1";​ 
- 
-while(true) 
-{ 
- 
- MSG = nb_voice_event(1).call.calling;​ 
- 
- if ( !is_void(MSG)) 
- { 
- 
- MSG = left(MSG,​strlen(MSG)-5);​ 
- MSG = right(MSG,​strlen(MSG)-6);​ 
- 
- /* check serial port config */ 
- st = nb_config_get("​serial.0.status"​);​ 
- if (st != "​2"​) { 
-    printf("​Serial port is not enabled for us\n"​);​ 
-    exit(1); 
- } 
- 
- ret = nb_serial_setattr(DEV,​ 115200, 8, 1, 0, 0); 
- if (ret != 0) { 
-     ​printf("​Could not set serial attributes: %i \n",​ret);​ 
-     ​exit(1);​ 
- } 
- 
- fd = nb_serial_open(DEV);​ 
- if (fd < 0) { 
-     ​printf("​Unable to open %s\n", DEV); 
-     ​exit(1);​ 
- } 
- 
- ​message = strcat(MSG, "​\r\n"​);​ 
- ret = write(fd, message, strlen(message));​ 
- if (ret> 0) { 
-     ​printf("​Wrote %d bytes to %s\n", ret, DEV); 
- } else { 
-     ​printf("​Unable to write to %s\n", DEV); 
- } 
- ​close(fd);​ 
- 
- } 
-} 
- 
-exit(0); 
- 
-</​code>​ 
-