diff --git a/SimulationRuntime/c/math-support/ringbuffer.c b/SimulationRuntime/c/math-support/ringbuffer.c index e4b1ccb26b8..f11076c6fb1 100644 --- a/SimulationRuntime/c/math-support/ringbuffer.c +++ b/SimulationRuntime/c/math-support/ringbuffer.c @@ -54,7 +54,7 @@ RINGBUFFER *allocRingBuffer(int bufferSize, int itemSize) rb->bufferSize = bufferSize > 0 ? bufferSize : 1; rb->itemSize = itemSize; rb->buffer = calloc(rb->bufferSize, rb->itemSize); - ASSERT(rb->buffer, "out of memory", 1); + ASSERT(rb->buffer, "out of memory"); } void freeRingBuffer(RINGBUFFER *rb) @@ -65,8 +65,8 @@ void freeRingBuffer(RINGBUFFER *rb) void *getRingData(RINGBUFFER *rb, int i) { - ASSERT(i < rb->nElements, "index out of range", 1); - ASSERT(-rb->nElements < i, "index out of range", 1); + ASSERT(i < rb->nElements, "index out of range"); + ASSERT(-rb->nElements < i, "index out of range"); return ((char*)rb->buffer)+(((rb->firstElement+i)%rb->bufferSize)*rb->itemSize); } @@ -75,7 +75,7 @@ void expandRingBuffer(RINGBUFFER *rb) int i; void *temp = calloc(2*rb->bufferSize, rb->itemSize); - ASSERT(temp, "out of memory", 1); + ASSERT(temp, "out of memory"); for(i=0; inElements; i++) memcpy(((char*)temp)+(i*rb->itemSize), getRingData(rb, i), rb->itemSize); @@ -97,8 +97,8 @@ void appendRingData(RINGBUFFER *rb, void *value) void dequeueNFirstRingDatas(RINGBUFFER *rb, int n) { - ASSERT(n <= rb->nElements, "index out of range", 1); - ASSERT(0 <= n, "index out of range)", 1); + ASSERT(n <= rb->nElements, "index out of range"); + ASSERT(0 <= n, "index out of range"); rb->firstElement = (rb->firstElement+n)%rb->bufferSize; rb->nElements -= n; @@ -108,3 +108,10 @@ int ringBufferLength(RINGBUFFER *rb) { return rb->nElements; } + +void rotateRingBuffer(RINGBUFFER *rb, int n) +{ + ASSERT(n <= rb->nElements, "index out of range"); + ASSERT(0 <= n, "index out of range"); + rb->firstElement = (rb->firstElement+n)%rb->bufferSize; +} diff --git a/SimulationRuntime/c/math-support/ringbuffer.h b/SimulationRuntime/c/math-support/ringbuffer.h index 291cc91c85d..47af8674234 100644 --- a/SimulationRuntime/c/math-support/ringbuffer.h +++ b/SimulationRuntime/c/math-support/ringbuffer.h @@ -54,6 +54,8 @@ extern "C" { int ringBufferLength(RINGBUFFER *rb); + void rotateRingBuffer(RINGBUFFER *rb, int n); + #ifdef __cplusplus } #endif diff --git a/SimulationRuntime/c/util/error.h b/SimulationRuntime/c/util/error.h index 347daf1afea..4c48ee7efc5 100644 --- a/SimulationRuntime/c/util/error.h +++ b/SimulationRuntime/c/util/error.h @@ -59,16 +59,19 @@ extern const unsigned int LV_ZEROCROSSINGS; extern const unsigned int LV_DEBUG; extern const unsigned int LV_LOG_RES_INIT; -#define MSG(type, stream, ...) {fprintf(stream, "%s | [line] %d | [file] %s\n > ", type, __LINE__, __FILE__); fprintf(stream, __VA_ARGS__); fprintf(stream, "\n"); fflush(NULL);} -#define MSG_AL(stream, ...) {fprintf(stream, " > "); fprintf(stream, __VA_ARGS__); fprintf(stream, "\n"); fflush(NULL);} +#define MSG_H(type, stream) {fprintf(stream, "%s | [line] %d | [file] %s\n", type, __LINE__, __FILE__); fflush(NULL);} +#define MSG(type, stream, ...) {fprintf(stream, "%s > ", type); fprintf(stream, __VA_ARGS__); fprintf(stream, "\n"); fflush(NULL);} #define INFO(...) {MSG("info ", stdout, __VA_ARGS__);} -#define INFO_AL(...) {MSG_AL(stdout, __VA_ARGS__);} +#define INFO_AL(...) {MSG(" ", stdout, __VA_ARGS__);} + #define WARNING(...) {MSG("warning", stdout, __VA_ARGS__);} -#define THROW(...) {MSG("throw ", stderr, __VA_ARGS__); longjmp(globalJmpbuf, 1);} -#define ASSERT(exp, ...) {if(!exp){MSG("assert ", stderr, __VA_ARGS__); longjmp(globalJmpbuf, 1);}} +#define WARNING_AL(...) {INFO_AL(...);} + +#define THROW(...) {MSG_H("throw ", stderr); MSG(" ", stderr, __VA_ARGS__); longjmp(globalJmpbuf, 1);} +#define ASSERT(exp, ...) {if(!(exp)){MSG_H("assert ", stderr); MSG(" ", stderr, __VA_ARGS__); longjmp(globalJmpbuf, 1);}} -#define DEBUG_INFO(flag, ...) {if(flag & globalDebugFlags) INFO(__VA_ARGS__);} +#define DEBUG_INFO(flag, ...) {if(flag & globalDebugFlags){MSG_H("debug ", stdout); INFO(__VA_ARGS__);}} #define DEBUG_INFO_AL(flag, ...) {if(flag & globalDebugFlags) INFO_AL(__VA_ARGS__);} #ifdef __cplusplus