User Tools

Site Tools


arduino:wio-canprot-en

WIOCAN

RCAN Protocol

WIOcan, (WIO-02 WIO-PROG2 WIO-PicoW-CAN), uses extended CAN frames, populated with the Rocrail RCAN protocol.
The used CAN baudrate is 125k, which is fast enough and allows long wires.
By using all of the 29 ID bits, will allow instructions with zero to eight bytes of data.
This protocol can be used parallel with other protocols using standard frames and the same baudrate.
Some CAN interfaces cannot be used for extended frames because the ID will be mangled. Use an other available Interface Type.
The recommended way to serialise CAN Frames over USB and TCP is CAN ASCII Framing.

CAN Frame

Extended ID Count Data[Count]
PRIO TYPE SID IC RID DLC DATA
3 2 8 8 8 4 (0…8) x 8
EID 29bit: <PRIO 3bit> <TYPE 2bit> <SID 8bit>  <IC 8bit>   <RID 8bit>
             Mask: <0x1C000000><0x03000000><0x00FF0000><0x0000FF00><0x000000FF>


CAN usage Description Range Remark
PRIO ID Priority 0…7
TYPE Instruction type 0…3 cmd, evt, rsp, inf
SID Sender ID 1…255 1=Rocrail
IC Instruction Code 0x00…0xFF Group 0xFn + Opcode 0xnF
RID Receiver ID 0…255 0=broadcast
DLC Number of following data bytes 0…8
DATA 8 data bytes (0…8) x 0…255


Streaming

An exception on this header is streaming:
The PRIO and SID are used as 11bit down counter. This allows file sizes of max. 16kB.
The end of streaming is triggered if the down counter reaches zero.
The first data packet contains the file name with a max. length of 8 characters incl. extension.


0 System

CBUS Bootloader

Group GRP_SYS and command zero, Instruction Code 0x00, are not used to avoid CBUS bootloader EID conflicts.
This could happen in case the SID is 8 and RID is 4 or 5.

:X00080004N -> Bootloader command
:X00080005N -> Bootloader data

0.1 State

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 SYS_STATE x 0

Response/Event

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_RSP/TYPE_EVT x SYS_STATE 1 1 State bits

0.2 SoD

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 SYS_SOD 0 0

Response

This packets are the same as spontaneous events.

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_SENSOR TYPE_EVT x INF_PORT 0 6 Port# Type Value Aspect H Aspect M Aspect L
PRIO_INFO TYPE_EVT x INF_IO 0 1..8 Port 0-7 Port 8-15 Port16-23 Port 24-31 Port 32-39 Port 40-47 Port 48-55 Port 56-63

0.3 Clock

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_INFO TYPE_CMD 1 SYS_CLOCK 0 8 Hour Minute Brightness Month Day of month Temp.H Temp.L Divider

0.4 EBreak

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 SYS_EBREAK 0 0

0.5 Power

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 SYS_POWER 0 1 On=1 Off=0

0.6 Shutdown

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 SYS_SHUTDOWN x/0 1 x or all=0

0.7 Reboot

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 SYS_REBOOT x 0
Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 SYS_LINK x 3 Source block Destination block Options
Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 SYS_UNLINK x 2 Block Options


1 Configuration

1.0 Query

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_QUERY x 0

Response

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_RSP x CNF_QUERY 1 8 Manu-ID Product-ID Board type Options 1 Options 2 Options 3 Version High Version Low

1.1 Get

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_GET x 1 CNF_OPTIONS
PRIO_CONFIG TYPE_CMD 1 CNF_GET x 1 CNF_PORTGROUP_n

Response

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_RSP x CNF_GET 1 7 CNF_OPTIONS Options 1 Options2 Options3 Pulse length CAN-ID Subtype
PRIO_CONFIG TYPE_RSP x CNF_GET 1 5 CNF_PORTGROUP_n nib0 + nib1 nib2 + nib3 nib4 + nib5 nib6 + nib7

One nible represents a port type, 0…15.

1.2 Set

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_SET x 7 CNF_OPTIONS Options 1 Options 2 Options 3 Pulselength CAN-ID Subtype
PRIO_CONFIG TYPE_CMD 1 CNF_SET x 5 CNF_PORTGROUP_n nib0 + nib1 nib2 + nib3 nib4 + nib5 nib6 + nib7

