optimize code and add control alarm
This commit is contained in:
parent
afa8ddeb63
commit
72dbf8e8a4
@ -389,4 +389,10 @@ struct Param_103{
|
|||||||
std::string operate;
|
std::string operate;
|
||||||
Param_103() : mac(""),name(""),operate(""){};
|
Param_103() : mac(""),name(""),operate(""){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Param_110{
|
||||||
|
int alarmMode; // 0:关灯,1:绿⾊,2:红⾊,3:蓝⾊,4:⻘⾊,5:⻩⾊,6:紫⾊,7:⽩⾊
|
||||||
|
int flashTime; // 单位是ms,0表⽰不闪烁常亮,其他值为闪烁的间隔
|
||||||
|
Param_110() : alarmMode(0),flashTime(0){};
|
||||||
|
};
|
||||||
#endif // PARAMETER_DEFINATION_HPP_
|
#endif // PARAMETER_DEFINATION_HPP_
|
||||||
|
|||||||
@ -82,6 +82,9 @@ public:
|
|||||||
std::string JsonCmd_Cgi_103(Param_103 ¶m);
|
std::string JsonCmd_Cgi_103(Param_103 ¶m);
|
||||||
std::string JsonCmd_Cgi_default();
|
std::string JsonCmd_Cgi_default();
|
||||||
|
|
||||||
|
//报警灯
|
||||||
|
std::string JsonCmd_Cgi_110(Param_110 ¶m);
|
||||||
|
|
||||||
//CMT tcp
|
//CMT tcp
|
||||||
void CmtCmd_80(char* send_data,int& send_length);
|
void CmtCmd_80(char* send_data,int& send_length);
|
||||||
void CmtCmd_81(char* recv_body,int& count,char* send_data,int& send_length);
|
void CmtCmd_81(char* recv_body,int& count,char* send_data,int& send_length);
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "dbaccess/sql_db.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
#include "platform/platform_init.hpp"
|
#include "platform/platform_init.hpp"
|
||||||
#include "wifi_5g/scan_blueteeth.h"
|
#include "wifi_5g/scan_blueteeth.h"
|
||||||
|
#include "uart/uart.hpp"
|
||||||
|
|
||||||
extern zlog_category_t *zct;
|
extern zlog_category_t *zct;
|
||||||
extern const char *JSON_FIELD_CMD;
|
extern const char *JSON_FIELD_CMD;
|
||||||
@ -195,5 +196,49 @@ std::string JsonData::JsonCmd_Cgi_103(Param_103 ¶m){
|
|||||||
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_BT_INFO(TNAME), whereCon);
|
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_BT_INFO(TNAME), whereCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
//报警灯
|
||||||
|
std::string JsonData::JsonCmd_Cgi_110(Param_110 ¶m){
|
||||||
|
Json::Value jsonVal;
|
||||||
|
jsonVal.clear();
|
||||||
|
jsonVal[JSON_FIELD_CMD] = "110";
|
||||||
|
jsonVal["success"] = true;
|
||||||
|
jsonVal["message"] = "设置报警灯成功";
|
||||||
|
uart_inst::instance().alarmFlag = true;
|
||||||
|
if(uart_inst::instance().bUpdate){
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "设置报警灯失败";
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
unsigned char command[11] = {0x00};
|
||||||
|
int data = (param.flashTime << 16) | (param.alarmMode & 0xFFFF);
|
||||||
|
command[0] = 0xA5;
|
||||||
|
command[1] = 0x5A;
|
||||||
|
command[2] = 0xA5;
|
||||||
|
command[3] = 0x02;
|
||||||
|
command[4] = 0x02;
|
||||||
|
command[5] = 0x03;
|
||||||
|
command[6] = data & 0xFF;
|
||||||
|
command[7] = (data >> 8) & 0xFF;
|
||||||
|
command[8] = (data >> 16) & 0xFF;
|
||||||
|
command[9] = (data >> 24) & 0xFF;
|
||||||
|
unsigned char tmp = 0x00;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
tmp += command[i];
|
||||||
|
}
|
||||||
|
command[10] = tmp;
|
||||||
|
uart_inst::instance().WriteToUart((const char*)command, 11);
|
||||||
|
mssleep(15000);
|
||||||
|
char recvData[12] = {0x00};
|
||||||
|
int ret = uart_inst::instance().ReadFromAlarm();
|
||||||
|
if (ret == 2 ) {
|
||||||
|
jsonVal["message"] = "设置报警灯成功";
|
||||||
|
} else {
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "设置报警灯失败";
|
||||||
|
}
|
||||||
|
uart_inst::instance().alarmFlag = false;
|
||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,10 @@ enum WebCommand {
|
|||||||
kGetSensorInfo = 100,
|
kGetSensorInfo = 100,
|
||||||
kGetFeatureSensorInfo = 101,
|
kGetFeatureSensorInfo = 101,
|
||||||
kScanSenorInfo = 102,
|
kScanSenorInfo = 102,
|
||||||
kOperateSensor = 103
|
kOperateSensor = 103,
|
||||||
|
|
||||||
|
//报警灯
|
||||||
|
kAlarmLight = 110
|
||||||
};
|
};
|
||||||
enum GatewayType{
|
enum GatewayType{
|
||||||
kGWTDW2700 = 1,
|
kGWTDW2700 = 1,
|
||||||
|
|||||||
@ -553,6 +553,14 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
std::string data = jd.JsonCmd_Cgi_103(param);
|
std::string data = jd.JsonCmd_Cgi_103(param);
|
||||||
return data;
|
return data;
|
||||||
}break;
|
}break;
|
||||||
|
case kAlarmLight:{
|
||||||
|
JsonData jd;
|
||||||
|
Param_110 param;
|
||||||
|
param.alarmMode = recvBody["alarmMode"].asInt();
|
||||||
|
param.flashTime = recvBody["flashTime"].asInt();
|
||||||
|
std::string data = jd.JsonCmd_Cgi_110(param);
|
||||||
|
return data;
|
||||||
|
}break;
|
||||||
default:
|
default:
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
std::string data = jd.JsonCmd_Cgi_default();
|
std::string data = jd.JsonCmd_Cgi_default();
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@ -54,7 +54,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
sqlite_db_ctrl::instance().InintGateway();
|
sqlite_db_ctrl::instance().InintGateway();
|
||||||
|
|
||||||
uart_inst::instance().InitZigbeeHW();
|
|
||||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||||
boost::thread searchT(SearchThread);
|
boost::thread searchT(SearchThread);
|
||||||
searchT.detach();
|
searchT.detach();
|
||||||
|
|||||||
@ -148,6 +148,7 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
|||||||
memset(send_data, 0, sizeof(send_data));
|
memset(send_data, 0, sizeof(send_data));
|
||||||
last_short_addr = 0;
|
last_short_addr = 0;
|
||||||
last_time = 0;
|
last_time = 0;
|
||||||
|
alarmFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uart::~Uart() {
|
Uart::~Uart() {
|
||||||
@ -256,7 +257,7 @@ int Uart::ZigbeeTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uart::WriteToUart(const char *strSend, int pLen) {
|
void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||||
//if (!bUpdate)
|
if (!bUpdate)
|
||||||
{
|
{
|
||||||
printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str());
|
printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str());
|
||||||
for (int i = 0; i < pLen; i++) {
|
for (int i = 0; i < pLen; i++) {
|
||||||
@ -266,7 +267,6 @@ void Uart::WriteToUart(const char *strSend, int pLen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int iRet = write_data(fd, (char *)strSend, pLen);
|
int iRet = write_data(fd, (char *)strSend, pLen);
|
||||||
printf( "WriteToUart iRet = %d, pLen = %d\n", iRet, pLen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Uart::ReadFromUart() {
|
int Uart::ReadFromUart() {
|
||||||
@ -283,12 +283,8 @@ int Uart::ReadFromUart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Uart::ReadFromAlarm(){
|
int Uart::ReadFromAlarm(){
|
||||||
char buffer[100] = {0x00};
|
char buffer[1024] = {0x00};
|
||||||
int len = read_data(fd, (char *)buffer, 100, 10);
|
int len = read_data(fd, (char *)buffer, 1024, 20);
|
||||||
printf( "ReadFromAlarm len = %d\n", len);
|
|
||||||
for (int i = 0; i < len; i++) printf( "%02X ", buffer[i] & 0xFF);
|
|
||||||
printf( "print end\n");
|
|
||||||
zlog_info(zct, "==========ReadFromAlarm========len = %d", len);
|
|
||||||
char head[] = {0xA5, 0x5A, 0xA5};
|
char head[] = {0xA5, 0x5A, 0xA5};
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
@ -301,14 +297,19 @@ int Uart::ReadFromAlarm(){
|
|||||||
|
|
||||||
if(buffer[i + 5] == 0x02 && buffer[i + 6] == 0x01){
|
if(buffer[i + 5] == 0x02 && buffer[i + 6] == 0x01){
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}else{
|
}else if(buffer[i + 5] == 0x03 && buffer[i + 6] == 0xFF){
|
||||||
|
return 2 ;
|
||||||
|
}else if(buffer[i + 5] == 0x02 && buffer[i + 6] == 0x00){
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
else{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1 ;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uart::Run() { mIoSev.run(); }
|
void Uart::Run() { mIoSev.run(); }
|
||||||
|
|||||||
@ -236,6 +236,7 @@ public:
|
|||||||
bool bZigbeeSinal;
|
bool bZigbeeSinal;
|
||||||
bool bModifyAddr;
|
bool bModifyAddr;
|
||||||
bool bSendTimeStamp;
|
bool bSendTimeStamp;
|
||||||
|
bool alarmFlag;
|
||||||
std::string DataNodeUpdateFile;
|
std::string DataNodeUpdateFile;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -184,8 +184,10 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
|||||||
//帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte]
|
//帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte]
|
||||||
zlog_warn(zbt, "Start Upgrade!!! file Size = %d,fileName = %s,Count = %d,lastSize = %d,shortAddr = %02x%02x", (int)thisSize,DataNodeUpdateFile.c_str(),Count,lastSize,UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
zlog_warn(zbt, "Start Upgrade!!! file Size = %d,fileName = %s,Count = %d,lastSize = %d,shortAddr = %02x%02x", (int)thisSize,DataNodeUpdateFile.c_str(),Count,lastSize,UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||||
tmp = 0x00;
|
tmp = 0x00;
|
||||||
|
int time = 0 ,value = -1;
|
||||||
for(int j = 0; j < Count;j++){
|
for(int j = 0; j < Count;j++){
|
||||||
int time ,value;
|
time = 0 ;
|
||||||
|
value = -1;
|
||||||
UpdateData[0]=0xAA;
|
UpdateData[0]=0xAA;
|
||||||
UpdateData[1]=0x55;
|
UpdateData[1]=0x55;
|
||||||
UpdateData[2]=0xAA;
|
UpdateData[2]=0xAA;
|
||||||
@ -200,13 +202,19 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
|||||||
}
|
}
|
||||||
UpdateData[99] = tmp;
|
UpdateData[99] = tmp;
|
||||||
WriteToUart((const char*)UpdateData,100);
|
WriteToUart((const char*)UpdateData,100);
|
||||||
mssleep(100000);
|
mssleep(10000);
|
||||||
WriteToUart((const char*)command,11);
|
WriteToUart((const char*)command,11);
|
||||||
mssleep(100000);
|
mssleep(10000);
|
||||||
if (ReadFromAlarm() == 0) {
|
do{
|
||||||
zlog_info(zct, "Packge %d ACK send success,shortAddr = %02x%02x", j, UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
value = ReadFromAlarm();
|
||||||
} else {
|
if(value == 0)
|
||||||
zlog_warn(zct, "Packge %d ACK send failed,shortAddr = %02x%02x", j, UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
break;
|
||||||
|
WriteToUart((const char*)command,11);
|
||||||
|
mssleep(10000);
|
||||||
|
time += 1;
|
||||||
|
}while(time < 150);//1500000
|
||||||
|
if(time >= 150){
|
||||||
|
zlog_warn(zct, "Packge %d ACK send failed,shortAddr = %02x%02x,time = %d", j, UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),time);
|
||||||
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x,index = %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),j);
|
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x,index = %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),j);
|
||||||
zlog_warn(zct, "gpio_read failed \n");
|
zlog_warn(zct, "gpio_read failed \n");
|
||||||
bUpdate = false;
|
bUpdate = false;
|
||||||
@ -216,7 +224,8 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
|||||||
memset(UpdateData,0x00,sizeof(UpdateData));
|
memset(UpdateData,0x00,sizeof(UpdateData));
|
||||||
mssleep(5000);
|
mssleep(5000);
|
||||||
}
|
}
|
||||||
|
time = 0 ;
|
||||||
|
value = -1;
|
||||||
if (lastSize > 0) {
|
if (lastSize > 0) {
|
||||||
UpdateData[0] = 0xAA;
|
UpdateData[0] = 0xAA;
|
||||||
UpdateData[1] = 0x55;
|
UpdateData[1] = 0x55;
|
||||||
@ -232,13 +241,20 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
|||||||
}
|
}
|
||||||
UpdateData[99] = tmp;
|
UpdateData[99] = tmp;
|
||||||
WriteToUart((const char*)UpdateData, 100);
|
WriteToUart((const char*)UpdateData, 100);
|
||||||
mssleep(100000);
|
mssleep(10000);
|
||||||
getGPIOStatus();
|
getGPIOStatus();
|
||||||
mssleep(100000);
|
mssleep(10000);
|
||||||
if (ReadFromAlarm() == 0) {
|
do{
|
||||||
zlog_info(zct, "ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
value = ReadFromAlarm();
|
||||||
} else {
|
if(value == 0)
|
||||||
zlog_warn(zct, "ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
break;
|
||||||
|
WriteToUart((const char*)command,11);
|
||||||
|
mssleep(10000);
|
||||||
|
time += 1;
|
||||||
|
}while(time < 150);//1500000
|
||||||
|
if(time >= 150){
|
||||||
|
zlog_warn(zct, "Packge %d ACK send failed,shortAddr = %02x%02x,time = %d", lastSize, UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),time);
|
||||||
|
zlog_warn(zct, "gpio_read failed shortAdd %02x %02x,index = %d", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd),lastSize);
|
||||||
zlog_warn(zct, "gpio_read failed \n");
|
zlog_warn(zct, "gpio_read failed \n");
|
||||||
bUpdate = false;
|
bUpdate = false;
|
||||||
upgrade_status = 3;
|
upgrade_status = 3;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user