mergCanBus

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
Message.h
1 #ifndef BYTE_TYPE
2 #define BYTE_TYPE
3 //typedef char byte;
4 #endif // BYTE_TYPE
5
6 #ifndef MESSAGE_H
7 #define MESSAGE_H
8
9 //#define bitRead(val,pos){return 1;};
10 //#define bitSet(val,pos){return;};
11 //#define bitClear(val,pos){return;};
12
13 #include <Arduino.h>
14 #include "opcodes.h"
15
16
17 #define CANDATA_SIZE 8
18 #define HEADER_SIZE 4
19 #define MSGSIZE 256
24 enum message_type {
25 RESERVED=0,
26 DCC=1,
27 CONFIG=2,
28 ACCESSORY=3,
29 GENERAL=4
30 };
31
37 enum message_config_pos {
38 NODE_NUMBER=0,
39 DEVICE_NUMBER=1,
40 EVENT_NUMBER=2,
41 SESSION=3,
42 DECODER=4,
43 CV=5
44 };
45
53 class Message
54 {
55 public:
56 Message();
57 Message(unsigned int canId,
58 unsigned int opc,
59 unsigned int nodeNumber,
60 unsigned int eventNumber,
61 byte data [CANDATA_SIZE] ,
62 unsigned int priority);
63 virtual ~Message();
64
65 byte getByte(byte pos);
66
71 byte *getDataBuffer(){return data;};
72 void setDataBuffer(byte val[CANDATA_SIZE]);
76 byte *getHeaderBuffer(){return header;};
77 void setHeaderBuffer(byte val[HEADER_SIZE] );
78
79 byte getCanId();
84 void setCanId(byte val) { canId = val; }
85
86 byte getOpc();
91 void setOpc(byte val) {opc = val; }
95 message_type getType() { return _type; }
100 void setType(message_type val) { _type = val; }
101
102 unsigned int getEventNumber();
107 void setEventNumber(unsigned int val) { _eventNumber = val; }
108
109 unsigned int getNodeNumber();
114 void setNodeNumber(unsigned int val) { _nodeNumber = val; }
115
116 unsigned int getDeviceNumber();
121 void setDeviceNumber(unsigned int val) { _deviceNumber = val; }
122
126 byte getPriority() { return _priority;}
131 void setPriority(byte val) { _priority = val; }
132
133 byte getMessageSize();
137 unsigned int getNumBytes() { return _numBytes; }
142 void setNumBytes(unsigned int val) { _numBytes = val; }
145 void setRTR() {_RTR=true;};
148 void unsetRTR(){_RTR=false;};
152 bool getRTR(){return _RTR;};
157 void setSession(byte val) {_session=val;}
158 byte getSession();
159
160 unsigned int getDecoder();
165 void setDecoder(unsigned int val) { _decoder = val; }
166
167 unsigned int getCV();
172 void setCV(unsigned int val) { _cv = val; }
173
174 unsigned int getCVMode();
175 unsigned int getCVValue();
176 byte getConsist();
177 byte getSpeedDir();
178 byte getEngineFlag();
179 byte getAvailableEventsLeft();
180 byte getStoredEvents();
181 byte getFunctionNumber();
182 byte functionValue();
183 byte getStatus();
184 byte getParaIndex();
185 byte getParameter();
186 byte getNodeVariableIndex();
187 byte getNodeVariable();
188 byte getEventIndex();
189 byte getEventVarIndex();
190 byte getEventVar();
191 void clear();
195 void setDebug(bool val){debug=val;};
196 byte getCanMessageSize();
201 void setCanMessageSize(byte val) {canMsgSize=val;};
202
203 bool isAccOn();
204 bool isAccOff();
205 bool isLongEvent();
206 bool isShortEvent();
207 byte accExtraData();
208 byte getAccExtraData(byte idx);//idx starts at 1
209 void createOnEvent(unsigned int nodeNumber,bool longEvent,unsigned int eventNumber,byte numDataBytes,byte* data);
210 void createOffEvent(unsigned int nodeNumber,bool longEvent,unsigned int eventNumber,byte numDataBytes,byte* data);
211
212
213 protected:
214 private:
215 byte canId;
216 byte opc;
217 byte msgSize;
218 byte canMsgSize;
219 message_type _type;
220 unsigned int _eventNumber;
221 unsigned int _nodeNumber;
222 unsigned int _deviceNumber;
223 unsigned int _decoder;
224 unsigned int _cv;
225 byte _session;
226 byte data[CANDATA_SIZE] ;
227 byte header[HEADER_SIZE] ;
228 byte _priority;
229 unsigned int _numBytes;
230 bool _RTR;
231 message_type messages[MSGSIZE];
232 unsigned int message_params[MSGSIZE];
233 bool hasThisData(byte opc, message_config_pos pos);
234 void loadMessageConfig();
235 void loadMessageType();
237 bool debug;
238
239 };
240
241 #endif // MESSAGE_H
Message::setDeviceNumber
void setDeviceNumber(unsigned int val)
Set the device number to be used on message NOT USED. At the moment the messages are being assembled ...
Definition: Message.h:121
Message::getNodeVariable
byte getNodeVariable()
Definition: Message.cpp:468
Message::setNodeNumber
void setNodeNumber(unsigned int val)
Set the node number to be used on message NOT USED. At the moment the messages are being assembled ou...
Definition: Message.h:114
Message::getType
message_type getType()
Get the message type.
Definition: Message.h:95
Message::getCV
unsigned int getCV()
Definition: Message.cpp:263
Message::getEventIndex
byte getEventIndex()
Definition: Message.cpp:480
Message::createOffEvent
void createOffEvent(unsigned int nodeNumber, bool longEvent, unsigned int eventNumber, byte numDataBytes, byte *data)
Create a OFF event message.
Definition: Message.cpp:755
Message::getCanId
byte getCanId()
Definition: Message.cpp:78
Message::isAccOn
bool isAccOn()
Definition: Message.cpp:560
Message::setDataBuffer
void setDataBuffer(byte val[CANDATA_SIZE])
Definition: Message.cpp:98
Message::isShortEvent
bool isShortEvent()
Definition: Message.cpp:597
Message::isAccOff
bool isAccOff()
Definition: Message.cpp:578
Message::getAccExtraData
byte getAccExtraData(byte idx)
Definition: Message.cpp:657
Message::getCVMode
unsigned int getCVMode()
Definition: Message.cpp:300
Message::getEventNumber
unsigned int getEventNumber()
Definition: Message.cpp:202
Message::getEngineFlag
byte getEngineFlag()
Definition: Message.cpp:344
Message::unsetRTR
void unsetRTR()
Unset the CAN RTR parameter.
Definition: Message.h:148
Message::setDebug
void setDebug(bool val)
Force the code to print debug messages to the serial interface if value is True.
Definition: Message.h:195
Message::setDecoder
void setDecoder(unsigned int val)
Set the decoder value NOT USED. At the moment the messages are being assembled outside and loaded by ...
Definition: Message.h:165
Message::setCanId
void setCanId(byte val)
Set the can id in the message NOT USED. At the moment the messages are being assembled outside and lo...
Definition: Message.h:84
Message::getConsist
byte getConsist()
Definition: Message.cpp:315
Message::setRTR
void setRTR()
Set the CAN RTR parameter. Set after reading the CAN header.
Definition: Message.h:145
Message::setHeaderBuffer
void setHeaderBuffer(byte val[HEADER_SIZE])
Definition: Message.cpp:110
Message::Message
Message()
Definition: Message.cpp:9
Message::getNodeNumber
unsigned int getNodeNumber()
Definition: Message.cpp:162
Message::setCV
void setCV(unsigned int val)
Set the DCC CV value in the message NOT USED. At the moment the messages are being assembled outside ...
Definition: Message.h:172
Message::getEventVarIndex
byte getEventVarIndex()
Definition: Message.cpp:500
Message::getCanMessageSize
byte getCanMessageSize()
Definition: Message.cpp:60
Message::getAvailableEventsLeft
byte getAvailableEventsLeft()
Definition: Message.cpp:361
Message::getOpc
byte getOpc()
Definition: Message.cpp:90
Message::clear
void clear()
Definition: Message.cpp:120
Message::getStatus
byte getStatus()
Definition: Message.cpp:413
Message::setPriority
void setPriority(byte val)
Set the message priority in the CAN header NOT USED. At the moment the messages are being assembled o...
Definition: Message.h:131
Message::setNumBytes
void setNumBytes(unsigned int val)
Set the number of bytes parameter in the message NOT USED. At the moment the messages are being assem...
Definition: Message.h:142
Message::getNumBytes
unsigned int getNumBytes()
Get the number of bytes parameter in the message.
Definition: Message.h:137
Message::getDecoder
unsigned int getDecoder()
Definition: Message.cpp:245
Message::getEventVar
byte getEventVar()
Definition: Message.cpp:519
Message::getParaIndex
byte getParaIndex()
Definition: Message.cpp:425
Message::setOpc
void setOpc(byte val)
Set the opc in the message NOT USED. At the moment the messages are being assembled outside and loade...
Definition: Message.h:91
Message::~Message
virtual ~Message()
Definition: Message.cpp:51
Message::getByte
byte getByte(byte pos)
Definition: Message.cpp:147
Message::functionValue
byte functionValue()
Definition: Message.cpp:400
Message::getHeaderBuffer
byte * getHeaderBuffer()
Get the 8 bytes CAN header buffer. The user can also get specific values using other methods...
Definition: Message.h:76
Message::createOnEvent
void createOnEvent(unsigned int nodeNumber, bool longEvent, unsigned int eventNumber, byte numDataBytes, byte *data)
Create a ON event message.
Definition: Message.cpp:686
Message::setEventNumber
void setEventNumber(unsigned int val)
Set event number to be used on message NOT USED. At the moment the messages are being assembled outsi...
Definition: Message.h:107
Message::getPriority
byte getPriority()
Get the message priority in the Can header.
Definition: Message.h:126
Message::setSession
void setSession(byte val)
Set the session value in the message NOT USED. At the moment the messages are being assembled outside...
Definition: Message.h:157
Message::getNodeVariableIndex
byte getNodeVariableIndex()
Definition: Message.cpp:456
Message::accExtraData
byte accExtraData()
Definition: Message.cpp:635
Message
Definition: Message.h:53
Message::getCVValue
unsigned int getCVValue()
Definition: Message.cpp:282
Message::getParameter
byte getParameter()
Definition: Message.cpp:444
Message::setCanMessageSize
void setCanMessageSize(byte val)
Set the message size NOT USED. At the moment the messages are being assembled outside and loaded by s...
Definition: Message.h:201
Message::setType
void setType(message_type val)
Set the message type NOT USED. At the moment the messages are being assembled outside and loaded by s...
Definition: Message.h:100
Message::getMessageSize
byte getMessageSize()
Definition: Message.cpp:69
Message::getStoredEvents
byte getStoredEvents()
Definition: Message.cpp:374
Message::isLongEvent
bool isLongEvent()
Definition: Message.cpp:615
Message::getSpeedDir
byte getSpeedDir()
Definition: Message.cpp:328
Message::getRTR
bool getRTR()
Get the CAN RTR parameter. Set after reading the CAN header.
Definition: Message.h:152
Message::getDeviceNumber
unsigned int getDeviceNumber()
Definition: Message.cpp:219
Message::getSession
byte getSession()
Definition: Message.cpp:187
Message::getFunctionNumber
byte getFunctionNumber()
Definition: Message.cpp:388
Message::getDataBuffer
byte * getDataBuffer()
Get the 8 bytes CAN message buffer. The user can also get specific values using other methods...
Definition: Message.h:71