update item commuation
This commit is contained in:
+16
-7
@@ -1,5 +1,14 @@
|
||||
#include <ExtSRAMInterface.h>
|
||||
#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 <Ultrasonic.h>
|
||||
#include <BKRC_Voice.h>
|
||||
#include "GlobalDatas.h"
|
||||
@@ -7,7 +16,6 @@
|
||||
#include <DCMotor.h>
|
||||
#include <CoreKEY.h>
|
||||
#include <CoreLED.h>
|
||||
#include <Command.h>
|
||||
#include "Handler.h"
|
||||
#include <BH1750.h>
|
||||
#include <BEEP.h>
|
||||
@@ -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接收数据处理
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<PreprocessorDefinitions>__AVR_atmega2560__;__AVR_ATmega2560__;F_CPU=16000000L;ARDUINO=108010;ARDUINO_AVR_MEGA2560;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
<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;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)</AdditionalIncludeDirectories>
|
||||
<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)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@@ -106,19 +106,33 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AccurateMotor.h" />
|
||||
<ClInclude Include="BarrierCommand.h" />
|
||||
<ClInclude Include="CommandDecoder.h" />
|
||||
<ClInclude Include="CommandEncoder.h" />
|
||||
<ClInclude Include="DebugOpt.h" />
|
||||
<ClInclude Include="GarageCommand.h" />
|
||||
<ClInclude Include="GlobalDatas.h" />
|
||||
<ClInclude Include="Handler.h" />
|
||||
<ClInclude Include="LEDDisplayCommand.h" />
|
||||
<ClInclude Include="OpenMVOpt.h" />
|
||||
<ClInclude Include="VoiceRepotCommand.h" />
|
||||
<ClInclude Include="ZigBeeOperator.h" />
|
||||
<ClInclude Include="__vm\.2021_Arduino_Demo.vsarduino.h" />
|
||||
<ClInclude Include="__vm\.Arduino.vsarduino.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AccurateMotor.cpp" />
|
||||
<ClCompile Include="BarrierCommand.cpp" />
|
||||
<ClCompile Include="CommandDecoder.cpp" />
|
||||
<ClCompile Include="CommandEncoder.cpp" />
|
||||
<ClCompile Include="DebugOpt.cpp" />
|
||||
<ClCompile Include="GarageCommand.cpp" />
|
||||
<ClCompile Include="GlobalDatas.cpp" />
|
||||
<ClCompile Include="Handler.cpp" />
|
||||
<ClCompile Include="LEDDisplayCommand.cpp" />
|
||||
<ClCompile Include="OpenMVOpt.cpp" />
|
||||
<ClCompile Include="VoiceRepotCommand.cpp" />
|
||||
<ClCompile Include="ZigBeeOperator.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<DebuggerFlavor>VisualMicroDebugger</DebuggerFlavor>
|
||||
|
||||
@@ -39,6 +39,27 @@
|
||||
<ClInclude Include="AccurateMotor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CommandEncoder.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BarrierCommand.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZigBeeOperator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CommandDecoder.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LEDDisplayCommand.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GarageCommand.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VoiceRepotCommand.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="OpenMVOpt.cpp">
|
||||
@@ -56,5 +77,26 @@
|
||||
<ClCompile Include="AccurateMotor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CommandEncoder.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="BarrierCommand.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZigBeeOperator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CommandDecoder.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LEDDisplayCommand.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GarageCommand.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="VoiceRepotCommand.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+4
-4
@@ -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();
|
||||
|
||||
+3
-1
@@ -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();
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
+25
-34
@@ -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);
|
||||
}
|
||||
|
||||
+9
-10
@@ -1,14 +1,18 @@
|
||||
#ifndef __DEBUG_OPT__
|
||||
#define __DEBUG_OPT_
|
||||
|
||||
#include <ExtSRAMInterface.h>
|
||||
#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 <BKRC_Voice.h>
|
||||
#include "OpenMVOpt.h"
|
||||
#include <Infrare.h>
|
||||
#include <CoreLED.h>
|
||||
#include <Command.h>
|
||||
#include <BEEP.h>
|
||||
#include <LED.h>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+13
-19
@@ -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 到达第四层
|
||||
|
||||
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发送识别二维码
|
||||
@@ -39,3 +20,16 @@ uint8_t Data_Type;
|
||||
uint8_t Data_Flag;
|
||||
uint8_t Data_Length;
|
||||
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------");
|
||||
}
|
||||
|
||||
+35
-16
@@ -1,28 +1,47 @@
|
||||
#ifndef __GLOBAL_DATAS__
|
||||
#define __GLOBAL_DATAS__
|
||||
#include <Wire.h>
|
||||
#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 到达第四层
|
||||
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];
|
||||
|
||||
|
||||
+74
-29
@@ -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
|
||||
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 0x06: //语音播报标志物
|
||||
}
|
||||
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 0x07: //红外报警标志物
|
||||
}
|
||||
case CommandData::Devices::AlarmTower: //红外报警标志物
|
||||
{
|
||||
AlarmTowerCommand cmd;
|
||||
if (cmd.IsAlarmTowerCommand(mar))
|
||||
{
|
||||
Serial.print("Rescue Position: ");
|
||||
Serial.println(cmd.ReadRescuePosition(mar), HEX);
|
||||
}
|
||||
break;
|
||||
case 0x08: //TFT显示标志物B
|
||||
}
|
||||
case CommandData::Devices::TFT_B: //TFT显示标志物B
|
||||
break;
|
||||
case 0x09: //调光标志物
|
||||
case CommandData::Devices::WirelessCharger: //磁悬浮无线充电标志物
|
||||
break;
|
||||
case 0x0A: //磁悬浮无线充电标志物
|
||||
case CommandData::Devices::TFT_A: //TFT显示标志物A
|
||||
break;
|
||||
case 0x0B: //TFT显示标志物A
|
||||
case CommandData::Devices::ETC: //ETC系统标志物
|
||||
break;
|
||||
case 0x0C: //ETC系统标志物
|
||||
case CommandData::Devices::Garage_A: //立体车库标志物A
|
||||
break;
|
||||
case 0x0D: //立体车库标志物A
|
||||
case CommandData::Devices::TrafficLight_A: //交通灯标注物A
|
||||
break;
|
||||
case 0x0E: //交通灯标注物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)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __HANDLER__
|
||||
#define __HANDLER__
|
||||
|
||||
#include "CommandDecoder.h"
|
||||
#include "GlobalDatas.h"
|
||||
#include "DebugOpt.h"
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
//
|
||||
// 标志物通信 - TFT(A/B) - ZigBee
|
||||
//
|
||||
|
||||
#include "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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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. 数据的查询:数据查询的结果会被返回到主车而不是从车。
|
||||
* 2. 语音合成:从车的ZigBee限制了8位带校验和数据导致此功能无法实现。
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <ExtSRAMInterface.h>
|
||||
|
||||
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
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user