25 Commits

Author SHA1 Message Date
57fa805851 start wifi stuff 2021-02-25 15:00:56 +01:00
b6127854e0 fix for wifi 2021-02-25 10:34:12 +01:00
b272c6a2d0 time request every five minutes 2021-02-24 23:22:32 +01:00
685082ae03 duration of time request 2021-02-24 23:21:28 +01:00
081256eb51 sntp 2021-02-24 19:45:50 +01:00
5e03f5e1a3 enable counter 2021-02-24 19:39:01 +01:00
f220e15afe sntp problem 2021-02-24 19:35:53 +01:00
f16b38ffd5 Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mains-frequency-counter-stm32 into master 2021-02-22 10:47:36 +01:00
1dd4d35530 modem stuff 2021-02-19 21:21:08 +01:00
e499c6607b fix 2021-02-19 11:03:59 +01:00
12d8f9a9fe modem stuff 2021-02-18 17:33:42 +01:00
84f58a343e modem stuff 2021-02-18 17:32:15 +01:00
1f124976e7 code generated 2021-02-18 17:10:16 +01:00
9c4a5d7a01 Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mains-frequency-counter-stm32 2021-02-18 17:08:46 +01:00
9ec3d165a4 modem lines 2021-02-18 17:08:38 +01:00
f141e8bf0d start configmaker 2021-02-17 18:15:48 +01:00
62a5a1bc70 version in sink 2021-02-16 13:22:59 +01:00
7af317f768 version 2021-02-16 13:20:52 +01:00
d1e54da7aa version 2021-02-16 13:20:29 +01:00
baaf7bf665 version 2021-02-16 13:19:31 +01:00
901b2fbea4 version 2021-02-16 13:14:49 +01:00
5d8567a206 forgotten resolves 2021-02-16 13:11:03 +01:00
a09024c6a2 forgotten resolves 2021-02-16 13:09:50 +01:00
b6439e7df3 merged 2021-02-16 13:08:39 +01:00
f58538ab79 rearrange configblock 2021-02-16 12:09:08 +01:00
26 changed files with 809 additions and 79 deletions

1
configmaker/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

40
configmaker/Makefile Normal file
View File

@ -0,0 +1,40 @@
BUILD_DIR = build
C_SOURCES = \
configmaker.c
C_INCLUDES = \
-I. \
-I../cube/User/Inc
VERSION := $(shell git rev-parse --short=8 HEAD)
CC = gcc
CFLAGS = $(C_INCLUDES) -Wall -Werror -std=c99 -DVERSION="\"$(VERSION)\""
LDFLAGS = -lconfig
TARGET = configmaker
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
CFLAGS += -I/usr/local/include -DOpenBSD=1
LDFLAGS += -L/usr/local/lib
endif
all: $(BUILD_DIR)/$(TARGET)
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(BUILD_DIR):
mkdir $@
.phony: clean
clean:
-rm -rf $(BUILD_DIR)

391
configmaker/configmaker.c Normal file
View File

