implemented precision timestamps in report messages
This commit is contained in:
+17
-17
@@ -3,11 +3,7 @@
|
||||
//
|
||||
|
||||
#include "unit_base.h"
|
||||
#include "platform/irq_dispatcher.h"
|
||||
#include "comm/messages.h"
|
||||
#include "unit_din.h"
|
||||
#include "tasks/task_msg.h"
|
||||
#include "utils/avrlibc.h"
|
||||
|
||||
/** Private data structure */
|
||||
struct priv {
|
||||
@@ -168,18 +164,19 @@ static error_t DI_preInit(Unit *unit)
|
||||
*/
|
||||
static void ID_SendTriggerReportToMaster(Job *job)
|
||||
{
|
||||
Unit *unit = job->data1;
|
||||
|
||||
PayloadBuilder pb = pb_start(unit_tmp512, UNIT_TMP_LEN, NULL);
|
||||
pb_u8(&pb, unit->callsign);
|
||||
pb_u8(&pb, 0x00); // report type "Trigger"
|
||||
{
|
||||
pb_u16(&pb, (uint16_t) job->d32_2); // packed, 1 on the triggering pin
|
||||
pb_u16(&pb, (uint16_t) job->d32_3); // packed, snapshot
|
||||
// the snapshot can be used to capture the other input pins
|
||||
}
|
||||
pb_u16(&pb, (uint16_t) job->data1); // packed, 1 on the triggering pin
|
||||
pb_u16(&pb, (uint16_t) job->data2); // packed, snapshot
|
||||
assert_param(pb.ok);
|
||||
com_send_pb(MSG_UNIT_REPORT, &pb);
|
||||
|
||||
EventReport event = {
|
||||
.unit = job->unit,
|
||||
.timestamp = job->timestamp,
|
||||
.data = pb.start,
|
||||
.length = (uint16_t) pb_length(&pb),
|
||||
};
|
||||
|
||||
EventReport_Send(&event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,6 +186,8 @@ static void ID_SendTriggerReportToMaster(Job *job)
|
||||
*/
|
||||
static void DI_handleExti(void *arg)
|
||||
{
|
||||
const uint64_t ts = PTIM_GetMicrotime();
|
||||
|
||||
Unit *unit = arg;
|
||||
struct priv *priv = unit->data;
|
||||
const uint16_t snapshot = (uint16_t) priv->port->IDR;
|
||||
@@ -215,9 +214,10 @@ static void DI_handleExti(void *arg)
|
||||
|
||||
if (trigger_map != 0) {
|
||||
Job j = {
|
||||
.data1 = unit,
|
||||
.d32_2 = pinmask_pack(trigger_map, priv->pins),
|
||||
.d32_3 = pinmask_pack(snapshot, priv->pins),
|
||||
.unit = unit,
|
||||
.timestamp = ts,
|
||||
.data1 = pinmask_pack(trigger_map, priv->pins),
|
||||
.data2 = pinmask_pack(snapshot, priv->pins),
|
||||
.cb = ID_SendTriggerReportToMaster
|
||||
};
|
||||
scheduleJob(&j);
|
||||
|
||||
+17
-18
@@ -2,31 +2,28 @@
|
||||
// Created by MightyPork on 2018/01/02.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "comm/messages.h"
|
||||
#include "unit_base.h"
|
||||
#include "unit_usart.h"
|
||||
#include "tasks/task_msg.h"
|
||||
|
||||
#define UUSART_INTERNAL
|
||||
#include "_internal.h"
|
||||
|
||||
static void UUSART_SendReceivedDataToMaster(Job *job)
|
||||
{
|
||||
Unit *unit = job->data1;
|
||||
Unit *unit = job->unit;
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
uint32_t readpos = job->d32;
|
||||
uint32_t count = job->len;
|
||||
uint16_t readpos = (uint16_t) job->data1;
|
||||
uint16_t count = (uint16_t) job->data2;
|
||||
|
||||
// TODO use TF's Multipart sending
|
||||
// TODO add API for building reports
|
||||
PayloadBuilder pb = pb_start(unit_tmp512, UNIT_TMP_LEN, NULL);
|
||||
pb_u8(&pb, unit->callsign);
|
||||
pb_u8(&pb, 0x00); // report type "Data received"
|
||||
pb_buf(&pb, (uint8_t *) (priv->rx_buffer + readpos), count);
|
||||
assert_param(pb.ok);
|
||||
com_send_pb(MSG_UNIT_REPORT, &pb);
|
||||
EventReport event = {
|
||||
.unit = job->unit,
|
||||
.timestamp = job->timestamp,
|
||||
.data = (uint8_t *) (priv->rx_buffer + readpos),
|
||||
.length = count,
|
||||
};
|
||||
|
||||
EventReport_Send(&event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +34,8 @@ static void UUSART_SendReceivedDataToMaster(Job *job)
|
||||
*/
|
||||
void UUSART_DMA_HandleRxFromIRQ(Unit *unit, uint16_t endpos)
|
||||
{
|
||||
const uint64_t ts = PTIM_GetMicrotime();
|
||||
|
||||
assert_param(unit);
|
||||
struct priv *priv = unit->data;
|
||||
assert_param(priv);
|
||||
@@ -47,11 +46,11 @@ void UUSART_DMA_HandleRxFromIRQ(Unit *unit, uint16_t endpos)
|
||||
uint16_t count = (endpos - readpos);
|
||||
|
||||
// We defer it to the job queue
|
||||
// FIXME this can starve the shared queue if full duplex is used, we need a second higher priority queue for those report jobs
|
||||
Job j = {
|
||||
.data1 = unit,
|
||||
.d32 = priv->rx_buf_readpos,
|
||||
.len = count,
|
||||
.unit = unit,
|
||||
.timestamp = ts,
|
||||
.data1 = priv->rx_buf_readpos,
|
||||
.data2 = count,
|
||||
.cb = UUSART_SendReceivedDataToMaster
|
||||
};
|
||||
scheduleJob(&j);
|
||||
|
||||
Reference in New Issue
Block a user