262 lines
7.9 KiB
C
262 lines
7.9 KiB
C
#ifndef __FUNK_PROTO_H__
|
|
#define __FUNK_PROTO_H__
|
|
|
|
#include <stdint.h>
|
|
|
|
/* *********************************************************************** */
|
|
|
|
/*
|
|
* Protocol:
|
|
* - sender will restransmit up to 3 times if no response/confirmation is received after 10ms
|
|
* - receiver will ignore messages with corrupt headers/data
|
|
* - messages have a seqnum, retransmissions are are detected by same seqnum
|
|
* - response with cause "invalid seqnum"
|
|
* - initiator increases seqnum and sends request again
|
|
* - commands have 2bit req/resp/ind/conf encoding
|
|
* - single window
|
|
*
|
|
* - firmware has modules, that communicate through "events"
|
|
* - INPUT modules (button/quadencoder) send events to all other (!INPUT) modules
|
|
* - WORK modules (dimming, store/restore) send event to all other (!INPUT && !WORK) modules
|
|
* - OUTPUT modules (pwm channels, digital channels) send event to nobody
|
|
* - communication receives all events and can send to anyone
|
|
* - configuration in eeprom(?) to enable which events shall be send (and to who)
|
|
*
|
|
* - support to switch to bootloader
|
|
* - support forward to mpm/twi
|
|
*
|
|
* - version request?
|
|
* - multiple events in one message?
|
|
* - analog values
|
|
*
|
|
*
|
|
*/
|
|
|
|
#define MSG_TYPE_REQUEST 0x00 /* master -> slave req */
|
|
#define MSG_TYPE_CONFIRMATION 0x40 /* master -> slave rsp */
|
|
#define MSG_TYPE_INDICATION 0x80 /* slave -> master req */
|
|
#define MSG_TYPE_RESPONSE 0xC0 /* slave -> master rsp */
|
|
#define MSG_TYPE_MASK 0xC0
|
|
#define MSG_CMD_MASK 0x3F
|
|
|
|
#define MSG_CMD_STATUS_REQUEST (MSG_TYPE_REQUEST | 0x01) /* 0x01 */
|
|
#define MSG_CMD_STATUS_RESPONSE (MSG_TYPE_RESPONSE | 0x01) /* 0xC1 */
|
|
#define MSG_CMD_DESCRIPTION_REQUEST (MSG_TYPE_REQUEST | 0x02) /* 0x02 */
|
|
#define MSG_CMD_DESCRIPTION_RESPONSE (MSG_TYPE_RESPONSE | 0x02) /* 0xC2 */
|
|
#define MSG_CMD_CONTROL_REQUEST (MSG_TYPE_REQUEST | 0x03) /* 0x03 */
|
|
#define MSG_CMD_CONTROL_RESPONSE (MSG_TYPE_RESPONSE | 0x03) /* 0xC3 */
|
|
#define MSG_CMD_REGISTER_REQUEST (MSG_TYPE_REQUEST | 0x04) /* 0x04 */
|
|
#define MSG_CMD_REGISTER_RESPONSE (MSG_TYPE_RESPONSE | 0x04) /* 0xC4 */
|
|
#define MSG_CMD_EVENT_INDICATION (MSG_TYPE_INDICATION | 0x03) /* 0x83 */
|
|
#define MSG_CMD_EVENT_CONFIRMATION (MSG_TYPE_CONFIRMATION | 0x03) /* 0x43 */
|
|
|
|
#define MSG_CMD_SWITCHAPP_REQUEST (MSG_TYPE_REQUEST | 0x20)
|
|
#define MSG_CMD_SWITCHAPP_RESPONSE (MSG_TYPE_RESPONSE | 0x20)
|
|
#define MSG_CMD_VERSION_REQUEST (MSG_TYPE_REQUEST | 0x21)
|
|
#define MSG_CMD_VERSION_RESPONSE (MSG_TYPE_RESPONSE | 0x21)
|
|
#define MSG_CMD_CHIPINFO_REQUEST (MSG_TYPE_REQUEST | 0x22)
|
|
#define MSG_CMD_CHIPINFO_RESPONSE (MSG_TYPE_RESPONSE | 0x22)
|
|
#define MSG_CMD_READ_REQUEST (MSG_TYPE_REQUEST | 0x23)
|
|
#define MSG_CMD_READ_RESPONSE (MSG_TYPE_RESPONSE | 0x23)
|
|
#define MSG_CMD_WRITE_REQUEST (MSG_TYPE_REQUEST | 0x24)
|
|
#define MSG_CMD_WRITE_RESPONSE (MSG_TYPE_RESPONSE | 0x24)
|
|
|
|
#define CAUSE_SUCCESS 0x00
|
|
#define CAUSE_NOT_SUPPORTED 0xF0
|
|
#define CAUSE_INVALID_PARAMETER 0xF1
|
|
#define CAUSE_UNSPECIFIED_ERROR 0xFF
|
|
|
|
#define DESCRIPTION_TYPE_CONTROL 0x01
|
|
#define DESCRIPTION_TYPE_EVENT 0x02
|
|
|
|
#define BOOTMODE_BOOTLOADER 0x00
|
|
#define BOOTMODE_APPLICATION 0x80
|
|
|
|
#define MEMTYPE_FLASH 0x01
|
|
#define MEMTYPE_EEPROM 0x02
|
|
|
|
/* *********************************************************************** */
|
|
|
|
/*
|
|
* Send a Description Request to a Light
|
|
* - type is "Control" or "Event"
|
|
* - num is number of controls or events
|
|
*/
|
|
struct _description_request
|
|
{
|
|
uint8_t type;
|
|
uint8_t num;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Send a Description Response to the master
|
|
* - type is Control or Event
|
|
* - num is number of controls or event
|
|
* - max_num is the max number of controls or events
|
|
* - data_type is used in Control_req / Event_ind
|
|
* - data_num is used in Control_req / Event_ind
|
|
* - data_desc is short ASCII name of that control/event
|
|
*/
|
|
struct _description_response
|
|
{
|
|
uint8_t type;
|
|
uint8_t num;
|
|
uint8_t max_num;
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
uint8_t data_desc[16];
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Send a Control Request to a Light
|
|
* - data_type is "button_press", "abs_dim_value", "step_up/down"
|
|
* - data_num is button_numer or channel ID of light
|
|
* - data is for abs values, width is encoded in ctrl_type
|
|
*/
|
|
struct _control_request
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
uint16_t data_value;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Response for Control Request
|
|
* just repeat the type & num
|
|
* cause is in header
|
|
*/
|
|
struct _control_response
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Register a Event
|
|
* - data_type is "button_press", "movement detected", "step up/down"
|
|
* - data_num is button number or channel ID
|
|
* - enable is true/false
|
|
*/
|
|
struct _register_request
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
uint8_t enable;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Response for Register Request
|
|
* - data_type is "button_press", "movement detected", "step up/down"
|
|
* - data_num is button number or channel ID
|
|
* - data_value is last known value
|
|
*/
|
|
struct _register_response
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
uint16_t data_value;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Send a Event to Master
|
|
* - data_type is "button_press", "movement detected", "step up/down"
|
|
* - data_num is button number or channel ID
|
|
* - data is for abs values, width is encoded in ctrl_type
|
|
*/
|
|
struct _event_indication
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
uint16_t data_value;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
/*
|
|
* Confirmation of event indication
|
|
* just repeat the type & num
|
|
* cause is in header
|
|
*/
|
|
struct _event_confirmation
|
|
{
|
|
uint8_t data_type;
|
|
uint8_t data_num;
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
struct rfm12_msg
|
|
{
|
|
uint8_t command; /* MSG_CMD_* */
|
|
uint8_t seqnum;
|
|
uint8_t cause; /* CAUSE_* */
|
|
|
|
union
|
|
{
|
|
/* application messages */
|
|
|
|
/* MSG_CMD_DESCRIPTION_REQUEST */
|
|
struct _description_request desc_req;
|
|
|
|
/* MSG_CMD_DESCRIPTION_RESPONSE */
|
|
struct _description_response desc_rsp;
|
|
|
|
/* MSG_CMD_CONTROL_REQUEST */
|
|
struct _control_request ctrl_req;
|
|
|
|
/* MSG_CMD_CONTROL_RESPONSE */
|
|
struct _control_response ctrl_rsp;
|
|
|
|
/* MSG_CMD_REGISTER_REQUEST */
|
|
struct _register_request reg_req;
|
|
|
|
/* MSG_CMD_REGISTER_RESPONSE */
|
|
struct _register_response reg_rsp;
|
|
|
|
/* MSG_CMD_EVENT_INDICATION */
|
|
struct _event_indication evt_ind;
|
|
|
|
/* MSG_CMD_EVENT_CONFIRMATION */
|
|
struct _event_confirmation evt_cnf;
|
|
|
|
/* bootloader messages */
|
|
|
|
struct { /* MSG_CMD_SWITCHAPP_REQUEST */
|
|
uint8_t app;
|
|
} switchapp;
|
|
|
|
struct { /* MSG_CMD_VERSION_RESPONSE */
|
|
uint8_t data[16];
|
|
} version;
|
|
|
|
struct { /* MSG_CMD_CHIPINFO_RESPONSE */
|
|
uint8_t data[8];
|
|
} chipinfo;
|
|
|
|
struct { /* MSG_CMD_READ_REQUEST */
|
|
uint16_t address;
|
|
uint8_t mem_type;
|
|
uint8_t size;
|
|
} read_req;
|
|
|
|
struct { /* MSG_CMD_READ_RESPONSE */
|
|
uint8_t data[32];
|
|
} read_rsp;
|
|
|
|
struct { /* MSG_CMD_WRITE_REQUEST */
|
|
uint16_t address;
|
|
uint8_t mem_type;
|
|
uint8_t size;
|
|
uint8_t data[32];
|
|
} write_req;
|
|
} p;
|
|
} __attribute__ ((__packed__));
|
|
|
|
/* *********************************************************************** */
|
|
|
|
#endif /* __FUNK_PROTO_H__ */
|