vif parsing
This commit is contained in:
parent
c7ac9a9dc3
commit
7bcfa7070d
@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
#include <mbus/mbus-protocol.h>
|
#include <mbus/mbus-protocol.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[32];
|
char name[32];
|
||||||
char unit[16];
|
char unit[16];
|
||||||
int8_t exponent;
|
int8_t exponent;
|
||||||
|
bool found;
|
||||||
} parsedVIB_t;
|
} parsedVIB_t;
|
||||||
|
|
||||||
parsedVIB_t parseVIB(mbus_value_information_block vib);
|
parsedVIB_t parseVIB(mbus_value_information_block vib);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <usart.h>
|
#include <usart.h>
|
||||||
@ -180,6 +181,12 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
|||||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
|
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
|
||||||
localMbusCommHandle->requestId,
|
localMbusCommHandle->requestId,
|
||||||
parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
|
parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
|
||||||
|
if (parsedVIB.found) {
|
||||||
|
uint8_t value = strtol(mbus_data_record_value(record), NULL, 10);
|
||||||
|
float weightedValue = ((float) value) * powf(10.0, ((float) parsedVIB.exponent));
|
||||||
|
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] result: %s is %d %s",
|
||||||
|
localMbusCommHandle->requestId, parsedVIB.name, weightedValue, parsedVIB.unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
static parsedVIB_t parseVIB_FB(mbus_value_information_block vib) {
|
static parsedVIB_t parseVIB_FB(mbus_value_information_block vib) {
|
||||||
parsedVIB_t parsedVIB = { .name = "FB unknown", .unit = "?", .exponent = 1 };
|
parsedVIB_t parsedVIB = { .name = "FB unknown", .unit = "?", .exponent = 1, .found = false };
|
||||||
|
|
||||||
coloredMsg(LOG_RED, true, "mpe pvd_fb unknown vife 0x%02x", vib.vife[0]);
|
coloredMsg(LOG_RED, true, "mpe pvd_fb unknown vife 0x%02x", vib.vife[0]);
|
||||||
|
|
||||||
@ -14,16 +16,18 @@ static parsedVIB_t parseVIB_FB(mbus_value_information_block vib) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parsedVIB_t parseVIB_FD(mbus_value_information_block vib) {
|
static parsedVIB_t parseVIB_FD(mbus_value_information_block vib) {
|
||||||
parsedVIB_t parsedVIB = { .name = "FD unknown", .unit = "?", .exponent = 1 };
|
parsedVIB_t parsedVIB = { .name = "FD unknown", .unit = "?", .exponent = 1, .found = false };
|
||||||
|
|
||||||
if ((vib.vife[0] & 0b01110000) == 0b01000000) {
|
if ((vib.vife[0] & 0b01110000) == 0b01000000) {
|
||||||
strcpy(parsedVIB.name, "Voltage");
|
strcpy(parsedVIB.name, "Voltage");
|
||||||
strcpy(parsedVIB.unit, "V");
|
strcpy(parsedVIB.unit, "V");
|
||||||
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 9;
|
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 9;
|
||||||
|
parsedVIB.found = true;
|
||||||
} else if ((vib.vife[0] & 0b01110000) == 0b01010000) {
|
} else if ((vib.vife[0] & 0b01110000) == 0b01010000) {
|
||||||
strcpy(parsedVIB.name, "Current");
|
strcpy(parsedVIB.name, "Current");
|
||||||
strcpy(parsedVIB.unit, "A");
|
strcpy(parsedVIB.unit, "A");
|
||||||
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 12;
|
parsedVIB.exponent = (vib.vife[0] & 0b01111) - 12;
|
||||||
|
parsedVIB.found = true;
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_RED, true, "mpe pvd_fd unknown vife 0x%02x", vib.vife[0]);
|
coloredMsg(LOG_RED, true, "mpe pvd_fd unknown vife 0x%02x", vib.vife[0]);
|
||||||
}
|
}
|
||||||
@ -32,16 +36,18 @@ static parsedVIB_t parseVIB_FD(mbus_value_information_block vib) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parsedVIB_t parseVIB_default(mbus_value_information_block vib) {
|
static parsedVIB_t parseVIB_default(mbus_value_information_block vib) {
|
||||||
parsedVIB_t parsedVIB = { .name = "default unknown", .unit = "?", .exponent = 1 };
|
parsedVIB_t parsedVIB = { .name = "default unknown", .unit = "?", .exponent = 1, .found = false };
|
||||||
|
|
||||||
if ((vib.vif & 0b01111000) == 0b00000000) {
|
if ((vib.vif & 0b01111000) == 0b00000000) {
|
||||||
strcpy(parsedVIB.name, "Energy");
|
strcpy(parsedVIB.name, "Energy");
|
||||||
strcpy(parsedVIB.unit, "Wh");
|
strcpy(parsedVIB.unit, "Wh");
|
||||||
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
||||||
|
parsedVIB.found = true;
|
||||||
} else if ((vib.vif & 0b01111000) == 0b00101000) {
|
} else if ((vib.vif & 0b01111000) == 0b00101000) {
|
||||||
strcpy(parsedVIB.name, "Power");
|
strcpy(parsedVIB.name, "Power");
|
||||||
strcpy(parsedVIB.unit, "W");
|
strcpy(parsedVIB.unit, "W");
|
||||||
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
|
||||||
|
parsedVIB.found = true;
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_RED, true, "mpe pvd unknown vif 0x%02x", vib.vif);
|
coloredMsg(LOG_RED, true, "mpe pvd unknown vif 0x%02x", vib.vif);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user