@ -0,0 +1,391 @@
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <getopt.h>
#include <libconfig.h>
#include <sinkStruct.h>
#include <sha256.h>
const char DEFAULT_CONFIG_FILENAME[] = "./configmaker.cfg";
typedef struct {
uint32_t eepromMagic;
uint32_t configMagic;
uint8_t macAddress[6];
char deviceName[16];
char deviceId[16];
uint8_t sharedSecret[32];
char ntpServer[48];
char sinkServer[48];
} t_configHandle;
t_configHandle configHandle;
int initConfig(const char *configFilename, t_configHandle *configHandle) {
config_init(&(configHandle->cfg));
if (! config_read_file(&(configHandle->cfg), configFilename)) {
logmsg(LOG_ERR, "failed to read config file: %s:%d - %s\n",
config_error_file(&(configHandle->cfg)), config_error_line(&(configHandle->cfg)),
config_error_text(&(configHandle->cfg)));
config_destroy(&(configHandle->cfg));
return -1;
}
config_setting_t *devicesConfig = config_lookup(&(configHandle->cfg), "devices");
if (devicesConfig == NULL) {
logmsg(LOG_ERR, "receiver: no devices configuration found");
return -2;
}
configHandle->numOfDevices = config_setting_length(devicesConfig);
configHandle->devices = (t_device*) malloc(configHandle->numOfDevices * sizeof(t_device));
for (uint16_t i = 0; i < configHandle->numOfDevices; i++) {
config_setting_t *deviceConfig = config_setting_get_elem(devicesConfig, i);
if (! config_setting_lookup_string(deviceConfig, "deviceId", &(configHandle->devices[i].deviceId))) {
logmsg(LOG_ERR, "no deviceId for device %d", i);
return -3;
}
if (! config_setting_lookup_string(deviceConfig, "location", &(configHandle->devices[i].location))) {
logmsg(LOG_ERR, "no location for device %d", i);
return -4;
}
if (! config_setting_lookup_string(deviceConfig, "sharedSecret", &(configHandle->devices[i].sharedSecret))) {
logmsg(LOG_ERR, "no sharedSecret for device %d", i);
return -5;
}
if (strlen(configHandle->devices[i].sharedSecret) >= SHA256_BLOCK_SIZE) {
logmsg(LOG_ERR, "Configured sharedsecret for device %d is too long", i);
return -6;
}
logmsg(LOG_INFO, "Device loaded: %d %s %s %s", i,
configHandle->devices[i].deviceId,
configHandle->devices[i].location,
configHandle->devices[i].sharedSecret);
}
return 0;
}
void deinitConfig(t_configHandle *configHandle) {
config_destroy(&(configHandle->cfg));
if (configHandle->devices) {
free(configHandle->devices);
configHandle->devices = NULL;
}
}
t_device *findDevice(t_configHandle *configHandle, char *deviceId) {
for (uint16_t i = 0; i < configHandle->numOfDevices; i++) {
if (! strcmp(configHandle->devices[i].deviceId, deviceId)) {
return &(configHandle->devices[i]);
}
}
return NULL;
}
int initReceiver(t_configHandle *configHandle, t_receiverHandle *handle) {
handle->configHandle = configHandle;
struct sockaddr_in servaddr;
handle->receiveSockFd = socket(AF_INET, SOCK_DGRAM, 0);
if (handle->receiveSockFd == -1) {
logmsg(LOG_ERR, "failed to create receive socket: %d", errno);
return -1;
}
int receivePort = 20169;
config_lookup_int(&(configHandle->cfg), "receivePort", &receivePort);
if (receivePort < 1 || receivePort > 65535) {
logmsg(LOG_ERR, "illegal receive port configured");
return -2;
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(receivePort);
if (-1 == bind(handle->receiveSockFd, (const struct sockaddr *) &servaddr, sizeof(servaddr))) {
logmsg(LOG_ERR, "unable to bind receive: %d", errno);
return -3;
}
return 0;
}
void deinitReceiver(t_receiverHandle *handle) {
close(handle->receiveSockFd);
}
int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf) {
struct sockaddr_in cliaddr;
socklen_t cliaddrlen = sizeof(cliaddr);
int n = recvfrom(handle->receiveSockFd, buf->b, sizeof(buf->b), MSG_TRUNC,
(struct sockaddr *) &cliaddr, &cliaddrlen);
logmsg(LOG_INFO, "received %d octets from %d.%d.%d.%d",
n,
(cliaddr.sin_addr.s_addr & 0x0ff),
((cliaddr.sin_addr.s_addr >> 8) & 0x0ff),
((cliaddr.sin_addr.s_addr >> 16) & 0x0ff),
((cliaddr.sin_addr.s_addr >> 24) & 0x0ff));
if (n != sizeof(buf->b)) {
logmsg(LOG_INFO, "Illegal packet size: %d", n);
return -1;
}
t_device *device = findDevice(handle->configHandle, buf->s.deviceId);
const char *sharedSecret = device->sharedSecret;
uint8_t receivedHash[SHA256_BLOCK_SIZE];
memcpy(receivedHash, buf->s.hash, SHA256_BLOCK_SIZE);
memcpy(buf->s.hash, sharedSecret, SHA256_BLOCK_SIZE);
SHA256_CTX ctx;
uint8_t calculatedHash[SHA256_BLOCK_SIZE];
sha256_init(&ctx);
sha256_update(&ctx, buf->b, sizeof(buf->b));
sha256_final(&ctx, calculatedHash);
if (memcmp(receivedHash, calculatedHash, SHA256_BLOCK_SIZE) != 0) {
logmsg(LOG_INFO, "Invalid hash in msg for device %s", buf->s.deviceId);
return -5;
}
return 0;
}
int initForwarder(t_configHandle *configHandle, t_forwarderHandle *handle) {
handle->configHandle = configHandle;
handle->influxUser = NULL;
handle->influxPass = NULL;
handle->influxServer = NULL;
handle->influxDatabase = NULL;
handle->influxMeasurement = NULL;
config_lookup_string(&(configHandle->cfg), "influxUser", &(handle->influxUser));
config_lookup_string(&(configHandle->cfg), "influxPass", &(handle->influxPass));
config_lookup_string(&(configHandle->cfg), "influxServer", &(handle->influxServer));
config_lookup_string(&(configHandle->cfg), "influxDatabase", &(handle->influxDatabase));
config_lookup_string(&(configHandle->cfg), "influxMeasurement", &(handle->influxMeasurement));
int influxPort = 8086;
config_lookup_int(&(configHandle->cfg), "influxPort", &influxPort);
if (influxPort < 1 || influxPort > 65535) {
logmsg(LOG_ERR, "illegal influx port configured");
return -2;
}
handle->influxPort = influxPort;
if (! handle->influxServer) {
logmsg(LOG_ERR, "no influxServer configured");
return -1;
}
if (! handle->influxDatabase) {
logmsg(LOG_ERR, "no influxDatabase configured");
return -2;
}
if (! handle->influxMeasurement) {
logmsg(LOG_ERR, "no influxMeasurement configured");
return -3;
}
int res = snprintf(handle->influxUrl, sizeof(handle->influxUrl),
"http://%s:%d/write?db=%s&precision=s",
handle->influxServer, handle->influxPort, handle->influxDatabase);
if (res > sizeof(handle->influxUrl)) {
logmsg(LOG_ERR, "influxUrl has not enough space");
return -4;
}
logmsg(LOG_INFO, "influxUrl is %s", handle->influxUrl);
return 0;
}
void deinitForwarder(t_forwarderHandle *handle) {
}
int httpPostRequest(char *url, const char *user, const char *pass, char *payload) {
CURL *curl = curl_easy_init();
if (! curl) {
logmsg(LOG_ERR, "error instantiating curl");
return -1;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
if (user && pass) {
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_USERNAME, user);
curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
logmsg(LOG_ERR, "post request failed: %s", curl_easy_strerror(res));
return -2;
}
curl_easy_cleanup(curl);
return 0;
}
int forwardMinuteBuffer(t_forwarderHandle *handle, t_minuteBuffer *buf) {
logmsg(LOG_INFO, "DeviceId: %s", buf->s.deviceId);
t_device *device = findDevice(handle->configHandle, buf->s.deviceId);
const char *location = device->location;
for (uint8_t j = 0; j < SECONDS_PER_MINUTE; j++) {
logmsg(LOG_DEBUG, "Time: %lu, Frequency: %u", buf->s.events[j].timestamp, buf->s.events[j].frequency);
int frequency_before_point = buf->s.events[j].frequency / 1000;
int frequency_behind_point = buf->s.events[j].frequency - (frequency_before_point * 1000);
char payload[256];
int res = snprintf(payload, sizeof(payload),
"%s,valid=1,location=%s,host=%s freq=%d.%03d"
#ifdef OpenBSD
" %llu"
#else
" %lu"
#endif
"",
handle->influxMeasurement, location, buf->s.deviceId,
frequency_before_point, frequency_behind_point,
buf->s.events[j].timestamp);
if (res > sizeof(payload)) {
logmsg(LOG_ERR, "payload buffer to small");
return -1;
}
logmsg(LOG_DEBUG, "Payload: %s", payload);
res = httpPostRequest(handle->influxUrl, handle->influxUser, handle->influxPass, payload);
if (res == 0) {
logmsg(LOG_DEBUG, "Successfully sent to InfluxDB");
}
}
logmsg(LOG_INFO, "Successfully sent whole minute to InfluxDB");
return 0;
}
void usage() {
printf("sinkserver for mainsfrequency counter\n");
printf("https://home.hottis.de/gitlab/wolutator/mains-frequency-counter-stm32\n");
printf("Version: " VERSION "\n");
printf("\nUsage\n");
printf(" -f FILENAME R..... Config file to be used\n");
printf(" -v ............... Verbose, writes all logging on stdout too\n");
printf(" -s FACILITY ...... Sets syslog facility, only LOCAL[0..7]\n");
printf(" USER and DAEMON are supported\n");
printf(" -n USER .......... If started as root drop privileges and become\n");
printf(" USER\n");
printf(" -b ............... fork into background\n");
printf(" -h ............... This help\n");
}
int main(int argc, char **argv) {
t_configHandle configHandle;
t_forwarderHandle forwarderHandle;
t_receiverHandle receiverHandle;
const char *configFilename = DEFAULT_CONFIG_FILENAME;
const char *dropPrivilegesToUser = NULL;
bool doFork = false;
int c;
while ((c = getopt(argc, argv, "f:vs:hn:b")) != -1) {
switch (c) {
case 'f':
configFilename = strdup(optarg);
break;
case 'v':
verbose = true;
break;
case 's':
setfacility(optarg);
break;
case 'n':
dropPrivilegesToUser = strdup(optarg);
break;
case 'b':
doFork = true;
break;
case 'h':
usage();
exit(0);
break;
}
}
if ((getuid() == 0) && (dropPrivilegesToUser != NULL)) {
logmsg(LOG_INFO, "dropping root privileges, become %s", dropPrivilegesToUser);
struct passwd *userEntry = getpwnam(dropPrivilegesToUser);
if (userEntry == NULL) {
logmsg(LOG_ERR, "can not find entry for user %s", dropPrivilegesToUser);
exit(1);
}
if (setuid(userEntry->pw_uid) != 0) {
logmsg(LOG_ERR, "unable to drop root privileges to %d", userEntry->pw_uid);
exit(2);
}
}
if (0 != initConfig(configFilename, &configHandle)) {
logmsg(LOG_ERR, "error when reading configuration");
exit(3);
}
if (doFork) {
int pid = fork();
if (pid == -1) {
logmsg(LOG_ERR, "error when forking into background: %d", errno);
exit(4);
}
if (pid != 0) {
logmsg(LOG_INFO, "successfully forking into background, child's pid is %d", pid);
exit(0);
}
}
if (0 != initReceiver(&configHandle, &receiverHandle)) {
logmsg(LOG_ERR, "error when initializing receiver");
exit(5);
}
if (0 != initForwarder(&configHandle, &forwarderHandle)) {
logmsg(LOG_ERR, "error when initializing forwarder");
exit(6);
}
while (1) {
t_minuteBuffer buf;
if (receiveAndVerifyMinuteBuffer(&receiverHandle, &buf) < 0) {
logmsg(LOG_ERR, "error in receiveAndVerify");
continue;
}
if (forwardMinuteBuffer(&forwarderHandle, &buf) < 0) {
logmsg(LOG_ERR, "error in send");
}
}
deinitForwarder(&forwarderHandle);
deinitReceiver(&receiverHandle);
deinitConfig(&configHandle);
}

