implemented precision timestamps in report messages

This commit is contained in:
2018-01-27 20:27:33 +01:00
parent 94e87c74d3
commit 04e32860f7
14 changed files with 246 additions and 59 deletions
+53
View File
@@ -0,0 +1,53 @@
//
// Created by MightyPork on 2018/01/27.
//
#include "platform.h"
#include "messages.h"
#include "event_reports.h"
static uint8_t evt_buf[10];
bool EventReport_Start(EventReport *report)
{
assert_param(report->timestamp != 0);
TF_Msg msg;
TF_ClearMsg(&msg);
msg.len = (TF_LEN) (report->length + 1 /*callsign*/ + 1 /*type*/ + 8 /*checksum*/);
msg.type = MSG_UNIT_REPORT;
if (!TF_Send_Multipart(comm, &msg)) {
dbg("!! Err sending event");
return false;
}
PayloadBuilder pb = pb_start(evt_buf, 10, NULL);
pb_u8(&pb, report->unit->callsign);
pb_u8(&pb, report->type);
pb_u64(&pb, report->timestamp);
assert_param(pb.ok);
TF_Multipart_Payload(comm, evt_buf, 10);
return true;
}
void EventReport_Data(const uint8_t *buff, uint16_t len)
{
TF_Multipart_Payload(comm, buff, len);
}
void EventReport_End(void)
{
TF_Multipart_Close(comm);
}
bool EventReport_Send(EventReport *report)
{
assert_param(report->data != NULL);
if (!EventReport_Start(report)) return false;
EventReport_Data(report->data, report->length);
EventReport_End();
return true;
}
+32
View File
@@ -0,0 +1,32 @@
//
// Created by MightyPork on 2018/01/27.
//
#ifndef GEX_F072_EVENT_REPORTS_H
#define GEX_F072_EVENT_REPORTS_H
#ifndef GEX_MESSAGES_H
#error "Include messages.h instead!"
#endif
#include <TinyFrame.h>
#include "framework/unit.h"
/**
* Event report object
*/
typedef struct event_report_ {
Unit *unit; //!< Reporting unit
uint8_t type; //!< Report type (if unit has multiple reports, otherwise 0)
uint64_t timestamp; //!< Microsecond timestamp of the event, captured as close as possible to the IRQ
uint16_t length; //!< Payload length
uint8_t *data; //!< Data if using the EventReport_Send() function, otherwise NULL and data is sent using EventReport_Data()
} EventReport;
bool EventReport_Send(EventReport *report);
bool EventReport_Start(EventReport *report);
void EventReport_Data(const uint8_t *buff, uint16_t len);
void EventReport_End(void);
#endif //GEX_F072_EVENT_REPORTS_H
+1
View File
@@ -49,6 +49,7 @@ extern TinyFrame *comm;
#include "msg_responses.h"
#include "msg_bulkread.h"
#include "msg_bulkwrite.h"
#include "event_reports.h"
/**
* Initialize TinyFrame and set up listeners