|
33 | 33 |
|
34 | 34 | #include <esp_rmaker_core.h>
|
35 | 35 | #include <esp_rmaker_user_mapping.h>
|
| 36 | +#include <esp_rmaker_utils.h> |
36 | 37 |
|
37 | 38 | #include <esp_rmaker_console_internal.h>
|
38 | 39 |
|
@@ -352,11 +353,61 @@ static void register_wifi_prov()
|
352 | 353 | esp_console_cmd_register(&cmd);
|
353 | 354 | }
|
354 | 355 |
|
| 356 | +static int local_time_cli_handler(int argc, char *argv[]) |
| 357 | +{ |
| 358 | + char local_time[64]; |
| 359 | + if (esp_rmaker_get_local_time_str(local_time, sizeof(local_time)) == ESP_OK) { |
| 360 | + printf("%s: Current local time: %s\n", TAG, local_time); |
| 361 | + } else { |
| 362 | + printf("%s: Current local time (truncated): %s\n", TAG, local_time); |
| 363 | + } |
| 364 | + return ESP_OK; |
| 365 | +} |
| 366 | + |
| 367 | +static int tz_set_cli_handler(int argc, char *argv[]) |
| 368 | +{ |
| 369 | + if (argc < 2) { |
| 370 | + printf("%s: Invalid Usage.\n", TAG); |
| 371 | + return ESP_ERR_INVALID_ARG; |
| 372 | + } |
| 373 | + if (strcmp(argv[1], "posix") == 0) { |
| 374 | + if (argv[2]) { |
| 375 | + esp_rmaker_time_set_timezone_posix(argv[2]); |
| 376 | + } else { |
| 377 | + printf("%s: Invalid Usage.\n", TAG); |
| 378 | + return ESP_ERR_INVALID_ARG; |
| 379 | + } |
| 380 | + } else { |
| 381 | + esp_rmaker_time_set_timezone(argv[1]); |
| 382 | + } |
| 383 | + return ESP_OK; |
| 384 | +} |
| 385 | + |
| 386 | +static void register_time_commands() |
| 387 | +{ |
| 388 | + const esp_console_cmd_t local_time_cmd = { |
| 389 | + .command = "local-time", |
| 390 | + .help = "Get the local time of device.", |
| 391 | + .func = &local_time_cli_handler, |
| 392 | + }; |
| 393 | + ESP_LOGI(TAG, "Registering command: %s", local_time_cmd.command); |
| 394 | + esp_console_cmd_register(&local_time_cmd); |
| 395 | + |
| 396 | + const esp_console_cmd_t tz_set_cmd = { |
| 397 | + .command = "tz-set", |
| 398 | + .help = "Set Timezone. Usage: tz-set [posix] <tz_string>.", |
| 399 | + .func = &tz_set_cli_handler, |
| 400 | + }; |
| 401 | + ESP_LOGI(TAG, "Registering command: %s", tz_set_cmd.command); |
| 402 | + esp_console_cmd_register(&tz_set_cmd); |
| 403 | +} |
| 404 | + |
355 | 405 | void register_commands()
|
356 | 406 | {
|
357 | 407 | register_generic_debug_commands();
|
358 | 408 | register_reset_to_factory();
|
359 | 409 | register_user_node_mapping();
|
360 | 410 | register_get_node_id();
|
361 | 411 | register_wifi_prov();
|
| 412 | + register_time_commands(); |
362 | 413 | }
|
0 commit comments