arduino:wio-rascii-en
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | arduino:wio-rascii-en [2025/05/04 07:17] (current) – [Frame] rjversluis | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======WIO RASCII====== | ||
+ | |||
+ | | //Not to be translated.// | ||
+ | |||
+ | RASCII documentation as used in WIO.\\ | ||
+ | |||
+ | ^ WIP ^ | ||
+ | |||
+ | \\ | ||
+ | =====Overview===== | ||
+ | |||
+ | ====Frame==== | ||
+ | |< >| | ||
+ | ^ Header | ||
+ | | Prefix | Length | OPC | NID | Data 0...120 | | ||
+ | \\ | ||
+ | |< >| | ||
+ | ^ Field ^ Description ^ Remark ^ Size ^ | ||
+ | | Prefix | Message type | | 1 char | | ||
+ | | Length | OPC + NID + Data | | 2 char | | ||
+ | | OPC | Operation Code | Command/ | ||
+ | | NID | Node ID | 0...255, zero is broadcast | 2 char | | ||
+ | | Data | Optional data | | 0, 2, 4, ...240 char | | ||
+ | |||
+ | |||
+ | \\ | ||
+ | ====Binary Structure==== | ||
+ | |< >| | ||
+ | ^ Field ^ Value ^ Size | | ||
+ | | type | Prefix character | char | | ||
+ | | nid | bin(NID) | byte | | ||
+ | | opc | bin(OPC) | byte | | ||
+ | | dlc | (bin(Length)/ | ||
+ | | data[120] | Data bin(0)...bin(120) | byte[120] | | ||
+ | |||
+ | \\ | ||
+ | ====Example==== | ||
+ | RASCII: | ||
+ | < | ||
+ | $060C2101 | ||
+ | </ | ||
+ | Binary: | ||
+ | < | ||
+ | type=$ | ||
+ | nid=31 (0x21) | ||
+ | opc=12 (0x0C) | ||
+ | dlc=1 (6/2 - 2) | ||
+ | data[0]=1 | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | =====Constants===== | ||
+ | ====Prefixes==== | ||
+ | < | ||
+ | #define PREFIX_CMD ' | ||
+ | #define PREFIX_EVT ' | ||
+ | #define PREFIX_INF '#' | ||
+ | #define PREFIX_RSP '&' | ||
+ | #define PREFIX_TXT '/' | ||
+ | </ | ||
+ | |||
+ | ====Commands==== | ||
+ | < | ||
+ | #define CMD_INFO | ||
+ | #define CMD_START | ||
+ | #define CMD_STOP | ||
+ | #define CMD_GETCONF | ||
+ | #define CMD_SETCONF | ||
+ | #define CMD_RESETCONF | ||
+ | #define CMD_GETCV | ||
+ | #define CMD_SETCV | ||
+ | #define CMD_DOUT | ||
+ | #define CMD_AOUT | ||
+ | #define CMD_ACCESSORY | ||
+ | #define CMD_MOBILE_DIRV 13 | ||
+ | #define CMD_MOBILE_FUN | ||
+ | #define CMD_MOBILE_DISPATCH 15 | ||
+ | #define CMD_MOBILE_RELEASE | ||
+ | #define CMD_EBREAK | ||
+ | #define CMD_SOD | ||
+ | #define CMD_QUERY | ||
+ | #define CMD_SETIDTYPE | ||
+ | #define CMD_SETWIO | ||
+ | |||
+ | #define CMD_SERVO | ||
+ | #define CMD_TEXT | ||
+ | #define CMD_CLOCK | ||
+ | #define CMD_SIGNAL | ||
+ | #define CMD_SWITCH | ||
+ | #define CMD_BINSTATE | ||
+ | #define CMD_MOBILE_SHORTID | ||
+ | #define CMD_CLEAR_SHORTIDS | ||
+ | #define CMD_END_SHORTIDS | ||
+ | #define CMD_SHUTDOWN | ||
+ | #define CMD_MOBILE_STATE | ||
+ | #define CMD_SOUND_PLAY | ||
+ | #define CMD_OTA | ||
+ | #define CMD_REBOOT | ||
+ | #define CMD_PT_ON | ||
+ | #define CMD_PT_OFF | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====Events==== | ||
+ | < | ||
+ | #define EVT_ALIVE 0 | ||
+ | #define EVT_OCC | ||
+ | #define EVT_RFID | ||
+ | #define EVT_DIN | ||
+ | #define EVT_AIN | ||
+ | #define EVT_DSEN | ||
+ | #define EVT_ASEN | ||
+ | #define EVT_DOUT | ||
+ | #define EVT_ACCESSORY | ||
+ | #define EVT_SHORTCIRCUIT 9 | ||
+ | #define EVT_BIDI | ||
+ | #define EVT_SENSORID | ||
+ | #define EVT_STATE | ||
+ | #define EVT_MOBILE_STATE 13 | ||
+ | #define EVT_GOODBYE | ||
+ | </ | ||
+ | |||
+ | ====BiDi type==== | ||
+ | < | ||
+ | #define BIDI_SETCV | ||
+ | #define BIDI_GETCV | ||
+ | #define BIDI_ADDRESS 2 | ||
+ | #define BIDI_DYN | ||
+ | #define BIDI_EXT | ||
+ | </ | ||
+ | |||
+ | ====Port type==== | ||
+ | < | ||
+ | #define PORTTYPE_DOUT | ||
+ | #define PORTTYPE_AOUT | ||
+ | #define PORTTYPE_SERVO 2 | ||
+ | </ | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====System===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 4 | CMD_START | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_STOP | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_EBREAK | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_SOD | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_CLEAR_SHORTIDS | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_END_SHORTIDS | - | " | ||
+ | | PREFIX_CMD | 4 | CMD_SHUTDOWN | - | " | ||
+ | ====Events==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_EVT | 6...22 | EVT_STATE | D0=state flags (0x01=globalpower), | ||
+ | |||
+ | \\ | ||
+ | =====Mobile===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 10 + ID-length * 2 | CMD_MOBILE_SHORTID | D0=addrH, D1=addrL, D2=dirF, D3=speed D4=" | ||
+ | | PREFIX_CMD | 32 | CMD_MOBILE_DIRV | D0=bus, D1=addrH, D2=addrL, D3=dirV, D4=lights, D5=steps, D6=mass, D7=speed, D8=angle, D9=minstep, D10=maxstep, | ||
+ | | PREFIX_CMD | 22 | CMD_MOBILE_FUN | D0=bus, D1=addrH, D2=addrL, D3=Fchanged, | ||
+ | | PREFIX_CMD | 14 | CMD_BINSTATE | D0=bus, D1=addrH, D2=addrL, D3=binH, D4=binL, D5=state | | Change binary state for one port. | | ||
+ | | PREFIX_CMD | 16 | CMD_MOBILE_DISPATCH | D0=bus, D1=addrH, D2=addrL, D3=V, D4=Lights, D5=fxH, D6=fxL | | Dispatch loco for throttle. | | ||
+ | | PREFIX_CMD | 8 | CMD_MOBILE_RELEASE | D0=bus, D1=addrH, D2=addrL | | Release loco from throttle. | | ||
+ | |||
+ | \\ | ||
+ | |||
+ | |||
+ | =====Signal===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 18 | CMD_SIGNAL | D0=bus, D1=addr, D2=nraspects, | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====Switch===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 12 | CMD_SERVO | D0=bus, D1=addr, D2=paramon/ | ||
+ | | PREFIX_CMD | 16 | CMD_SWITCH | D0=bus, D1=addrH, D2=addrL, D3=port, D4=gate, D5=value, D6=delay | | Type: Accessory + DCC | | ||
+ | | PREFIX_CMD | 8 | CMD_ACCESSORY | D0=bus, D1=addr, D2=on/off | | Type: None Servo + Single gate | | ||
+ | | PREFIX_CMD | 8 | CMD_ACCESSORY | D0=bus, D1=addr, D2=gate | | Type: None Servo + no single gate | | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====Output===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 12 | CMD_DOUT | D0=bus, D1=addr, D2=on, D3=delay, D4=blink | | - | | ||
+ | | PREFIX_CMD | 12 | CMD_SERVO | D0=bus, D1=addr, D2=paramon/ | ||
+ | | PREFIX_CMD | 6 + soundfile*2 | CMD_SOUND_PLAY | D0=bus, D1=paramon/ | ||
+ | | PREFIX_CMD | 18 | CMD_AOUT | D0=bus, D1=addr, D2=valueon, D3=red, D4=green, D5=blue, D6=blink+delay, | ||
+ | | PREFIX_CMD | 22 | CMD_MOTOR | D0=bus, D1=addr, D2=dirT, D3=delay, D4=stepsH, D5=stepsM, D6=stepsL, D7=reportH, D8=reportM, D9=reportL | | Type: Motor \\ dirT& | ||
+ | |||
+ | \\ | ||
+ | |||
+ | |||
+ | =====Text===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_TXT | 6 + textlength*1 | CMD_TEXT | D0=bus, D1=display, D2...Dn=text | | The text is __not__ in HEXA, max 250 length. | | ||
+ | |||
+ | \\ | ||
+ | |||
+ | =====Clock===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 8 | CMD_CLOCK | D0=hour, D1=minute, D2=brightness | | | | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====Program===== | ||
+ | ====Commands==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_CMD | 2 | CMD_QUERY | | | Query all WIO modules. | | ||
+ | | PREFIX_CMD | 4 | CMD_OTA | D0=bus | | Put a WIO module in OTA mode for firmware update. | | ||
+ | | PREFIX_CMD | 8 + nodename*2 | CMD_SETIDTYPE | D0=bus, D1=ID , D2=config, D3...Dn=nodename | | D1 is the new WIO ID number, and config determines the WIO type. | | ||
+ | | PREFIX_CMD | 4 | CMD_REBOOT | D0=bus | | Reboot the selected WIO module. | | ||
+ | | PREFIX_CMD | 16 + configlength*2 | CMD_SETWIO | D0=bus, D1=I/ | ||
+ | | PREFIX_CMD | 12 | CMD_GETCV | D0=bus, D1=addrH, D2=addrL, D3=cvH, D4=cvL, D5=options | | options: bit0=PT, bit1=accessory \\ Default POM Mobile.| | ||
+ | | PREFIX_CMD | 14 | CMD_SETCV | D0=bus, D1=addrH, D2=addrL, D3=cvH, D4=cvL, D5=value, D6=options | | | | ||
+ | |||
+ | |||
+ | ====Responses==== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_RSP | 42 | CMD_QUERY | D0=bus, D1=type, D2=manu, D3=pid, D4=vmaj, D5=vmin, D6=options1, | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====Events===== | ||
+ | ^ Prefix ^ Length ^ Code ^ Data ^ Example ^ Description ^ | ||
+ | | PREFIX_EVT | 16 | EVT_GOODBYE | D0=bus, D1=analogH, D2=analogL, D3=rssiH, D4=rssiL, D5=locoH, D6=locoL | | WIO Control in pause or low battery. | | ||
+ | | PREFIX_EVT | 6 | EVT_SHORTCIRCUIT | D0=bus, D1=shortcircuit | | WIO Boost/Drive reports overload. | | ||
+ | | PREFIX_EVT | 32 | EVT_ALIVE | D0=bus, D1=analogH, D2=analogL, D3=rssiH, D4=rssiL, D5=locoH, D6=locoL, D7=tempH, D8=tempL, D9=temp100H, | ||
+ | | PREFIX_EVT | 8 | EVT_DIN | D0=bus, D1=port, D2=value | | Digital input. | | ||
+ | | PREFIX_EVT | 8 | EVT_DOUT | D0=bus, D1=port, D2=value | | Digital output. | | ||
+ | | PREFIX_EVT | 10 | EVT_ACCESSORY | D0=bus, D1=port, D2=value, D3=**[[# | ||
+ | | PREFIX_EVT | 16 | EVT_BIDI | D0=bus, D1=port, D2=locoH, D3=locoL, D4=**[[# | ||
+ | | PREFIX_EVT | 8 + rfidlen*2 | EVT_RFID | D0=bus, D1=port, D2=len, D3...Dn=RFID | | Stationary sensor; Must be confirmed. | | ||
+ | | PREFIX_EVT | 8 + rfidlen*2 | EVT_SENSORID | D0=bus, D1=port, D2=len, D3...Dn=RFID | | Mobile sensor; Must be confirmed. | | ||
+ | |||
+ | |||
+ | |||
+ | \\ | ||
+ | =====C Code===== | ||
+ | <code c> | ||
+ | typedef struct RASCIIFrame { | ||
+ | char type; | ||
+ | byte opc; | ||
+ | byte nid; | ||
+ | byte dlc; | ||
+ | byte data[120]; | ||
+ | } *iRASCIIFrame; | ||
+ | |||
+ | static byte _HEXA2Byte( const char* s ) { | ||
+ | /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A | ||
+ | static char hexb[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; | ||
+ | return (hexb[s[0] - 0x30] << 4) + hexb[s[1] - 0x30]; | ||
+ | } | ||
+ | |||
+ | |||
+ | static char* _Byte2HEXA(byte b, char* c) { | ||
+ | static char cHex[] = {' | ||
+ | c[0] = cHex[(b& | ||
+ | c[1] = cHex[ b& | ||
+ | c[2] = ' | ||
+ | return c; | ||
+ | } | ||
+ | |||
+ | |||
+ | static int _encode( iRASCIIFrame frame, char* rascii) { | ||
+ | int idx = 0; | ||
+ | |||
+ | // Type @,#, | ||
+ | rascii[0] = frame-> | ||
+ | idx++; | ||
+ | |||
+ | if( frame-> | ||
+ | TraceOp.trc( " | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | // Length = opc + rid + data | ||
+ | _Byte2HEXA((frame-> | ||
+ | idx+=2; | ||
+ | |||
+ | // Command, Event | ||
+ | _Byte2HEXA(frame-> | ||
+ | idx+=2; | ||
+ | |||
+ | // Recipioent ID | ||
+ | _Byte2HEXA(frame-> | ||
+ | idx+=2; | ||
+ | |||
+ | // Data | ||
+ | if( frame-> | ||
+ | for( int i = 0; i < frame-> | ||
+ | _Byte2HEXA(frame-> | ||
+ | idx+=2; | ||
+ | } | ||
+ | } | ||
+ | rascii[idx+0] = ' | ||
+ | rascii[idx+1] = ' | ||
+ | idx++; | ||
+ | |||
+ | return idx; | ||
+ | } | ||
+ | |||
+ | |||
+ | static char _decode( const char* rascii, iRASCIIFrame frame ) { | ||
+ | int idx = 0; | ||
+ | frame-> | ||
+ | idx += 1; | ||
+ | frame-> | ||
+ | |||
+ | if( frame-> | ||
+ | TraceOp.trc( " | ||
+ | return ' | ||
+ | } | ||
+ | idx += 2; | ||
+ | |||
+ | frame-> | ||
+ | |||
+ | if( frame-> | ||
+ | TraceOp.trc( " | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | frame-> | ||
+ | idx += 2; | ||
+ | frame-> | ||
+ | idx += 2; | ||
+ | |||
+ | for( int i = 0; i < frame-> | ||
+ | frame-> | ||
+ | } | ||
+ | |||
+ | return rascii[0]; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | #ifndef __RASCII_CODES_H__ | ||
+ | #define __RASCII_CODES_H__ | ||
+ | |||
+ | #define PREFIX_CMD ' | ||
+ | #define PREFIX_EVT ' | ||
+ | #define PREFIX_INF '#' | ||
+ | #define PREFIX_RSP '&' | ||
+ | |||
+ | #define CMD_INFO | ||
+ | #define CMD_START | ||
+ | #define CMD_STOP | ||
+ | #define CMD_GETCONF | ||
+ | #define CMD_SETCONF | ||
+ | #define CMD_RESETCONF | ||
+ | #define CMD_GETCV | ||
+ | #define CMD_SETCV | ||
+ | #define CMD_DOUT | ||
+ | #define CMD_AOUT | ||
+ | #define CMD_ACCESSORY | ||
+ | #define CMD_MOBILE_DIRV 13 | ||
+ | #define CMD_MOBILE_FUN | ||
+ | #define CMD_MOBILE_DISPATCH 15 | ||
+ | #define CMD_MOBILE_RELEASE | ||
+ | #define CMD_EBREAK | ||
+ | #define CMD_SOD | ||
+ | #define CMD_QUERY | ||
+ | #define CMD_SETIDTYPE | ||
+ | #define CMD_SETWIO | ||
+ | |||
+ | #define CMD_SERVO | ||
+ | #define CMD_TEXT | ||
+ | #define CMD_CLOCK | ||
+ | #define CMD_SIGNAL | ||
+ | #define CMD_SWITCH | ||
+ | #define CMD_BINSTATE | ||
+ | #define CMD_MOBILE_SHORTID | ||
+ | #define CMD_CLEAR_SHORTIDS | ||
+ | #define CMD_END_SHORTIDS | ||
+ | #define CMD_SHUTDOWN | ||
+ | #define CMD_MOBILE_STATE | ||
+ | #define CMD_SOUND_PLAY | ||
+ | #define CMD_OTA | ||
+ | #define CMD_REBOOT | ||
+ | #define CMD_PT_ON | ||
+ | #define CMD_PT_OFF | ||
+ | #define CMD_ACC_GETCV | ||
+ | #define CMD_ACC_SETCV | ||
+ | #define CMD_ACC_PAIR | ||
+ | #define CMD_MOTOR | ||
+ | #define CMD_SLEEP | ||
+ | #define CMD_SHOW | ||
+ | #define CMD_STARTCAM | ||
+ | #define CMD_STOPCAM | ||
+ | |||
+ | #define EVT_ALIVE 0 | ||
+ | #define EVT_OCC | ||
+ | #define EVT_RFID | ||
+ | #define EVT_DIN | ||
+ | #define EVT_AIN | ||
+ | #define EVT_DSEN | ||
+ | #define EVT_ASEN | ||
+ | #define EVT_DOUT | ||
+ | #define EVT_ACCESSORY | ||
+ | #define EVT_SHORTCIRCUIT 9 | ||
+ | #define EVT_BIDI | ||
+ | #define EVT_SENSORID | ||
+ | #define EVT_STATE | ||
+ | #define EVT_MOBILE_STATE 13 | ||
+ | #define EVT_PT | ||
+ | #define EVT_IO | ||
+ | #define EVT_GOODBYE | ||
+ | |||
+ | #define BIDI_SETCV | ||
+ | #define BIDI_GETCV | ||
+ | #define BIDI_ADDRESS 2 | ||
+ | #define BIDI_DYN | ||
+ | #define BIDI_EXT | ||
+ | #define BIDI_PT | ||
+ | #define BIDI_SC | ||
+ | |||
+ | #define PROGOPT_PT | ||
+ | #define PROGOPT_ACC | ||
+ | #define PROGOPT_SET | ||
+ | |||
+ | #define PORTTYPE_DOUT | ||
+ | #define PORTTYPE_AOUT | ||
+ | #define PORTTYPE_SERVO 2 | ||
+ | #define PORTTYPE_PAIR | ||
+ | #define PORTTYPE_MOTOR 4 | ||
+ | #define PORTTYPE_DIN | ||
+ | #define PORTTYPE_ACC | ||
+ | #define PORTTYPE_LED | ||
+ | |||
+ | #define STATEFLAG_POWER 0x01 | ||
+ | |||
+ | #define PORT_STATE_STRAIGHT 0 | ||
+ | #define PORT_STATE_TURNOUT | ||
+ | |||
+ | #define RFID_LENGTH_MASK | ||
+ | #define RFID_STATE_OFF | ||
+ | #define RFID_STATE_ERROR | ||
+ | |||
+ | #define SUBIOTYPE_NONE | ||
+ | #define SUBIOTYPE_LED | ||
+ | #define SUBIOTYPE_SERVO | ||
+ | #define SUBIOTYPE_RFID | ||
+ | #define SUBIOTYPE_DCC | ||
+ | #define SUBIOTYPE_MOBILE | ||
+ | #define SUBIOTYPE_CAM | ||
+ | #define SUBIOTYPE_CANBUS | ||
+ | #define SUBIOTYPE_THROTTLE 8 | ||
+ | |||
+ | #define MOBILE_STATE_LOWBATTERY 1 | ||
+ | |||
+ | |||
+ | #endif | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | \\ | ||
+ | =====16bit NID===== | ||
+ | Proposal for 16bit NID:\\ | ||
+ | If the first character of the NID is a '' | ||
+ | |||
+ | |||
+ | |||