prepare buffer
This commit is contained in:
@ -5,8 +5,8 @@ LDFLAGS=-lwiringPi -lconfig
|
|||||||
|
|
||||||
INST_DIR=/opt/sbin
|
INST_DIR=/opt/sbin
|
||||||
|
|
||||||
REFCNT:=$(shell git rev-list --all --count)
|
REFCNT := $(shell git rev-list --all --count)
|
||||||
VERSION:=$(shell cat VERSION)
|
VERSION := $(shell git rev-parse --short=8 HEAD)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: counter
|
all: counter
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include "sinkSender.h"
|
#include "sinkSender.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
@ -23,6 +24,8 @@ const char *sharedSecret;
|
|||||||
static t_minuteBuffer minuteBuffer;
|
static t_minuteBuffer minuteBuffer;
|
||||||
static uint32_t secondOfMinute;
|
static uint32_t secondOfMinute;
|
||||||
|
|
||||||
|
extern char VERSION[];
|
||||||
|
|
||||||
|
|
||||||
void sinkSenderInit(config_t *pCfg) {
|
void sinkSenderInit(config_t *pCfg) {
|
||||||
if (! config_lookup_string(pCfg, SINKSERVER_KEY, &sinkServer)) {
|
if (! config_lookup_string(pCfg, SINKSERVER_KEY, &sinkServer)) {
|
||||||
@ -54,9 +57,29 @@ void sinkSenderPut(uint32_t seconds, uint32_t frequency) {
|
|||||||
minuteBuffer.s.timestamp = seconds;
|
minuteBuffer.s.timestamp = seconds;
|
||||||
}
|
}
|
||||||
minuteBuffer.s.frequency[secondOfMinute] = frequency;
|
minuteBuffer.s.frequency[secondOfMinute] = frequency;
|
||||||
|
secondOfMinute += 1;
|
||||||
|
|
||||||
|
if (secondOfMinute == SECONDS_PER_MINUTE) {
|
||||||
|
logmsg(LOG_DEBUG, "minute is full");
|
||||||
|
|
||||||
|
minuteBuffer->s.totalRunningHours = 0;
|
||||||
|
minuteBuffer->s.totalPowercycles = 0;
|
||||||
|
minuteBuffer->s.totalWatchdogResets = 0;
|
||||||
|
minuteBuffer->s.version = strtol(VERSION, NULL, 16);
|
||||||
|
|
||||||
|
memset(minuteBuffer->s.deviceId, 0, sizeof(minuteBuffer->s.deviceId));
|
||||||
|
strcpy(minuteBuffer->s.deviceId, config->deviceId);
|
||||||
|
|
||||||
|
memcpy(minuteBuffer->s.hash, config->sharedSecret, SHA256_BLOCK_SIZE);
|
||||||
|
SHA256_CTX ctx;
|
||||||
|
sha256_init(&ctx);
|
||||||
|
sha256_update(&ctx, minuteBuffer->b, sizeof(minuteBuffer->b));
|
||||||
|
sha256_final(&ctx, minuteBuffer->s.hash);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
led(E_GREEN, true);
|
led(E_GREEN, true);
|
||||||
}
|
}
|
Reference in New Issue
Block a user