From: <jac...@us...> - 2010-05-24 00:46:12
|
Revision: 194 http://openlcb.svn.sourceforge.net/openlcb/?rev=194&view=rev Author: jacobsen Date: 2010-05-24 00:46:06 +0000 (Mon, 24 May 2010) Log Message: ----------- test directories Added Paths: ----------- trunk/prototypes/C/tests/ trunk/prototypes/C/tests/interface/ trunk/prototypes/C/tests/interface/LEDuino/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-05-24 00:46:13
|
Revision: 194 http://openlcb.svn.sourceforge.net/openlcb/?rev=194&view=rev Author: jacobsen Date: 2010-05-24 00:46:06 +0000 (Mon, 24 May 2010) Log Message: ----------- test directories Added Paths: ----------- trunk/prototypes/C/tests/ trunk/prototypes/C/tests/interface/ trunk/prototypes/C/tests/interface/LEDuino/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-19 18:43:30
|
Revision: 353 http://openlcb.svn.sourceforge.net/openlcb/?rev=353&view=rev Author: jacobsen Date: 2010-06-19 18:43:24 +0000 (Sat, 19 Jun 2010) Log Message: ----------- consistent set of makefiles and fragments Added Paths: ----------- trunk/prototypes/C/Makefile trunk/prototypes/C/standard.mk Copied: trunk/prototypes/C/Makefile (from rev 329, trunk/prototypes/C/GNUmakefile) =================================================================== --- trunk/prototypes/C/Makefile (rev 0) +++ trunk/prototypes/C/Makefile 2010-06-19 18:43:24 UTC (rev 353) @@ -0,0 +1,20 @@ +binaries := +objects := +CPPFLAGS := -I$(PWD)/src/openlcb -I$(PWD)/scaffold $(CPPFLAGS) + +# default target: clean & rebuild +all: clean scaffold src tests + +# compile directories +src: FORCE + @make -C src CPPFLAGS="$(CPPFLAGS)" + +scaffold: FORCE + @make -C scaffold CPPFLAGS="$(CPPFLAGS)" + +tests: FORCE + @make -C tests CPPFLAGS="$(CPPFLAGS)" + +clean: FORCE + +FORCE: Added: trunk/prototypes/C/standard.mk =================================================================== --- trunk/prototypes/C/standard.mk (rev 0) +++ trunk/prototypes/C/standard.mk 2010-06-19 18:43:24 UTC (rev 353) @@ -0,0 +1,45 @@ +# Simple Makefile fragment included by convention + + +# CC_SUFFIX can be set to .cc or .cxx or .cpp +ifeq ($(CC_SUFFIX),) + CC_SUFFIX := .cpp +endif +ifeq ($(HH_SUFFIX),) + HH_SUFFIX := .hh +endif + +# List of C++ source files +SRCLIST := $(wildcard *$(CC_SUFFIX)) +# list of object (*.o) files to create +OBJLIST := $(foreach V,$(SRCLIST),$(V:$(CC_SUFFIX)=.o)) + +clean: + @$(RM) *.o lib*.a $(BINFILES) + +# Compile general C++ file +%.o: %.cpp + @$(CXX) $(CCFLAGS) $(CPPFLAGS) -c -o $(*F).o $(<F) + +# compile everything +compile: $(OBJLIST) + +# link a library from all object files +# use libtool in preference to ar +AR := libtool +ARFLAGS := -static -o +%.a: $(OBJLIST) + @$(AR) $(ARFLAGS) $@ $(OBJLIST) + +# Reset the default goal. +.DEFAULT_GOAL := + +# +# Notes: +# +# @ at the front of a command suppresses display unless -n is used +# +# +# The assumption is that a directory makes _either_ +# one library, or executables; not both. +# This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-19 18:43:31
|
Revision: 353 http://openlcb.svn.sourceforge.net/openlcb/?rev=353&view=rev Author: jacobsen Date: 2010-06-19 18:43:24 +0000 (Sat, 19 Jun 2010) Log Message: ----------- consistent set of makefiles and fragments Added Paths: ----------- trunk/prototypes/C/Makefile trunk/prototypes/C/standard.mk Copied: trunk/prototypes/C/Makefile (from rev 329, trunk/prototypes/C/GNUmakefile) =================================================================== --- trunk/prototypes/C/Makefile (rev 0) +++ trunk/prototypes/C/Makefile 2010-06-19 18:43:24 UTC (rev 353) @@ -0,0 +1,20 @@ +binaries := +objects := +CPPFLAGS := -I$(PWD)/src/openlcb -I$(PWD)/scaffold $(CPPFLAGS) + +# default target: clean & rebuild +all: clean scaffold src tests + +# compile directories +src: FORCE + @make -C src CPPFLAGS="$(CPPFLAGS)" + +scaffold: FORCE + @make -C scaffold CPPFLAGS="$(CPPFLAGS)" + +tests: FORCE + @make -C tests CPPFLAGS="$(CPPFLAGS)" + +clean: FORCE + +FORCE: Added: trunk/prototypes/C/standard.mk =================================================================== --- trunk/prototypes/C/standard.mk (rev 0) +++ trunk/prototypes/C/standard.mk 2010-06-19 18:43:24 UTC (rev 353) @@ -0,0 +1,45 @@ +# Simple Makefile fragment included by convention + + +# CC_SUFFIX can be set to .cc or .cxx or .cpp +ifeq ($(CC_SUFFIX),) + CC_SUFFIX := .cpp +endif +ifeq ($(HH_SUFFIX),) + HH_SUFFIX := .hh +endif + +# List of C++ source files +SRCLIST := $(wildcard *$(CC_SUFFIX)) +# list of object (*.o) files to create +OBJLIST := $(foreach V,$(SRCLIST),$(V:$(CC_SUFFIX)=.o)) + +clean: + @$(RM) *.o lib*.a $(BINFILES) + +# Compile general C++ file +%.o: %.cpp + @$(CXX) $(CCFLAGS) $(CPPFLAGS) -c -o $(*F).o $(<F) + +# compile everything +compile: $(OBJLIST) + +# link a library from all object files +# use libtool in preference to ar +AR := libtool +ARFLAGS := -static -o +%.a: $(OBJLIST) + @$(AR) $(ARFLAGS) $@ $(OBJLIST) + +# Reset the default goal. +.DEFAULT_GOAL := + +# +# Notes: +# +# @ at the front of a command suppresses display unless -n is used +# +# +# The assumption is that a directory makes _either_ +# one library, or executables; not both. +# This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 17:36:10
|
Revision: 377 http://openlcb.svn.sourceforge.net/openlcb/?rev=377&view=rev Author: jacobsen Date: 2010-06-22 17:36:04 +0000 (Tue, 22 Jun 2010) Log Message: ----------- working datagram code Modified Paths: -------------- trunk/prototypes/C/tests/DatagramTest.cpp Removed Paths: ------------- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h Deleted: trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp =================================================================== --- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp 2010-06-22 17:36:04 UTC (rev 377) @@ -1,272 +0,0 @@ -// makes this an Arduino file -#include "WConstants.h" - -// The following line is needed because the Arduino environment -// won't search a library directory unless the library is included -// from the top level file (this file) -#include "CAN.h" - -#include "OpenLcbCan.h" -#include "OpenLcbCanInterface.h" -#include "OpenLcbCanBuffer.h" -#include "NodeID.h" -#include "EventID.h" - - -// for definiton, see -// http://openlcb.sf.net/trunk/documents/can/index.html -// -// In the following masks, bit 0 of the frame is 0x10000000L -// - -// bit 1 -#define MASK_FRAME_TYPE 0x08000000L - -// bit 17-28 -#define MASK_SRC_ALIAS 0x00000FFFL - -// bit 2-16 -#define MASK_VARIABLE_FIELD 0x07FFF000L -#define SHIFT_VARIABLE_FIELD 12 - -// bit 2-4 -#define MASK_OPENLCB_FORMAT 0x7000 -#define SHIFT_OPENLCB_FORMAT 12 - - void OpenLcbCanBuffer::init() { - // set default header: extended frame w low priority - flags.extended = 1; - id = 0x1FFFFFFF; // all bits in header default to 1 - } - - // start of basic message structure - - void OpenLcbCanBuffer::setSourceAlias(unsigned int a) { - id &= ~MASK_SRC_ALIAS; - id = id | (a & MASK_SRC_ALIAS); - } - - unsigned int OpenLcbCanBuffer::getSourceAlias() { - return id & MASK_SRC_ALIAS; - } - - void OpenLcbCanBuffer::setFrameTypeCAN() { - id &= ~MASK_FRAME_TYPE; - } - - bool OpenLcbCanBuffer::isFrameTypeCAN() { - return (id & MASK_FRAME_TYPE) == 0x00000000L; - } - - void OpenLcbCanBuffer::setFrameTypeOpenLcb() { - id |= MASK_FRAME_TYPE; - } - - bool OpenLcbCanBuffer::isFrameTypeOpenLcb() { - return (id & MASK_FRAME_TYPE) == MASK_FRAME_TYPE; - } - - void OpenLcbCanBuffer::setVariableField(unsigned int f) { - id &= ~MASK_VARIABLE_FIELD; - id |= ((f << SHIFT_VARIABLE_FIELD) & MASK_VARIABLE_FIELD) ; - } - - unsigned int OpenLcbCanBuffer::getVariableField() { - return (id & MASK_VARIABLE_FIELD) >> SHIFT_VARIABLE_FIELD; - } - - // end of basic message structure - - // start of CAN-level messages - -#define RIM_VAR_FIELD 0x7FFF - - void OpenLcbCanBuffer::setCIM(int i, unsigned int testval, unsigned int alias) { - init(); - setFrameTypeCAN(); - setVariableField( ((i & 7) << 12) | (testval & 0xFFF) ); - setSourceAlias(alias); - length=0; - } - - bool OpenLcbCanBuffer::isCIM() { - return isFrameTypeCAN() && (getVariableField()&0x7000) <= 0x5FFF; - } - - void OpenLcbCanBuffer::setRIM(unsigned int alias) { - init(); - setFrameTypeCAN(); - setVariableField(RIM_VAR_FIELD); - setSourceAlias(alias); - length=0; - } - - bool OpenLcbCanBuffer::isRIM() { - return isFrameTypeCAN() && getVariableField() == RIM_VAR_FIELD; - } - - - // end of CAN-level messages - - // start of OpenLCB format support - - int OpenLcbCanBuffer::getOpenLcbFormat() { - return (getVariableField() & MASK_OPENLCB_FORMAT) >> SHIFT_OPENLCB_FORMAT; - } - - void OpenLcbCanBuffer::setOpenLcbFormat(int i) { - setVariableField( (i << SHIFT_OPENLCB_FORMAT) & MASK_OPENLCB_FORMAT); - } - - bool OpenLcbCanBuffer::isOpenLcbMtiFormat() { - return ( ( getOpenLcbFormat() & 0x4 ) == 0x0); - } - - bool OpenLcbCanBuffer::isOpenLcDestIdFormat() { - return ( getOpenLcbFormat() == 0x6); - } - - bool OpenLcbCanBuffer::isOpenLcbStreamIdFormat() { - return ( getOpenLcbFormat() == 0x7); - } - - bool OpenLcbCanBuffer::isOpenLcbMTI(unsigned int mti) { - return isFrameTypeOpenLcb() - && isOpenLcbMtiFormat() - && ( getVariableField() == mti ); - } - - // end of OpenLCB format support - - // start of OpenLCB messages - - void OpenLcbCanBuffer::setPCEventReport(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PCER); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isPCEventReport() { - return isOpenLcbMTI(MTI_PCER); - } - - void OpenLcbCanBuffer::setInitializationComplete(unsigned int alias, NodeID* nid) { - nodeAlias = alias; - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_INITIALIZATION_COMPLETE); - setSourceAlias(nodeAlias); - length=6; - data[0] = nid->val[0]; - data[1] = nid->val[1]; - data[2] = nid->val[2]; - data[3] = nid->val[3]; - data[4] = nid->val[4]; - data[5] = nid->val[5]; - } - - bool OpenLcbCanBuffer::isInitializationComplete() { - return isOpenLcbMTI(MTI_INITIALIZATION_COMPLETE); - } - - void OpenLcbCanBuffer::getEventID(EventID* evt) { - evt->val[0] = data[0]; - evt->val[1] = data[1]; - evt->val[2] = data[2]; - evt->val[3] = data[3]; - evt->val[4] = data[4]; - evt->val[5] = data[5]; - evt->val[6] = data[6]; - evt->val[7] = data[7]; - } - - void OpenLcbCanBuffer::getNodeID(NodeID* nid) { - nid->val[0] = data[0]; - nid->val[1] = data[1]; - nid->val[2] = data[2]; - nid->val[3] = data[3]; - nid->val[4] = data[4]; - nid->val[5] = data[5]; - } - - bool OpenLcbCanBuffer::isVerifyNID() { - return isOpenLcbMTI(MTI_VERIFY_NID); - } - - void OpenLcbCanBuffer::setVerifiedNID(NodeID* nid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_VERIFIED_NID); - setSourceAlias(nodeAlias); - length=6; - data[0] = nid->val[0]; - data[1] = nid->val[1]; - data[2] = nid->val[2]; - data[3] = nid->val[3]; - data[4] = nid->val[4]; - data[5] = nid->val[5]; - } - - bool OpenLcbCanBuffer::isIdentifyConsumers() { - return isOpenLcbMTI(MTI_IDENTIFY_CONSUMERS); - } - - void OpenLcbCanBuffer::setConsumerIdentified(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_CONSUMER_IDENTIFIED); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - void OpenLcbCanBuffer::setConsumerIdentifyRange(EventID* eid, EventID* mask) { - // does send a message, but not complete yet - RGJ 2009-06-14 - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_CONSUMER_IDENTIFY_RANGE); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isIdentifyProducers() { - return isOpenLcbMTI(MTI_IDENTIFY_PRODUCERS); - } - - void OpenLcbCanBuffer::setProducerIdentified(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PRODUCER_IDENTIFIED); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - void OpenLcbCanBuffer::setProducerIdentifyRange(EventID* eid, EventID* mask) { - // does send a message, but not complete yet - RGJ 2009-06-14 - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PRODUCER_IDENTIFY_RANGE); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isIdentifyEvents() { - return isOpenLcbMTI(MTI_IDENTIFY_EVENTS); - } - - void OpenLcbCanBuffer::loadFromEid(EventID* eid) { - data[0] = eid->val[0]; - data[1] = eid->val[1]; - data[2] = eid->val[2]; - data[3] = eid->val[3]; - data[4] = eid->val[4]; - data[5] = eid->val[5]; - data[6] = eid->val[6]; - data[7] = eid->val[7]; - } \ No newline at end of file Deleted: trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h =================================================================== --- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h 2010-06-22 17:36:04 UTC (rev 377) @@ -1,97 +0,0 @@ -#ifndef OpenLcbCanBuffer_h -#define OpenLcbCanBuffer_h - -class NodeID; -class EventID; -#include "OpenLcbCanInterface.h" - -/** - * Class to handle transforming OpenLCB (S9.6) frames to/from std CAN frames. - * <p> - * We're trying to localize the formating of frames to/from the node here, - * so that only this class needs to change when/if the wire protocol changes. - */ - class OpenLcbCanBuffer : public CanInterfaceBuffer { - public: - - // Initialize a buffer for transmission - void init(); - - // start of basic message structure - - void setFrameTypeCAN(); - bool isFrameTypeCAN(); - - void setFrameTypeOpenLcb(); - bool isFrameTypeOpenLcb(); - - void setVariableField(unsigned int f); - unsigned int getVariableField(); - - void setSourceAlias(unsigned int a); - unsigned int getSourceAlias(); - - // end of basic message structure - - // start of CAN-level messages - - void setCIM(int i, unsigned int testval, unsigned int alias); - bool isCIM(); - - void setRIM(unsigned int alias); - bool isRIM(); - - // end of CAN-level messages - - // start of OpenLCB format support - - int getOpenLcbFormat(); - void setOpenLcbFormat(int i); - - bool isOpenLcbMtiFormat(); - bool isOpenLcDestIdFormat(); - bool isOpenLcbStreamIdFormat(); - - bool isOpenLcbMTI(unsigned int mti); - - // end of OpenLCB format support - - // start of OpenLCB messages - - void setInitializationComplete(unsigned int alias, NodeID* nid); - bool isInitializationComplete(); - - void setPCEventReport(EventID* eid); - bool isPCEventReport(); - - void getEventID(EventID* evt); - void getNodeID(NodeID* nid); - - bool isVerifyNID(); - void setVerifiedNID(NodeID* nid); - - bool isIdentifyConsumers(); - - void setConsumerIdentified(EventID* eid); - - // Mask uses an EventID data structure; 1 bit means mask out when routing - void setConsumerIdentifyRange(EventID* eid, EventID* mask); - - bool isIdentifyProducers(); - - void setProducerIdentified(EventID* eid); - - // Mask uses an EventID data structure; 1 bit means mask out when routing - void setProducerIdentifyRange(EventID* eid, EventID* mask); - - bool isIdentifyEvents(); - - - private: - unsigned int nodeAlias; // Initialization complete sets, all later use - - // service routine to copy content (0-7) to a previously-allocated Eid - void loadFromEid(EventID* eid); -}; - -#endif Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 17:36:04 UTC (rev 377) @@ -37,11 +37,15 @@ LinkControl link(&txBuffer, &nodeid); -void datagramCallback(int index){ +unsigned int resultcode; +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ // invoked when a datagram arrives - printf("consume %d\n",index); + printf("consume datagram of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + return resultcode; // return pre-ordained result } -Datagram dg(&txBuffer, &nodeid, datagramCallback); +Datagram dg(&txBuffer, datagramCallback); /** * This setup is just for testing @@ -78,16 +82,24 @@ // periodic processing of any datagram frames dg.check(); - // Demo: handle possible production of events from pin + // Demo: handle possible production of datagram from pin int val = inputRead(); if (producer_pin_record != val) { producer_pin_record = val; if (producer_pin_record == 0) { printf("send datagram A\n"); - //p.produce(0); + uint8_t* b = dg.getTransmitBuffer(); + dg.sendTransmitBuffer(5, 0xBFD); } else { printf("send datagram B\n"); - //p.produce(1); + uint8_t* b = dg.getTransmitBuffer(); + + // check that only one possible + if (dg.getTransmitBuffer() != 0) { + printf("error: should not have been possible to get buffer again\n"); + } + for (int i = 0; i<15; i++) b[i] = 16+i; + dg.sendTransmitBuffer(15, 0xBFD); } } } @@ -111,18 +123,125 @@ printf("setup done\n"); doLoop(1000); // long enough for timeout printf("one second done\n\n"); + printf("--------------\n"); - printf("queue short datagram, expect 1 reply\n"); - b.id = 0x1824F00F; - b.length = (uint8_t)8; - b.data[0]=1;b.data[1]=2;b.data[2]=3;b.data[3]=4;b.data[4]=5;b.data[5]=6;b.data[6]=7;b.data[7]=8; - queueTestMessage(&b); - doLoop(100); + printf("datagram reply for another, expect it doesn't clear buffer\n"); + b.id = 0x19111BFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + if (dg.getTransmitBuffer() == 0) { + printf("OK\n"); + } else { + printf("Error: should be still in use\n"); + } + printf("\n"); + + printf("datagram reply for this, expect it clears buffer\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + if ( dg.getTransmitBuffer() != 0) { + printf("OK, send 0 length datagram\n"); + dg.sendTransmitBuffer(0, 0xBFF); + loop(); + printf("handle datagram ack reply\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + } else { + printf("Error: still in use\n"); + } + + printf("send long datagram to test nak reply\n"); + uint8_t* d = dg.getTransmitBuffer(); + if ( d != 0) { + for (int i = 0; i<23; i++) d[i] = (uint8_t)(32+i); + dg.sendTransmitBuffer(23, 0xBFF); + doLoop(4); + } else { + printf("Error: buffer still in use"); + } + printf("datagram nak reply for different node, ignore\n"); + b.id = 0x1E111BFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("datagram nak reply from different node, ignore\n"); + b.id = 0x1E6ba111; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("handle datagram nak reply by resending\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("handle 2nd datagram nak reply by resending again\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("final positive reply clears buffer\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); + printf("--------------\n"); + printf("Start to test receiving datagrams\n"); + printf("\n"); + + printf("Receive single fragment datagram OK\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("Receive three fragment datagram OK\n"); + resultcode = 0; + b.id = 0x1C6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x50;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + b.id = 0x1C6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x60;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x70;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("Receive single fragment datagram fail\n"); + resultcode = 0x1234; + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("test ends\n"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 17:36:10
|
Revision: 377 http://openlcb.svn.sourceforge.net/openlcb/?rev=377&view=rev Author: jacobsen Date: 2010-06-22 17:36:04 +0000 (Tue, 22 Jun 2010) Log Message: ----------- working datagram code Modified Paths: -------------- trunk/prototypes/C/tests/DatagramTest.cpp Removed Paths: ------------- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h Deleted: trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp =================================================================== --- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/scaffold/OpenLcbCanBuffer.cpp 2010-06-22 17:36:04 UTC (rev 377) @@ -1,272 +0,0 @@ -// makes this an Arduino file -#include "WConstants.h" - -// The following line is needed because the Arduino environment -// won't search a library directory unless the library is included -// from the top level file (this file) -#include "CAN.h" - -#include "OpenLcbCan.h" -#include "OpenLcbCanInterface.h" -#include "OpenLcbCanBuffer.h" -#include "NodeID.h" -#include "EventID.h" - - -// for definiton, see -// http://openlcb.sf.net/trunk/documents/can/index.html -// -// In the following masks, bit 0 of the frame is 0x10000000L -// - -// bit 1 -#define MASK_FRAME_TYPE 0x08000000L - -// bit 17-28 -#define MASK_SRC_ALIAS 0x00000FFFL - -// bit 2-16 -#define MASK_VARIABLE_FIELD 0x07FFF000L -#define SHIFT_VARIABLE_FIELD 12 - -// bit 2-4 -#define MASK_OPENLCB_FORMAT 0x7000 -#define SHIFT_OPENLCB_FORMAT 12 - - void OpenLcbCanBuffer::init() { - // set default header: extended frame w low priority - flags.extended = 1; - id = 0x1FFFFFFF; // all bits in header default to 1 - } - - // start of basic message structure - - void OpenLcbCanBuffer::setSourceAlias(unsigned int a) { - id &= ~MASK_SRC_ALIAS; - id = id | (a & MASK_SRC_ALIAS); - } - - unsigned int OpenLcbCanBuffer::getSourceAlias() { - return id & MASK_SRC_ALIAS; - } - - void OpenLcbCanBuffer::setFrameTypeCAN() { - id &= ~MASK_FRAME_TYPE; - } - - bool OpenLcbCanBuffer::isFrameTypeCAN() { - return (id & MASK_FRAME_TYPE) == 0x00000000L; - } - - void OpenLcbCanBuffer::setFrameTypeOpenLcb() { - id |= MASK_FRAME_TYPE; - } - - bool OpenLcbCanBuffer::isFrameTypeOpenLcb() { - return (id & MASK_FRAME_TYPE) == MASK_FRAME_TYPE; - } - - void OpenLcbCanBuffer::setVariableField(unsigned int f) { - id &= ~MASK_VARIABLE_FIELD; - id |= ((f << SHIFT_VARIABLE_FIELD) & MASK_VARIABLE_FIELD) ; - } - - unsigned int OpenLcbCanBuffer::getVariableField() { - return (id & MASK_VARIABLE_FIELD) >> SHIFT_VARIABLE_FIELD; - } - - // end of basic message structure - - // start of CAN-level messages - -#define RIM_VAR_FIELD 0x7FFF - - void OpenLcbCanBuffer::setCIM(int i, unsigned int testval, unsigned int alias) { - init(); - setFrameTypeCAN(); - setVariableField( ((i & 7) << 12) | (testval & 0xFFF) ); - setSourceAlias(alias); - length=0; - } - - bool OpenLcbCanBuffer::isCIM() { - return isFrameTypeCAN() && (getVariableField()&0x7000) <= 0x5FFF; - } - - void OpenLcbCanBuffer::setRIM(unsigned int alias) { - init(); - setFrameTypeCAN(); - setVariableField(RIM_VAR_FIELD); - setSourceAlias(alias); - length=0; - } - - bool OpenLcbCanBuffer::isRIM() { - return isFrameTypeCAN() && getVariableField() == RIM_VAR_FIELD; - } - - - // end of CAN-level messages - - // start of OpenLCB format support - - int OpenLcbCanBuffer::getOpenLcbFormat() { - return (getVariableField() & MASK_OPENLCB_FORMAT) >> SHIFT_OPENLCB_FORMAT; - } - - void OpenLcbCanBuffer::setOpenLcbFormat(int i) { - setVariableField( (i << SHIFT_OPENLCB_FORMAT) & MASK_OPENLCB_FORMAT); - } - - bool OpenLcbCanBuffer::isOpenLcbMtiFormat() { - return ( ( getOpenLcbFormat() & 0x4 ) == 0x0); - } - - bool OpenLcbCanBuffer::isOpenLcDestIdFormat() { - return ( getOpenLcbFormat() == 0x6); - } - - bool OpenLcbCanBuffer::isOpenLcbStreamIdFormat() { - return ( getOpenLcbFormat() == 0x7); - } - - bool OpenLcbCanBuffer::isOpenLcbMTI(unsigned int mti) { - return isFrameTypeOpenLcb() - && isOpenLcbMtiFormat() - && ( getVariableField() == mti ); - } - - // end of OpenLCB format support - - // start of OpenLCB messages - - void OpenLcbCanBuffer::setPCEventReport(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PCER); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isPCEventReport() { - return isOpenLcbMTI(MTI_PCER); - } - - void OpenLcbCanBuffer::setInitializationComplete(unsigned int alias, NodeID* nid) { - nodeAlias = alias; - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_INITIALIZATION_COMPLETE); - setSourceAlias(nodeAlias); - length=6; - data[0] = nid->val[0]; - data[1] = nid->val[1]; - data[2] = nid->val[2]; - data[3] = nid->val[3]; - data[4] = nid->val[4]; - data[5] = nid->val[5]; - } - - bool OpenLcbCanBuffer::isInitializationComplete() { - return isOpenLcbMTI(MTI_INITIALIZATION_COMPLETE); - } - - void OpenLcbCanBuffer::getEventID(EventID* evt) { - evt->val[0] = data[0]; - evt->val[1] = data[1]; - evt->val[2] = data[2]; - evt->val[3] = data[3]; - evt->val[4] = data[4]; - evt->val[5] = data[5]; - evt->val[6] = data[6]; - evt->val[7] = data[7]; - } - - void OpenLcbCanBuffer::getNodeID(NodeID* nid) { - nid->val[0] = data[0]; - nid->val[1] = data[1]; - nid->val[2] = data[2]; - nid->val[3] = data[3]; - nid->val[4] = data[4]; - nid->val[5] = data[5]; - } - - bool OpenLcbCanBuffer::isVerifyNID() { - return isOpenLcbMTI(MTI_VERIFY_NID); - } - - void OpenLcbCanBuffer::setVerifiedNID(NodeID* nid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_VERIFIED_NID); - setSourceAlias(nodeAlias); - length=6; - data[0] = nid->val[0]; - data[1] = nid->val[1]; - data[2] = nid->val[2]; - data[3] = nid->val[3]; - data[4] = nid->val[4]; - data[5] = nid->val[5]; - } - - bool OpenLcbCanBuffer::isIdentifyConsumers() { - return isOpenLcbMTI(MTI_IDENTIFY_CONSUMERS); - } - - void OpenLcbCanBuffer::setConsumerIdentified(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_CONSUMER_IDENTIFIED); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - void OpenLcbCanBuffer::setConsumerIdentifyRange(EventID* eid, EventID* mask) { - // does send a message, but not complete yet - RGJ 2009-06-14 - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_CONSUMER_IDENTIFY_RANGE); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isIdentifyProducers() { - return isOpenLcbMTI(MTI_IDENTIFY_PRODUCERS); - } - - void OpenLcbCanBuffer::setProducerIdentified(EventID* eid) { - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PRODUCER_IDENTIFIED); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - void OpenLcbCanBuffer::setProducerIdentifyRange(EventID* eid, EventID* mask) { - // does send a message, but not complete yet - RGJ 2009-06-14 - init(); - setFrameTypeOpenLcb(); - setVariableField(MTI_PRODUCER_IDENTIFY_RANGE); - setSourceAlias(nodeAlias); - length=8; - loadFromEid(eid); - } - - bool OpenLcbCanBuffer::isIdentifyEvents() { - return isOpenLcbMTI(MTI_IDENTIFY_EVENTS); - } - - void OpenLcbCanBuffer::loadFromEid(EventID* eid) { - data[0] = eid->val[0]; - data[1] = eid->val[1]; - data[2] = eid->val[2]; - data[3] = eid->val[3]; - data[4] = eid->val[4]; - data[5] = eid->val[5]; - data[6] = eid->val[6]; - data[7] = eid->val[7]; - } \ No newline at end of file Deleted: trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h =================================================================== --- trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/scaffold/OpenLcbCanBuffer.h 2010-06-22 17:36:04 UTC (rev 377) @@ -1,97 +0,0 @@ -#ifndef OpenLcbCanBuffer_h -#define OpenLcbCanBuffer_h - -class NodeID; -class EventID; -#include "OpenLcbCanInterface.h" - -/** - * Class to handle transforming OpenLCB (S9.6) frames to/from std CAN frames. - * <p> - * We're trying to localize the formating of frames to/from the node here, - * so that only this class needs to change when/if the wire protocol changes. - */ - class OpenLcbCanBuffer : public CanInterfaceBuffer { - public: - - // Initialize a buffer for transmission - void init(); - - // start of basic message structure - - void setFrameTypeCAN(); - bool isFrameTypeCAN(); - - void setFrameTypeOpenLcb(); - bool isFrameTypeOpenLcb(); - - void setVariableField(unsigned int f); - unsigned int getVariableField(); - - void setSourceAlias(unsigned int a); - unsigned int getSourceAlias(); - - // end of basic message structure - - // start of CAN-level messages - - void setCIM(int i, unsigned int testval, unsigned int alias); - bool isCIM(); - - void setRIM(unsigned int alias); - bool isRIM(); - - // end of CAN-level messages - - // start of OpenLCB format support - - int getOpenLcbFormat(); - void setOpenLcbFormat(int i); - - bool isOpenLcbMtiFormat(); - bool isOpenLcDestIdFormat(); - bool isOpenLcbStreamIdFormat(); - - bool isOpenLcbMTI(unsigned int mti); - - // end of OpenLCB format support - - // start of OpenLCB messages - - void setInitializationComplete(unsigned int alias, NodeID* nid); - bool isInitializationComplete(); - - void setPCEventReport(EventID* eid); - bool isPCEventReport(); - - void getEventID(EventID* evt); - void getNodeID(NodeID* nid); - - bool isVerifyNID(); - void setVerifiedNID(NodeID* nid); - - bool isIdentifyConsumers(); - - void setConsumerIdentified(EventID* eid); - - // Mask uses an EventID data structure; 1 bit means mask out when routing - void setConsumerIdentifyRange(EventID* eid, EventID* mask); - - bool isIdentifyProducers(); - - void setProducerIdentified(EventID* eid); - - // Mask uses an EventID data structure; 1 bit means mask out when routing - void setProducerIdentifyRange(EventID* eid, EventID* mask); - - bool isIdentifyEvents(); - - - private: - unsigned int nodeAlias; // Initialization complete sets, all later use - - // service routine to copy content (0-7) to a previously-allocated Eid - void loadFromEid(EventID* eid); -}; - -#endif Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 05:05:58 UTC (rev 376) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 17:36:04 UTC (rev 377) @@ -37,11 +37,15 @@ LinkControl link(&txBuffer, &nodeid); -void datagramCallback(int index){ +unsigned int resultcode; +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ // invoked when a datagram arrives - printf("consume %d\n",index); + printf("consume datagram of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + return resultcode; // return pre-ordained result } -Datagram dg(&txBuffer, &nodeid, datagramCallback); +Datagram dg(&txBuffer, datagramCallback); /** * This setup is just for testing @@ -78,16 +82,24 @@ // periodic processing of any datagram frames dg.check(); - // Demo: handle possible production of events from pin + // Demo: handle possible production of datagram from pin int val = inputRead(); if (producer_pin_record != val) { producer_pin_record = val; if (producer_pin_record == 0) { printf("send datagram A\n"); - //p.produce(0); + uint8_t* b = dg.getTransmitBuffer(); + dg.sendTransmitBuffer(5, 0xBFD); } else { printf("send datagram B\n"); - //p.produce(1); + uint8_t* b = dg.getTransmitBuffer(); + + // check that only one possible + if (dg.getTransmitBuffer() != 0) { + printf("error: should not have been possible to get buffer again\n"); + } + for (int i = 0; i<15; i++) b[i] = 16+i; + dg.sendTransmitBuffer(15, 0xBFD); } } } @@ -111,18 +123,125 @@ printf("setup done\n"); doLoop(1000); // long enough for timeout printf("one second done\n\n"); + printf("--------------\n"); - printf("queue short datagram, expect 1 reply\n"); - b.id = 0x1824F00F; - b.length = (uint8_t)8; - b.data[0]=1;b.data[1]=2;b.data[2]=3;b.data[3]=4;b.data[4]=5;b.data[5]=6;b.data[6]=7;b.data[7]=8; - queueTestMessage(&b); - doLoop(100); + printf("datagram reply for another, expect it doesn't clear buffer\n"); + b.id = 0x19111BFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + if (dg.getTransmitBuffer() == 0) { + printf("OK\n"); + } else { + printf("Error: should be still in use\n"); + } + printf("\n"); + + printf("datagram reply for this, expect it clears buffer\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + if ( dg.getTransmitBuffer() != 0) { + printf("OK, send 0 length datagram\n"); + dg.sendTransmitBuffer(0, 0xBFF); + loop(); + printf("handle datagram ack reply\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + } else { + printf("Error: still in use\n"); + } + + printf("send long datagram to test nak reply\n"); + uint8_t* d = dg.getTransmitBuffer(); + if ( d != 0) { + for (int i = 0; i<23; i++) d[i] = (uint8_t)(32+i); + dg.sendTransmitBuffer(23, 0xBFF); + doLoop(4); + } else { + printf("Error: buffer still in use"); + } + printf("datagram nak reply for different node, ignore\n"); + b.id = 0x1E111BFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("datagram nak reply from different node, ignore\n"); + b.id = 0x1E6ba111; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("handle datagram nak reply by resending\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("handle 2nd datagram nak reply by resending again\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4d; + queueTestMessage(&b); + doLoop(10); + printf("final positive reply clears buffer\n"); + b.id = 0x1E6baBFF; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); + printf("--------------\n"); + printf("Start to test receiving datagrams\n"); + printf("\n"); + + printf("Receive single fragment datagram OK\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("Receive three fragment datagram OK\n"); + resultcode = 0; + b.id = 0x1C6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x50;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + b.id = 0x1C6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x60;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x70;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("Receive single fragment datagram fail\n"); + resultcode = 0x1234; + b.id = 0x1D6baBFD; + b.length = (uint8_t)4; + b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + printf("test ends\n"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 17:48:26
|
Revision: 380 http://openlcb.svn.sourceforge.net/openlcb/?rev=380&view=rev Author: jacobsen Date: 2010-06-22 17:48:20 +0000 (Tue, 22 Jun 2010) Log Message: ----------- semi-auto tests Modified Paths: -------------- trunk/prototypes/C/Makefile Added Paths: ----------- trunk/prototypes/C/TODO trunk/prototypes/C/tests/results/ trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt trunk/prototypes/C/tests/results/DatagramTest.out.txt trunk/prototypes/C/tests/results/README Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 17:41:43 UTC (rev 379) +++ trunk/prototypes/C/Makefile 2010-06-22 17:48:20 UTC (rev 380) @@ -18,3 +18,8 @@ clean: FORCE FORCE: + +# run known tests; silent if no errors +run: all + @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt Added: trunk/prototypes/C/TODO =================================================================== --- trunk/prototypes/C/TODO (rev 0) +++ trunk/prototypes/C/TODO 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,5 @@ + +<> vs "" in #include + +Makefile (esp tests/Makefile) doesn't have a general link rule; +needs to know how to pass library search path Added: trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,74 @@ +new key alias +-------------- +Starting CanMrrlcbTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +queue_xmt_wait: [182af6ba] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826f6ba] 01 02 03 04 05 06 07 08 +produce p1 +queue_xmt_wait: [182af6ba] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [1826f6ba] 08 07 06 05 04 03 02 01 +one second done + +trigger RIM conflict +can_get_frame: [17fff6ba] +new key alias +queue_xmt_wait: [10002e8d] +queue_xmt_wait: [11003e8d] +queue_xmt_wait: [12004e8d] +queue_xmt_wait: [13005e8d] +queue_xmt_wait: [14006e8d] +queue_xmt_wait: [15007e8d] +alias assigned +queue_xmt_wait: [17fffe8d] +queue_xmt_wait: [1808fe8d] 02 03 04 05 06 07 + +trigger CIM conflict +can_get_frame: [110036ba] + +queue Verify Node +can_get_frame: [180af00f] 02 03 04 05 06 07 +queue_xmt_wait: [180bfe8d] 02 03 04 05 06 07 + +queue Request Consumers, expect 1 reply +can_get_frame: [1824f00f] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826fe8d] 01 02 03 04 05 06 07 08 + +queue Request Consumers, no reply +can_get_frame: [1824f00f] 01 0c 03 04 05 06 07 08 + +queue Request Producers, expect 1 reply +can_get_frame: [1828f00f] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [182afe8d] 08 07 06 05 04 03 02 01 + +queue Request Producers, no reply +can_get_frame: [1828f00f] 08 0c 06 05 04 03 02 01 + +queue Request Events, expect 4 replies +can_get_frame: [182bf00f] 02 03 04 05 06 07 +queue_xmt_wait: [182afe8d] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826fe8d] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [182afe8d] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [1826fe8d] 08 07 06 05 04 03 02 01 + +queue Request Events, no reply +can_get_frame: [182bf00f] 19 03 04 05 06 07 + +queue P/C Event Transfer, no match +can_get_frame: [182df00f] 00 0c 06 05 04 03 02 01 + +queue P/C Event Transfer, match event 1 +can_get_frame: [182df00f] 08 07 06 05 04 03 02 01 +consume 1 + +test ends Property changes on: trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/DatagramTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/DatagramTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,74 @@ +new key alias +-------------- +Starting CanMrrlcbTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +send datagram B +queue_xmt_wait: [1cbfd6ba] 10 11 12 13 14 15 16 17 +queue_xmt_wait: [1dbfd6ba] 18 19 1a 1b 1c 1d 1e +one second done + +-------------- +datagram reply for another, expect it doesn't clear buffer +can_get_frame: [19111bfd] 4c +OK + +datagram reply for this, expect it clears buffer +can_get_frame: [1e6babfd] 4c +OK, send 0 length datagram +queue_xmt_wait: [1dbff6ba] +handle datagram ack reply +can_get_frame: [1e6babff] 4c + +send long datagram to test nak reply +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +datagram nak reply for different node, ignore +can_get_frame: [1e111bff] 4d +datagram nak reply from different node, ignore +can_get_frame: [1e6ba111] 4d +handle datagram nak reply by resending +can_get_frame: [1e6babff] 4d +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +handle 2nd datagram nak reply by resending again +can_get_frame: [1e6babff] 4d +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +final positive reply clears buffer +can_get_frame: [1e6babff] 4c + +-------------- +Start to test receiving datagrams + +Receive single fragment datagram OK +can_get_frame: [1d6babfd] 40 41 42 43 +consume datagram of length 4: 40 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4c + +Receive three fragment datagram OK +can_get_frame: [1c6babfd] 50 41 42 43 +can_get_frame: [1c6babfd] 60 41 42 43 +can_get_frame: [1d6babfd] 70 41 42 43 +consume datagram of length 12: 50 41 42 43 60 41 42 43 70 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4c + +Receive single fragment datagram fail +can_get_frame: [1d6babfd] 40 41 42 43 +consume datagram of length 4: 40 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4d 12 34 + +test ends Property changes on: trunk/prototypes/C/tests/results/DatagramTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/README =================================================================== --- trunk/prototypes/C/tests/results/README (rev 0) +++ trunk/prototypes/C/tests/results/README 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,6 @@ + +This directory contains reference outputs from +running the test programs. e.g. at top level: + +make && ./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 17:48:26
|
Revision: 380 http://openlcb.svn.sourceforge.net/openlcb/?rev=380&view=rev Author: jacobsen Date: 2010-06-22 17:48:20 +0000 (Tue, 22 Jun 2010) Log Message: ----------- semi-auto tests Modified Paths: -------------- trunk/prototypes/C/Makefile Added Paths: ----------- trunk/prototypes/C/TODO trunk/prototypes/C/tests/results/ trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt trunk/prototypes/C/tests/results/DatagramTest.out.txt trunk/prototypes/C/tests/results/README Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 17:41:43 UTC (rev 379) +++ trunk/prototypes/C/Makefile 2010-06-22 17:48:20 UTC (rev 380) @@ -18,3 +18,8 @@ clean: FORCE FORCE: + +# run known tests; silent if no errors +run: all + @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt Added: trunk/prototypes/C/TODO =================================================================== --- trunk/prototypes/C/TODO (rev 0) +++ trunk/prototypes/C/TODO 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,5 @@ + +<> vs "" in #include + +Makefile (esp tests/Makefile) doesn't have a general link rule; +needs to know how to pass library search path Added: trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,74 @@ +new key alias +-------------- +Starting CanMrrlcbTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +queue_xmt_wait: [182af6ba] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826f6ba] 01 02 03 04 05 06 07 08 +produce p1 +queue_xmt_wait: [182af6ba] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [1826f6ba] 08 07 06 05 04 03 02 01 +one second done + +trigger RIM conflict +can_get_frame: [17fff6ba] +new key alias +queue_xmt_wait: [10002e8d] +queue_xmt_wait: [11003e8d] +queue_xmt_wait: [12004e8d] +queue_xmt_wait: [13005e8d] +queue_xmt_wait: [14006e8d] +queue_xmt_wait: [15007e8d] +alias assigned +queue_xmt_wait: [17fffe8d] +queue_xmt_wait: [1808fe8d] 02 03 04 05 06 07 + +trigger CIM conflict +can_get_frame: [110036ba] + +queue Verify Node +can_get_frame: [180af00f] 02 03 04 05 06 07 +queue_xmt_wait: [180bfe8d] 02 03 04 05 06 07 + +queue Request Consumers, expect 1 reply +can_get_frame: [1824f00f] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826fe8d] 01 02 03 04 05 06 07 08 + +queue Request Consumers, no reply +can_get_frame: [1824f00f] 01 0c 03 04 05 06 07 08 + +queue Request Producers, expect 1 reply +can_get_frame: [1828f00f] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [182afe8d] 08 07 06 05 04 03 02 01 + +queue Request Producers, no reply +can_get_frame: [1828f00f] 08 0c 06 05 04 03 02 01 + +queue Request Events, expect 4 replies +can_get_frame: [182bf00f] 02 03 04 05 06 07 +queue_xmt_wait: [182afe8d] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [1826fe8d] 01 02 03 04 05 06 07 08 +queue_xmt_wait: [182afe8d] 08 07 06 05 04 03 02 01 +queue_xmt_wait: [1826fe8d] 08 07 06 05 04 03 02 01 + +queue Request Events, no reply +can_get_frame: [182bf00f] 19 03 04 05 06 07 + +queue P/C Event Transfer, no match +can_get_frame: [182df00f] 00 0c 06 05 04 03 02 01 + +queue P/C Event Transfer, match event 1 +can_get_frame: [182df00f] 08 07 06 05 04 03 02 01 +consume 1 + +test ends Property changes on: trunk/prototypes/C/tests/results/CanMrrlcbTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/DatagramTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/DatagramTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,74 @@ +new key alias +-------------- +Starting CanMrrlcbTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +send datagram B +queue_xmt_wait: [1cbfd6ba] 10 11 12 13 14 15 16 17 +queue_xmt_wait: [1dbfd6ba] 18 19 1a 1b 1c 1d 1e +one second done + +-------------- +datagram reply for another, expect it doesn't clear buffer +can_get_frame: [19111bfd] 4c +OK + +datagram reply for this, expect it clears buffer +can_get_frame: [1e6babfd] 4c +OK, send 0 length datagram +queue_xmt_wait: [1dbff6ba] +handle datagram ack reply +can_get_frame: [1e6babff] 4c + +send long datagram to test nak reply +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +datagram nak reply for different node, ignore +can_get_frame: [1e111bff] 4d +datagram nak reply from different node, ignore +can_get_frame: [1e6ba111] 4d +handle datagram nak reply by resending +can_get_frame: [1e6babff] 4d +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +handle 2nd datagram nak reply by resending again +can_get_frame: [1e6babff] 4d +queue_xmt_wait: [1cbff6ba] 20 21 22 23 24 25 26 27 +queue_xmt_wait: [1cbff6ba] 28 29 2a 2b 2c 2d 2e 2f +queue_xmt_wait: [1dbff6ba] 30 31 32 33 34 35 36 +final positive reply clears buffer +can_get_frame: [1e6babff] 4c + +-------------- +Start to test receiving datagrams + +Receive single fragment datagram OK +can_get_frame: [1d6babfd] 40 41 42 43 +consume datagram of length 4: 40 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4c + +Receive three fragment datagram OK +can_get_frame: [1c6babfd] 50 41 42 43 +can_get_frame: [1c6babfd] 60 41 42 43 +can_get_frame: [1d6babfd] 70 41 42 43 +consume datagram of length 12: 50 41 42 43 60 41 42 43 70 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4c + +Receive single fragment datagram fail +can_get_frame: [1d6babfd] 40 41 42 43 +consume datagram of length 4: 40 41 42 43 +queue_xmt_wait: [1ebfd6ba] 4d 12 34 + +test ends Property changes on: trunk/prototypes/C/tests/results/DatagramTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/README =================================================================== --- trunk/prototypes/C/tests/results/README (rev 0) +++ trunk/prototypes/C/tests/results/README 2010-06-22 17:48:20 UTC (rev 380) @@ -0,0 +1,6 @@ + +This directory contains reference outputs from +running the test programs. e.g. at top level: + +make && ./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 18:52:16
|
Revision: 381 http://openlcb.svn.sourceforge.net/openlcb/?rev=381&view=rev Author: jacobsen Date: 2010-06-22 18:52:10 +0000 (Tue, 22 Jun 2010) Log Message: ----------- finish handling src ID Modified Paths: -------------- trunk/prototypes/C/src/openlcb/Datagram.cpp trunk/prototypes/C/src/openlcb/Datagram.h trunk/prototypes/C/tests/DatagramTest.cpp trunk/prototypes/C/tests/results/DatagramTest.out.txt Modified: trunk/prototypes/C/src/openlcb/Datagram.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-22 18:52:10 UTC (rev 381) @@ -3,12 +3,14 @@ #include "OpenLcbCan.h" #include "OpenLcbCanBuffer.h" +#include "LinkControl.h" #include "Datagram.h" #include "logging.h" -Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length)) { +Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* ln) { buffer = b; + link = ln; callback = cb; reserved = false; sendcount = -1; @@ -60,9 +62,8 @@ } void Datagram::receivedFrame(OpenLcbCanBuffer* rcv) { - // TODO: Proper handling checking of our address (dummy is 0x6ba now) // check for datagram reply, which can free buffer - if ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_NON_DATAGRAM, 0x6ba) ) + if ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_NON_DATAGRAM, link->getAlias()) ) && (dest == rcv->getSourceAlias()) && (rcv->length == 1) ) { // for this node, check meaning @@ -78,17 +79,16 @@ } } // check for datagram fragment received - // TODO: Proper handling checking of our address (dummy is 0x6ba now) // TODO: Check for correct source (prevent overlapping reception) if ( (true) // saved for address check - && ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM, 0x6ba) ) - || (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, 0x6ba) ) ) ) { + && ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM, link->getAlias()) ) + || (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, link->getAlias()) ) ) ) { // this is a datagram fragment, store into the buffer for (int i=0; i<rcv->length; i++) { *(rptr++) = rcv->data[i]; } // is the end of the datagram? - if (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, 0x6ba) ) { + if (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, link->getAlias()) ) { // unsigned int length = rptr-rbuf; // callback Modified: trunk/prototypes/C/src/openlcb/Datagram.h =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-22 18:52:10 UTC (rev 381) @@ -12,6 +12,7 @@ #define DATAGRAM_LENGTH 70 class OpenLcbCanBuffer; +class LinkControl; class Datagram { public: @@ -41,11 +42,12 @@ */ void receivedFrame(OpenLcbCanBuffer* rcv); - Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length)); + Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* link); private: OpenLcbCanBuffer* buffer; - + LinkControl* link; + uint8_t tbuf[DATAGRAM_LENGTH]; int sendcount; int resendcount; Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 18:52:10 UTC (rev 381) @@ -1,5 +1,5 @@ //=========================================================== -// DatagramTests +// DatagramTest // Tests for OpenLCB Datagrams support // // Bob Jacobsen 2010 @@ -45,7 +45,7 @@ printf("\n"); return resultcode; // return pre-ordained result } -Datagram dg(&txBuffer, datagramCallback); +Datagram dg(&txBuffer, datagramCallback, &link); /** * This setup is just for testing @@ -53,7 +53,7 @@ void setup() { // show we've started to run - printf("Starting CanMrrlcbTest\n"); + printf("Starting DatagramTest\n"); // Initialize OpenLCB CAN connection OpenLcb_can_init(); @@ -107,6 +107,11 @@ } + +// ======================================= +// end of demo program, start of test code +// ======================================= + void doLoop(int n) { for (int i = 0; i < n; i++) { loop(); Modified: trunk/prototypes/C/tests/results/DatagramTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 18:52:10 UTC (rev 381) @@ -1,6 +1,6 @@ new key alias -------------- -Starting CanMrrlcbTest +Starting DatagramTest OpenLcb_can_init new key alias setup done This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 18:52:17
|
Revision: 381 http://openlcb.svn.sourceforge.net/openlcb/?rev=381&view=rev Author: jacobsen Date: 2010-06-22 18:52:10 +0000 (Tue, 22 Jun 2010) Log Message: ----------- finish handling src ID Modified Paths: -------------- trunk/prototypes/C/src/openlcb/Datagram.cpp trunk/prototypes/C/src/openlcb/Datagram.h trunk/prototypes/C/tests/DatagramTest.cpp trunk/prototypes/C/tests/results/DatagramTest.out.txt Modified: trunk/prototypes/C/src/openlcb/Datagram.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-22 18:52:10 UTC (rev 381) @@ -3,12 +3,14 @@ #include "OpenLcbCan.h" #include "OpenLcbCanBuffer.h" +#include "LinkControl.h" #include "Datagram.h" #include "logging.h" -Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length)) { +Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* ln) { buffer = b; + link = ln; callback = cb; reserved = false; sendcount = -1; @@ -60,9 +62,8 @@ } void Datagram::receivedFrame(OpenLcbCanBuffer* rcv) { - // TODO: Proper handling checking of our address (dummy is 0x6ba now) // check for datagram reply, which can free buffer - if ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_NON_DATAGRAM, 0x6ba) ) + if ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_NON_DATAGRAM, link->getAlias()) ) && (dest == rcv->getSourceAlias()) && (rcv->length == 1) ) { // for this node, check meaning @@ -78,17 +79,16 @@ } } // check for datagram fragment received - // TODO: Proper handling checking of our address (dummy is 0x6ba now) // TODO: Check for correct source (prevent overlapping reception) if ( (true) // saved for address check - && ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM, 0x6ba) ) - || (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, 0x6ba) ) ) ) { + && ( (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM, link->getAlias()) ) + || (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, link->getAlias()) ) ) ) { // this is a datagram fragment, store into the buffer for (int i=0; i<rcv->length; i++) { *(rptr++) = rcv->data[i]; } // is the end of the datagram? - if (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, 0x6ba) ) { + if (rcv->isOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST, link->getAlias()) ) { // unsigned int length = rptr-rbuf; // callback Modified: trunk/prototypes/C/src/openlcb/Datagram.h =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-22 18:52:10 UTC (rev 381) @@ -12,6 +12,7 @@ #define DATAGRAM_LENGTH 70 class OpenLcbCanBuffer; +class LinkControl; class Datagram { public: @@ -41,11 +42,12 @@ */ void receivedFrame(OpenLcbCanBuffer* rcv); - Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length)); + Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* link); private: OpenLcbCanBuffer* buffer; - + LinkControl* link; + uint8_t tbuf[DATAGRAM_LENGTH]; int sendcount; int resendcount; Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-22 18:52:10 UTC (rev 381) @@ -1,5 +1,5 @@ //=========================================================== -// DatagramTests +// DatagramTest // Tests for OpenLCB Datagrams support // // Bob Jacobsen 2010 @@ -45,7 +45,7 @@ printf("\n"); return resultcode; // return pre-ordained result } -Datagram dg(&txBuffer, datagramCallback); +Datagram dg(&txBuffer, datagramCallback, &link); /** * This setup is just for testing @@ -53,7 +53,7 @@ void setup() { // show we've started to run - printf("Starting CanMrrlcbTest\n"); + printf("Starting DatagramTest\n"); // Initialize OpenLCB CAN connection OpenLcb_can_init(); @@ -107,6 +107,11 @@ } + +// ======================================= +// end of demo program, start of test code +// ======================================= + void doLoop(int n) { for (int i = 0; i < n; i++) { loop(); Modified: trunk/prototypes/C/tests/results/DatagramTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 17:48:20 UTC (rev 380) +++ trunk/prototypes/C/tests/results/DatagramTest.out.txt 2010-06-22 18:52:10 UTC (rev 381) @@ -1,6 +1,6 @@ new key alias -------------- -Starting CanMrrlcbTest +Starting DatagramTest OpenLcb_can_init new key alias setup done This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 18:53:29
|
Revision: 382 http://openlcb.svn.sourceforge.net/openlcb/?rev=382&view=rev Author: jacobsen Date: 2010-06-22 18:53:23 +0000 (Tue, 22 Jun 2010) Log Message: ----------- placeholder files for stream implementaiton Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/tests/results/StreamTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 18:52:10 UTC (rev 381) +++ trunk/prototypes/C/Makefile 2010-06-22 18:53:23 UTC (rev 382) @@ -21,5 +21,6 @@ # run known tests; silent if no errors run: all + @./tests/StreamTest | diff - tests/results/StreamTest.out.txt + @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt - @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-22 18:52:10 UTC (rev 381) +++ trunk/prototypes/C/tests/Makefile 2010-06-22 18:53:23 UTC (rev 382) @@ -2,14 +2,17 @@ include ../standard.mk -BINFILES := CanMrrlcbTest DatagramTest +BINFILES := StreamTest DatagramTest CanMrrlcbTest default: clean compile $(BINFILES) +CanMrrlcbTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold CanMrrlcbTest.o -o CanMrrlcbTest + DatagramTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold DatagramTest.o -o DatagramTest -CanMrrlcbTest: - @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold CanMrrlcbTest.o -o CanMrrlcbTest +StreamTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold StreamTest.o -o StreamTest Added: trunk/prototypes/C/tests/results/StreamTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/StreamTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/StreamTest.out.txt 2010-06-22 18:53:23 UTC (rev 382) @@ -0,0 +1,19 @@ +new key alias +-------------- +Starting StreamTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +one second done + +-------------- +test ends Property changes on: trunk/prototypes/C/tests/results/StreamTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-22 18:53:29
|
Revision: 382 http://openlcb.svn.sourceforge.net/openlcb/?rev=382&view=rev Author: jacobsen Date: 2010-06-22 18:53:23 +0000 (Tue, 22 Jun 2010) Log Message: ----------- placeholder files for stream implementaiton Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/tests/results/StreamTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 18:52:10 UTC (rev 381) +++ trunk/prototypes/C/Makefile 2010-06-22 18:53:23 UTC (rev 382) @@ -21,5 +21,6 @@ # run known tests; silent if no errors run: all + @./tests/StreamTest | diff - tests/results/StreamTest.out.txt + @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt - @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-22 18:52:10 UTC (rev 381) +++ trunk/prototypes/C/tests/Makefile 2010-06-22 18:53:23 UTC (rev 382) @@ -2,14 +2,17 @@ include ../standard.mk -BINFILES := CanMrrlcbTest DatagramTest +BINFILES := StreamTest DatagramTest CanMrrlcbTest default: clean compile $(BINFILES) +CanMrrlcbTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold CanMrrlcbTest.o -o CanMrrlcbTest + DatagramTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold DatagramTest.o -o DatagramTest -CanMrrlcbTest: - @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold CanMrrlcbTest.o -o CanMrrlcbTest +StreamTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold StreamTest.o -o StreamTest Added: trunk/prototypes/C/tests/results/StreamTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/StreamTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/StreamTest.out.txt 2010-06-22 18:53:23 UTC (rev 382) @@ -0,0 +1,19 @@ +new key alias +-------------- +Starting StreamTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +one second done + +-------------- +test ends Property changes on: trunk/prototypes/C/tests/results/StreamTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-23 04:24:42
|
Revision: 385 http://openlcb.svn.sourceforge.net/openlcb/?rev=385&view=rev Author: jacobsen Date: 2010-06-23 04:24:36 +0000 (Wed, 23 Jun 2010) Log Message: ----------- scaffold for configuration Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/src/openlcb/Configuration.cpp trunk/prototypes/C/src/openlcb/Configuration.h trunk/prototypes/C/tests/ConfigurationTest.cpp trunk/prototypes/C/tests/results/ConfigurationTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 18:54:40 UTC (rev 384) +++ trunk/prototypes/C/Makefile 2010-06-23 04:24:36 UTC (rev 385) @@ -21,6 +21,7 @@ # run known tests; silent if no errors run: all + @./tests/ConfigurationTest | diff - tests/results/ConfigurationTest.out.txt @./tests/StreamTest | diff - tests/results/StreamTest.out.txt @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt Added: trunk/prototypes/C/src/openlcb/Configuration.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.cpp (rev 0) +++ trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,134 @@ +// makes this an Arduino file +#include "WConstants.h" + +#include "Configuration.h" +#include "Datagram.h" +#include "Stream.h" + +#include "logging.h" + + +#define CONFIGURATION_DATAGRAM_CODE 0x23 + +// define the operation codes, full byte +#define CFG_CMD_WRITE 0x00 +#define CFG_CMD_READ 0x40 +#define CFG_CMD_OPERATION 0x80 + +#define CFG_CMD_READ_REPLY 0x50 + +#define CFG_CMD_GET_CONFIG 0x80 +#define CFG_CMD_GET_CONFIG_REPLY 0x82 +#define CFG_CMD_GET_ADD_SPACE_INFO 0x84 +#define CFG_CMD_GET_ADD_SPACE_INFO_REPLY 0x86 +#define CFG_CMD_LOCK 0x88 +#define CFG_CMD_LOCK_REPLY 0x8A +#define CFG_CMD_GET_UNIQUEID 0x8C +#define CFG_CMD_GET_UNIQUEID_REPLY 0x8E + +#define CFG_CMD_FREEZE 0xA0 +#define CFG_CMD_INDICATE 0xA4 +#define CFG_CMD_RESET 0xA8 +#define CFG_CMD_FACTORY_RESET 0xAC + +/** + * Structure: Requests come in via + * receiveDatagram. Results (if any) are stored in a + * buffer, and check() then sends it when possible. + * + * TODO: No stream implementation yet. + * TODO: Uses an extra buffer, which it would be good to avoid, + * but I've included it now to not make assumptions about + * Datagram use & structure + */ + +Configuration::Configuration(Datagram* d, Stream *s) { + dg = d; + str = s; + request = false; +} + +void Configuration::check() { + if (!request) return; + // have a request pending + switch (buffer[1]&0xC0) { + case CFG_CMD_READ: + processRead(buffer, length); + break; + case CFG_CMD_WRITE: + processWrite(buffer, length); + break; + case CFG_CMD_OPERATION: + processCmd(buffer, length); + break; + } +} + +int Configuration::receivedDatagram(uint8_t* data, int ln) { + // decode whether this is a configuration request + if (data[0] != CONFIGURATION_DATAGRAM_CODE) return 0; + // yes, copy to our buffer + length = ln; + for (int i = 0; i<length; i++) + buffer[i] = *(data++); + // mark as ready + request = true; + return 0; +} + +uint32_t Configuration::getAddress(uint8_t* data) { + uint32_t val = 0; + val |= (data[2]<<24); + val |= (data[3]<<16); + val |= (data[4]<<8); + val |= (data[5]); + return val; +} + +// -1 means stream +int Configuration::decodeLen(uint8_t* data) { + int count = data[1]&0x7; + int val; + if ( count <= 6) val = 1 << count; + else val = -1; + + return val; +} +int Configuration::decodeSpace(uint8_t* data) { + int val; + switch (data[1]&0x18) { + case 0x00: + val = 0xFF; + break; + case 0x08: + val = 0xFE; + break; + case 0x10: + val = 0xFD; + break; + case 0x18: + val = data[6]; + break; + } + return val; +} + +void Configuration::processRead(uint8_t* data, int length) { + printf(" processRead start=0x%x len=%d space=%x\n", getAddress(data), decodeLen(data), decodeSpace(data) ); + // see if we can get datagram buffer to reply + uint8_t* d = dg->getTransmitBuffer(); + if (d == 0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=0xAA; d[1]=0xBB; + dg->sendTransmitBuffer(2, 0x123); +} + +void Configuration::processWrite(uint8_t* data, int length) { + printf(" processWrite start=0x%x space=%x\n", getAddress(data), decodeSpace(data) ); +} + +void Configuration::processCmd(uint8_t* data, int length) { + printf(" processCmd\n"); +} + Property changes on: trunk/prototypes/C/src/openlcb/Configuration.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/src/openlcb/Configuration.h =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.h (rev 0) +++ trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,38 @@ +#ifndef Configuration_h +#define Configuration_h + +/** + * Class for handling Configuration protocol + * + * + */ +#include <stdint.h> + +#include "Datagram.h" +class Stream; + +class Configuration { + public: + + Configuration(Datagram* dg, Stream *str); + + void check(); + int receivedDatagram(uint8_t* data, int length); + + private: + void processRead(uint8_t* data, int length); + void processWrite(uint8_t* data, int length); + void processCmd(uint8_t* data, int length); + + Datagram* dg; + Stream* str; + uint8_t buffer[DATAGRAM_LENGTH]; + int length; + bool request; + + uint32_t getAddress(uint8_t* data); + int decodeLen(uint8_t* data); + int decodeSpace(uint8_t* data); +}; + +#endif Property changes on: trunk/prototypes/C/src/openlcb/Configuration.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/ConfigurationTest.cpp =================================================================== --- trunk/prototypes/C/tests/ConfigurationTest.cpp (rev 0) +++ trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,191 @@ +//=========================================================== +// StreamTest +// Tests for OpenLCB Stream support +// +// Bob Jacobsen 2010 +//=========================================================== +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> + +#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 "Stream.h" +#include "Configuration.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 rcvCallback(uint8_t *rbuf, unsigned int length); + +Datagram dg(&txBuffer, datagramCallback, &link); +Stream str(&txBuffer, rcvCallback, &link); +Configuration cfg(&dg, &str); + +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ + // invoked when a datagram arrives + printf("consume datagram of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + // pass to consumers + cfg.receivedDatagram(rbuf, length); + + return 0; // return pre-ordained result +} + +unsigned int resultcode; +unsigned int rcvCallback(uint8_t *rbuf, unsigned int length){ + // invoked when a stream frame arrives + printf("consume frame of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + return resultcode; // return pre-ordained result +} + +/** + * This setup is just for testing + */ +void setup() +{ + // show we've started to run + printf("Starting ConfigurationTest\n"); + + // Initialize OpenLCB CAN connection + OpenLcb_can_init(); + + // Initialize OpenLCB CAN link controller + link.reset(); +} + +void loop() { + // check for input frames, acquire if present + bool rcvFramePresent = OpenLcb_can_get_frame(&rxBuffer); + + // process link control first + link.check(); + if (rcvFramePresent) { + // received a frame, ask if changes link state + link.receivedFrame(&rxBuffer); + } + + // if link is initialized, higher-level operations possible + if (link.linkInitialized()) { + // if frame present, pass to frame handlers + if (rcvFramePresent) { + dg.receivedFrame(&rxBuffer); + str.receivedFrame(&rxBuffer); + } + // periodic processing of any datagram frames + dg.check(); + str.check(); + cfg.check(); + } + + +} + + +// ======================================= +// end of demo program, start of test code +// ======================================= + +void doLoop(int n) { + for (int i = 0; i < n; i++) { + loop(); + } +} + +OpenLcbCanBuffer b; + +int main( int argc, const char* argv[] ) +{ + // run the code for a test + printf("--------------\n"); + setup(); + printf("setup done\n"); + doLoop(1000); // long enough for timeout + printf("one second done\n\n"); + printf("--------------\n"); + + + printf("Test Read Operation\n"); + printf("\n"); + + printf(" Single fragment datagram for short read\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x23;b.data[1]=0x63; // header + b.data[2]=0x12;b.data[3]=0x34;b.data[4]=0x56;b.data[5]=0x78; // address + b.data[6]=0x08; // count + queueTestMessage(&b); + doLoop(10); + printf("\n"); + + +// printf("Receive three fragment datagram OK\n"); +// resultcode = 0; +// b.id = 0x1C6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x50;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// b.id = 0x1C6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x60;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// b.id = 0x1D6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x70;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// printf("\n"); +// +// printf("Receive single fragment datagram fail\n"); +// resultcode = 0x1234; +// b.id = 0x1D6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// printf("\n"); + + printf("test ends\n"); +} + +// to test (messages in JMRI format) +// send a CIM frame which should get a RIM: [110036ba] +// then a RIM which should restart sequence: [17fff6ba] + +// (these need to be redone) +// send a Verify Node frame of [180Af00f] 2 3 4 5 6 7 +// send a Request Consumers frame of [1824F00F] 1 2 3 4 5 6 7 8 +// send a Request Producers frame of [1828F00F] 8 7 6 5 4 3 2 1 +// send a Request Events frame of [182BF00F] 2 3 4 5 6 7 + +// produce an event with [182DF00F] 8 7 6 5 4 3 2 1 Property changes on: trunk/prototypes/C/tests/ConfigurationTest.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-22 18:54:40 UTC (rev 384) +++ trunk/prototypes/C/tests/Makefile 2010-06-23 04:24:36 UTC (rev 385) @@ -2,7 +2,7 @@ include ../standard.mk -BINFILES := StreamTest DatagramTest CanMrrlcbTest +BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest default: clean compile $(BINFILES) @@ -15,4 +15,6 @@ StreamTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold StreamTest.o -o StreamTest +ConfigurationTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold ConfigurationTest.o -o ConfigurationTest Added: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/ConfigurationTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,28 @@ +new key alias +-------------- +Starting ConfigurationTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +one second done + +-------------- +Test Read Operation + + Single fragment datagram for short read +can_get_frame: [1d6babfd] 23 63 12 34 56 78 08 +consume datagram of length 7: 23 63 12 34 56 78 8 +queue_xmt_wait: [1ebfd6ba] 4c + processRead start=0x12345678 len=8 space=ff +queue_xmt_wait: [1d1236ba] aa bb + +test ends Property changes on: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-23 04:24:42
|
Revision: 385 http://openlcb.svn.sourceforge.net/openlcb/?rev=385&view=rev Author: jacobsen Date: 2010-06-23 04:24:36 +0000 (Wed, 23 Jun 2010) Log Message: ----------- scaffold for configuration Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/src/openlcb/Configuration.cpp trunk/prototypes/C/src/openlcb/Configuration.h trunk/prototypes/C/tests/ConfigurationTest.cpp trunk/prototypes/C/tests/results/ConfigurationTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-22 18:54:40 UTC (rev 384) +++ trunk/prototypes/C/Makefile 2010-06-23 04:24:36 UTC (rev 385) @@ -21,6 +21,7 @@ # run known tests; silent if no errors run: all + @./tests/ConfigurationTest | diff - tests/results/ConfigurationTest.out.txt @./tests/StreamTest | diff - tests/results/StreamTest.out.txt @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt Added: trunk/prototypes/C/src/openlcb/Configuration.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.cpp (rev 0) +++ trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,134 @@ +// makes this an Arduino file +#include "WConstants.h" + +#include "Configuration.h" +#include "Datagram.h" +#include "Stream.h" + +#include "logging.h" + + +#define CONFIGURATION_DATAGRAM_CODE 0x23 + +// define the operation codes, full byte +#define CFG_CMD_WRITE 0x00 +#define CFG_CMD_READ 0x40 +#define CFG_CMD_OPERATION 0x80 + +#define CFG_CMD_READ_REPLY 0x50 + +#define CFG_CMD_GET_CONFIG 0x80 +#define CFG_CMD_GET_CONFIG_REPLY 0x82 +#define CFG_CMD_GET_ADD_SPACE_INFO 0x84 +#define CFG_CMD_GET_ADD_SPACE_INFO_REPLY 0x86 +#define CFG_CMD_LOCK 0x88 +#define CFG_CMD_LOCK_REPLY 0x8A +#define CFG_CMD_GET_UNIQUEID 0x8C +#define CFG_CMD_GET_UNIQUEID_REPLY 0x8E + +#define CFG_CMD_FREEZE 0xA0 +#define CFG_CMD_INDICATE 0xA4 +#define CFG_CMD_RESET 0xA8 +#define CFG_CMD_FACTORY_RESET 0xAC + +/** + * Structure: Requests come in via + * receiveDatagram. Results (if any) are stored in a + * buffer, and check() then sends it when possible. + * + * TODO: No stream implementation yet. + * TODO: Uses an extra buffer, which it would be good to avoid, + * but I've included it now to not make assumptions about + * Datagram use & structure + */ + +Configuration::Configuration(Datagram* d, Stream *s) { + dg = d; + str = s; + request = false; +} + +void Configuration::check() { + if (!request) return; + // have a request pending + switch (buffer[1]&0xC0) { + case CFG_CMD_READ: + processRead(buffer, length); + break; + case CFG_CMD_WRITE: + processWrite(buffer, length); + break; + case CFG_CMD_OPERATION: + processCmd(buffer, length); + break; + } +} + +int Configuration::receivedDatagram(uint8_t* data, int ln) { + // decode whether this is a configuration request + if (data[0] != CONFIGURATION_DATAGRAM_CODE) return 0; + // yes, copy to our buffer + length = ln; + for (int i = 0; i<length; i++) + buffer[i] = *(data++); + // mark as ready + request = true; + return 0; +} + +uint32_t Configuration::getAddress(uint8_t* data) { + uint32_t val = 0; + val |= (data[2]<<24); + val |= (data[3]<<16); + val |= (data[4]<<8); + val |= (data[5]); + return val; +} + +// -1 means stream +int Configuration::decodeLen(uint8_t* data) { + int count = data[1]&0x7; + int val; + if ( count <= 6) val = 1 << count; + else val = -1; + + return val; +} +int Configuration::decodeSpace(uint8_t* data) { + int val; + switch (data[1]&0x18) { + case 0x00: + val = 0xFF; + break; + case 0x08: + val = 0xFE; + break; + case 0x10: + val = 0xFD; + break; + case 0x18: + val = data[6]; + break; + } + return val; +} + +void Configuration::processRead(uint8_t* data, int length) { + printf(" processRead start=0x%x len=%d space=%x\n", getAddress(data), decodeLen(data), decodeSpace(data) ); + // see if we can get datagram buffer to reply + uint8_t* d = dg->getTransmitBuffer(); + if (d == 0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=0xAA; d[1]=0xBB; + dg->sendTransmitBuffer(2, 0x123); +} + +void Configuration::processWrite(uint8_t* data, int length) { + printf(" processWrite start=0x%x space=%x\n", getAddress(data), decodeSpace(data) ); +} + +void Configuration::processCmd(uint8_t* data, int length) { + printf(" processCmd\n"); +} + Property changes on: trunk/prototypes/C/src/openlcb/Configuration.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/src/openlcb/Configuration.h =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.h (rev 0) +++ trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,38 @@ +#ifndef Configuration_h +#define Configuration_h + +/** + * Class for handling Configuration protocol + * + * + */ +#include <stdint.h> + +#include "Datagram.h" +class Stream; + +class Configuration { + public: + + Configuration(Datagram* dg, Stream *str); + + void check(); + int receivedDatagram(uint8_t* data, int length); + + private: + void processRead(uint8_t* data, int length); + void processWrite(uint8_t* data, int length); + void processCmd(uint8_t* data, int length); + + Datagram* dg; + Stream* str; + uint8_t buffer[DATAGRAM_LENGTH]; + int length; + bool request; + + uint32_t getAddress(uint8_t* data); + int decodeLen(uint8_t* data); + int decodeSpace(uint8_t* data); +}; + +#endif Property changes on: trunk/prototypes/C/src/openlcb/Configuration.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/ConfigurationTest.cpp =================================================================== --- trunk/prototypes/C/tests/ConfigurationTest.cpp (rev 0) +++ trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,191 @@ +//=========================================================== +// StreamTest +// Tests for OpenLCB Stream support +// +// Bob Jacobsen 2010 +//=========================================================== +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> + +#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 "Stream.h" +#include "Configuration.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 rcvCallback(uint8_t *rbuf, unsigned int length); + +Datagram dg(&txBuffer, datagramCallback, &link); +Stream str(&txBuffer, rcvCallback, &link); +Configuration cfg(&dg, &str); + +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ + // invoked when a datagram arrives + printf("consume datagram of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + // pass to consumers + cfg.receivedDatagram(rbuf, length); + + return 0; // return pre-ordained result +} + +unsigned int resultcode; +unsigned int rcvCallback(uint8_t *rbuf, unsigned int length){ + // invoked when a stream frame arrives + printf("consume frame of length %d: ",length); + for (int i = 0; i<length; i++) printf("%x ", rbuf[i]); + printf("\n"); + return resultcode; // return pre-ordained result +} + +/** + * This setup is just for testing + */ +void setup() +{ + // show we've started to run + printf("Starting ConfigurationTest\n"); + + // Initialize OpenLCB CAN connection + OpenLcb_can_init(); + + // Initialize OpenLCB CAN link controller + link.reset(); +} + +void loop() { + // check for input frames, acquire if present + bool rcvFramePresent = OpenLcb_can_get_frame(&rxBuffer); + + // process link control first + link.check(); + if (rcvFramePresent) { + // received a frame, ask if changes link state + link.receivedFrame(&rxBuffer); + } + + // if link is initialized, higher-level operations possible + if (link.linkInitialized()) { + // if frame present, pass to frame handlers + if (rcvFramePresent) { + dg.receivedFrame(&rxBuffer); + str.receivedFrame(&rxBuffer); + } + // periodic processing of any datagram frames + dg.check(); + str.check(); + cfg.check(); + } + + +} + + +// ======================================= +// end of demo program, start of test code +// ======================================= + +void doLoop(int n) { + for (int i = 0; i < n; i++) { + loop(); + } +} + +OpenLcbCanBuffer b; + +int main( int argc, const char* argv[] ) +{ + // run the code for a test + printf("--------------\n"); + setup(); + printf("setup done\n"); + doLoop(1000); // long enough for timeout + printf("one second done\n\n"); + printf("--------------\n"); + + + printf("Test Read Operation\n"); + printf("\n"); + + printf(" Single fragment datagram for short read\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x23;b.data[1]=0x63; // header + b.data[2]=0x12;b.data[3]=0x34;b.data[4]=0x56;b.data[5]=0x78; // address + b.data[6]=0x08; // count + queueTestMessage(&b); + doLoop(10); + printf("\n"); + + +// printf("Receive three fragment datagram OK\n"); +// resultcode = 0; +// b.id = 0x1C6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x50;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// b.id = 0x1C6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x60;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// b.id = 0x1D6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x70;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// printf("\n"); +// +// printf("Receive single fragment datagram fail\n"); +// resultcode = 0x1234; +// b.id = 0x1D6baBFD; +// b.length = (uint8_t)4; +// b.data[0]=0x40;b.data[1]=0x41;b.data[2]=0x42;b.data[3]=0x43; +// queueTestMessage(&b); +// doLoop(10); +// printf("\n"); + + printf("test ends\n"); +} + +// to test (messages in JMRI format) +// send a CIM frame which should get a RIM: [110036ba] +// then a RIM which should restart sequence: [17fff6ba] + +// (these need to be redone) +// send a Verify Node frame of [180Af00f] 2 3 4 5 6 7 +// send a Request Consumers frame of [1824F00F] 1 2 3 4 5 6 7 8 +// send a Request Producers frame of [1828F00F] 8 7 6 5 4 3 2 1 +// send a Request Events frame of [182BF00F] 2 3 4 5 6 7 + +// produce an event with [182DF00F] 8 7 6 5 4 3 2 1 Property changes on: trunk/prototypes/C/tests/ConfigurationTest.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-22 18:54:40 UTC (rev 384) +++ trunk/prototypes/C/tests/Makefile 2010-06-23 04:24:36 UTC (rev 385) @@ -2,7 +2,7 @@ include ../standard.mk -BINFILES := StreamTest DatagramTest CanMrrlcbTest +BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest default: clean compile $(BINFILES) @@ -15,4 +15,6 @@ StreamTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold StreamTest.o -o StreamTest +ConfigurationTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold ConfigurationTest.o -o ConfigurationTest Added: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/ConfigurationTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-23 04:24:36 UTC (rev 385) @@ -0,0 +1,28 @@ +new key alias +-------------- +Starting ConfigurationTest +OpenLcb_can_init +new key alias +setup done +queue_xmt_wait: [100026ba] +queue_xmt_wait: [110036ba] +queue_xmt_wait: [120046ba] +queue_xmt_wait: [130056ba] +queue_xmt_wait: [140066ba] +queue_xmt_wait: [150076ba] +alias assigned +queue_xmt_wait: [17fff6ba] +queue_xmt_wait: [1808f6ba] 02 03 04 05 06 07 +one second done + +-------------- +Test Read Operation + + Single fragment datagram for short read +can_get_frame: [1d6babfd] 23 63 12 34 56 78 08 +consume datagram of length 7: 23 63 12 34 56 78 8 +queue_xmt_wait: [1ebfd6ba] 4c + processRead start=0x12345678 len=8 space=ff +queue_xmt_wait: [1d1236ba] aa bb + +test ends Property changes on: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-24 05:41:13
|
Revision: 389 http://openlcb.svn.sourceforge.net/openlcb/?rev=389&view=rev Author: jacobsen Date: 2010-06-24 05:41:07 +0000 (Thu, 24 Jun 2010) Log Message: ----------- handle datagram overlaps by routing from field in calls Modified Paths: -------------- trunk/prototypes/C/TODO trunk/prototypes/C/src/openlcb/Configuration.cpp trunk/prototypes/C/src/openlcb/Configuration.h trunk/prototypes/C/src/openlcb/Datagram.cpp trunk/prototypes/C/src/openlcb/Datagram.h trunk/prototypes/C/tests/ConfigurationTest.cpp trunk/prototypes/C/tests/DatagramTest.cpp trunk/prototypes/C/tests/results/ConfigurationTest.out.txt Modified: trunk/prototypes/C/TODO =================================================================== --- trunk/prototypes/C/TODO 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/TODO 2010-06-24 05:41:07 UTC (rev 389) @@ -3,3 +3,16 @@ Makefile (esp tests/Makefile) doesn't have a general link rule; needs to know how to pass library search path + +Streams is just a scaffold at present; buffer management needs thought + +Datagram interface needs to transfer source ID of received datagrams, +so reply datagrams can be properly routed back. + +Need to devise a way to have multiple datagram processors called +in sequence, with the first one to consume the datagram +causing the proper ack/nak to be sent & ending the sequence. +Default should actually be "don't know what to do with this" +if all fall through. + +Configuration needs code for testing actual read/write response. Modified: trunk/prototypes/C/src/openlcb/Configuration.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -8,7 +8,7 @@ #include "logging.h" -#define CONFIGURATION_DATAGRAM_CODE 0x23 +#define CONFIGURATION_DATAGRAM_CODE 0x20 // define the operation codes, full byte #define CFG_CMD_WRITE 0x00 @@ -64,11 +64,12 @@ } } -int Configuration::receivedDatagram(uint8_t* data, int ln) { +int Configuration::receivedDatagram(uint8_t* data, int ln, unsigned int f) { // decode whether this is a configuration request if (data[0] != CONFIGURATION_DATAGRAM_CODE) return 0; // yes, copy to our buffer length = ln; + from = f; for (int i = 0; i<length; i++) buffer[i] = *(data++); // mark as ready @@ -120,15 +121,67 @@ if (d == 0) return; // skip and return again later // will reply, mark as done. request = false; - d[0]=0xAA; d[1]=0xBB; - dg->sendTransmitBuffer(2, 0x123); + // copy front matter + for (int i=0; i<6; i++) + d[i]=data[i]; + d[0] = CFG_CMD_READ_REPLY | d[0]&0x0F; + // get length, space + int len = decodeLen(data); + int space = decodeSpace(data); + // TODO: copy real data + // TODO: from address spaces + for (int i=0; i<len; i++) + d[i+6] = i+16; + // send + dg->sendTransmitBuffer(6+len, from); } void Configuration::processWrite(uint8_t* data, int length) { printf(" processWrite start=0x%x space=%x\n", getAddress(data), decodeSpace(data) ); + // TODO: Copy data into place + // TODO: with proper address space } void Configuration::processCmd(uint8_t* data, int length) { - printf(" processCmd\n"); + printf(" processCmd cmd=%x\n", data[1]); + switch (data[1]&0xFC) { + case CFG_CMD_GET_CONFIG: { // to partition local variable below + // reply with canned message + uint8_t* d = dg->getTransmitBuffer(); + if (d==0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=CONFIGURATION_DATAGRAM_CODE; d[1]=CFG_CMD_GET_CONFIG_REPLY; + d[2]=0x03;d[3]=0x01;d[4]=0x38;d[5]=0x00;d[6]=0x00; + dg->sendTransmitBuffer(7, from); + break; + } + case CFG_CMD_GET_ADD_SPACE_INFO: { // to partition local variable below + // reply with canned message + uint8_t* d = dg->getTransmitBuffer(); + if (d==0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=CONFIGURATION_DATAGRAM_CODE; d[1]=CFG_CMD_GET_CONFIG_REPLY; + d[2]=0x03;d[3]=0x01;d[4]=0x38;d[5]=0x00;d[6]=0x00; + dg->sendTransmitBuffer(7, from); + break; + } + //case CFG_CMD_CFG_CMD_GET_CONFIG_REPLY : + //case CFG_CMD_CFG_CMD_GET_ADD_SPACE_INFO_REPLY: + //case CFG_CMD_LOCK: + //case CFG_CMD_LOCK_REPLY: + //case CFG_CMD_GET_UNIQUEID: + //case CFG_CMD_GET_UNIQUEID_REPLY: + //case CFG_CMD_FREEZE: + //case CFG_CMD_INDICATE: + //case CFG_CMD_RESET: + //case CFG_CMD_FACTORY_RESET: + //case CFG_CMD_INDICATE: + default: + // these do nothing in this implementation + request = false; + break; + } } Modified: trunk/prototypes/C/src/openlcb/Configuration.h =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-24 05:41:07 UTC (rev 389) @@ -17,7 +17,7 @@ Configuration(Datagram* dg, Stream *str); void check(); - int receivedDatagram(uint8_t* data, int length); + int receivedDatagram(uint8_t* data, int length, unsigned int from); private: void processRead(uint8_t* data, int length); @@ -28,6 +28,7 @@ Stream* str; uint8_t buffer[DATAGRAM_LENGTH]; int length; + unsigned int from; bool request; uint32_t getAddress(uint8_t* data); Modified: trunk/prototypes/C/src/openlcb/Datagram.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -8,7 +8,7 @@ #include "logging.h" -Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* ln) { +Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from), LinkControl* ln) { buffer = b; link = ln; callback = cb; @@ -92,7 +92,7 @@ // unsigned int length = rptr-rbuf; // callback - int result = (*callback)(rbuf, length); + int result = (*callback)(rbuf, length, rcv->getSourceAlias()); rptr = rbuf; if (result == 0) { // send OK; done immediately with wait Modified: trunk/prototypes/C/src/openlcb/Datagram.h =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-24 05:41:07 UTC (rev 389) @@ -42,7 +42,7 @@ */ void receivedFrame(OpenLcbCanBuffer* rcv); - Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* link); + Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from), LinkControl* link); private: OpenLcbCanBuffer* buffer; @@ -58,7 +58,7 @@ uint8_t rbuf[DATAGRAM_LENGTH]; uint8_t* rptr; - unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length); // void callback(int index) pointer + unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from); // void callback(int index) pointer }; #endif Modified: trunk/prototypes/C/tests/ConfigurationTest.cpp =================================================================== --- trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -39,20 +39,20 @@ LinkControl link(&txBuffer, &nodeid); -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length); +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from); unsigned int rcvCallback(uint8_t *rbuf, unsigned int length); Datagram dg(&txBuffer, datagramCallback, &link); Stream str(&txBuffer, rcvCallback, &link); Configuration cfg(&dg, &str); -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ +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<length; i++) printf("%x ", rbuf[i]); printf("\n"); // pass to consumers - cfg.receivedDatagram(rbuf, length); + cfg.receivedDatagram(rbuf, length, from); return 0; // return pre-ordained result } @@ -132,18 +132,53 @@ printf("--------------\n"); - printf("Test Read Operation\n"); + printf("Single fragment datagram for get config\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x20;b.data[1]=0x80; // header + b.data[6]=0x02; // count + queueTestMessage(&b); + doLoop(10); + printf(" Ack to config reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); - - printf(" Single fragment datagram for short read\n"); + + printf("Second single fragment datagram for get config\n"); resultcode = 0; b.id = 0x1D6baBFD; b.length = (uint8_t)7; - b.data[0]=0x23;b.data[1]=0x63; // header + b.data[0]=0x20;b.data[1]=0x80; // header + b.data[6]=0x02; // count + queueTestMessage(&b); + doLoop(10); + printf(" Ack to config reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + + printf("Single fragment datagram for short read\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x20;b.data[1]=0x63; // header b.data[2]=0x12;b.data[3]=0x34;b.data[4]=0x56;b.data[5]=0x78; // address b.data[6]=0x08; // count queueTestMessage(&b); doLoop(10); + printf(" Ack to reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -38,7 +38,7 @@ LinkControl link(&txBuffer, &nodeid); unsigned int resultcode; -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ +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<length; i++) printf("%x ", rbuf[i]); Modified: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-24 05:41:07 UTC (rev 389) @@ -16,13 +16,32 @@ one second done -------------- -Test Read Operation +Single fragment datagram for get config +can_get_frame: [1d6babfd] 20 80 00 00 00 00 02 +consume datagram of length 7: 20 80 0 0 0 0 2 +queue_xmt_wait: [1ebfd6ba] 4c + processCmd cmd=80 +queue_xmt_wait: [1dbfd6ba] 20 82 03 01 38 00 00 + Ack to config reply datagram +can_get_frame: [1e6babfd] 4c - Single fragment datagram for short read -can_get_frame: [1d6babfd] 23 63 12 34 56 78 08 -consume datagram of length 7: 23 63 12 34 56 78 8 +Second single fragment datagram for get config +can_get_frame: [1d6babfd] 20 80 00 00 00 00 02 +consume datagram of length 7: 20 80 0 0 0 0 2 queue_xmt_wait: [1ebfd6ba] 4c + processCmd cmd=80 +queue_xmt_wait: [1dbfd6ba] 20 82 03 01 38 00 00 + Ack to config reply datagram +can_get_frame: [1e6babfd] 4c + +Single fragment datagram for short read +can_get_frame: [1d6babfd] 20 63 12 34 56 78 08 +consume datagram of length 7: 20 63 12 34 56 78 8 +queue_xmt_wait: [1ebfd6ba] 4c processRead start=0x12345678 len=8 space=ff -queue_xmt_wait: [1d1236ba] aa bb +queue_xmt_wait: [1cbfd6ba] 50 63 12 34 56 78 10 11 +queue_xmt_wait: [1dbfd6ba] 12 13 14 15 16 17 + Ack to reply datagram +can_get_frame: [1e6babfd] 4c test ends This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-24 05:41:14
|
Revision: 389 http://openlcb.svn.sourceforge.net/openlcb/?rev=389&view=rev Author: jacobsen Date: 2010-06-24 05:41:07 +0000 (Thu, 24 Jun 2010) Log Message: ----------- handle datagram overlaps by routing from field in calls Modified Paths: -------------- trunk/prototypes/C/TODO trunk/prototypes/C/src/openlcb/Configuration.cpp trunk/prototypes/C/src/openlcb/Configuration.h trunk/prototypes/C/src/openlcb/Datagram.cpp trunk/prototypes/C/src/openlcb/Datagram.h trunk/prototypes/C/tests/ConfigurationTest.cpp trunk/prototypes/C/tests/DatagramTest.cpp trunk/prototypes/C/tests/results/ConfigurationTest.out.txt Modified: trunk/prototypes/C/TODO =================================================================== --- trunk/prototypes/C/TODO 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/TODO 2010-06-24 05:41:07 UTC (rev 389) @@ -3,3 +3,16 @@ Makefile (esp tests/Makefile) doesn't have a general link rule; needs to know how to pass library search path + +Streams is just a scaffold at present; buffer management needs thought + +Datagram interface needs to transfer source ID of received datagrams, +so reply datagrams can be properly routed back. + +Need to devise a way to have multiple datagram processors called +in sequence, with the first one to consume the datagram +causing the proper ack/nak to be sent & ending the sequence. +Default should actually be "don't know what to do with this" +if all fall through. + +Configuration needs code for testing actual read/write response. Modified: trunk/prototypes/C/src/openlcb/Configuration.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Configuration.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -8,7 +8,7 @@ #include "logging.h" -#define CONFIGURATION_DATAGRAM_CODE 0x23 +#define CONFIGURATION_DATAGRAM_CODE 0x20 // define the operation codes, full byte #define CFG_CMD_WRITE 0x00 @@ -64,11 +64,12 @@ } } -int Configuration::receivedDatagram(uint8_t* data, int ln) { +int Configuration::receivedDatagram(uint8_t* data, int ln, unsigned int f) { // decode whether this is a configuration request if (data[0] != CONFIGURATION_DATAGRAM_CODE) return 0; // yes, copy to our buffer length = ln; + from = f; for (int i = 0; i<length; i++) buffer[i] = *(data++); // mark as ready @@ -120,15 +121,67 @@ if (d == 0) return; // skip and return again later // will reply, mark as done. request = false; - d[0]=0xAA; d[1]=0xBB; - dg->sendTransmitBuffer(2, 0x123); + // copy front matter + for (int i=0; i<6; i++) + d[i]=data[i]; + d[0] = CFG_CMD_READ_REPLY | d[0]&0x0F; + // get length, space + int len = decodeLen(data); + int space = decodeSpace(data); + // TODO: copy real data + // TODO: from address spaces + for (int i=0; i<len; i++) + d[i+6] = i+16; + // send + dg->sendTransmitBuffer(6+len, from); } void Configuration::processWrite(uint8_t* data, int length) { printf(" processWrite start=0x%x space=%x\n", getAddress(data), decodeSpace(data) ); + // TODO: Copy data into place + // TODO: with proper address space } void Configuration::processCmd(uint8_t* data, int length) { - printf(" processCmd\n"); + printf(" processCmd cmd=%x\n", data[1]); + switch (data[1]&0xFC) { + case CFG_CMD_GET_CONFIG: { // to partition local variable below + // reply with canned message + uint8_t* d = dg->getTransmitBuffer(); + if (d==0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=CONFIGURATION_DATAGRAM_CODE; d[1]=CFG_CMD_GET_CONFIG_REPLY; + d[2]=0x03;d[3]=0x01;d[4]=0x38;d[5]=0x00;d[6]=0x00; + dg->sendTransmitBuffer(7, from); + break; + } + case CFG_CMD_GET_ADD_SPACE_INFO: { // to partition local variable below + // reply with canned message + uint8_t* d = dg->getTransmitBuffer(); + if (d==0) return; // skip and return again later + // will reply, mark as done. + request = false; + d[0]=CONFIGURATION_DATAGRAM_CODE; d[1]=CFG_CMD_GET_CONFIG_REPLY; + d[2]=0x03;d[3]=0x01;d[4]=0x38;d[5]=0x00;d[6]=0x00; + dg->sendTransmitBuffer(7, from); + break; + } + //case CFG_CMD_CFG_CMD_GET_CONFIG_REPLY : + //case CFG_CMD_CFG_CMD_GET_ADD_SPACE_INFO_REPLY: + //case CFG_CMD_LOCK: + //case CFG_CMD_LOCK_REPLY: + //case CFG_CMD_GET_UNIQUEID: + //case CFG_CMD_GET_UNIQUEID_REPLY: + //case CFG_CMD_FREEZE: + //case CFG_CMD_INDICATE: + //case CFG_CMD_RESET: + //case CFG_CMD_FACTORY_RESET: + //case CFG_CMD_INDICATE: + default: + // these do nothing in this implementation + request = false; + break; + } } Modified: trunk/prototypes/C/src/openlcb/Configuration.h =================================================================== --- trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Configuration.h 2010-06-24 05:41:07 UTC (rev 389) @@ -17,7 +17,7 @@ Configuration(Datagram* dg, Stream *str); void check(); - int receivedDatagram(uint8_t* data, int length); + int receivedDatagram(uint8_t* data, int length, unsigned int from); private: void processRead(uint8_t* data, int length); @@ -28,6 +28,7 @@ Stream* str; uint8_t buffer[DATAGRAM_LENGTH]; int length; + unsigned int from; bool request; uint32_t getAddress(uint8_t* data); Modified: trunk/prototypes/C/src/openlcb/Datagram.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Datagram.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -8,7 +8,7 @@ #include "logging.h" -Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* ln) { +Datagram::Datagram(OpenLcbCanBuffer* b, unsigned int (*cb)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from), LinkControl* ln) { buffer = b; link = ln; callback = cb; @@ -92,7 +92,7 @@ // unsigned int length = rptr-rbuf; // callback - int result = (*callback)(rbuf, length); + int result = (*callback)(rbuf, length, rcv->getSourceAlias()); rptr = rbuf; if (result == 0) { // send OK; done immediately with wait Modified: trunk/prototypes/C/src/openlcb/Datagram.h =================================================================== --- trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/src/openlcb/Datagram.h 2010-06-24 05:41:07 UTC (rev 389) @@ -42,7 +42,7 @@ */ void receivedFrame(OpenLcbCanBuffer* rcv); - Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length), LinkControl* link); + Datagram(OpenLcbCanBuffer* b, unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from), LinkControl* link); private: OpenLcbCanBuffer* buffer; @@ -58,7 +58,7 @@ uint8_t rbuf[DATAGRAM_LENGTH]; uint8_t* rptr; - unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length); // void callback(int index) pointer + unsigned int (*callback)(uint8_t tbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from); // void callback(int index) pointer }; #endif Modified: trunk/prototypes/C/tests/ConfigurationTest.cpp =================================================================== --- trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/ConfigurationTest.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -39,20 +39,20 @@ LinkControl link(&txBuffer, &nodeid); -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length); +unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length, unsigned int from); unsigned int rcvCallback(uint8_t *rbuf, unsigned int length); Datagram dg(&txBuffer, datagramCallback, &link); Stream str(&txBuffer, rcvCallback, &link); Configuration cfg(&dg, &str); -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ +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<length; i++) printf("%x ", rbuf[i]); printf("\n"); // pass to consumers - cfg.receivedDatagram(rbuf, length); + cfg.receivedDatagram(rbuf, length, from); return 0; // return pre-ordained result } @@ -132,18 +132,53 @@ printf("--------------\n"); - printf("Test Read Operation\n"); + printf("Single fragment datagram for get config\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x20;b.data[1]=0x80; // header + b.data[6]=0x02; // count + queueTestMessage(&b); + doLoop(10); + printf(" Ack to config reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); - - printf(" Single fragment datagram for short read\n"); + + printf("Second single fragment datagram for get config\n"); resultcode = 0; b.id = 0x1D6baBFD; b.length = (uint8_t)7; - b.data[0]=0x23;b.data[1]=0x63; // header + b.data[0]=0x20;b.data[1]=0x80; // header + b.data[6]=0x02; // count + queueTestMessage(&b); + doLoop(10); + printf(" Ack to config reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); + printf("\n"); + + printf("Single fragment datagram for short read\n"); + resultcode = 0; + b.id = 0x1D6baBFD; + b.length = (uint8_t)7; + b.data[0]=0x20;b.data[1]=0x63; // header b.data[2]=0x12;b.data[3]=0x34;b.data[4]=0x56;b.data[5]=0x78; // address b.data[6]=0x08; // count queueTestMessage(&b); doLoop(10); + printf(" Ack to reply datagram\n"); + b.id = 0x1E6baBFD; + b.length = (uint8_t)1; + b.data[0]=0x4c; + queueTestMessage(&b); + doLoop(10); printf("\n"); Modified: trunk/prototypes/C/tests/DatagramTest.cpp =================================================================== --- trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/DatagramTest.cpp 2010-06-24 05:41:07 UTC (rev 389) @@ -38,7 +38,7 @@ LinkControl link(&txBuffer, &nodeid); unsigned int resultcode; -unsigned int datagramCallback(uint8_t rbuf[DATAGRAM_LENGTH], unsigned int length){ +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<length; i++) printf("%x ", rbuf[i]); Modified: trunk/prototypes/C/tests/results/ConfigurationTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-24 05:39:51 UTC (rev 388) +++ trunk/prototypes/C/tests/results/ConfigurationTest.out.txt 2010-06-24 05:41:07 UTC (rev 389) @@ -16,13 +16,32 @@ one second done -------------- -Test Read Operation +Single fragment datagram for get config +can_get_frame: [1d6babfd] 20 80 00 00 00 00 02 +consume datagram of length 7: 20 80 0 0 0 0 2 +queue_xmt_wait: [1ebfd6ba] 4c + processCmd cmd=80 +queue_xmt_wait: [1dbfd6ba] 20 82 03 01 38 00 00 + Ack to config reply datagram +can_get_frame: [1e6babfd] 4c - Single fragment datagram for short read -can_get_frame: [1d6babfd] 23 63 12 34 56 78 08 -consume datagram of length 7: 23 63 12 34 56 78 8 +Second single fragment datagram for get config +can_get_frame: [1d6babfd] 20 80 00 00 00 00 02 +consume datagram of length 7: 20 80 0 0 0 0 2 queue_xmt_wait: [1ebfd6ba] 4c + processCmd cmd=80 +queue_xmt_wait: [1dbfd6ba] 20 82 03 01 38 00 00 + Ack to config reply datagram +can_get_frame: [1e6babfd] 4c + +Single fragment datagram for short read +can_get_frame: [1d6babfd] 20 63 12 34 56 78 08 +consume datagram of length 7: 20 63 12 34 56 78 8 +queue_xmt_wait: [1ebfd6ba] 4c processRead start=0x12345678 len=8 space=ff -queue_xmt_wait: [1d1236ba] aa bb +queue_xmt_wait: [1cbfd6ba] 50 63 12 34 56 78 10 11 +queue_xmt_wait: [1dbfd6ba] 12 13 14 15 16 17 + Ack to reply datagram +can_get_frame: [1e6babfd] 4c test ends This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-25 05:08:55
|
Revision: 394 http://openlcb.svn.sourceforge.net/openlcb/?rev=394&view=rev Author: jacobsen Date: 2010-06-25 05:08:49 +0000 (Fri, 25 Jun 2010) Log Message: ----------- move logging to scaffold directory Added Paths: ----------- trunk/prototypes/C/scaffold/logging.h Removed Paths: ------------- trunk/prototypes/C/src/openlcb/logging.h Copied: trunk/prototypes/C/scaffold/logging.h (from rev 393, trunk/prototypes/C/src/openlcb/logging.h) =================================================================== --- trunk/prototypes/C/scaffold/logging.h (rev 0) +++ trunk/prototypes/C/scaffold/logging.h 2010-06-25 05:08:49 UTC (rev 394) @@ -0,0 +1,9 @@ +// define some rudimentary logging +// intended for inclusion in .cpp files for Arduino + +#ifndef lognl +#include <stdio.h> +#define logstr(...) printf(__VA_ARGS__) +#define loghex(...) printf("%h",__VA_ARGS__) +#define lognl() printf("\n") +#endif // logln Deleted: trunk/prototypes/C/src/openlcb/logging.h =================================================================== --- trunk/prototypes/C/src/openlcb/logging.h 2010-06-25 03:58:20 UTC (rev 393) +++ trunk/prototypes/C/src/openlcb/logging.h 2010-06-25 05:08:49 UTC (rev 394) @@ -1,9 +0,0 @@ -// define some rudimentary logging -// intended for inclusion in .cpp files for Arduino - -#ifndef lognl -#include <stdio.h> -#define logstr(...) printf(__VA_ARGS__) -#define loghex(...) printf("%h",__VA_ARGS__) -#define lognl() printf("\n") -#endif // logln This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-25 05:08:55
|
Revision: 394 http://openlcb.svn.sourceforge.net/openlcb/?rev=394&view=rev Author: jacobsen Date: 2010-06-25 05:08:49 +0000 (Fri, 25 Jun 2010) Log Message: ----------- move logging to scaffold directory Added Paths: ----------- trunk/prototypes/C/scaffold/logging.h Removed Paths: ------------- trunk/prototypes/C/src/openlcb/logging.h Copied: trunk/prototypes/C/scaffold/logging.h (from rev 393, trunk/prototypes/C/src/openlcb/logging.h) =================================================================== --- trunk/prototypes/C/scaffold/logging.h (rev 0) +++ trunk/prototypes/C/scaffold/logging.h 2010-06-25 05:08:49 UTC (rev 394) @@ -0,0 +1,9 @@ +// define some rudimentary logging +// intended for inclusion in .cpp files for Arduino + +#ifndef lognl +#include <stdio.h> +#define logstr(...) printf(__VA_ARGS__) +#define loghex(...) printf("%h",__VA_ARGS__) +#define lognl() printf("\n") +#endif // logln Deleted: trunk/prototypes/C/src/openlcb/logging.h =================================================================== --- trunk/prototypes/C/src/openlcb/logging.h 2010-06-25 03:58:20 UTC (rev 393) +++ trunk/prototypes/C/src/openlcb/logging.h 2010-06-25 05:08:49 UTC (rev 394) @@ -1,9 +0,0 @@ -// define some rudimentary logging -// intended for inclusion in .cpp files for Arduino - -#ifndef lognl -#include <stdio.h> -#define logstr(...) printf(__VA_ARGS__) -#define loghex(...) printf("%h",__VA_ARGS__) -#define lognl() printf("\n") -#endif // logln This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-27 08:28:41
|
Revision: 425 http://openlcb.svn.sourceforge.net/openlcb/?rev=425&view=rev Author: jacobsen Date: 2010-06-27 08:28:35 +0000 (Sun, 27 Jun 2010) Log Message: ----------- persistant memory handler Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/src/openlcb/Event.h trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/scaffold/EEPROM.cpp trunk/prototypes/C/scaffold/EEPROM.h trunk/prototypes/C/src/openlcb/NodeMemory.cpp trunk/prototypes/C/src/openlcb/NodeMemory.h trunk/prototypes/C/tests/NodeMemoryTest.cpp trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/Makefile 2010-06-27 08:28:35 UTC (rev 425) @@ -25,6 +25,7 @@ @./tests/StreamTest | diff - tests/results/StreamTest.out.txt @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + @./tests/NodeMemoryTest | diff - tests/results/NodeMemoryTest.out.txt # reset the comparison files; only if sure! reset: @@ -32,3 +33,4 @@ @./tests/StreamTest > tests/results/StreamTest.out.txt @./tests/DatagramTest > tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest > tests/results/CanMrrlcbTest.out.txt + @./tests/NodeMemoryTest > tests/results/NodeMemoryTest.out.txt Added: trunk/prototypes/C/scaffold/EEPROM.cpp =================================================================== --- trunk/prototypes/C/scaffold/EEPROM.cpp (rev 0) +++ trunk/prototypes/C/scaffold/EEPROM.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,29 @@ +#include "WConstants.h" +#include "EEPROM.h" +#include <stdio.h> + +#include "Event.h" + +uint8_t EEPROMClass::read(int address) +{ + return array[address]; +} + +void EEPROMClass::write(int address, uint8_t value) +{ + array[address]=value; +} + +void EEPROMClass::dump() { + for (int i = 0; i <= 3; i++) printf("%2x ", array[i]); printf("\n"); + for (int i = 4; i <= 5; i++) printf("%2x ", array[i]); printf("\n"); + for (int i = 6; i <= 11; i++) printf("%2x ", array[i]); printf("\n"); + + int j = 12; + for (int k = 0; k<4; k++) { + for (int i = 0; i<sizeof(Event); i++) printf("%2x ", array[j++]); printf("\n"); + } + printf("\n"); +} + +EEPROMClass EEPROM; Property changes on: trunk/prototypes/C/scaffold/EEPROM.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/scaffold/EEPROM.h =================================================================== --- trunk/prototypes/C/scaffold/EEPROM.h (rev 0) +++ trunk/prototypes/C/scaffold/EEPROM.h 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,23 @@ +// +// Dummy implementation of the Arduino EEPROM +// library + +#ifndef EEPROM_h +#define EEPROM_h + +#include <inttypes.h> + +class EEPROMClass +{ + public: + uint8_t read(int); + void write(int, uint8_t); + void dump(); + + private: + uint8_t array[128]; +}; + +extern EEPROMClass EEPROM; + +#endif Property changes on: trunk/prototypes/C/scaffold/EEPROM.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/src/openlcb/Event.h =================================================================== --- trunk/prototypes/C/src/openlcb/Event.h 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/src/openlcb/Event.h 2010-06-27 08:28:35 UTC (rev 425) @@ -10,7 +10,7 @@ } Event(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7) - : EventID(b0, b1, b2, b3, b4, b5, b6, b7){ + : EventID(b0, b1, b2, b3, b4, b5, b6, b7), flags(0){ } bool equals(Event* n) { Added: trunk/prototypes/C/src/openlcb/NodeMemory.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.cpp (rev 0) +++ trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,126 @@ +// makes this an Arduino file +#include "WConstants.h" + +#include "NodeMemory.h" + +#include "logging.h" +#include "Event.h" +#include "NodeID.h" +#include "EEPROM.h" + +// doesn't do anything +NodeMemory::NodeMemory() {} + +void NodeMemory::setup(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + if (!checkOK(addr)) { + // have to reload + // clear the count + writeByte(addr+4, 0); + writeByte(addr+5, 0); + // handle the rest + reset(addr, nid, cE, nC, pE, nP); + } + // read NodeID from non-volative memory + uint8_t* p; + addr = addr+6; // skip check word and count + p = (uint8_t*)nid; + for (int i=0; i<sizeof(NodeID); i++) + *p++ = EEPROM.read(addr++); + + // read consumer events + p = (uint8_t*)cE; + for (int k=0; k<nC; k++) + for (int i=0; i<sizeof(Event); i++) + *p++ = EEPROM.read(addr++); + + // read consumer events + p = (uint8_t*)pE; + for (int k=0; k<nP; k++) + for (int i=0; i<sizeof(Event); i++) + *p++ = EEPROM.read(addr++); + +} + +void NodeMemory::reset(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // do the in-memory update + // TODO: Not updating the count for used events properly, using + // TODO: the over-all store count, which includes writing back event changes + int part1 = EEPROM.read(addr+4); + int part2 = EEPROM.read(addr+5); + uint16_t count = ((part1<<8)+part2)*(nP+nC)+1; + Event* c; + + c = cE; + for (int i = 0; i<nC; i++) { + uint8_t* p = (uint8_t*)c++; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count>>8)&0xFF; + *p++ = count&0xFF; + count++; + } + + c = pE; + for (int i = 0; i<nP; i++) { + uint8_t* p = (uint8_t*)c++; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count>>8)&0xFF; + *p++ = count&0xFF; + count++; + } + // and store + store(addr, nid, cE, nC, pE, nP); +} + +void NodeMemory::store(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // write tag + writeByte(addr++, 0xEE); + writeByte(addr++, 0x55); + writeByte(addr++, 0x5E); + writeByte(addr++, 0xE5); + + // TODO: is this right way to handle count? + // incremement count of writes + int part1 = EEPROM.read(addr); + int part2 = EEPROM.read(addr+1); + uint16_t count = (part1<<8)+part2; + count++; + writeByte(addr++, (count>>8)&0xFF); + writeByte(addr++, (count)&0xFF); + + // write NodeID + uint8_t* p; + p = (uint8_t*)nid; + for (int i=0; i<sizeof(NodeID); i++) + writeByte(addr++, *p++); + + // write consumer events + p = (uint8_t*)cE; + for (int k=0; k<nC; k++) + for (int i=0; i<sizeof(Event); i++) + writeByte(addr++, *p++); + + // write consumer events + p = (uint8_t*)pE; + for (int k=0; k<nP; k++) + for (int i=0; i<sizeof(Event); i++) + writeByte(addr++, *p++); +} + +bool NodeMemory::checkOK(int addr) { + if (EEPROM.read(addr ) != 0xEE ) return false; + if (EEPROM.read(addr+1) != 0x55 ) return false; + if (EEPROM.read(addr+2) != 0x5E ) return false; + if (EEPROM.read(addr+3) != 0xE5 ) return false; + return true; +} + +// write only if needed +void NodeMemory::writeByte(int addr, uint8_t b) { + if (EEPROM.read(addr) != b ) { + EEPROM.write(addr, b); + } +} \ No newline at end of file Property changes on: trunk/prototypes/C/src/openlcb/NodeMemory.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/src/openlcb/NodeMemory.h =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.h (rev 0) +++ trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,54 @@ +#ifndef NodeMemory_h +#define NodeMemory_h + +/** + * Class for persisting node memory + * in a non-volative memory, e.g. EEPROM. + * + * This class doesn't take any space, it just + * organizes code. It stores a NodeID and + * two arrays of Events; it's up to you to store + * everything else. + * + * The memory can either be + * blank, needing complete initialization or + * OK at startup. + * + * When you "reset" the memory, you're + * putting _new_ unique EventIDs in place. + * + */ +#include <stdint.h> + +class NodeID; +class Event; + +class NodeMemory { + public: + + NodeMemory(); // doesn't do anything + + /** + * Make sure ready to go. NodeID should have a default + * value already in case this is the first time. + */ + void setup(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + /* + * Move to a completely new set of values, e.g. a factory reset + * for OpenLCB. NodeID is not changed. + */ + void reset(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + /* + * Put modified contents back into memory. + */ + void store(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + private: + bool checkOK(int address); // check if memory tag in place + void writeByte(int address, uint8_t value); // write only if needed + +}; + +#endif Property changes on: trunk/prototypes/C/src/openlcb/NodeMemory.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/tests/Makefile 2010-06-27 08:28:35 UTC (rev 425) @@ -2,7 +2,7 @@ include ../standard.mk -BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest +BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest NodeMemoryTest default: clean compile $(BINFILES) @@ -18,3 +18,6 @@ ConfigurationTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold ConfigurationTest.o -o ConfigurationTest +NodeMemoryTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold NodeMemoryTest.o -o NodeMemoryTest + Added: trunk/prototypes/C/tests/NodeMemoryTest.cpp =================================================================== --- trunk/prototypes/C/tests/NodeMemoryTest.cpp (rev 0) +++ trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,67 @@ +//=========================================================== +// StreamTest +// Tests for OpenLCB Stream support +// +// Bob Jacobsen 2010 +//=========================================================== +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> + +#include "logging.h" +#include "NodeMemory.h" + +#include "EEPROM.h" +#include "Event.h" +#include "NodeID.h" + +NodeID node(1,2,3,4,5,6); + +Event cEvents[] = { + Event(1,2,3,4,5,6,7,8), + Event(17,18,19,20,21,22,23,24) +}; +int cEventNum = 2; + +Event pEvents[] = { + Event(33,34,35,36,37,38,39,40), + Event(65,66,67,68,69,70,71,72) +}; +int pEventNum = 2; + +NodeMemory m; + +int main( int argc, const char* argv[] ) +{ + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do reset\n"); + m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do reset\n"); + m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("change values\n"); + cEvents[0] = pEvents[1]; + m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("change values\n"); + Event a(10,11,12,13,14,15,16,17); + cEvents[1] = a; + m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + +} \ No newline at end of file Property changes on: trunk/prototypes/C/tests/NodeMemoryTest.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,63 @@ +do setup +ee 55 5e e5 + 0 1 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 1 0 0 0 0 + 1 2 3 4 5 6 0 2 0 0 0 0 + 1 2 3 4 5 6 0 3 0 0 0 0 + 1 2 3 4 5 6 0 4 0 0 0 0 + +do setup +ee 55 5e e5 + 0 1 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 1 0 0 0 0 + 1 2 3 4 5 6 0 2 0 0 0 0 + 1 2 3 4 5 6 0 3 0 0 0 0 + 1 2 3 4 5 6 0 4 0 0 0 0 + +do reset +ee 55 5e e5 + 0 2 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 5 0 0 0 0 + 1 2 3 4 5 6 0 6 0 0 0 0 + 1 2 3 4 5 6 0 7 0 0 0 0 + 1 2 3 4 5 6 0 8 0 0 0 0 + +do reset +ee 55 5e e5 + 0 3 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 9 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +do setup +ee 55 5e e5 + 0 3 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 9 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +change values +ee 55 5e e5 + 0 4 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 c 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +change values +ee 55 5e e5 + 0 5 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 c 0 0 0 0 + a b c d e f 10 11 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + Property changes on: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-27 08:28:42
|
Revision: 425 http://openlcb.svn.sourceforge.net/openlcb/?rev=425&view=rev Author: jacobsen Date: 2010-06-27 08:28:35 +0000 (Sun, 27 Jun 2010) Log Message: ----------- persistant memory handler Modified Paths: -------------- trunk/prototypes/C/Makefile trunk/prototypes/C/src/openlcb/Event.h trunk/prototypes/C/tests/Makefile Added Paths: ----------- trunk/prototypes/C/scaffold/EEPROM.cpp trunk/prototypes/C/scaffold/EEPROM.h trunk/prototypes/C/src/openlcb/NodeMemory.cpp trunk/prototypes/C/src/openlcb/NodeMemory.h trunk/prototypes/C/tests/NodeMemoryTest.cpp trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/Makefile 2010-06-27 08:28:35 UTC (rev 425) @@ -25,6 +25,7 @@ @./tests/StreamTest | diff - tests/results/StreamTest.out.txt @./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + @./tests/NodeMemoryTest | diff - tests/results/NodeMemoryTest.out.txt # reset the comparison files; only if sure! reset: @@ -32,3 +33,4 @@ @./tests/StreamTest > tests/results/StreamTest.out.txt @./tests/DatagramTest > tests/results/DatagramTest.out.txt @./tests/CanMrrlcbTest > tests/results/CanMrrlcbTest.out.txt + @./tests/NodeMemoryTest > tests/results/NodeMemoryTest.out.txt Added: trunk/prototypes/C/scaffold/EEPROM.cpp =================================================================== --- trunk/prototypes/C/scaffold/EEPROM.cpp (rev 0) +++ trunk/prototypes/C/scaffold/EEPROM.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,29 @@ +#include "WConstants.h" +#include "EEPROM.h" +#include <stdio.h> + +#include "Event.h" + +uint8_t EEPROMClass::read(int address) +{ + return array[address]; +} + +void EEPROMClass::write(int address, uint8_t value) +{ + array[address]=value; +} + +void EEPROMClass::dump() { + for (int i = 0; i <= 3; i++) printf("%2x ", array[i]); printf("\n"); + for (int i = 4; i <= 5; i++) printf("%2x ", array[i]); printf("\n"); + for (int i = 6; i <= 11; i++) printf("%2x ", array[i]); printf("\n"); + + int j = 12; + for (int k = 0; k<4; k++) { + for (int i = 0; i<sizeof(Event); i++) printf("%2x ", array[j++]); printf("\n"); + } + printf("\n"); +} + +EEPROMClass EEPROM; Property changes on: trunk/prototypes/C/scaffold/EEPROM.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/scaffold/EEPROM.h =================================================================== --- trunk/prototypes/C/scaffold/EEPROM.h (rev 0) +++ trunk/prototypes/C/scaffold/EEPROM.h 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,23 @@ +// +// Dummy implementation of the Arduino EEPROM +// library + +#ifndef EEPROM_h +#define EEPROM_h + +#include <inttypes.h> + +class EEPROMClass +{ + public: + uint8_t read(int); + void write(int, uint8_t); + void dump(); + + private: + uint8_t array[128]; +}; + +extern EEPROMClass EEPROM; + +#endif Property changes on: trunk/prototypes/C/scaffold/EEPROM.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/src/openlcb/Event.h =================================================================== --- trunk/prototypes/C/src/openlcb/Event.h 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/src/openlcb/Event.h 2010-06-27 08:28:35 UTC (rev 425) @@ -10,7 +10,7 @@ } Event(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7) - : EventID(b0, b1, b2, b3, b4, b5, b6, b7){ + : EventID(b0, b1, b2, b3, b4, b5, b6, b7), flags(0){ } bool equals(Event* n) { Added: trunk/prototypes/C/src/openlcb/NodeMemory.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.cpp (rev 0) +++ trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,126 @@ +// makes this an Arduino file +#include "WConstants.h" + +#include "NodeMemory.h" + +#include "logging.h" +#include "Event.h" +#include "NodeID.h" +#include "EEPROM.h" + +// doesn't do anything +NodeMemory::NodeMemory() {} + +void NodeMemory::setup(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + if (!checkOK(addr)) { + // have to reload + // clear the count + writeByte(addr+4, 0); + writeByte(addr+5, 0); + // handle the rest + reset(addr, nid, cE, nC, pE, nP); + } + // read NodeID from non-volative memory + uint8_t* p; + addr = addr+6; // skip check word and count + p = (uint8_t*)nid; + for (int i=0; i<sizeof(NodeID); i++) + *p++ = EEPROM.read(addr++); + + // read consumer events + p = (uint8_t*)cE; + for (int k=0; k<nC; k++) + for (int i=0; i<sizeof(Event); i++) + *p++ = EEPROM.read(addr++); + + // read consumer events + p = (uint8_t*)pE; + for (int k=0; k<nP; k++) + for (int i=0; i<sizeof(Event); i++) + *p++ = EEPROM.read(addr++); + +} + +void NodeMemory::reset(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // do the in-memory update + // TODO: Not updating the count for used events properly, using + // TODO: the over-all store count, which includes writing back event changes + int part1 = EEPROM.read(addr+4); + int part2 = EEPROM.read(addr+5); + uint16_t count = ((part1<<8)+part2)*(nP+nC)+1; + Event* c; + + c = cE; + for (int i = 0; i<nC; i++) { + uint8_t* p = (uint8_t*)c++; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count>>8)&0xFF; + *p++ = count&0xFF; + count++; + } + + c = pE; + for (int i = 0; i<nP; i++) { + uint8_t* p = (uint8_t*)c++; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count>>8)&0xFF; + *p++ = count&0xFF; + count++; + } + // and store + store(addr, nid, cE, nC, pE, nP); +} + +void NodeMemory::store(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // write tag + writeByte(addr++, 0xEE); + writeByte(addr++, 0x55); + writeByte(addr++, 0x5E); + writeByte(addr++, 0xE5); + + // TODO: is this right way to handle count? + // incremement count of writes + int part1 = EEPROM.read(addr); + int part2 = EEPROM.read(addr+1); + uint16_t count = (part1<<8)+part2; + count++; + writeByte(addr++, (count>>8)&0xFF); + writeByte(addr++, (count)&0xFF); + + // write NodeID + uint8_t* p; + p = (uint8_t*)nid; + for (int i=0; i<sizeof(NodeID); i++) + writeByte(addr++, *p++); + + // write consumer events + p = (uint8_t*)cE; + for (int k=0; k<nC; k++) + for (int i=0; i<sizeof(Event); i++) + writeByte(addr++, *p++); + + // write consumer events + p = (uint8_t*)pE; + for (int k=0; k<nP; k++) + for (int i=0; i<sizeof(Event); i++) + writeByte(addr++, *p++); +} + +bool NodeMemory::checkOK(int addr) { + if (EEPROM.read(addr ) != 0xEE ) return false; + if (EEPROM.read(addr+1) != 0x55 ) return false; + if (EEPROM.read(addr+2) != 0x5E ) return false; + if (EEPROM.read(addr+3) != 0xE5 ) return false; + return true; +} + +// write only if needed +void NodeMemory::writeByte(int addr, uint8_t b) { + if (EEPROM.read(addr) != b ) { + EEPROM.write(addr, b); + } +} \ No newline at end of file Property changes on: trunk/prototypes/C/src/openlcb/NodeMemory.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/src/openlcb/NodeMemory.h =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.h (rev 0) +++ trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,54 @@ +#ifndef NodeMemory_h +#define NodeMemory_h + +/** + * Class for persisting node memory + * in a non-volative memory, e.g. EEPROM. + * + * This class doesn't take any space, it just + * organizes code. It stores a NodeID and + * two arrays of Events; it's up to you to store + * everything else. + * + * The memory can either be + * blank, needing complete initialization or + * OK at startup. + * + * When you "reset" the memory, you're + * putting _new_ unique EventIDs in place. + * + */ +#include <stdint.h> + +class NodeID; +class Event; + +class NodeMemory { + public: + + NodeMemory(); // doesn't do anything + + /** + * Make sure ready to go. NodeID should have a default + * value already in case this is the first time. + */ + void setup(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + /* + * Move to a completely new set of values, e.g. a factory reset + * for OpenLCB. NodeID is not changed. + */ + void reset(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + /* + * Put modified contents back into memory. + */ + void store(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + + private: + bool checkOK(int address); // check if memory tag in place + void writeByte(int address, uint8_t value); // write only if needed + +}; + +#endif Property changes on: trunk/prototypes/C/src/openlcb/NodeMemory.h ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Modified: trunk/prototypes/C/tests/Makefile =================================================================== --- trunk/prototypes/C/tests/Makefile 2010-06-27 04:49:57 UTC (rev 424) +++ trunk/prototypes/C/tests/Makefile 2010-06-27 08:28:35 UTC (rev 425) @@ -2,7 +2,7 @@ include ../standard.mk -BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest +BINFILES := ConfigurationTest StreamTest DatagramTest CanMrrlcbTest NodeMemoryTest default: clean compile $(BINFILES) @@ -18,3 +18,6 @@ ConfigurationTest: @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold ConfigurationTest.o -o ConfigurationTest +NodeMemoryTest: + @$(CXX) -L../src/openlcb -lopenlcb -L../scaffold -lscaffold NodeMemoryTest.o -o NodeMemoryTest + Added: trunk/prototypes/C/tests/NodeMemoryTest.cpp =================================================================== --- trunk/prototypes/C/tests/NodeMemoryTest.cpp (rev 0) +++ trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,67 @@ +//=========================================================== +// StreamTest +// Tests for OpenLCB Stream support +// +// Bob Jacobsen 2010 +//=========================================================== +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> + +#include "logging.h" +#include "NodeMemory.h" + +#include "EEPROM.h" +#include "Event.h" +#include "NodeID.h" + +NodeID node(1,2,3,4,5,6); + +Event cEvents[] = { + Event(1,2,3,4,5,6,7,8), + Event(17,18,19,20,21,22,23,24) +}; +int cEventNum = 2; + +Event pEvents[] = { + Event(33,34,35,36,37,38,39,40), + Event(65,66,67,68,69,70,71,72) +}; +int pEventNum = 2; + +NodeMemory m; + +int main( int argc, const char* argv[] ) +{ + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do reset\n"); + m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do reset\n"); + m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("do setup\n"); + m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("change values\n"); + cEvents[0] = pEvents[1]; + m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + + printf("change values\n"); + Event a(10,11,12,13,14,15,16,17); + cEvents[1] = a; + m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + EEPROM.dump(); + +} \ No newline at end of file Property changes on: trunk/prototypes/C/tests/NodeMemoryTest.cpp ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native Added: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt (rev 0) +++ trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 08:28:35 UTC (rev 425) @@ -0,0 +1,63 @@ +do setup +ee 55 5e e5 + 0 1 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 1 0 0 0 0 + 1 2 3 4 5 6 0 2 0 0 0 0 + 1 2 3 4 5 6 0 3 0 0 0 0 + 1 2 3 4 5 6 0 4 0 0 0 0 + +do setup +ee 55 5e e5 + 0 1 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 1 0 0 0 0 + 1 2 3 4 5 6 0 2 0 0 0 0 + 1 2 3 4 5 6 0 3 0 0 0 0 + 1 2 3 4 5 6 0 4 0 0 0 0 + +do reset +ee 55 5e e5 + 0 2 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 5 0 0 0 0 + 1 2 3 4 5 6 0 6 0 0 0 0 + 1 2 3 4 5 6 0 7 0 0 0 0 + 1 2 3 4 5 6 0 8 0 0 0 0 + +do reset +ee 55 5e e5 + 0 3 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 9 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +do setup +ee 55 5e e5 + 0 3 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 9 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +change values +ee 55 5e e5 + 0 4 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 c 0 0 0 0 + 1 2 3 4 5 6 0 a 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + +change values +ee 55 5e e5 + 0 5 + 1 2 3 4 5 6 + 1 2 3 4 5 6 0 c 0 0 0 0 + a b c d e f 10 11 0 0 0 0 + 1 2 3 4 5 6 0 b 0 0 0 0 + 1 2 3 4 5 6 0 c 0 0 0 0 + Property changes on: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-27 16:21:34
|
Revision: 427 http://openlcb.svn.sourceforge.net/openlcb/?rev=427&view=rev Author: jacobsen Date: 2010-06-27 16:21:28 +0000 (Sun, 27 Jun 2010) Log Message: ----------- refactor NodeMemory to maintain internal count Modified Paths: -------------- trunk/prototypes/C/src/openlcb/NodeMemory.cpp trunk/prototypes/C/src/openlcb/NodeMemory.h trunk/prototypes/C/tests/NodeMemoryTest.cpp trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt Modified: trunk/prototypes/C/src/openlcb/NodeMemory.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 16:21:28 UTC (rev 427) @@ -4,25 +4,30 @@ #include "NodeMemory.h" #include "logging.h" +#include "EventID.h" #include "Event.h" #include "NodeID.h" #include "EEPROM.h" -// doesn't do anything -NodeMemory::NodeMemory() {} +// ToDo: NodeID* not kept in object member to save RAM space, may be false economy -void NodeMemory::setup(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { - if (!checkOK(addr)) { +NodeMemory::NodeMemory(int start) { + startAddress = start; + count = 0; +} + +void NodeMemory::setup(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + if (!checkOK()) { // have to reload // clear the count - writeByte(addr+4, 0); - writeByte(addr+5, 0); + writeByte(startAddress+4, 0); + writeByte(startAddress+5, 0); // handle the rest - reset(addr, nid, cE, nC, pE, nP); + reset(nid, cE, nC, pE, nP); } // read NodeID from non-volative memory uint8_t* p; - addr = addr+6; // skip check word and count + int addr = startAddress+6; // skip check word and count p = (uint8_t*)nid; for (int i=0; i<sizeof(NodeID); i++) *p++ = EEPROM.read(addr++); @@ -41,53 +46,33 @@ } -void NodeMemory::reset(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { - // do the in-memory update - // TODO: Not updating the count for used events properly, using - // TODO: the over-all store count, which includes writing back event changes - int part1 = EEPROM.read(addr+4); - int part2 = EEPROM.read(addr+5); - uint16_t count = ((part1<<8)+part2)*(nP+nC)+1; +void NodeMemory::reset(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // Do the in-memory update. Does not change + // the total count, this is not an "initial config" for factory use. + Event* c; - c = cE; for (int i = 0; i<nC; i++) { - uint8_t* p = (uint8_t*)c++; - uint8_t* n = (uint8_t*)nid; - for (int k=0; k<sizeof(*nid); k++) - *p++ = *n++; - *p++ = (count>>8)&0xFF; - *p++ = count&0xFF; - count++; + setToNewEventID(nid, c++); } c = pE; for (int i = 0; i<nP; i++) { - uint8_t* p = (uint8_t*)c++; - uint8_t* n = (uint8_t*)nid; - for (int k=0; k<sizeof(*nid); k++) - *p++ = *n++; - *p++ = (count>>8)&0xFF; - *p++ = count&0xFF; - count++; + setToNewEventID(nid, c++); } // and store - store(addr, nid, cE, nC, pE, nP); + store(nid, cE, nC, pE, nP); } -void NodeMemory::store(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { +void NodeMemory::store(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + + int addr = startAddress; // write tag writeByte(addr++, 0xEE); writeByte(addr++, 0x55); writeByte(addr++, 0x5E); writeByte(addr++, 0xE5); - // TODO: is this right way to handle count? - // incremement count of writes - int part1 = EEPROM.read(addr); - int part2 = EEPROM.read(addr+1); - uint16_t count = (part1<<8)+part2; - count++; writeByte(addr++, (count>>8)&0xFF); writeByte(addr++, (count)&0xFF); @@ -110,11 +95,20 @@ writeByte(addr++, *p++); } -bool NodeMemory::checkOK(int addr) { - if (EEPROM.read(addr ) != 0xEE ) return false; - if (EEPROM.read(addr+1) != 0x55 ) return false; - if (EEPROM.read(addr+2) != 0x5E ) return false; - if (EEPROM.read(addr+3) != 0xE5 ) return false; +void NodeMemory::setToNewEventID(NodeID* nid, EventID* eventID) { + uint8_t* p = (uint8_t*)eventID; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count++>>8)&0xFF; + *p++ = count&0xFF; +} + +bool NodeMemory::checkOK() { + if (EEPROM.read(startAddress ) != 0xEE ) return false; + if (EEPROM.read(startAddress+1) != 0x55 ) return false; + if (EEPROM.read(startAddress+2) != 0x5E ) return false; + if (EEPROM.read(startAddress+3) != 0xE5 ) return false; return true; } Modified: trunk/prototypes/C/src/openlcb/NodeMemory.h =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 16:21:28 UTC (rev 427) @@ -5,50 +5,68 @@ * Class for persisting node memory * in a non-volative memory, e.g. EEPROM. * - * This class doesn't take any space, it just - * organizes code. It stores a NodeID and - * two arrays of Events; it's up to you to store - * everything else. + * This class loads from and stores to EEPROM + * a NodeID and two arrays of Events; it's up to you + * to store everything else. * * The memory can either be * blank, needing complete initialization or - * OK at startup. + * OK at startup. Call setup(...) with a valid NodeID + * to either load or create EventIDs. * + * If you change those, call store(...) when done. + * * When you "reset" the memory, you're * putting _new_ unique EventIDs in place. * + * TODO: Add a "dirty" bit to make store logic easier for external code? + * */ #include <stdint.h> class NodeID; class Event; +class EventID; class NodeMemory { public: - NodeMemory(); // doesn't do anything + /** + * Define starting address in EEPROM + */ + NodeMemory(int startAddress); // doesn't do anything /** * Make sure ready to go. NodeID should have a default * value already in case this is the first time. */ - void setup(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void setup(NodeID* nid, Event* c, int nC, Event* p, int nP); /* * Move to a completely new set of values, e.g. a factory reset * for OpenLCB. NodeID is not changed. */ - void reset(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void reset(NodeID* nid, Event* c, int nC, Event* p, int nP); /* * Put modified contents back into memory. */ - void store(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void store(NodeID* nid, Event* c, int nC, Event* p, int nP); + /* + * Get a new, forever unique EventID and put in + * given EventID location. Does not do a EEPROM store, + * which must be done separately. unique ID build using + * this node's nodeID. + */ + void setToNewEventID(NodeID* nodeID, EventID* eventID); + private: - bool checkOK(int address); // check if memory tag in place + bool checkOK(); // check if memory tag in place void writeByte(int address, uint8_t value); // write only if needed + int startAddress; // address of 1st byte in EEPROM + int count; // count of EventIDs provided to date }; #endif Modified: trunk/prototypes/C/tests/NodeMemoryTest.cpp =================================================================== --- trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 16:21:28 UTC (rev 427) @@ -29,39 +29,39 @@ }; int pEventNum = 2; -NodeMemory m; +NodeMemory m(0); int main( int argc, const char* argv[] ) { printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do reset\n"); - m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.reset(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do reset\n"); - m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.reset(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("change values\n"); cEvents[0] = pEvents[1]; - m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.store(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("change values\n"); Event a(10,11,12,13,14,15,16,17); cEvents[1] = a; - m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.store(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); } \ No newline at end of file Modified: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 16:21:28 UTC (rev 427) @@ -1,6 +1,6 @@ do setup ee 55 5e e5 - 0 1 + 0 4 1 2 3 4 5 6 1 2 3 4 5 6 0 1 0 0 0 0 1 2 3 4 5 6 0 2 0 0 0 0 @@ -9,7 +9,7 @@ do setup ee 55 5e e5 - 0 1 + 0 4 1 2 3 4 5 6 1 2 3 4 5 6 0 1 0 0 0 0 1 2 3 4 5 6 0 2 0 0 0 0 @@ -18,7 +18,7 @@ do reset ee 55 5e e5 - 0 2 + 0 8 1 2 3 4 5 6 1 2 3 4 5 6 0 5 0 0 0 0 1 2 3 4 5 6 0 6 0 0 0 0 @@ -27,7 +27,7 @@ do reset ee 55 5e e5 - 0 3 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 9 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -36,7 +36,7 @@ do setup ee 55 5e e5 - 0 3 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 9 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -45,7 +45,7 @@ change values ee 55 5e e5 - 0 4 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 c 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -54,7 +54,7 @@ change values ee 55 5e e5 - 0 5 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 c 0 0 0 0 a b c d e f 10 11 0 0 0 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-06-27 16:21:34
|
Revision: 427 http://openlcb.svn.sourceforge.net/openlcb/?rev=427&view=rev Author: jacobsen Date: 2010-06-27 16:21:28 +0000 (Sun, 27 Jun 2010) Log Message: ----------- refactor NodeMemory to maintain internal count Modified Paths: -------------- trunk/prototypes/C/src/openlcb/NodeMemory.cpp trunk/prototypes/C/src/openlcb/NodeMemory.h trunk/prototypes/C/tests/NodeMemoryTest.cpp trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt Modified: trunk/prototypes/C/src/openlcb/NodeMemory.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/src/openlcb/NodeMemory.cpp 2010-06-27 16:21:28 UTC (rev 427) @@ -4,25 +4,30 @@ #include "NodeMemory.h" #include "logging.h" +#include "EventID.h" #include "Event.h" #include "NodeID.h" #include "EEPROM.h" -// doesn't do anything -NodeMemory::NodeMemory() {} +// ToDo: NodeID* not kept in object member to save RAM space, may be false economy -void NodeMemory::setup(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { - if (!checkOK(addr)) { +NodeMemory::NodeMemory(int start) { + startAddress = start; + count = 0; +} + +void NodeMemory::setup(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + if (!checkOK()) { // have to reload // clear the count - writeByte(addr+4, 0); - writeByte(addr+5, 0); + writeByte(startAddress+4, 0); + writeByte(startAddress+5, 0); // handle the rest - reset(addr, nid, cE, nC, pE, nP); + reset(nid, cE, nC, pE, nP); } // read NodeID from non-volative memory uint8_t* p; - addr = addr+6; // skip check word and count + int addr = startAddress+6; // skip check word and count p = (uint8_t*)nid; for (int i=0; i<sizeof(NodeID); i++) *p++ = EEPROM.read(addr++); @@ -41,53 +46,33 @@ } -void NodeMemory::reset(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { - // do the in-memory update - // TODO: Not updating the count for used events properly, using - // TODO: the over-all store count, which includes writing back event changes - int part1 = EEPROM.read(addr+4); - int part2 = EEPROM.read(addr+5); - uint16_t count = ((part1<<8)+part2)*(nP+nC)+1; +void NodeMemory::reset(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + // Do the in-memory update. Does not change + // the total count, this is not an "initial config" for factory use. + Event* c; - c = cE; for (int i = 0; i<nC; i++) { - uint8_t* p = (uint8_t*)c++; - uint8_t* n = (uint8_t*)nid; - for (int k=0; k<sizeof(*nid); k++) - *p++ = *n++; - *p++ = (count>>8)&0xFF; - *p++ = count&0xFF; - count++; + setToNewEventID(nid, c++); } c = pE; for (int i = 0; i<nP; i++) { - uint8_t* p = (uint8_t*)c++; - uint8_t* n = (uint8_t*)nid; - for (int k=0; k<sizeof(*nid); k++) - *p++ = *n++; - *p++ = (count>>8)&0xFF; - *p++ = count&0xFF; - count++; + setToNewEventID(nid, c++); } // and store - store(addr, nid, cE, nC, pE, nP); + store(nid, cE, nC, pE, nP); } -void NodeMemory::store(int addr, NodeID* nid, Event* cE, int nC, Event* pE, int nP) { +void NodeMemory::store(NodeID* nid, Event* cE, int nC, Event* pE, int nP) { + + int addr = startAddress; // write tag writeByte(addr++, 0xEE); writeByte(addr++, 0x55); writeByte(addr++, 0x5E); writeByte(addr++, 0xE5); - // TODO: is this right way to handle count? - // incremement count of writes - int part1 = EEPROM.read(addr); - int part2 = EEPROM.read(addr+1); - uint16_t count = (part1<<8)+part2; - count++; writeByte(addr++, (count>>8)&0xFF); writeByte(addr++, (count)&0xFF); @@ -110,11 +95,20 @@ writeByte(addr++, *p++); } -bool NodeMemory::checkOK(int addr) { - if (EEPROM.read(addr ) != 0xEE ) return false; - if (EEPROM.read(addr+1) != 0x55 ) return false; - if (EEPROM.read(addr+2) != 0x5E ) return false; - if (EEPROM.read(addr+3) != 0xE5 ) return false; +void NodeMemory::setToNewEventID(NodeID* nid, EventID* eventID) { + uint8_t* p = (uint8_t*)eventID; + uint8_t* n = (uint8_t*)nid; + for (int k=0; k<sizeof(*nid); k++) + *p++ = *n++; + *p++ = (count++>>8)&0xFF; + *p++ = count&0xFF; +} + +bool NodeMemory::checkOK() { + if (EEPROM.read(startAddress ) != 0xEE ) return false; + if (EEPROM.read(startAddress+1) != 0x55 ) return false; + if (EEPROM.read(startAddress+2) != 0x5E ) return false; + if (EEPROM.read(startAddress+3) != 0xE5 ) return false; return true; } Modified: trunk/prototypes/C/src/openlcb/NodeMemory.h =================================================================== --- trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/src/openlcb/NodeMemory.h 2010-06-27 16:21:28 UTC (rev 427) @@ -5,50 +5,68 @@ * Class for persisting node memory * in a non-volative memory, e.g. EEPROM. * - * This class doesn't take any space, it just - * organizes code. It stores a NodeID and - * two arrays of Events; it's up to you to store - * everything else. + * This class loads from and stores to EEPROM + * a NodeID and two arrays of Events; it's up to you + * to store everything else. * * The memory can either be * blank, needing complete initialization or - * OK at startup. + * OK at startup. Call setup(...) with a valid NodeID + * to either load or create EventIDs. * + * If you change those, call store(...) when done. + * * When you "reset" the memory, you're * putting _new_ unique EventIDs in place. * + * TODO: Add a "dirty" bit to make store logic easier for external code? + * */ #include <stdint.h> class NodeID; class Event; +class EventID; class NodeMemory { public: - NodeMemory(); // doesn't do anything + /** + * Define starting address in EEPROM + */ + NodeMemory(int startAddress); // doesn't do anything /** * Make sure ready to go. NodeID should have a default * value already in case this is the first time. */ - void setup(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void setup(NodeID* nid, Event* c, int nC, Event* p, int nP); /* * Move to a completely new set of values, e.g. a factory reset * for OpenLCB. NodeID is not changed. */ - void reset(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void reset(NodeID* nid, Event* c, int nC, Event* p, int nP); /* * Put modified contents back into memory. */ - void store(int address, NodeID* nid, Event* c, int nC, Event* p, int nP); + void store(NodeID* nid, Event* c, int nC, Event* p, int nP); + /* + * Get a new, forever unique EventID and put in + * given EventID location. Does not do a EEPROM store, + * which must be done separately. unique ID build using + * this node's nodeID. + */ + void setToNewEventID(NodeID* nodeID, EventID* eventID); + private: - bool checkOK(int address); // check if memory tag in place + bool checkOK(); // check if memory tag in place void writeByte(int address, uint8_t value); // write only if needed + int startAddress; // address of 1st byte in EEPROM + int count; // count of EventIDs provided to date }; #endif Modified: trunk/prototypes/C/tests/NodeMemoryTest.cpp =================================================================== --- trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/tests/NodeMemoryTest.cpp 2010-06-27 16:21:28 UTC (rev 427) @@ -29,39 +29,39 @@ }; int pEventNum = 2; -NodeMemory m; +NodeMemory m(0); int main( int argc, const char* argv[] ) { printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do reset\n"); - m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.reset(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do reset\n"); - m.reset(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.reset(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("do setup\n"); - m.setup(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.setup(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("change values\n"); cEvents[0] = pEvents[1]; - m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.store(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); printf("change values\n"); Event a(10,11,12,13,14,15,16,17); cEvents[1] = a; - m.store(0, &node, cEvents, cEventNum, pEvents, cEventNum); + m.store(&node, cEvents, cEventNum, pEvents, cEventNum); EEPROM.dump(); } \ No newline at end of file Modified: trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt =================================================================== --- trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 13:37:31 UTC (rev 426) +++ trunk/prototypes/C/tests/results/NodeMemoryTest.out.txt 2010-06-27 16:21:28 UTC (rev 427) @@ -1,6 +1,6 @@ do setup ee 55 5e e5 - 0 1 + 0 4 1 2 3 4 5 6 1 2 3 4 5 6 0 1 0 0 0 0 1 2 3 4 5 6 0 2 0 0 0 0 @@ -9,7 +9,7 @@ do setup ee 55 5e e5 - 0 1 + 0 4 1 2 3 4 5 6 1 2 3 4 5 6 0 1 0 0 0 0 1 2 3 4 5 6 0 2 0 0 0 0 @@ -18,7 +18,7 @@ do reset ee 55 5e e5 - 0 2 + 0 8 1 2 3 4 5 6 1 2 3 4 5 6 0 5 0 0 0 0 1 2 3 4 5 6 0 6 0 0 0 0 @@ -27,7 +27,7 @@ do reset ee 55 5e e5 - 0 3 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 9 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -36,7 +36,7 @@ do setup ee 55 5e e5 - 0 3 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 9 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -45,7 +45,7 @@ change values ee 55 5e e5 - 0 4 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 c 0 0 0 0 1 2 3 4 5 6 0 a 0 0 0 0 @@ -54,7 +54,7 @@ change values ee 55 5e e5 - 0 5 + 0 c 1 2 3 4 5 6 1 2 3 4 5 6 0 c 0 0 0 0 a b c d e f 10 11 0 0 0 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-07-01 21:19:04
|
Revision: 497 http://openlcb.svn.sourceforge.net/openlcb/?rev=497&view=rev Author: jacobsen Date: 2010-07-01 21:18:57 +0000 (Thu, 01 Jul 2010) Log Message: ----------- add argument to allow cancel markToLearn Modified Paths: -------------- trunk/prototypes/C/src/openlcb/PCE.cpp trunk/prototypes/C/src/openlcb/PCE.h trunk/prototypes/C/tests/CanMrrlcbTest.cpp Modified: trunk/prototypes/C/src/openlcb/PCE.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/PCE.cpp 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/src/openlcb/PCE.cpp 2010-07-01 21:18:57 UTC (rev 497) @@ -102,8 +102,11 @@ consumed[index].flags |= IDENT_FLAG; } - void PCE::markToLearnP(int index) { - produced[index].flags |= LEARN_FLAG; + void PCE::markToLearnP(int index, bool mark) { + if (mark) + produced[index].flags |= LEARN_FLAG; + else + produced[index].flags &= ~LEARN_FLAG; sendProducer = min(sendProducer, index); } @@ -112,8 +115,11 @@ sendProducer = min(sendProducer, index); } - void PCE::markToLearnC(int index) { - consumed[index].flags |= LEARN_FLAG; + void PCE::markToLearnC(int index, bool mark) { + if (mark) + consumed[index].flags |= LEARN_FLAG; + else + consumed[index].flags &= ~LEARN_FLAG; sendConsumer = min(sendConsumer, index); } Modified: trunk/prototypes/C/src/openlcb/PCE.h =================================================================== --- trunk/prototypes/C/src/openlcb/PCE.h 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/src/openlcb/PCE.h 2010-07-01 21:18:57 UTC (rev 497) @@ -64,12 +64,13 @@ * Mark a particular slot to acquire the event * from the next learn message. * C is consumers, P is producers. + * true marks, false unmarks. * * index is the 0-based index of the desired * event in the array provided to the ctor earlier. */ - void markToLearnC(int index); - void markToLearnP(int index); + void markToLearnC(int index, bool mark); + void markToLearnP(int index, bool mark); /** * Send a learn frame for a particular slot's event. Modified: trunk/prototypes/C/tests/CanMrrlcbTest.cpp =================================================================== --- trunk/prototypes/C/tests/CanMrrlcbTest.cpp 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/tests/CanMrrlcbTest.cpp 2010-07-01 21:18:57 UTC (rev 497) @@ -229,8 +229,10 @@ printf("\n"); printf("Learn p0, c1\n"); - p.markToLearnP(0); - p.markToLearnC(1); + p.markToLearnP(0, true); + p.markToLearnC(0, true); + p.markToLearnC(1, true); + p.markToLearnC(0, false); printf("Teach new event 0x2x\n"); b.id = 0x182cf00F; b.length = (uint8_t)8; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-07-01 21:19:04
|
Revision: 497 http://openlcb.svn.sourceforge.net/openlcb/?rev=497&view=rev Author: jacobsen Date: 2010-07-01 21:18:57 +0000 (Thu, 01 Jul 2010) Log Message: ----------- add argument to allow cancel markToLearn Modified Paths: -------------- trunk/prototypes/C/src/openlcb/PCE.cpp trunk/prototypes/C/src/openlcb/PCE.h trunk/prototypes/C/tests/CanMrrlcbTest.cpp Modified: trunk/prototypes/C/src/openlcb/PCE.cpp =================================================================== --- trunk/prototypes/C/src/openlcb/PCE.cpp 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/src/openlcb/PCE.cpp 2010-07-01 21:18:57 UTC (rev 497) @@ -102,8 +102,11 @@ consumed[index].flags |= IDENT_FLAG; } - void PCE::markToLearnP(int index) { - produced[index].flags |= LEARN_FLAG; + void PCE::markToLearnP(int index, bool mark) { + if (mark) + produced[index].flags |= LEARN_FLAG; + else + produced[index].flags &= ~LEARN_FLAG; sendProducer = min(sendProducer, index); } @@ -112,8 +115,11 @@ sendProducer = min(sendProducer, index); } - void PCE::markToLearnC(int index) { - consumed[index].flags |= LEARN_FLAG; + void PCE::markToLearnC(int index, bool mark) { + if (mark) + consumed[index].flags |= LEARN_FLAG; + else + consumed[index].flags &= ~LEARN_FLAG; sendConsumer = min(sendConsumer, index); } Modified: trunk/prototypes/C/src/openlcb/PCE.h =================================================================== --- trunk/prototypes/C/src/openlcb/PCE.h 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/src/openlcb/PCE.h 2010-07-01 21:18:57 UTC (rev 497) @@ -64,12 +64,13 @@ * Mark a particular slot to acquire the event * from the next learn message. * C is consumers, P is producers. + * true marks, false unmarks. * * index is the 0-based index of the desired * event in the array provided to the ctor earlier. */ - void markToLearnC(int index); - void markToLearnP(int index); + void markToLearnC(int index, bool mark); + void markToLearnP(int index, bool mark); /** * Send a learn frame for a particular slot's event. Modified: trunk/prototypes/C/tests/CanMrrlcbTest.cpp =================================================================== --- trunk/prototypes/C/tests/CanMrrlcbTest.cpp 2010-07-01 20:48:16 UTC (rev 496) +++ trunk/prototypes/C/tests/CanMrrlcbTest.cpp 2010-07-01 21:18:57 UTC (rev 497) @@ -229,8 +229,10 @@ printf("\n"); printf("Learn p0, c1\n"); - p.markToLearnP(0); - p.markToLearnC(1); + p.markToLearnP(0, true); + p.markToLearnC(0, true); + p.markToLearnC(1, true); + p.markToLearnC(0, false); printf("Teach new event 0x2x\n"); b.id = 0x182cf00F; b.length = (uint8_t)8; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jac...@us...> - 2010-07-03 16:02:46
|
Revision: 519 http://openlcb.svn.sourceforge.net/openlcb/?rev=519&view=rev Author: jacobsen Date: 2010-07-03 16:02:40 +0000 (Sat, 03 Jul 2010) Log Message: ----------- rename for consistency with other prototype directories Modified Paths: -------------- trunk/prototypes/C/Makefile Added Paths: ----------- trunk/prototypes/C/test/ Removed Paths: ------------- trunk/prototypes/C/tests/ Modified: trunk/prototypes/C/Makefile =================================================================== --- trunk/prototypes/C/Makefile 2010-07-03 06:14:05 UTC (rev 518) +++ trunk/prototypes/C/Makefile 2010-07-03 16:02:40 UTC (rev 519) @@ -13,7 +13,7 @@ @make -C scaffold CPPFLAGS="$(CPPFLAGS)" tests: FORCE - @make -C tests CPPFLAGS="$(CPPFLAGS)" + @make -C test CPPFLAGS="$(CPPFLAGS)" clean: FORCE @@ -25,16 +25,16 @@ # run all tests run: all - @echo StreamTest; ./tests/StreamTest | diff - tests/results/StreamTest.out.txt - @echo DatagramTest; ./tests/DatagramTest | diff - tests/results/DatagramTest.out.txt - @echo NodeMemoryTest; ./tests/NodeMemoryTest | diff - tests/results/NodeMemoryTest.out.txt - @echo ConfigurationTest; ./tests/ConfigurationTest | diff - tests/results/ConfigurationTest.out.txt - @echo CanMrrlcbTest; ./tests/CanMrrlcbTest | diff - tests/results/CanMrrlcbTest.out.txt + @echo CanMrrlcbTest; ./test/CanMrrlcbTest | diff - test/results/CanMrrlcbTest.out.txt + @echo StreamTest; ./test/StreamTest | diff - test/results/StreamTest.out.txt + @echo DatagramTest; ./test/DatagramTest | diff - test/results/DatagramTest.out.txt + @echo NodeMemoryTest; ./test/NodeMemoryTest | diff - test/results/NodeMemoryTest.out.txt + @echo ConfigurationTest; ./test/ConfigurationTest | diff - test/results/ConfigurationTest.out.txt # reset the comparison files; only if sure! -reset: - @./tests/StreamTest > tests/results/StreamTest.out.txt - @./tests/DatagramTest > tests/results/DatagramTest.out.txt - @./tests/NodeMemoryTest > tests/results/NodeMemoryTest.out.txt - @./tests/ConfigurationTest > tests/results/ConfigurationTest.out.txt - @./tests/CanMrrlcbTest > tests/results/CanMrrlcbTest.out.txt +#reset: +# @./test/StreamTest > test/results/StreamTest.out.txt +# @./test/DatagramTest > test/results/DatagramTest.out.txt +# @./test/NodeMemoryTest > test/results/NodeMemoryTest.out.txt +# @./test/ConfigurationTest > test/results/ConfigurationTest.out.txt +# @./test/CanMrrlcbTest > test/results/CanMrrlcbTest.out.txt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |