diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-16 10:59:38 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-16 10:59:38 +0100 |
commit | e66516d57caf47eb8b7986c9ce51a2d56c03cf2e (patch) | |
tree | 2c6f81467023133038b2b09f39d71c44934bc6f5 | |
parent | add redundancy freq (diff) | |
download | fodtmf-e66516d57caf47eb8b7986c9ce51a2d56c03cf2e.tar.gz fodtmf-e66516d57caf47eb8b7986c9ce51a2d56c03cf2e.tar.bz2 fodtmf-e66516d57caf47eb8b7986c9ce51a2d56c03cf2e.tar.xz |
send a signal if cancelled, and at end of transmission
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
-rw-r--r-- | src/send.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -29,6 +29,10 @@ #define DURATION 100 /* ms */ /* 100 ms → 10 Bd → 5 B/s */ #define LATENCY 100000 /* µs */ +#define CHAR_ESCAPE 0x10 /* Data link escape */ +#define CHAR_CANCEL 0x18 /* Cancel */ +#define CHAR_END 0x04 /* End of transmission */ + #define N(buf) (sizeof(buf) / sizeof(*buf)) @@ -92,6 +96,7 @@ int main(int argc, char* argv[]) { int r; char buf[1024]; + int c; ssize_t n, i; (void) argc; @@ -124,17 +129,27 @@ int main(int argc, char* argv[]) if (n == 0) break; for (i = 0; i < n; i++) - if (send_byte(buf[i])) - goto snd_fail; + { + c = buf[i]; + if ((c == CHAR_ESCAPE) || (c == CHAR_CANCEL) || (c == CHAR_END)) + if (send_byte(CHAR_ESCAPE)) + goto snd_fail; + if (send_byte(c)) + goto snd_fail; + } } + if (send_byte(CHAR_END)) + goto snd_fail; snd_pcm_close(sound_handle); return 0; fail: perror(argv0); + send_byte(CHAR_CANCEL); return 1; snd_fail: snd_pcm_close(sound_handle); + send_byte(CHAR_CANCEL); return 1; } |