Skip to content
Victor Sonora Pombo edited this page Mar 19, 2014 · 66 revisions

This document describes the format of the UniDA Protocol messages managed by the UniDA library. This protocol is based on the Simple Message Protocol contained in Mytechia Commons which will be also explained.

Contents:

  1. Simple Message Protocol
  2. Message types
  3. Message relationships
  4. UniDA Gateway Messages:
    1. Discover Gateway Devices, Request
    2. Discover Gateway Devices, Reply
    3. Heartbeat
    4. Gateway Status Report, Request
    5. Gateway Status Report, Reply
    6. Autonomous Behaviour Add Rule
    7. Autonomous Behaviour Remove Rule
    8. Autonomous Behaviour Query, Request
    9. Autonomous Behaviour Query, Reply
  5. UniDA Device Messages:
    1. ACK
    2. Query Device States, Request
    3. Query Device States, Reply
    4. Query Device State, Request
    5. Query Device State, Reply
    6. Write Device State
    7. Execute Command
    8. Device Subscription
    9. Device Unsubscription
    10. Device Notification

Simple Message Protocol

Simple Message Protocol messages have always a fixed size header (8 bytes) and optionally a payload of variable length whose content structure is different for each kind of message.

Format:

Init Message type Sequence number Error code Data size Header checksum Payload Payload checksum
1 byte 1 byte 1 byte 1 byte 2 bytes 1 byte variable 1 byte

Fields:

  • Init byte: special byte that just marks the beginning of a message.
  • Message type: identifies the type of the message.
  • The sequence number is used to relate messages of the request/reply kind: the reply carries the same sequence number of the request message it is answering. It s auto-incremental, and cyclic.
  • Error code: can be used to signal different states of error or non-normal execution.
  • Data size: in number of bytes.
  • Header checksum: calculated using a XOR with all the header bytes.
  • Payload: actual content of the message, in case it s needed (some types of message don t use payload).
  • Payload checksum: calculated using a XOR with all the payload bytes.

Message types

These are the types of messages handle by the UniDA Protocol:

Generic ACK 0x001
Discover Gateway Devices, Request 0x002
Discover Gateway Devices- Reply 0x003
Gateway Heartbeat 0x004
Gateway Status Report, Request 0x005
Gateway Status Report, Reply 0x006
Query Device State, Request 0x007
Query Device State, Reply 0x008
Query Device States, Request 0x009
Query Device States, Reply 0x010
Send Command to Device 0x011
Subscribe, Request 0x012
Unsubscribe, Request 0x013
Notification 0x014
Write Device State, Request 0x015
Autonomous Behaviour: Add Rule 0x017
Autonomous Behaviour: Remove Rule 0x018
Autonomous Behaviour: Query, Request 0x019
Autonomous Behaviour: Query, Reply 0x020
Debug Init 0x101
Debug Data 0x106

Message relationships

Protocol Messages Diagram

UniDA Gateway Messages

All UniDA messages share the need to hold the information about the source and destination of the message. So it can be considered like a second header, common to any UniDA message.

Header Src Dest Message payload Checksum
7 bytes 6 bytes 6 bytes Variable size 1 byte

Fields:

  • The Simple Message Protocol header, already explained.
  • UniDA address for the source.
  • UniDA address for the destination.
  • UniDA message payload, of variable size (some messages don t need payload at all).
  • Simple Message Protocol checksum.

All gateway messages follow this format (the device messages do the same, but contain also a small additional "header").

UniDA message: Discover Gateway Devices, Request

This message is sent to ask an UniDA gateway for the information about the devices it handles.

Header Addresses Checksum
7 bytes 12 bytes 1 byte

This message needs no additional payload.

UniDA message: Discover Gateway Devices, Reply

This message contains the full information about the gateway, its device IOs and the devices the gateway contains. Its size is variable: the gateway data and each device chunk include string fields and both the IOs and device lists have a number of elements.

Header Addresses Gateway N Device IOs N Devices Checksum
7 bytes 12 bytes Variable size 2 bytes Variable size 2 bytes Variable size 1 byte

