Skip to content

Commit

Permalink
Move logging to application and fix port status callback
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed May 29, 2024
1 parent 16f5930 commit 26d99dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
14 changes: 11 additions & 3 deletions samples/read_pd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const uint32_t PDIN_PRINT_TIME_MS = 1000;

void iolm_port_event_cb(uint8_t port, enum iolm_port_evt evt, void *data, void *arg)
{
const uint8_t port_idx = port - 1;
switch (evt) {
case IOLM_PORT_PD:
{
const uint8_t port_idx = port - 1;
const uint32_t current_time = k_uptime_get_32();
if ( current_time - last_print[port_idx] < CONFIG_PDIN_RATE_MS) {
return;
Expand All @@ -61,13 +61,21 @@ void iolm_port_event_cb(uint8_t port, enum iolm_port_evt evt, void *data, void *
for (size_t i = 0; i < pd_data->len; i++) {
sprintf(pdin_data + (i * 2), "%02x", pd_data->data[i]);
}
LOG_INF("Port [%d] PDIn %s", port, pdin_data);
//LOG_INF("Port [%d] PDIn %s", port, pdin_data);
last_print[port_idx] = current_time;
break;
}
case IOLM_PORT_STATUS:
LOG_INF("Port [%d]: Status changed", port);
{
const arg_block_portstatuslist_t * status_list = (arg_block_portstatuslist_t *)data;
if (status_list->port_status_info == IOLINK_PORT_STATUS_INFO_OP) {
LOG_INF("Port [%d] Operate: VID %x DID %x", status_list->vendorid,status_list->deviceid);
}
if (status_list->port_status_info == IOLINK_PORT_STATUS_INFO_NO_DEV) {
LOG_WRN("Port [%d] COM Lost", port);
}
break;
}
case IOLM_PORT_DEV_EVT:
{
struct iolm_dev_evt *dev_evt = (struct iolm_dev_evt *)data;
Expand Down
13 changes: 5 additions & 8 deletions src/iolm.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,11 @@ void iolm_hdl_thread(void * p1, void * p2, void * p3) {
k_timer_start(&tsd_timr[port_idx], K_MSEC(500), K_NO_WAIT);
// Only inform of com lost if the device was not connected
if (port_status[port_idx].port_status_info != IOLINK_PORT_STATUS_INFO_NO_DEV) {
LOG_WRN("Port[%u]: COM Lost", evt.port_no);
port_status[port_idx].port_status_info = IOLINK_PORT_STATUS_INFO_NO_DEV;
if (port_evt_cb != NULL) {
port_evt_cb(evt.port_no, IOLM_PORT_STATUS, &port_status[port_idx], port_evt_arg);
}
}
if (port_evt_cb != NULL) {
port_evt_cb(evt.port_no, IOLM_PORT_STATUS, &port_status[port_idx].port_status_info, port_evt_arg);
}
port_status[port_idx].port_status_info = IOLINK_PORT_STATUS_INFO_NO_DEV;
break;
case RetryCOM:
{
Expand Down Expand Up @@ -695,10 +694,8 @@ void iolm_hdl_thread(void * p1, void * p2, void * p3) {
msg_idx -= IOLINK_PORT_STATUS_INFO_POWER_OFF;
msg_idx += (IOLINK_PORT_STATUS_INFO_DO + 1);
}
LOG_INF("Port [%u] status changed to %s",
evt.port_no, port_status_msg[status]);
if (port_evt_cb != NULL) {
port_evt_cb(evt.port_no, IOLM_PORT_STATUS, &port_status[port_idx].port_status_info, port_evt_arg);
port_evt_cb(evt.port_no, IOLM_PORT_STATUS, &port_status[port_idx], port_evt_arg);
}
break;
}
Expand Down

0 comments on commit 26d99dc

Please sign in to comment.