kfsw-modules/temperature-sensor-example/src/temperature_sensor_example_commands.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | #include <zephyr/sys/util.h> | ||
| 5 | |||
| 6 | #include <kfsw/modules/temperature_sensor_example.h> | ||
| 7 | #include <kfsw/services/command.h> | ||
| 8 | |||
| 9 | 2 | static int command_temp_clear(const struct kfsw_command_arg *args, size_t count, | |
| 10 | const struct kfsw_command_source *source, | ||
| 11 | struct kfsw_command_result *result) | ||
| 12 | { | ||
| 13 | struct kfsw_temp_example_reading reading; | ||
| 14 | int outcome; | ||
| 15 | |||
| 16 | ARG_UNUSED(args); | ||
| 17 | ARG_UNUSED(count); | ||
| 18 | ARG_UNUSED(source); | ||
| 19 | |||
| 20 | 2 | outcome = kfsw_temp_example_clear(); | |
| 21 | 2 | if (outcome != 0) { | |
| 22 | ✗ | result->status = KFSW_COMMAND_UNAVAILABLE; | |
| 23 | ✗ | (void)snprintf(result->detail, sizeof(result->detail), "not initialized"); | |
| 24 | ✗ | return outcome; | |
| 25 | } | ||
| 26 | 2 | (void)kfsw_temp_example_get(&reading); | |
| 27 | 2 | result->status = KFSW_COMMAND_OK; | |
| 28 | 2 | (void)snprintf(result->detail, sizeof(result->detail), "samples=%u failures=%u alarms=%u", | |
| 29 | reading.samples, reading.failures, reading.alarms); | ||
| 30 | 2 | return 0; | |
| 31 | } | ||
| 32 | |||
| 33 | static const struct kfsw_command_definition temp_example_commands[] = { | ||
| 34 | { | ||
| 35 | .id = KFSW_COMMAND_ID_TEMP_EXAMPLE_CLEAR, | ||
| 36 | .name = "temp_clear", | ||
| 37 | .help = "Zero the temperature read, failure and alarm counters.", | ||
| 38 | .flags = KFSW_COMMAND_FLAG_MUTATING, | ||
| 39 | .handler = command_temp_clear, | ||
| 40 | }, | ||
| 41 | }; | ||
| 42 | |||
| 43 | const struct kfsw_command_definition_set kfsw_temp_example_command_definitions = { | ||
| 44 | .commands = temp_example_commands, | ||
| 45 | .count = ARRAY_SIZE(temp_example_commands), | ||
| 46 | }; | ||
| 47 |