removed all uses of the jobs queue for TF responses, not needed naymore
This commit is contained in:
+3
-33
@@ -32,39 +32,19 @@ void comm_init(void)
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static void job_ping_reply(Job *job)
|
|
||||||
{
|
|
||||||
tf_respond_snprintf(MSG_SUCCESS, job->frame_id, "%s/%s", GEX_VERSION, GEX_PLATFORM);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TF_Result lst_ping(TinyFrame *tf, TF_Msg *msg)
|
static TF_Result lst_ping(TinyFrame *tf, TF_Msg *msg)
|
||||||
{
|
{
|
||||||
Job job = {
|
tf_respond_snprintf(MSG_SUCCESS, msg->frame_id, "%s/%s", GEX_VERSION, GEX_PLATFORM);
|
||||||
.cb = job_ping_reply,
|
|
||||||
.frame_id = msg->frame_id
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
|
|
||||||
return TF_STAY;
|
return TF_STAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void job_unhandled_resp(Job *job)
|
|
||||||
{
|
|
||||||
tf_respond_snprintf(MSG_ERROR, job->frame_id, "UNKNOWN MSG %"PRIu32, job->d32);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TF_Result lst_default(TinyFrame *tf, TF_Msg *msg)
|
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);
|
dbg("!! Unhandled msg type %02"PRIx8", frame_id 0x%04"PRIx16, msg->type, msg->frame_id);
|
||||||
Job job = {
|
|
||||||
.cb = job_unhandled_resp,
|
|
||||||
.frame_id = msg->frame_id,
|
|
||||||
.d32 = msg->type
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
|
|
||||||
|
tf_respond_snprintf(MSG_ERROR, msg->frame_id, "UNKNOWN MSG %"PRIu8, msg->type);
|
||||||
return TF_STAY;
|
return TF_STAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,18 +58,8 @@ static TF_Result lst_unit(TinyFrame *tf, TF_Msg *msg)
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void job_list_units(Job *job)
|
|
||||||
{
|
|
||||||
ureg_report_active_units(job->frame_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TF_Result lst_list_units(TinyFrame *tf, TF_Msg *msg)
|
static TF_Result lst_list_units(TinyFrame *tf, TF_Msg *msg)
|
||||||
{
|
{
|
||||||
Job job = {
|
ureg_report_active_units(msg->frame_id);
|
||||||
.cb = job_list_units,
|
|
||||||
.frame_id = msg->frame_id,
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
|
|
||||||
return TF_STAY;
|
return TF_STAY;
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-65
@@ -8,6 +8,7 @@
|
|||||||
void tf_respond_snprintf(TF_TYPE type, TF_ID id, const char *format, ...)
|
void tf_respond_snprintf(TF_TYPE type, TF_ID id, const char *format, ...)
|
||||||
{
|
{
|
||||||
#define ERR_STR_LEN 64
|
#define ERR_STR_LEN 64
|
||||||
|
|
||||||
char buf[ERR_STR_LEN];
|
char buf[ERR_STR_LEN];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
@@ -32,6 +33,12 @@ 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)
|
||||||
|
{
|
||||||
|
tf_respond_buf(MSG_SUCCESS, frame_id, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len)
|
void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len)
|
||||||
{
|
{
|
||||||
TF_Msg msg;
|
TF_Msg msg;
|
||||||
@@ -46,93 +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)
|
||||||
|
{
|
||||||
|
tf_respond_buf(type, frame_id, (const uint8_t *) str, (uint32_t) strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static void job_respond_err(Job *job)
|
void tf_respond_err(TF_ID frame_id, const char *message)
|
||||||
{
|
{
|
||||||
tf_respond_str(MSG_ERROR, job->frame_id, job->str);
|
tf_respond_str(MSG_ERROR, frame_id, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_err(TF_ID frame_id, const char *message)
|
void tf_respond_bad_cmd(TF_ID frame_id)
|
||||||
{
|
{
|
||||||
dbg("ERR: %s", message);
|
tf_respond_err(frame_id, "BAD COMMAND");
|
||||||
Job job = {
|
|
||||||
.cb = job_respond_err,
|
|
||||||
.frame_id = frame_id,
|
|
||||||
.str = message
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_bad_cmd(TF_ID frame_id)
|
void tf_respond_malformed_cmd(TF_ID frame_id)
|
||||||
{
|
{
|
||||||
sched_respond_err(frame_id, "BAD COMMAND");
|
tf_respond_err(frame_id, "MALFORMED PAYLOAD");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_malformed_cmd(TF_ID frame_id)
|
|
||||||
{
|
|
||||||
sched_respond_err(frame_id, "MALFORMED PAYLOAD");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static void job_respond_suc(Job *job)
|
void tf_respond_u8(TF_ID frame_id, uint8_t d)
|
||||||
{
|
{
|
||||||
tf_respond_ok(job->frame_id);
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_suc(TF_ID frame_id)
|
void tf_respond_u16(TF_ID frame_id, uint16_t d)
|
||||||
{
|
{
|
||||||
Job job = {
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 2);
|
||||||
.cb = job_respond_suc,
|
|
||||||
.frame_id = frame_id
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
static void job_respond_uX(Job *job)
|
|
||||||
{
|
|
||||||
tf_respond_buf(MSG_SUCCESS, job->frame_id, (const uint8_t *) &job->d32, job->len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_u8(TF_ID frame_id, uint8_t d)
|
void tf_respond_u32(TF_ID frame_id, uint32_t d)
|
||||||
{
|
{
|
||||||
Job job = {
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 4);
|
||||||
.cb = job_respond_uX,
|
|
||||||
.frame_id = frame_id,
|
|
||||||
.d32 = d,
|
|
||||||
.len = 1
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_u16(TF_ID frame_id, uint16_t d)
|
|
||||||
{
|
|
||||||
Job job = {
|
|
||||||
.cb = job_respond_uX,
|
|
||||||
.frame_id = frame_id,
|
|
||||||
.d32 = d,
|
|
||||||
.len = 2
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void sched_respond_u32(TF_ID frame_id, uint32_t d)
|
|
||||||
{
|
|
||||||
Job job = {
|
|
||||||
.cb = job_respond_uX,
|
|
||||||
.frame_id = frame_id,
|
|
||||||
.d32 = d,
|
|
||||||
.len = 4
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_HIGH);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-22
@@ -38,10 +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
|
* @param frame_id - ID of the original msg
|
||||||
*/
|
*/
|
||||||
static inline void tf_respond_ok(TF_ID frame_id)
|
void tf_respond_ok(TF_ID frame_id);
|
||||||
{
|
|
||||||
tf_respond_buf(MSG_SUCCESS, frame_id, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same like tf_respond_buf(), but used for sending spontaneous reports.
|
* Same like tf_respond_buf(), but used for sending spontaneous reports.
|
||||||
@@ -62,10 +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 frame_id - ID of the original msg
|
||||||
* @param str - character buffer, zero terminated
|
* @param str - character buffer, zero terminated
|
||||||
*/
|
*/
|
||||||
static inline void tf_respond_str(TF_TYPE type, TF_ID frame_id, const char *str)
|
void tf_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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule sending an ASCII string error response.
|
* Schedule sending an ASCII string error response.
|
||||||
@@ -74,29 +68,21 @@ static inline void tf_respond_str(TF_TYPE type, TF_ID frame_id, const char *str)
|
|||||||
* @param frame_id - ID of the original msg
|
* @param frame_id - ID of the original msg
|
||||||
* @param str - character buffer, zero terminated
|
* @param str - character buffer, zero terminated
|
||||||
*/
|
*/
|
||||||
void sched_respond_err(TF_ID frame_id, const char *str);
|
void tf_respond_err(TF_ID frame_id, const char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variant of sched_respond_err() for reporting bad received command code
|
* Variant of sched_respond_err() for reporting bad received command code
|
||||||
*
|
*
|
||||||
* @param msg_id - ID of the original msg
|
* @param msg_id - ID of the original msg
|
||||||
*/
|
*/
|
||||||
void sched_respond_bad_cmd(TF_ID frame_id);
|
void tf_respond_bad_cmd(TF_ID frame_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variant of sched_respond_err() for reporting malformed commands (e.g. too short payload)
|
* Variant of sched_respond_err() for reporting malformed commands (e.g. too short payload)
|
||||||
*
|
*
|
||||||
* @param msg_id - ID of the original msg
|
* @param msg_id - ID of the original msg
|
||||||
*/
|
*/
|
||||||
void sched_respond_malformed_cmd(TF_ID frame_id);
|
void tf_respond_malformed_cmd(TF_ID frame_id);
|
||||||
|
|
||||||
/**
|
|
||||||
* Schedule sending an empty response with MSG_SUCCESS type.
|
|
||||||
* Schedules a low priority job.
|
|
||||||
*
|
|
||||||
* @param frame_id - ID of the original msg
|
|
||||||
*/
|
|
||||||
void sched_respond_suc(TF_ID frame_id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule sending a one-byte response with MSG_SUCCESS type.
|
* Schedule sending a one-byte response with MSG_SUCCESS type.
|
||||||
@@ -105,7 +91,7 @@ void sched_respond_suc(TF_ID frame_id);
|
|||||||
* @param frame_id - ID of the original msg
|
* @param frame_id - ID of the original msg
|
||||||
* @param d - data
|
* @param d - data
|
||||||
*/
|
*/
|
||||||
void sched_respond_u8(TF_ID frame_id, uint8_t d);
|
void tf_respond_u8(TF_ID frame_id, uint8_t d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule sending a two-byte response with MSG_SUCCESS type.
|
* Schedule sending a two-byte response with MSG_SUCCESS type.
|
||||||
@@ -114,7 +100,7 @@ void sched_respond_u8(TF_ID frame_id, uint8_t d);
|
|||||||
* @param frame_id - ID of the original msg
|
* @param frame_id - ID of the original msg
|
||||||
* @param d - data
|
* @param d - data
|
||||||
*/
|
*/
|
||||||
void sched_respond_u16(TF_ID frame_id, uint16_t d);
|
void tf_respond_u16(TF_ID frame_id, uint16_t d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule sending a 4-byte response with MSG_SUCCESS type.
|
* Schedule sending a 4-byte response with MSG_SUCCESS type.
|
||||||
@@ -123,6 +109,6 @@ void sched_respond_u16(TF_ID frame_id, uint16_t d);
|
|||||||
* @param frame_id - ID of the original msg
|
* @param frame_id - ID of the original msg
|
||||||
* @param d - data
|
* @param d - data
|
||||||
*/
|
*/
|
||||||
void sched_respond_u32(TF_ID frame_id, uint32_t d);
|
void tf_respond_u32(TF_ID frame_id, uint32_t d);
|
||||||
|
|
||||||
#endif //GEX_F072_MSG_RESPONSES_H
|
#endif //GEX_F072_MSG_RESPONSES_H
|
||||||
|
|||||||
@@ -495,11 +495,6 @@ uint32_t ureg_get_num_units(void)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void job_nosuch_unit(Job *job)
|
|
||||||
{
|
|
||||||
tf_respond_snprintf(MSG_ERROR, job->frame_id, "NO UNIT @ %"PRIu32, job->d32);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Deliver message to it's destination unit */
|
/** Deliver message to it's destination unit */
|
||||||
void ureg_deliver_unit_request(TF_Msg *msg)
|
void ureg_deliver_unit_request(TF_Msg *msg)
|
||||||
{
|
{
|
||||||
@@ -514,7 +509,7 @@ void ureg_deliver_unit_request(TF_Msg *msg)
|
|||||||
if (!pp.ok) { dbg("!! pp not OK!"); }
|
if (!pp.ok) { dbg("!! pp not OK!"); }
|
||||||
|
|
||||||
if (callsign == 0 || !pp.ok) {
|
if (callsign == 0 || !pp.ok) {
|
||||||
sched_respond_malformed_cmd(msg->frame_id);
|
tf_respond_malformed_cmd(msg->frame_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +519,7 @@ void ureg_deliver_unit_request(TF_Msg *msg)
|
|||||||
if (pUnit->callsign == callsign) {
|
if (pUnit->callsign == callsign) {
|
||||||
bool ok = pUnit->driver->handleRequest(pUnit, msg->frame_id, command, &pp);
|
bool ok = pUnit->driver->handleRequest(pUnit, msg->frame_id, command, &pp);
|
||||||
if (ok && confirmed) {
|
if (ok && confirmed) {
|
||||||
sched_respond_suc(msg->frame_id);
|
tf_respond_ok(msg->frame_id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -532,12 +527,7 @@ void ureg_deliver_unit_request(TF_Msg *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not found
|
// Not found
|
||||||
Job job = {
|
tf_respond_snprintf(MSG_ERROR, msg->frame_id, "NO UNIT @ %"PRIu8, callsign);
|
||||||
.cb = job_nosuch_unit,
|
|
||||||
.frame_id = msg->frame_id,
|
|
||||||
.d32 = callsign
|
|
||||||
};
|
|
||||||
scheduleJob(&job, TSK_SCHED_LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -173,14 +173,14 @@ static bool Npx_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sched_respond_bad_cmd(frame_id);
|
tf_respond_bad_cmd(frame_id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bad_count:
|
bad_count:
|
||||||
sched_respond_err(frame_id, "BAD PIXEL COUNT");
|
tf_respond_err(frame_id, "BAD PIXEL COUNT");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,23 +194,23 @@ static bool Pin_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo
|
|||||||
|
|
||||||
case CMD_READ:
|
case CMD_READ:
|
||||||
if (!priv->output) {
|
if (!priv->output) {
|
||||||
sched_respond_u8(frame_id, (bool) LL_GPIO_IsInputPinSet(priv->port, priv->ll_pin));
|
tf_respond_u8(frame_id, (bool) LL_GPIO_IsInputPinSet(priv->port, priv->ll_pin));
|
||||||
} else goto must_be_input;
|
} else goto must_be_input;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sched_respond_bad_cmd(frame_id);
|
tf_respond_bad_cmd(frame_id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
must_be_output:
|
must_be_output:
|
||||||
sched_respond_err(frame_id, "NOT OUTPUT PIN");
|
tf_respond_err(frame_id, "NOT OUTPUT PIN");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
must_be_input:
|
must_be_input:
|
||||||
sched_respond_err(frame_id, "NOT INPUT PIN");
|
tf_respond_err(frame_id, "NOT INPUT PIN");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ static bool Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sched_respond_bad_cmd(frame_id);
|
tf_respond_bad_cmd(frame_id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user