ER-SP-I0013-13 Inuktun Version 2 Serial Protocol: Date: OCT 21, 2013 Changes in This Revision
ER-SP-I0013-13 Inuktun Version 2 Serial Protocol: Date: OCT 21, 2013 Changes in This Revision
ER-SP-I0013-09
Table of Contents
The Protocol .................................................................................................................................................. 1 Signaling rates ........................................................................................................................................... 1 Timing Constraints ..................................................................................................................................... 1 Coordinate System Definition .................................................................................................................... 1 Byte Ordering ............................................................................................................................................ 2 Definitions .................................................................................................................................................. 2 Philosophical Differences .......................................................................................................................... 2 Encapsulation ........................................................................................................................................ 2 Example: ................................................................................................................................................ 3 Real-World Units .................................................................................................................................... 3 Example: ................................................................................................................................................ 3 Packet Structure ........................................................................................................................................ 4 Standard packets ................................................................................................................................... 4 Group control packets ............................................................................................................................ 5 CRC Calculation ........................................................................................................................................ 5 The Interfaces ............................................................................................................................................... 6 Summary of the Interfaces ........................................................................................................................ 6 Administrative Interface (0x00) .................................................................................................................. 7 Identification .............................................................................................................................................. 7 Identify device configure (0x00) ............................................................................................................. 7 Identify Node ID configure (0x01) .......................................................................................................... 8 Ping (0x02) ............................................................................................................................................. 8 Ping Reply (0x03) .................................................................................................................................. 8 Identify and interrogate .............................................................................................................................. 9 Identify (0x04) ........................................................................................................................................ 9 Determining Supported Interfaces ............................................................................................................. 9 Enumerate supported interfaces (0x05) ................................................................................................ 9 Supported interfaces response (0x06)................................................................................................. 10
Page i
ER-SP-I0013-09
Composite Packet Definition ................................................................................................................... 10 Subscribe to composite packet (0x07) ................................................................................................. 11 Unsubscribe from composite packet (0x08) ........................................................................................ 12 Remove all composite packet subscriptions (0x09) ............................................................................ 12 Composite packet subscription response (0x0a) ................................................................................. 12 Enumerate composite packet subscriptions (0x0b) ............................................................................. 13 Report composite packet subscriptions (0x0e) .................................................................................... 13 Firmware Version Request (0x0f) ........................................................................................................ 14 Firmware Version Reply (0x10) ........................................................................................................... 14 Environmental Parameter Interface (0x01) ............................................................................................. 15 Get Environmental Parameters (0x00) ................................................................................................ 15 Return Environmental Parameters (0x01) ........................................................................................... 16 Get Available Parameters (0x02) ......................................................................................................... 16 Return Available Parameters (0x03) .................................................................................................... 16 Set Zero Offsets (0x04)........................................................................................................................ 17 Amplitude Control Interface (0x02) .......................................................................................................... 18 Set Amplitude (0x00) ........................................................................................................................... 18 Amplitude Reply (0x01)........................................................................................................................ 18 Get Amplitude Control Parameter Info (0x02) ..................................................................................... 18 Return Amplitude Control Parameter Info (0x03) ................................................................................ 19 Closed Loop Rotating Machine Linear Motion Control Interface (0x03) ................................................. 20 Set Speed (0x00) ................................................................................................................................. 20 Set Speed Reply (0x01) ....................................................................................................................... 20 Get Closed Loop Rotating Machine Parameter Info (0x02)................................................................. 21 Return Closed Loop Rotating Machine Parameter Info (0x03)............................................................ 21 Set Raw Position (0x08) ...................................................................................................................... 21 Set Raw Position Reply (0x09) ......................................................................................................... 22 iGEMS Gamma Radiation Detector Interface (0x04) .............................................................................. 23 Get number of events in FIFO (0x04) .................................................................................................. 23 Return number of events in FIFO (0x84) ............................................................................................. 23 Success response (0xFE) .................................................................................................................... 23 Failure response (0xFF)....................................................................................................................... 24 Clear event FIFO (0x05) ...................................................................................................................... 24 Get iGEM unit number (0x0B) ............................................................................................................. 24 Return iGEM Unit Number (0x8B) ....................................................................................................... 24 Get detector type (0x0D) ..................................................................................................................... 25 Return iGEM Detector Type (0x8D) ..................................................................................................... 25
Page ii
ER-SP-I0013-09
Get detector bias voltage (0x0F) ......................................................................................................... 25 Return detector bias voltage (0x8F) .................................................................................................... 25 Set ASIC Gain (0x10) .......................................................................................................................... 26 Set ASIC Shaping Time (0x11) ............................................................................................................ 26 Set High Voltage Level (0x12) ............................................................................................................. 26 Set FIFO Nearly Full Value (0x13) ....................................................................................................... 27 Enable/Disable Event Counter (0x14) ................................................................................................. 27 Read and Reset Event Counter (0x15)................................................................................................ 27 Return Event Count (0x95) .................................................................................................................. 28 Get N Events (0x40) ............................................................................................................................ 28 Return N Events (0xC0) ....................................................................................................................... 28 Rotating Motor Position Control Interface (0x07) .................................................................................... 29 Set Position (0x00) ............................................................................................................................... 29 Set Position Reply (0x01) .................................................................................................................... 29 Get Position Control Parameter Info (0x02)......................................................................................... 30 Return Position Control Parameter Info (0x03) ................................................................................... 30 Move to Reset Position (0x04) ............................................................................................................. 30 Verify at Reset Position (0x05) ............................................................................................................ 31 Verify Reset Reply (0x06) .................................................................................................................... 31 Get Position (0x07) .............................................................................................................................. 31 Return Position (0x08) ......................................................................................................................... 32 Set Parameters (0x09) ......................................................................................................................... 32 Set Parameters Response (0x0a) ....................................................................................................... 32 Stop (0x0b) .......................................................................................................................................... 32 Set Speed Position Control (0x0c) ....................................................................................................... 33 Speed Position Control Reply (0x0d) ................................................................................................... 33 Zero Position (0x0e)............................................................................................................................. 33 Zero Position Reply(0x0f) ................................................................................................................. 34 Auxiliary Control Interface (0x08) ............................................................................................................ 34 Arm Raise Control Set (0x00) .............................................................................................................. 34 Arm Raise Control Reply (0x01) .......................................................................................................... 35 Arm Raise Calibration Set (0x02) ..................................................................................................... 35 Arm Raise Calibration Reply (0x03) ................................................................................................. 36 Lights Control Interface (0x09) ................................................................................................................ 36 Set Light Control (0x00) ....................................................................................................................... 36 Light Control Reply (0x01) ................................................................................................................... 36 Get Light Parameter Info (0x02) .......................................................................................................... 37
Page iii
ER-SP-I0013-09
Return Lights Parameter Info (0x03) ................................................................................................... 37 Error Interface (0xFF) .............................................................................................................................. 37 Throw (0x00) ........................................................................................................................................ 38 Various Comments, Notes, Things to Do .................................................................................................... 38
Page iv
ER-SP-I0013-09
The Protocol
This protocol is an adaptation of the serial protocol described in ER-SP-I0011-01. It extends the old protocol to handle the following: Addressing same-type components: with the old protocol, it was not possible to have two of the same type of component (two SP90s, for example) on the same bus. Run-time discovery of components on the bus: the new protocol describes the process by which components are enumerated. Allowing this to happen at run-time makes it possible to have "plug and play" components. Run-time formation of ad-hoc groups: allows arbitrary groups of components (all forward-facing lights, for example) to be controlled in unison. Ad-hoc commands: allows simultaneous control of dissimilar components.
For consistency with the previous version of the protocol, one can assume that controller means host, and vice versa. In either version, the most natural implementation is to have a single controller, but there is nothing to prevent using multiple controllers, so long as they coordinate between themselves to avoid bus contention. In the case of a single controller, the convention is for it to be node 0. Data is sent to and from the host in packets of bytes. Each packet starts with a start byte and ends with a 2-byte CRC. The maximum packet length is 255 bytes. Data flow is governed by the controller/host. All other components will transmit only if they have received a valid packet directed at them.
Signaling rates
The communication protocol is based on RS485 voltage levels and asynchronous, 38,400 bps, 1 start bit, 8 data bits, 1 stop bit signaling.
Timing Constraints
Name Reply Packet Latency Host Packet Period Receive Packet Timeout Receive Byte Timeout Min (ms) Typical (ms) Max (ms) 10 Description The time between a host request and a slave reply The time between the host sending requests under normal conditions The time after which the host may assume a packet loss after sending a request and waiting for a reply The time after which the host may assume an incomplete packet and attempt to send a new one
75 100
30
Page 1
ER-SP-I0013-09
Roll is the angle about the x axis, pitch is the angle about the y axis, and yaw is the angle about the z axis. Sign convention is, again, determined by the right hand rule. Note that this system matches exactly the sign conventions expressed in ER-SP-I0011-01.
Byte Ordering
On-the-wire byte ordering shall follow network byte ordering convention. In other words, all data types should be transmitted most significant byte first. In C, hton and ntoh functions provide this mapping.
Definitions
The following definitions are for a device, which can be assumed to be a microcontroller that is in communication with a controller on the RS-485 bus. Node id (byte type) Similar in concept to an IP address. Nodes can have ids in the range [0, 127], allowing for a system to be comprised of up to 128 devices. Prior to configuration, a node will have the id 255, which signifies that it has not yet been assigned a proper node id. Given the limitations of RS-485 signaling, allowing a larger range (thus demanding a larger data type) would probably produce little benefit. All packets are sent from node to [group of] node(s). Physical address (UInt32 type) Similar in concept, though not purpose, to a MAC address. This is a non-volatile, semi-permanent id for a particular component. It is intended to be set during production, and provides a means to discriminate between components that are grouped together into something that is given a serial number. Thus, a Minitrac-2XL might have a single serial number, but it would have two motor drivers, each with their own physical address. Unlike in Ethernet, this is not used for routing, but solely for bootstrapping to the point that the device can be given a Node id. Each and every microcontrolled device manufactured by Inuktun should have a unique machine address. Serial number (UInt32 type) This is the standard Inuktun serial number that is given to a device. It is not necessarily unique, because it is in theory possible that a product made by Inuktun with a single serial number may include more than one device, each of which will have the same serial number but different machine addresses. Group (byte type) A plurality of nodes that, for some reason, is convenient to treat collectively. Group ids are used in place of Node ids, and can have the range [128, 255]. The node id 255 is defined to be the broadcast / all nodes group. Interface (UInt16 type) A collection of methods supported by a component. A component may support more than one interface. Subcomponent (byte type) This index is used to identify components within a single device that implement the same interface. For example a single device may control two banks of lights each of which is independent of the other. Most interfaces will only be implemented by the root subcomponent, which is zero. Method (byte type) These describe the methods provided by the interface.
Philosophical Differences
Encapsulation
While it would be possible to map almost directly the commands described in ER-SP-E0012-02 into this protocol, to do so would belie the power that abstracting to interfaces provides. Further, enforcing good encapsulation of objects (both real-world and abstract) will be beneficial, both for flexibility when building custom systems from modular components, and for improving code maintainability.
Page 2
ER-SP-I0013-09
Example:
A Spectrum 90 is actually a pan/tilt gimbal, camera, light source, and possibly laser striper all rolled into one. So, under this paradigm, it would implement at least three separate interfaces. A forward-viewing camera would be similar, but simply not implement pan/tilt. Now, assume Sony develops another camera block that is size-compatible with the one currently used in the SP90, but offers a nifty new auto focus mode, or more powerful zoom, or some such feature. It would be only the camera interface that would need to be adapted, and, provided that the additional features were purely an extension of the blocks features, the camera could simultaneously implement both the old and new interfaces for the camera block. Notice that this also provides a mechanism to address options. If the particular SP90 has lasers, then it will implement that interface; otherwise it wont.
Real-World Units
Rather than using units that favor efficiency of conversion or convenience to the embedded programmer, components should use units that have real-world significance. A direct result of this is that a quantitys natural representation may not be a whole number. The jump to floating point has its drawbacks, most notably in efficiency, but it offers the most flexibility and natural representation.
Example:
When expressing the commanded speed for a track, it might be tempting to express this value as a single byte, with +127 meaning full forward, and -127 meaning full reverse. Thus, the resolution (and unit of th measurement) is 1/127 of the tracks full speed. The difficulty comes when it is desired to mix this track with a track of another type on a particular system, and the tracks have differing top speeds. If the two are to look to the same command for their speed, they must use a shared representation. Taking this one step further, it only makes sense if this shared representation also carries some real-world significance. Without question, the system of units for such measurements should be SI. One could easily go overboard with this, however. Theres not much cause to command li ght intensity in terms of candela, for instance. The number isnt likely to have meaning for the operator, and a group of lights commanded to do the same thing probably should be commanded as a fraction of their full intensity.
Page 3
ER-SP-I0013-09
Packet Structure
Standard packets
All packets except group control packets must have the following structure: Byte 0 Name Start byte Description All packets begin with this value. It serves as a marker, and helps to synchronize UARTs with auto baud rate detection The length of the packet (including start byte and CRCs), in bytes Value 0xAA
The node id or group id of the receiver(s) The senders node id The subcomponent (within the node) that is being addressed The interface upon which the method is being called The number of the method within the interface The parameters of the method
[10, 255]. Each node shall be able to cope with packets having lengths up to 255 being present on the bus, but the size of a nodes receive buffer may dictate that it is not able to itself receive such a large packet. 32 or 64 would be a much more practical expectation. Group or node id; [0, 255] Node id; [0, 127] [0, 255] [0, 65535] [0, 255] Byte array with arbitrary contents, having length, n, in the range [0, 245] [0, 255] [0, 255]
8+n 9+n
CRCH CRCL
The most significant byte of the CRC. The least significant byte of the CRC.
Page 4
ER-SP-I0013-09
2 3 4 [5, 5+n)
The group id of the receiver(s) The senders node id Parameters of the method used by the group, possibly for each node in the group. The most significant byte of the CRC. The least significant byte of the CRC.
8+n 9+n
CRCH CRCL
[10, 255]. Each group shall be able to cope with packets having lengths up to 255 being present on the bus, but the size of a nodes receive buffer may dictate that it is not able to itself receive such a large packet. 32 or 64 would be a much more practical expectation. Group id; [128, 254] Node id; [0, 127] [0, 250] Byte array with arbitrary contents, having length, n, in the range [0, 245] [0, 255] [0, 255]
CRC Calculation
The CRC is calculated using the polynomial X^16 + X^12 + X^5 + 1. To calculate the CRC, use the following pseudo-code: Preload the CRC accumulator with 0xFFFF. For each bit to be checked, as in the order of appearance on the wire { Left shift the current bit of the message into the CRC accumulator If the CRC accumulator overflows (the 16th bit is one) { XOR the CRC accumulator with 0x1021 } Mask the CRC accumulator to the bottom 16 bits } Important note: The CRC bytes should not be included in the CRC calculation (how could they be?). Implementation note: Should a component receive a packet having a CRC mismatch, it should silently ignore the packet. After all, it cannot even be sure the packet was intended for it. Should the packet have had a response, the controller will timeout, and retransmit if necessary.
Page 5
ER-SP-I0013-09
The Interfaces
Summary of the Interfaces
Interface Name Administrative Environmental Parameter Amplitude Control Closed Loop Rotating Machine Linear Motion IGEMS Gamma Radiation Detector Position Control Error Number (hex) 00 01 02 03 04 07 FF Number of Methods 16 5 4 4 20 11 1
Page 6
ER-SP-I0013-09
Identification
The nodes on the system are to be discoverable at run-time. While some user interaction may be required to actually use a newly-inserted component, the system shall be able to detect and communicate with the component with no operator intervention beyond instructing the system to scan for new components. To ensure that all devices will be discovered, devices must implement some means of avoiding or recovering from collisions on the bus during discovery. Physical address byes definition: Byte Description 1 Physical address 2 Physical address 3 Physical address 4 Device type
Response: None Upon reception of a Identify device configure packet, the device will update its physical address and serial number to those provided only when packet serial number=0xffffffff or device serial number is equal to the packet serial number. This packet could be used in production to save a serial number and machine address to a device.
Page 7
ER-SP-I0013-09
Response: None Upon reception of a Identify Node ID configure packet, the node shall immediately assume the new node ID and consider the discovery process successful only when packet serial number=0xffffffff or device serial number is equal to the packet serial number.
Ping (0x02)
Byte 1 2 3 4 5-6 7 8-11 Name Length (in bytes) Destination node Source node Subcomponent Interface Method Serial number Description The length of the packet The responding nodes id The senders node id The root subcomponent Administrative Ping The serial number of the piece of equipment containing the node Value 14 [1, 127] ,255 [1, 127] 0 0x00 0x02 [0, 255]
Response: Ping Reply This method is a quick way to get information that a node is available and configured, and to ensure that information about a node is current and correct.
Response: none
Page 8
ER-SP-I0013-09
Response: None Provides another means for the user to match a node ID with an actual piece of equipment. When id number is non-zero, the node shall attempt to identify itself by some means native to it. If its a light source, it might flash, for example. Optionally, the device may try to convey the number, by flashing in bursts of long and short flashes, for example.
Response: Supported interfaces response Recalling that packets can have a maximum length of 255 bytes, and many components may use buffers substantially smaller, it may take several packets to fully enumerate all of the supported interfaces. The page argument is used to specify with which group of n (where n can vary between 1 and 122) interfaces the component should reply.
Page 9
ER-SP-I0013-09
In Greek mythology, a snake-like monster with 9 heads. Those familiar with Inuktun mythology will tell stories of a mythical system with nine cameras, between three and nine tracks, and a tail that went on for miles.
Page 10
ER-SP-I0013-09
Packet index
[0, 250], but packets must be kept to within the size of the devices receive buffer [0, 65535] [0, 255] [0, 255], but realistically probably no more than 10. 255 signifies do not respond.
10-11 12 13
Response: Composite packet subscription response Upon reception of a Subscribe to composite packet, the component shall react to incoming packets with the subscribed group. When such a packet is received, the component will interpret the data at packet index as a command having interface native interface and method native method. Should response index be less than 255, the component will reply to the commanded packet after response index other components have already done so. In this way, any subset of the components subscribed to the composite command can be made to respond, in turn. Trivial grouping would be implemented by having multiple components look to the same packet index for their command. It is intended that components persist their subscriptions between power interruptions, presumably by writing them into EE-PROM. This would require 6 bytes per subscription.
Page 11
ER-SP-I0013-09
Packet index
[0, 250], but packets must be kept to within the size of the devices receive buffer
Response: Composite packet subscription response Upon reception of an Unsubscribe from composite packet packet, the component shall no longer look to packet index upon an incoming packet with the subscribed group. Note that a component may be made to subscribe to the same group multiple times, so as to react to multiple commands embedded in the composite packet. The correct behavior for an unsubscribe command is to remove only the subscription looking to packet index, and not to remove all subscriptions of the particular group.
Response: None
Page 12
ER-SP-I0013-09
10-11 12 13
[0, 250], but packets must be kept to within the size of the devices receive buffer [0, 65535] [0, 255] [0, 255], but realistically probably no more than 10. 255 signifies do not respond. [128, 254]
14
15
16-17 18 19
[0, 250], but packets must be kept to within the size of the devices receive buffer [0, 65535] [0, 255] [0, 255], but realistically probably no more than 10. 255 signifies do not respond.
Response: None
Page 13
ER-SP-I0013-09
Page 14
ER-SP-I0013-09
15
Position Sensor
The interface includes four methods, Get Environmental Parameters, Return Environmental Parameters, Get Available Parameters, and Return Available Parameters.
Page 15
ER-SP-I0013-09
Response: none
Response: none
Page 16
ER-SP-I0013-09
Response: None
Response: none
Page 17
ER-SP-I0013-09
Response: none
Page 18
ER-SP-I0013-09
Response: none Possible codes for device type include M for Minitracs, and L for lights.
Page 19
ER-SP-I0013-09
Response: none
Page 20
ER-SP-I0013-09
Response: none
7 8-11 12
0x08 Unit 32
Page 21
ER-SP-I0013-09
Response: none
Page 22
ER-SP-I0013-09
Response: None Note that only up to 2000 events may be reported even though there are more available the FIFO depth is 5000 events.
Response: None
Page 23
ER-SP-I0013-09
Response: None
Response: None
Page 24
ER-SP-I0013-09
Response: None
Page 25
ER-SP-I0013-09
Response: None
Page 26
ER-SP-I0013-09
Page 27
ER-SP-I0013-09
Response: None
Page 28
ER-SP-I0013-09
Page 29
Inuktun Services Ltd. Byte 1 2 3 4 5-6 7 8-11 12-15 16-19 Name Length (in bytes) Destination node Source node Subcomponent Interface Method Position Feedback parameter 1 Feedback parameter 2
ER-SP-I0013-09 Description The length of the packet The responding nodes id The senders node id The interface subcomponent Position Control Set Position Reply Current encoder counts Feedback parameter 1 value (optional) Feedback parameter 2 value (optional)
October 21, 2013 Value 14, 18 or 22 [0, 127] [0, 127] [0, 255] 0x07 0x01 Int32 [0..Maximum] Float Float
Response: none
Response: none Possible codes for parameter type include V for volts, A for amperes, and X for no parameter returned.
Page 30
ER-SP-I0013-09
position, the device should ignore all commands except the Stop command and the Verify at Reset Position command. Byte 1 2 3 4 5-6 7 Name Length (in bytes) Destination node Source node Subcomponent Interface Method Description The length of the packet The responding nodes id The senders node id The interface subcomponent Position Control Move to Reset Position Value 10 [0, 127] [0, 127] [0, 255] 0x07 0x04
Response: None
Response: none Possible status replies are: T - at reset position; F not at reset position; E error when trying to achieve reset position.
Page 31
ER-SP-I0013-09
Stop (0x0b)
This command will stop the motor. Byte Name 1 Length (in bytes) 2 Destination node 3 Source node 4 Subcomponent 5-6 Interface 7 Method Response: none Description The length of the packet The responding nodes id The senders node id The interface subcomponent Position Control Stop Value 10 [0, 127] [0, 127] [0, 255] 0x07 0x0b
Page 32
ER-SP-I0013-09
Response: none
Page 33
ER-SP-I0013-09
Response: None
Page 34
ER-SP-I0013-09
9-12
Arm position
13-16
Touch pressure
Page 35
ER-SP-I0013-09
Response: none
Page 36
ER-SP-I0013-09
Response: none
0 is reserved for errors/exceptions that havent been added to this list, and would result in a generic Throwable. This list may be extended by future revisions of this document, but for the moment, it is the short list of what would appear to be immediately useful.
Page 37
ER-SP-I0013-09
Throw (0x00)
Byte 1 2 3 4-5 6 7 8 Name Length (in bytes) Destination node Source node Interface Method Throwable ID Message Description The length of the packet The responding nodes id The senders node id Error Throw The ID of the throwable An array of 8-bit ASCII characters containing the intended message (or key to the internationalized version) for the exception Value 15 [0, 127] [0, 127] 0x01 0x00 Currently [0, 6] [0, 245], but packets must be kept to within the size of the devices buffer
Response: None
Implementation note: Should the controller software be written in an exception-capable language, it remains necessary to map errors/exception from the serial protocol into those of the controllers implementation lan guage. The errors and exceptions included thus far have a 1:1 mapping in the Java language. One will further notice that, in Java, all the exceptions used here (except IOException) inherit from RuntimeException, meaning that they do not have to be declared. As any method may return one of these Throwables in place of the expected response, inclusion of a non-Runtime exception dictates that all controller methods receiving a response via this serial protocol would need to declare that exception. Clearly, inclusion of such exceptions in this interface should not be done without careful consideration. It is intended that the controller have a getResponse(), or some such method, by which the code necessary to turn serial protocol exceptions into those of the implementation language will exist in only one place.
- Light, Sony FCB-blah, Open loop p/t, Position mode p/t, Transporter velocity control
Watchdog is at node level (still on the bus, and is being sent commands) - think about tracks, though Make node watchdog commands part of an interface E-stop
Page 38
ER-SP-I0013-09
In EE-PROM: = 10 - MAC address (4) - S/N (4) - Node ID (1) - Meta ID Each composite registration: 6
Page 39