|
|
|
@ -8,6 +8,7 @@ |
|
|
|
|
void tf_respond_snprintf(TF_TYPE type, TF_ID id, const char *format, ...) |
|
|
|
|
{ |
|
|
|
|
#define ERR_STR_LEN 64 |
|
|
|
|
|
|
|
|
|
char buf[ERR_STR_LEN]; |
|
|
|
|
va_list args; |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
TF_Msg msg; |
|
|
|
@ -46,93 +53,46 @@ void tf_send_buf(TF_TYPE type, const uint8_t *buf, uint32_t len) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static void job_respond_err(Job *job) |
|
|
|
|
{ |
|
|
|
|
tf_respond_str(MSG_ERROR, job->frame_id, job->str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sched_respond_err(TF_ID frame_id, const char *message) |
|
|
|
|
{ |
|
|
|
|
dbg("ERR: %s", message); |
|
|
|
|
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_str(TF_TYPE type, TF_ID frame_id, const char *str) |
|
|
|
|
{ |
|
|
|
|
sched_respond_err(frame_id, "BAD COMMAND"); |
|
|
|
|
tf_respond_buf(type, frame_id, (const uint8_t *) str, (uint32_t) strlen(str)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_err(TF_ID frame_id, const char *message) |
|
|
|
|
{ |
|
|
|
|
tf_respond_ok(job->frame_id); |
|
|
|
|
tf_respond_str(MSG_ERROR, frame_id, message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sched_respond_suc(TF_ID frame_id) |
|
|
|
|
void tf_respond_bad_cmd(TF_ID frame_id) |
|
|
|
|
{ |
|
|
|
|
Job job = { |
|
|
|
|
.cb = job_respond_suc, |
|
|
|
|
.frame_id = frame_id |
|
|
|
|
}; |
|
|
|
|
scheduleJob(&job, TSK_SCHED_LOW); |
|
|
|
|
tf_respond_err(frame_id, "BAD COMMAND"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static void job_respond_uX(Job *job) |
|
|
|
|
void tf_respond_malformed_cmd(TF_ID frame_id) |
|
|
|
|
{ |
|
|
|
|
tf_respond_buf(MSG_SUCCESS, job->frame_id, (const uint8_t *) &job->d32, job->len); |
|
|
|
|
tf_respond_err(frame_id, "MALFORMED PAYLOAD"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void sched_respond_u8(TF_ID frame_id, uint8_t d) |
|
|
|
|
void tf_respond_u8(TF_ID frame_id, uint8_t d) |
|
|
|
|
{ |
|
|
|
|
Job job = { |
|
|
|
|
.cb = job_respond_uX, |
|
|
|
|
.frame_id = frame_id, |
|
|
|
|
.d32 = d, |
|
|
|
|
.len = 1 |
|
|
|
|
}; |
|
|
|
|
scheduleJob(&job, TSK_SCHED_HIGH); |
|
|
|
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sched_respond_u16(TF_ID frame_id, uint16_t d) |
|
|
|
|
void tf_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); |
|
|
|
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sched_respond_u32(TF_ID frame_id, uint32_t d) |
|
|
|
|
void tf_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); |
|
|
|
|
tf_respond_buf(MSG_SUCCESS, frame_id, (const uint8_t *) &d, 4); |
|
|
|
|
} |
|
|
|
|