I'm going a little deep on this because I'm seeing things which don't appear to fit that model all of the time.
One of my confusing situations shows up while monitoring the bottom line of the CDU - that with the blinking cursor (line 9). I would expect to see about two calls to that update every second (cursor-on / cursor-off) which is the case most of the time. However, every so often (maybe once every 5 blinks) there is an extra call to that update function.
This has lead me into the danger zone of trying to understand more fully what the dataflow looks like from DCS to my serial-port connected Arduino, and as a side effect, understanding better the program flow. Unfortunately, my C++ experience is very limited which is making my research more difficult.
I suppose my next route will take me into understanding the StringBuffer class defined within ExportStreamListener.h:
template < unsigned int LENGTH >
class StringBuffer : public ExportStreamListener {
private:
char receivingBuffer[LENGTH+1];
char userBuffer[LENGTH+1];
volatile bool receivingDirty;
bool userDirty;
void (*callback)(char*);
void setChar(unsigned int index, unsigned char value) {
// DCS-BIOS will occasionally send data even if it did not change
if (receivingBuffer[index] == value) return;
receivingBuffer[index] = value;
receivingDirty = true;
}
public:
StringBuffer(unsigned int address, void (*callback)(char*)) : ExportStreamListener(address, address+LENGTH) {
memset(receivingBuffer, ' ', LENGTH-1);
receivingBuffer[LENGTH] = '\0';
userBuffer[LENGTH] = '\0';
receivingDirty = false;
userDirty = false;
this->callback = callback;
}
virtual void onDcsBiosWrite(unsigned int address, unsigned int data) {
unsigned int index = address - firstAddressOfInterest;
setChar(index, ((char*)&data)[0] );
index++;
if (LENGTH > index) {
setChar(index, ((char*)&data)[1] );
}
}
virtual void onConsistentData() {
if (receivingDirty) {
noInterrupts();
memcpy(userBuffer, receivingBuffer, LENGTH);
receivingDirty = false;
userDirty = true;
interrupts();
}
}
bool hasUpdatedData() {
return userDirty;
}
char* getData() {
userDirty = false;
return userBuffer;
}
virtual void loop() {
if (hasUpdatedData()) {
if (callback) {
callback(getData());
}
}
}
};