mergCanBus

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
opcodes.h
1 #ifndef __OPCODES_H
2 #define __OPCODES_H
3 /* CANBUS OPCodes
4 Extracted from the Developer’s Guide for CBUS (Version 5g)
5 */
6 // NOTE: To display this file with everything correctly lined up set your editor or IDE tab stop to 4
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // at <http://www.gnu.org/licenses/>.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 // See the GNU General Public License for more details.
15 //
16 // As set out in the GNU General Public License, you must retain and acknowledge
17 // the statements above relating to copyright and licensing. You must also
18 // state clearly any modifications made. Please therefore retain this header
19 // and add documentation of any changes you make. If you distribute a changed
20 // version, you must make those changes publicly available.
21 //
22 // The GNU license requires that if you distribute this software, changed or
23 // unchanged, or software which includes code from this software, including
24 // the supply of hardware that incorporates this software, you MUST either
25 // include the source code or a link to a location where you make the source
26 // publicly available. The best way to make your changes publicly available is
27 // via the MERG online resources. See <www.merg.co.uk>
28
29
30 // Manufacturers
31 #define MANU_MERG 165 // http://www.merg.co.uk
32 #define MANU_ROCRAIL 70 // http://www.rocrail.net
33 #define MANU_SPECTRUM 80 // http://animatedmodeler.com (Spectrum Engineering)
34 // MERG Module types
35 #define MTYP_SLIM 0 // default for SLiM nodes
36 #define MTYP_FLIM 1 // default for SLiM nodes
37
38 // CBUS opcodes list
39 // Packets with no data bytes
40 #define OPC_ACK 0x00 // General ack
41 #define OPC_NAK 0x01 // General nak
42 #define OPC_HLT 0x02 // Bus Halt
43 #define OPC_BON 0x03 // Bus on
44 #define OPC_TOF 0x04 // Track off
45 #define OPC_TON 0x05 // Track on
46 #define OPC_ESTOP 0x06 // Track stopped
47 #define OPC_ARST 0x07 // System reset
48 #define OPC_RTOF 0x08 // Request track off
49 #define OPC_RTON 0x09 // Request track on
50 #define OPC_RESTP 0x0a // Request emergency stop all
51 #define OPC_RSTAT 0x0c // Request command station status
52 #define OPC_QNN 0x0d // Query nodes
53 #define OPC_RQNP 0x10 // Read node parameters
54 #define OPC_RQMN 0x11 // Request name of module type
55 // Packets with 1 data byte
56 #define OPC_KLOC 0x21 // Release engine by handle
57 #define OPC_QLOC 0x22 // Query engine by handle
58 #define OPC_DKEEP 0x23 // Keep alive for cab
59 #define OPC_DBG1 0x30 // Debug message with 1 status byte
60 #define OPC_EXTC 0x3F // Extended opcode
61 // Packets with 2 data bytes
62 #define OPC_RLOC 0x40 // Request session for loco
63 #define OPC_QCON 0x41 // Query consist
64 #define OPC_SNN 0x42 // Set node number
65 #define OPC_STMOD 0x44 // Set Throttle mode
66 #define OPC_PCON 0x45 // Consist loco
67 #define OPC_KCON 0x46 // De-consist loco
68 #define OPC_DSPD 0x47 // Loco speed/dir
69 #define OPC_DFLG 0x48 // Set engine flags
70 #define OPC_DFNON 0x49 // Loco function on
71 #define OPC_DFNOF 0x4A // Loco function off
72 #define OPC_SSTAT 0x4C // Service mode status
73 #define OPC_RQNN 0x50 // Request Node number in setup mode
74 #define OPC_NNREL 0x51 // Node number release
75 #define OPC_NNACK 0x52 // Node number acknowledge
76 #define OPC_NNLRN 0x53 // Set learn mode
77 #define OPC_NNULN 0x54 // Release learn mode
78 #define OPC_NNCLR 0x55 // Clear all events
79 #define OPC_NNEVN 0x56 // Read available event slots
80 #define OPC_NERD 0x57 // Read all stored events
81 #define OPC_RQEVN 0x58 // Read number of stored events
82 #define OPC_WRACK 0x59 // Write acknowledge
83 #define OPC_RQDAT 0x5A // Request node data event
84 #define OPC_RQDDS 0x5B // Request short data frame
85 #define OPC_BOOT 0x5C // Put node into boot mode
86 #define OPC_ENUM 0x5D // Force self enumeration for CAN_ID
87 #define OPC_RST 0x5E // Reset node
88 #define OPC_EXTC1 0x5F // Extended opcode with 1 data byte
89 // Packets with 3 data bytes
90 #define OPC_DFUN 0x60 // Set engine functions
91 #define OPC_GLOC 0x61 // Get loco (with support for steal/share)
92 #define OPC_ERR 0x63 // Command station error
93 #define OPC_CMDERR 0x6F // Errors from nodes during config
94 #define OPC_EVNLF 0x70 // Event slots left response
95 #define OPC_NVRD 0x71 // Request read of node variable
96 #define OPC_NENRD 0x72 // Request read stored event by index
97 #define OPC_RQNPN 0x73 // Request read module parameters
98 #define OPC_NUMEV 0x74 // Number of events stored response
99 #define OPC_CANID 0x75 // Set specified CANID.
100 #define OPC_EXTC2 0x7F // Extended opcode with 2 data bytes
101 // Packets with 4 data bytes
102 #define OPC_RDCC3 0x80 // 3 byte DCC packet
103 #define OPC_WCVO 0x82 // Write CV byte Ops mode by handle
104 #define OPC_WCVB 0x83 // Write CV bit Ops mode by handle
105 #define OPC_QCVS 0x84 // Read CV
106 #define OPC_PCVS 0x85 // Report CV
107 #define OPC_ACON 0x90 // on event
108 #define OPC_ACOF 0x91 // off event
109 #define OPC_AREQ 0x92 // Accessory Request event
110 #define OPC_ARON 0x93 // Accessory response event on
111 #define OPC_AROF 0x94 // Accessory response event off
112 #define OPC_EVULN 0x95 // Unlearn event
113 #define OPC_NVSET 0x96 // Set a node variable
114 #define OPC_NVANS 0x97 // Node variable value response
115 #define OPC_ASON 0x98 // Short event on
116 #define OPC_ASOF 0x99 // Short event off
117 #define OPC_ASRQ 0x9A // Short Request event
118 #define OPC_PARAN 0x9B // Single node parameter response
119 #define OPC_REVAL 0x9C // Request read of event variable
120 #define OPC_ARSON 0x9D // Accessory short response on event
121 #define OPC_ARSOF 0x9E // Accessory short response off event
122 #define OPC_EXTC3 0x9F // Extended opcode with 3 data bytes
123 // Packets with 5 data bytes
124 #define OPC_RDCC4 0xA0 // 4 byte DCC packet
125 #define OPC_WCVS 0xA2 // Write CV service mode
126 #define OPC_ACON1 0xB0 // On event with one data byte
127 #define OPC_ACOF1 0xB1 // Off event with one data byte
128 #define OPC_REQEV 0xB2 // Read event variable in learn mode
129 #define OPC_ARON1 0xB3 // Accessory on response (1 data byte)
130 #define OPC_AROF1 0xB4 // Accessory off response (1 data byte)
131 #define OPC_NEVAL 0xB5 // Event variable by index read response
132 #define OPC_PNN 0xB6 // Response to QNN
133 #define OPC_ASON1 0xB8 // Accessory short on with 1 data byte
134 #define OPC_ASOF1 0xB9 // Accessory short off with 1 data byte
135 #define OPC_ARSON1 0xBD // Short response event on with one data byte
136 #define OPC_ARSOF1 0xBE // Short response event off with one data byte
137 #define OPC_EXTC4 0xBF // Extended opcode with 4 data bytes
138 // Packets with 6 data bytes
139 #define OPC_RDCC5 0xC0 // 5 byte DCC packet
140 #define OPC_WCVOA 0xC1 // Write CV ops mode by address
141 #define OPC_FCLK 0xCF // Fast clock
142 #define OPC_ACON2 0xD0 // On event with two data bytes
143 #define OPC_ACOF2 0xD1 // Off event with two data bytes
144 #define OPC_EVLRN 0xd2 // Teach event
145 #define OPC_EVANS 0xd3 // Event variable read response in learn mode
146 #define OPC_ARON2 0xD4 // Accessory on response
147 #define OPC_AROF2 0xD5 // Accessory off response
148 #define OPC_ASON2 0xD8 // Accessory short on with 2 data bytes
149 #define OPC_ASOF2 0xD9 // Accessory short off with 2 data bytes
150 #define OPC_ARSON2 0xDD // Short response event on with two data bytes
151 #define OPC_ARSOF2 0xDE // Short response event off with two data bytes
152 #define OPC_EXTC5 0xDF // Extended opcode with 5 data bytes
153 // Packets with 7 data bytes
154 #define OPC_RDCC6 0xE0 // 6 byte DCC packets
155 #define OPC_PLOC 0xE1 // Loco session report
156 #define OPC_NAME 0xE2 // Module name response
157 #define OPC_STAT 0xE3 // Command station status report
158 #define OPC_PARAMS 0xEF // Node parameters response
159 #define OPC_ACON3 0xF0 // On event with 3 data bytes
160 #define OPC_ACOF3 0xF1 // Off event with 3 data bytes
161 #define OPC_ENRSP 0xF2 // Read node events response
162 #define OPC_ARON3 0xF3 // Accessory on response
163 #define OPC_AROF3 0xF4 // Accessory off response
164 #define OPC_EVLRNI 0xF5 // Teach event using event indexing
165 #define OPC_ACDAT 0xF6 // Accessory data event: 5 bytes of node data (eg: RFID)
166 #define OPC_ARDAT 0xF7 // Accessory data response
167 #define OPC_ASON3 0xF8 // Accessory short on with 3 data bytes
168 #define OPC_ASOF3 0xF9 // Accessory short off with 3 data bytes
169 #define OPC_DDES 0xFA // Short data frame aka device data event (device id plus 5 data bytes)
170 #define OPC_DDRS 0xFB // Short data frame response aka device data response
171 #define OPC_ARSON3 0xFD // Short response event on with 3 data bytes
172 #define OPC_ARSOF3 0xFE // Short response event off with 3 data bytes
173 #define OPC_EXTC6 0xFF // Extended opcode with 6 data byes
174 // Modes for STMOD
175 #define TMOD_SPD_MASK 3
176 #define TMOD_SPD_128 0
177 #define TMOD_SPD_14 1
178 #define TMOD_SPD_28I 2
179 #define TMOD_SPD_28 3
180 // Error codes for OPC_ERR
181 #define ERR_LOCO_STACK_FULL 1
182 #define ERR_LOCO_ADDR_TAKEN 2
183 #define ERR_SESSION_NOT_PRESENT 3
184 #define ERR_CONSIST_EMPTY 4
185 #define ERR_LOCO_NOT_FOUND 5
186 #define ERR_CMD_RX_BUF_OFLOW 6
187 #define ERR_INVALID_REQUEST 7
188 #define ERR_SESSION_CANCELLED 8
189 // Status codes for OPC_SSTAT
190 #define SSTAT_NO_ACK 1
191 #define SSTAT_OVLD 2
192 #define SSTAT_WR_ACK 3
193 #define SSTAT_BUSY 4
194 #define SSTAT_CV_ERROR 5
195 // Error codes for OPC_CMDERR
196 #define CMDERR_INV_CMD 1
197 #define CMDERR_NOT_LRN 2
198 #define CMDERR_NOT_SETUP 3
199 #define CMDERR_TOO_MANY_EVENTS 4
200 // #define CMDERR_NO_EV 5 now reserved
201 #define CMDERR_INV_EV_IDX 6
202 #define CMDERR_INVALID_EVENT 7
203 // #define CMDERR_INV_EN_IDX 8 now reserved
204 #define CMDERR_INV_PARAM_IDX 9
205 #define CMDERR_INV_NV_IDX 10
206 #define CMDERR_INV_EV_VALUE 11
207 #define CMDERR_INV_NV_VALUE 12
208 // Parameter index numbers (readable by OPC_RQNPN, returned in OPC_PARAN)
209 // Index numbers count from 1, subtract 1 for offset into parameter block
210 // Note that RQNPN with index 0 returns the parameter count
211 #define PAR_MANU 1 // Manufacturer id
212 #define PAR_MINVER 2 // Minor version letter
213 #define PAR_MTYP 3 // Module type code
214 #define PAR_EVTNUM 4 // Number of events supported
215 #define PAR_EVNUM 5 // Event variables per event
216 #define PAR_NVNUM 6 // Number of Node variables
217 #define PAR_MAJVER 7 // Major version number
218 #define PAR_FLAGS 8 // Node flags
219 #define PAR_CPUID 9 // Processor type
220 #define PAR_BUSTYPE 10 // Bus type
221 #define PAR_LOAD 11 // load address, 4 bytes
222 // Offsets to other values stored at the top of the parameter block.
223 // These are not returned by opcode PARAN, but are present in the hex
224 // file for FCU.
225 #define PAR_COUNT 0x18 // Number of parameters implemented
226 #define PAR_NAME 0x1A // 4 byte Address of Module type name, up to 8 characters
227 // null terminated
228 #define PAR_CKSUM 0x1E // Checksum word at end of parameters
229 // Flags in PAR_FLAGS
230 #define PF_CONSUMER 1
231 #define PF_PRODUCER 2
232 #define PF_COMBI 3
233 #define PF_FLiM 4
234 #define PF_BOOT 8
235 // BUS type that module is connected to
236 #define PB_CAN 1
237 #define PB_ETH 2
238 #endif