#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\begin_preamble
\usepackage[long]{datetime}
\usepackage[toc]{multitoc}
\renewcommand\tableofcontents{%
\@starttoc{toc}%
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\chead{Sense/Net Bus Specification}
\lhead{}
\rhead{}
\end_preamble
\use_default_options true
\begin_modules
customHeadersFooters
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman lmodern
\font_sans lmss
\font_typewriter lmtt
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement h
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder true
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize default
\use_geometry true
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 2cm
\topmargin 2cm
\rightmargin 2cm
\bottommargin 2cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Title
Sense/Net Bus Specification
\end_layout
\begin_layout Author
Nick Ames
\begin_inset Formula $\cdot$
\end_inset
Revision 3
\begin_inset Newline newline
\end_inset
Copyright 2016 Sensiplicity Systems
\end_layout
\begin_layout Standard
\begin_inset Box Frameless
position "t"
hor_pos "c"
has_inner_box 1
inner_pos "t"
use_parbox 0
use_makebox 0
width "100col%"
special "none"
height "1in"
height_special "totalheight"
status open
\begin_layout Plain Layout
\begin_inset CommandInset toc
LatexCommand tableofcontents
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Section
Overview
\end_layout
\begin_layout Standard
The Sense/Net bus is an inexpensive system for retrieving data from large
numbers of environment sensors.
It provides power and two digital buses: RS-485 and 1-Wire.
The 1-Wire bus is used over short distances (TODO) with simple 1-wire sensors,
such as thermometers.
The RS-485 bus is used over longer distances to connect more sophisticated
sensors.
Up to 100 sensors can be connected to the bus.
\end_layout
\begin_layout Standard
An individual Sense/Net bus is composed of a single controller, many nodes
(sensors), an optional terminator, and optional power injectors.
All communication on the bus is initiated by the controller, which gathers
data from the nodes.
\end_layout
\begin_layout Section
Physical Layer
\end_layout
\begin_layout Subsection
Wiring
\end_layout
\begin_layout Standard
\begin_inset Note Note
status open
\begin_layout Plain Layout
Include info on new four-conductor pinout
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Connections are made using modular jacks (RJ-12) and six conductor cable.
(If no 1-wire devices are present, RJ-11 jacks and four-conductor cable
may be employed.) Cables should be wired
\begin_inset Quotes eld
\end_inset
straight-through
\begin_inset Quotes erd
\end_inset
, meaning they have the same connections on both ends.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\begin_inset Box Frameless
position "c"
hor_pos "c"
has_inner_box 1
inner_pos "t"
use_parbox 0
use_makebox 0
width "3cm"
special "none"
height "1in"
height_special "totalheight"
status open
\begin_layout Plain Layout
\begin_inset Graphics
filename images/RJ-12 Pinout.eps
width 3cm
\end_inset
\end_layout
\end_inset
\begin_inset space \hspace{}
\length 1cm
\end_inset
\family sans
\size small
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
\emph on
Signals
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
\emph on
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
Unused
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
\emph on
2
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
5V Power
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
\emph on
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
RS-485 B
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
\emph on
4
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\family sans
\size small
RS-485 A
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
5
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Gnd
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
6
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1-Wire I/O
\end_layout
\end_inset
|
\end_inset
\family default
\size default
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Connector signals and pinout
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Topology
\end_layout
\begin_layout Standard
To prevent signal degradation, a Sense/Net bus should be arranged as a line,
not as a tree.
For longer runs, a terminator at the end of the bus opposite the controller
is recommended.
\end_layout
\begin_layout Standard
\begin_inset Note Note
status open
\begin_layout Plain Layout
TODO: Power limitations
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Power
\end_layout
\begin_layout Standard
Power to sensors is provided by +5V and ground lines in the cable.
\end_layout
\begin_layout Section
Protocol (RS-485) v3
\end_layout
\begin_layout Standard
At the lowest level, bytes are transmitted on the RS-485 bus at 19200 baud
with eight data bits, one stop bit, and no parity (8N1).
Data on the Sense/Net bus is exchanged in packets.
A packet can be sent from the controller to a node (a request) or from
a node to the controller (a reply).
Each node contains a unique nine byte long ID which is used to address
it on the bus.
Nodes connected to the bus are discovered by the controller during enumeration.
\begin_inset Note Note
status open
\begin_layout Plain Layout
Cross-reference
\end_layout
\end_inset
\end_layout
\begin_layout Standard
To request data, or perform an action, the controller sends a packet to
a node.
The node may reply with a single packet.
While awaiting a reply, the controller should not send any other packets
until the wait-reply interval has elapsed.
\begin_inset Note Note
status open
\begin_layout Plain Layout
Cross-reference
\end_layout
\end_inset
Nodes may only send packets when requested by the controller, and may only
send a single packet for each request.
Enumeration is an exception to normal operation; during enumeration, a
single request from the controller results in a reply from all nodes.
\begin_inset Note Note
status open
\begin_layout Plain Layout
Cross-reference
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Packets are delineated with two special characters: Start (0x01), End (0x03),
and Escape (0x1B).
Start and end characters are placed at the beginning and end of each packet
to separate it from others.
An escape character is inserted immediately before any verbatim 0x01, 0x03,
or 0x1B bytes that must appear in a packet.
\end_layout
\begin_layout Standard
When a node receives a start character it discards any in-progress packet
and begins a new one.
If the controller receives a start character in the middle of a reply,
it is an error, and the reply is invalid.
Nodes process a packet and perform an action only after receiving a stop
character.
\end_layout
\begin_layout Standard
To protect against corruption, packets are validated with a two-byte CRC
at their end.
The CRC is computed over all packet data that precedes it, excluding the
start byte.
CRC calculation uses a polynomial of 0x1021 and an initial value of 0xFFFF.
\end_layout
\begin_layout Subsection
Packet Structure
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
(Start Character)
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
Header
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Node ID
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Data
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
CRC
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
1 byte
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
9 bytes
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0-128 bytes
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
2 bytes
\end_layout
\end_inset
|
\end_inset
\emph on
(End Character)
\emph default
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Packet structure.
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsubsection
Header
\end_layout
\begin_layout Subsubsection
Header
\end_layout
\begin_layout Standard
The header describes the direction of data transfer and contains commands
common to all node types (nodes may implement additional commands in the
data field).
Packets do not contain any data for standard commands, but nodes may implement
additional commands that require data.
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
Controller to Node:
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Bit
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
7
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
6
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
5
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
4
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
2
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
0
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Value
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Command
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
Node to Controller:
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Bit
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
7
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
6
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
5
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
4
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
2
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
0
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Value
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Status
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Header structure.
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsubsection*
Command Codes
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $000_{2}$
\end_inset
-- Get Data
\end_layout
\begin_layout Standard
Tells the node to send a sensor data packet.
The format of the data packets is defined by the node.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $001_{2}$
\end_inset
-- Enumerate
\end_layout
\begin_layout Standard
Tells all nodes to perform an enumeration.
All nodes respond to this command, regardless of the node ID in the packet.
(Although the node ID is not checked, the CRC must match the contents of
the packet.)
\end_layout
\begin_layout Standard
During an enumeration, each node waits a random length of time (up to 2
seconds) before sending an enumeration reply packet to the controller.
If the bus is busy when a node is ready to send, it will wait until the
bus is free.
The enumeration process allows the controller to discover the nodes connected
on the bus.
\end_layout
\begin_layout Standard
An enumeration reply packet contains two bytes of data, giving the type
code of the node replying.
All types codes except 0x0000 are potentially valid.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $010{}_{2}$
\end_inset
-- Fast Enumerate
\end_layout
\begin_layout Standard
Tells the node to immediately send an enumeration reply.
All nodes respond to this command, regardless of the node ID in the packet.
(Although the node ID is not checked, the CRC must match the contents of
the packet.)
\end_layout
\begin_layout Standard
This command is for testing purposes, and must only be used on a bus containing
a single node.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $011{}_{2}$
\end_inset
-- Blink
\end_layout
\begin_layout Standard
Tells the node to blink its status LED, if it has one.
No reply will be returned.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $100{}_{2}-111_{2}$
\end_inset
-- Node Defined
\end_layout
\begin_layout Standard
Nodes may define additional commands.
\end_layout
\begin_layout Subsubsection*
Status Codes
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $000_{2}$
\end_inset
-- Data
\end_layout
\begin_layout Standard
This packet contains data requested by the controller.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $001_{2}$
\end_inset
-- Enumeration Reply
\end_layout
\begin_layout Standard
This packet is a reply to an enumeration command.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $010{}_{2}$
\end_inset
-- Invalid Command Error
\end_layout
\begin_layout Standard
The node received an invalid command from the controller.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $011_{2}$
\end_inset
-- Internal Error
\end_layout
\begin_layout Standard
The node encountered an internal error that prevents it from returning data.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $100{}_{2}-111_{2}$
\end_inset
-- Node Defined
\end_layout
\begin_layout Standard
Nodes may define additional responses.
\end_layout
\begin_layout Subsubsection
Node ID
\end_layout
\begin_layout Standard
The node ID is the unique ID burned into the microcontroller of the node.
\end_layout
\begin_layout Subsubsection
Data Length
\end_layout
\begin_layout Standard
The length of the data field.
Valid values are 0--128.
\end_layout
\begin_layout Subsubsection
Data
\end_layout
\begin_layout Standard
Packet data.
The structure and meaning of this data is defined by the particular type
of node being addressed.
Multi-byte values within packet data are transmitted least-significant
byte first (little-endian).
For enumeration reply packets, this field contains the two-byte type code
of the node replying.
\end_layout
\begin_layout Subsubsection
CRC
\end_layout
\begin_layout Standard
Data corruption during transmission is detected by computing a CRC (16-bit,
polynomial 0x1021, initial value 0xFFFF) of all the bytes in the packet
up to the CRC (excluding the start byte), and comparing it with the CRC
at the end.
If they do not match, the packet has been corrupted, and is discarded without
a response.
The following C code can be used to calculate the CRC:
\end_layout
\begin_layout Standard
\begin_inset listings
inline false
status open
\begin_layout Plain Layout
#include
\end_layout
\begin_layout Plain Layout
\end_layout
\begin_layout Plain Layout
/* Calculate CRC of a Sense/Net packet.
packet[0] is the header.
\end_layout
\begin_layout Plain Layout
* If this function is computed over a whole packet, including the
\end_layout
\begin_layout Plain Layout
* CRC at the end, a return value of 0 indicates a valid packet.
*/
\end_layout
\begin_layout Plain Layout
uint16_t calc_crc(uint8_t *packet, int packet_length){
\end_layout
\begin_layout Plain Layout
uint16_t remainder = 0xFFFF;
\end_layout
\begin_layout Plain Layout
for (int i = 0; i < packet_length; i++){
\end_layout
\begin_layout Plain Layout
remainder ^= packet[i] << 8;
\end_layout
\begin_layout Plain Layout
for (int bit = 8; bit > 0; bit--){
\end_layout
\begin_layout Plain Layout
if (remainder & 0x8000){
\end_layout
\begin_layout Plain Layout
remainder = (remainder << 1) ^ 0x1021;
\end_layout
\begin_layout Plain Layout
} else {
\end_layout
\begin_layout Plain Layout
remainder = (remainder << 1);
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
return remainder;
\end_layout
\begin_layout Plain Layout
}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Enumeration
\end_layout
\begin_layout Standard
Enumeration allows the controller to discover all nodes connected to the
bus.
After sending an enumeration command, each node will
\end_layout
\begin_layout Standard
each reply takes 14 bytes=7.3ms
\end_layout
\begin_layout Standard
for 100 devices, minimum time is = 730ms
\end_layout
\begin_layout Standard
nodes can detect collisions within one byte
\end_layout
\begin_layout Section
Protocol (RS-485)
\end_layout
\begin_layout Standard
At the lowest level, bytes are transmitted on the RS-485 bus at 19200 baud
with eight data bits, one stop bit, and no parity (8N1).
Data on the Sense/Net bus is exchanged in packets.
Packets can be sent from the controller to a single node, from the controller
to all nodes, or from a node to the controller.
Each node has a unique ID that is discovered by the controller during enumerati
on.
\end_layout
\begin_layout Standard
To request data, or perform an action, the controller sends a packet to
a node.
If required, that node will send a packet back to the controller.
In between sending the command packet and receiving the reply, the controller
should not send packets to other nodes.
Nodes may not send a packet except when requested by the controller, and
may only send a single packet for each request.
\end_layout
\begin_layout Standard
Enumeration allows the controller to discover the nodes on the bus.
TODO
\end_layout
\begin_layout Subsection
Packet Structure
\end_layout
\begin_layout Standard
Each packet has the follow fields: header, node ID, data length, data, and
CRC.
Multi-byte values are sent least significant byte first (little-endian).
The maximum size of a Sense/Net packet is 141 bytes.
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
(Start)
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
Header
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Node ID
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Data Length
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Data
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
CRC
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
1 byte
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
9 bytes
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1 byte
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0-128 bytes
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
2 bytes
\end_layout
\end_inset
|
\end_inset
\emph on
(End)
\emph default
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Packet structure.
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsubsection
Header
\end_layout
\begin_layout Standard
The header describes the direction of data transfer and contains commands
common to all node types (nodes may implement additional commands in the
data field).
Packets do not contain any data for standard commands, but nodes may implement
additional commands that require data.
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
Controller to Node:
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Bit
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
7
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
6
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
5
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
4
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
2
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
0
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Value
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Command
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\emph on
Node to Controller:
\emph default
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Bit
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
7
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
6
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
5
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
4
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
2
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
0
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Value
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
Status
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\end_layout
\end_inset
|
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Header structure.
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsubsection*
Command Codes
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $000_{2}$
\end_inset
-- Get Data
\end_layout
\begin_layout Standard
Tells the node to send a sensor data packet.
The format of the data packets is defined by the node.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $001_{2}$
\end_inset
-- Enumerate
\end_layout
\begin_layout Standard
Tells all nodes to perform an enumeration.
All nodes respond to this command, regardless of the node ID in the packet.
(Although the node ID is not checked, the CRC must match the contents of
the packet.)
\end_layout
\begin_layout Standard
During an enumeration, each node waits a random length of time (up to 2
seconds) before sending an enumeration reply packet to the controller.
If the bus is busy when a node is ready to send, it will wait until the
bus is free.
The enumeration process allows the controller to discover the nodes connected
on the bus.
\end_layout
\begin_layout Standard
An enumeration reply packet contains two bytes of data, giving the type
code of the node replying.
All types codes except 0x0000 are potentially valid.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $010{}_{2}$
\end_inset
-- Fast Enumerate
\end_layout
\begin_layout Standard
Tells the node to immediately send an enumeration reply.
All nodes respond to this command, regardless of the node ID in the packet.
(Although the node ID is not checked, the CRC must match the contents of
the packet.)
\end_layout
\begin_layout Standard
This command is for testing purposes, and must only be used on a bus containing
a single node.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $011{}_{2}$
\end_inset
-- Blink
\end_layout
\begin_layout Standard
Tells the node to blink its status LED, if it has one.
No reply will be returned.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $100{}_{2}-111_{2}$
\end_inset
-- Node Defined
\end_layout
\begin_layout Standard
Nodes may define additional commands.
\end_layout
\begin_layout Subsubsection*
Status Codes
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $000_{2}$
\end_inset
-- Data
\end_layout
\begin_layout Standard
This packet contains data requested by the controller.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $001_{2}$
\end_inset
-- Enumeration Reply
\end_layout
\begin_layout Standard
This packet is a reply to an enumeration command.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $010{}_{2}$
\end_inset
-- Invalid Command Error
\end_layout
\begin_layout Standard
The node received an invalid command from the controller.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $011_{2}$
\end_inset
-- Internal Error
\end_layout
\begin_layout Standard
The node encountered an internal error that prevents it from returning data.
\end_layout
\begin_layout Subsubsection*
\begin_inset Formula $100{}_{2}-111_{2}$
\end_inset
-- Node Defined
\end_layout
\begin_layout Standard
Nodes may define additional responses.
\end_layout
\begin_layout Subsubsection
Node ID
\end_layout
\begin_layout Standard
The node ID is the unique ID burned into the microcontroller of the node.
\end_layout
\begin_layout Subsubsection
Data Length
\end_layout
\begin_layout Standard
The length of the data field.
Valid values are 0--128.
\end_layout
\begin_layout Subsubsection
Data
\end_layout
\begin_layout Standard
Packet data.
The structure and meaning of this data is defined by the particular type
of node being addressed.
For enumeration reply packets, this field contains the two-byte type code
of the node replying.
\end_layout
\begin_layout Subsubsection
CRC
\end_layout
\begin_layout Standard
Data corruption during transmission is detected by computing a CRC (16-bit,
polynomial 0x1021, initial value 0xFFFF) of all the bytes in the packet
up to the CRC, and comparing it with the CRC at the end.
If they do not match, the packet has been corrupted, and is discarded without
a response.
The following C code can be used to calculate the CRC:
\end_layout
\begin_layout Standard
\begin_inset listings
inline false
status open
\begin_layout Plain Layout
#include
\end_layout
\begin_layout Plain Layout
\end_layout
\begin_layout Plain Layout
/* Calculate CRC of a Sense/Net packet.
packet[0] is the header.
\end_layout
\begin_layout Plain Layout
* If this function is computed over a whole packet, including the
\end_layout
\begin_layout Plain Layout
* CRC at the end, a return value of 0 indicates a valid packet.
*/
\end_layout
\begin_layout Plain Layout
uint16_t calc_crc(uint8_t *packet, int packet_length){
\end_layout
\begin_layout Plain Layout
uint16_t remainder = 0xFFFF;
\end_layout
\begin_layout Plain Layout
for (int i = 0; i < packet_length; i++){
\end_layout
\begin_layout Plain Layout
remainder ^= packet[i] << 8;
\end_layout
\begin_layout Plain Layout
for (int bit = 8; bit > 0; bit--){
\end_layout
\begin_layout Plain Layout
if (remainder & 0x8000){
\end_layout
\begin_layout Plain Layout
remainder = (remainder << 1) ^ 0x1021;
\end_layout
\begin_layout Plain Layout
} else {
\end_layout
\begin_layout Plain Layout
remainder = (remainder << 1);
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
}
\end_layout
\begin_layout Plain Layout
return remainder;
\end_layout
\begin_layout Plain Layout
}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Enumeration
\end_layout
\begin_layout Standard
The enumeration process enables the controller to discover the nodes connected
to it.
After sending the enumeration command, each node randomly chooses one of
500000 time slots, each 4us long, with the first (0th) time slot occurring
5ms after the enumeration command.
When its time slot arrives, the node sends an enumeration reply packet
to the controller.
Because the time slots are chosen randomly, and each node's reply packet
occupies 1750 time slots, collisions between nodes are possible.
To prevent this, each node listens to the reply bytes of the other nodes.
If the next possible byte in the conflicting node's packet would overlap
a node's time slot, it reschedules its transmission to 256 plus a random
number (up to 512) of time slots later.
\end_layout
\begin_layout Subsection
Timing
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\begin_inset Graphics
filename images/Timing.png
lyxscale 10
width 12cm
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Timing
\begin_inset CommandInset label
LatexCommand label
name "timing"
\end_inset
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Some timing requirements are imposed on packets and frames within a packet
(fig.
\begin_inset CommandInset ref
LatexCommand ref
reference "timing"
\end_inset
and table
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Timing"
\end_inset
).
The ends of packets are detected using the packet spacing (
\begin_inset Formula $t_{ps}$
\end_inset
).
When a byte arrives, a timer is started.
When the timer expires, the packet is check for consistency (using the
CRC) and validity.
If valid, it is processed, and the buffer index is reset for the next packet.
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset space \hfill{}
\end_inset
\begin_inset Tabular
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Description
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Symbol
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Min
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Max
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\emph on
Unit
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
Frame Spacing
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $t_{fs}$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
400
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
us
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
Packet Spacing
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $t_{ps}$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
1500
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $\infty$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
us
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
Request Latency
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $t_{rl}$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $t_{ps}$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
5000
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
us
\end_layout
\end_inset
|
|
\begin_inset Text
\begin_layout Plain Layout
Enumeration Time
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
\begin_inset Formula $t_{enum}$
\end_inset
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
0.7
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
3
\end_layout
\end_inset
|
\begin_inset Text
\begin_layout Plain Layout
s
\end_layout
\end_inset
|
\end_inset
\begin_inset space \hfill{}
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
Timing
\begin_inset CommandInset label
LatexCommand label
name "tab:Timing"
\end_inset
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Besides the packet timing requirements, each node is allowed a one-second
\begin_inset Quotes eld
\end_inset
warm-up
\begin_inset Quotes erd
\end_inset
time between power-on and when it begins listening to the Sense/Net bus.
For most controllers, the time required to boot up will exceed the warm-up
time.
\end_layout
\end_body
\end_document