#ifndef __FUNK_PROTO_H__ #define __FUNK_PROTO_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 * - multi master should be supported (for lights talking to each other) * * * - 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) * * - or is there a register service? * - need to detect if device is restarted and register again * * - 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_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 BOOTMODE_BOOTLOADER 0x00 #define BOOTMODE_APPLICATION 0x80 #define MEMTYPE_FLASH 0x01 #define MEMTYPE_EEPROM 0x02 /* *********************************************************************** */ struct rfm12_msg { uint8_t command; /* MSG_CMD_* */ uint8_t seqnum; uint8_t cause; /* CAUSE_* */ union { /* * Send a Description Request to a Light * - type is "Control" or "Event" * - num is 1-based number of controls or events */ struct { /* MSG_CMD_DESCRIPTION_REQUEST */ uint8_t type; uint8_t num; } desc_req; /* * Send a Description Response to the master * - type is Control or Event * - num is 1-based 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 { /* MSG_CMD_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]; } desc_rsp; /* * 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 { /* MSG_CMD_CONTROL_REQUEST */ uint8_t data_type; uint8_t data_num; union { uint8_t u8[4]; uint16_t u16[2]; uint32_t u32; } data; } ctrl_req; /* * Response for Control Response * just repeat the type & num * cause is in header */ struct { /* MSG_CMD_CONTROL_RESPONSE */ uint8_t data_type; uint8_t data_num; } ctrl_rsp; /* * 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 { /* MSG_CMD_EVENT_INDICATION */ uint8_t data_type; uint8_t data_num; union { uint8_t u8[4]; uint16_t u16[2]; uint32_t u32; } data; } evt_ind; /* * Confirmation of event indication * just repeat the type & num * cause is in header */ struct { /* MSG_CMD_EVENT_CONFIRMATION */ uint8_t data_type; uint8_t data_num; } 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; }; /* *********************************************************************** */ #endif /* __FUNK_PROTO_H__ */