View File

@ -0,0 +1,21 @@
eepromMagic = 0xaffe000b;
configMagic = 0xdead0007;
macAddress = 0x...........;
# max 16 octets
deviceName = "MainsCnt01";
# max 16 octets
deviceId = "MainsCnt01";
# exactly 31 octets
sharedSecret = "5DVYZoB3TwGoFoLAPF8S8EkgURLPqjY";
# max 48 octets
ntpServer = "pool.ntp.org";
# max 48 octets
sinkServer = "sink.hottis.de";

View File

@ -61,6 +61,7 @@ void Error_Handler(void);
#define eepromSpi hspi1
#define etherSpi hspi2
#define debugUart huart1
#define modemUart huart2
#define mainsCnt htim1
#define LED_Red_Pin GPIO_PIN_13
#define LED_Red_GPIO_Port GPIOC
@ -68,6 +69,12 @@ void Error_Handler(void);
#define LED_Green_GPIO_Port GPIOC
#define LED_Blue_Pin GPIO_PIN_15
#define LED_Blue_GPIO_Port GPIOC
#define MODEM_RES_Pin GPIO_PIN_1
#define MODEM_RES_GPIO_Port GPIOA
#define MODEM_TX_Pin GPIO_PIN_2
#define MODEM_TX_GPIO_Port GPIOA
#define MODEM_RX_Pin GPIO_PIN_3
#define MODEM_RX_GPIO_Port GPIOA
#define EEPROM_CS_Pin GPIO_PIN_4
#define EEPROM_CS_GPIO_Port GPIOA
#define EEPROM_SCK_Pin GPIO_PIN_5

