Cleanup of the 93m1 applications - #29
Conversation
8f45573 to
379f687
Compare
| return; | ||
| } | ||
|
|
||
| (void)snprintf(cmd, sizeof(cmd), |
There was a problem hiding this comment.
Is it guaranteed that it is always okay to void the return value?
snprintk() should be used instead
| } | ||
| *chg_status = val.val1; | ||
|
|
||
| struct sensor_value vbus_val; |
There was a problem hiding this comment.
Can be moved to top of function scope
| (enum sensor_channel)SENSOR_CHAN_NPM13XX_CHARGER_VBUS_STATUS, | ||
| (enum sensor_attribute)SENSOR_ATTR_NPM13XX_CHARGER_VBUS_PRESENT, | ||
| &vbus_val); | ||
| *vbus = (err == 0) && (vbus_val.val1 != 0); |
There was a problem hiding this comment.
Is it fine to return 0 even though this fails?
| } | ||
|
|
||
| return (int)soc; | ||
| LOG_INF("Battery %d%% sent to nRF Cloud", (int)soc); |
There was a problem hiding this comment.
Is it intentional to communicate with cloud from battery module?
Anyway, usually want to avoid INF level in modules. Could be DBG instead
| uint8_t msg_buf[MAX_MSG_SIZE]; | ||
| bool connected = false; | ||
|
|
||
| err = modem_at_urc_subscribe("%NRFCLOUDLOCATION: ", on_location, NULL); |
There was a problem hiding this comment.
Is it safe with multi-thread access to modem APIs?
| struct modem_backend_uart uart_backend; | ||
| struct modem_pipe *uart_pipe; | ||
| struct modem_chat chat; | ||
| uint8_t uart_rx_buf[CONFIG_APP_MODEM_AT_UART_RECEIVE_BUF_SIZE] __aligned(4); |
| } | ||
|
|
||
| if (strlen(req) >= sizeof(request_buf)) { | ||
| if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >= |
There was a problem hiding this comment.
| if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >= | |
| if (snprintk((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >= |
| } | ||
|
|
||
| if (strlen(req) >= sizeof(request_buf)) { | ||
| if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >= |
There was a problem hiding this comment.
I would do this in two steps, first assign to a variable and then check it
| k_sem_give(&cereg_sem); | ||
| struct cereg_msg msg = { .stat = atoi(argv[1]) }; | ||
|
|
||
| (void)zbus_chan_pub(&cereg_chan, &msg, K_NO_WAIT); |
| while (true) { | ||
| bool reg = (atomic_get(&cereg_stat) == 1 || atomic_get(&cereg_stat) == 5); | ||
| k_timeout_t wake = (reg && !connected) ? K_MSEC(500) : wait; | ||
| bool reg = (cereg_stat == 1 || cereg_stat == 5); |
There was a problem hiding this comment.
I would check return value of network_attach() above
simensrostad
left a comment
There was a problem hiding this comment.
To make network handling easier and reduce overall complexity I would use zephyr cellular modem driver and net mgmt for basic connectivity control. The rest can be pure AT. IMO its worth the extra overhead.
The 93m1 driver also exposes ip,apn, psm control that can be re-used.
| (void)snprintf(cmd, sizeof(cmd), | ||
| "AT%%NRFCLOUDMESSAGE={\"appId\":\"BATTERY\",\"data\":\"%d\"}", (int)soc); | ||
|
|
||
| err = modem_at_run(cmd, NULL, 0, CONFIG_APP_BATTERY_AT_TIMEOUT_SECONDS); |
There was a problem hiding this comment.
Make sure that modem_at_run() is thread safe when calling from multiple modules. I think end-goal should be to have one module handle cloud related calls. This would also make it easier for users to attach an aggregator/storage type module. AND you'll worry less about conccurency issues like thread safety.
| (void)snprintf(cmd, sizeof(cmd), | ||
| "AT%%NRFCLOUDMESSAGE={\"appId\":\"BATTERY\",\"data\":\"%d\"}", soc); | ||
| while (true) { | ||
| err = zbus_sub_wait_msg(&battery, &chan, msg_buf, K_FOREVER); |
There was a problem hiding this comment.
Make sure that the latest changes applied to ATT are in here. cc @Trond-F-Christiansen
|
|
||
| CHANNEL_LIST(ADD_OBSERVERS) | ||
|
|
||
| static bool is_coordinate(const char *s); |
There was a problem hiding this comment.
| static bool is_coordinate(const char *s); | |
| /* Forward declarations */ | |
| static bool is_coordinate(const char *s); |
| { | ||
| struct location_msg msg = { .type = LOCATION_FIX_REQUEST, .mode = LOCATION_MODE_ALL }; | ||
|
|
||
| (void)zbus_chan_pub(&location_chan, &msg, PUB_TIMEOUT); |
There was a problem hiding this comment.
Make sure that return values are explicitly handled throughout the code to avoid undefined behavior.
| } | ||
| #endif | ||
|
|
||
| #if defined(CONFIG_APP_BATTERY) |
There was a problem hiding this comment.
Consider making battery and other modules in the app non-optional to avoid ifdeffing if it makes the code harder to read.
| LOG_INF("Serial Modem Host 93m1 starting"); | ||
|
|
||
| #if defined(CONFIG_APP_BATTERY) | ||
| k_work_reschedule(&battery_sample_work, K_NO_WAIT); |
There was a problem hiding this comment.
Easy to miss checking retvals for these. A lot of bad practise in NCS leaving these unchecked.
3d943d4 to
5561f83
Compare
A general cleanup of the 93m1_ppp application. This includes removing unused code, and moving logic to be more uniform. Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no>
5561f83 to
d3a4129
Compare
General cleanup and refactoring of the 93m1_at application. Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no>
d3a4129 to
ab5c6f8
Compare
|



Making the applications more readable and uniform to our other samples.