去掉代码中多余的部分
This commit is contained in:
parent
176b573457
commit
4358142573
@ -382,29 +382,7 @@ void Calculation::FFTSpec(std::vector<float> & vecData, std::vector<float> & vec
|
||||
|
||||
void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData,int StartFrequency,int EndFrequency)
|
||||
{
|
||||
/*std::vector<float> vecDropMeanData;
|
||||
drop_mean(vecDropMeanData, vecData);
|
||||
|
||||
std::vector<float> vecHilbertData;
|
||||
hilbert(vecDropMeanData, vecHilbertData, vecDropMeanData.size());
|
||||
|
||||
fftw_complex *inHilFFt, *outHilFFt;
|
||||
inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecHilbertData.size());
|
||||
outHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecHilbertData.size());
|
||||
|
||||
for (int j = 0; j < vecHilbertData.size(); j++) {
|
||||
inHilFFt[j][0] = (double)vecHilbertData[j];
|
||||
inHilFFt[j][1] = 0;
|
||||
}
|
||||
|
||||
FFT(vecHilbertData.size(), inHilFFt, outHilFFt);
|
||||
fftShift(outHilFFt, vecHilbertData.size());
|
||||
|
||||
vecEnvSpecData.push_back(0);
|
||||
for (int i = vecHilbertData.size() / 2 + 1; i < vecHilbertData.size(); i++) {
|
||||
float ftemp = 2 * sqrt(outHilFFt[i][0] * outHilFFt[i][0] + outHilFFt[i][1] * outHilFFt[i][1]) / vecHilbertData.size();
|
||||
vecEnvSpecData.push_back(ftemp);
|
||||
}*/
|
||||
std::vector<float> vecFFTrealData,vecFFTimageData;
|
||||
std::vector<float> vecRealData,vecImageData;
|
||||
std::vector<float> veciFFtData;
|
||||
@ -475,72 +453,5 @@ void Calculation::Integration(std::vector<float> & vecData,std::vector<float>& r
|
||||
}
|
||||
|
||||
_iFFT(realvalue,imagevalue,retData);
|
||||
|
||||
// for (size_t i = 0; i < ifftData.size(); i++)
|
||||
// {
|
||||
// retData.push_back( ifftData[i] * 2);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*void acceleration_to_velocity(int fs, int N, float *data, int min_freq, int max_freq, float *out_data) {
|
||||
fftwf_execute_dft_r2c(forward_plan[fft_plan_id(N)], data, forward_out);
|
||||
|
||||
float df = fs * 1.0f / N;
|
||||
int ni = round(min_freq / df);
|
||||
int na = round(max_freq / df);
|
||||
float dw = 2 * fcl_pi * df;
|
||||
|
||||
int double_id = get_idle_double_res();
|
||||
if (double_id < 0) {
|
||||
return;
|
||||
}
|
||||
float *w11 = get_double_res_ptr(double_id);
|
||||
|
||||
int len = 0;
|
||||
int max_f = round((0.5 * fs - df) / df);
|
||||
|
||||
for (int i = 0; i <= max_f; ++i) {
|
||||
w11[i] = i * dw;
|
||||
++len;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max_f; ++i) {
|
||||
w11[len] = -2 * fcl_pi * (0.5 * fs - df) + i * dw;
|
||||
++len;
|
||||
}
|
||||
|
||||
forward_out[0][0] = forward_out[0][1] = forward_out[N - 1][0] = forward_out[N - 1][1] = 0;
|
||||
float tmp_real, tmp_imag;
|
||||
for (int i = 1; i < N - 1; ++i) {
|
||||
tmp_real = forward_out[i][1] / w11[i];
|
||||
tmp_imag = -forward_out[i][0] / w11[i];
|
||||
forward_out[i][0] = tmp_real; // real
|
||||
forward_out[i][1] = tmp_imag; // imag
|
||||
}
|
||||
|
||||
free_double_res(double_id);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
backward_in[i][0] = 0;
|
||||
backward_in[i][1] = 0;
|
||||
}
|
||||
|
||||
for (int i = ni - 1; i < na; ++i) {
|
||||
backward_in[i][0] = forward_out[i][0];
|
||||
backward_in[i][1] = forward_out[i][1];
|
||||
}
|
||||
|
||||
for (int i = N - na; i < N - ni + 1; ++i) {
|
||||
backward_in[i][0] = forward_out[i][0];
|
||||
backward_in[i][1] = forward_out[i][1];
|
||||
}
|
||||
|
||||
fftwf_execute_dft(backward_plan[fft_plan_id(N)], backward_in, backward_out);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
out_data[i] = backward_out[i][0] / N * 2 * 1000; // *1000 是单位换算, 跟python保持一致
|
||||
}
|
||||
}*/
|
||||
|
||||
@ -2330,31 +2330,6 @@ int socketHeart(const char* pSendData)
|
||||
|
||||
return 0;
|
||||
}
|
||||
//unsigned short cal_chksum(unsigned short *addr, int len)
|
||||
//{
|
||||
// int nleft=len;
|
||||
// int sum=0;
|
||||
// unsigned short *w=addr;
|
||||
// unsigned short answer=0;
|
||||
//
|
||||
// while(nleft > 1)
|
||||
// {
|
||||
// sum += *w++;
|
||||
// nleft -= 2;
|
||||
// }
|
||||
//
|
||||
// if( nleft == 1)
|
||||
// {
|
||||
// *(unsigned char *)(&answer) = *(unsigned char *)w;
|
||||
// sum += answer;
|
||||
// }
|
||||
//
|
||||
// sum = (sum >> 16) + (sum & 0xffff);
|
||||
// sum += (sum >> 16);
|
||||
// answer = ~sum;
|
||||
//
|
||||
// return answer;
|
||||
//}
|
||||
|
||||
// Ping函数,timeout为超时时间,单位是ms,10000 毫秒=10 秒
|
||||
//成功:返回0,失败:返回1或-1
|
||||
|
||||
@ -24,8 +24,8 @@ enum enumZigBeeTransmitStatus {
|
||||
//#define Q4G_MODULE
|
||||
//#define WIFI_MODULE
|
||||
//#define NR5G_MEIGE
|
||||
//#define G2UL_GATEWAY
|
||||
#define IMX6UL_GATEWAY
|
||||
#define G2UL_GATEWAY
|
||||
//#define IMX6UL_GATEWAY
|
||||
|
||||
class GlobalConfig
|
||||
{
|
||||
|
||||
@ -817,7 +817,7 @@ int SqliteDB::InsertData(const char* tablename, const char* insertValues, int re
|
||||
}
|
||||
sprintf(strSql, "%s %s%s %s %s %s", "insert into", strReplace, tablename, "values(", insertValues, ");");
|
||||
print_light_green("%s\n", strSql);
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql);
|
||||
|
||||
iRet = sqlite3_exec(GetDbHandle(isDB2), strSql, 0, 0, &msg);
|
||||
|
||||
free(strSql);
|
||||
@ -828,7 +828,7 @@ int SqliteDB::InsertData(const char* tablename, const char* insertValues, int re
|
||||
}
|
||||
strSql = strSql + tablename + " values(" + insertValues + ");";
|
||||
print_light_green("%s\n", strSql.c_str());
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||
|
||||
iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||
}
|
||||
if (iRet != SQLITE_OK) {
|
||||
@ -913,7 +913,7 @@ int SqliteDB::CalculateBattery()
|
||||
vector<long> vecsendTime;
|
||||
float to_math = 0.0;
|
||||
print_info("vecResbattery = %d,temp = %s\n",vecResbattery.size(),vecResbattery[0][2].c_str());
|
||||
//LOG_INFO("vecResbattery = %d,temp = %s\n",vecResbattery.size(),vecResbattery[0][2].c_str());
|
||||
|
||||
for (size_t j = 0; j < vecResbattery.size(); j++)
|
||||
{
|
||||
float b = 2 - 25 * k;
|
||||
@ -926,7 +926,6 @@ int SqliteDB::CalculateBattery()
|
||||
}
|
||||
|
||||
print_info("自放电 = %f\n",to_math);
|
||||
//LOG_INFO("自放电 = %f\n",to_math);
|
||||
long sumworkTime = 0.0,sumsendTime = 0.0;
|
||||
for(size_t j = 0 ; j < vecworkTime.size();j++)
|
||||
{
|
||||
@ -937,11 +936,11 @@ int SqliteDB::CalculateBattery()
|
||||
sumsendTime += vecsendTime[j];
|
||||
}
|
||||
print_info("sumworkTime = %ld,sumsendTime = %ld\n",sumworkTime,sumsendTime);
|
||||
//LOG_INFO("sumworkTime = %ld,sumsendTime = %ld\n",sumworkTime,sumsendTime);
|
||||
|
||||
float usageworkTime = ((float)sumworkTime/3600000) * 4;
|
||||
float usagesendTime = ((float)sumsendTime/3600000) * 39;
|
||||
print_info("work = %f,send = %f\n",usageworkTime,usagesendTime);
|
||||
//LOG_INFO("work = %f,send = %f\n",usageworkTime,usagesendTime);
|
||||
|
||||
if(to_math < 0)
|
||||
to_math = 0;
|
||||
float usageBattery = usageworkTime + usagesendTime + to_math;
|
||||
@ -987,57 +986,6 @@ int SqliteDB::CalculateBattery()
|
||||
}
|
||||
LOG_INFO("CalculateBattery end\n");
|
||||
|
||||
|
||||
|
||||
|
||||
/*float dayStaticPower = 6.5,dayWavePower = 237;//
|
||||
char whereCon[1024] = {0};
|
||||
char selectSql[1024] = { 0 };
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(selectSql,0x00,sizeof(selectSql));
|
||||
sprintf(selectSql," DataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate ");
|
||||
array_t vecRes ;
|
||||
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||
if(vecRes.size() > 0){
|
||||
for(int i = 0; i < vecRes.size(); i++){
|
||||
if(vecRes[i][5] == "12800"){
|
||||
|
||||
}else if(vecRes[i][5] == "3200"){
|
||||
|
||||
}
|
||||
float dayStaticTime = 0.0;
|
||||
float dayWaveTime = 0.0;
|
||||
if(atoi(vecRes[i][3].c_str()) == 0){
|
||||
dayStaticTime = 0;
|
||||
}else{
|
||||
dayStaticTime = 24*60/atoi(vecRes[i][3].c_str());
|
||||
}
|
||||
if(atoi(vecRes[i][4].c_str()) == 0){
|
||||
dayWaveTime = 0;
|
||||
}else{
|
||||
dayWaveTime = 24*60/atoi(vecRes[i][4].c_str());
|
||||
}
|
||||
|
||||
float dayPower = dayStaticTime * dayStaticPower + dayWaveTime * dayWavePower + 24*3.26;//static + wave + sleep
|
||||
float usePower = atoi(vecRes[i][1].c_str()) * dayStaticPower + atoi(vecRes[i][2].c_str()) * dayWavePower;
|
||||
if(dayPower == 0)
|
||||
dayPower = 1;
|
||||
float remainDay = (19000000*0.5 - usePower)/dayPower;
|
||||
float bateryProportion = remainDay/(19000000*0.5/dayPower);
|
||||
char updateSql[1024] = { 0x00 };
|
||||
char tmpParam[1024] = {0x00};
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(updateSql,0x00,sizeof(updateSql));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' ",vecRes[i][0].c_str());
|
||||
sprintf(updateSql,"batteryPower = '%f,%f' ",bateryProportion,remainDay);
|
||||
int iRet = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
print_info("iRet = %d\n",iRet);
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
}*/
|
||||
|
||||
print_info("CalculateBattery \n");
|
||||
return 0;
|
||||
}
|
||||
int SqliteDB::CalculateDip()
|
||||
@ -1326,7 +1274,6 @@ int SqliteDB::QueryofflineData()
|
||||
std::string strstatisticData = featureValue.write(root);
|
||||
|
||||
int iRet = data_publish(strstatisticData.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
|
||||
//print_info("dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d\n",arrRetData[j][0].c_str(),nowTimetamp.c_str(),iRet);
|
||||
if(iRet == 0){
|
||||
char updateSql[1024] = { 0 };
|
||||
char whereCon[64] = { 0 };
|
||||
@ -1335,7 +1282,6 @@ int SqliteDB::QueryofflineData()
|
||||
memcpy(updateSql, "sendMsg='1'",sizeof(updateSql));
|
||||
sql_ctl->UpdateTableData(StaticTableName, 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1387,12 +1333,10 @@ int SqliteDB::QueryofflineData()
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", arrRetData[i][0].c_str(),arrRetData[i][2].c_str());
|
||||
sprintf(updateSql, "SendMsg = 1");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
//char whereCon[64]={0x00};
|
||||
//sprintf(whereCon,"waveName = '%s'",arrRetData[i][1].c_str());
|
||||
//DeleteTableData("t_data_waveSend", whereCon);
|
||||
|
||||
std::string strCmd = "rm " + arrRetData[i][1];
|
||||
system(strCmd.c_str());
|
||||
//LOG_INFO("resend success waveName = %s\n",arrRetData[i][1].c_str());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -58,17 +58,13 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
Json::FastWriter fw;
|
||||
std::string strjson = fw.write(recvValue);
|
||||
data_publish(strjson.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
//system("echo 1 > /CIDW/start");
|
||||
|
||||
sleep(1);
|
||||
system("reboot");
|
||||
}
|
||||
break;
|
||||
case 12:{
|
||||
/* std::string strBody = recvValue["cmdBody"].asString();
|
||||
Json::Value jsBody;
|
||||
if (!recvReader.parse(strBody, jsBody)) {
|
||||
return;
|
||||
}*/
|
||||
|
||||
std::string timestamp = recvBody["timestamp"].asString();
|
||||
unsigned long itimestamp = atol(timestamp.c_str());
|
||||
SetTime(itimestamp);
|
||||
@ -78,14 +74,6 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
std::string zoneid = recvValue["ZoneId"].asString();
|
||||
ZoneConfig(zoneid);
|
||||
}
|
||||
/* Json::Value retVal;
|
||||
retVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
retVal["cmd"] = 12;
|
||||
retVal["success"] = true;
|
||||
retVal["message"] = "校时成功";
|
||||
Json::FastWriter fw;
|
||||
std::string strjson = fw.write(retVal);
|
||||
data_publish(strjson.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());*/
|
||||
}
|
||||
break;
|
||||
case 13:{
|
||||
@ -167,7 +155,6 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_25(param);
|
||||
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
// platform->EquipIpInit();
|
||||
}
|
||||
break;
|
||||
case 26:{
|
||||
@ -182,7 +169,6 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_26(param);
|
||||
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
// platform->EquipIpInit();
|
||||
}
|
||||
break;
|
||||
case 27:{
|
||||
@ -419,7 +405,6 @@ try{
|
||||
}
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_25(param);
|
||||
//platform->EquipIpInit();
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
|
||||
15
main.cpp
15
main.cpp
@ -48,8 +48,7 @@ int main(int argc, char *argv[])
|
||||
platform->PlatFormInit();
|
||||
|
||||
sql_ctl->InintGateway();
|
||||
//sql_ctl->CalculateData();
|
||||
//sql_ctl->CalculateBattery();
|
||||
|
||||
pUart->InitZigbee();
|
||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
boost::thread searchT(SearchThread);
|
||||
@ -64,8 +63,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
boost::thread InitModuleReadTh(InitModule);
|
||||
InitModuleReadTh.detach();
|
||||
//boost::thread uartWatchDogReadTh(WatchDog);
|
||||
//uartWatchDogReadTh.detach();
|
||||
|
||||
|
||||
// 休眠2秒,等待串口线程初始化完毕
|
||||
sleep(2);
|
||||
@ -124,15 +122,6 @@ int main(int argc, char *argv[])
|
||||
sleep(1);
|
||||
pUart->UpdateZigbeeInfoCtrl();
|
||||
|
||||
bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
print_info("===========status ======== %d\n",status);
|
||||
|
||||
/* char * szRes = sql_ctl->GetDataChar(T_SENSOR_INFO(TNAME), "dataNodeName", "dataNodeNo = '074cfd0000158d00'");
|
||||
printf("szRes = %s\n",szRes);
|
||||
for(int i = 0; i < 64;i++){
|
||||
printf("temp = %02x ",szRes[i]);
|
||||
}*/
|
||||
|
||||
//启动 mqtt客户端
|
||||
boost::thread startMqtt(StartMqttClient);
|
||||
startMqtt.detach();
|
||||
|
||||
@ -96,7 +96,7 @@ void CheckThread()
|
||||
std::string ipTemp = IpAddrInit();
|
||||
GlobalConfig::IpAddr_G = ipTemp;
|
||||
if ( 0 != ipTemp.compare(GlobalConfig::IpAddr_G)) {
|
||||
//exit(0);
|
||||
|
||||
}
|
||||
heart_count = 0;
|
||||
}
|
||||
@ -478,7 +478,6 @@ void HeartRep()
|
||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||
print_info("heart = %s,iRet = %d\n",strJson.c_str(),iRet);
|
||||
if(iRet != 0){
|
||||
//count ++;
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,1);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
@ -495,52 +494,8 @@ void HeartRep()
|
||||
count = 0;
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
}
|
||||
//gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
// if(count > 0){
|
||||
// bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
// if(status != 0)
|
||||
// //LOG_INFO("===========net status ========failed heart count %d\n",count);
|
||||
// if(status != 0 && count > 30){
|
||||
// LOG_ERROR("heart send failed,heart count %d\n",count);
|
||||
// count = 0;
|
||||
// sleep(20);
|
||||
// gpio_set(GlobalConfig::GPIO_G.power,1);
|
||||
// }
|
||||
// }
|
||||
// if(count > 1000){
|
||||
// gpio_set(GlobalConfig::GPIO_G.power,1);
|
||||
// count = 0;
|
||||
// }
|
||||
// write_data(fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
// //sleep(1);
|
||||
// char buff[1024]={0x00};
|
||||
// int ret = read_data(fd, buff, 1024, 10);
|
||||
// print_info("ret = %d,buff = %s\n",ret,buff);
|
||||
// const char *str2 = "+QENG: ";
|
||||
// char csq[128] = {0};
|
||||
// char *pdata = strstr((char*)buff, str2);
|
||||
// if(pdata){
|
||||
// strncpy(csq, pdata+7, sizeof(csq));
|
||||
// }
|
||||
// else {
|
||||
// }
|
||||
//
|
||||
// //printf("SIM-CSQ: %s\n", csq);
|
||||
// GlobalConfig::NetStatus = GetOneContent(csq,1,",");
|
||||
// string signal = GetOneContent(csq,13,",");
|
||||
// GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
// print_info("NetStatus = %s,NetSignal = %d\n",GlobalConfig::NetStatus.c_str(),GlobalConfig::NetSignal);
|
||||
|
||||
//GlobalConfig::NetSignal = getcsq();
|
||||
/*if(GlobalConfig::NetSignal <= -105 ){
|
||||
gpio_set(130,1);
|
||||
}else if(GlobalConfig::NetSignal > -105 ){
|
||||
gpio_set(130,0);
|
||||
}else{
|
||||
gpio_set(130,1);
|
||||
}*/
|
||||
sleep(10);
|
||||
//socketHeart(strJson.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,8 +584,7 @@ dial5G:
|
||||
}
|
||||
void UartStart()
|
||||
{
|
||||
// onReceiveUart cb = (onReceiveUart)&ProtoConvert::HandleFromUart;
|
||||
// pUart->setCallBack(cb);
|
||||
|
||||
print_info("zigAckrep = %d,zigAckreset = %d,zigReset = %d,errorLed = %d,power = %d",\
|
||||
GlobalConfig::GPIO_G.zigAckrep,GlobalConfig::GPIO_G.zigAckreset,GlobalConfig::GPIO_G.zigReset,GlobalConfig::GPIO_G.errorLed,\
|
||||
GlobalConfig::GPIO_G.power);
|
||||
@ -800,9 +754,6 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||
GlobalConfig::LinkStatus_G = 1;
|
||||
print_debug("Connect to server success.\n");
|
||||
|
||||
// std::string cmd20 = JsonCmd_Cgi_20();
|
||||
// data_publish(cmd20.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
|
||||
char buf[256] = {0};
|
||||
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}",
|
||||
GlobalConfig::MacAddr_G.c_str());
|
||||
@ -875,8 +826,7 @@ void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||
print_info("%s\n", buf);
|
||||
|
||||
#else
|
||||
// int iRet = reconnect();
|
||||
// print_info("reconnect = %d\n",iRet);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
518
uart/SH_Uart.cpp
518
uart/SH_Uart.cpp
@ -26,11 +26,7 @@ std::vector<RecvData> g_VecWaveDataX;
|
||||
std::vector<RecvData> g_VecWaveDataY;
|
||||
std::vector<RecvData> g_VecWaveDataZ;
|
||||
map<string,compressWaveChannel> g_mapCompress;
|
||||
// namespace{
|
||||
// PlatformInit *platform = PlatformInit::instance();
|
||||
// LocalServer *wlServer = LocalServer::instance();
|
||||
// GenericFunc *genericFunc = GenericFunc::instance();
|
||||
// }
|
||||
|
||||
using namespace boost::asio;
|
||||
const UINT CharSize = 8;
|
||||
const UINT UartBaud = 115200;
|
||||
@ -98,12 +94,7 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
|
||||
}
|
||||
else if(ret > 0){
|
||||
maxSize += ret;
|
||||
// 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++){
|
||||
// printf("[%02x]", buff[i]&0xff);
|
||||
// }
|
||||
//print_debug("maxSize = %d\n",maxSize);
|
||||
//print_debug("\n");
|
||||
|
||||
timeoutflag = 0;
|
||||
|
||||
if((bUpdatePre || bUpdateconfig))
|
||||
@ -111,13 +102,9 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
|
||||
for(int i = 0; i < ret;i++){
|
||||
printf("%02x ", buff[i]&0xff);
|
||||
}
|
||||
//print_debug("maxSize111 = %d\n",maxSize);
|
||||
// string strTime = GetLocalTimeWithMs();
|
||||
// LOG_INFO("str_recv strTime1 = %s\n",strTime.c_str());
|
||||
|
||||
FindRecvPackage(ret,buff,head);
|
||||
// ReadHandle(buff,ret);
|
||||
// strTime = GetLocalTimeWithMs();
|
||||
// LOG_INFO("str_recv strTime2 = %s\n",strTime.c_str());
|
||||
|
||||
}else{
|
||||
m_TimeStamp = 0;
|
||||
memcpy(mUartRecvTmpBuf + offSize,buff,ret);
|
||||
@ -135,7 +122,6 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
}
|
||||
//print_debug("offSize = %d\n",offSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +169,6 @@ int Uart::UartRecv(int fd, char srcshow,char* buffer)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
//mssleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,18 +350,8 @@ void Uart::WriteToUart(const char *strSend,int pLen)
|
||||
}
|
||||
print_debug("\nWrite To Uart End.\n");
|
||||
}
|
||||
//#endif
|
||||
/* if (mUart.is_open()) {
|
||||
mUart.async_write_some(buffer(strSend,pLen),
|
||||
mStrand.wrap(
|
||||
boost::bind(&Uart::WriteHandle,this,strSend,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred))
|
||||
);
|
||||
}*/
|
||||
|
||||
int len = write_data(fd,(char*)strSend,pLen);
|
||||
// printf("len = %d\n",len);
|
||||
// ReadFromUart();
|
||||
}
|
||||
|
||||
int Uart::ReadFromUart()
|
||||
@ -424,8 +399,6 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
string strTime = GetLocalTimeWithMs();
|
||||
char head1[] = {0xAB,0xBC,0xCD};
|
||||
char head2[] = {0xDE,0xDF,0xEF};
|
||||
|
||||
//LOG_INFO("m_VecWaveData= %d\n",m_VecWaveData.size());
|
||||
int lastSize = 0;
|
||||
char UartRecvBuf[BUF_LENGTH*15]={0x00};
|
||||
char RecvBuf[200] = {0x00};
|
||||
@ -439,11 +412,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
memset(mUartRecvTmpBuf,0x00,sizeof(mUartRecvTmpBuf));
|
||||
}
|
||||
memcpy(UartRecvBuf + mlastSize,mUartRecvBuf,bytesRead);
|
||||
// for(int i = 0 ; i < bytesRead;i++){
|
||||
// if(!(i % 100))
|
||||
// printf("\n");
|
||||
// printf("%02x ",mUartRecvBuf[i]);
|
||||
// }
|
||||
|
||||
bytesRead = bytesRead + mlastSize;
|
||||
for(int i = 0; i < bytesRead;i++){
|
||||
if(UartRecvBuf[i] == head[0]){
|
||||
@ -459,11 +428,9 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
char buf[8]={0x00};
|
||||
sprintf(buf, "%02d", UartRecvBuf[i+5]&0xFF);
|
||||
int command = atoi(buf);
|
||||
//print_info("command = %d\n",command);
|
||||
//print_info("index = %d\n",UartRecvBuf[i+6]&0xFF);
|
||||
//print_info("mPackgeIndex1 = %d\n",mPackgeIndex);
|
||||
|
||||
if((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i+6] == 0) && (!bUpdatePre && !bUpdateconfig)){
|
||||
//print_info("mPackgeIndex2 = %d\n",mPackgeIndex);
|
||||
|
||||
mPackgeIndex = UartRecvBuf[i+6]&0xFF;
|
||||
}else if((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i+6] &&
|
||||
mPackgeIndex != -1 && (!bUpdatePre && !bUpdateconfig) && command != 2){
|
||||
@ -474,7 +441,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
}else if((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i+6] &&
|
||||
mPackgeIndex != -1 && (!bUpdatePre && !bUpdateconfig) && command != 2){
|
||||
m_TimeStamp = 0;
|
||||
//print_info("mPackgeIndex3 = %d\n",mPackgeIndex);
|
||||
|
||||
LOG_ERROR("mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s \n",\
|
||||
mPackgeIndex,UartRecvBuf[i+6]&0xff,strShortAddr.c_str());
|
||||
mPackgeIndex = -1;
|
||||
@ -496,16 +463,14 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
bSendTimeStamp = false;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
//std::vector<RecvData>().swap(m_VecWaveData);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(command == 32){
|
||||
LOG_INFO("bUpdatepackge command = %d ShortAddr :%s\n",command,strShortAddr.c_str());
|
||||
memcpy(RecvBuf,(char*)&UartRecvBuf[i],12);
|
||||
//for(int j = i; j < i+12;j++){
|
||||
// print_info("%02X ",UartRecvBuf[j]&0xFF);
|
||||
//}
|
||||
|
||||
|
||||
if(!CheckCrc(RecvBuf,11)){
|
||||
LOG_INFO("CheckCrc error command 20 \n");
|
||||
@ -554,12 +519,12 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
g_VecWaveDataX.clear();
|
||||
g_VecWaveDataY.clear();
|
||||
g_VecWaveDataZ.clear();
|
||||
//std::vector<RecvData>().swap(m_VecWaveData);
|
||||
|
||||
break;
|
||||
}
|
||||
mlastSize = 0;
|
||||
lastSize = bytesRead - i;
|
||||
//print_info("laseSize = %d , i = %d\n",lastSize,i);
|
||||
|
||||
if(lastSize < 100 && lastSize > 0){
|
||||
memcpy(mUartRecvTmpBuf,(char*)&UartRecvBuf[bytesRead-lastSize],lastSize);
|
||||
mlastSize = lastSize;
|
||||
@ -580,7 +545,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
|
||||
print_info("m_strDestShortAddr = %s,strShortAddr = %s,waittime = %d\n",\
|
||||
m_strDestShortAddr.c_str(),strShortAddr.c_str(),waittime);
|
||||
//if(waittime >= 2 || m_strDestShortAddr == strShortAddr)
|
||||
|
||||
{
|
||||
char RecvBuf[100] = {0x00};
|
||||
memcpy(RecvBuf,&UartRecvBuf[i],100);
|
||||
@ -593,22 +558,15 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
//break;
|
||||
}/*else if(m_strDestShortAddr != strShortAddr){
|
||||
mssleep(100000);
|
||||
waittime ++;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}else if(command == 34 && bUpdateconfig){
|
||||
LOG_INFO("bUpdateconfig command = %d ShortAddr :%s\n",command,strShortAddr.c_str());
|
||||
memset(RecvBuf,0x00,sizeof(RecvBuf));
|
||||
print_info("bUpdateconfig ShortAddr :%s\n",strShortAddr.c_str());
|
||||
//memcpy(RecvBuf,(char*)&UartRecvBuf[i],100);
|
||||
/*for(int j = i; j < i+100;j++){
|
||||
print_info("%02X ",UartRecvBuf[j]&0xFF);
|
||||
}*/
|
||||
|
||||
m_TimeStamp = 0;
|
||||
//if(!CheckCrc((char*)&UartRecvBuf[i],99))
|
||||
{
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = { 0 };
|
||||
@ -617,8 +575,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
sprintf(updateSql, "UpdateFlag = UpdateFlag + 1");
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", buf);
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
//string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
//data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||
bUpdateconfig = false;
|
||||
mPackgeIndex = -1;
|
||||
@ -635,10 +592,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
}
|
||||
break;
|
||||
}else if(command == 35){
|
||||
//LOG_INFO("command = %d ShortAddr :%s,Timetamp=%s\n",command,strShortAddr.c_str(),strTimetamp.c_str());
|
||||
// for(int j = i; j < i+100;j++){
|
||||
// printf("%02X ",UartRecvBuf[j]&0xFF);
|
||||
// }
|
||||
|
||||
char signalNode[10]={0x00};
|
||||
sprintf(signalNode,"%02d",UartRecvBuf[i+14]&0xFF);
|
||||
if(!strcmp(signalNode,"00") || !strcmp(signalNode,"0")){
|
||||
@ -716,9 +670,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
print_info("%02x,%02x,%02x,%02x,%02x \n",UartRecvBuf[i],UartRecvBuf[i+1],UartRecvBuf[i+2],UartRecvBuf[i+3],UartRecvBuf[i+4]);
|
||||
LOG_INFO("zigbeeShortAddr = %s , ret = %02d\n",m_strDestShortAddr.c_str(),UartRecvBuf[i+4]&0xFF);
|
||||
|
||||
//pTestRecv(command);
|
||||
}else if(command == 218){//DA
|
||||
//LOG_INFO("command = %d,zigbeeShortAddr = %s , signal = %02d,strTimetamp = %s\n",command,m_strDestShortAddr.c_str(),UartRecvBuf[i+6]&0xFF,strTimetamp.c_str());
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = { 0 };
|
||||
char tableName[100]={0x00};
|
||||
@ -743,11 +695,11 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
boost::split( vParamRSSI, vecDataNodeNo[2], boost::is_any_of( "," ), boost::token_compress_on );
|
||||
if(vParamRSSI.size() == 1){
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ",UartRecvBuf[i+6]&0xFF,vParamRSSI[0].c_str());
|
||||
//LOG_INFO(updateSql);
|
||||
|
||||
|
||||
}else if(vParamRSSI.size() == 2){
|
||||
sprintf(updateSql, "RSSI = '%02d,%s' ",UartRecvBuf[i+6]&0xFF,vParamRSSI[1].c_str());
|
||||
//LOG_INFO(updateSql);
|
||||
|
||||
}
|
||||
sprintf(whereCon, "dataNodeNo='%s'", (char*)vecDataNodeNo[0].c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
@ -764,8 +716,6 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
|
||||
}
|
||||
|
||||
}
|
||||
strTime = GetLocalTimeWithMs();
|
||||
// LOG_INFO("findRecvPackage strTime2 = %s\n",strTime.c_str());
|
||||
}
|
||||
void Uart::ReadHandle(char* pUartRecvBuf,size_t bytesRead)
|
||||
{
|
||||
@ -885,16 +835,12 @@ void Uart::ThreadInit()
|
||||
void Uart::DataAnalysis_W(DevData &pData,bool pFlag)
|
||||
{
|
||||
this->WriteToUart(pData.mData,pData.mLen);
|
||||
// LOG_INFO("WriteToUart:%s", pData.mDataMing);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(110));
|
||||
}
|
||||
|
||||
void Uart::UpdateZigbeeInfoCtrl()
|
||||
{
|
||||
/* char buf[5] = {0xAB, 0xBC, 0xCD, 0xD1, 0x05};
|
||||
WriteToUart(buf, 5);
|
||||
sleep(1);*/
|
||||
// ReadFromUart();
|
||||
|
||||
char command[5]={0x00};
|
||||
unsigned char command1[100]={0x00};
|
||||
command[0] = 0xab;
|
||||
@ -904,23 +850,7 @@ void Uart::UpdateZigbeeInfoCtrl()
|
||||
command[4] = 0xaa;
|
||||
WriteToUart(command,5);
|
||||
LOG_INFO("UpdateZigbeeInfoCtrl \n");
|
||||
/*for ( int i = 0; i < 20; i++)
|
||||
print_info("%02X ",command[i]);
|
||||
print_info("\n");*/
|
||||
/*int ret = write_data(fd, (char*)command, 5);
|
||||
if (ret < 0) {
|
||||
perror("write");
|
||||
return ;
|
||||
}
|
||||
// sleep(1);
|
||||
|
||||
/*ret = read_data(fd, (char *)command1, 100, 10);
|
||||
printf("ret = %d\n",ret);
|
||||
if (ret <= 4) {
|
||||
printf("info get error!\n");
|
||||
return ;
|
||||
}
|
||||
UpdateZigbeeInfo((char*)command1);*/
|
||||
}
|
||||
|
||||
void Uart::UpdateZigbeeInfo(const char *pData)
|
||||
@ -959,36 +889,14 @@ void Uart::UpdateZigbeeInfo(const char *pData)
|
||||
|
||||
LOG_INFO("local zigbee module info Mode : %d Chan : %d PanID : %s MyAddr : %s DstAddr : %s,RetryNum:%s,TranTimeout:%s\n", GlobalConfig::ZigbeeInfo_G.DevMode, GlobalConfig::ZigbeeInfo_G.Channel,
|
||||
GlobalConfig::ZigbeeInfo_G.PanID.c_str(),GlobalConfig::ZigbeeInfo_G.MyAddr.c_str(), GlobalConfig::ZigbeeInfo_G.DstAddr.c_str(),GlobalConfig::ZigbeeInfo_G.RetryNum.c_str(),GlobalConfig::ZigbeeInfo_G.TranTimeout.c_str());
|
||||
// if(GlobalConfig::ZigbeeInfo_G.MyAddr != "8888"){
|
||||
// modify_LocalAddr(0x8888);
|
||||
//
|
||||
// LOG_INFO("zigbee Update \n");
|
||||
// GlobalConfig::ZigbeeInfo_G.MyAddr = "8888";
|
||||
// }
|
||||
|
||||
LOG_INFO("PanID = %s,MacAddr_G= %s\n",GlobalConfig::ZigbeeInfo_G.PanID.c_str(),GlobalConfig::MacAddr_G.c_str());
|
||||
// if(GlobalConfig::ZigbeeInfo_G.PanID != GlobalConfig::MacAddr_G.substr(8)){
|
||||
// string strPanId = GlobalConfig::MacAddr_G.substr(8);
|
||||
// long lShortAddr = strtol(strPanId.c_str(), NULL, 16);
|
||||
// unsigned short panid = lShortAddr & 0xffff;
|
||||
// //modify_LocalPanID(panid);
|
||||
// WritePanId2Zigbee(panid);
|
||||
// mssleep(100000);
|
||||
// LOG_ERROR("PanID error");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
|
||||
LOG_INFO("Channel = %d,strchan = %s\n",GlobalConfig::ZigbeeInfo_G.Channel,strchan.c_str());
|
||||
// if(GlobalConfig::ZigbeeInfo_G.Channel != atoi(strchan.c_str())){
|
||||
// unsigned short Chan = (unsigned short)strtol(strchan.c_str(), NULL, 10);
|
||||
// if(Chan > 10 && Chan < 27)
|
||||
// {
|
||||
// //modify_Localchannel(Chan);
|
||||
// WriteChanl2Zigbee(Chan);
|
||||
// mssleep(100000);
|
||||
// }
|
||||
// LOG_ERROR("channel error");
|
||||
// }
|
||||
|
||||
|
||||
std::string strType = ReadStrByOpt(SYSTEMINFOFILE, "ZigbeeType", "type");
|
||||
print_info("TranTimeout = %02x,strType = %s \n",GlobalConfig::Zigbee_G.TranTimeout,strType.c_str());
|
||||
@ -1000,11 +908,10 @@ void Uart::UpdateZigbeeInfo(const char *pData)
|
||||
unsigned short TranTimeout = 0x03;
|
||||
WriteTranTimeout2Zigbee(TranTimeout);
|
||||
}
|
||||
// LOG_INFO("[UpdateZigbeeInfo---] ZigBee PanID: %s ; Channel: %d ; MyAddr : %s ",GlobalConfig::ZigbeeInfo_G.PanID.c_str(),GlobalConfig::ZigbeeInfo_G.Channel,GlobalConfig::ZigbeeInfo_G.MyAddr.c_str());
|
||||
|
||||
}
|
||||
void int2bytes(int i, unsigned char* bytes, int size) {
|
||||
// byte[] bytes = new byte[4];
|
||||
|
||||
memset(bytes,0,sizeof(unsigned char) * size);
|
||||
bytes[0] = (unsigned char) (0xff & i);
|
||||
bytes[1] = (unsigned char) ((0xff00 & i) >> 8);
|
||||
@ -1049,12 +956,6 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr)
|
||||
if(thisindex < 0)
|
||||
return false;
|
||||
|
||||
// if(!strncmp(vecResult[0].c_str(),"3",1)){
|
||||
// WriteTranTimeout2Zigbee(0x03);
|
||||
// }else if(!strncmp(vecResult[0].c_str(),"4",1)){
|
||||
// WriteTranTimeout2Zigbee(0x0A);
|
||||
// }
|
||||
|
||||
print_info("thisindex = %d\n",thisindex);
|
||||
|
||||
FILE * pFile=NULL;
|
||||
@ -1073,13 +974,6 @@ bool Uart::ReadUpdatePackge(unsigned char* pDestShortAddr)
|
||||
fclose (pFile);
|
||||
}
|
||||
|
||||
// WriteShortAddr_DistAddr2Zigbee(localAddr,pDestShortAddr);//永久参数配置
|
||||
/* char tmpbuf[8] = {0x00};
|
||||
* unsigned short localAddr = 0x9999;
|
||||
sprintf(tmpbuf,"%02x%02x",pDestShortAddr[0],pDestShortAddr[1]);
|
||||
m_strDestShortAddr = std::string(tmpbuf);
|
||||
modify_distaddr_info(localAddr,"",pDestShortAddr);//临时参数配置
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x9999;*/
|
||||
|
||||
unsigned char Data[12]={0x00};
|
||||
unsigned char size[4]={0x00};
|
||||
@ -1118,19 +1012,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
{
|
||||
string strTime = GetLocalTimeWithMs();
|
||||
LOG_INFO("UpdateWirelessNode start = %s UpdateWirelessNode id = %02x %02x\n",strTime.c_str(),UINT16_HIGH(shortAdd),UINT16_LOW(shortAdd));
|
||||
/*std::string strFileName = "",strSoftVersion = "";
|
||||
std::vector <DataNodeUpdate> vecDataNodeUpdate;
|
||||
vecDataNodeUpdate = ReadStrUpdate("/opt/DataNode/config.json");
|
||||
|
||||
char gethardVersion_sql[32] = { 0 };
|
||||
sprintf(gethardVersion_sql, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(shortAdd),UINT16_LOW(shortAdd));
|
||||
std::string SoftVersion = sql_ctl->GetData(T_SENSOR_INFO(TNAME), "softVersion", gethardVersion_sql);
|
||||
|
||||
print_info("SoftVersion = %s\n",SoftVersion.c_str());
|
||||
LOG_INFO(" NOW SoftVersion = %s\n",SoftVersion.c_str());*/
|
||||
//////
|
||||
//////
|
||||
//strFileName = "/opt/DataNode/" + strFileName;
|
||||
FILE * pFile=NULL;
|
||||
int thisSize = 0;
|
||||
char *buffer=NULL;
|
||||
@ -1154,7 +1036,6 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
print_info("Start Update!!! file Size = %d\n",thisSize);
|
||||
unsigned char tmp = 0x00;
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
|
||||
//boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
mssleep(1000);
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
for(int j = 0; j < Count;j++){
|
||||
@ -1172,7 +1053,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
tmp +=UpdateData[k];
|
||||
}
|
||||
UpdateData[99] = tmp;
|
||||
// RESEND:
|
||||
|
||||
WriteToUart((const char*)UpdateData,100);
|
||||
if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
@ -1199,15 +1080,14 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
}
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
|
||||
mssleep(2000);
|
||||
// if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
|
||||
// gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
|
||||
memset(UpdateData,0x00,sizeof(UpdateData));
|
||||
//boost::this_thread::sleep(boost::posix_time::milliseconds(5));
|
||||
|
||||
mssleep(5000);
|
||||
}
|
||||
if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
// printf("Count =%d,lastSize = %d\n",Count,lastSize);
|
||||
|
||||
if(lastSize > 0){
|
||||
UpdateData[0]=0xAA;
|
||||
UpdateData[1]=0x55;
|
||||
@ -1224,11 +1104,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
UpdateData[99] = tmp;
|
||||
WriteToUart((const char*)UpdateData,100);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||||
// if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 49){
|
||||
// gpio_set(GlobalConfig::GPIO_G.zigAckreset,0);
|
||||
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
// if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48)gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
// }
|
||||
|
||||
int time = 0;
|
||||
do{
|
||||
int value = gpio_read(GlobalConfig::GPIO_G.zigAckrep);
|
||||
@ -1266,9 +1142,7 @@ void Uart::UpdateWirelessNode(unsigned short shortAdd)
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||
DataNodeUpdateFile = "";
|
||||
// std::vector<RecvData>().swap(m_VecWaveData);
|
||||
// WriteShortAddr2Zigbee(shortAddr);
|
||||
// UpdateZigbeeInfoCtrl();
|
||||
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
LOG_INFO("UpdateWirelessNode end");
|
||||
@ -1280,28 +1154,24 @@ int Uart::UpdateConfig(unsigned char* pDestShortAddr)
|
||||
char whereCon[64] = { 0 };
|
||||
char selCon[100]={0x00};
|
||||
sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", pDestShortAddr[0],pDestShortAddr[1]);
|
||||
//std::string strUpdate = sql_ctl->GetData(T_SENSOR_INFO(TNAME), "UpdateFlag", whereCon);
|
||||
|
||||
vec_t vecResultNode = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
if(vecResultNode.size() <= 0)
|
||||
return -1;
|
||||
if(vecResultNode[41] == "0")
|
||||
{
|
||||
// if(!strncmp(vecResult[1].c_str(),"3",1)){//zm5161
|
||||
// WriteTranTimeout2Zigbee(0x03);
|
||||
// }else if(!strncmp(vecResult[1].c_str(),"4",1)){//aw21
|
||||
// WriteTranTimeout2Zigbee(0x0A);
|
||||
// }
|
||||
|
||||
print_info("UpdateConfig\n");
|
||||
LOG_INFO("UpdateConfig\n");
|
||||
bUpdateconfig = true;
|
||||
unsigned short localAddr = 0x9999;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = ENTER_TRANSMITTING_STATUS;
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||
// WriteShortAddr_DistAddr2Zigbee(localAddr,pDestShortAddr);//永久参数配置
|
||||
|
||||
char tmpbuf[8] = {0x00};
|
||||
sprintf(tmpbuf,"%02x%02x",pDestShortAddr[0],pDestShortAddr[1]);
|
||||
m_strDestShortAddr = std::string(tmpbuf);
|
||||
//modify_distaddr_info(localAddr,"",pDestShortAddr);//临时参数配置
|
||||
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x9999;
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
|
||||
vec_t vecResult;
|
||||
@ -1532,17 +1402,13 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*,
|
||||
if(modifyaddr)
|
||||
modify_DistAddr(pDestShortAddr);
|
||||
mssleep(10000);
|
||||
//print_info("nodewaveindex = %d,nodetime = %d,nodeindex = %d\n",nodewaveindex,nodetime,nodeindex);
|
||||
|
||||
char localtimestamp[32]={0x00};
|
||||
int millisecond = 0;
|
||||
|
||||
string rtcTime = GetRTC(localtimestamp,millisecond);
|
||||
LOG_INFO("ShortAddr = %02x%02x,rtcTime = %s,localtimestamp = %s,millisecond = %d,bSendTimeStamp = %d \n",pDestShortAddr[0],pDestShortAddr[1],rtcTime.c_str(),localtimestamp,millisecond,bSendTimeStamp);
|
||||
// struct timeval tv;
|
||||
// gettimeofday(&tv, NULL);
|
||||
// int millisecond = tv.tv_usec / 1000;
|
||||
|
||||
// sprintf(localtimestamp, "%ld", tv.tv_sec);
|
||||
|
||||
unsigned char UpdateData[100]={0x00};
|
||||
UpdateData[0]=0xAA;
|
||||
@ -1559,10 +1425,7 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*,
|
||||
UpdateData[11]=UINT32_HIGH_1(atol(localtimestamp));
|
||||
UpdateData[12]=UINT16_LOW(millisecond);
|
||||
UpdateData[13]=UINT16_HIGH(millisecond);
|
||||
//UpdateData[13]=UINT16_HIGH(nodetime);
|
||||
//UpdateData[14]=UINT16_LOW(nodetime);
|
||||
//UpdateData[15]=UINT16_LOW(nodewaveindex);
|
||||
//UpdateData[16]=UINT16_LOW(nodeindex);
|
||||
|
||||
unsigned char tmp = 0x00;
|
||||
for(int k = 0; k < 99;k++){
|
||||
tmp += UpdateData[k];
|
||||
@ -1597,20 +1460,8 @@ void Uart::DealRecvData(const char *pData)
|
||||
DealDataNodeFeature(pData, 0);
|
||||
}
|
||||
break;
|
||||
/* case 3:{//0x03:长波形X轴
|
||||
DealDataNodeWave(pData);
|
||||
}
|
||||
break;
|
||||
case 4:{//0x04:长波形Y轴
|
||||
DealDataNodeWave(pData);
|
||||
}
|
||||
break;
|
||||
case 5:{//0x05:长波形Z轴
|
||||
DealDataNodeWave(pData);
|
||||
}
|
||||
break;*/
|
||||
case 6:{//0x06:特征值+长波形
|
||||
//LOG_INFO("DealDataNodeFeature 06");
|
||||
|
||||
DealDataNodeFeature(pData, 1);
|
||||
}
|
||||
break;
|
||||
@ -1633,7 +1484,6 @@ void Uart::DealDataNodeName(const char* pData)
|
||||
bSendTimeStamp = false;
|
||||
print_info("DealDataNodeName \n");
|
||||
string strTime = GetLocalTimeWithMs();
|
||||
//LOG_INFO("DealDataNodeName Time = %s\n",strTime.c_str());
|
||||
char szShortAdd[8]={0x00};
|
||||
char shortAdd[8]={0x00};
|
||||
char NodeName[64]={0x00};
|
||||
@ -1748,12 +1598,10 @@ void Uart::DealDataNodeInfo(const char *pData)
|
||||
dataNodeInfo.StaticTime = atoi(buf);//特征值发送次数 4 byte
|
||||
printf("StaticTime = %d\n",dataNodeInfo.StaticTime);
|
||||
memset(buf, 0, 32);
|
||||
// sprintf(buf, "%d", BUILD_UINT32(pRecvData->Data[31], pRecvData->Data[32], pRecvData->Data[33], pRecvData->Data[34]));
|
||||
|
||||
dataNodeInfo.WaveTime = BUILD_UINT32(pRecvData->Data[31], pRecvData->Data[32], pRecvData->Data[33], pRecvData->Data[34]);//原始波形发送次数 4 byte
|
||||
|
||||
memset(buf, 0, 32);
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[35], pRecvData->Data[36]);
|
||||
dataNodeInfo.BateryV = BUILD_UINT16(pRecvData->Data[35],pRecvData->Data[36]);//电池电压 2 byte
|
||||
|
||||
memset(buf, 0, 32);
|
||||
@ -1796,29 +1644,23 @@ void Uart::DealDataNodeInfo(const char *pData)
|
||||
memcpy(shortAddr,(unsigned char*)&pRecvData->Data[46],2);
|
||||
modify_DistAddr(shortAddr);//修改目标地址
|
||||
string strTime = GetLocalTimeWithMs();
|
||||
//LOG_INFO("DealDataNodeInfo modify_DistAddr Time = %s\n",strTime.c_str());
|
||||
|
||||
//LOG_INFO("ZigbeeShortAddr = %s,SoftVersion = %s\n",dataNodeInfo.ZigbeeShortAddr.c_str(),dataNodeInfo.SoftVersion.c_str());
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%02x%02x", pRecvData->Data[48], pRecvData->Data[49]);//Zigbee 目标地址 2 byte
|
||||
dataNodeInfo.ZigbeeDesAddr = std::string(buf);
|
||||
//print_info("ZigbeeDesAddr = %s\n",buf);
|
||||
//50 51 52=》序号23 zigbee重试间隔
|
||||
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%02x", pRecvData->Data[50]);//Zigbee 发射功率 1 byte
|
||||
dataNodeInfo.ZigbeePower = atoi(buf);
|
||||
//print_info("ZigbeePower = %s\n",buf);
|
||||
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%d", BUILD_UINT16(00,pRecvData->Data[51]));//Zigbee 重试次数 1 byte
|
||||
dataNodeInfo.ZigbeeRetry = atoi(buf);
|
||||
//print_info("ZigbeeRetry = %s\n",buf);
|
||||
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%d", BUILD_UINT16(00,pRecvData->Data[52]));//Zigbee 重试间隔 1 byte
|
||||
dataNodeInfo.ZigbeeRetryGap = atoi(buf);
|
||||
//print_info("ZigbeeRetryGap = %s\n",buf);
|
||||
|
||||
|
||||
if(dataNodeInfo.ProductNo == "01"){
|
||||
@ -2058,7 +1900,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
char getLongAddr_sql[32] = { 0 };
|
||||
//根据数据包中的传感器的短地址获取数据库中长地址(MAC),在下面判断该传感器是否存在,如果不存在则把数据包丢弃
|
||||
sprintf(getLongAddr_sql, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
//std::string strLongAddr = sql_ctl->GetData(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(ZIGBEELONGADDR), getLongAddr_sql);
|
||||
vec_t vecResult = sql_ctl->GetDataSingleLine(T_SENSOR_INFO(TNAME)," softVersion,dataNodeNo,MeasurementID,ProductNo ",getLongAddr_sql);
|
||||
|
||||
if (vecResult.size() < 1) {
|
||||
@ -2096,7 +1937,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
return;
|
||||
}
|
||||
|
||||
//modify_distaddr_info(0x9999,"",pRecvData->ShortAddr);//临时参数配置
|
||||
|
||||
GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x9999;
|
||||
@ -2169,8 +2009,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
sprintf(updateSql, " StaticTime = StaticTime + 1");
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
//string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
//data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
|
||||
if (vecResult[0] == "3.0" || vecResult[0] == "4.0"){
|
||||
@ -2308,14 +2146,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
sprintf(sztmp,"ALTER TABLE %s ADD COLUMN 'nodeResend'",szTableNameStatic);
|
||||
sql_ctl->CreateTable(sztmp);
|
||||
}
|
||||
// strTmp = "name = '" + string(szTableNameStatic)+ "' and sql LIKE '%zigbeeRSSIType%' ";
|
||||
// row = sql_ctl->GetTableRows(" sqlite_master ",strTmp.c_str());
|
||||
// print_info("row2 = %d\n",row);
|
||||
// if(row == 0){
|
||||
// memset(sztmp,0x00,sizeof(sztmp));
|
||||
// sprintf(sztmp,"ALTER TABLE %s ADD COLUMN 'zigbeeRSSIType'",szTableNameStatic);
|
||||
// sql_ctl->CreateTable(sztmp);
|
||||
// }
|
||||
|
||||
strTmp = "name = '" + string(szTableNameData)+ "' and sql LIKE '%nodeResend%' ";
|
||||
row = sql_ctl->GetTableRows(" sqlite_master ",strTmp.c_str());
|
||||
print_info("row2 = %d\n",row);
|
||||
@ -2610,119 +2441,28 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
dataDymX.Amp5 = lowbit * n;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[27], pRecvData->Data[26]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
// dataDymX.EnvelopEnergy = lowbit * n;
|
||||
|
||||
|
||||
dataDymX.EnvelopEnergy = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[29], pRecvData->Data[28]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
// dataDymX.Phase1 = lowbit * n;
|
||||
|
||||
|
||||
dataDymX.Phase1 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[31], pRecvData->Data[30]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymX.Phase2 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
memset(buf, 0, 8);
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[33], pRecvData->Data[32]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymX.Phase3 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", pRecvData->Data[35], pRecvData->Data[34]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymX.Phase4 = 0;
|
||||
|
||||
memset(whereCon, 0, 1024);
|
||||
@ -2732,7 +2472,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %d,nodeResend = %d ",\
|
||||
dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy,\
|
||||
dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5,dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, nowTimetamp.c_str(),staticIndex,nodeResend);
|
||||
if ( /*0 == sql_ctl->GetTableRows(T_DATA_INFO(TNAME), whereCon)*/(Count * 3 < SAVE_COUNT && lTime < OneWeek ) || strTime.size() == 0) {//1 week
|
||||
if ( (Count * 3 < SAVE_COUNT && lTime < OneWeek ) || strTime.size() == 0) {//1 week
|
||||
char insertSql[1024] = { 0 };
|
||||
memset(insertSql,0x00,sizeof(insertSql));
|
||||
sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%d,'%s','1',%d",
|
||||
@ -2747,7 +2487,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
} else {
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-X").c_str(),strTime.c_str());
|
||||
// sprintf(whereCon, "channelID='%s' and sendMsg = '1' ", (strLongAddr + "-X").c_str());
|
||||
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
|
||||
@ -2977,115 +2717,23 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
dataDymY.Amp5 = lowbit * n;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[55], pRecvData->Data[54]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
// dataDymY.EnvelopEnergy = lowbit * n;
|
||||
|
||||
dataDymY.EnvelopEnergy = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[57], pRecvData->Data[56]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymY.Phase1 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[59], pRecvData->Data[58]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymY.Phase2 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[61], pRecvData->Data[60]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymY.Phase3 = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "%02x%02x", pRecvData->Data[63], pRecvData->Data[62]);
|
||||
// iTemp = (unsigned int)strtol(buf, NULL, 16);
|
||||
// highbit = iTemp >> 14 & 0x3;
|
||||
// lowbit = iTemp & 0x3fff;
|
||||
// switch (highbit)
|
||||
// {
|
||||
// case 0:
|
||||
// n = 0.0001;
|
||||
// break;
|
||||
// case 1:
|
||||
// n = 0.01;
|
||||
// break;
|
||||
// case 2:
|
||||
// n = 1;
|
||||
// break;
|
||||
// case 3:
|
||||
// n = 100;
|
||||
// break;
|
||||
// }
|
||||
|
||||
dataDymY.Phase4 = 0;
|
||||
|
||||
memset(whereCon, 0, 1024);
|
||||
@ -3474,7 +3122,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-Z").c_str(),strTime.c_str());
|
||||
// sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strLongAddr + "-Z").c_str());
|
||||
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
|
||||
@ -3487,8 +3134,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strLongAddr.c_str());
|
||||
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
//string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
//data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
|
||||
//无线传感器Z信息
|
||||
valNodeFeature["dataNodeNo"] = strMeasurementID;
|
||||
valNodeFeature["ChannelId"] = strMeasurementID + "-Z";
|
||||
@ -3597,7 +3243,7 @@ void Uart::DealDataNodeWave(const char *pData,int comand)
|
||||
m_waveCountZ++;
|
||||
}
|
||||
}
|
||||
//print_blue("wave data size is(m_VecWaveData.size) : %d\n",m_VecWaveData.size());
|
||||
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
// 接收到原始数据信息,则更新时间戳,如果三秒种未收到原始数据,则重新从短地址 9999 切换回 短地址 8888
|
||||
@ -3795,8 +3441,6 @@ std::vector<float> Uart::DealData(int iChannel,float coe,int sampleRate,int ACCS
|
||||
}
|
||||
void Uart::DealWave()
|
||||
{
|
||||
//LOG_DEBUG("begin deal Wave data !\n");
|
||||
//print_blue("wave data size is(m_VecWaveData.size) : %d\n",m_VecWaveData.size());
|
||||
std::string strShortAddr = "";
|
||||
std::string strShortAddrTemp;
|
||||
std::string strLongAddr = "";
|
||||
@ -3875,14 +3519,6 @@ void Uart::DealWave()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
//data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
// memset(buf, 0, 8);
|
||||
// sprintf(buf, "%02x%02x", recvTemp.ShortAddr[0], recvTemp.ShortAddr[1]);
|
||||
// std::string strShortAddr = std::string(buf);
|
||||
|
||||
}
|
||||
float Uart::Calcoe(int ran,int iChannel,string& product,int range)
|
||||
{
|
||||
@ -4358,8 +3994,6 @@ void Uart::WriteChanl2Zigbee(unsigned char pad)
|
||||
unsigned char pad1 = pad;
|
||||
unsigned short tmp;
|
||||
tmp = GlobalConfig::Zigbee_G.MyAddr;
|
||||
//swap((char *)&pad1);
|
||||
//swap((char *)&tmp);
|
||||
GlobalConfig::Zigbee_G.Chan = pad1;
|
||||
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
|
||||
|
||||
@ -4375,7 +4009,6 @@ void Uart::WritePanId2Zigbee(unsigned short pad)
|
||||
tmp = GlobalConfig::Zigbee_G.MyAddr;
|
||||
print_info("MyAddr : %d\n", GlobalConfig::Zigbee_G.MyAddr);
|
||||
swap((char *)&pad1);
|
||||
//swap((char *)&tmp);
|
||||
GlobalConfig::Zigbee_G.PanID = pad1;
|
||||
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
|
||||
|
||||
@ -4395,27 +4028,7 @@ void Uart::WriteSpeed2Zigbee()
|
||||
mssleep(10000);
|
||||
gpio_set(GlobalConfig::GPIO_G.zigReset,1);
|
||||
}
|
||||
/*void Uart::WriteLocalAddr(unsigned short id)
|
||||
{
|
||||
gpio_set(116,0);
|
||||
mssleep(10000);
|
||||
gpio_set(116,1);
|
||||
sleep(1);
|
||||
char command[8]={0x00};
|
||||
command[0] = 0xab;
|
||||
command[1] = 0xbc;
|
||||
command[2] = 0xcd;
|
||||
command[3] = 0xdc;
|
||||
command[4] = ((char *)&id)[1];
|
||||
command[5] = ((char *)&id)[0];
|
||||
command[6] = 0x00;
|
||||
command[7] = 0xaa;
|
||||
WriteToUart(command, 8);
|
||||
mssleep(600000);
|
||||
gpio_set(116,0);
|
||||
mssleep(10000);
|
||||
gpio_set(116,1);
|
||||
}*/
|
||||
|
||||
void Uart::WriteTranTimeout2Zigbee(unsigned char Time)
|
||||
{
|
||||
print_info("WriteTranTimeout2Zigbee : %d\n", Time);
|
||||
@ -4437,8 +4050,7 @@ void Uart::WriteShortAddr2Zigbee(unsigned short pad)
|
||||
print_info("WriteShortAddr2Zigbee : %4x\n", (unsigned short)pad);
|
||||
unsigned short pad1 = pad,tmp;
|
||||
tmp = GlobalConfig::Zigbee_G.MyAddr;
|
||||
//swap((char *)&pad1);
|
||||
//swap((char *)&tmp);
|
||||
|
||||
GlobalConfig::Zigbee_G.MyAddr = pad1;
|
||||
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
|
||||
|
||||
@ -4459,7 +4071,7 @@ void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad,unsigned char* pDes
|
||||
sprintf(tmpDest,"%02x%02x",pDestShortAddr[0],pDestShortAddr[1]);
|
||||
memcpy(&GlobalConfig::Zigbee_G.DstAddr,pDestShortAddr,2);
|
||||
GlobalConfig::Zigbee_G.MyAddr = pad1;
|
||||
// GlobalConfig::Zigbee_G.DstAddr = (short)atoi((char*)tmpDest);
|
||||
|
||||
print_info("DstAddr = %x\n",GlobalConfig::Zigbee_G.DstAddr);
|
||||
GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
|
||||
modify_info(tmp, (char *)& GlobalConfig::Zigbee_G);
|
||||
@ -4490,15 +4102,13 @@ void Uart::ZigbeeInit()
|
||||
|
||||
{
|
||||
unsigned short shortAddr = 0x8888;
|
||||
//GlobalConfig::Zigbee_G.MyAddr = shortAddr;
|
||||
//WriteLocalAddr(shortAddr);
|
||||
|
||||
WriteShortAddr2Zigbee(shortAddr);
|
||||
mssleep(100000);
|
||||
// 更新GlobalConfig::ZigbeeInfo_G.MyAddr,用于外部显示
|
||||
|
||||
|
||||
}
|
||||
|
||||
//std::string strPanId = GlobalConfig::MacAddr_G.substr(8);
|
||||
print_info("strPanId : %s\n", strPanId.c_str());
|
||||
print_info("MacAddr_G : %s\n", GlobalConfig::MacAddr_G.c_str());
|
||||
// 新增管理ZigBee代码
|
||||
@ -4508,26 +4118,18 @@ void Uart::ZigbeeInit()
|
||||
print_info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the chan = %u\n",Chan);
|
||||
print_info("ZigbeeInfo_G.Channel=%d\n",GlobalConfig::ZigbeeInfo_G.Channel);
|
||||
if(Chan > 10 && Chan < 27)
|
||||
{
|
||||
//if (Chan != GlobalConfig::ZigbeeInfo_G.Channel)
|
||||
{
|
||||
WriteChanl2Zigbee(Chan);
|
||||
//modify_Localchannel(Chan);
|
||||
mssleep(100000);
|
||||
}
|
||||
|
||||
}
|
||||
print_info("PanID1 = %s,strPanId = %s\n",GlobalConfig::ZigbeeInfo_G.PanID.c_str(),strPanId.c_str());
|
||||
//if (0 != GlobalConfig::ZigbeeInfo_G.PanID.compare(strPanId.c_str()))
|
||||
{
|
||||
|
||||
long lShortAddr = strtol(strPanId.c_str(), NULL, 16);
|
||||
unsigned short panid = lShortAddr & 0xffff;
|
||||
//modify_LocalPanID(panid);
|
||||
|
||||
WritePanId2Zigbee(panid);
|
||||
mssleep(100000);
|
||||
}
|
||||
|
||||
//if (0 != GlobalConfig::ZigbeeInfo_G.MyAddr.compare("8888"))
|
||||
|
||||
print_info("ZigbeeInfo_G.MyAddr=%s\n",GlobalConfig::ZigbeeInfo_G.MyAddr.c_str());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user