Log

Dependents:   oldheating gps motorhome heating

Revision:
16:5c41b457c7f3
Parent:
15:e490fce9b6ef
Child:
17:7acb89d71f48
--- a/log.c	Thu Dec 06 16:05:51 2018 +0000
+++ b/log.c	Mon Feb 04 15:26:50 2019 +0000
@@ -23,7 +23,7 @@
     if (p == buffer + bufferLength) p = buffer; //if the pointer is now beyond the end then point it back to the start
     return p;
 }
-static void push(char c)
+static void push(const char c)
 {
     //Move the pull position if about to run into it
     char* pNext = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH);
@@ -33,7 +33,7 @@
     *pPush = c;
     pPush = incrementPushPullPointer(pPush, buffer, BUFFER_LENGTH);
 }
-void LogPush(char c)
+void LogChar(const char c)
 {
     //Only add if allowed
     if (!enable) return;
@@ -100,20 +100,20 @@
     int result = SerialPcPutC(*pUart); //Attempt to write the character
     if (result == 0) pUart = incrementPushPullPointer(pUart, buffer, BUFFER_LENGTH); //If the character was written to the uart then move to the next
 }
-int Log(char* snd)
+int Log(const char* snd)
 {
-    char* ptr = snd;
-    while (*ptr) LogPush(*ptr++); //Send the string to the log buffer
+    const char* ptr = snd;
+    while (*ptr) LogChar(*ptr++); //Send the string to the log buffer
     return ptr - snd;
 }
-int LogV(char *fmt, va_list argptr)
+int LogV(const char *fmt, va_list argptr)
 {
     int size  = vsnprintf(NULL, 0, fmt, argptr);  //Find the size required
     char snd[size + 1];                           //Allocate enough memory for the size required with an extra byte for the terminating null
     vsprintf(snd, fmt, argptr);                   //Fill the new buffer
     return Log(snd);                              //Send the string to the log buffer
 }
-int LogF(char *fmt, ...)
+int LogF(const char *fmt, ...)
 {
     va_list argptr;
     va_start(argptr, fmt);
@@ -123,8 +123,8 @@
 }
 static void pushuint4(int value)
 {    
-    if      (value > 9999) { LogPush('+'); LogPush('+'); LogPush('+'); LogPush('+'); }
-    else if (value <    0) { LogPush('-'); LogPush('-'); LogPush('-'); LogPush('-'); }
+    if      (value > 9999) { LogChar('+'); LogChar('+'); LogChar('+'); LogChar('+'); }
+    else if (value <    0) { LogChar('-'); LogChar('-'); LogChar('-'); LogChar('-'); }
     else
     {
         div_t divres;
@@ -133,13 +133,13 @@
         divres = div(divres.quot, 10); t = divres.rem;
         divres = div(divres.quot, 10); c = divres.rem;
                                        k = divres.quot;                           
-        LogPush(k + '0'); LogPush(c + '0'); LogPush(t + '0'); LogPush(u + '0');
+        LogChar(k + '0'); LogChar(c + '0'); LogChar(t + '0'); LogChar(u + '0');
     }
 }
 static void pushuint3(int value)
 {
-    if      (value > 999) { LogPush('+'); LogPush('+'); LogPush('+'); }
-    else if (value <   0) { LogPush('-'); LogPush('-'); LogPush('-'); }
+    if      (value > 999) { LogChar('+'); LogChar('+'); LogChar('+'); }
+    else if (value <   0) { LogChar('-'); LogChar('-'); LogChar('-'); }
     else
     {
         div_t divres;
@@ -147,20 +147,20 @@
         divres = div(value      , 10); u = divres.rem;
         divres = div(divres.quot, 10); t = divres.rem;
                                        c = divres.quot;
-        LogPush(c + '0'); LogPush(t + '0'); LogPush(u + '0');
+        LogChar(c + '0'); LogChar(t + '0'); LogChar(u + '0');
     }
 }
 static void pushuint2(int value)
 {
-    if      (value > 99) { LogPush('+'); LogPush('+'); }
-    else if (value <  0) { LogPush('-'); LogPush('-'); }
+    if      (value > 99) { LogChar('+'); LogChar('+'); }
+    else if (value <  0) { LogChar('-'); LogChar('-'); }
     else
     {
         div_t divres;
         int t, u;
         divres = div(value      , 10); u = divres.rem;
                                        t = divres.quot;
-        LogPush(t + '0'); LogPush(u + '0');
+        LogChar(t + '0'); LogChar(u + '0');
     }
 }
 
@@ -172,31 +172,31 @@
     tmFunction(&tm);
     
     pushuint4(tm.tm_year + 1900);
-    LogPush('-');
+    LogChar('-');
     pushuint3(tm.tm_yday + 1);
-    LogPush(' ');
+    LogChar(' ');
     pushuint2(tm.tm_hour);
-    LogPush(':');
+    LogChar(':');
     pushuint2(tm.tm_min);
-    LogPush(':');
+    LogChar(':');
     pushuint2(tm.tm_sec);
     return 17;
 }
-int LogTime(char *snd)
+int LogTime(const char *snd)
 {
     int size = 0;
     size += logTimeOnly();
-    size++; LogPush(' ');
+    size++; LogChar(' ');
     size += Log(snd);
     return size;
 }
-int LogTimeF(char *fmt, ...)
+int LogTimeF(const char *fmt, ...)
 {
     int size = 0;
     va_list argptr;
     va_start(argptr, fmt);
     size == logTimeOnly();
-    size++; LogPush(' ');
+    size++; LogChar(' ');
     size += LogV(fmt, argptr);
     va_end(argptr);
     return size;