View File

@ -31,12 +31,14 @@
/* USER CODE END Includes */
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_USART1_UART_Init(void);
void MX_USART2_UART_Init(void);
/* USER CODE BEGIN Prototypes */

View File

@ -52,7 +52,7 @@ void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOC, LED_Red_Pin|LED_Green_Pin|LED_Blue_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, MODEM_RES_Pin|EEPROM_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, ETHER_RES_Pin|ETHER_CS_Pin|Debug_Signal_2_Pin|Debug_Signal_1_Pin, GPIO_PIN_RESET);
@ -64,12 +64,12 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = EEPROM_CS_Pin;
/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = MODEM_RES_Pin|EEPROM_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(EEPROM_CS_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = ADMIN_MODE_Pin;

View File

@ -99,6 +99,7 @@ int main(void)
MX_TIM1_Init();
MX_USART1_UART_Init();
MX_IWDG_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
my_setup_2();

View File

@ -94,6 +94,7 @@ int main(void)
MX_TIM1_Init();
MX_USART1_UART_Init();
MX_IWDG_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */

View File

@ -25,6 +25,7 @@
/* USER CODE END 0 */
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
/* USART1 init function */
@ -44,6 +45,25 @@ void MX_USART1_UART_Init(void)
Error_Handler();
}
}
/* USART2 init function */
void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
@ -80,6 +100,33 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
/* USER CODE END USART1_MspInit 1 */
}
else if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/* USART2 clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = MODEM_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(MODEM_TX_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = MODEM_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MODEM_RX_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
@ -105,6 +152,24 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
/* USER CODE END USART1_MspDeInit 1 */
}
else if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspDeInit 0 */
/* USER CODE END USART2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOA, MODEM_TX_Pin|MODEM_RX_Pin);
/* USER CODE BEGIN USART2_MspDeInit 1 */
/* USER CODE END USART2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */

