diff --git a/2021_Arduino_Demo.ino b/2021_Arduino_Demo.ino index c8b26c8..af87b30 100644 --- a/2021_Arduino_Demo.ino +++ b/2021_Arduino_Demo.ino @@ -1,5 +1,14 @@ -#include +#include "AlarmTowerCommand.h" +#include "VoiceRepotCommand.h" +#include "GarageCommand.h" +#include "LEDDisplayCommand.h" +#include "CommandDecoder.h" +#include "ZigBeeOperator.h" +#include "BarrierCommand.h" +#include "CommandEncoder.h" +#include "ZigBeeOperator.h" #include "AccurateMotor.h" +#include "CommandDecoder.h" #include #include #include "GlobalDatas.h" @@ -7,7 +16,6 @@ #include #include #include -#include #include "Handler.h" #include #include @@ -18,7 +26,7 @@ void setup() CoreLED.Initialization(); CoreKEY.Initialization(); CoreBeep.Initialization(); - ExtSRAMInterface.Initialization(); + ZigBeeOperator.Initialization(); LED.Initialization(); BH1750.Initialization(); BEEP.Initialization(); @@ -31,6 +39,8 @@ void setup() sendflag = 0; frisrtime = 0; Tcount = 0; + + OpenMVOpt::Servo_Control(0); } void loop() @@ -40,12 +50,11 @@ void loop() CoreKEY.Kwhile(Handler::KEY_Handler); //按键检测 - if (ExtSRAMInterface.ExMem_Read(0x6100) != 0x00) //从车接收ZigBee数据 + if (ExtSRAMInterface.ExMem_Read(ZigBee_Read_Address) != 0x00) //从车接收ZigBee数据 { ExtSRAMInterface.ExMem_Read_Bytes(ZigBee_command, 8); - ZigBee_judge = ZigBee_command[6]; //获取校验和 - Command.Judgment(ZigBee_command); //计算校验和 - if ((ZigBee_judge == ZigBee_command[6]) && (ZigBee_command[0] == 0x55) && (ZigBee_command[7] == 0xBB)) + CommandDecoder decoder(ZigBee_command); + if(decoder.CommandValidate()) Handler::ZigBeeRx_Handler(ZigBee_command); //ZigBee接收数据处理 } diff --git a/2021_Arduino_Demo.vcxproj b/2021_Arduino_Demo.vcxproj index a1639d7..5848cce 100644 --- a/2021_Arduino_Demo.vcxproj +++ b/2021_Arduino_Demo.vcxproj @@ -76,7 +76,7 @@ __AVR_atmega2560__;__AVR_ATmega2560__;F_CPU=16000000L;ARDUINO=108010;ARDUINO_AVR_MEGA2560;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions) stdcpp17 stdc11 - $(ProjectDir)..\Arduino;G:\Users\15819\Documents\Arduino\libraries\ExtSRAMInterface;G:\Users\15819\Documents\Arduino\libraries\DCMotor;G:\Users\15819\Documents\Arduino\libraries\MsTimer2;G:\Users\15819\Documents\Arduino\libraries\Ultrasonic;G:\Users\15819\Documents\Arduino\libraries\BKRC_Voice;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src;G:\Users\15819\Documents\Arduino\libraries\CoreBeep;G:\Users\15819\Documents\Arduino\libraries\CoreKEY;G:\Users\15819\Documents\Arduino\libraries\CoreLED;G:\Users\15819\Documents\Arduino\libraries\Command;G:\Users\15819\Documents\Arduino\libraries\Infrares;G:\Users\15819\Documents\Arduino\libraries\BEEP;G:\Users\15819\Documents\Arduino\libraries\LED;G:\Users\15819\Documents\Arduino\libraries\BH1750;G:\Users\15819\Documents\Arduino\libraries\Metro;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src\utility;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino;$(ProjectDir)..\..\..\RACECA~1\SUBCAR~1\Arduino;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include-fixed;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Arduino;G:\Users\15819\Documents\Arduino\libraries\ExtSRAMInterface;G:\Users\15819\Documents\Arduino\libraries\DCMotor;G:\Users\15819\Documents\Arduino\libraries\MsTimer2;G:\Users\15819\Documents\Arduino\libraries\Ultrasonic;G:\Users\15819\Documents\Arduino\libraries\BKRC_Voice;G:\Users\15819\Documents\Arduino\libraries\CoreBeep;G:\Users\15819\Documents\Arduino\libraries\CoreKEY;G:\Users\15819\Documents\Arduino\libraries\CoreLED;G:\Users\15819\Documents\Arduino\libraries\Command;G:\Users\15819\Documents\Arduino\libraries\Infrares;G:\Users\15819\Documents\Arduino\libraries\BEEP;G:\Users\15819\Documents\Arduino\libraries\LED;G:\Users\15819\Documents\Arduino\libraries\BH1750;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src;G:\Users\15819\Documents\Arduino\libraries\Metro;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega;C:\Users\15819\AppData\Local\arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\\lib\gcc\avr\7.3.0\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include-fixed;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.2\include;C:\Users\15819\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories) true @@ -106,19 +106,33 @@ + + + + + + + + + + + + + + VisualMicroDebugger diff --git a/2021_Arduino_Demo.vcxproj.filters b/2021_Arduino_Demo.vcxproj.filters index e7ff4b8..d5953a4 100644 --- a/2021_Arduino_Demo.vcxproj.filters +++ b/2021_Arduino_Demo.vcxproj.filters @@ -39,6 +39,27 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -56,5 +77,26 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/AccurateMotor.cpp b/AccurateMotor.cpp index f99be02..1620502 100644 --- a/AccurateMotor.cpp +++ b/AccurateMotor.cpp @@ -21,7 +21,7 @@ void AccurateMotorClass::TurnLeft(uint8_t degree) return; DCMotor.TurnLeft(car_speed, car_speed); SetCarRunning(); - MsTimer2::set(degree * 50, []() + MsTimer2::set(degree * turn_multplyer, []() { { DCMotor.Stop(); @@ -45,7 +45,7 @@ void AccurateMotorClass::TurnRight(uint8_t degree) return; DCMotor.TurnRight(car_speed, car_speed); SetCarRunning(); - MsTimer2::set(degree * 50, []() + MsTimer2::set(degree * turn_multplyer, []() { { DCMotor.Stop(); @@ -62,7 +62,7 @@ void AccurateMotorClass::RunForward(uint8_t distence) return; DCMotor.Go(car_speed); SetCarRunning(); - MsTimer2::set(distence * 100, []() + MsTimer2::set(distence * run_multplyer, []() { { DCMotor.Stop(); @@ -90,7 +90,7 @@ void AccurateMotorClass::RunBackward(uint8_t distence) return; DCMotor.Back(car_speed); SetCarRunning(); - MsTimer2::set(distence * 100, []() + MsTimer2::set(distence * run_multplyer, []() { { DCMotor.Stop(); diff --git a/AccurateMotor.h b/AccurateMotor.h index a62c99b..4d54fa7 100644 --- a/AccurateMotor.h +++ b/AccurateMotor.h @@ -19,7 +19,9 @@ class AccurateMotorClass { private: bool car_running; - const uint8_t car_speed = 100; + const uint8_t car_speed = 50; + const uint8_t turn_multplyer = 13; + const uint8_t run_multplyer = 100; private: static void SetCarRunning(); diff --git a/AlarmTowerCommand.cpp b/AlarmTowerCommand.cpp new file mode 100644 index 0000000..fde146c --- /dev/null +++ b/AlarmTowerCommand.cpp @@ -0,0 +1,52 @@ +// +// ־ͨ - ̨ - ZigBee/IR +// + +#include "AlarmTowerCommand.h" + +AlarmTowerCommand::AlarmTowerCommand() +{ + SetDevice(CommandData::Devices::AlarmTower); +} + +byte* AlarmTowerCommand::CMD_DefaultIRAlarm() +{ + SetCommand(0x03, 0x05, 0x14, 0x45, 0xDE, 0x92); + return GetIRCommandArray(); +} + +byte* AlarmTowerCommand::CMD_IRAlarm(byte d1, byte d2, byte d3, byte d4, byte d5, byte d6) +{ + SetCommand(d1, d2, d3, d4, d5, d6); + return GetIRCommandArray(); +} + +byte* AlarmTowerCommand::CMD_ChangeOpenCode_1to3(byte d1, byte d2, byte d3) +{ + SetCommand(0x10, d1, d2, d3); + return GetCommandArray(); +} + +byte* AlarmTowerCommand::CMD_ChangeOpenCode_4to6(byte d4, byte d5, byte d6) +{ + SetCommand(0x11, d4, d5, d6); + return GetCommandArray(); +} + +byte* AlarmTowerCommand::CMD_QueryRescuePosition() +{ + SetCommand(0x09); + return GetCommandArray(); +} + +bool AlarmTowerCommand::IsAlarmTowerCommand(byte* cmd) +{ + return ((cmd[1] == CommandData::Devices::AlarmTower) && (cmd[2] == 0x01)); +} + +byte AlarmTowerCommand::ReadRescuePosition(byte* cmd) +{ + if (!IsAlarmTowerCommand(cmd)) + return 0xFF; + return cmd[3]; +} diff --git a/AlarmTowerCommand.h b/AlarmTowerCommand.h new file mode 100644 index 0000000..fcfce47 --- /dev/null +++ b/AlarmTowerCommand.h @@ -0,0 +1,30 @@ +// AlarmTowerCommand.h + +#ifndef _ALARMTOWERCOMMAND_h +#define _ALARMTOWERCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class AlarmTowerCommand : private CommandEncoder +{ +public: + AlarmTowerCommand(); +public: + byte* CMD_DefaultIRAlarm(); + byte* CMD_IRAlarm(byte d1, byte d2, byte d3, byte d4, byte d5, byte d6); + byte* CMD_ChangeOpenCode_1to3(byte d1, byte d2, byte d3); + byte* CMD_ChangeOpenCode_4to6(byte d4, byte d5, byte d6); + byte* CMD_QueryRescuePosition(); +public: + bool IsAlarmTowerCommand(byte* cmd); + byte ReadRescuePosition(byte* cmd); +}; + +#endif + diff --git a/BarrierCommand.cpp b/BarrierCommand.cpp new file mode 100644 index 0000000..a86194b --- /dev/null +++ b/BarrierCommand.cpp @@ -0,0 +1,52 @@ +// +// ־ͨ - բ - ZigBee +// + +#include "BarrierCommand.h" + +BarrierCommand::BarrierCommand() +{ + SetDevice(CommandData::Devices::Barrier); +} + +byte* BarrierCommand::CMD_GateOn() +{ + SetCommand(0x01, 0x01); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_GateOff() +{ + SetCommand(0x01, 0x02); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_GateUp() +{ + SetCommand(0x09, 0x01); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_GateDown() +{ + SetCommand(0x09, 0x02); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_RequireStatus() +{ + SetCommand(0x20, 0x01); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_CarLicense_1to3(byte _1, byte _2, byte _3) +{ + SetCommand(0x10, _1, _2, _3); + return GetCommandArray(); +} + +byte* BarrierCommand::CMD_CarLicense_4to6(byte _4, byte _5, byte _6) +{ + SetCommand(0x11, _4, _5, _6); + return GetCommandArray(); +} diff --git a/BarrierCommand.h b/BarrierCommand.h new file mode 100644 index 0000000..35c050b --- /dev/null +++ b/BarrierCommand.h @@ -0,0 +1,29 @@ +// BarrierCommand.h + +#ifndef _BARRIERCOMMAND_h +#define _BARRIERCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class BarrierCommand : private CommandEncoder +{ +public: + BarrierCommand(); +public: + byte* CMD_GateOn(); + byte* CMD_GateOff(); + byte* CMD_GateUp(); + byte* CMD_GateDown(); + byte* CMD_RequireStatus(); + byte* CMD_CarLicense_1to3(byte _1, byte _2, byte _3); + byte* CMD_CarLicense_4to6(byte _4, byte _5, byte _6); +}; + +#endif + diff --git a/CommandDecoder.cpp b/CommandDecoder.cpp new file mode 100644 index 0000000..2ea6b4f --- /dev/null +++ b/CommandDecoder.cpp @@ -0,0 +1,53 @@ +// +// +// + +#include "CommandDecoder.h" + +byte CommandDecoder::_CheckSUM(byte main, byte data1, byte data2, byte data3) +{ + return ((byte)((main + data1 + data2 + data3) % 0xFF)); +} + +CommandDecoder::CommandDecoder() +{ +} + +CommandDecoder::CommandDecoder(byte* arr) +{ + cmd[0] = arr[0]; + cmd[1] = arr[1]; + cmd[2] = arr[2]; + cmd[3] = arr[3]; + cmd[4] = arr[4]; + cmd[5] = arr[5]; + cmd[6] = arr[6]; + cmd[7] = arr[7]; +} + +bool CommandDecoder::CommandValidate() +{ + if ((cmd[0] != CommandData::FrameHead) || (cmd[7] != CommandData::FrameEnd)) + return false; + byte checksum = _CheckSUM(cmd[2], cmd[3], cmd[4], cmd[5]); + if (cmd[6] != checksum) + return false; + return true; +} + +byte CommandDecoder::GetDevice() +{ + return cmd[1]; +} + +byte CommandDecoder::GetMainCommand() +{ + return cmd[2]; +} + +byte CommandDecoder::GetDataBit(byte num) +{ + if ((num < 1) || (num > 3)) + return -1; + return cmd[2 + num]; +} diff --git a/CommandDecoder.h b/CommandDecoder.h new file mode 100644 index 0000000..1e9811f --- /dev/null +++ b/CommandDecoder.h @@ -0,0 +1,33 @@ +// CommandDecoder.h + +#ifndef _COMMANDDECODER_h +#define _COMMANDDECODER_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "GlobalDatas.h" + +class CommandDecoder +{ +private: + byte cmd[8] = { 0 }; +private: + byte _CheckSUM(byte main, byte data1, byte data2, byte data3); +public: + CommandDecoder(); + CommandDecoder(byte* arr); + CommandDecoder(const CommandDecoder& obj) = delete; +public: + bool CommandValidate(); +public: + byte GetDevice(); + byte GetMainCommand(); + byte GetDataBit(byte num); //1 - 3 +}; + +#endif + diff --git a/CommandEncoder.cpp b/CommandEncoder.cpp new file mode 100644 index 0000000..eb88e94 --- /dev/null +++ b/CommandEncoder.cpp @@ -0,0 +1,75 @@ +#include "CommandEncoder.h" + +byte CommandEncoder::CheckSUM(byte main, byte data1, byte data2, byte data3) +{ + uint16_t sum = ((uint16_t)main + (uint16_t)data1 + (uint16_t)data2 + (uint16_t)data3); + return ((byte)(sum % 256)); +} + +CommandEncoder::CommandEncoder() +{ + cmd[0] = CommandData::FrameHead; + cmd[7] = CommandData::FrameEnd; +} + +CommandEncoder::CommandEncoder(byte ir1, byte ir2, byte ir3, byte ir4, byte ir5, byte ir6) +{ + ir_cmd[0] = ir1; + ir_cmd[1] = ir2; + ir_cmd[2] = ir3; + ir_cmd[3] = ir4; + ir_cmd[4] = ir5; + ir_cmd[5] = ir6; +} + +CommandEncoder::CommandEncoder(byte device, byte main, byte data1, byte data2, byte data3) +{ + cmd[0] = CommandData::FrameHead; + cmd[1] = device; + cmd[2] = main; + cmd[3] = data1; + cmd[4] = data2; + cmd[5] = data3; + cmd[6] = CheckSUM(main, data1, data2, data3); + cmd[7] = CommandData::FrameEnd; +} + +void CommandEncoder::SetDevice(byte device) +{ + cmd[1] = device; +} + +void CommandEncoder::OverrideFrameHead(byte h1, byte h2) +{ + cmd[0] = h1; + cmd[1] = h2; +} + +void CommandEncoder::SetCommand(byte ir1, byte ir2, byte ir3, byte ir4, byte ir5, byte ir6) +{ + ir_cmd[0] = ir1; + ir_cmd[1] = ir2; + ir_cmd[2] = ir3; + ir_cmd[3] = ir4; + ir_cmd[4] = ir5; + ir_cmd[5] = ir6; +} + +void CommandEncoder::SetCommand(byte main, byte data1, byte data2, byte data3) +{ + cmd[2] = main; + cmd[3] = data1; + cmd[4] = data2; + cmd[5] = data3; + cmd[6] = CheckSUM(main, data1, data2, data3); +} + +byte* CommandEncoder::GetCommandArray() +{ + return cmd; +} + +byte* CommandEncoder::GetIRCommandArray() +{ + return ir_cmd; +} diff --git a/CommandEncoder.h b/CommandEncoder.h new file mode 100644 index 0000000..3ca0e86 --- /dev/null +++ b/CommandEncoder.h @@ -0,0 +1,34 @@ +// CommandEncoder.h + +#ifndef _COMMANDENCODER_h +#define _COMMANDENCODER_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif +#include "GlobalDatas.h" + +class CommandEncoder +{ +private: + byte cmd[8]; + byte ir_cmd[6]; +private: + byte CheckSUM(byte main, byte data1, byte data2, byte data3); +public: + CommandEncoder(); + CommandEncoder(const CommandEncoder& obj) = delete; + CommandEncoder(byte ir1, byte ir2, byte ir3, byte ir4, byte ir5, byte ir6); + CommandEncoder(byte device, byte main = 0x00, byte data1 = 0x00, byte data2 = 0x00, byte data3 = 0x00); +public: + void SetDevice(byte device); + void OverrideFrameHead(byte h1, byte h2); + void SetCommand(byte ir1, byte ir2, byte ir3, byte ir4, byte ir5, byte ir6); + void SetCommand(byte main, byte data1 = 0x00, byte data2 = 0x00, byte data3 = 0x00); + byte* GetCommandArray(); + byte* GetIRCommandArray(); +}; + +#endif diff --git a/DebugOpt.cpp b/DebugOpt.cpp index 01185a8..e43508e 100644 --- a/DebugOpt.cpp +++ b/DebugOpt.cpp @@ -1,13 +1,12 @@ #include "DebugOpt.h" uint8_t DebugOpt::led_flow_cnt = 0; -uint8_t DebugOpt::open_road_buf[8] = { 0x55,0x03,0x01,0x01,0x00,0x00,0x00,0xBB }; -uint8_t DebugOpt::voive_test_buf[9] = { 0xFD,0x00,0x06,0x01,0x01,0xC4,0xFA,0xBA,0xC3 }; -uint8_t DebugOpt::voice_trm_buf[8] = { 0xAF,0x06,0x00,0x02,0x00,0x00,0x01,0xBB }; -uint8_t DebugOpt::ir_repo_buf[6] = { 0x03,0x05,0x14,0x45,0xDE,0x92 }; +bool DebugOpt::led_flow_switch = true; void DebugOpt::DoLEDFlow() { + if (!led_flow_switch) + return; switch (led_flow_cnt) { case 0: @@ -16,9 +15,6 @@ void DebugOpt::DoLEDFlow() CoreLED.TurnOff(LED3); CoreLED.TurnOff(LED4); - LED.LeftTurnOn(); - LED.RightTurnOff(); - digitalWrite(LED_BUILTIN, HIGH); break; case 1: @@ -27,9 +23,6 @@ void DebugOpt::DoLEDFlow() CoreLED.TurnOff(LED3); CoreLED.TurnOff(LED4); - LED.LeftTurnOff(); - LED.RightTurnOn(); - digitalWrite(LED_BUILTIN, LOW); break; case 2: @@ -38,9 +31,6 @@ void DebugOpt::DoLEDFlow() CoreLED.TurnOn(LED3); CoreLED.TurnOff(LED4); - LED.LeftTurnOn(); - LED.RightTurnOff(); - digitalWrite(LED_BUILTIN, LOW); break; case 3: @@ -49,41 +39,33 @@ void DebugOpt::DoLEDFlow() CoreLED.TurnOff(LED3); CoreLED.TurnOn(LED4); - LED.LeftTurnOff(); - LED.RightTurnOn(); - digitalWrite(LED_BUILTIN, LOW); break; } led_flow_cnt++; if (led_flow_cnt >= 4) led_flow_cnt = 0; - delay(200); + delay(10); } void DebugOpt::DebugRun() { - Serial.println("Hello Accurate DCMotor."); LED.LeftTurnOn(); LED.RightTurnOn(); BEEP.TurnOn(); delay(100); BEEP.TurnOff(); - /*DCMotor.Go(100, 100); - DCMotor.Stop(); - DCMotor.Back(100, 100); - DCMotor.Stop(); - DCMotor.TurnLeft_Code(200, 100); - DCMotor.Stop(); - DCMotor.TurnRight_Code(200, 100); - DCMotor.Stop();*/ - AccurateMotor.RunForward(10); + /*AccurateMotor.RunForward(10); AccurateMotor.DelayUntilCarStop(); AccurateMotor.RunBackward(10); AccurateMotor.DelayUntilCarStop(); AccurateMotor.TurnLeft(20); AccurateMotor.DelayUntilCarStop(); AccurateMotor.TurnRight(20); + AccurateMotor.DelayUntilCarStop();*/ + AccurateMotor.TurnRight(180); + AccurateMotor.DelayUntilCarStop(); + AccurateMotor.RunForward(10); AccurateMotor.DelayUntilCarStop(); BEEP.TurnOn(); delay(100); @@ -94,7 +76,6 @@ void DebugOpt::DebugRun() void DebugOpt::DebugServo() { - Serial.println("Hello Servo."); for (int i = -80; i <= 20; i++) { OpenMVOpt::Servo_Control(i); @@ -103,15 +84,25 @@ void DebugOpt::DebugServo() OpenMVOpt::Servo_Control(0); } +void DebugOpt::LEDFlowOn() +{ + led_flow_switch = true; +} + +void DebugOpt::LEDFlowOff() +{ + led_flow_switch = false; +} + void DebugOpt::Road_Gate_Test() { - Command.Judgment(open_road_buf); //У - ExtSRAMInterface.ExMem_Write_Bytes(0x6008, open_road_buf, 8); + BarrierCommand b_cmd; + ZigBeeOperator.SendCommand(b_cmd.CMD_GateDown()); } void DebugOpt::Speech_Sounds_Ctr() { - ExtSRAMInterface.ExMem_Write_Bytes(0x6180, voive_test_buf, 13); + //ExtSRAMInterface.ExMem_Write_Bytes(0x6180, voive_test_buf, 13); } void DebugOpt::Speech_Disc() @@ -123,11 +114,11 @@ void DebugOpt::Speech_Disc() delay(200); Serial.print("ʶ𵽵ĴIDΪ"); Serial.println(sph_id, HEX); - voice_trm_buf[2] = sph_id; - ExtSRAMInterface.ExMem_Write_Bytes(0x6008, voice_trm_buf, 8);//ϴʶն + //voice_trm_buf[2] = sph_id; + //ExtSRAMInterface.ExMem_Write_Bytes(0x6008, voice_trm_buf, 8);//ϴʶն } void DebugOpt::Infrared_Test() { - Infrare.Transmition(ir_repo_buf, 6); + //Infrare.Transmition(ir_repo_buf, 6); } diff --git a/DebugOpt.h b/DebugOpt.h index a7fc883..eedf8f7 100644 --- a/DebugOpt.h +++ b/DebugOpt.h @@ -1,14 +1,18 @@ #ifndef __DEBUG_OPT__ #define __DEBUG_OPT_ -#include +#include "VoiceRepotCommand.h" +#include "LEDDisplayCommand.h" +#include "AlarmTowerCommand.h" +#include "BarrierCommand.h" +#include "ZigBeeOperator.h" +#include "GarageCommand.h" #include "AccurateMotor.h" #include "GlobalDatas.h" #include #include "OpenMVOpt.h" #include #include -#include #include #include @@ -16,17 +20,12 @@ namespace DebugOpt { //LEDˮƼ extern uint8_t led_flow_cnt; - //բָ - extern uint8_t open_road_buf[8]; - //ָ - extern uint8_t voive_test_buf[9]; - //ʶָ - extern uint8_t voice_trm_buf[8]; - //ָ - extern uint8_t ir_repo_buf[6]; + extern bool led_flow_switch; //LEDˮ void DoLEDFlow(); + void LEDFlowOn(); + void LEDFlowOff(); //в void DebugRun(); diff --git a/GarageCommand.cpp b/GarageCommand.cpp new file mode 100644 index 0000000..1173c9b --- /dev/null +++ b/GarageCommand.cpp @@ -0,0 +1,92 @@ +// +// ־ͨ - ⣨A/B - ZigBee +// + +#include "GarageCommand.h" + +GarageCommand::GarageCommand() +{ + SetDevice(CommandData::Devices::Garage_A); +} + +void GarageCommand::UsingA() +{ + SetDevice(CommandData::Devices::Garage_A); +} + +void GarageCommand::UsingB() +{ + SetDevice(CommandData::Devices::Garage_B); +} + +byte* GarageCommand::CMD_PositionReset() +{ + SetCommand(0x01, 0x01); + return GetCommandArray(); +} + +byte* GarageCommand::CMD_SetToFloor2() +{ + SetCommand(0x01, 0x02); + return GetCommandArray(); +} + +byte* GarageCommand::CMD_SetToFloor3() +{ + SetCommand(0x01, 0x03); + return GetCommandArray(); +} + +byte* GarageCommand::CMD_SetToFloor4() +{ + SetCommand(0x01, 0x04); + return GetCommandArray(); +} + +byte* GarageCommand::CMD_QueryCurrentPos() +{ + SetCommand(0x02, 0x01); + return GetCommandArray(); +} + +byte* GarageCommand::CMD_QueryIRStatus() +{ + SetCommand(0x02, 0x02); + return GetCommandArray(); +} + +bool GarageCommand::IsGarageCommand(byte* data) +{ + if ((data[1] == CommandData::Devices::Garage_A) || (data[1] == CommandData::Devices::Garage_B)) + return (data[2] == ReturnMainCommand); + return false; +} + +bool GarageCommand::IsPositionData(byte* data) +{ + if (!IsGarageCommand(data)) + return false; + return (data[3] == 0x01); +} + +bool GarageCommand::IsIRData(byte* data) +{ + if (!IsGarageCommand(data)) + return false; + return (data[3] == 0x02); +} + +byte GarageCommand::CurrentPos(byte* data) +{ + return data[4]; +} + +bool GarageCommand::FrontIRTiggered(byte* data) +{ + return (data[4] == 0x01); +} + +bool GarageCommand::BackIRTiggered(byte* data) +{ + return (data[5] == 0x01); +} diff --git a/GarageCommand.h b/GarageCommand.h new file mode 100644 index 0000000..7a19313 --- /dev/null +++ b/GarageCommand.h @@ -0,0 +1,41 @@ +// GarageCommand.h + +#ifndef _GARAGECOMMAND_h +#define _GARAGECOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class GarageCommand : private CommandEncoder +{ +public: + const byte ReturnMainCommand = 0x03; +public: + GarageCommand(); +public: + void UsingA(); + void UsingB(); +public: + byte* CMD_PositionReset(); + byte* CMD_SetToFloor2(); + byte* CMD_SetToFloor3(); + byte* CMD_SetToFloor4(); + byte* CMD_QueryCurrentPos(); + byte* CMD_QueryIRStatus(); +public: + //ҪʹCommandDecoderָϷУ + bool IsGarageCommand(byte* data); + bool IsPositionData(byte* data); + bool IsIRData(byte* data); + byte CurrentPos(byte* data); + bool FrontIRTiggered(byte* data); + bool BackIRTiggered(byte* data); +}; + +#endif + diff --git a/GlobalDatas.cpp b/GlobalDatas.cpp index 2324a33..40bd89c 100644 --- a/GlobalDatas.cpp +++ b/GlobalDatas.cpp @@ -1,24 +1,5 @@ #include "GlobalDatas.h" -uint8_t GarageB_To1[8] = { 0x55,0x05,0x01,0x01,0x00,0x00,0x02,0xBB }; // 峵B һ -uint8_t GarageB_To2[8] = { 0x55,0x05,0x01,0x02,0x00,0x00,0x03,0xBB }; // 峵B ڶ -uint8_t GarageB_To3[8] = { 0x55,0x05,0x01,0x03,0x00,0x00,0x04,0xBB }; // 峵B -uint8_t GarageB_To4[8] = { 0x55,0x05,0x01,0x04,0x00,0x00,0x05,0xBB }; // 峵B IJ - -uint8_t TrafficA_Open[8] = { 0x55,0x0E,0x01,0x00,0x00,0x00,0x01,0xBB }; // ܽͨA ʶģʽ ʶģʽ -uint8_t TrafficA_Red[8] = { 0x55,0x0E,0x02,0x01,0x00,0x00,0x03,0xBB }; // ܽͨA ʶΪɫȷ -uint8_t TrafficA_Green[8] = { 0x55,0x0E,0x02,0x02,0x00,0x00,0x04,0xBB }; // ܽͨA ʶΪɫȷ -uint8_t TrafficA_Yellow[8] = { 0x55,0x0E,0x02,0x03,0x00,0x00,0x05,0xBB }; // ܽͨA ʶΪɫȷ - -uint8_t Gate_Open[8] = { 0x55,0x03,0x01,0x01,0x00,0x00,0x02,0xBB }; // բ - -uint8_t Light_plus1[4] = { 0x00,0xFF,0x0C,~(0x0C) }; // · Դλ1 -uint8_t Light_plus2[4] = { 0x00,0xFF,0x18,~(0x18) }; // · Դλ2 -uint8_t Light_plus3[4] = { 0x00,0xFF,0x5E,~(0x5E) }; // · Դλ3 - -uint8_t SEG_TimOpen[8] = { 0x55,0x04,0x03,0x01,0x00,0x00,0x04,0xBB }; // LEDʾ ʱ -uint8_t SMG_TimClose[8] = { 0x55,0x04,0x03,0x00,0x00,0x00,0x03,0xBB }; // LEDʾ ʱر - uint8_t ZigBee_back[16] = { 0x55, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t qrdi_buf[8] = { 0x55,0x02,0x92,0x00,0x00,0x00,0x00,0xBB }; // OpenMVʶά @@ -38,4 +19,17 @@ unsigned long Tcount; uint8_t Data_Type; uint8_t Data_Flag; uint8_t Data_Length; -uint8_t Data_OTABuf[40]; \ No newline at end of file +uint8_t Data_OTABuf[40]; + +void DataTool::PrintDataArray(uint8_t* arr, uint8_t len) +{ + Serial.println("------Data Array------"); + for (uint8_t i = 0; i < len; i++) + { + Serial.print("arr["); + Serial.print(i); + Serial.print("] = 0x"); + Serial.println(arr[i], HEX); + } + Serial.println("------Array End------"); +} diff --git a/GlobalDatas.h b/GlobalDatas.h index 25126b0..493371f 100644 --- a/GlobalDatas.h +++ b/GlobalDatas.h @@ -1,28 +1,47 @@ #ifndef __GLOBAL_DATAS__ #define __GLOBAL_DATAS__ -#include +#include "arduino.h" #define TSendCycle 200 #define ATM_Data_Length 48 +#define ZigBee_Read_Address 0x6100 -extern uint8_t GarageB_To1[8]; // 峵B һ -extern uint8_t GarageB_To2[8]; // 峵B ڶ -extern uint8_t GarageB_To3[8]; // 峵B -extern uint8_t GarageB_To4[8]; // 峵B IJ +typedef uint8_t byte; -extern uint8_t TrafficA_Open[8]; // ܽͨA ʶģʽ ʶģʽ -extern uint8_t TrafficA_Red[8]; // ܽͨA ʶΪɫȷ -extern uint8_t TrafficA_Green[8]; // ܽͨA ʶΪɫȷ -extern uint8_t TrafficA_Yellow[8]; // ܽͨA ʶΪɫȷ +namespace CommandData +{ + const byte FrameHead = 0x55; + const byte FrameEnd = 0xBB; + const byte CustomVoiceFrameHead = 0xFD; -extern uint8_t Gate_Open[8]; // բ + namespace Devices + { + const byte Barrier = 0x03; + const byte LED_Display = 0x04; + const byte Garage_A = 0x0D; + const byte Garage_B = 0x05; + const byte VoiceReport = 0x06; + const byte AlarmTower = 0x07; + const byte TFT_A = 0x0B; + const byte TFT_B = 0x08; + const byte RodeLight_1 = 0x00; + const byte RodeLight_2 = 0xFF; + const byte WirelessCharger = 0x0A; + const byte ETC = 0x0C; + const byte TrafficLight_A = 0x0E; + const byte TrafficLight_B = 0x0F; + const byte SpecTerrain = 0x10; + const byte _3D_Display = 0x11; + const byte AutoMarkSystem_1 = 0xAF; + const byte AutoMarkSystem_2 = 0x06; + const byte MainCar = 0x02; + }; +}; -extern uint8_t Light_plus1[4]; // · Դλ1 -extern uint8_t Light_plus2[4]; // · Դλ2 -extern uint8_t Light_plus3[4]; // · Դλ3 - -extern uint8_t SEG_TimOpen[8]; // LEDʾ ʱ -extern uint8_t SMG_TimClose[8]; // LEDʾ ʱر +namespace DataTool +{ + void PrintDataArray(uint8_t* arr, uint8_t len); +}; extern uint8_t ZigBee_back[16]; diff --git a/Handler.cpp b/Handler.cpp index 605f8ce..2da5eaa 100644 --- a/Handler.cpp +++ b/Handler.cpp @@ -2,36 +2,84 @@ void Handler::ZigBeeRx_Handler(uint8_t* mar) { - switch (mar[1]) + CommandDecoder decoder(mar); + switch (decoder.GetDevice()) { - case 0x02: // + case CommandData::Devices::MainCar: // MainCarRx_Handler(mar); //Ӧ break; - case 0x03: //բ־ + case CommandData::Devices::Barrier: //բ־ + DataTool::PrintDataArray(mar, 8); break; - case 0x04: //LEDʾ־޷أ + case CommandData::Devices::LED_Display: //LEDʾ־޷أ break; - case 0x05: //峵־B - break; - case 0x06: //־ + case CommandData::Devices::Garage_B: //峵־B + { + GarageCommand cmd; + if (cmd.IsPositionData(mar)) + { + Serial.print("Garage at: "); + Serial.println(cmd.CurrentPos(mar)); + } + if (cmd.IsIRData(mar)) + { + Serial.print("Front IR: "); + Serial.println(cmd.FrontIRTiggered(mar) ? "Triggered" : "Not Triggered"); + Serial.print("Back IR: "); + Serial.println(cmd.BackIRTiggered(mar) ? "Triggered" : "Not Triggered"); + } break; - case 0x07: //ⱨ־ + } + case CommandData::Devices::VoiceReport: //־ + { + VoiceReportCommand cmd; + uint16_t y; + byte m, d, h, mm, s; + if (cmd.ReadRTCDate(mar, y, m, d)) + { + Serial.print(y); + Serial.print("-"); + Serial.print(m); + Serial.print("-"); + Serial.println(d); + } + else + Serial.println("Invalidate Date"); + if (cmd.ReadRTCTime(mar, h, mm, s)) + { + Serial.print(h); + Serial.print(":"); + Serial.print(mm); + Serial.print(":"); + Serial.println(s); + } + else + Serial.println("Invalidate Time"); break; - case 0x08: //TFTʾ־B + } + case CommandData::Devices::AlarmTower: //ⱨ־ + { + AlarmTowerCommand cmd; + if (cmd.IsAlarmTowerCommand(mar)) + { + Serial.print("Rescue Position: "); + Serial.println(cmd.ReadRescuePosition(mar), HEX); + } break; - case 0x09: //־ + } + case CommandData::Devices::TFT_B: //TFTʾ־B break; - case 0x0A: //߳־ + case CommandData::Devices::WirelessCharger: //߳־ break; - case 0x0B: //TFTʾ־A + case CommandData::Devices::TFT_A: //TFTʾ־A break; - case 0x0C: //ETCϵͳ־ + case CommandData::Devices::ETC: //ETCϵͳ־ break; - case 0x0D: //峵־A + case CommandData::Devices::Garage_A: //峵־A break; - case 0x0E: //ͨƱעA + case CommandData::Devices::TrafficLight_A: //ͨƱעA break; - case 0x0F: //ͨƱ־B + case CommandData::Devices::TrafficLight_B: //ͨƱ־B break; default: break; @@ -159,31 +207,28 @@ void Handler::MainCarRx_Handler(uint8_t* com) void Handler::Key_0() { - BEEP.TurnOn(); - delay(50); - BEEP.TurnOff(); - OpenMVOpt::Servo_Control(-60); - OpenMVOpt::OpenMV_Track(50); - DCMotor.TurnLeft_Code(80, 760); + AlarmTowerCommand cmd; + ZigBeeOperator.SendCommand(cmd.CMD_QueryRescuePosition()); } void Handler::Key_1() { - BEEP.TurnOn(); - delay(50); - BEEP.TurnOff(); - delay(50); - OpenMVOpt::Servo_Control(0); + AlarmTowerCommand cmd; + Infrare.Transmition(cmd.CMD_DefaultIRAlarm(), 6); } void Handler::Key_2() { - DebugOpt::DebugRun(); + LEDDisplayCommand cmd; + ZigBeeOperator.SendCommand(cmd.CMD_FirstLineDisplay(0x123456)); + delay(1000); + ZigBeeOperator.SendCommand(cmd.CMD_SecondLineDisplay(0x7890AB)); } void Handler::Key_3() { - DebugOpt::DebugServo(); + /*OpenMVOpt::Servo_Control(-60); + OpenMVOpt::OpenMV_Track(10);*/ } void Handler::KEY_Handler(uint8_t k_value) diff --git a/Handler.h b/Handler.h index b1daaab..7c841ae 100644 --- a/Handler.h +++ b/Handler.h @@ -1,6 +1,7 @@ #ifndef __HANDLER__ #define __HANDLER__ +#include "CommandDecoder.h" #include "GlobalDatas.h" #include "DebugOpt.h" diff --git a/LEDDisplayCommand.cpp b/LEDDisplayCommand.cpp new file mode 100644 index 0000000..e2d7477 --- /dev/null +++ b/LEDDisplayCommand.cpp @@ -0,0 +1,72 @@ +// +// ־ͨ - LEDʾ - ZigBee +// + +#include "LEDDisplayCommand.h" + +LEDDisplayCommand::LEDDisplayCommand() +{ + SetDevice(CommandData::Devices::LED_Display); +} + +byte* LEDDisplayCommand::CMD_StartTimer() +{ + SetCommand(0x03, 0x01); + return GetCommandArray(); +} + +byte* LEDDisplayCommand::CMD_StopTimer() +{ + SetCommand(0x03, 0x00); + return GetCommandArray(); +} + +byte* LEDDisplayCommand::CMD_ClearTimer() +{ + SetCommand(0x03, 0x02); + return GetCommandArray(); +} + +byte* LEDDisplayCommand::CMD_FirstLineDisplay(uint32_t num) +{ + if (num >= 0xFFFFFF) + SetCommand(0x01, 0xFF, 0xFF, 0xFF); + else + { + byte d1 = ((num > 0xFFFF) ? (num / 0x10000) : 0x00); + num -= (d1 * 0x10000); + byte d2 = ((num > 0xFF) ? (num / 0x100) : 0x00); + byte d3 = num % 0x100; + SetCommand(0x01, d1, d2, d3); + } + return GetCommandArray(); +} + +byte* LEDDisplayCommand::CMD_SecondLineDisplay(uint32_t num) +{ + if (num >= 0xFFFFFF) + SetCommand(0x02, 0xFF, 0xFF, 0xFF); + else + { + byte d1 = ((num > 0xFFFF) ? (num / 0x10000) : 0x00); + num -= (d1 * 0x10000); + byte d2 = ((num > 0xFF) ? (num / 0x100) : 0x00); + byte d3 = num % 0x100; + SetCommand(0x02, d1, d2, d3); + } + return GetCommandArray(); +} + +byte* LEDDisplayCommand::CMD_DisplayDistence(uint16_t dis) +{ + if (dis >= 0xFFF) + SetCommand(0x04, 0x00, 0x0F, 0xFF); + else + { + byte d1 = ((dis > 0xFF) ? (dis / 0x100) : 0x00); + dis -= (d1 * 0x100); + byte d2 = dis % 0x100; + SetCommand(0x04, 0x00, d1, d2); + } + return GetCommandArray(); +} diff --git a/LEDDisplayCommand.h b/LEDDisplayCommand.h new file mode 100644 index 0000000..dc90f23 --- /dev/null +++ b/LEDDisplayCommand.h @@ -0,0 +1,28 @@ +// LEDDisplayCommand.h + +#ifndef _LEDDISPLAYCOMMAND_h +#define _LEDDISPLAYCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class LEDDisplayCommand : private CommandEncoder +{ +public: + LEDDisplayCommand(); +public: + byte* CMD_StartTimer(); + byte* CMD_StopTimer(); + byte* CMD_ClearTimer(); + byte* CMD_FirstLineDisplay(uint32_t num); + byte* CMD_SecondLineDisplay(uint32_t num); + byte* CMD_DisplayDistence(uint16_t dis); +}; + +#endif + diff --git a/TFTCommand.cpp b/TFTCommand.cpp new file mode 100644 index 0000000..73b16bb --- /dev/null +++ b/TFTCommand.cpp @@ -0,0 +1,7 @@ +// +// ־ͨ - TFTA/B - ZigBee +// + +#include "TFTCommand.h" + + diff --git a/TFTCommand.h b/TFTCommand.h new file mode 100644 index 0000000..6420a55 --- /dev/null +++ b/TFTCommand.h @@ -0,0 +1,26 @@ +// TFTCommand.h + +#ifndef _TFTCOMMAND_h +#define _TFTCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +class TFTCommand : private CommandEncoder +{ +public: + TFTCommand(); +public: + void UsingA(); + void UsingB(); +public: + +}; + +#endif + diff --git a/VoiceRepotCommand.cpp b/VoiceRepotCommand.cpp new file mode 100644 index 0000000..3ae807f --- /dev/null +++ b/VoiceRepotCommand.cpp @@ -0,0 +1,110 @@ +// +// ־ͨ - - ZigBee +// + +#include "VoiceRepotCommand.h" + +VoiceReportCommand::VoiceReportCommand() +{ + SetDevice(CommandData::Devices::VoiceReport); +} + +byte* VoiceReportCommand::CMD_ReportSpecVoice(VoiceCmd type) +{ + SetCommand(0x10, (byte)type); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_ReportRandomVoice() +{ + SetCommand(0x20, 0x01); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_SetRTCStartDate(uint16_t year, byte month, byte day) +{ + byte two_bit_year = year - 2000; + SetCommand(0x30, two_bit_year, month, day); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_ReadRTCDate() +{ + SetCommand(0x31, 0x01); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_SetRTCStartTime(byte hour, byte minute, byte second) +{ + SetCommand(0x40, hour, minute, second); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_ReadRTCTime() +{ + SetCommand(0x41, 0x01); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_SetWeatherAndTemperature(WeatherCmd weather, byte temp) +{ + SetCommand(0x42, (byte)weather, temp); + return GetCommandArray(); +} + +byte* VoiceReportCommand::CMD_QueryWeatherAndTemperator() +{ + SetCommand(0x43); + return GetCommandArray(); +} + +bool VoiceReportCommand::IsVoiceCommand(byte* cmd) +{ + return ((cmd[1] == CommandData::Devices::VoiceReport) && (cmd[2] == RT_VoiceCommand)); +} + +bool VoiceReportCommand::IsVoiceAvailable(byte* cmd) +{ + if (!IsVoiceCommand(cmd)) + return false; + return (cmd[3] == 0x4F); +} + +bool VoiceReportCommand::ReadRTCDate(byte* cmd, uint16_t& year, byte& month, byte& day) +{ + if ((cmd[1] == CommandData::Devices::VoiceReport) && (cmd[2] == RT_DateCommand)) + { + year = 2000 + cmd[3]; + month = cmd[4]; + day = cmd[5]; + return true; + } + else + return false; +} + +bool VoiceReportCommand::ReadRTCTime(byte* cmd, byte& hour, byte& minute, byte& second) +{ + if ((cmd[1] == CommandData::Devices::VoiceReport) && (cmd[2] == RT_TimeCommand)) + { + hour = cmd[3]; + minute = cmd[4]; + second = cmd[5]; + return true; + } + else + return false; +} + +bool VoiceReportCommand::ReadWeatherAndTemperature(byte* cmd, WeatherCmd& weather, byte& temp) +{ + if ((cmd[1] == CommandData::Devices::VoiceReport) && (cmd[2] == RT_WeatherTempCommand)) + { + weather = (WeatherCmd)cmd[3]; + temp = cmd[4]; + return true; + } + else + return false; +} + diff --git a/VoiceRepotCommand.h b/VoiceRepotCommand.h new file mode 100644 index 0000000..3c3b0f2 --- /dev/null +++ b/VoiceRepotCommand.h @@ -0,0 +1,76 @@ +// VoiceRepotCommand.h + +#ifndef _VOICEREPOTCOMMAND_h +#define _VOICEREPOTCOMMAND_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include "CommandEncoder.h" + +/* +* ־ +* 1. ݵIJѯݲѯĽᱻصǴӳ +* 2. ϳɣӳZigBee8λУݵ´˹޷ʵ֡ +*/ + +class VoiceReportCommand : private CommandEncoder +{ +private: + const byte RT_VoiceCommand = 0x01; + const byte RT_DateCommand = 0x02; + const byte RT_TimeCommand = 0x03; + const byte RT_WeatherTempCommand = 0x04; +public: + enum class VoiceCmd + { + Fu_Qiang_Lu_Zhan = 0x00, //ǿ·վ + Min_Zhu_Lu_Zhan = 0x01, //·վ + Wen_Ming_Lu_Zhan = 0x02, //·վ + He_Xie_Lu_Zhan = 0x03, //г·վ + Ai_Guo_Lu_Zhan = 0x04, //·վ + Jing_Ye_Lu_Zhan = 0x05, //ҵ·վ + You_Shan_Lu_Zhan = 0x06 //·վ + }; + + enum class WeatherCmd + { + Wind = 0x00, // + Cloudy = 0x01, // + Sunny = 0x02, // + Snow = 0x03, //Сѩ + Rain = 0x04, //С + Overcast = 0x05 // + }; + + enum class TextEncoding + { + GB2312 = 0x00, + GBK = 0x01, + BIG5 = 0x02, + Unicode = 0x03 + }; +public: + VoiceReportCommand(); +public: + byte* CMD_ReportSpecVoice(VoiceCmd type); + byte* CMD_ReportRandomVoice(); + byte* CMD_SetRTCStartDate(uint16_t year, byte month, byte day); + byte* CMD_ReadRTCDate(); + byte* CMD_SetRTCStartTime(byte hour, byte minute, byte second); + byte* CMD_ReadRTCTime(); + byte* CMD_SetWeatherAndTemperature(WeatherCmd weather, byte temp); + byte* CMD_QueryWeatherAndTemperator(); +public: + bool IsVoiceCommand(byte* cmd); + bool IsVoiceAvailable(byte* cmd); + bool ReadRTCDate(byte* cmd, uint16_t& year, byte& month, byte& day); + bool ReadRTCTime(byte* cmd, byte& hour, byte& minute, byte& second); + bool ReadWeatherAndTemperature(byte* cmd, WeatherCmd& weather, byte& temp); +}; + +#endif + diff --git a/ZigBeeOperator.cpp b/ZigBeeOperator.cpp new file mode 100644 index 0000000..d1f4e88 --- /dev/null +++ b/ZigBeeOperator.cpp @@ -0,0 +1,19 @@ +// +// +// + +#include "ZigBeeOperator.h" + +void ZigBeeOperatorClass::Initialization() +{ + ExtSRAMInterface.Initialization(); +} + +void ZigBeeOperatorClass::SendCommand(uint8_t* cmd, uint16_t siz) +{ + ExtSRAMInterface.ExMem_Write_Bytes(zigbee_address, cmd, siz); +} + + +ZigBeeOperatorClass ZigBeeOperator; + diff --git a/ZigBeeOperator.h b/ZigBeeOperator.h new file mode 100644 index 0000000..29579cc --- /dev/null +++ b/ZigBeeOperator.h @@ -0,0 +1,27 @@ +// ZigBeeOperator.h + +#ifndef _ZIGBEEOPERATOR_h +#define _ZIGBEEOPERATOR_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +#include + +class ZigBeeOperatorClass +{ + private: + const uint16_t zigbee_address = 0x6008; + public: + void Initialization(); +public: + void SendCommand(uint8_t* cmd, uint16_t siz = 8); +}; + +extern ZigBeeOperatorClass ZigBeeOperator; + +#endif + diff --git a/__vm/Compile.vmps.xml b/__vm/Compile.vmps.xml index 26bfbf9..270a588 100644 --- a/__vm/Compile.vmps.xml +++ b/__vm/Compile.vmps.xml @@ -2,7 +2,7 @@ - + diff --git a/__vm/Upload.vmps.xml b/__vm/Upload.vmps.xml index 26bfbf9..270a588 100644 --- a/__vm/Upload.vmps.xml +++ b/__vm/Upload.vmps.xml @@ -2,7 +2,7 @@ - +