GPS Device
Loading...
Searching...
No Matches
IO Command Handlers

Functions

static ERR_te io_cmd_w_handler (uint32_t argc, char **argv)
 CLI handler for the "w" command. Writes a logic level to a named IO pin.
static ERR_te io_cmd_r_handler (uint32_t argc, char **argv)
 CLI handler for the "r" command. Reads and logs the logic level of a named IO pin.
static ERR_te io_cmd_info_handler (uint32_t argc, char **argv)
 CLI handler for the "info" command. Logs the name and GPIO mode of all active IO handles.

Detailed Description

Function Documentation

◆ io_cmd_w_handler()

ERR_te io_cmd_w_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "w" command. Writes a logic level to a named IO pin.

Expected invocation: io w <name> <1|on|0|off>

Searches the registered IO pool for a handle whose name matches argv[2], then calls io_write with HIGH or LOW depending on argv[3].

Parameters
[in]argcArgument count. Must be exactly 4.
[in]argvArgument list: argv[0] = "io", argv[1] = "w", argv[2] = IO name, argv[3] = "1", "on", "0", or "off".
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 4, the name is not found, or the value string is not recognized
  • Propagated error from io_write on failure

Definition at line 392 of file io.c.

392 {
393 ERR_te err;
394
395 if(argc != 4) {
396 LOG_ERROR(
397 internal_state.subsys,
398 internal_state.log_level,
399 "io_cmd_w_handler: invalid arguments"
400 );
402 }
403
404 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
405 if(str_cmp(argv[2], internal_state.ios[i].name) == true) {
406 if(str_cmp(argv[3], "0") == true ||
407 str_cmp(argv[3], "off") == true) {
408 err = io_write(&internal_state.ios[i], LOW);
409 if(err != ERR_OK)
410 return err;
411
412 return ERR_OK;
413 }
414 else if(str_cmp(argv[3], "1") == true ||
415 str_cmp(argv[3], "on") == true) {
416 err = io_write(&internal_state.ios[i], HIGH);
417 if(err != ERR_OK)
418 return err;
419
420 return ERR_OK;
421 }
422 else {
423 LOG_ERROR(
424 internal_state.subsys,
425 internal_state.log_level,
426 "io_cmd_w_handler: invalid arguments"
427 );
429 }
430 }
431
432 if(i == internal_state.io_num - 1) {
433 LOG_ERROR(
434 internal_state.subsys,
435 internal_state.log_level,
436 "io_cmd_w_handler: invalid arguments"
437 );
439 }
440 }
441
442 return ERR_OK;
443}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
bool str_cmp(const char *str1, const char *str2)
Compares two null-terminated strings for equality.
Definition common.c:248
@ HIGH
Definition common.h:89
@ LOW
Definition common.h:86
ERR_te
Standard return type used by all public API functions.
Definition err.h:35
@ ERR_OK
Definition err.h:36
@ ERR_INVALID_ARGUMENT
Definition err.h:38
ERR_te io_write(IO_HANDLE_ts *io_handle, PIN_STATUS_te pin_status)
Writes a logic level to an IO pin.
Definition io.c:323
#define LOG_ERROR(subsys, lvl, fmt,...)
Definition log.h:258
Here is the call graph for this function:

◆ io_cmd_r_handler()

ERR_te io_cmd_r_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "r" command. Reads and logs the logic level of a named IO pin.

Expected invocation: io r <name>

Searches the registered IO pool for a handle whose name matches argv[2], then calls io_read and logs the result.

Parameters
[in]argcArgument count. Must be exactly 3.
[in]argvArgument list: argv[0] = "io", argv[1] = "r", argv[2] = IO name.
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 3 or the name is not found
  • Propagated error from io_read on failure

Definition at line 463 of file io.c.

463 {
464 ERR_te err;
465
466 if(argc != 3) {
467 LOG_ERROR(
468 internal_state.subsys,
469 internal_state.log_level,
470 "io_cmd_r_handler: invalid arguments"
471 );
473 }
474
475 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
476 if(str_cmp(argv[2], internal_state.ios[i].name) == true) {
477 PIN_STATUS_te pin_status = 0;
478
479 err = io_read(&internal_state.ios[i], &pin_status);
480 if(err != ERR_OK) {
481 return err;
482 }
483
484 LOG_INFO(
485 internal_state.subsys,
486 internal_state.log_level,
487 "io_cmd_r_handler: %s pin status: %d",
488 internal_state.ios[i].name,
489 pin_status
490 );
491
492 return ERR_OK;
493 }
494
495 if(i == internal_state.io_num - 1) {
496 LOG_ERROR(
497 internal_state.subsys,
498 internal_state.log_level,
499 "io_cmd_r_handler: invalid arguments"
500 );
502 }
503 }
504
505 return ERR_OK;
506}
PIN_STATUS_te
Represents the logical level of a GPIO pin.
Definition common.h:84
ERR_te io_read(IO_HANDLE_ts const *io_handle, PIN_STATUS_te *pin_status_o)
Reads the current logic level of an IO pin.
Definition io.c:345
#define LOG_INFO(subsys, lvl, fmt,...)
Definition log.h:255
Here is the call graph for this function:

◆ io_cmd_info_handler()

ERR_te io_cmd_info_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "info" command. Logs the name and GPIO mode of all active IO handles.

Expected invocation: io info

Iterates over the internal IO pool and logs the name and GPIO mode of every slot that is currently in use.

Parameters
[in]argcArgument count. Must be exactly 2.
[in]argvArgument list: argv[0] = "io", argv[1] = "info".
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 2

Definition at line 524 of file io.c.

524 {
525 if(argc != 2) {
526 LOG_ERROR(
527 internal_state.subsys,
528 internal_state.log_level,
529 "io_cmd_info_handler: invalid arguments"
530 );
531
533 }
534
535 LOG_INFO(internal_state.subsys, internal_state.log_level, "Printing IO information:");
536
537 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
538 if(internal_state.ios[i].in_use == true) {
539 LOG_INFO(
540 internal_state.subsys,
541 internal_state.log_level,
542 "name: %s, mode: %d",
543 internal_state.ios[i].name,
544 internal_state.ios[i].gpio_cfg.mode
545 );
546 }
547 }
548
549 return ERR_OK;
550}