Data collection core that utilises the nine ring buffer. Intended as the base of other data collection projects
Diff: record_ring/record_ring.cpp
- Revision:
- 0:79615902fcb0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/record_ring/record_ring.cpp Fri Jul 10 18:13:44 2015 +0000 @@ -0,0 +1,88 @@ +#include "mbed.h" +#include "record_ring.h" +/* +J.J.Trinder, based on original code for midi projects 199X +updateded sometime to the MBED +Yeh its atad klunky, it works and is useful to explain things to people... +*/ + +JRecordRing::JRecordRing() +{ + int bufsize = buff_size; + buf = new log_record [bufsize+1]; + // sp = ep = buf; + memset(buf,0,bufsize); +} + +JRecordRing::~JRecordRing() +{ +//not convinced this cleans up properly + delete [] buf; +} +/*======================================================================*/ +/* RingWriteToBuffer */ +/*======================================================================*/ +//add critical section ie disable interrupts while fiddling with buffers +int JRecordRing::RingWriteToBuffer(log_record n) +{ + // printf("WriteInBuffer%d",inCount); + __disable_irq(); // Disable Interrupts + +// do something that can't be interrupted + opBuffer[inIndex].timestamp = n.timestamp; + opBuffer[inIndex].ad1 = n.ad1; + opBuffer[inIndex].ad2 = n.ad2; + opBuffer[inIndex].ad3 = n.ad3; + opBuffer[inIndex].ad4 = n.ad4; + opBuffer[inIndex].ad5 = n.ad5; + opBuffer[inIndex].ad6 = n.ad6; + opBuffer[inIndex].count = n.count; + opBuffer[inIndex].count2 = n.count2; + opBuffer[inIndex].record_type = n.record_type; + opBuffer[inIndex].temperature = n.temperature; + inCount++; + inIndex++; + if (inIndex >= buff_size) + inIndex = 0; + __enable_irq(); // Enable Interrupts + //printf("ZWriteInBuffer%d\n",inCount); + return 0; +} + + +/*======================================================================*/ +/* Output whats remaining.... */ +/*======================================================================*/ +long JRecordRing::get_next_record(log_record * lr) +{ + + // long toSend; +#ifdef _PC + printf("\nCall in %x out %x count %x",inIndex,outIndex, inCount); +#endif + if (inCount == 0) + return -1; /* nowt to send */ + __disable_irq(); // Disable Interrupts + //lr. = opBuffer[outIndex]; + lr->timestamp = opBuffer[outIndex].timestamp; + lr->ad1 = opBuffer[outIndex].ad1; + lr->ad2 = opBuffer[outIndex].ad2; + lr->ad3 = opBuffer[outIndex].ad3; + lr->ad4 = opBuffer[outIndex].ad4; + lr->ad5 = opBuffer[outIndex].ad5; + lr->ad6 = opBuffer[outIndex].ad6; + lr->count = opBuffer[outIndex].count; + lr->count2 = opBuffer[outIndex].count2; + lr->temperature = opBuffer[outIndex].temperature; + lr->record_type = opBuffer[outIndex].record_type; + +#ifdef _PC + printf(" <%s> ",lr->count); +#endif + inCount--; + outIndex++; + if (outIndex >=buff_size) + outIndex = 0; + __enable_irq(); // Enable Interrupts + return 0; //check what we should return as now record in the arg +} \ No newline at end of file