Log
Dependents: oldheating gps motorhome heating
Diff: log.cpp
- Revision:
- 2:ee4ec2d72525
- Parent:
- 1:4d81afe3859e
- Child:
- 3:7806ff3f1a2d
--- a/log.cpp Wed Feb 01 07:41:22 2017 +0000 +++ b/log.cpp Sat Feb 04 18:45:41 2017 +0000 @@ -20,40 +20,58 @@ //Only add if allowed if (!enable) return; + char* pNext; + + //Work out what has to be sent + bool delimited = false; + if (c < ' ' && c != '\r' && c != '\n') delimited = true; + if (c > 126) delimited = true; + //Move the pull position if about to run into it - char* pNext = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + pNext = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + if (pNext == pPull) pPull = incrementPushPullPointer(pPull, buffer, BUFFER_LENGTH); + + //Add the character at the push position + if (delimited) *pPush = '^'; + else *pPush = c; + pPush = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + + if (!delimited) return; + + //Move the pull position if about to run into it + pNext = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); if (pNext == pPull) pPull = incrementPushPullPointer(pPull, buffer, BUFFER_LENGTH); //Add the character at the push position - *pPush = c; + char h = c >> 4; + if (h < 10) h += '0'; + else h += 'A' - 10; + *pPush = h; pPush = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + + //Move the pull position if about to run into it + pNext = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + if (pNext == pPull) pPull = incrementPushPullPointer(pPull, buffer, BUFFER_LENGTH); + + //Add the character at the push position + h = c & 0x0F; + if (h < 10) h += '0'; + else h += 'A' - 10; + *pPush = h; + pPush = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH); + } static char *pEnumerate; -static int hadNull; void LogEnumerateStart() { pEnumerate = pPull; - hadNull = false; } int LogEnumerate() { - if (hadNull) - { - hadNull = false; - return '0'; - } if (pEnumerate == pPush) return EOF; char c = *pEnumerate; pEnumerate = incrementPushPullPointer(pEnumerate, buffer, BUFFER_LENGTH); - if (c) - { - return c; - } - else - { - hadNull = true; - return '\\'; - } + return c; } void LogEnable(int on) {