FreeCalypso > hg > freecalypso-tools
annotate loadtools/buzplaybu.c @ 963:b515a97e5dff
sms-pdu-decode family: fix VP-Relative header spacing
When VP-Relative is small enough to be reckoned in 5 min or 30 min units,
it was printed incorrectly, with a cosmetic defect of one extra space.
Fix this bug.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 28 Aug 2023 03:52:53 +0000 |
parents | 7ade15d4e0cb |
children |
rev | line source |
---|---|
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
2 * fc-buzplay: this module implements the legacy BU mode. |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
12 buzplay_bu_file(filename) |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
13 char *filename; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 FILE *f; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char linebuf[256], *cp, *num1, *num2; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int lineno; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *targv[4]; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 u_long n1, n2, total_ms; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int rc, timeout; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
22 f = fopen(filename, "r"); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (!f) { |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
24 perror(filename); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 printf("Uploading the melody to the target\n"); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 targv[0] = "I"; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 targv[1] = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (tpinterf_send_cmd() < 0) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rc = tpinterf_pass_output(1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (rc) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return(rc); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 targv[0] = "E"; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 targv[3] = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 total_ms = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 cp = index(linebuf, '\n'); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!cp) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(stderr, "%s line %d: missing newline\n", |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
47 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 for (cp = linebuf; isspace(*cp); cp++) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (*cp == '\0' || *cp == '#') |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 continue; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (!isdigit(*cp)) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 inv: fprintf(stderr, "%s line %d: unexpected content\n", |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
57 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 for (num1 = cp; *cp && !isspace(*cp); cp++) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!isdigit(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 goto inv; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (isspace(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 *cp++ = '\0'; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 while (isspace(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 cp++; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (!isdigit(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 goto inv; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 for (num2 = cp; *cp && !isspace(*cp); cp++) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!isdigit(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 goto inv; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (isspace(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *cp++ = '\0'; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 while (isspace(*cp)) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 cp++; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (*cp != '\0' && *cp != '#') |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 goto inv; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 n1 = strtoul(num1, 0, 10); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 n2 = strtoul(num2, 0, 10); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (n1 > 255) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 "%s line %d: the tone number is out of range\n", |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
84 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (n2 < 1 || n2 > 0xFFFF) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 fprintf(stderr, |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 "%s line %d: the duration number is out of range\n", |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
91 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 /* send it to the target */ |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 targv[1] = num1; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 targv[2] = num2; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (tpinterf_send_cmd() < 0) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 rc = tpinterf_pass_output(1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (rc) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 return(rc); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 /* account for the duration */ |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 total_ms += n2 * 5; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (!total_ms) { |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
113 fprintf(stderr, "%s is empty!\n", filename); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 printf("Requesting play of the uploaded melody on the target\n"); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 targv[0] = "P"; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 targv[1] = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if (tpinterf_send_cmd() < 0) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 timeout = total_ms / 1000 + 2; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 return tpinterf_pass_output(timeout); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
894
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
125 |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
126 cmd_play_bu(argc, argv) |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
127 char **argv; |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
128 { |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
129 buzplay_bu_file(argv[1]); |
7ade15d4e0cb
fc-buzplay: BU refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
130 } |