Stairs/module/mockmaster/protocol.h

156 lines
4.1 KiB
C
Raw Normal View History

/*
* Stairs lighting
* Copyright 2017 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/Stairs
*/
#ifndef __protocol
#define __protocol
#include <stdint.h>
/*
* There are three classes of messages, these masks provide a way to identify
* unknown messages if the protocol ever changes.
*
* MaskBroadcastCommand: commands which do not expect a response
* MaskModuleCommand: commands which do expect a command. respond with ResponseUhmWhat to satisfy the response requirement.
* MaskResponse: responses to commands
*/
const uint8_t MaskMessageType = 0b11000000;
const uint8_t MaskBroadcastCommand = 0b10000000;
const uint8_t MaskModuleCommand = 0b11000000;
const uint8_t MaskResponse = 0b01000000;
const uint8_t ResponseUhmWhat = 0x00 | MaskResponse;
/*
* Ping:
* Aimed at a specific module, which must respond with a
* ResponsePing message.
*
* Request:
* [0] CommandPing
* [1] Module index
*
* Response:
* [0] ResponsePing
* [1] Module index
*/
const uint8_t BasePing = 0x01;
const uint8_t CommandPing = BasePing | MaskModuleCommand;
const uint8_t ResponsePing = BasePing | MaskResponse;
/*
* Display module index:
* Broadcast to all modules which should turn on their display
* and show the current settings. No response is expected.
*
* Request:
* [0] CommandDisplayModuleIndex
*/
const uint8_t CommandDisplayModuleIndex = 0x02 | MaskBroadcastCommand;
/*
* Start linking:
* Broadcast to all modules which should change to link mode.
* During link mode the master will disable all other communication,
* allowing the module to respond at will in response to user input.
*
* Each module should send a CommandRequestLink message when user input
* is provided.
*
* Request:
* [0] CommandStartLink
*
* Response (eventually):
* See CommandRequestLink
*/
const uint8_t CommandStartLink = 0x10 | MaskBroadcastCommand;
/*
* Request link:
* Sent by a module when user input is provided to link this module
* as the next in line. All other modules should disable sending this
* message until the currently requesting module receives a response.
*
* The master must respond with the new module index, which the
* module must apply and store immediately.
*
* Request:
* [0] CommandRequestLink
*
* Response:
* [0] ResponseRequestLink
* [1] New module index
*/
const uint8_t BaseRequestLink = 0x11;
const uint8_t CommandRequestLink = BaseRequestLink | MaskBroadcastCommand;
const uint8_t ResponseRequestLink = BaseRequestLink | MaskResponse;
/*
* Stop linking:
* Broadcast to all modules when the master takes back control
* over the communication line. No response is expected.
*
* Request:
* [0] CommandStopLink
*/
const uint8_t CommandStopLink = 0x12 | MaskBroadcastCommand;
/*
* Set PWM value:
* Aimed at a specific module, which must apply the specified
* PWM values to the LED strips and respond with a
* ResponseSetPWM message.
*
* Request:
* [0] CommandSetPWM
* [1] Module index
* [2] Flags, see below
* [3,4] PWM value for step 1 (0-4095, uint16_t)
* [5,6] PWM value for step 2 (0-4095, uint16_t)
*
* Response:
* [0] ResponseSetPWM
* [1] Module index
*/
const uint8_t BaseSetPWM = 0x20;
const uint8_t CommandSetPWM = BaseSetPWM | MaskModuleCommand;
const uint8_t ResponseSetPWM = BaseSetPWM | MaskResponse;
// If included, the on-board verification LEDs should light up with
// the specified PWM values as well. Otherwise they should be off.
const uint8_t SetPWMFlagModuleLEDs = 0x01;
/*
* Get sensor values:
* Aimed at a specific module, which must response with a
* ResponseGetSensors message containing the current sensor states.
*
* Request:
* [0] CommandGetSensors
* [1] Module index
*
* Response:
* [0] ResponseGetSensors
* [1] Module index
* [2] Analog (0-255) or digital (0, 255) value for sensor 1
* [3] Analog (0-255) or digital (0, 255) value for sensor 2
*/
const uint8_t BaseGetSensors = 0x30;
const uint8_t CommandGetSensors = BaseGetSensors | MaskModuleCommand;
const uint8_t ResponseGetSensors = BaseGetSensors | MaskResponse;
#endif