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
67
68 byte *getDataBuffer(){return data;};
69 void setDataBuffer(byte val[CANDATA_SIZE]);
70
71 byte *getHeaderBuffer(){return header;};
72 void setHeaderBuffer(byte val[HEADER_SIZE] );
73
74 byte getCanId();
75 void setCanId(byte val) { canId = val; }
76
77 byte getOpc();
78 void setOpc(byte val) {opc = val; }
79
80 message_type getType() { return _type; }
81 void setType(message_type val) { _type = val; }
82
83 unsigned int getEventNumber();
84 void setEventNumber(unsigned int val) { _eventNumber = val; }
85
86 unsigned int getNodeNumber();
87 void setNodeNumber(unsigned int val) { _nodeNumber = val; }
88
89 unsigned int getDeviceNumber();
90 void setDeviceNumber(unsigned int val) { _deviceNumber = val; }
91
92
93
94 byte getPriority() { return _priority;}
95 void setPriority(byte val) { _priority = val; }
96
97 byte getMessageSize();
98 unsigned int getNumBytes() { return _numBytes; }
99 void setNumBytes(unsigned int val) { _numBytes = val; }
100
101 void setRTR() {_RTR=true;};
102 void unsetRTR(){_RTR=false;};
103 bool getRTR(){return _RTR;};
104
105 void setSession(byte val) {_session=val;}
106 byte getSession();
107
108 unsigned int getDecoder();
109 void setDecoder(unsigned int val) { _decoder = val; }
110
111 unsigned int getCV();
112 void setCV(unsigned int val) { _cv = val; }
113
114 unsigned int getCVMode();
115 unsigned int getCVValue();
116 byte getConsist();
117 byte getSpeedDir();
118 byte getEngineFlag();
119 byte getAvailableEventsLeft();
120 byte getStoredEvents();
121 byte getFunctionNumber();
122 byte functionValue();
123 byte getStatus();
124 byte getParaIndex();
125 byte getParameter();
126 byte getNodeVariableIndex();
127 byte getNodeVariable();
128 byte getEventIndex();
129 byte getEventVarIndex();
130 byte getEventVar();
131 void clear();
132 void setDebug(bool val){debug=val;};
133 byte getCanMessageSize();
134 void setCanMessageSize(byte val) {canMsgSize=val;};
135
136 bool isAccOn();
137 bool isAccOff();
138 bool isLongEvent();
139 bool isShortEvent();
140 byte accExtraData();
141 byte getAccExtraData(byte idx);//idx starts at 1
142 void createOnEvent(unsigned int nodeNumber,bool longEvent,unsigned int eventNumber,byte numDataBytes,byte* data);
143 void createOffEvent(unsigned int nodeNumber,bool longEvent,unsigned int eventNumber,byte numDataBytes,byte* data);
144
145
146 protected:
147 private:
148 byte canId;
149 byte opc;
150 byte msgSize;
151 byte canMsgSize;
152 message_type _type;
153 unsigned int _eventNumber;
154 unsigned int _nodeNumber;
155 unsigned int _deviceNumber;
156 unsigned int _decoder;
157 unsigned int _cv;
158 byte _session;
159 byte data[CANDATA_SIZE] ;
160 byte header[HEADER_SIZE] ;
161 byte _priority;
162 unsigned int _numBytes;
163 bool _RTR;
164 message_type messages[MSGSIZE];
165 unsigned int message_params[MSGSIZE];
166 bool hasThisData(byte opc, message_config_pos pos);
167 void loadMessageConfig();
168 void loadMessageType();
170 bool debug;
171
172 };
173
174 #endif // MESSAGE_H
Message::getNodeVariable
byte getNodeVariable()
Definition: Message.cpp:461
Message::getCV
unsigned int getCV()
Definition: Message.cpp:256
Message::getEventIndex
byte getEventIndex()
Definition: Message.cpp:473
Message::getCanId
byte getCanId()
Definition: Message.cpp:71
Message::isAccOn
bool isAccOn()
Definition: Message.cpp:553
Message::setDataBuffer
void setDataBuffer(byte val[CANDATA_SIZE])
Definition: Message.cpp:91
Message::isShortEvent
bool isShortEvent()
Definition: Message.cpp:590
Message::isAccOff
bool isAccOff()
Definition: Message.cpp:571
Message::getAccExtraData
byte getAccExtraData(byte idx)
Definition: Message.cpp:650
Message::getCVMode
unsigned int getCVMode()
Definition: Message.cpp:293
Message::getEventNumber
unsigned int getEventNumber()
Definition: Message.cpp:195
Message::getEngineFlag
byte getEngineFlag()
Definition: Message.cpp:337
Message::getConsist
byte getConsist()
Definition: Message.cpp:308
Message::setHeaderBuffer
void setHeaderBuffer(byte val[HEADER_SIZE])
Definition: Message.cpp:103
Message::Message
Message()
Definition: Message.cpp:9
Message::getNodeNumber
unsigned int getNodeNumber()
Definition: Message.cpp:155
Message::getEventVarIndex
byte getEventVarIndex()
Definition: Message.cpp:493
Message::getCanMessageSize
byte getCanMessageSize()
Definition: Message.cpp:53
Message::getAvailableEventsLeft
byte getAvailableEventsLeft()
Definition: Message.cpp:354
Message::getOpc
byte getOpc()
Definition: Message.cpp:83
Message::clear
void clear()
Definition: Message.cpp:113
Message::getStatus
byte getStatus()
Definition: Message.cpp:406
Message::getDecoder
unsigned int getDecoder()
Definition: Message.cpp:238
Message::getEventVar
byte getEventVar()
Definition: Message.cpp:512
Message::getParaIndex
byte getParaIndex()
Definition: Message.cpp:418
Message::~Message
virtual ~Message()
Definition: Message.cpp:44
Message::getByte
byte getByte(byte pos)
Definition: Message.cpp:140
Message::functionValue
byte functionValue()
Definition: Message.cpp:393
Message::getNodeVariableIndex
byte getNodeVariableIndex()
Definition: Message.cpp:449
Message::accExtraData
byte accExtraData()
Definition: Message.cpp:628
Message
Definition: Message.h:53
Message::getCVValue
unsigned int getCVValue()
Definition: Message.cpp:275
Message::getParameter
byte getParameter()
Definition: Message.cpp:437
Message::getMessageSize
byte getMessageSize()
Definition: Message.cpp:62
Message::getStoredEvents
byte getStoredEvents()
Definition: Message.cpp:367
Message::isLongEvent
bool isLongEvent()
Definition: Message.cpp:608
Message::getSpeedDir
byte getSpeedDir()
Definition: Message.cpp:321
Message::getDeviceNumber
unsigned int getDeviceNumber()
Definition: Message.cpp:212
Message::getSession
byte getSession()
Definition: Message.cpp:180
Message::getFunctionNumber
byte getFunctionNumber()
Definition: Message.cpp:381