View File

@ -26,6 +26,9 @@ ifndef NETWORK
$(error NETWORK is not set)
endif
VERSION := $(shell git rev-parse --short=8 HEAD)
######################################
# target
######################################
@ -94,11 +97,14 @@ C_SOURCES += \
User/Src/ports.c \
User/Src/wizHelper.c \
User/Src/networkAbstractionLayer_lan.c
NETWORK_STACK=1
endif
ifeq ($(NETWORK), WiFi)
C_SOURCES += \
User/Src/networkAbstractionLayer_wifi.c
User/Src/networkAbstractionLayer_wifi.c \
User/Src/modemCom.c
NETWORK_STACK=2
endif
# ASM sources
@ -178,7 +184,7 @@ endif
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -DNETWORK=$(NETWORK) -Wall -Werror -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -DNETWORK_STACK=$(NETWORK_STACK) -DVERSION="\"$(VERSION)\"" -Wall -Werror -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2

View File

@ -1,7 +1,11 @@
# Processed by ../tools/insertMyCode.sh
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sat Feb 13 18:28:59 CET 2021]
##########################################################################################################################
# FILE NOT LONGER UNDER CONTROL OF THE GENERATOR BUT MANUALLY MAINTAINED, 2020-02-16 #
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
@ -10,6 +14,21 @@
# 2015-07-22 - first version
# ------------------------------------------------
# Network implementations, to be set on commandline
# LAN
# WiFi
# GSM
# NETWORK = LAN
ifndef NETWORK
$(error NETWORK is not set)
endif
VERSION := $(shell git rev-parse --short=8 HEAD)
######################################
# target
######################################
@ -35,35 +54,58 @@ BUILD_DIR = build
# source
######################################
# C sources
C_SOURCES = \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/iwdg.c \
Core/Src/spi.c \
Core/Src/tim.c \
Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
C_SOURCES = \
User/Src/config.c \
User/Src/counter.c \
User/Src/eeprom.c \
User/Src/logger.c \
User/Src/main2.c \
User/Src/ringbuffer.c \
User/Src/sha256.c \
User/Src/show.c \
User/Src/utils.c \
User/Src/networkAbstractionLayer.c \
hottislib/PontCoopScheduler.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/iwdg.c \
Core/Src/spi.c \
Core/Src/tim.c \
Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
Core/Src/system_stm32f1xx.c
ifeq ($(NETWORK), LAN)
C_SOURCES += \
User/Src/ports.c \
User/Src/wizHelper.c \
User/Src/networkAbstractionLayer_lan.c
endif
ifeq ($(NETWORK), WiFi)
C_SOURCES += \
User/Src/networkAbstractionLayer_wifi.c
endif
# ASM sources
ASM_SOURCES = \
ASM_SOURCES = \
startup_stm32f103xb.s
@ -107,8 +149,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F103xB
@ -116,19 +158,30 @@ C_DEFS = \
AS_INCLUDES =
# C includes
C_INCLUDES = \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \
C_INCLUDES = \
-Ihottislib \
-IUser/Inc \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \
-IDrivers/CMSIS/Include
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(NETWORK), LAN)
C_INCLUDES += \
-IioLibrary_Driver/Internet/SNTP \
-IioLibrary_Driver/Internet/DNS \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Ethernet
endif
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -DNETWORK=$(NETWORK) -DVERSION="\"$(VERSION)\"" -Wall -Werror -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
@ -148,7 +201,7 @@ LDSCRIPT = STM32F103C8Tx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
@ -160,10 +213,20 @@ all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
ifeq ($(NETWORK), LAN)
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a)
endif
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
ifeq ($(NETWORK), LAN)
$(BUILD_DIR)/w5500.a:
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
endif
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
@ -194,4 +257,4 @@ clean:
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
# *** EOF ***

