decrease size of minute buffer
This commit is contained in:
@ -5,17 +5,12 @@
|
|||||||
#include <sha256.h>
|
#include <sha256.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) {
|
|
||||||
uint64_t timestamp;
|
|
||||||
uint32_t frequency;
|
|
||||||
} t_event;
|
|
||||||
|
|
||||||
#define SECONDS_PER_MINUTE 60
|
#define SECONDS_PER_MINUTE 60
|
||||||
typedef struct __attribute__((__packed__)) {
|
typedef struct __attribute__((__packed__)) {
|
||||||
char deviceId[sizeof(((t_configBlock*)0)->deviceId)];
|
char deviceId[sizeof(((t_configBlock*)0)->deviceId)];
|
||||||
uint8_t hash[SHA256_BLOCK_SIZE];
|
uint8_t hash[SHA256_BLOCK_SIZE];
|
||||||
uint8_t done;
|
uint64_t timestamp;
|
||||||
t_event events[SECONDS_PER_MINUTE];
|
uint32_t frequency[SECONDS_PER_MINUTE];
|
||||||
} t_minuteStruct;
|
} t_minuteStruct;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
@ -30,7 +30,8 @@ static t_seconds *seconds;
|
|||||||
|
|
||||||
#define NUM_OF_MINUTE_BUFFERS 2
|
#define NUM_OF_MINUTE_BUFFERS 2
|
||||||
t_minuteBuffer minuteBuffers[NUM_OF_MINUTE_BUFFERS];
|
t_minuteBuffer minuteBuffers[NUM_OF_MINUTE_BUFFERS];
|
||||||
uint8_t activeMinuteBuffer = 0;
|
bool minuteBufferReady[NUM_OF_MINUTE_BUFFERS];
|
||||||
|
uint8_t activeMinuteBuffer;
|
||||||
|
|
||||||
static t_configBlock *config;
|
static t_configBlock *config;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ void counterMinuteTick(void *handle) {
|
|||||||
for (uint8_t minuteBufferIdx = 0; minuteBufferIdx < NUM_OF_MINUTE_BUFFERS; minuteBufferIdx++) {
|
for (uint8_t minuteBufferIdx = 0; minuteBufferIdx < NUM_OF_MINUTE_BUFFERS; minuteBufferIdx++) {
|
||||||
t_minuteBuffer *minuteBuffer = &(minuteBuffers[minuteBufferIdx]);
|
t_minuteBuffer *minuteBuffer = &(minuteBuffers[minuteBufferIdx]);
|
||||||
|
|
||||||
if (minuteBuffer->s.done == 1) {
|
if (minuteBufferReady[minuteBufferIdx] == 1) {
|
||||||
coloredMsg(LOG_BLUE, "cmt, buffer %d is done, handle it", minuteBufferIdx);
|
coloredMsg(LOG_BLUE, "cmt, buffer %d is done, handle it", minuteBufferIdx);
|
||||||
memset(minuteBuffer->s.deviceId, 0, sizeof(minuteBuffer->s.deviceId));
|
memset(minuteBuffer->s.deviceId, 0, sizeof(minuteBuffer->s.deviceId));
|
||||||
strcpy(minuteBuffer->s.deviceId, config->deviceId);
|
strcpy(minuteBuffer->s.deviceId, config->deviceId);
|
||||||
@ -116,7 +117,7 @@ void counterMinuteTick(void *handle) {
|
|||||||
int8_t res = counterSendMinuteBuffer(minuteBuffer);
|
int8_t res = counterSendMinuteBuffer(minuteBuffer);
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
coloredMsg(LOG_BLUE, "cmt, successfully sent");
|
coloredMsg(LOG_BLUE, "cmt, successfully sent");
|
||||||
minuteBuffer->s.done = 0;
|
minuteBufferReady[minuteBufferIdx] = false;
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_BLUE, "cmt, not successfully sent, try again");
|
coloredMsg(LOG_BLUE, "cmt, not successfully sent, try again");
|
||||||
schAdd(counterMinuteTick, NULL, 1000, 0);
|
schAdd(counterMinuteTick, NULL, 1000, 0);
|
||||||
@ -145,16 +146,18 @@ void counterSecondTick(void *handle) {
|
|||||||
|
|
||||||
if (! seconds->valid) {
|
if (! seconds->valid) {
|
||||||
coloredMsg(LOG_RED, "cst, time is not yet valid");
|
coloredMsg(LOG_RED, "cst, time is not yet valid");
|
||||||
} else if (minuteBuffers[activeMinuteBuffer].s.done == 1) {
|
} else if (minuteBufferReady[activeMinuteBuffer]) {
|
||||||
coloredMsg(LOG_RED, "cst, minute buffer overrun");
|
coloredMsg(LOG_RED, "cst, minute buffer overrun");
|
||||||
} else {
|
} else {
|
||||||
minuteBuffers[activeMinuteBuffer].s.events[bufferIdx].timestamp = seconds->seconds;
|
if (bufferIdx == 0) {
|
||||||
minuteBuffers[activeMinuteBuffer].s.events[bufferIdx].frequency = freq;
|
minuteBuffers[activeMinuteBuffer].s.timestamp = seconds->seconds;
|
||||||
|
}
|
||||||
|
minuteBuffers[activeMinuteBuffer].s.frequency[bufferIdx] = freq;
|
||||||
coloredMsg(LOG_GREEN, "cst, added to buffer %d, slot %d", activeMinuteBuffer, bufferIdx);
|
coloredMsg(LOG_GREEN, "cst, added to buffer %d, slot %d", activeMinuteBuffer, bufferIdx);
|
||||||
bufferIdx += 1;
|
bufferIdx += 1;
|
||||||
if (bufferIdx == SECONDS_PER_MINUTE) {
|
if (bufferIdx == SECONDS_PER_MINUTE) {
|
||||||
coloredMsg(LOG_GREEN, "cst, buffer %d is done", activeMinuteBuffer);
|
coloredMsg(LOG_GREEN, "cst, buffer %d is done", activeMinuteBuffer);
|
||||||
minuteBuffers[activeMinuteBuffer].s.done = 1;
|
minuteBufferReady[activeMinuteBuffer] = true;
|
||||||
activeMinuteBuffer += 1;
|
activeMinuteBuffer += 1;
|
||||||
bufferIdx = 0;
|
bufferIdx = 0;
|
||||||
if (activeMinuteBuffer >= NUM_OF_MINUTE_BUFFERS) {
|
if (activeMinuteBuffer >= NUM_OF_MINUTE_BUFFERS) {
|
||||||
@ -188,8 +191,11 @@ void mainsCntsInputCaptureCallback(TIM_HandleTypeDef *htim) {
|
|||||||
|
|
||||||
void counterInit() {
|
void counterInit() {
|
||||||
seconds = wizGetSeconds();
|
seconds = wizGetSeconds();
|
||||||
minuteBuffers[0].s.done = 0;
|
for (uint8_t i = 0; i < NUM_OF_MINUTE_BUFFERS; i++) {
|
||||||
minuteBuffers[1].s.done = 0;
|
minuteBufferReady[i] = false;
|
||||||
|
}
|
||||||
|
activeMinuteBuffer = 0;
|
||||||
|
|
||||||
|
|
||||||
config = getConfig();
|
config = getConfig();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user