implement register request

This commit is contained in:
Olaf Rempel 2017-11-28 20:52:00 +01:00
parent e6487845b4
commit 1c766cbc27
2 changed files with 86 additions and 27 deletions

View File

@ -38,17 +38,35 @@
/* *********************************************************************** */ /* *********************************************************************** */
static const struct _description_response control_desc[] PROGMEM = { static const struct _description_response control_desc[] PROGMEM = {
{ DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_COMMAND, EVENT_NUM_PWM_CH0, "Door Light Cmd" }, { DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_COMMAND, EVENT_NUM_PWM_CH0, "door/pwm_cmd" },
{ DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_COMMAND, EVENT_NUM_PWM_CH1, "Wall Light Cmd" }, { DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_COMMAND, EVENT_NUM_PWM_CH1, "wall/pwm_cmd" },
{ DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_VALUE, EVENT_NUM_PWM_CH0, "Door Light Val" }, { DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_VALUE, EVENT_NUM_PWM_CH0, "door/pwm_set" },
{ DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_VALUE, EVENT_NUM_PWM_CH1, "Wall Light Val" }, { DESCRIPTION_TYPE_CONTROL, 0xFF, 0xFF, EVENT_TYPE_PWM_VALUE, EVENT_NUM_PWM_CH1, "wall/pwm_set" },
}; };
static const struct _description_response event_desc[] PROGMEM = { static const struct _description_response event_desc[] PROGMEM = {
{ DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_INPUT_BUTTON, EVENT_NUM_INPUT_BUTTON, "Wall Button" }, // { DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_INPUT_BUTTON, EVENT_NUM_INPUT_BUTTON, "wall/input" },
{ DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_INPUT_SWITCH, EVENT_NUM_INPUT_DOOR, "Door Switch" }, // { DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_INPUT_SWITCH, EVENT_NUM_INPUT_DOOR, "door/input" },
{ DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_PWM_STATUS, EVENT_NUM_PWM_CH0, "door/pwm" },
{ DESCRIPTION_TYPE_EVENT, 0xFF, 0xFF, EVENT_TYPE_PWM_STATUS, EVENT_NUM_PWM_CH1, "wall/pwm" },
}; };
#define EVT_DATA_STATE_FREE 0x00
#define EVT_DATA_STATE_REGISTERED 0x01
#define EVT_DATA_STATE_UPDATE 0x02
#define EVT_DATA_STATE_WAIT4CONF 0x04
struct _event_data
{
uint8_t state; // free/registered/wait4conf/retrigger
uint8_t dest_address;
uint16_t data_value; // type/num via event_desc with same idx
};
static struct _event_data event_data[2];
static uint8_t event_idx;
static uint8_t rtx_count;
/* *********************************************************************** */ /* *********************************************************************** */
#define LED_RX 0 #define LED_RX 0
@ -140,9 +158,6 @@ int main(void)
pwm_event_handler(event); pwm_event_handler(event);
break; break;
case EVENT_TYPE_PWM_STATUS:
break;
case EVENT_TYPE_INPUT_INCDEC: case EVENT_TYPE_INPUT_INCDEC:
if (event->num == EVENT_NUM_INPUT_QUAD) if (event->num == EVENT_NUM_INPUT_QUAD)
{ {
@ -150,15 +165,13 @@ int main(void)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH1, EVENT_NUM_PWM_CH1,
EVENT_VALUE_PWM_DEC EVENT_VALUE_PWM_DEC);
);
} }
else if (event->value == EVENT_VALUE_INPUT_QUAD_INC) else if (event->value == EVENT_VALUE_INPUT_QUAD_INC)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH1, EVENT_NUM_PWM_CH1,
EVENT_VALUE_PWM_INC EVENT_VALUE_PWM_INC);
);
} }
} }
break; break;
@ -170,8 +183,7 @@ int main(void)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH1, EVENT_NUM_PWM_CH1,
EVENT_VALUE_PWM_TOGGLE EVENT_VALUE_PWM_TOGGLE);
);
} }
} }
break; break;
@ -183,25 +195,21 @@ int main(void)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH0, EVENT_NUM_PWM_CH0,
EVENT_VALUE_PWM_KEEP EVENT_VALUE_PWM_KEEP);
);
event_queue(EVENT_TYPE_TIMER_SET, event_queue(EVENT_TYPE_TIMER_SET,
EVENT_NUM_TIMER_DOOR_CLOSE_DELAY, EVENT_NUM_TIMER_DOOR_CLOSE_DELAY,
2000 2000);
);
} }
else if (event->value == EVENT_VALUE_INPUT_DOOR_OPEN) else if (event->value == EVENT_VALUE_INPUT_DOOR_OPEN)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH0, EVENT_NUM_PWM_CH0,
EVENT_VALUE_PWM_FADE_MAX EVENT_VALUE_PWM_FADE_MAX);
);
event_queue(EVENT_TYPE_TIMER_SET, event_queue(EVENT_TYPE_TIMER_SET,
EVENT_NUM_TIMER_DOOR_CLOSE_DELAY, EVENT_NUM_TIMER_DOOR_CLOSE_DELAY,
0 0);
);
} }
} }
break; break;
@ -211,12 +219,17 @@ int main(void)
break; break;
case EVENT_TYPE_TIMER_ELAPSED: case EVENT_TYPE_TIMER_ELAPSED:
if (event->num == EVENT_NUM_TIMER_DOOR_CLOSE_DELAY) if ((event->num == EVENT_NUM_TIMER_DEBOUNCE1) ||
(event->num == EVENT_NUM_TIMER_DEBOUNCE2)
)
{
input_event_handler(event);
}
else if (event->num == EVENT_NUM_TIMER_DOOR_CLOSE_DELAY)
{ {
event_queue(EVENT_TYPE_PWM_COMMAND, event_queue(EVENT_TYPE_PWM_COMMAND,
EVENT_NUM_PWM_CH0, EVENT_NUM_PWM_CH0,
EVENT_VALUE_PWM_FADE_MIN EVENT_VALUE_PWM_FADE_MIN);
);
} }
break; break;
@ -224,6 +237,22 @@ int main(void)
break; break;
} }
uint8_t i;
for (i = 0; i < ARRAY_SIZE(event_desc); i++)
{
if ((pgm_read_byte(&event_desc[i].data_type) == event->type) &&
(pgm_read_byte(&event_desc[i].data_num) == event->num)
)
{
event_data[i].data_value = event->value;
if (event_data[i].state & EVT_DATA_STATE_REGISTERED)
{
event_data[i].state |= EVT_DATA_STATE_UPDATE;
}
}
}
event_clear(); event_clear();
} }
@ -335,6 +364,35 @@ int main(void)
} }
break; break;
case MSG_CMD_REGISTER_REQUEST:
rsp_msg->cause = CAUSE_INVALID_PARAMETER;
for (i = 0; i < ARRAY_SIZE(control_desc); i++)
{
if ((pgm_read_byte(&event_desc[i].data_type) == req_msg->p.reg_req.data_type) &&
(pgm_read_byte(&event_desc[i].data_num) == req_msg->p.reg_req.data_num)
)
{
if (req_msg->p.reg_req.enable)
{
event_data[i].state |= EVT_DATA_STATE_REGISTERED;
event_data[i].dest_address = req_pkt->source_address;
}
else
{
event_data[i].state |= ~(EVT_DATA_STATE_REGISTERED | EVT_DATA_STATE_UPDATE);
}
rsp_msg->cause = CAUSE_SUCCESS;
rsp_msg->p.reg_rsp.data_type = req_msg->p.reg_req.data_type;
rsp_msg->p.reg_rsp.data_num = req_msg->p.reg_req.data_num;
rsp_msg->p.reg_rsp.data_value = event_data[i].data_value;
rsp_pkt->data_length += sizeof(struct _register_response);
break;
}
}
break;
default: default:
rsp_msg->cause = CAUSE_NOT_SUPPORTED; rsp_msg->cause = CAUSE_NOT_SUPPORTED;
break; break;
@ -350,5 +408,6 @@ int main(void)
} }
} }
} }
return 0; return 0;
} /* main */ } /* main */