// // 标志物通信 - 交通灯(A/B) - ZigBee // #include "TrafficLightCommand.h" uint8_t TrafficLightCommand::RandomDisc() { randomSeed(micros()); return random(0x01, 0x04); } TrafficLightCommand::TrafficLightCommand() { SetDevice(CommandData::Devices::TrafficLight_A); } void TrafficLightCommand::UsingA() { SetDevice(CommandData::Devices::TrafficLight_A); } void TrafficLightCommand::UsingB() { SetDevice(CommandData::Devices::TrafficLight_B); } byte* TrafficLightCommand::CMD_EnterIdentifyMode() { SetCommand(0x01); return GetCommandArray(); } byte* TrafficLightCommand::CMD_CheckResult(Color color) { SetCommand(0x02, (byte)color); return GetCommandArray(); } byte* TrafficLightCommand::CMD_CheckRandomResult() { SetCommand(0x02, RandomDisc()); return GetCommandArray(); } bool TrafficLightCommand::IsTrafficLightCommand(byte* cmd) { if ((cmd[1] == CommandData::Devices::TrafficLight_A) || (cmd[1] == CommandData::Devices::TrafficLight_B)) return (cmd[2] == 0x01); return false; } bool TrafficLightCommand::ModeChangeSuccess(byte* cmd) { if (!IsTrafficLightCommand(cmd)) return false; return ((cmd[3] == 0x01) && (cmd[4] == 0x07)); }