comparison uptools/atcmd/settime.c @ 387:b61b81d3cece

fcup-settime program written, compiles, produces expected AT+CCLK command
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Mar 2018 00:46:03 +0000
parents
children 19e5a3e2f9c0
comparison
equal deleted inserted replaced
386:bae0fd7285dd 387:b61b81d3cece
1 /*
2 * This utility sends an AT+CCLK command to the GSM device to set its time
3 * to the host's notion of local time.
4 */
5
6 #include <time.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include "../../rvinterf/include/exitcodes.h"
11
12 main(argc, argv)
13 char **argv;
14 {
15 int c;
16 extern int optind;
17 time_t unixtime;
18 struct tm *tm;
19 char command[32];
20
21 while ((c = getopt(argc, argv, "B:np:RX:")) != EOF)
22 if (!atinterf_cmdline_opt(c)) {
23 /* error msg already printed */
24 exit(ERROR_USAGE);
25 }
26 if (argc != optind) {
27 fprintf(stderr, "usage: %s [options]\n", argv[0]);
28 exit(ERROR_USAGE);
29 }
30 time(&unixtime);
31 tm = localtime(&unixtime);
32 sprintf(command, "AT+CCLK=\"%02d/%02d/%02d,%02d:%02d:%02d%+03d\"",
33 tm->tm_year % 100, tm->tm_mon + 1, tm->tm_mday,
34 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_gmtoff / (15*60));
35 atinterf_init();
36 atinterf_exec_cmd_needok(command, 0, 0);
37 exit(0);
38 }