Explorar o código

log: add log_f and log_buf

Add a header to SCSI2SD code so it can reach these
joshua stein %!s(int64=2) %!d(string=hai) anos
pai
achega
d99b40ae60

+ 1 - 0
lib/SCSI2SD/src/firmware/config.h

@@ -18,6 +18,7 @@
 #define S2S_Config_H
 
 #include "scsi2sd.h"
+#include "log.h"
 
 void s2s_configInit(S2S_BoardCfg* config);
 void s2s_debugInit(void);

+ 27 - 0
lib/SCSI2SD/src/firmware/log.h

@@ -0,0 +1,27 @@
+//	Copyright (C) 2023 joshua stein <jcs@jcs.org>
+//
+//	This file is part of SCSI2SD.
+//
+//	SCSI2SD is free software: you can redistribute it and/or modify
+//	it under the terms of the GNU General Public License as published by
+//	the Free Software Foundation, either version 3 of the License, or
+//	(at your option) any later version.
+//
+//	SCSI2SD is distributed in the hope that it will be useful,
+//	but WITHOUT ANY WARRANTY; without even the implied warranty of
+//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//	GNU General Public License for more details.
+//
+//	You should have received a copy of the GNU General Public License
+//	along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void log_buf(const unsigned char *buf, unsigned long size);
+extern void log_f(const char *format, ...);
+
+#ifdef __cplusplus
+}
+#endif

+ 32 - 0
src/BlueSCSI_log.cpp

@@ -129,6 +129,38 @@ void log_raw(bool value)
     else log_raw("false");
 }
 
+void log_f(const char *format, ...)
+{
+    static char out[2048];
+
+    va_list ap;
+    va_start(ap, format);
+    vsnprintf(out, sizeof(out), format, ap);
+    va_end(ap);
+
+    log(out);
+}
+
+void log_buf(const unsigned char *buf, unsigned long size)
+{
+    static char tmp[1500 * 3];
+    static char hex[] = "0123456789abcdef";
+    int o = 0;
+
+    for (int j = 0; j < size; j++) {
+        if (o + 3 >= sizeof(tmp))
+            break;
+
+        if (j != 0)
+            tmp[o++] = ' ';
+        tmp[o++] = hex[(buf[j] >> 4) & 0xf];
+        tmp[o++] = hex[buf[j] & 0xf];
+        tmp[o] = 0;
+    }
+
+    log_f("%s", tmp);
+}
+
 uint32_t log_get_buffer_len()
 {
     return g_logpos;

+ 10 - 0
src/BlueSCSI_log.h

@@ -53,6 +53,16 @@ inline void log_raw()
     // End of template recursion
 }
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+void log_buf(const unsigned char *buf, unsigned long size);
+// Log formatted string
+void log_f(const char *format, ...);
+#ifdef __cplusplus
+}
+#endif
+
 extern "C" unsigned long millis();
 
 // Variadic template for printing multiple items