This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
configuration:telephone-on-serial [2017/10/23 16:14] fachet |
configuration:telephone-on-serial [2017/10/23 16:35] 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 calling phone numbers |
- | * Copyright (C) 2017 NetModule AG, Switzerland | + | * CR/LF terminated to the serial port. |
+ | * | ||
+ | * Copyright (C) 2017 NetModule AG, Switzerland (arg) | ||
*/ | */ | ||
DEV = "SERIAL1"; | DEV = "SERIAL1"; | ||
- | + | /* open serial port */ | |
- | void usage() | + | fd = nb_serial_open(DEV); |
- | { | + | if (fd < 0) { |
- | printf("usage: serial-write.are <MSG>\n"); | + | nb_syslog("Unable to open %s", DEV); |
- | exit(1); | + | exit(2); |
} | } | ||
- | if (argc < 1) | ||
- | usage(); | ||
- | |||
- | |||
- | /* open serial port */ | ||
ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); | ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); | ||
if (ret != 0) { | if (ret != 0) { | ||
Line 99: | Line 96: | ||
exit(3); | exit(3); | ||
} | } | ||
- | fd = nb_serial_open(DEV); | + | |
- | if (fd < 0) { | + | |
- | nb_syslog("Unable to open %s\n", DEV); | + | |
- | exit(4); | + | |
- | } | + | |
while (true) { | while (true) { | ||
Line 111: | Line 104: | ||
msg = right(msg, strlen(msg) - 6); | msg = right(msg, strlen(msg) - 6); | ||
msg = strcat(msg, "\r\n"); | msg = strcat(msg, "\r\n"); | ||
+ | len = strlen(msg); | ||
- | if (write(fd, msg, strlen(msg) < 0 ); | + | if (write(fd, msg, len) != len) { |
- | nb_syslog("Error on writing to %s\n", DEV); | + | nb_syslog("Error on writing %d bytes to %s", len, DEV); |
close(fd); | close(fd); | ||
- | exit(5); | + | exit(4); |
} | } | ||
+ | } | ||
} | } | ||
/* not reached */ | /* not reached */ |