1.3 Name

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_NAME x 8 Name characters; Unused data bytes must be set to zero.

1.4 ID

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_ID x 2 New ID Board type

1.5 Identify

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_IDENTIFY x 0

The RID should blink the onboard LED fast until it receives another identify command.

1.6 Get option

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_OPTIONGET x 1 Option#

Option number zero request all option bytes.

1.7 Set option

Option number zero: (8 bit values)

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_OPTIONSET x 8 Option# Options1 Options2 Options3 Options4 Options5 Options6 Options7

Option number greater then zero: (16 bit value)

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 CNF_OPTIONSET x 3 Option# Options H Options L


2 Programming

2.0 Get CV

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 PRG_GETCV x 6 Address H Address L CV H CV L Value Options

2.1 Set CV

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 PRG_SETCV x 6 Address H Address L CV H CV L Value Options

2.2 Programming Track

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD 1 PRG_PT x 1 On/Off


3 Streaming

3.0 Text start

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_LOW TYPE_CMD 1 STR_TEXT_START x 4 Display# downcount Text length Type

3.1 Text packet

The Prio and SID field are used as packet index.
prio = (downcount & 0x700) » 8; sid = downcount & 0xFF;

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
prio TYPE_CMD sid STR_TEXT x 8 text[] text[] text[] text[] text[] text[] text[] text[]

3.2 not used

3.3 File packet

The Prio and SID field are used as packet index.
prio = (downcount & 0x700) » 8; sid = downcount & 0xFF;

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
prio TYPE_CMD sid STR_FILE x 8 text[] text[] text[] text[] text[] text[] text[] text[]

3.4 Play

The filename is max. 8 characters in length.

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_LOW TYPE_CMD sid STR_PLAY x 8 filename[] filename[] filename[] filename[] filename[] filename[] filename[] filename[]

3.5 List files

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_CONFIG TYPE_CMD sid STR_LIST x 0

The receiver will respond with STR_TEXT_START and n * STR_TEXT.


4 Port

4.0 Port

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 PRT_GET x 3…4 Port# Type Value Options

Response

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_SENSOR TYPE_EVT x INF_PORT 0 3..6 Port# Type Value Aspect H Aspect M Aspect L

4.1 Signal

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 PRT_SIGNAL x 7 Port# Aspects Aspect Value H Value L Brightness Dim delay

4.2 Multiplex

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 PRT_MULTIPLEX x 7 Port# Aspects Aspect Value H Value L Brightness Dim delay

See Charlieplexing

4.3 PWM Pair

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 PRT_PWMPAIR x 8 PWM Port# Options Direction + F 0x80 Velocity Mass Min. duty Max. duty Kickstart

See H-Bridge for more information.

5 DCC

5.0 Dir-Velocity

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 DCC_DIRV x 5 Address H Address L Velocity + direction 0x80 Fn Steps

5.1 Function

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 DCC_FUN x 6 Address H Address L Changed F Value Group Fx

5.3 Accessory

Prio Type SID Command RID DLC D0 D1 D2 D3 D4 D5 D6 D7
PRIO_HIGH TYPE_CMD 1 DCC_ACC x 6 Address H Address L Port Gate Value Delay



C-Header

// Priority
#define PRIO_SENSOR  0x00
#define PRIO_HIGH    0x01
#define PRIO_MEDIUM  0x02
#define PRIO_CONFIG  0x03
#define PRIO_LOW     0x05
#define PRIO_INFO    0x07
 
// Types
#define TYPE_CMD 0x00
#define TYPE_EVT 0x01
#define TYPE_RSP 0x02
#define TYPE_ACK 0x03
 
/*
IC = GRP | OPC
 
GRP = (IC & 0xF0)
OPC = (IC & 0x0F)
*/
 
#define GRP_SYS 0x00 // System
  #define SYS_NOTUSED   0x00 // See "Bootloader"
  #define SYS_STATE     0x01
  #define SYS_SOD       0x02
  #define SYS_CLOCK     0x03
  #define SYS_EBREAK    0x04
  #define SYS_POWER     0x05
  #define SYS_SHUTDOWN  0x06
  #define SYS_REBOOT    0x07
  #define SYS_LINK      0x08
  #define SYS_UNLINK    0x09
 
