Sync work
This commit is contained in:
parent
43d1811d2e
commit
d4e346c5a0
7 changed files with 241 additions and 28 deletions
|
|
@ -27,6 +27,26 @@ void rs485_out(void) {
|
|||
RS485_DIR = 1;
|
||||
}
|
||||
|
||||
void send_state(void) {
|
||||
MyMessage state;
|
||||
|
||||
state.data[0] = 0;
|
||||
state.version_length = (1 << 3) + V2_MYS_HEADER_PROTOCOL_VERSION;
|
||||
state.sensor = 0;
|
||||
state.type = V_TRIPPED;
|
||||
send(&state, P_BYTE);
|
||||
state.sensor = 1;
|
||||
send(&state, P_BYTE);
|
||||
state.data[0] = RELAY1;
|
||||
state.sensor = 2;
|
||||
state.type = V_STATUS;
|
||||
send(&state, P_BYTE);
|
||||
state.data[0] = RELAY2;
|
||||
state.sensor = 3;
|
||||
send(&state, P_BYTE);
|
||||
sendBattery(100);
|
||||
}
|
||||
|
||||
void receive(const MyMessage* mymsg)
|
||||
{
|
||||
uint8_t sensor;
|
||||
|
|
@ -34,22 +54,23 @@ void receive(const MyMessage* mymsg)
|
|||
// We only expect one type of message from controller. But we better check anyway.
|
||||
if (mymsg->type == V_STATUS) {
|
||||
sensor = mymsg->sensor;
|
||||
if (sensor == 3)
|
||||
if (sensor == 2)
|
||||
RELAY1 = (mymsg->data[0]=='1')?1:0;
|
||||
if (sensor == 4)
|
||||
if (sensor == 3)
|
||||
RELAY2 = (mymsg->data[0]=='1')?1:0;
|
||||
}
|
||||
}
|
||||
|
||||
void present_node(void) {
|
||||
present(NODE_SENSOR_ID, S_ARDUINO_NODE,"Nuvoton Relay Board");
|
||||
sendSketchInfo("Relay_Nuvoton", "1.1");
|
||||
present(1, S_DOOR, "IN1");
|
||||
present(2, S_DOOR, "IB2");
|
||||
present(3, S_BINARY, "Relay 1");
|
||||
present(4, S_BINARY, "Relay 2");
|
||||
present(NODE_SENSOR_ID, S_ARDUINO_NODE,"2.3.2");
|
||||
sendSketchInfo("Relay_Nuvoton", "1.2");
|
||||
present(0, S_DOOR, "IN1");
|
||||
present(1, S_DOOR, "IN2");
|
||||
present(2, S_BINARY, "Relay 1");
|
||||
present(3, S_BINARY, "Relay 2");
|
||||
registerNode();
|
||||
delay(20);
|
||||
send_state();
|
||||
}
|
||||
|
||||
void uart_loop() {
|
||||
|
|
@ -83,7 +104,7 @@ int main()
|
|||
uart_init(9600);
|
||||
|
||||
RS485_DIR = 0;
|
||||
P13_PushPull_Mode;
|
||||
P14_PushPull_Mode;
|
||||
|
||||
/* Relays */
|
||||
RELAY1 = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue