Skip to content

Instantly share code, notes, and snippets.

@Lunaphied
Last active August 29, 2015 14:14
Show Gist options
  • Save Lunaphied/515db383f047c4245c42 to your computer and use it in GitHub Desktop.
Save Lunaphied/515db383f047c4245c42 to your computer and use it in GitHub Desktop.
// overflow.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
#include <list>
using namespace std;
#define BUFSIZ 4096
class PollAgent {
private:
unsigned char* m_memBase;
volatile unsigned long m_bucket;
// clear to send
bool m_bCTS;
public:
PollAgent(unsigned char* pMemBase) {
m_memBase = pMemBase;
// start a thread that examines m_bCTS
// if m_bCTS is true, then begin to log data in the payload bucket.
}
void setCTS() {
m_bCTS = true;
}
void clearCTS() {
m_bCTS = false;
}
void logData(volatile unsigned long data) {
m_bucket = data;
}
};
class DataReader {
private:
unsigned char m_buffer[BUFSIZ];
PollAgent* pPollAgent;
std::list<volatile unsigned char*>* m_pRegList;
public:
DataReader() {
memset(m_buffer, 0, sizeof(m_buffer));
pPollAgent = new PollAgent(m_buffer);
m_pRegList = new std::list<volatile unsigned char*>();
}
bool readRegisters() {
// for each registger in reglist, read it.
// if reading a register flags a state to Log the data, then pPollAgent->setCTS();
// at the conclusion of reading registers, turn of CTS pPollAgent->clearCTS();
// if the state of reads cause the Data Reader to be concluded with operations, return true, else
// return false;
return true;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
DataReader* pDataReader = new DataReader();
bool bDone = false;
while (!bDone) {
bDone = pDataReader->readRegisters();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment