more stats output
This commit is contained in:
parent
206e371d48
commit
b1fdc04366
@ -4,10 +4,19 @@
|
||||
#include <stdint.h>
|
||||
#include <spi.h>
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_deviceStats {
|
||||
uint32_t totalRunningHours;
|
||||
uint32_t totalPowercycles;
|
||||
uint32_t totalRequests;
|
||||
uint32_t totalFailures;
|
||||
} t_deviceStats;
|
||||
|
||||
void eepromInit();
|
||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||
t_deviceStats* getGlobalDeviceStats();
|
||||
|
||||
|
||||
#endif /* EEPROM_H_ */
|
||||
|
@ -35,18 +35,15 @@ typedef union {
|
||||
static const uint16_t EEPROM_HEADER_ADDR = 0;
|
||||
static t_eepromHeader eepromHeader;
|
||||
|
||||
|
||||
|
||||
typedef union {
|
||||
struct __attribute__((__packed__)) s_deviceStats {
|
||||
uint32_t totalRunningHours;
|
||||
uint32_t totalPowercycles;
|
||||
uint32_t totalRequests;
|
||||
uint32_t totalFailures;
|
||||
} s;
|
||||
uint8_t b[sizeof(struct s_deviceStats)];
|
||||
} t_deviceStats;
|
||||
t_deviceStats s;
|
||||
uint8_t b[sizeof(t_deviceStats)];
|
||||
} t_deviceStatsBlock;
|
||||
|
||||
static const uint16_t DEVICE_STATS_ADDR = 32;
|
||||
static t_deviceStats deviceStats;
|
||||
static t_deviceStatsBlock deviceStats;
|
||||
|
||||
static const uint8_t NUM_OF_BLOCKS = 2;
|
||||
static const uint16_t BLOCK_ADDR[] = { 64, 4128 };
|
||||
@ -62,6 +59,9 @@ typedef union {
|
||||
} t_spiMsg;
|
||||
|
||||
|
||||
t_deviceStats* getGlobalDeviceStats() {
|
||||
return &(deviceStats.s);
|
||||
}
|
||||
|
||||
inline static void __EEPROM_CS(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <wizHelper.h>
|
||||
#include <mbusComm.h>
|
||||
#include <oled.h>
|
||||
#include <eeprom.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -53,10 +54,12 @@ static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength)
|
||||
static void mqttStatusPublisher(void *handle) {
|
||||
coloredMsg(LOG_GREEN, false, "mqsp: publishing status");
|
||||
t_mbusCommStats *mbusCommStats = mbusCommGetStats();
|
||||
t_deviceStats* globalDeviceStats = getGlobalDeviceStats();
|
||||
|
||||
char buf[64];
|
||||
uint32_t uptime = HAL_GetTick() / 1000;
|
||||
snprintf(buf, 128, "{\"uptime\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\"}",
|
||||
uptime, schTaskCnt(), mbusCommStats->requestCnt, mbusCommStats->errorCnt);
|
||||
snprintf(buf, 128, "{\"uptime\":\"%ld\", \"runningHours\":\"%ld\", \"powerCycles\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\"}",
|
||||
uptime, globalDeviceStats->totalRunningHours, globalDeviceStats->totalPowercycles, schTaskCnt(), mbusCommStats->requestCnt, mbusCommStats->errorCnt);
|
||||
bool res = publish(&mqttClient, StatusTopic, (const uint8_t*)buf, strlen(buf), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
|
||||
@ -66,8 +69,11 @@ static void mqttStatusPublisher(void *handle) {
|
||||
oledPrintf(OLED_SCREEN1, "Addr:%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
|
||||
oledPrintf(OLED_SCREEN1, "Network available:%d", isNetworkAvailable());
|
||||
oledPrintf(OLED_SCREEN1, "Uptime:%ld", uptime);
|
||||
oledPrintf(OLED_SCREEN1, "RunHours:%d", globalDeviceStats->totalRunningHours);
|
||||
oledPrintf(OLED_SCREEN1, "PowerCycl:%d", globalDeviceStats->totalPowercycles);
|
||||
oledPrintf(OLED_SCREEN1, "Req:%ld", mbusCommStats->requestCnt);
|
||||
oledPrintf(OLED_SCREEN1, "Err:%ld", mbusCommStats->errorCnt);
|
||||
|
||||
}
|
||||
|
||||
void mqttCommHandler(void *handle) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user