#define GRP_CNF 0x10 // Configuration
  #define CNF_QUERY     0x10
  #define CNF_GET       0x11
  #define CNF_SET       0x12
  #define CNF_NAME      0x13
  #define CNF_ID        0x14
  #define CNF_IDENTIFY  0x15
  #define CNF_REBOOT    0x1F
 
#define GRP_PRG 0x20 // Programming
  #define PRG_GETCV 0x20
  #define PRG_SETCV 0x21
  #define PRG_PT    0x22
 
#define GRP_STR 0x30 // Streaming
  #define STR_TEXT_START 0x30 // datat[0] = display number
  #define STR_TEXT       0x31
  #define STR_FILE       0x33
  #define STR_PLAY       0x34 // data = filename
  #define STR_LIST       0x35 // SPIFFS directory listing
 
#define GRP_PRT 0x40 // Port I/O
  #define PRT_PORT      0x40
  #define PRT_SIGNAL    0x41
  #define PRT_MULTIPLEX 0x42
  #define PRT_PWMPAIR   0x43
 
#define GRP_DCC 0x50 // DCC Command Station
  #define DCC_DIRV     0x50
  #define DCC_FUN      0x51
  #define DCC_BINSTATE 0x52
  #define DCC_ACC      0x53
  #define DCC_BIND     0x54
 
#define GRP_INF 0x60 // Unsolicited events like Sensors, RailCom, RFID scanner, ...
  #define INF_PORT 0x60
  #define INF_RFID 0x61
  #define INF_BIDI 0x62
  #define INF_ENV  0x63 // temperature, humidity, pressure, light 
  #define INF_IO      0x64 // Max. 64 I/O status which is mostly used for SoD.
  #define INF_GOODBYE 0x65
 
// type for streaming text
#define TEXT_TYPE_TEXT          0
#define TEXT_TYPE_SSID          1
#define TEXT_TYPE_FILE          2
#define TEXT_TYPE_FILE_DEL      3
#define TEXT_TYPE_FILE_DOWNLOAD 4
#define TEXT_TYPE_BIN           5
 
 
 
// Config indexes
#define WIO_CNF_OPTIONS     0
#define WIO_CNF_PORTGROUP_0 1
#define WIO_CNF_PORTGROUP_1 2
#define WIO_CNF_PORTGROUP_2 3
#define WIO_CNF_PORTGROUP_3 4
#define WIO_CNF_REBOOT      0xFF
 
// Prio values
#define PRIO_SENSOR  0x00
#define PRIO_HIGH    0x01
#define PRIO_CONFIG  0x03
#define PRIO_LOW     0x05
#define PRIO_INFO    0x07
 
// Instruction types
#define TYPE_CMD 0x00
#define TYPE_EVT 0x01
#define TYPE_RSP 0x02
#define TYPE_ACK 0x03
 
// EID masks
#define MASK_PRIO 0x1C000000 // >> 26
#define MASK_MODE 0x03000000 // >> 24
#define MASK_SID  0x00FF0000 // >> 16
#define MASK_IC   0x0000FF00 // >>  8
#define MASK_RID  0x000000FF // >>  0
 
#define SHIFT_PRIO 26
#define SHIFT_MODE 24
#define SHIFT_SID  16
#define SHIFT_IC    8
#define SHIFT_RID   0
 
// State bits
#define SYS_STATE_POWER 0x01
#define SYS_STATE_SC    0x02
#define SYS_STATE_PT    0x04
#define SYS_STATE_SLAVE 0x08
 
// Port types
#define PORTTYPE_DOUT  0
#define PORTTYPE_AOUT  1
#define PORTTYPE_SERVO 2
#define PORTTYPE_PAIR  3
#define PORTTYPE_MOTOR 4
#define PORTTYPE_DIN   5
#define PORTTYPE_ACC   6
#define PORTTYPE_LED   7
#define PORTTYPE_MULTIPLEX 10
 
#define PORT_STATE_STRAIGHT 0
#define PORT_STATE_TURNOUT  1
 
// Config indexes
#define CNF_IDX_OPTIONS     0
#define CNF_IDX_PORTGROUP_0 1 //  0... 7
#define CNF_IDX_PORTGROUP_1 2 //  8...15
#define CNF_IDX_PORTGROUP_2 3 // 16...23
#define CNF_IDX_PORTGROUP_3 4 // 24...31
arduino/wio-canprot-en.txt · Last modified: 2024/05/24 09:59 by rjversluis