//=========================================================== // StreamTest // Tests for OpenLCB Stream support // // Bob Jacobsen 2010 //=========================================================== #include #include #include #include "logging.h" int inputRead() { return 1; } // demo I/O pins #define INPUT_PIN 9 #define OUTPUT_PIN 14 int producer_pin_record; // OpenLCB definitions #include "OpenLcbCanInterface.h" #include "OpenLcbCanBuffer.h" #include "NodeID.h" #include "EventID.h" // specific OpenLCB implementations #include "LinkControl.h" #include "Datagram.h" #include "OlcbStream.h" #include "Configuration.h" #include "NodeMemory.h" OpenLcbCanBuffer rxBuffer; // CAN receive buffer OpenLcbCanBuffer txBuffer; // CAN send buffer OpenLcbCanBuffer* ptxCAN; NodeID nodeid(2,3,4,5,6,7); // This node's ID LinkControl link(&txBuffer, &nodeid); unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from); unsigned int rcvCallback(uint8_t *rbuf, unsigned int length); extern "C" { uint32_t spaceUpperAddr(uint8_t space) { // return last valid address switch (space) { case 255: return 0x100; // CDI (data starts at zero) case 254: return RAMEND; // RAM from Arduino definition case 253: return 0x300; // Configuration } return (uint32_t)3; } }; /** * Get and put routines that * use a test memory space. */ uint8_t test_mem[200]; const uint8_t getRead(uint32_t address, int space) { return *(test_mem+address); } void getWrite(uint32_t address, int space, uint8_t val) { *(test_mem+address) = val; } void restart() {printf("restart called\n");} Datagram dg(&txBuffer, datagramCallback, &link); OlcbStream str(&txBuffer, rcvCallback, &link); Configuration cfg(&dg, &str, &getRead, &getWrite, &restart); unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from){ // invoked when a datagram arrives printf("consume datagram of length %d: ",length); for (int i = 0; i