16
cube/User/Inc/modemCom.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _MODEM_COM_H_
#define _MODEM_COM_H_
#include <usart.h>
#if NETWORK_STACK == 2 // WiFi
void modemTxCpltCallback(UART_HandleTypeDef *huart);
void modemRxCpltCallback(UART_HandleTypeDef *huart);
#endif
#endif // _MODEM_COM_H_

View File

@ -17,4 +17,5 @@ t_seconds* networkGetSeconds();
int8_t networkSendMinuteBuffer(t_minuteBuffer *minuteBuffer);
#endif /* _NETWORK_ABSTRACTION_LAYER_H_ */

View File

@ -7,4 +7,5 @@ uint64_t networkSntpQuery();
int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufLen);
void networkImplInit();
#endif /* _NETWORK_ABSTRACTION_LAYER_IMPL_H_ */

View File

@ -12,6 +12,7 @@ typedef struct __attribute__((__packed__)) {
uint32_t totalRunningHours;
uint32_t totalPowercycles;
uint32_t totalWatchdogResets;
uint32_t version;
uint64_t timestamp;
uint32_t frequency[SECONDS_PER_MINUTE];
} t_minuteStruct;

View File

@ -14,8 +14,7 @@ t_configBlock defaultConfigBlock = {
.ntpServer = "0.de.pool.ntp.org",
.deviceId = "MainsCnt01",
.sharedSecret = "sharedSecretGanzGeheim",
.sinkServer = "laborpc",
.filler = { 0 }
.sinkServer = "laborpc"
};

View File

@ -1,5 +1,6 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <tim.h>
@ -47,6 +48,8 @@ void counterMinuteTick(void *handle) {
minuteBuffer->s.totalRunningHours = deviceStats->totalRunningHours;
minuteBuffer->s.totalPowercycles = deviceStats->totalPowercycles;
minuteBuffer->s.totalWatchdogResets = deviceStats->totalWatchdogResets;
minuteBuffer->s.version = strtol(VERSION, NULL, 16);
memset(minuteBuffer->s.deviceId, 0, sizeof(minuteBuffer->s.deviceId));
strcpy(minuteBuffer->s.deviceId, config->deviceId);

View File

@ -17,6 +17,9 @@
#include <config.h>
#include <counter.h>
#if NETWORK_STACK == 2
#include <modemCom.h>
#endif
@ -35,6 +38,7 @@ void my_setup_2() {
show(LED_RED, OFF);
show(LED_GREEN, BLINK);
logMsg("Application starting");
logMsg("Version: " VERSION);
eepromInit();
@ -67,8 +71,24 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
debugTxCpltCallback(huart);
}
#endif //LOGGER_OUTPUT_BY_INTERRUPT
#if NETWORK_STACK == 2
if (huart == &modemUart) {
modemTxCpltCallback(huart);
}
#endif
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
#if NETWORK_STACK == 2
if (huart == &modemUart) {
modemRxCpltCallback(huart);
}
#endif
}
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
if (hspi == &eepromSpi) {
eepromSpiTxCpltCallback(hspi);

62
cube/User/Src/modemCom.c Normal file
View File

@ -0,0 +1,62 @@
#include <modemCom.h>
#include <main.h>
#include <usart.h>
void modemISR() {
uint32_t isrflags = READ_REG(modemUart.Instance->SR);
uint32_t cr1its = READ_REG(modemUart.Instance->CR1);
// RXNEIE doesn't need to be considered since it is always on and more over the
// RXNE flag is cleared by reading the DR, which is done in any case
if (((isrflags & USART_SR_RXNE) != RESET) || ((isrflags & (USART_SR_ORE | USART_SR_FE | USART_SR_PE | USART_SR_NE)) != RESET)) {
// Error flags are only valid together with the RX flag.
// They will be cleared by reading SR (already done above) followed by reading DR (below).
bool errorFound = false;
if ((isrflags & USART_SR_ORE) != RESET) {
mbusCommStats.uartOverrunCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_FE) != RESET) {
mbusCommStats.uartFramingErrCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_PE) != RESET) {
mbusCommStats.uartParityErrCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_NE) != RESET) {
mbusCommStats.uartNoiseErrCnt += 1;
errorFound = true;
}
mbusCommStats.uartOctetCnt += 1;
// it is required to read the DR in any case here, not only when the buffer has space
// otherwise the interrupt flag won't be reset, particularly important in case of ORE
uint8_t data = (uint8_t)(mbusUart.Instance->DR & (uint8_t)0x00FF);
if ((! errorFound) &&
(mbusCommHandle.receiveBuffer.writeIdx < mbusCommHandle.receiveBuffer.size)) {
mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.writeIdx] = data;
mbusCommHandle.receiveBuffer.writeIdx += 1;
}
}
// TXEIE needs to be considered since TXE is cleared by writing the DR, which isn't done
// after the last octet sent
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) {
if (mbusCommHandle.sendBuffer.readIdx < mbusCommHandle.sendBuffer.writeIdx) {
mbusUart.Instance->DR = mbusCommHandle.sendBuffer.buffer[mbusCommHandle.sendBuffer.readIdx];
mbusCommHandle.sendBuffer.readIdx += 1;
if (mbusCommHandle.sendBuffer.readIdx == mbusCommHandle.sendBuffer.writeIdx) {
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TXE);
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TC);
}
}
}
// advance the state for the engine only when the last octet is shifted out completely
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) {
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TC);
mbusCommHandle.state = MBCS_SENDING_DONE;
}
}

View File

@ -31,7 +31,7 @@ static void networkSecondsHandler(void *handle) {
coloredMsg(LOG_YELLOW, "nsh, failed");
seconds.missedUpdates += 1;
}
} else if (tryAgain || ((seconds.seconds % 3600) == 0)) {
} else if (tryAgain || ((seconds.seconds % 300) == 0)) {
coloredMsg(LOG_YELLOW, "nsh, periodically querying time");
uint64_t tmpSeconds = networkSntpQuery();
if (tmpSeconds != 0) {

View File

@ -1,8 +1,9 @@
#include <networkAbstractionLayer_impl.h>
#include <logger.h>
#include <utils.h>
#include <stdint.h>
#include <main.h>
uint64_t networkSntpQuery() {
@ -15,5 +16,7 @@ int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufL
}
void networkImplInit() {
HAL_GPIO_WritePin(MODEM_RES_GPIO_Port, MODEM_RES_Pin, GPIO_PIN_RESET);
activeDelay(255);
HAL_GPIO_WritePin(MODEM_RES_GPIO_Port, MODEM_RES_Pin, GPIO_PIN_SET);
}

View File

@ -142,12 +142,16 @@ uint64_t wizSntpQuery() {
uint8_t ntpServer[4];
if (wizDnsQuery(config->ntpServer, ntpServer)) {
SNTP_init(SNTP_SOCK, ntpServer, 0, sntpBuffer);
for (uint8_t i = 0; i < 16; i++) {
uint16_t cycles = 0;
uint32_t startTime = HAL_GetTick();
while (1) {
cycles += 1;
datetime curTime;
int8_t res = SNTP_run(&curTime);
if (res == 1) {
if (1 == SNTP_run(&curTime)) {
seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF;
coloredMsg(LOG_BLUE, "wizsq, curTime: %lu", seconds);
coloredMsg(LOG_BLUE, "wizsq, cycles: %u, curTime: %lu", cycles, seconds);
uint32_t stopTime = HAL_GetTick();
coloredMsg(LOG_BLUE, "wizsq, duration: %u ms", stopTime - startTime);
break;
}
}

View File

@ -1,6 +1,6 @@
#MicroXplorer Configuration settings - do not modify
File.Version=6
GPIO.groupedBy=
GPIO.groupedBy=Group By Peripherals
IWDG.IPParameters=Prescaler
IWDG.Prescaler=IWDG_PRESCALER_256
KeepUserPlacement=false
@ -13,35 +13,39 @@ Mcu.IP4=SPI2
Mcu.IP5=SYS
Mcu.IP6=TIM1
Mcu.IP7=USART1
Mcu.IPNb=8
Mcu.IP8=USART2
Mcu.IPNb=9
Mcu.Name=STM32F103C(8-B)Tx
Mcu.Package=LQFP48
Mcu.Pin0=PC13-TAMPER-RTC
Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PB11
Mcu.Pin11=PB12
Mcu.Pin12=PB13
Mcu.Pin13=PB14
Mcu.Pin14=PB15
Mcu.Pin15=PA8
Mcu.Pin16=PA9
Mcu.Pin17=PA10
Mcu.Pin18=PA12
Mcu.Pin19=PA13
Mcu.Pin10=PA6
Mcu.Pin11=PA7
Mcu.Pin12=PB10
Mcu.Pin13=PB11
Mcu.Pin14=PB12
Mcu.Pin15=PB13
Mcu.Pin16=PB14
Mcu.Pin17=PB15
Mcu.Pin18=PA8
Mcu.Pin19=PA9
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=PA14
Mcu.Pin21=PB5
Mcu.Pin22=PB6
Mcu.Pin23=VP_IWDG_VS_IWDG
Mcu.Pin24=VP_SYS_VS_Systick
Mcu.Pin20=PA10
Mcu.Pin21=PA12
Mcu.Pin22=PA13
Mcu.Pin23=PA14
Mcu.Pin24=PB5
Mcu.Pin25=PB6
Mcu.Pin26=VP_IWDG_VS_IWDG
Mcu.Pin27=VP_SYS_VS_Systick
Mcu.Pin3=PD0-OSC_IN
Mcu.Pin4=PD1-OSC_OUT
Mcu.Pin5=PA4
Mcu.Pin6=PA5
Mcu.Pin7=PA6
Mcu.Pin8=PA7
Mcu.Pin9=PB10
Mcu.PinsNb=25
Mcu.Pin5=PA1
Mcu.Pin6=PA2
Mcu.Pin7=PA3
Mcu.Pin8=PA4
Mcu.Pin9=PA5
Mcu.PinsNb=28
Mcu.ThirdPartyNb=0
Mcu.UserConstants=eepromSpi,hspi1;etherSpi,hspi2;debugUart,huart1;mainsCnt,htim1
Mcu.UserName=STM32F103C8Tx
@ -61,6 +65,10 @@ NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
NVIC.TIM1_CC_IRQn=true\:0\:0\:false\:false\:true\:true\:true
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
PA1.GPIOParameters=GPIO_Label
PA1.GPIO_Label=MODEM_RES
PA1.Locked=true
PA1.Signal=GPIO_Output
PA10.GPIOParameters=GPIO_Label
PA10.GPIO_Label=Debug_RX
PA10.Mode=Asynchronous
@ -72,6 +80,14 @@ PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK
PA2.GPIOParameters=GPIO_Label
PA2.GPIO_Label=MODEM_TX
PA2.Mode=Asynchronous
PA2.Signal=USART2_TX
PA3.GPIOParameters=GPIO_Label
PA3.GPIO_Label=MODEM_RX
PA3.Mode=Asynchronous
PA3.Signal=USART2_RX
PA4.GPIOParameters=GPIO_Label
PA4.GPIO_Label=EEPROM_CS
PA4.Locked=true
@ -214,6 +230,8 @@ TIM1.IPParameters=Channel-Input_Capture1_from_TI1,Prescaler,ClockDivision
TIM1.Prescaler=13
USART1.IPParameters=VirtualMode
USART1.VirtualMode=VM_ASYNC
USART2.IPParameters=VirtualMode
USART2.VirtualMode=VM_ASYNC
VP_IWDG_VS_IWDG.Mode=IWDG_Activate
VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
VP_SYS_VS_Systick.Mode=SysTick

View File

@ -270,8 +270,9 @@ int httpPostRequest(char *url, const char *user, const char *pass, char *payload
}
int forwardMinuteBuffer(t_forwarderHandle *handle, t_minuteBuffer *buf) {
logmsg(LOG_INFO, "DeviceId: %s, RunningHours: %u, Powercycles: %u, WatchdogResets: %u",
buf->s.deviceId, buf->s.totalRunningHours, buf->s.totalPowercycles, buf->s.totalWatchdogResets);
logmsg(LOG_INFO, "D: %s, R: %u, P: %u, W: %u, V: %08x",
buf->s.deviceId, buf->s.totalRunningHours, buf->s.totalPowercycles, buf->s.totalWatchdogResets,
buf->s.version);
t_device *device = findDevice(handle->configHandle, buf->s.deviceId);
const char *location = device->location;

View File

@ -49,7 +49,10 @@ cp $IT_C $IT_C_BAK
echo "// $PROCESSED" > $IT_C
cat $IT_C_BAK | \
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' \
-e 's,\(/\* USER CODE BEGIN PFP \*/\),\1\nvoid modemISR();\n,' \
-e 's,\(/\* USER CODE BEGIN SysTick_IRQn 1 \*/\),\1\n SYSTICK_Callback();\n,' \
-e 's,\(HAL_UART_IRQHandler(&huart2);\),// \1,' \
-e 's,\(/\* USER CODE BEGIN UART5_IRQn 1 \*/\),\1\n modemISR();\n,' \
>> $IT_C