color refactoring
This commit is contained in:
parent
bef20bcaed
commit
6bbe4d7eaf
@ -12,6 +12,7 @@ void logFree();
|
|||||||
// log a message, make sure it is a null-terminated string
|
// log a message, make sure it is a null-terminated string
|
||||||
// return value can be ignored, it is only used in test
|
// return value can be ignored, it is only used in test
|
||||||
int logMsg(const char *format, ...);
|
int logMsg(const char *format, ...);
|
||||||
|
int errMsg(const char *format, ...);
|
||||||
|
|
||||||
// reads the ringbuffer and transfers data to output channel
|
// reads the ringbuffer and transfers data to output channel
|
||||||
// call this from the idle-loop
|
// call this from the idle-loop
|
||||||
|
@ -60,17 +60,22 @@ static void flashGreenLed(void *handle) {
|
|||||||
}
|
}
|
||||||
#endif // TEST
|
#endif // TEST
|
||||||
|
|
||||||
int logMsg(const char *format, ...) {
|
static int innerLogMsg(const char *pre, const char *post, const char *format, va_list vl) {
|
||||||
int res = -1;
|
int res = -1;
|
||||||
char msgBuffer[MSGBUFFER_SIZE];
|
int offset = 0;
|
||||||
|
char msgBuffer[MSGBUFFER_SIZE+20];
|
||||||
|
memset(msgBuffer, 0, MSGBUFFER_SIZE+20);
|
||||||
|
|
||||||
va_list vl;
|
if (pre) {
|
||||||
va_start(vl, format);
|
strcpy(msgBuffer, pre);
|
||||||
int vcnt = vsnprintf(msgBuffer, MSGBUFFER_SIZE-2, format, vl);
|
offset = strlen(pre);
|
||||||
va_end(vl);
|
}
|
||||||
|
int vcnt = vsnprintf(msgBuffer+offset, MSGBUFFER_SIZE, format, vl);
|
||||||
|
|
||||||
if (vcnt < MSGBUFFER_SIZE) {
|
if (vcnt < MSGBUFFER_SIZE) {
|
||||||
strcat(msgBuffer, "\r\n");
|
if (post) {
|
||||||
|
strcat(msgBuffer, post);
|
||||||
|
}
|
||||||
|
|
||||||
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
|
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
@ -84,3 +89,21 @@ int logMsg(const char *format, ...) {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int logMsg(const char *format, ...) {
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, format);
|
||||||
|
int res = innerLogMsg(NULL, "\r\n", format, vl);
|
||||||
|
va_end(vl);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int errMsg(const char *format, ...) {
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, format);
|
||||||
|
int res = innerLogMsg("\x1b[31;1m", "\x1b[0m\r\n", format, vl);
|
||||||
|
va_end(vl);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,28 +118,28 @@ static void parseAndPrintFrame(t_mbusCommHandle *mbusCommHandle) {
|
|||||||
mbus_data_variable *data_var = &(frame_data.data_var);
|
mbus_data_variable *data_var = &(frame_data.data_var);
|
||||||
logMsg("papf sts: %02x", data_var->header.status);
|
logMsg("papf sts: %02x", data_var->header.status);
|
||||||
if ((data_var->header.status & 0x01)) {
|
if ((data_var->header.status & 0x01)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Application Busy\x1b[0m");
|
errMsg("papf sts: Application Busy");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x02)) {
|
if ((data_var->header.status & 0x02)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Any Application Error\x1b[0m");
|
errMsg("papf sts: Any Application Error");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x04)) {
|
if ((data_var->header.status & 0x04)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Power Low\x1b[0m");
|
errMsg("papf sts: Power Low");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x08)) {
|
if ((data_var->header.status & 0x08)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Permanent Error\x1b[0m");
|
errMsg("papf sts: Permanent Error");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x10)) {
|
if ((data_var->header.status & 0x10)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Temporary Error\x1b[0m");
|
errMsg("papf sts: Temporary Error");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x20)) {
|
if ((data_var->header.status & 0x20)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Specific to manufacturer Error 1\x1b[0m");
|
errMsg("papf sts: Specific to manufacturer Error 1");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x40)) {
|
if ((data_var->header.status & 0x40)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Specific to manufacturer Error 2\x1b[0m");
|
errMsg("papf sts: Specific to manufacturer Error 2");
|
||||||
}
|
}
|
||||||
if ((data_var->header.status & 0x80)) {
|
if ((data_var->header.status & 0x80)) {
|
||||||
logMsg("\x1b[31;1mpapf sts: Specific to manufacturer Error 3\x1b[0m");
|
errMsg("papf sts: Specific to manufacturer Error 3");
|
||||||
}
|
}
|
||||||
mbus_data_record *record;
|
mbus_data_record *record;
|
||||||
int i;
|
int i;
|
||||||
@ -161,7 +161,6 @@ static void parseAndPrintFrame(t_mbusCommHandle *mbusCommHandle) {
|
|||||||
} else {
|
} else {
|
||||||
logMsg("papf err: unable to parse frame");
|
logMsg("papf err: unable to parse frame");
|
||||||
}
|
}
|
||||||
logMsg("\x1b[0m");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user