diff --git a/comm/messages.c b/comm/messages.c index 2d99935..7ce00ea 100644 --- a/comm/messages.c +++ b/comm/messages.c @@ -34,7 +34,7 @@ void comm_init(void) static TF_Result lst_ping(TinyFrame *tf, TF_Msg *msg) { - tf_respond_snprintf(MSG_SUCCESS, msg->frame_id, "%s/%s", GEX_VERSION, GEX_PLATFORM); + com_respond_snprintf(msg->frame_id, MSG_SUCCESS, "%s/%s", GEX_VERSION, GEX_PLATFORM); return TF_STAY; } @@ -44,7 +44,7 @@ static TF_Result lst_default(TinyFrame *tf, TF_Msg *msg) { dbg("!! Unhandled msg type %02"PRIx8", frame_id 0x%04"PRIx16, msg->type, msg->frame_id); - tf_respond_snprintf(MSG_ERROR, msg->frame_id, "UNKNOWN MSG %"PRIu8, msg->type); + com_respond_snprintf(msg->frame_id, MSG_ERROR, "UNKNOWN MSG %"PRIu8, msg->type); return TF_STAY; } diff --git a/comm/msg_responses.c b/comm/msg_responses.c index 5c09325..3562b02 100644 --- a/comm/msg_responses.c +++ b/comm/msg_responses.c @@ -5,7 +5,7 @@ #include "messages.h" #include "msg_responses.h" -void tf_respond_snprintf(TF_TYPE type, TF_ID id, const char *format, ...) +void com_respond_snprintf(TF_ID frame_id, TF_TYPE type, const char *format, ...) { #define ERR_STR_LEN 64 @@ -15,17 +15,17 @@ void tf_respond_snprintf(TF_TYPE type, TF_ID id, const char *format, ...) uint32_t len = (uint32_t) fixup_vsnprintf(&buf[0], ERR_STR_LEN, format, args); va_end(args); - tf_respond_buf(type, id, (const uint8_t *) buf, len); + com_respond_buf(frame_id, type, (const uint8_t *) buf, len); } -void tf_respond_buf(TF_TYPE type, TF_ID id, const uint8_t *buf, uint32_t len) +void com_respond_buf(TF_ID frame_id, TF_TYPE type, const uint8_t *buf, uint32_t len) { TF_Msg msg; TF_ClearMsg(&msg); { msg.type = type; - msg.frame_id = id; + msg.frame_id = frame_id; msg.data = buf; msg.len = (TF_LEN) len; } @@ -33,13 +33,13 @@ void tf_respond_buf(TF_TYPE type, TF_ID id, const uint8_t *buf, uint32_t len) } -void tf_respond_ok(TF_ID frame_id) +void com_respond_ok(TF_ID frame_id) { - tf_respond_buf(MSG_SUCCESS, frame_id, NULL, 0); + com_respond_buf(frame_id, MSG_SUCCESS, NULL, 0); } -void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len) +void com_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len) { TF_Msg msg; TF_ClearMsg(&msg); @@ -53,46 +53,46 @@ void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len) } -void tf_respond_str(TF_TYPE type, TF_ID frame_id, const char *str) +void com_respond_str(TF_TYPE type, TF_ID frame_id, const char *str) { - tf_respond_buf(type, frame_id, (const uint8_t *) str, (uint32_t) strlen(str)); + com_respond_buf(frame_id, type, (const uint8_t *) str, (uint32_t) strlen(str)); } // --------------------------------------------------------------------------- -void tf_respond_err(TF_ID frame_id, const char *message) +void com_respond_err(TF_ID frame_id, const char *message) { - tf_respond_str(MSG_ERROR, frame_id, message); + com_respond_str(MSG_ERROR, frame_id, message); } -void tf_respond_bad_cmd(TF_ID frame_id) +void com_respond_bad_cmd(TF_ID frame_id) { - tf_respond_err(frame_id, "BAD COMMAND"); + com_respond_err(frame_id, "BAD COMMAND"); } -void tf_respond_malformed_cmd(TF_ID frame_id) +void com_respond_malformed_cmd(TF_ID frame_id) { - tf_respond_err(frame_id, "MALFORMED PAYLOAD"); + com_respond_err(frame_id, "MALFORMED PAYLOAD"); } // --------------------------------------------------------------------------- -void tf_respond_u8(TF_ID frame_id, uint8_t d) +void com_respond_u8(TF_ID frame_id, uint8_t d) { - tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 1); + com_respond_buf(frame_id, MSG_SUCCESS, (const uint8_t *) &d, 1); } -void tf_respond_u16(TF_ID frame_id, uint16_t d) +void com_respond_u16(TF_ID frame_id, uint16_t d) { - tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 2); + com_respond_buf(frame_id, MSG_SUCCESS, (const uint8_t *) &d, 2); } -void tf_respond_u32(TF_ID frame_id, uint32_t d) +void com_respond_u32(TF_ID frame_id, uint32_t d) { - tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 4); + com_respond_buf(frame_id, MSG_SUCCESS, (const uint8_t *) &d, 4); } diff --git a/comm/msg_responses.h b/comm/msg_responses.h index 9c319ac..8189092 100644 --- a/comm/msg_responses.h +++ b/comm/msg_responses.h @@ -19,7 +19,7 @@ * @param ... - replacements */ void __attribute__((format(printf,3,4))) -tf_respond_snprintf(TF_TYPE type, TF_ID frame_id, const char *format, ...); +com_respond_snprintf(TF_ID frame_id, TF_TYPE type, const char *format, ...); /** * Respond to a TF message with a buffer of fixed length and custom type. @@ -30,7 +30,7 @@ tf_respond_snprintf(TF_TYPE type, TF_ID frame_id, const char *format, ...); * @param buf - byte buffer * @param len - buffer size */ -void tf_respond_buf(TF_TYPE type, TF_ID frame_id, const uint8_t *buf, uint32_t len); +void com_respond_buf(TF_ID frame_id, TF_TYPE type, const uint8_t *buf, uint32_t len); /** * Respond to a TF message with empty body and MSG_SUCCESS type. @@ -38,7 +38,7 @@ void tf_respond_buf(TF_TYPE type, TF_ID frame_id, const uint8_t *buf, uint32_t l * * @param frame_id - ID of the original msg */ -void tf_respond_ok(TF_ID frame_id); +void com_respond_ok(TF_ID frame_id); /** * Same like tf_respond_buf(), but used for sending spontaneous reports. @@ -48,7 +48,7 @@ void tf_respond_ok(TF_ID frame_id); * @param buf - byte buffer * @param len - buffer size */ -void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len); +void com_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len); /** * Same like tf_respond_buf(), but the buffer length is measured with strlen. @@ -59,7 +59,7 @@ void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len); * @param frame_id - ID of the original msg * @param str - character buffer, zero terminated */ -void tf_respond_str(TF_TYPE type, TF_ID frame_id, const char *str); +void com_respond_str(TF_TYPE type, TF_ID frame_id, const char *str); /** * Schedule sending an ASCII string error response. @@ -68,21 +68,21 @@ void tf_respond_str(TF_TYPE type, TF_ID frame_id, const char *str); * @param frame_id - ID of the original msg * @param str - character buffer, zero terminated */ -void tf_respond_err(TF_ID frame_id, const char *str); +void com_respond_err(TF_ID frame_id, const char *str); /** * Variant of sched_respond_err() for reporting bad received command code * * @param msg_id - ID of the original msg */ -void tf_respond_bad_cmd(TF_ID frame_id); +void com_respond_bad_cmd(TF_ID frame_id); /** * Variant of sched_respond_err() for reporting malformed commands (e.g. too short payload) * * @param msg_id - ID of the original msg */ -void tf_respond_malformed_cmd(TF_ID frame_id); +void com_respond_malformed_cmd(TF_ID frame_id); /** * Schedule sending a one-byte response with MSG_SUCCESS type. @@ -91,7 +91,7 @@ void tf_respond_malformed_cmd(TF_ID frame_id); * @param frame_id - ID of the original msg * @param d - data */ -void tf_respond_u8(TF_ID frame_id, uint8_t d); +void com_respond_u8(TF_ID frame_id, uint8_t d); /** * Schedule sending a two-byte response with MSG_SUCCESS type. @@ -100,7 +100,7 @@ void tf_respond_u8(TF_ID frame_id, uint8_t d); * @param frame_id - ID of the original msg * @param d - data */ -void tf_respond_u16(TF_ID frame_id, uint16_t d); +void com_respond_u16(TF_ID frame_id, uint16_t d); /** * Schedule sending a 4-byte response with MSG_SUCCESS type. @@ -109,6 +109,6 @@ void tf_respond_u16(TF_ID frame_id, uint16_t d); * @param frame_id - ID of the original msg * @param d - data */ -void tf_respond_u32(TF_ID frame_id, uint32_t d); +void com_respond_u32(TF_ID frame_id, uint32_t d); #endif //GEX_F072_MSG_RESPONSES_H diff --git a/framework/unit_registry.c b/framework/unit_registry.c index 725f2ff..524b2f9 100644 --- a/framework/unit_registry.c +++ b/framework/unit_registry.c @@ -509,7 +509,7 @@ void ureg_deliver_unit_request(TF_Msg *msg) if (!pp.ok) { dbg("!! pp not OK!"); } if (callsign == 0 || !pp.ok) { - tf_respond_malformed_cmd(msg->frame_id); + com_respond_malformed_cmd(msg->frame_id); return; } @@ -519,7 +519,7 @@ void ureg_deliver_unit_request(TF_Msg *msg) if (pUnit->callsign == callsign) { bool ok = pUnit->driver->handleRequest(pUnit, msg->frame_id, command, &pp); if (ok && confirmed) { - tf_respond_ok(msg->frame_id); + com_respond_ok(msg->frame_id); } return; } @@ -527,7 +527,7 @@ void ureg_deliver_unit_request(TF_Msg *msg) } // Not found - tf_respond_snprintf(MSG_ERROR, msg->frame_id, "NO UNIT @ %"PRIu8, callsign); + com_respond_snprintf(msg->frame_id, MSG_ERROR, "NO UNIT @ %"PRIu8, callsign); } @@ -547,7 +547,7 @@ void ureg_report_active_units(TF_ID frame_id) bool suc = true; uint8_t *buff = malloc_ck(msglen, &suc); - if (!suc) { tf_respond_str(MSG_ERROR, frame_id, "OUT OF MEMORY"); return; } + if (!suc) { com_respond_str(MSG_ERROR, frame_id, "OUT OF MEMORY"); return; } { PayloadBuilder pb = pb_start(buff, msglen, NULL); @@ -562,7 +562,7 @@ void ureg_report_active_units(TF_ID frame_id) assert_param(pb.ok); - tf_respond_buf(MSG_SUCCESS, frame_id, buff, msglen); + com_respond_buf(frame_id, MSG_SUCCESS, buff, msglen); } free(buff); diff --git a/units/neopixel/unit_neopixel.c b/units/neopixel/unit_neopixel.c index 5f0f42f..3610590 100644 --- a/units/neopixel/unit_neopixel.c +++ b/units/neopixel/unit_neopixel.c @@ -173,14 +173,14 @@ static bool Npx_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo break; default: - tf_respond_bad_cmd(frame_id); + com_respond_bad_cmd(frame_id); return false; } return true; bad_count: - tf_respond_err(frame_id, "BAD PIXEL COUNT"); + com_respond_err(frame_id, "BAD PIXEL COUNT"); return false; } diff --git a/units/pin/unit_pin.c b/units/pin/unit_pin.c index b56ff6c..fb5a299 100644 --- a/units/pin/unit_pin.c +++ b/units/pin/unit_pin.c @@ -194,23 +194,23 @@ static bool Pin_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo case CMD_READ: if (!priv->output) { - tf_respond_u8(frame_id, (bool) LL_GPIO_IsInputPinSet(priv->port, priv->ll_pin)); + com_respond_u8(frame_id, (bool) LL_GPIO_IsInputPinSet(priv->port, priv->ll_pin)); } else goto must_be_input; break; default: - tf_respond_bad_cmd(frame_id); + com_respond_bad_cmd(frame_id); return false; } return true; must_be_output: - tf_respond_err(frame_id, "NOT OUTPUT PIN"); + com_respond_err(frame_id, "NOT OUTPUT PIN"); return false; must_be_input: - tf_respond_err(frame_id, "NOT INPUT PIN"); + com_respond_err(frame_id, "NOT INPUT PIN"); return false; } diff --git a/units/test/unit_test.c b/units/test/unit_test.c index d3d7f87..7490fe1 100644 --- a/units/test/unit_test.c +++ b/units/test/unit_test.c @@ -117,13 +117,13 @@ static bool Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo switch (command) { case CMD_PING: - tf_respond_ok(frame_id); + com_respond_ok(frame_id); break; case CMD_ECHO:; uint32_t len; const uint8_t *data = pp_tail(pp, &len); - tf_respond_buf(MSG_SUCCESS, frame_id, data, len); + com_respond_buf(frame_id, MSG_SUCCESS, data, len); break; case CMD_BULKREAD:; @@ -138,7 +138,7 @@ static bool Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo break; default: - tf_respond_bad_cmd(frame_id); + com_respond_bad_cmd(frame_id); return false; }