From cb2dcc4ccb4ac09bbce4e4ecbaaafc0a79989799 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Wed, 24 Jan 2018 22:10:29 -0800 Subject: [PATCH] dm: Transition all senders to use dm_send() Transition all calls to hdlc_enqueue on the client out-queue to use dm_send(). This reduces the need for clients to know the workings of the transmition and knowledge of the diag_client struct. Signed-off-by: Bjorn Andersson --- app_cmds.c | 7 ++++--- common_cmds.c | 25 +++++++++++++------------ router.c | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app_cmds.c b/app_cmds.c index ba937b5..4550ac9 100644 --- a/app_cmds.c +++ b/app_cmds.c @@ -35,6 +35,7 @@ #include #include "diag.h" +#include "dm.h" #include "hdlc.h" #include "util.h" @@ -55,7 +56,7 @@ static int handle_diag_version(struct diag_client *client, const void *buf, { uint8_t resp[] = { DIAG_CMD_DIAG_VERSION_ID, DIAG_PROTOCOL_VERSION_NUMBER }; - return hdlc_enqueue(&client->outq, resp, sizeof(resp)); + return dm_send(client, resp, sizeof(resp)); } static int handle_extended_build_id(struct diag_client *client, @@ -89,13 +90,13 @@ static int handle_extended_build_id(struct diag_client *client, strcpy(resp->strings, MOBILE_SOFTWARE_REVISION); strcpy(resp->strings + string1_size, MOBILE_MODEL_STRING); - return hdlc_enqueue(&client->outq, resp, resp_size); + return dm_send(client, resp, resp_size); } static int handle_keep_alive(struct diag_client *client, const void *buf, size_t len) { - return hdlc_enqueue(&client->outq, buf, len); + return dm_send(client, buf, len); } void register_app_cmds(void) diff --git a/common_cmds.c b/common_cmds.c index 54ac60f..cea8ff6 100644 --- a/common_cmds.c +++ b/common_cmds.c @@ -35,6 +35,7 @@ #include #include "diag.h" +#include "dm.h" #include "hdlc.h" #include "masks.h" #include "peripheral.h" @@ -98,7 +99,7 @@ static int handle_logging_configuration(struct diag_client *client, peripheral_broadcast_log_mask(0); - hdlc_enqueue(&client->outq, &resp, sizeof(resp)); + dm_send(client, &resp, sizeof(resp)); break; } case DIAG_CMD_OP_GET_LOG_RANGE: { @@ -115,7 +116,7 @@ static int handle_logging_configuration(struct diag_client *client, diag_cmd_get_log_range(resp.ranges, MAX_EQUIP_ID); resp.status = DIAG_CMD_STATUS_SUCCESS; - hdlc_enqueue(&client->outq, &resp, sizeof(resp)); + dm_send(client, &resp, sizeof(resp)); break; } case DIAG_CMD_OP_SET_LOG_MASK: { @@ -144,7 +145,7 @@ static int handle_logging_configuration(struct diag_client *client, peripheral_broadcast_log_mask(resp->mask_structure.equip_id); - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); break; @@ -193,7 +194,7 @@ static int handle_logging_configuration(struct diag_client *client, peripheral_broadcast_log_mask(resp->mask_structure.equip_id); - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); break; @@ -247,7 +248,7 @@ static int handle_extended_message_configuration(struct diag_client *client, } resp->status = DIAG_CMD_MSG_STATUS_SUCCESSFUL; - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); break; @@ -295,7 +296,7 @@ static int handle_extended_message_configuration(struct diag_client *client, resp->status = DIAG_CMD_MSG_STATUS_UNSUCCESSFUL; } - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); break; } @@ -334,7 +335,7 @@ static int handle_extended_message_configuration(struct diag_client *client, resp->status = DIAG_CMD_MSG_STATUS_UNSUCCESSFUL; } - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(masks); break; @@ -385,7 +386,7 @@ static int handle_extended_message_configuration(struct diag_client *client, resp->status = DIAG_CMD_MSG_STATUS_UNSUCCESSFUL; } - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); break; @@ -414,7 +415,7 @@ static int handle_extended_message_configuration(struct diag_client *client, peripheral_broadcast_msg_mask(NULL); - hdlc_enqueue(&client->outq, &resp, sizeof(resp)); + dm_send(client, &resp, sizeof(resp)); break; } default: @@ -476,7 +477,7 @@ static int handle_event_get_mask(struct diag_client *client, const void *buf, resp->error_code = DIAG_CMD_EVENT_ERROR_CODE_FAIL; } - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); return 0; @@ -531,7 +532,7 @@ static int handle_event_set_mask(struct diag_client *client, resp->error_code = DIAG_CMD_EVENT_ERROR_CODE_FAIL; } - hdlc_enqueue(&client->outq, resp, resp_size); + dm_send(client, resp, resp_size); free(resp); return 0; @@ -558,7 +559,7 @@ static int handle_event_report_control(struct diag_client *client, pkt.cmd_code = DIAG_CMD_EVENT_REPORT_CONTROL; pkt.length = 0; - hdlc_enqueue(&client->outq, &pkt, sizeof(pkt)); + dm_send(client, &pkt, sizeof(pkt)); return 0; } diff --git a/router.c b/router.c index 34d15ea..67d6a10 100644 --- a/router.c +++ b/router.c @@ -36,6 +36,7 @@ #include #include "diag.h" +#include "dm.h" #include "hdlc.h" #include "peripheral.h" #include "util.h" @@ -110,7 +111,7 @@ static void diag_rsp_bad_command(struct diag_client *client, uint8_t *msg, buf[0] = error_code; memcpy(buf + 1, msg, len); - hdlc_enqueue(&client->outq, buf, len + 1); + dm_send(client, buf, len + 1); free(buf); }