3.2.4 beta1 优化波形接收处理逻辑,定时器线程在遇到波形传输时将不处理,日志记录扩大到321k

This commit is contained in:
zhangsheng 2024-09-20 17:30:40 +08:00
parent 40ab840cd8
commit e15ad5cc4a
13 changed files with 276 additions and 203 deletions

View File

@ -482,6 +482,17 @@ int ModifyMac(char* buff)
system("cp /opt/system/mac /opt/system/macbak"); system("cp /opt/system/mac /opt/system/macbak");
system("/opt/Cidn/init.sh"); system("/opt/Cidn/init.sh");
} }
void mssleep(unsigned long microseconds)
{
struct timespec req;
struct timespec rem;
req.tv_sec = microseconds / 1000000;
req.tv_nsec = (microseconds % 1000000) * 1000;
nanosleep(&req, &rem);
}
std::string GetCurrentTime() std::string GetCurrentTime()
{ {
struct tm nowtime; struct tm nowtime;

View File

@ -616,6 +616,7 @@ extern int config_uart(const char* Port,speed_t speed);
extern int write_data(int fd, char *buff, int len); extern int write_data(int fd, char *buff, int len);
extern int read_data(int fd, char *buff, int len, int timeout); extern int read_data(int fd, char *buff, int len, int timeout);
extern int ModifyMac(char* buff); extern int ModifyMac(char* buff);
extern void mssleep(unsigned long microseconds);
//extern int str_recv(int fd, char srcshow,char* buffer); //extern int str_recv(int fd, char srcshow,char* buffer);
/** /**
* @brief * @brief

View File

@ -20,7 +20,7 @@ enum enumZigBeeTransmitStatus {
//#define NR5G_MODULE //#define NR5G_MODULE
#define Q4G_MODULE //#define Q4G_MODULE
//#define WIFI_MODULE //#define WIFI_MODULE
//#define NR5G_MEIGE //#define NR5G_MEIGE
//#define G2UL_GATEWAY //#define G2UL_GATEWAY

View File

@ -1179,62 +1179,75 @@ int SqliteDB::InintGateway()
std::string SqliteDB::GetNodeConfigureInfor(const char* whereCon) std::string SqliteDB::GetNodeConfigureInfor(const char* whereCon)
{ {
vec_t vecRes = GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon);
if(vecRes.size() < 1)
return "";
Json::Value jsSensorData;
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear();
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsonVal["cmd"] = "26";
jsSensorData["dataNodeNo"] = vecRes[44];
jsSensorData["dataNodeName"] = vecRes[1];
jsSensorData["initFlag"] = atoi(vecRes[2].c_str());
jsSensorData["accFlag"] = atoi(vecRes[3].c_str());
jsSensorData["zigbeeFlag"] = atoi(vecRes[4].c_str());
jsSensorData["temTopFlag"] = atoi(vecRes[5].c_str());
jsSensorData["temBotFlag"] = atoi(vecRes[6].c_str());
jsSensorData["hardVersion"] = vecRes[8];
jsSensorData["softVersion"] = vecRes[9];
jsSensorData["bpNo"] = vecRes[10];
jsSensorData["serialNo"] = vecRes[11];
jsSensorData["firstPowerTime"] = vecRes[12];
jsSensorData["WakeupTime"] = atoi(vecRes[13].c_str());
jsSensorData["StaticTime"] = atoi(vecRes[14].c_str());
jsSensorData["WaveTime"] = atoi(vecRes[15].c_str());
jsSensorData["BateryV"] = vecRes[16];
jsSensorData["ProductNo"] = vecRes[17];
jsSensorData["configFlag"] = atoi(vecRes[18].c_str());
jsSensorData["startBrands"] = vecRes[19];
jsSensorData["stopBrands"] = vecRes[20];
jsSensorData["featureInterVal"] = (vecRes[21]);
jsSensorData["waveInterVal"] = atoi(vecRes[22].c_str());
jsSensorData["samplingRate"] = atoi(vecRes[23].c_str());
jsSensorData["range"] = atoi(vecRes[25].c_str());
jsSensorData["envelopeBandPass"] = vecRes[26];
jsSensorData["faultFrequency"] = vecRes[27];
jsSensorData["zigbeePanId"] = vecRes[28];
jsSensorData["zigbeeChannel"] = (vecRes[29]);
jsSensorData["zigbeeAddr"] = vecRes[30];
jsSensorData["zigbeeLongAddr"] = vecRes[31];
jsSensorData["zigbeeDesAddr"] = vecRes[32];
jsSensorData["ZigbeePower"] = atoi(vecRes[33].c_str());
jsSensorData["ZigbeeRetry"] = atoi(vecRes[34].c_str());
jsSensorData["ZigbeeRetryGap"] = atoi(vecRes[35].c_str());
jsSensorData["ACCSampleTime"] = atoi(vecRes[36].c_str());
jsSensorData["status"] = atoi(vecRes[37].c_str());
jsSensorData["timeStamp"] = vecRes[38];
jsSensorData["viff"] = atoi(vecRes[39].c_str());
jsSensorData["RSSI"] = atoi(vecRes[40].c_str());
jsSensorData["Update"] = atoi(vecRes[41].c_str());
jsSensorData["LooseValue"] = (vecRes[42].c_str());
jsSensorData["batteryPower"] = (vecRes[43].c_str());
Json::FastWriter showValue; Json::FastWriter showValue;
jsonVal.clear();
jsonVal["cmd"] = "26";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsonVal["success"] = true;
jsonVal["message"] = "查询成功";
Json::Value jsArray;
array_t arrRes;
arrRes = sql_ctl->GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", whereCon);
int iResult = arrRes.size();
if (iResult > 0) {
for (int j = 0; j < iResult; j++) {
Json::Value jsSensorData;
jsSensorData["dataNodeNo"] = arrRes[j][44];
jsSensorData["dataNodeName"] = arrRes[j][1];
jsSensorData["initFlag"] = atoi(arrRes[j][2].c_str());
jsSensorData["accFlag"] = atoi(arrRes[j][3].c_str());
jsSensorData["zigbeeFlag"] = atoi(arrRes[j][4].c_str());
jsSensorData["temTopFlag"] = atoi(arrRes[j][5].c_str());
jsSensorData["temBotFlag"] = atoi(arrRes[j][6].c_str());
jsSensorData["equipsta"] = atoi(arrRes[j][7].c_str());
jsSensorData["hardVersion"] = arrRes[j][8];
jsSensorData["softVersion"] = arrRes[j][9];
jsSensorData["bpNo"] = arrRes[j][10];
jsSensorData["serialNo"] = arrRes[j][11];
jsSensorData["firstPowerTime"] = arrRes[j][12];
jsSensorData["WakeupTime"] = atoi(arrRes[j][13].c_str());
jsSensorData["StaticTime"] = atoi(arrRes[j][14].c_str());
jsSensorData["WaveTime"] = atoi(arrRes[j][15].c_str());
jsSensorData["BateryV"] = arrRes[j][16];
jsSensorData["ProductNo"] = arrRes[j][17];
jsSensorData["configFlag"] = atoi(arrRes[j][18].c_str());
jsSensorData["startBrands"] = arrRes[j][19];
jsSensorData["stopBrands"] = arrRes[j][20];
jsSensorData["featureInterVal"] = (arrRes[j][21]);
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
jsSensorData["envelopeBandPass"] = arrRes[j][26];
jsSensorData["faultFrequency"] = arrRes[j][27];
jsSensorData["zigbeePanId"] = arrRes[j][28];
jsSensorData["zigbeeChannel"] = (arrRes[j][29]);
jsSensorData["zigbeeAddr"] = arrRes[j][30];
jsSensorData["zigbeeLongAddr"] = arrRes[j][31];
jsSensorData["zigbeeDesAddr"] = arrRes[j][32];
jsSensorData["ZigbeePower"] = atoi(arrRes[j][33].c_str());
jsSensorData["ZigbeeRetry"] = atoi(arrRes[j][34].c_str());
jsSensorData["ZigbeeRetryGap"] = atoi(arrRes[j][35].c_str());
jsSensorData["ACCSampleTime"] = atoi(arrRes[j][36].c_str());
jsSensorData["status"] = atoi(arrRes[j][37].c_str());
jsSensorData["timeStamp"] = arrRes[j][38];
jsSensorData["viff"] = atoi(arrRes[j][39].c_str());
jsSensorData["RSSI"] = arrRes[j][40];
jsSensorData["Update"] = atoi(arrRes[j][41].c_str());
jsSensorData["looseValue"] = arrRes[j][42];
jsSensorData["battery"] = arrRes[j][43];
jsSensorData["MeasurementID"] = arrRes[j][44];
jsArray.append(jsSensorData);
}
} else {
jsArray.resize(0);
jsonVal["success"] = false;
jsonVal["message"] = "查询失败";
}
Json::Value jsBody; Json::Value jsBody;
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsBody["dataNodeData"] = jsSensorData; jsBody["dataNodeArray"] = jsArray;
std::string dataBody = showValue.write(jsBody); std::string dataBody = showValue.write(jsBody);
jsonVal["cmdBody"] = dataBody; jsonVal["cmdBody"] = dataBody;
return showValue.write(jsonVal); return showValue.write(jsonVal);
@ -1317,7 +1330,6 @@ int SqliteDB::QueryofflineData()
sql_ctl->UpdateTableData(dataTableName, updateSql, whereCon); sql_ctl->UpdateTableData(dataTableName, updateSql, whereCon);
LOG_INFO("resend success dataNodeNo = %s,TimeStamp = '%s'\n",arrRetData[j][0].c_str(),arrRetData[j][8].c_str()); LOG_INFO("resend success dataNodeNo = %s,TimeStamp = '%s'\n",arrRetData[j][0].c_str(),arrRetData[j][8].c_str());
} }
sleep(1);
} }
} }
char whereCon[1024] = {0x00}; char whereCon[1024] = {0x00};

View File

@ -203,7 +203,7 @@ int Dial::recvData()
memset(szbuffer,0x00,sizeof(szbuffer)); memset(szbuffer,0x00,sizeof(szbuffer));
offSize = 0; offSize = 0;
} }
usleep(100); mssleep(100);
}else if(ret > 0){ }else if(ret > 0){
print_info("ret = %d,buff = %s\n",ret,buff); print_info("ret = %d,buff = %s\n",ret,buff);
memcpy(szbuffer + offSize,buff,ret); memcpy(szbuffer + offSize,buff,ret);
@ -211,7 +211,7 @@ int Dial::recvData()
print_info("szbuffer = %s\n",szbuffer); print_info("szbuffer = %s\n",szbuffer);
continue; continue;
} }
usleep(500000); mssleep(500000);
} }
} }
int Dial::queryPin() int Dial::queryPin()

View File

@ -473,7 +473,7 @@ std::string JsonData::JsonCmd_52()
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME),whereCon,0); sql_ctl->DeleteTableData(T_DATA_INFO(TNAME),whereCon,0);
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME),whereCon,0); sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME),whereCon,0);
} }
usleep(100); mssleep(100);
} }
return ""; return "";
} }
@ -665,7 +665,7 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 &param)
jsonVal["type"] = "SET"; jsonVal["type"] = "SET";
if(param.mMode == 0){//本地校时 if(param.mMode == 0){//本地校时
SetTime((unsigned long)param.mTimeStamp); SetTime((unsigned long)param.mTimeStamp);
usleep(200); mssleep(200);
system("hwclock -w"); system("hwclock -w");
}else if(param.mMode == 1){//与服务器校时 }else if(param.mMode == 1){//与服务器校时
char buf[256] = {0}; char buf[256] = {0};
@ -1077,7 +1077,7 @@ std::string JsonData::JsonCmd_Cgi_20(Param_20 &param)
jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID; jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID;
jsSystemInfo["zigbeeChannel"] = GlobalConfig::ZigbeeInfo_G.Channel; jsSystemInfo["zigbeeChannel"] = GlobalConfig::ZigbeeInfo_G.Channel;
jsSystemInfo["zigbeeAddr"] = GlobalConfig::ZigbeeInfo_G.MyAddr; jsSystemInfo["zigbeeAddr"] = GlobalConfig::ZigbeeInfo_G.MyAddr;
jsSystemInfo["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion"); jsSystemInfo["GateWayVersion"] = GlobalConfig::Version;
jsSystemInfo["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion"); jsSystemInfo["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
jsSystemInfo["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion"); jsSystemInfo["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
jsSystemInfo["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion"); jsSystemInfo["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");

View File

@ -72,7 +72,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
std::string timestamp = recvBody["timestamp"].asString(); std::string timestamp = recvBody["timestamp"].asString();
unsigned long itimestamp = atol(timestamp.c_str()); unsigned long itimestamp = atol(timestamp.c_str());
SetTime(itimestamp); SetTime(itimestamp);
usleep(200); mssleep(200);
system("hwclock -w"); system("hwclock -w");
if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) { if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) {
std::string zoneid = recvValue["ZoneId"].asString(); std::string zoneid = recvValue["ZoneId"].asString();
@ -222,7 +222,7 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
} }
std::string data = jd.JsonCmd_Cgi_41(param41,1); std::string data = jd.JsonCmd_Cgi_41(param41,1);
char whereCon[64] = { 0 }; char whereCon[64] = { 0 };
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str()); sprintf(whereCon, " UpdateFlag <> 1 ");
string strData = sql_ctl->GetNodeConfigureInfor(whereCon); string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
@ -528,7 +528,7 @@ try{
} }
std::string data = jd.JsonCmd_Cgi_41(param41); std::string data = jd.JsonCmd_Cgi_41(param41);
char whereCon[64] = { 0 }; char whereCon[64] = { 0 };
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str()); sprintf(whereCon, " UpdateFlag <> 1 ");
string strData = sql_ctl->GetNodeConfigureInfor(whereCon); string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
return data; return data;
@ -604,7 +604,7 @@ try{
} }
std::string data = jd.JsonCmd_Cgi_53(param53); std::string data = jd.JsonCmd_Cgi_53(param53);
char whereCon[64] = { 0 }; char whereCon[64] = { 0 };
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str()); sprintf(whereCon, "UpdateFlag <> 0 ");
string strData = sql_ctl->GetNodeConfigureInfor(whereCon); string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
return data; return data;

View File

@ -153,11 +153,10 @@ int main(int argc, char *argv[])
GlobalConfig::threadStatus = 0; GlobalConfig::threadStatus = 0;
count = 0; count = 0;
} }
if(count >= 180){ if(count >= 30){
LOG_ERROR("===========threadStatus ========failed \n"); LOG_ERROR("===========threadStatus ========failed \n");
break; break;
} }
// data_publish(senddata.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
} }
return 0; return 0;

View File

@ -12,7 +12,7 @@ int GlobalConfig::LinkCount = 0;
int GlobalConfig::net0Status = 1; int GlobalConfig::net0Status = 1;
std::string GlobalConfig::Version = "3.2.3"; std::string GlobalConfig::Version = "3.2.4";
std::string GlobalConfig::MacAddr_G = ""; std::string GlobalConfig::MacAddr_G = "";
std::string GlobalConfig::MacAddr_G2 = ""; std::string GlobalConfig::MacAddr_G2 = "";
std::string GlobalConfig::IpAddr_G = ""; std::string GlobalConfig::IpAddr_G = "";

View File

@ -51,8 +51,37 @@ void CheckThread()
while (GlobalConfig::QuitFlag_G) { while (GlobalConfig::QuitFlag_G) {
GlobalConfig::threadStatus = 1; GlobalConfig::threadStatus = 1;
sleep(1);
if(GlobalConfig::EnterZigBeeWaveTransmittingFlag_G == ENTER_TRANSMITTING_STATUS) {
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G ++;
if(GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) {
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !\n");
// 重新写入 0x8888
unsigned short shortAddr = 0x8888;
pUart->modify_LocalAddr(0x8888);
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
// 延时1秒
sleep(1);
// 重新读回 GlobalConfig::ZigbeeInfo_G.PanID
pUart->UpdateZigbeeInfoCtrl();
pUart->bUpdateconfig = false;
pUart->bUpdate = false;
pUart->bSendTimeStamp = false;
// 延时1秒
sleep(1);
std::string str("8888");
if( GlobalConfig::ZigbeeInfo_G.MyAddr.compare(str) == 0 ){
LOG_INFO("[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !\n");
}
else {
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !\n");
}
}
continue;
}
if (10 == heart_count) { if (10 == heart_count) {
// StatusPub();
if (GlobalConfig::LinkCount > 30) { if (GlobalConfig::LinkCount > 30) {
LOG_ERROR("MQTT connect failed\n"); LOG_ERROR("MQTT connect failed\n");
#ifdef IMX6UL_GATEWAY #ifdef IMX6UL_GATEWAY
@ -106,7 +135,6 @@ void CheckThread()
exit(0); exit(0);
} }
#endif #endif
//bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
#ifdef NR5G_MODULE #ifdef NR5G_MODULE
#ifdef IMX6UL_GATEWAY #ifdef IMX6UL_GATEWAY
dial.closePort(); dial.closePort();
@ -238,10 +266,7 @@ void CheckThread()
LOG_INFO("Battery\n"); LOG_INFO("Battery\n");
sql_ctl->CalculateBattery(); sql_ctl->CalculateBattery();
} }
// if(10800 == UpdateZigbee){
// UpdateZigbee = 0;
// pUart->UpdateZigbeeInfoCtrl();
// }
if(3500 == loose_check){ if(3500 == loose_check){
LOG_INFO("loosecheck\n"); LOG_INFO("loosecheck\n");
loose_check = 0; loose_check = 0;
@ -323,7 +348,12 @@ void CheckThread()
char localtimestamp[32] = { 0 }; char localtimestamp[32] = { 0 };
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
char whereCon[1024] = {0}; char whereCon[1024] = {0};
#ifdef G2UL_GATEWAY
sprintf(whereCon," timestamp < '%ld' ",atol(localtimestamp) - 2592000 * 2); //删除2个月前的数据
#endif
#ifdef IMX6UL_GATEWAY
sprintf(whereCon," timestamp < '%ld' ",atol(localtimestamp) - 2592000); //删除1个月前的数据 sprintf(whereCon," timestamp < '%ld' ",atol(localtimestamp) - 2592000); //删除1个月前的数据
#endif
sql_ctl->DeleteTableData(" t_battery_history ",whereCon); sql_ctl->DeleteTableData(" t_battery_history ",whereCon);
/*staticData = 0; /*staticData = 0;
Json::Value jsHeart; Json::Value jsHeart;
@ -399,7 +429,6 @@ void CheckThread()
heart_count++; heart_count++;
online_check++; online_check++;
HardStatus ++; HardStatus ++;
//UpdateZigbee ++;
logClean ++ ; logClean ++ ;
loose_check ++; loose_check ++;
ModifyAddr ++; ModifyAddr ++;
@ -411,37 +440,6 @@ void CheckThread()
wifi_reconnect_count ++; wifi_reconnect_count ++;
#endif #endif
//rebootsystem ++;
if(GlobalConfig::EnterZigBeeWaveTransmittingFlag_G == ENTER_TRANSMITTING_STATUS) {
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G ++;
if(GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) {
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !\n");
// 重新写入 0x8888
unsigned short shortAddr = 0x8888;
pUart->modify_LocalAddr(0x8888);
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
// pUart->WriteShortAddr2Zigbee(shortAddr);
// 延时1秒
sleep(1);
// 重新读回 GlobalConfig::ZigbeeInfo_G.PanID
pUart->UpdateZigbeeInfoCtrl();
pUart->bUpdateconfig = false;
pUart->bUpdate = false;
pUart->bSendTimeStamp = false;
// 延时1秒
sleep(1);
std::string str("8888");
if( GlobalConfig::ZigbeeInfo_G.MyAddr.compare(str) == 0 ){
LOG_INFO("[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !\n");
}
else {
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !\n");
}
}
}
sleep(1);;
} }
} }

View File

@ -44,6 +44,7 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
{ {
if((unsigned short)GlobalConfig::Zigbee_G.MyAddr == 0x9999){ if((unsigned short)GlobalConfig::Zigbee_G.MyAddr == 0x9999){
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
ret = read_data(fd, buff, BUF_LENGTH, 10); ret = read_data(fd, buff, BUF_LENGTH, 10);
if (ret <= 0 ){ if (ret <= 0 ){
@ -61,14 +62,14 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
bModifyAddr = true; bModifyAddr = true;
modify_LocalAddr(0x8888); modify_LocalAddr(0x8888);
bSendTimeStamp = false; bSendTimeStamp = false;
usleep(10000); mssleep(10000);
m_waveTrans = true;
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
DealWave();
LOG_DEBUG("wave end\n"); LOG_DEBUG("wave end\n");
} }
usleep(10000); mssleep(10000);
}else if(bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)){ }else if(bUpdatePre || (bUpdateconfig && GlobalConfig::EnterZigBeeWaveTransmittingCnt_G > 15)){
timeoutflag ++; timeoutflag ++;
if(timeoutflag > 300){ if(timeoutflag > 300){
@ -84,15 +85,15 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
bModifyAddr = true; bModifyAddr = true;
bSendTimeStamp = false; bSendTimeStamp = false;
modify_LocalAddr(0x8888); modify_LocalAddr(0x8888);
usleep(10000); mssleep(10000);
GlobalConfig::Zigbee_G.MyAddr = 0x8888; GlobalConfig::Zigbee_G.MyAddr = 0x8888;
} }
usleep(10000); mssleep(10000);
} }
} }
else if(ret > 0){ else if(ret > 0){
maxSize += ret; maxSize += ret;
//print_debug("0x9999===str_recv===,ret = %d offSize = %d,bUpdatePre = %d,bUpdateconfig = %d\n",ret,maxSize,bUpdatePre,bUpdateconfig); print_debug("0x9999===str_recv===,ret = %d offSize = %d,bUpdatePre = %d,bUpdateconfig = %d\n",ret,maxSize,bUpdatePre,bUpdateconfig);
// for(int i = 0; i < ret;i++){ // for(int i = 0; i < ret;i++){
// printf("[%02x]", buff[i]&0xff); // printf("[%02x]", buff[i]&0xff);
// } // }
@ -161,7 +162,7 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
timeoutflag = 0; timeoutflag = 0;
offSize = 0; offSize = 0;
maxSize = 0; maxSize = 0;
usleep(10000); mssleep(10000);
} }
}else if(ret > 0){ }else if(ret > 0){
maxSize += ret; maxSize += ret;
@ -177,7 +178,7 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
} }
#endif #endif
} }
usleep(50); //mssleep(50);
} }
} }
@ -324,7 +325,7 @@ void Uart::ReadTestUart()
pTestRecv(0); pTestRecv(0);
} }
} }
usleep(20000); mssleep(20000);
} }
} }
@ -332,14 +333,14 @@ int Uart::ZigbeeTest()
{ {
char buff[BUF_LENGTH] = {0x00}; char buff[BUF_LENGTH] = {0x00};
modify_Localchannel(22); modify_Localchannel(22);
usleep(100000); mssleep(100000);
modify_LocalPanID(2222); modify_LocalPanID(2222);
usleep(100000); mssleep(100000);
modify_LocalAddr(6666); modify_LocalAddr(6666);
usleep(100000); mssleep(100000);
return 0; return 0;
} }
@ -577,7 +578,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
//break; //break;
}/*else if(m_strDestShortAddr != strShortAddr){ }/*else if(m_strDestShortAddr != strShortAddr){
usleep(100000); mssleep(100000);
waittime ++; waittime ++;
}*/ }*/
@ -806,7 +807,7 @@ void Uart::ReadHandle(char* pUartRecvBuf,size_t bytesRead)
bUpdate = false; bUpdate = false;
m_strDestShortAddr = ""; m_strDestShortAddr = "";
}else if(m_strDestShortAddr != strShortAddr){ }else if(m_strDestShortAddr != strShortAddr){
usleep(100000); mssleep(100000);
waittime ++; waittime ++;
return ; return ;
} }
@ -954,7 +955,7 @@ void Uart::UpdateZigbeeInfo(const char *pData)
// unsigned short panid = lShortAddr & 0xffff; // unsigned short panid = lShortAddr & 0xffff;
// //modify_LocalPanID(panid); // //modify_LocalPanID(panid);
// WritePanId2Zigbee(panid); // WritePanId2Zigbee(panid);
// usleep(100000); // mssleep(100000);
// LOG_ERROR("PanID error"); // LOG_ERROR("PanID error");
// } // }
@ -967,7 +968,7 @@ void Uart::UpdateZigbeeInfo(const char *pData)
// { // {
// //modify_Localchannel(Chan); // //modify_Localchannel(Chan);
// WriteChanl2Zigbee(Chan); // WriteChanl2Zigbee(Chan);
// usleep(100000); // mssleep(100000);
// } // }
// LOG_ERROR("channel error"); // LOG_ERROR("channel error");
// } // }
@ -1086,6 +1087,12 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr)
Data[11]=tmp; Data[11]=tmp;
sleep(1); sleep(1);
WriteToUart((const char*)Data,12); WriteToUart((const char*)Data,12);
int iRet = CheckZigbeeACK();
if(iRet == 0){
LOG_DEBUG("Packge ACK send success,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}else{
LOG_ERROR("Packge ACK send failed,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}
string strTime = GetLocalTimeWithMs(); string strTime = GetLocalTimeWithMs();
LOG_INFO("ReadUpdatePackge strTime = %s\n",strTime.c_str()); LOG_INFO("ReadUpdatePackge strTime = %s\n",strTime.c_str());
return true; return true;
@ -1131,7 +1138,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
unsigned char tmp = 0x00; unsigned char tmp = 0x00;
gpio_set(GlobalConfig::GPIO_G.zigAckreset,0); gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
//boost::this_thread::sleep(boost::posix_time::milliseconds(1)); //boost::this_thread::sleep(boost::posix_time::milliseconds(1));
usleep(1000); mssleep(1000);
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1); gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
for(int j = 0; j < Count;j++){ for(int j = 0; j < Count;j++){
int time ,value; int time ,value;
@ -1157,7 +1164,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
value = gpio_read(GlobalConfig::GPIO_G.zigAckrep); value = gpio_read(GlobalConfig::GPIO_G.zigAckrep);
if(value == 49) if(value == 49)
break; break;
usleep(10000); mssleep(10000);
time += 1; time += 1;
}while(time < 150); }while(time < 150);
if(time >= 150){ if(time >= 150){
@ -1174,12 +1181,12 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
} }
} }
gpio_set(GlobalConfig::GPIO_G.zigAckreset,0); gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
usleep(2000); mssleep(2000);
// if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) // if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
// gpio_set(GlobalConfig::GPIO_G.zigAckreset,1); // gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
memset(UpdateData,0x00,sizeof(UpdateData)); memset(UpdateData,0x00,sizeof(UpdateData));
//boost::this_thread::sleep(boost::posix_time::milliseconds(5)); //boost::this_thread::sleep(boost::posix_time::milliseconds(5));
usleep(5000); mssleep(5000);
} }
if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1); gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
@ -1210,12 +1217,12 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
int value = gpio_read(GlobalConfig::GPIO_G.zigAckrep); int value = gpio_read(GlobalConfig::GPIO_G.zigAckrep);
if(value == 49){ if(value == 49){
gpio_set(GlobalConfig::GPIO_G.zigAckreset,0); gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
usleep(10000); mssleep(10000);
if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1); gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
break; break;
} }
usleep(10000); mssleep(10000);
time += 1; time += 1;
}while(time < 150); }while(time < 150);
if(time >= 150){ if(time >= 150){
@ -1412,6 +1419,12 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr)
UpdateData[99] = tmp1; UpdateData[99] = tmp1;
tcflush(fd,TCIFLUSH); tcflush(fd,TCIFLUSH);
WriteToUart((const char*)UpdateData,100); WriteToUart((const char*)UpdateData,100);
int iRet = CheckZigbeeACK();
if(iRet == 0){
LOG_DEBUG("updataconfig ACK send success,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}else{
LOG_ERROR("updataconfig ACK send failed,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}
return 0; return 0;
}else if(vecResultNode[41] == "-1"){ }else if(vecResultNode[41] == "-1"){
@ -1451,6 +1464,12 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr)
UpdateData[99] = tmp1; UpdateData[99] = tmp1;
tcflush(fd,TCIFLUSH); tcflush(fd,TCIFLUSH);
WriteToUart((const char*)UpdateData,100); WriteToUart((const char*)UpdateData,100);
int iRet = CheckZigbeeACK();
if(iRet == 0){
LOG_DEBUG("updataname ACK send success,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}else{
LOG_ERROR("updataname ACK send failed,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}
return 0; return 0;
} }
@ -1466,7 +1485,7 @@ void Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*
{ {
if(modifyaddr) if(modifyaddr)
modify_DistAddr(pDestShortAddr); modify_DistAddr(pDestShortAddr);
usleep(10000); mssleep(10000);
//print_info("nodewaveindex = %d,nodetime = %d,nodeindex = %d\n",nodewaveindex,nodetime,nodeindex); //print_info("nodewaveindex = %d,nodetime = %d,nodeindex = %d\n",nodewaveindex,nodetime,nodeindex);
char localtimestamp[32]={0x00}; char localtimestamp[32]={0x00};
int millisecond = 0; int millisecond = 0;
@ -1504,6 +1523,12 @@ void Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*
} }
UpdateData[99] = tmp; UpdateData[99] = tmp;
WriteToUart((const char*)UpdateData,100); WriteToUart((const char*)UpdateData,100);
int iRet = CheckZigbeeACK();
if(iRet == 0){
LOG_DEBUG("NodeTime ACK send success,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}else{
LOG_ERROR("NodeTime ACK send failed,shortAddr = %02x%02x\n",pDestShortAddr[0],pDestShortAddr[1]);
}
} }
void Uart::DealRecvData(const char *pData) void Uart::DealRecvData(const char *pData)
{ {
@ -2000,17 +2025,17 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
{ {
bSendTimeStamp = true; bSendTimeStamp = true;
modify_distaddr_info(0x9999,"",pRecvData->ShortAddr);//临时参数配置 modify_distaddr_info(0x9999,"",pRecvData->ShortAddr);//临时参数配置
usleep(10000); mssleep(10000);
LOG_DEBUG("Zigbee Signal !\n"); LOG_DEBUG("Zigbee Signal !\n");
int Times = 0; int Times = 0;
usleep(20000); mssleep(20000);
while(Times < 3 ){ while(Times < 3 ){
getZigbeeSignal(pRecvData->ShortAddr); getZigbeeSignal(pRecvData->ShortAddr);
Times ++ ; Times ++ ;
usleep(20000); mssleep(20000);
} }
usleep(10000); mssleep(10000);
UpdateWirelessNodeTime((unsigned char*)pRecvData->ShortAddr,0); UpdateWirelessNodeTime((unsigned char*)pRecvData->ShortAddr,0);
}else }else
{ {
@ -3463,49 +3488,50 @@ void Uart::DealWaveThread() //连续三秒没有原始数据,则处理缓存
while (1) while (1)
{ {
// 接收到原始波形,则 m_TimeStamp 不为零 // // 接收到原始波形,则 m_TimeStamp 不为零
// 如果当前时间与记录时间超过3秒要求m_TimeStamp不变化而数据在传输则一定小于3秒 // // 如果当前时间与记录时间超过3秒要求m_TimeStamp不变化而数据在传输则一定小于3秒
if (0 == m_TimeStamp) { // if (0 == m_TimeStamp) {
sleep(1); // sleep(1);
continue; // continue;
} // }
char localtimestamp[32] = { 0 }; // char localtimestamp[32] = { 0 };
GetTimeNet(localtimestamp, 1); // GetTimeNet(localtimestamp, 1);
nowTimeStamp = strtol(localtimestamp, NULL, 10); // nowTimeStamp = strtol(localtimestamp, NULL, 10);
// 避免在未同步时钟导致数据错误 // // 避免在未同步时钟导致数据错误
if(nowTimeStamp >= m_TimeStamp) { // if(nowTimeStamp >= m_TimeStamp) {
tmpTimeStamp = nowTimeStamp - m_TimeStamp; // tmpTimeStamp = nowTimeStamp - m_TimeStamp;
} // }
else { // else {
tmpTimeStamp = m_TimeStamp - nowTimeStamp; // tmpTimeStamp = m_TimeStamp - nowTimeStamp;
} // }
//if ((nowTimeStamp - m_TimeStamp) > 3) { 时间戳需要修改为绝对值,可能丢失时钟,或工作一会儿,才同步时钟,可能减出异常值 // //if ((nowTimeStamp - m_TimeStamp) > 3) { 时间戳需要修改为绝对值,可能丢失时钟,或工作一会儿,才同步时钟,可能减出异常值
if (tmpTimeStamp > 3 ) { // TODO 时间戳需要修改为绝对值,可能丢失时钟,或工作一会儿,才同步时钟,可能减出异常值 print_info("yes!The time difference is more than 3,nowTimeStamp : %ld m_TimeStamp : %ld\n", nowTimeStamp, m_TimeStamp); // if (tmpTimeStamp > 3 ) { // TODO 时间戳需要修改为绝对值,可能丢失时钟,或工作一会儿,才同步时钟,可能减出异常值 print_info("yes!The time difference is more than 3,nowTimeStamp : %ld m_TimeStamp : %ld\n", nowTimeStamp, m_TimeStamp);
//DealWave(); // //DealWave();
m_TimeStamp = 0; // m_TimeStamp = 0;
offSize = 0; // offSize = 0;
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS; // GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0; // GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
// 准备重新恢复到 8888 PanID正常接收特征数据 // // 准备重新恢复到 8888 PanID正常接收特征数据
mPackgeIndex = -1; // mPackgeIndex = -1;
//WriteLocalAddr(0x8888); // //WriteLocalAddr(0x8888);
//GlobalConfig::Zigbee_G.MyAddr = 0x8888; // //GlobalConfig::Zigbee_G.MyAddr = 0x8888;
// WriteShortAddr2Zigbee(0x8888); // // WriteShortAddr2Zigbee(0x8888);
// UpdateZigbeeInfoCtrl(); // // UpdateZigbeeInfoCtrl();
} else {
print_info("NO! The time difference is less than 3,nowTimeStamp : %ld m_TimeStamp : %ld\n", nowTimeStamp, m_TimeStamp);
}
// } else {
// print_info("NO! The time difference is less than 3,nowTimeStamp : %ld m_TimeStamp : %ld\n", nowTimeStamp, m_TimeStamp);
// }
DealWave();
sleep(1); sleep(1);
} }
} }
void Uart::DealWave() void Uart::DealWave()
{ {
LOG_DEBUG("begin deal Wave data !\n"); //LOG_DEBUG("begin deal Wave data !\n");
print_blue("wave data size is(m_VecWaveData.size) : %d\n",m_VecWaveData.size()); //print_blue("wave data size is(m_VecWaveData.size) : %d\n",m_VecWaveData.size());
std::string strShortAddr = ""; std::string strShortAddr = "";
std::string strShortAddrTemp; std::string strShortAddrTemp;
std::string strLongAddr = ""; std::string strLongAddr = "";
@ -3518,7 +3544,7 @@ void Uart::DealWave()
char buf[8]; char buf[8];
RecvData recvTemp; RecvData recvTemp;
LOG_INFO("all wave data size is(m_VecWaveData.size) : %d \n",\ //LOG_INFO("all wave data size is(m_VecWaveData.size) : %d \n",\
m_VecWaveData.size()); m_VecWaveData.size());
while (m_VecWaveData.size() > 0) { //对每个传感器的每个通道进行遍历然后处理数据例如传感器1x轴的数据处理完后再去处理y轴的。传感器1的所有数据处理完后再处理传感器2的 while (m_VecWaveData.size() > 0) { //对每个传感器的每个通道进行遍历然后处理数据例如传感器1x轴的数据处理完后再去处理y轴的。传感器1的所有数据处理完后再处理传感器2的
std::vector<RecvData>::iterator iter = m_VecWaveData.begin(); std::vector<RecvData>::iterator iter = m_VecWaveData.begin();
@ -3715,6 +3741,11 @@ void Uart::DealWave()
strWaveData = waveTemp; strWaveData = waveTemp;
else else
strWaveData = strWaveData + "," + waveTemp; strWaveData = strWaveData + "," + waveTemp;
if (i % 100 == 0)
{
mssleep(5000);
}
} }
fclose(fp); fclose(fp);
@ -3734,29 +3765,29 @@ void Uart::DealWave()
if(res[17] == "01"){ if(res[17] == "01"){
//print_blue("vecData.size() = %d,sampleRate * ACCSampleTime = %d,iChannel = %d\n",vecData.size(),sampleRate * ACCSampleTime,iChannel); //print_blue("vecData.size() = %d,sampleRate * ACCSampleTime = %d,iChannel = %d\n",vecData.size(),sampleRate * ACCSampleTime,iChannel);
if(vecData.size() < sampleRate * ACCSampleTime && iChannel == 3 ){//过滤数据包结尾空数据 if(vecData.size() != sampleRate * ACCSampleTime && iChannel == 3 ){//过滤数据包结尾空数据
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime); print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime);
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
continue; continue;
} }
if(vecData.size() < sampleRate * ACCSampleTime && iChannel == 4 ){//过滤数据包结尾空数据 if(vecData.size() != sampleRate * ACCSampleTime && iChannel == 4 ){//过滤数据包结尾空数据
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime); print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime);
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
continue; continue;
} }
if(vecData.size() < sampleRate * ACCSampleTime && iChannel == 5 ){//过滤数据包结尾空数据 if(vecData.size() != sampleRate * ACCSampleTime && iChannel == 5 ){//过滤数据包结尾空数据
print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime); print_blue("%d vecData.size() == %d,sampleRate * ACCSampleTime = %d\n",iChannel,vecData.size(),sampleRate * ACCSampleTime);
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
continue; continue;
} }
}else if(res[17] == "02"){ }else if(res[17] == "02"){
if(vecData.size() < 8192 && iChannel == 3 ){//过滤数据包结尾空数据 if(vecData.size() != 8192 && iChannel == 3 ){//过滤数据包结尾空数据
continue; continue;
} }
if(vecData.size() < 8192 && iChannel == 4 ){//过滤数据包结尾空数据 if(vecData.size() != 8192 && iChannel == 4 ){//过滤数据包结尾空数据
continue; continue;
} }
if(vecData.size() < sampleRate * ACCSampleTime && iChannel == 5 ){//过滤数据包结尾空数据 if(vecData.size() != sampleRate * ACCSampleTime && iChannel == 5 ){//过滤数据包结尾空数据
continue; continue;
} }
} }
@ -3885,12 +3916,17 @@ void Uart::DealWave()
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
sleep(1); sleep(1);
} }
if (strLongAddr != "")
{
std::vector<RecvData>().swap(m_VecWaveData); std::vector<RecvData>().swap(m_VecWaveData);
char whereCon[1024] = {0x00}; char whereCon[1024] = {0x00};
char updateSql[1024] = {0x00}; char updateSql[1024] = {0x00};
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str()); sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
sprintf(updateSql, "WaveTime = WaveTime + 1"); sprintf(updateSql, "WaveTime = WaveTime + 1");
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
}
//string strData = sql_ctl->GetNodeConfigureInfor(whereCon); //string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
//data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); //data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
@ -4003,7 +4039,7 @@ void Uart::modify_distaddr_info(unsigned short id, char * zigbee,unsigned char*
command[5] = ((char *)&id)[0]; command[5] = ((char *)&id)[0];
WriteToUart(command, 6); WriteToUart(command, 6);
usleep(10000); mssleep(10000);
memset(command,0x00,sizeof(command)); memset(command,0x00,sizeof(command));
command[0] = 0xDE; command[0] = 0xDE;
command[1] = 0xDF; command[1] = 0xDF;
@ -4017,7 +4053,7 @@ void Uart::modify_distaddr_info(unsigned short id, char * zigbee,unsigned char*
} }
void Uart::getZigbeeSignal(unsigned char* distAddr) void Uart::getZigbeeSignal(unsigned char* distAddr)
{ {
usleep(10000); mssleep(10000);
char command[6] = {0x00}; char command[6] = {0x00};
command[0] = 0xDE; command[0] = 0xDE;
command[1] = 0xDF; command[1] = 0xDF;
@ -4138,7 +4174,7 @@ void Uart::WriteChanl2Zigbee(unsigned char pad)
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G); modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
} }
@ -4154,7 +4190,7 @@ void Uart::WritePanId2Zigbee(unsigned short pad)
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
} }
void Uart::WriteSpeed2Zigbee() void Uart::WriteSpeed2Zigbee()
@ -4166,13 +4202,13 @@ void Uart::WriteSpeed2Zigbee()
tmp = GlobalConfig::Zigbee_G.MyAddr; tmp = GlobalConfig::Zigbee_G.MyAddr;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
} }
/*void Uart::WriteLocalAddr(unsigned short id) /*void Uart::WriteLocalAddr(unsigned short id)
{ {
gpio_set(116,0); gpio_set(116,0);
usleep(10000); mssleep(10000);
gpio_set(116,1); gpio_set(116,1);
sleep(1); sleep(1);
char command[8]={0x00}; char command[8]={0x00};
@ -4185,9 +4221,9 @@ void Uart::WriteSpeed2Zigbee()
command[6] = 0x00; command[6] = 0x00;
command[7] = 0xaa; command[7] = 0xaa;
WriteToUart(command, 8); WriteToUart(command, 8);
usleep(600000); mssleep(600000);
gpio_set(116,0); gpio_set(116,0);
usleep(10000); mssleep(10000);
gpio_set(116,1); gpio_set(116,1);
}*/ }*/
void Uart::WriteTranTimeout2Zigbee(unsigned char Time) void Uart::WriteTranTimeout2Zigbee(unsigned char Time)
@ -4202,7 +4238,7 @@ void Uart::WriteTranTimeout2Zigbee(unsigned char Time)
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
} }
@ -4217,7 +4253,7 @@ void Uart::WriteShortAddr2Zigbee(unsigned short pad)
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G); modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
sleep(1); sleep(1);
} }
@ -4239,10 +4275,25 @@ void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad,unsigned char* pDes
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G); modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset,0); gpio_set(GlobalConfig::GPIO_G.zigReset,0);
usleep(10000); mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset,1); gpio_set(GlobalConfig::GPIO_G.zigReset,1);
} }
int Uart::CheckZigbeeACK()
{
if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
int time = 0,value = 0,iRet = -1;
do{
value = gpio_read(GlobalConfig::GPIO_G.zigAckrep);
if(value == 49)
{
iRet = 0;
break;
}
mssleep(10000);
}while(time < 150);
return iRet;
}
void Uart::ZigbeeInit() void Uart::ZigbeeInit()
{ {
std::string strPanId = sql_ctl->GetData("t_gateway_info","zigbeePanID",NULL); std::string strPanId = sql_ctl->GetData("t_gateway_info","zigbeePanID",NULL);
@ -4252,7 +4303,7 @@ void Uart::ZigbeeInit()
//GlobalConfig::Zigbee_G.MyAddr = shortAddr; //GlobalConfig::Zigbee_G.MyAddr = shortAddr;
//WriteLocalAddr(shortAddr); //WriteLocalAddr(shortAddr);
WriteShortAddr2Zigbee(shortAddr); WriteShortAddr2Zigbee(shortAddr);
usleep(100000); mssleep(100000);
// 更新GlobalConfig::ZigbeeInfo_G.MyAddr用于外部显示 // 更新GlobalConfig::ZigbeeInfo_G.MyAddr用于外部显示
} }
@ -4272,7 +4323,7 @@ void Uart::ZigbeeInit()
{ {
WriteChanl2Zigbee(Chan); WriteChanl2Zigbee(Chan);
//modify_Localchannel(Chan); //modify_Localchannel(Chan);
usleep(100000); mssleep(100000);
} }
} }
print_info("PanID1 = %s,strPanId = %s\n",GlobalConfig::ZigbeeInfo_G.PanID.c_str(),strPanId.c_str()); print_info("PanID1 = %s,strPanId = %s\n",GlobalConfig::ZigbeeInfo_G.PanID.c_str(),strPanId.c_str());
@ -4283,7 +4334,7 @@ void Uart::ZigbeeInit()
//modify_LocalPanID(panid); //modify_LocalPanID(panid);
WritePanId2Zigbee(panid); WritePanId2Zigbee(panid);
usleep(100000); mssleep(100000);
} }
//if (0 != GlobalConfig::ZigbeeInfo_G.MyAddr.compare("8888")) //if (0 != GlobalConfig::ZigbeeInfo_G.MyAddr.compare("8888"))

View File

@ -104,6 +104,7 @@ public :
virtual void ThreadInit(); virtual void ThreadInit();
int UartRecv(int fd, char srcshow,char* buffer); int UartRecv(int fd, char srcshow,char* buffer);
void openSwitch(); void openSwitch();
int CheckZigbeeACK();
private : private :
void ReadHandle(char* pUartRecvBuf,size_t bytesRead); void ReadHandle(char* pUartRecvBuf,size_t bytesRead);
void WriteHandle(const char *strSend,const boost::system::error_code &ec,size_t bytesWrite); void WriteHandle(const char *strSend,const boost::system::error_code &ec,size_t bytesWrite);

View File

@ -87,7 +87,7 @@ bool MXDHCP::Start(const std::string & net_interface)
} }
std::string cmd = "udhcpc -b -i " + net_interface + " &"; std::string cmd = "udhcpc -b -i " + net_interface + " &";
system("killall -9 udhcpc &"); system("killall -9 udhcpc &");
usleep(1000*100); mssleep(1000*100);
pstream = popen(cmd.data(),"r"); pstream = popen(cmd.data(),"r");
if(pstream == NULL) if(pstream == NULL)
{ {