void serial_setrtc_run(char *line) { uint32_t unixtime = 0; sscanf(line,"%u\r\n",&unixtime); realtime_set_unixtime(unixtime); }
/** * Sets the real time clock (unix time). Part 2 */ void serial_setrtc_run(char *line) { uint32_t unixtime = 0; sscanf(line,"%"PRIu32"\r\n",&unixtime); realtime_set_unixtime(unixtime); command_stack_pop(); }
/** * Called by serial_eventloop, this calls the relevant commands. * * This calls the next command in the stack. By default, the command * is cmd_main_menu. * * New in 12.17 onwards: we accept json-formatted commands as well. Those * commands are parsed & dispatched below. * * Important remark: the CLI does not support multiple commands in one * line. For instance { "get": "guid", "get": "rtc" } will not work. * * JSON commands are as follow: * * Settings not linked to setting keys * "set" { * "rtc": integer (Unix timestamp) * "devicetag": string (device tag) * } * * Get/set settings keys (Work in progress not implemented yet): * "setkey" { "name": string, "value": value } * "getkey": "name" * * Getting values not linked to setting keys * "get": * - "guid" * - "rtc" * - "devicetag" * - "settings" * - "cpm" * */ void serial_process_command(char *line) { JSONNODE *n = json_parse(line); if (n == NULL) { // Old style commands (*command_stack[command_stack_size-1])(line); } else { // Dispatch: int err = true; ///// // get ///// JSONNODE *cmd = json_get_nocase(n,"get"); if (cmd != 0 && json_type(cmd) == JSON_STRING) { json_char *val = json_as_string(cmd); if (strcmp(val, "cpm") == 0) { err = false; cmd_cpm(0); } else if (strcmp(val, "guid") == 0) { err = false; cmd_guid(0); } else if (strcmp(val,"rtc") == 0) { err = false; cmd_getrtc(); } else if (strcmp(val,"devicetag") == 0) { err = false; cmd_getdevicetag(0); } else if (strcmp(val, "settings") == 0) { err = false; cmd_keyvaldump(0); } else if (strcmp(val, "version") == 0) { err = false; cmd_version(0); } else if (strcmp(val,"logstatus") == 0) { err = false; cmd_logstatus(0); } json_free(val); } ///// // set ///// cmd = json_get_nocase(n,"set"); if (cmd !=0 && json_type(cmd) == JSON_NODE) { // Find what set operation we wanted: JSONNODE *op = json_get_nocase(cmd, "devicetag"); if (op != 0 && json_type(op) == JSON_STRING) { err = false; json_char *tag = json_as_string(op); flashstorage_keyval_set("DEVICETAG",tag); json_keyval("ok", "devicetag"); } op = json_get_nocase(cmd, "rtc"); if (op != 0 && json_type(op) == JSON_NUMBER) { err = false; uint32_t time = json_as_int(op); if (time != 0) { realtime_set_unixtime(time); json_keyval("ok", "rtc"); } } } if (err) { json_keyval("error", "unknown command"); } } json_delete(n); }