The gateway chunk contains the following fields:

Gateway data
Class Model Manufacturer Op. State
4 bytes Variable size Variable size 2 bytes

Each device IO contains the following fields:

Device IO
IO id N Manufacturer
2 bytes 2 bytes Variable size

And each UniDA device contains the following fields:

Device
Id Class Model Manufacturer Description Op. State N IOs
2 bytes 4 bytes Variable size Variable size Variable size 2 bytes 2 bytes Variable size

UniDA message: Gateway Heartbeat

Every UniDA gateway must send heartbeat messages periodically, as the way to announce its presence. An UniDA Heartbeat Message does not contain information regarding the neither gateway, nor its rules nor its devices. That information is sent only when requested.

Header Addresses Checksum
7 bytes 12 bytes 1 byte

This message needs no additional payload.

UniDA message: Gateway Status Report, Request

This message is a request to a gateway: the client asks about the status of the gateway itself and the status of its devices.

Header Addresses Checksum
7 bytes 12 bytes 1 byte

This message needs no additional payload.

UniDA message: Gateway Status Report, Reply

This message is sent as a reply to an UniDA Gateway Status Request, and contains the information about the current states (error code) of the gateway and each of its devices.

Header Addresses Gw code N Devices codes Checksum
7 bytes 12 bytes 1 byte 2 bytes Variable size 1 byte

For each device:

Device status
Device Id Device code
2 bytes 1 byte

UniDA message: Autonomous Behaviour Add Rule

TBD.

UniDA message: Autonomous Behaviour Remove Rule

TBD.

UniDA message: Autonomous Behaviour Query, Request

TBD.

UniDA message: Autonomous Behaviour Query, Reply

TBD.

UniDA Device Messages

The UniDA messages sent to an specific device have the same overall structure of the other messages, but carry also the information about the device id to which the message is intended, and an operation id also.

Header Src Dest Device Id Operation Id Message payload Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes Variable size 1 byte

Fields:

  • The Simple Message Protocol header.
  • UniDA address for the source.
  • UniDA address for the destination.
  • UniDA device identification.
  • Operation id, used by the UniDA library to get hold of which request messages haven t still been answered.
  • UniDA message payload, of variable size (some messages don t need payload at all).
  • Simple Message Protocol checksum.

UniDA device message: ACK

The ACK message is used as a response to several device operation messages. It contains the operation id that relates it to the original operation message.

Header Src Dest Device Id Operation Id Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 1 byte

UniDA device message: Query Device States, Request

This message asks for the current values of all the states of the specified device.

Header Src Dest Device Id Operation Id Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 1 byte

UniDA device message: Query Device States, Reply

This message sends the information about the current values of all the states of a device. It is always a reply to an UniDA Query Device States Request.

Header Src Dest Device Id Operation Id N State values Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 2 bytes Variable size 1 byte

For each state value:

Device state value
State Id Value Id Value (raw)
4 bytes 4 bytes Variable size

UniDA device message: Query Device State, Request

This request message asks for the current value of the specified state (of the specified device).

Header Src Dest Device Id Operation Id State Id Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 4 bytes 1 byte

UniDA device message: Query Device State, Reply

This message is sent as reply to an UniDA Query Device State Request message. It contains the values for a device state (both id and raw value).

Header Src Dest Device Id Operation Id Value Id Value (raw) Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 4 bytes Variable size 1 byte

UniDA device message: Write Device State

This message informs a device to modify the specified state with the given value (both id and raw value are passed).

Header Src Dest Dev Id Op Id State Id Value Id Value (raw) Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 4 bytes 4 bytes Variable size 1 byte

UniDA device message: Execute Command

With this message, a device is indicated to perform a command specified by its functionality id and command id. Optionally, the message can carry arguments valid for the given command.

Header Src Dest Dev Id Op Id Func Id Cmd Id N Params Checksum
7 bytes 6 bytes 6 bytes 2 bytes 8 bytes 4 bytes 4 bytes 2 bytes Variable size 1 byte

UniDA device message: Subscription

TBD.

UniDA device message: Unsubscription

TBD.

UniDA device message: Notification

TBD.