check more error codes

This commit is contained in:
Kevin Hester 2021-03-09 16:45:40 +08:00
parent 5b0d8381b9
commit 772f2a15ff
5 changed files with 54 additions and 40 deletions

2
proto

@ -1 +1 @@
Subproject commit 7c025b9a4d54bb410ec17ee653122861b413f177 Subproject commit e56f2770c33216ba94f289e2fb7f0b2dfd33aca2

View File

@ -1,9 +1,9 @@
#include "RedirectablePrint.h" #include "RedirectablePrint.h"
#include "concurrency/OSThread.h"
#include "configuration.h" #include "configuration.h"
#include <assert.h> #include <assert.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include "concurrency/OSThread.h"
/** /**
* A printer that doesn't go anywhere * A printer that doesn't go anywhere
@ -38,7 +38,7 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg)
va_end(arg); va_end(arg);
return 0; return 0;
}; };
if (len >= (int) printBufLen) { if (len >= (int)printBufLen) {
delete[] printBuf; delete[] printBuf;
printBufLen *= 2; printBufLen *= 2;
printBuf = new char[printBufLen]; printBuf = new char[printBufLen];
@ -55,47 +55,52 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg)
size_t RedirectablePrint::logDebug(const char *format, ...) size_t RedirectablePrint::logDebug(const char *format, ...)
{ {
va_list arg;
va_start(arg, format);
// Cope with 0 len format strings, but look for new line terminator
bool hasNewline = *format && format[strlen(format) - 1] == '\n';
size_t r = 0; size_t r = 0;
// If we are the first message on a report, include the header if (!inDebugPrint) {
if (!isContinuationMessage) { inDebugPrint = true;
struct timeval tv;
if (!gettimeofday(&tv, NULL)) {
long hms = tv.tv_sec % SEC_PER_DAY;
//hms += tz.tz_dsttime * SEC_PER_HOUR;
//hms -= tz.tz_minuteswest * SEC_PER_MIN;
// mod `hms` to ensure in positive range of [0...SEC_PER_DAY)
hms = (hms + SEC_PER_DAY) % SEC_PER_DAY;
// Tear apart hms into h:m:s va_list arg;
int hour = hms / SEC_PER_HOUR; va_start(arg, format);
int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN;
int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN
r += printf("%02d:%02d:%02d %u ", hour, min, sec, millis() / 1000); // Cope with 0 len format strings, but look for new line terminator
} else bool hasNewline = *format && format[strlen(format) - 1] == '\n';
r += printf("??:??:?? %u ", millis() / 1000);
auto thread = concurrency::OSThread::currentThread; // If we are the first message on a report, include the header
if(thread) { if (!isContinuationMessage) {
print("["); struct timeval tv;
// printf("%p ", thread); if (!gettimeofday(&tv, NULL)) {
// assert(thread->ThreadName.length()); long hms = tv.tv_sec % SEC_PER_DAY;
print(thread->ThreadName); // hms += tz.tz_dsttime * SEC_PER_HOUR;
print("] "); // hms -= tz.tz_minuteswest * SEC_PER_MIN;
// mod `hms` to ensure in positive range of [0...SEC_PER_DAY)
hms = (hms + SEC_PER_DAY) % SEC_PER_DAY;
// Tear apart hms into h:m:s
int hour = hms / SEC_PER_HOUR;
int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN;
int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN
r += printf("%02d:%02d:%02d %u ", hour, min, sec, millis() / 1000);
} else
r += printf("??:??:?? %u ", millis() / 1000);
auto thread = concurrency::OSThread::currentThread;
if (thread) {
print("[");
// printf("%p ", thread);
// assert(thread->ThreadName.length());
print(thread->ThreadName);
print("] ");
}
} }
r += vprintf(format, arg);
va_end(arg);
isContinuationMessage = !hasNewline;
inDebugPrint = false;
} }
r += vprintf(format, arg);
va_end(arg);
isContinuationMessage = !hasNewline;
return r; return r;
} }

View File

@ -19,6 +19,8 @@ class RedirectablePrint : public Print
/// Used to allow multiple logDebug messages to appear on a single log line /// Used to allow multiple logDebug messages to appear on a single log line
bool isContinuationMessage = false; bool isContinuationMessage = false;
volatile bool inDebugPrint = false;
public: public:
RedirectablePrint(Print *_dest) : dest(_dest) {} RedirectablePrint(Print *_dest) : dest(_dest) {}

View File

@ -1,5 +1,6 @@
#include "concurrency/BinarySemaphoreFreeRTOS.h" #include "concurrency/BinarySemaphoreFreeRTOS.h"
#include "configuration.h" #include "configuration.h"
#include <assert.h>
#ifdef HAS_FREE_RTOS #ifdef HAS_FREE_RTOS
@ -9,6 +10,7 @@ namespace concurrency
BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS() BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS()
{ {
semaphore = xSemaphoreCreateBinary(); semaphore = xSemaphoreCreateBinary();
assert(semaphore);
} }
BinarySemaphoreFreeRTOS::~BinarySemaphoreFreeRTOS() BinarySemaphoreFreeRTOS::~BinarySemaphoreFreeRTOS()

View File

@ -101,25 +101,30 @@ template <class T> class MemoryPool : public Allocator<T>
/// Return a buffer for use by others /// Return a buffer for use by others
virtual void release(T *p) virtual void release(T *p)
{ {
assert(dead.enqueue(p, 0));
assert(p >= buf && assert(p >= buf &&
(size_t)(p - buf) < (size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueue(p, 0));
} }
#ifdef HAS_FREE_RTOS #ifdef HAS_FREE_RTOS
/// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-) /// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-)
void releaseFromISR(T *p, BaseType_t *higherPriWoken) void releaseFromISR(T *p, BaseType_t *higherPriWoken)
{ {
assert(dead.enqueueFromISR(p, higherPriWoken));
assert(p >= buf && assert(p >= buf &&
(size_t)(p - buf) < (size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueueFromISR(p, higherPriWoken));
} }
#endif #endif
protected: protected:
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you /// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you
/// probably don't want this version). /// probably don't want this version).
virtual T *alloc(TickType_t maxWait) { return dead.dequeuePtr(maxWait); } virtual T *alloc(TickType_t maxWait)
{
T *p = dead.dequeuePtr(maxWait);
assert(p);
return p;
}
}; };