comparison uptools/atcmd/smsend_pduin.c @ 384:3eb92855f7b9

fcup-smsendpdu program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Mar 2018 03:29:40 +0000
parents
children dc2fd8e6f42c
comparison
equal deleted inserted replaced
383:f8c693d16978 384:3eb92855f7b9
1 /*
2 * This is the main module for the fcup-smsendpdu utility.
3 */
4
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <unistd.h>
12 #include "../../rvinterf/include/exitcodes.h"
13
14 int sms_write_mode;
15 char input_line[176*2+2];
16 int lineno;
17 int initdone, cmms_done;
18
19 process_cmdline(argc, argv)
20 char **argv;
21 {
22 int c;
23 extern int optind;
24
25 while ((c = getopt(argc, argv, "B:np:RwWX:")) != EOF) {
26 if (atinterf_cmdline_opt(c))
27 continue;
28 switch (c) {
29 case 'w':
30 sms_write_mode = 1;
31 continue;
32 case 'W':
33 sms_write_mode = 2;
34 continue;
35 default:
36 /* error msg already printed */
37 exit(ERROR_USAGE);
38 }
39 }
40 if (argc != optind) {
41 fprintf(stderr, "usage: %s [options]\n", argv[0]);
42 exit(ERROR_USAGE);
43 }
44 return(0);
45 }
46
47 more_input()
48 {
49 int c;
50
51 c = getc(stdin);
52 if (c == EOF)
53 return(0);
54 ungetc(c, stdin);
55 return(1);
56 }
57
58 init_send_process()
59 {
60 if (initdone)
61 return(0);
62 atinterf_init();
63 /* enable verbose error messages */
64 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
65 /* set PDU mode */
66 prep_for_pdu_mode();
67 if (sms_write_mode == 0 && more_input()) {
68 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0);
69 cmms_done = 1;
70 }
71 initdone = 1;
72 return(1);
73 }
74
75 process_line()
76 {
77 char *cp;
78 u_char pdubin[176];
79 int cc, scalen;
80
81 cp = index(input_line, '\n');
82 if (!cp) {
83 fprintf(stderr, "input line %d: too long or unterminated\n",
84 lineno);
85 exit(ERROR_USAGE);
86 }
87 *cp = '\0';
88 cc = decode_hex_line(input_line, pdubin, sizeof pdubin);
89 if (cc < 1) {
90 inv: fprintf(stderr, "input line %d: not a valid PDU\n", lineno);
91 exit(ERROR_USAGE);
92 }
93 if (pdubin[0] == 1 || pdubin[0] > 11)
94 goto inv;
95 scalen = pdubin[0] + 1;
96 if (cc < scalen + 1)
97 goto inv;
98 /* good to go */
99 init_send_process();
100 send_pdu_out(input_line, cc - scalen);
101 }
102
103 main(argc, argv)
104 char **argv;
105 {
106 process_cmdline(argc, argv);
107 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++)
108 process_line();
109 if (!initdone)
110 exit(0);
111 if (cmms_done)
112 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0);
113 if (sms_write_mode == 1)
114 sendafterwr_process();
115 exit(0);
116 }