logging
This commit is contained in:
parent
dc91b5317a
commit
5d3a2bbff3
@ -46,6 +46,7 @@ typedef struct {
|
||||
bool clearCmd(uint8_t argc, char **args) {
|
||||
t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 };
|
||||
mbusCommSetStats(zeroedStats);
|
||||
coloredMsg(LOG_YELLOW, true, "ch cc global statistics cleared");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -67,8 +68,10 @@ bool mbusCommEnableCmd(uint8_t argc, char **args) {
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
mbusCommEnable(false);
|
||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication disabled");
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
mbusCommEnable(true);
|
||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication enabled");
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
@ -83,8 +86,10 @@ bool loopEnableCmd(uint8_t argc, char **args) {
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
loopDisable();
|
||||
coloredMsg(LOG_YELLOW, true, "ch lec loop disabled");
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
loopEnable();
|
||||
coloredMsg(LOG_YELLOW, true, "ch lec loop enabled");
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
@ -148,7 +153,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
|
||||
configMode = false;
|
||||
}
|
||||
|
||||
coloredMsg(LOG_YELLOW, false, "cec, cmdLine is %s", cmdLine);;
|
||||
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
|
||||
|
||||
#define MAX_NUM_OF_ARGS 8
|
||||
char *args[MAX_NUM_OF_TASKS];
|
||||
@ -164,7 +169,7 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
|
||||
char *cmd = args[0];
|
||||
|
||||
int8_t retCode = 0;
|
||||
coloredMsg(LOG_YELLOW, false, "cec, cmd is %s, number of arguments %d", cmd, argc);
|
||||
coloredMsg(LOG_YELLOW, false, "ch cec cmd is %s, number of arguments %d", cmd, argc);
|
||||
|
||||
if (0 == strcmp(cmd, "quit")) {
|
||||
messageToSend = GOODBYE_MSG;
|
||||
@ -182,11 +187,11 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
|
||||
}
|
||||
messageToSend = NULL;
|
||||
} else if (0 == strcmp(cmd, "enable")) {
|
||||
coloredMsg(LOG_YELLOW, true, "cec, enable config mode");
|
||||
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");
|
||||
configMode = true;
|
||||
retCode = 1;
|
||||
} else if (0 == strcmp(cmd, "disable")) {
|
||||
coloredMsg(LOG_YELLOW, true, "cec, disable config mode");
|
||||
coloredMsg(LOG_YELLOW, true, "ch cec disable config mode");
|
||||
configMode = false;
|
||||
retCode = 2;
|
||||
} else {
|
||||
@ -241,13 +246,13 @@ void cmdHandlerEngine(void *handle) {
|
||||
if (isNetworkAvailable()) {
|
||||
switch (state) {
|
||||
case CH_INIT:
|
||||
coloredMsg(LOG_YELLOW, false, "che, initializing socket");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che initializing socket");
|
||||
|
||||
res = socket(CMD_SOCK, Sn_MR_TCP, cmdPort, SF_IO_NONBLOCK);
|
||||
coloredMsg(LOG_YELLOW, false, "che, socket returns %d", res);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket returns %d", res);
|
||||
|
||||
if (res == CMD_SOCK) {
|
||||
coloredMsg(LOG_YELLOW, false, "che, socket is initialized");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket is initialized");
|
||||
state = CH_LISTEN;
|
||||
} else {
|
||||
state = CH_ERROR;
|
||||
@ -255,13 +260,13 @@ void cmdHandlerEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case CH_LISTEN:
|
||||
coloredMsg(LOG_YELLOW, false, "che, listening");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che listening");
|
||||
|
||||
res = listen(CMD_SOCK);
|
||||
coloredMsg(LOG_YELLOW, false, "che, listen returns %d", res);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che listen returns %d", res);
|
||||
|
||||
if (res == SOCK_OK) {
|
||||
coloredMsg(LOG_YELLOW, false, "che, ok, waiting for established");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che ok, waiting for established");
|
||||
state = CH_WAITING;
|
||||
} else {
|
||||
state = CH_ERROR;
|
||||
@ -271,24 +276,24 @@ void cmdHandlerEngine(void *handle) {
|
||||
case CH_WAITING:
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_LISTEN) {
|
||||
coloredMsg(LOG_YELLOW, false, "che, socket state is 0x%02x", sockState);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che socket state is 0x%02x", sockState);
|
||||
}
|
||||
|
||||
if (sockState == SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "che, connection is established");
|
||||
coloredMsg(LOG_YELLOW, true, "ch che connection is established");
|
||||
state = CH_BANNER;
|
||||
}
|
||||
break;
|
||||
|
||||
case CH_BANNER:
|
||||
coloredMsg(LOG_YELLOW, false, "che, send banner");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che send banner");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to send banner", sockState);
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send banner", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
resultSend = send(CMD_SOCK, banner, strlen(banner));
|
||||
coloredMsg(LOG_YELLOW, false, "che, sent banner, send returns 0x%02x", resultSend);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend);
|
||||
prompt = defaultPrompt;
|
||||
resetConfigMode = true;
|
||||
state = CH_PROMPT;
|
||||
@ -296,14 +301,14 @@ void cmdHandlerEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case CH_PROMPT:
|
||||
coloredMsg(LOG_YELLOW, false, "che send prompt");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che send prompt");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to send promt", sockState);
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send promt", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
resultSend = send(CMD_SOCK, prompt, strlen(prompt));
|
||||
coloredMsg(LOG_YELLOW, false, "che, sent prompt %s, send returns 0x%02x", prompt, resultSend);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che sent prompt %s, send returns 0x%02x", prompt, resultSend);
|
||||
state = CH_RECEIVE;
|
||||
}
|
||||
break;
|
||||
@ -311,7 +316,7 @@ void cmdHandlerEngine(void *handle) {
|
||||
case CH_RECEIVE:
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
if (sockState != SOCK_ESTABLISHED) {
|
||||
coloredMsg(LOG_YELLOW, true, "che sockState is 0x%02x when trying to receive something", sockState);
|
||||
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to receive something", sockState);
|
||||
state = CH_DISCONNECT;
|
||||
} else {
|
||||
receivedOctets = getSn_RX_RSR(CMD_SOCK);
|
||||
@ -319,7 +324,7 @@ void cmdHandlerEngine(void *handle) {
|
||||
if (receivedOctets > 0) {
|
||||
memset(receiveBuffer, 0, sizeof(receiveBuffer));
|
||||
resultRecv = recv(CMD_SOCK, receiveBuffer, sizeof(receiveBuffer));
|
||||
coloredMsg(LOG_YELLOW, false, "che, recv returns 0x%02x", resultRecv);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che recv returns 0x%02x", resultRecv);
|
||||
if (resultRecv > 0) {
|
||||
if ((receiveBuffer[strlen(receiveBuffer) - 1] == 0x0a) ||
|
||||
(receiveBuffer[strlen(receiveBuffer) - 1] == 0x0d)) {
|
||||
@ -329,7 +334,7 @@ void cmdHandlerEngine(void *handle) {
|
||||
(receiveBuffer[strlen(receiveBuffer) - 1] == 0x0d)) {
|
||||
receiveBuffer[strlen(receiveBuffer) - 1] = 0;
|
||||
}
|
||||
coloredMsg(LOG_YELLOW, false, "che, received: %s", receiveBuffer);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer);
|
||||
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetConfigMode);
|
||||
resetConfigMode = false;
|
||||
switch (resCEC) {
|
||||
@ -354,25 +359,25 @@ void cmdHandlerEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case CH_DISCONNECT:
|
||||
coloredMsg(LOG_YELLOW, true, "che, close our end");
|
||||
coloredMsg(LOG_YELLOW, true, "ch che close our end");
|
||||
resultDisconnect = disconnect(CMD_SOCK);
|
||||
coloredMsg(LOG_YELLOW, true, "che, disconnect returns 0x%02x", resultDisconnect);
|
||||
coloredMsg(LOG_YELLOW, true, "ch che disconnect returns 0x%02x", resultDisconnect);
|
||||
state = CH_DISCONNECT_WAIT;
|
||||
break;
|
||||
|
||||
case CH_DISCONNECT_WAIT:
|
||||
coloredMsg(LOG_YELLOW, false, "che, waiting after disconnect");
|
||||
coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
|
||||
sockState = getSn_SR(CMD_SOCK);
|
||||
coloredMsg(LOG_YELLOW, false, "che, sockState is 0x%02x", sockState);
|
||||
coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
|
||||
if (sockState == SOCK_CLOSED) {
|
||||
coloredMsg(LOG_YELLOW, true, "che, socket is closed now");
|
||||
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
|
||||
state = CH_INIT;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CH_ERROR:
|
||||
coloredMsg(LOG_YELLOW, true, "che, error state, will stop here");
|
||||
coloredMsg(LOG_YELLOW, true, "ch che error state, will stop here");
|
||||
schDel(cmdHandlerEngine, NULL);
|
||||
break;
|
||||
}
|
||||
|
@ -127,30 +127,30 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
int r = mbus_frame_data_parse(&reply, &frame_data);
|
||||
if (r == 0) {
|
||||
mbus_data_variable *data_var = &(frame_data.data_var);
|
||||
coloredMsg(LOG_YELLOW, false, "papf [%d] sts: %02x", localMbusCommHandle->requestId, data_var->header.status);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] sts: %02x", localMbusCommHandle->requestId, data_var->header.status);
|
||||
if ((data_var->header.status & 0x01)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Application Busy", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Application Busy", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x02)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Any Application Error", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Any Application Error", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x04)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Power Low", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Power Low", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x08)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Permanent Error", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Permanent Error", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x10)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Temporary Error", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Temporary Error", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x20)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Specific to manufacturer Error 1", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 1", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x40)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Specific to manufacturer Error 2", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 2", localMbusCommHandle->requestId);
|
||||
}
|
||||
if ((data_var->header.status & 0x80)) {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] sts: Specific to manufacturer Error 3", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 3", localMbusCommHandle->requestId);
|
||||
}
|
||||
mbus_data_record *record;
|
||||
int i;
|
||||
@ -160,7 +160,7 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
for (uint8_t j = 0; j < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; j++) {
|
||||
if ((localMbusCommHandle->device->consideredField[j].index == i) &&
|
||||
(strlen(localMbusCommHandle->device->consideredField[j].label) > 0)) {
|
||||
coloredMsg(LOG_YELLOW, true, "papf [%d] txt: I:%d, L:%s, U:%s V:%s",
|
||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] txt: I:%d, L:%s, U:%s V:%s",
|
||||
localMbusCommHandle->requestId,
|
||||
i,
|
||||
localMbusCommHandle->device->consideredField[j].label,
|
||||
@ -171,7 +171,7 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
}
|
||||
mbus_data_record_free(data_var->record);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
static void handleRequestEngine(void *handle);
|
||||
static void timeoutHandler(void *handle) {
|
||||
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
|
||||
coloredMsg(LOG_RED, true, "mbcth [%d] timeout", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc th [%d] timeout", localMbusCommHandle->requestId);
|
||||
localMbusCommHandle->state = MBCS_TIMEOUT;
|
||||
localMbusCommHandle->receiving = false;
|
||||
handleRequestEngine(handle);
|
||||
@ -198,11 +198,11 @@ static void handleRequestEngine(void *handle) {
|
||||
|
||||
switch (localMbusCommHandle->state) {
|
||||
case MBCS_IDLE:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state IDLE", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state IDLE", localMbusCommHandle->requestId);
|
||||
break;
|
||||
|
||||
case MBCS_SEND:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state SEND", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", localMbusCommHandle->requestId);
|
||||
localMbusCommHandle->sendBuf[0] = 0x10;
|
||||
localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd;
|
||||
localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr;
|
||||
@ -212,10 +212,10 @@ static void handleRequestEngine(void *handle) {
|
||||
// no break !!
|
||||
|
||||
case MBCS_SEND_CONTINUED:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state SEND_CONTINUED", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", localMbusCommHandle->requestId);
|
||||
show(LED_RED, OFF);
|
||||
if (! loopActive) {
|
||||
coloredMsg(LOG_YELLOW, true, "hre [%d] enabling loop, try %d", localMbusCommHandle->requestId, localMbusCommHandle->retryCnt);
|
||||
coloredMsg(LOG_YELLOW, true, "mbc hre [%d] enabling loop, try %d", localMbusCommHandle->requestId, localMbusCommHandle->retryCnt);
|
||||
localMbusCommHandle->retryCnt++;
|
||||
loopEnable();
|
||||
schAdd(handleRequestEngine, handle, 100, 0); // give 100ms to settled the loop
|
||||
@ -229,13 +229,13 @@ static void handleRequestEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case MBCS_SENDING_DONE:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state SENDING_DONE", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", localMbusCommHandle->requestId);
|
||||
localMbusCommHandle->state = MBCS_ENABLE_FRONTEND;
|
||||
schAdd(handleRequestEngine, handle, 3, 0);
|
||||
break;
|
||||
|
||||
case MBCS_ENABLE_FRONTEND:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state ENABLE_FRONTEND", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", localMbusCommHandle->requestId);
|
||||
frontendEnable();
|
||||
schAdd(timeoutHandler, handle, 2500, 0);
|
||||
calculatedChksum = 0;
|
||||
@ -249,7 +249,7 @@ static void handleRequestEngine(void *handle) {
|
||||
localMbusCommHandle->frame.start1 = localMbusCommHandle->receivedOctet;
|
||||
localMbusCommHandle->state = MBCS_LENGTH1;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: invalid start1 symbol %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start1 symbol %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__START1;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
}
|
||||
@ -258,14 +258,14 @@ static void handleRequestEngine(void *handle) {
|
||||
|
||||
case MBCS_LENGTH1:
|
||||
if (localMbusCommHandle->receivedOctet <= 3) {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: length to small %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: length to small %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__LENGTH1;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
} else {
|
||||
localMbusCommHandle->frame.length1 = localMbusCommHandle->receivedOctet;
|
||||
localMbusCommHandle->frame.userdata = (uint8_t*) malloc(localMbusCommHandle->frame.length1 - 3);
|
||||
if (! localMbusCommHandle->frame.userdata) {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: unable to allocate memory for userdata", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: unable to allocate memory for userdata", localMbusCommHandle->requestId);
|
||||
localMbusCommHandle->result = MBCR_ERROR_OUT_OF_MEMORY__USERDATA;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
} else {
|
||||
@ -277,7 +277,7 @@ static void handleRequestEngine(void *handle) {
|
||||
|
||||
case MBCS_LENGTH2:
|
||||
if (localMbusCommHandle->frame.length1 != localMbusCommHandle->receivedOctet) {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: invalid length2 %02x vs. %02x",
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid length2 %02x vs. %02x",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->frame.length1, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__LENGTH2;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
@ -293,7 +293,7 @@ static void handleRequestEngine(void *handle) {
|
||||
localMbusCommHandle->frame.start2 = localMbusCommHandle->receivedOctet;
|
||||
localMbusCommHandle->state = MBCS_C_FIELD;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: invalid start2 symbol %02x",
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start2 symbol %02x",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__START2;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
@ -334,7 +334,7 @@ static void handleRequestEngine(void *handle) {
|
||||
|
||||
case MBCS_CHKSUM:
|
||||
if (localMbusCommHandle->receivedOctet != calculatedChksum) {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: invalid checksum %02x vs %02x",
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid checksum %02x vs %02x",
|
||||
localMbusCommHandle->requestId, calculatedChksum, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
@ -351,7 +351,7 @@ static void handleRequestEngine(void *handle) {
|
||||
localMbusCommHandle->state = MBCS_DONE;
|
||||
schAdd(handleRequestEngine, handle, 0, 0);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: invalid stop symbol %02x",
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid stop symbol %02x",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__STOP;
|
||||
localMbusCommHandle->state = MBCS_ERROR;
|
||||
@ -360,7 +360,7 @@ static void handleRequestEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case MBCS_DONE:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state DONE", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DONE", localMbusCommHandle->requestId);
|
||||
parseAndPrintFrame(localMbusCommHandle);
|
||||
if (localMbusCommHandle->frame.userdata != NULL) {
|
||||
free(localMbusCommHandle->frame.userdata);
|
||||
@ -373,15 +373,15 @@ static void handleRequestEngine(void *handle) {
|
||||
break;
|
||||
|
||||
case MBCS_ERROR:
|
||||
coloredMsg(LOG_RED, true, "hre [%d] state ERROR", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] state ERROR", localMbusCommHandle->requestId);
|
||||
show(LED_RED, ON);
|
||||
coloredMsg(LOG_RED, true, "hre [%d] err: already error, read the rest (now: %02x) until timeout",
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] err: already error, read the rest (now: %02x) until timeout",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
|
||||
receiveNext(localMbusCommHandle);
|
||||
break;
|
||||
|
||||
case MBCS_TIMEOUT:
|
||||
coloredMsg(LOG_RED, true, "hre [%d] state TIMEOUT", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] state TIMEOUT", localMbusCommHandle->requestId);
|
||||
mbusCommStats.errorCnt += 1;
|
||||
localMbusCommHandle->device->failures += 1;
|
||||
localMbusCommHandle->receiving = false;
|
||||
@ -393,11 +393,11 @@ static void handleRequestEngine(void *handle) {
|
||||
uint8_t kitchenSink[16];
|
||||
memset(kitchenSink, 0, 16);
|
||||
HAL_StatusTypeDef r = HAL_UART_Receive(&mbusUart, kitchenSink, 16, 100);
|
||||
coloredMsg(LOG_RED, true, "hre [%d] abort, last receive result: %02x", localMbusCommHandle->requestId, r);
|
||||
coloredMsg(LOG_RED, true, "mbc hre [%d] abort, last receive result: %02x", localMbusCommHandle->requestId, r);
|
||||
// no break
|
||||
|
||||
case MBCS_DISABLE_FRONTEND:
|
||||
coloredMsg(LOG_YELLOW, false, "hre [%d] state DISABLE_FRONTEND", localMbusCommHandle->requestId);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DISABLE_FRONTEND", localMbusCommHandle->requestId);
|
||||
frontendDisable();
|
||||
localMbusCommHandle->state = MBCS_IDLE;
|
||||
break;
|
||||
@ -417,9 +417,6 @@ void mbusCommRxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
if (mbusCommHandle.receiving) {
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
mbusCommHandle.receiving = false;
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mcrx [%d] received 0x%02x but not expected",
|
||||
mbusCommHandle.requestId, mbusCommHandle.receivedOctet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -440,7 +437,7 @@ e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
mbusDevice->requests += 1;
|
||||
|
||||
coloredMsg(LOG_YELLOW, true, "mcr [%d] new request %s R:%d F:%d GRC:%d GEC:%d",
|
||||
coloredMsg(LOG_YELLOW, true, "mbc mcr [%d] new request %s R:%d F:%d GRC:%d GEC:%d",
|
||||
mbusCommHandle.requestId,
|
||||
mbusDevice->deviceName,
|
||||
mbusDevice->requests,
|
||||
|
Loading…
x
Reference in New Issue
Block a user