fix bugs
This commit is contained in:
parent
b8c1c34797
commit
2781b79775
@ -86,6 +86,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
}
|
}
|
||||||
if (srcshow) {
|
if (srcshow) {
|
||||||
zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret);
|
zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret);
|
||||||
|
printf("\ncurrent time = %s\n", GetCurrentTime().c_str());
|
||||||
for (int i = 0; i < ret; i++) {
|
for (int i = 0; i < ret; i++) {
|
||||||
printf("[%02x]", buff[i] & 0xff);
|
printf("[%02x]", buff[i] & 0xff);
|
||||||
}
|
}
|
||||||
@ -118,6 +119,7 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
|||||||
VecWaveDataX.reserve(1000);
|
VecWaveDataX.reserve(1000);
|
||||||
VecWaveDataY.reserve(1000);
|
VecWaveDataY.reserve(1000);
|
||||||
VecWaveDataZ.reserve(1500);
|
VecWaveDataZ.reserve(1500);
|
||||||
|
memset(send_data, 0, sizeof(send_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Uart::~Uart() {
|
Uart::~Uart() {
|
||||||
@ -227,7 +229,7 @@ int Uart::ZigbeeTest() {
|
|||||||
void Uart::WriteToUart(const char *strSend, int pLen) {
|
void Uart::WriteToUart(const char *strSend, int pLen) {
|
||||||
if (!bUpdate)
|
if (!bUpdate)
|
||||||
{
|
{
|
||||||
printf( "Write To Uart Start:\n");
|
printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str());
|
||||||
for (int i = 0; i < pLen; i++) {
|
for (int i = 0; i < pLen; i++) {
|
||||||
printf("%02X ", *(strSend + i) & 0xFF);
|
printf("%02X ", *(strSend + i) & 0xFF);
|
||||||
}
|
}
|
||||||
@ -334,7 +336,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
|
zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ModifyDistAddr(ushortAdd);
|
|
||||||
int next_duration = 0,next_task_id = 0;
|
int next_duration = 0,next_task_id = 0;
|
||||||
int taskID;
|
int taskID;
|
||||||
ScheduleTask scheduleTask;
|
ScheduleTask scheduleTask;
|
||||||
@ -346,7 +347,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
scheduleTask.duration = next_duration;
|
scheduleTask.duration = next_duration;
|
||||||
scheduleTask.next_taskID = next_task_id;
|
scheduleTask.next_taskID = next_task_id;
|
||||||
scheduleTask.shortAddr = ushortAdd;
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
mssleep(50000);
|
|
||||||
TaskResp(scheduleTask);
|
TaskResp(scheduleTask);
|
||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
UpdateConfig(ushortAdd);
|
UpdateConfig(ushortAdd);
|
||||||
@ -432,8 +432,6 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
|||||||
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||||
|
|
||||||
zlog_info(zct, "DealWaveCompress ");
|
zlog_info(zct, "DealWaveCompress ");
|
||||||
ModifyDistAddr(ushortAdd);
|
|
||||||
mssleep(50000);
|
|
||||||
now_task = WAVE_CMD;
|
now_task = WAVE_CMD;
|
||||||
WaveResp(ushortAdd);
|
WaveResp(ushortAdd);
|
||||||
char buf[20] = {0x00};
|
char buf[20] = {0x00};
|
||||||
@ -563,6 +561,10 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
int taskID = 0;
|
int taskID = 0;
|
||||||
ScheduleTask scheduleTask;
|
ScheduleTask scheduleTask;
|
||||||
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
|
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
|
||||||
|
mssleep(50000);
|
||||||
|
ModifyDistAddr(ushortAdd);
|
||||||
|
mssleep(50000);
|
||||||
|
int iRet = 0;
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case DEVICE_INF:
|
case DEVICE_INF:
|
||||||
DealDataNodeInfo(pData);
|
DealDataNodeInfo(pData);
|
||||||
@ -577,10 +579,10 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
DealException(pData);
|
DealException(pData);
|
||||||
break;
|
break;
|
||||||
case MEAS_EVAL:
|
case MEAS_EVAL:
|
||||||
|
iRet = DealDataNodeFeature(pData, 0);
|
||||||
|
if (iRet == 0){
|
||||||
DealAskTask(ushortAdd);
|
DealAskTask(ushortAdd);
|
||||||
DealDataNodeFeature(pData, 0);
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case UPGRADE:
|
case UPGRADE:
|
||||||
if (recvcode == 0){
|
if (recvcode == 0){
|
||||||
@ -611,7 +613,6 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
DealWaveCompress(pData,ushortAdd);
|
DealWaveCompress(pData,ushortAdd);
|
||||||
break;
|
break;
|
||||||
case UPGRADE_ASK:
|
case UPGRADE_ASK:
|
||||||
ModifyDistAddr(ushortAdd);
|
|
||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
|
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
|
||||||
taskID = kScheduleUpgrade;
|
taskID = kScheduleUpgrade;
|
||||||
@ -1239,9 +1240,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
|||||||
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
||||||
DealDataNodeWave(RecvBuf, command);
|
DealDataNodeWave(RecvBuf, command);
|
||||||
mPackgeIndex = (unsigned int)UartRecvBuf[i + 6];
|
mPackgeIndex = (unsigned int)UartRecvBuf[i + 6];
|
||||||
} else if (now_task != WAVE_CMD && (command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) {
|
} else if (now_task != WAVE_CMD && ( command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) {
|
||||||
char RecvBuf[100] = {0x00};
|
char RecvBuf[100] = {0x00};
|
||||||
if (command == ASK_TASK || command == UPGRADE_ASK)
|
if (command == UPGRADE_ASK)
|
||||||
{
|
{
|
||||||
memcpy(RecvBuf, &UartRecvBuf[i], 8);
|
memcpy(RecvBuf, &UartRecvBuf[i], 8);
|
||||||
if (!CheckCrc(RecvBuf, 7)) {
|
if (!CheckCrc(RecvBuf, 7)) {
|
||||||
|
|||||||
@ -184,7 +184,7 @@ public:
|
|||||||
void GetLocalZigbeeRSSI(uint16_t ushortAdd);
|
void GetLocalZigbeeRSSI(uint16_t ushortAdd);
|
||||||
|
|
||||||
// feature parse
|
// feature parse
|
||||||
void DealDataNodeFeature(const char* pData, int flag);
|
int DealDataNodeFeature(const char* pData, int flag);
|
||||||
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
||||||
void DealDataNodeWave(const char* pData, int comand);
|
void DealDataNodeWave(const char* pData, int comand);
|
||||||
void DealWaveThread();
|
void DealWaveThread();
|
||||||
@ -262,6 +262,9 @@ private:
|
|||||||
std::vector<RecvData> VecWaveDataX;
|
std::vector<RecvData> VecWaveDataX;
|
||||||
std::vector<RecvData> VecWaveDataY;
|
std::vector<RecvData> VecWaveDataY;
|
||||||
std::vector<RecvData> VecWaveDataZ;
|
std::vector<RecvData> VecWaveDataZ;
|
||||||
|
|
||||||
|
uint8_t send_data[100];
|
||||||
|
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::container::dtl::singleton_default<Uart> uart_inst;
|
typedef boost::container::dtl::singleton_default<Uart> uart_inst;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) {
|
|||||||
n = ScaleConvert(highbit);
|
n = ScaleConvert(highbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
int Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||||
RecvData *pRecvData = (RecvData *)pData;
|
RecvData *pRecvData = (RecvData *)pData;
|
||||||
char whereCon[1024] = {0};
|
char whereCon[1024] = {0};
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
@ -66,7 +66,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
|
|
||||||
if (vecResult.size() < 1) {
|
if (vecResult.size() < 1) {
|
||||||
zlog_warn(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
zlog_warn(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str());
|
zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str());
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
|
|
||||||
|
|
||||||
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
|
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
|
||||||
return;
|
return -2;
|
||||||
}
|
}
|
||||||
long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
|
||||||
|
|
||||||
@ -153,7 +153,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
char logInfo[100] = {0x00};
|
char logInfo[100] = {0x00};
|
||||||
sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2);
|
sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2);
|
||||||
zlog_info(zct, logInfo);
|
zlog_info(zct, logInfo);
|
||||||
return;
|
std::vector<uint8_t>& data_vec = map_send_data[u_short_addr];
|
||||||
|
const uint8_t* send_data = data_vec.data();
|
||||||
|
WriteToUart((const char*)send_data, 100);
|
||||||
|
return -3;
|
||||||
}
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
||||||
@ -598,6 +601,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
if (flag == 1) {
|
if (flag == 1) {
|
||||||
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); }
|
float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); }
|
||||||
|
|||||||
@ -550,51 +550,57 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /
|
|||||||
}
|
}
|
||||||
int Uart::TaskResp(ScheduleTask scheduleTask){
|
int Uart::TaskResp(ScheduleTask scheduleTask){
|
||||||
|
|
||||||
unsigned char UpdateData[100] = {0};
|
memset(send_data,0,sizeof(send_data));
|
||||||
UpdateData[0] = 0xAA;
|
send_data[0] = 0xAA;
|
||||||
UpdateData[1] = 0x55;
|
send_data[1] = 0x55;
|
||||||
UpdateData[2] = 0xAA;
|
send_data[2] = 0xAA;
|
||||||
UpdateData[3] = (scheduleTask.shortAddr >> 8) & 0xFF;
|
send_data[3] = (scheduleTask.shortAddr >> 8) & 0xFF;
|
||||||
UpdateData[4] = scheduleTask.shortAddr & 0xFF;
|
send_data[4] = scheduleTask.shortAddr & 0xFF;
|
||||||
UpdateData[5] = scheduleTask.cmd & 0xFF;
|
send_data[5] = scheduleTask.cmd & 0xFF;
|
||||||
UpdateData[6] = 0x00;
|
send_data[6] = 0x00;
|
||||||
char localtimestamp[32] = {0x00};
|
char localtimestamp[32] = {0x00};
|
||||||
int millisecond = 0;
|
int millisecond = 0;
|
||||||
std::string rtcTime = GetRTC(localtimestamp, millisecond);
|
std::string rtcTime = GetRTC(localtimestamp, millisecond);
|
||||||
scheduleTask.timeStamp = atoi(localtimestamp);
|
scheduleTask.timeStamp = atoi(localtimestamp);
|
||||||
zlog_info(zct,"next taskID = %d\n",scheduleTask.next_taskID);
|
zlog_info(zct,"next taskID = %d\n",scheduleTask.next_taskID);
|
||||||
|
|
||||||
UpdateData[7] = UINT16_LOW(scheduleTask.duration);
|
send_data[7] = UINT16_LOW(scheduleTask.duration);
|
||||||
UpdateData[8] = UINT16_HIGH(scheduleTask.duration);
|
send_data[8] = UINT16_HIGH(scheduleTask.duration);
|
||||||
UpdateData[9] = UINT32_LOW_2(scheduleTask.timeStamp);
|
send_data[9] = UINT32_LOW_2(scheduleTask.timeStamp);
|
||||||
UpdateData[10] = UINT32_LOW_1(scheduleTask.timeStamp);
|
send_data[10] = UINT32_LOW_1(scheduleTask.timeStamp);
|
||||||
UpdateData[11] = UINT32_HIGH_2(scheduleTask.timeStamp);
|
send_data[11] = UINT32_HIGH_2(scheduleTask.timeStamp);
|
||||||
UpdateData[12] = UINT32_HIGH_1(scheduleTask.timeStamp);
|
send_data[12] = UINT32_HIGH_1(scheduleTask.timeStamp);
|
||||||
UpdateData[20] = scheduleTask.acc_z;
|
send_data[20] = scheduleTask.acc_z;
|
||||||
UpdateData[21] = scheduleTask.next_taskID & 0xFF;
|
send_data[21] = scheduleTask.next_taskID & 0xFF;
|
||||||
UpdateData[22] = UINT16_LOW(scheduleTask.millisecond);
|
send_data[22] = UINT16_LOW(scheduleTask.millisecond);
|
||||||
UpdateData[23] = UINT16_HIGH(scheduleTask.millisecond);
|
send_data[23] = UINT16_HIGH(scheduleTask.millisecond);
|
||||||
|
|
||||||
if (scheduleTask.next_taskID == WAVE_CMD)
|
if (scheduleTask.next_taskID == WAVE_CMD)
|
||||||
{
|
{
|
||||||
uint8_t x,y,z;
|
uint8_t x,y,z;
|
||||||
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
|
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
|
||||||
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
|
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
|
||||||
UpdateData[17] = (x^1) & 0xFF;
|
send_data[17] = (x^1) & 0xFF;
|
||||||
UpdateData[18] = (y^1) & 0xFF;
|
send_data[18] = (y^1) & 0xFF;
|
||||||
UpdateData[19] = (z^1) & 0xFF;
|
send_data[19] = (z^1) & 0xFF;
|
||||||
}
|
}
|
||||||
unsigned char tmp = 0x00;
|
unsigned char tmp = 0x00;
|
||||||
for (int k = 0; k < 99; k++) {
|
for (int k = 0; k < 99; k++) {
|
||||||
tmp += UpdateData[k];
|
tmp += send_data[k];
|
||||||
}
|
}
|
||||||
UpdateData[99] = tmp;
|
send_data[99] = tmp;
|
||||||
mssleep(10000);
|
if (scheduleTask.cmd != REVIVE_DURATION)
|
||||||
WriteToUart((const char*)UpdateData, 100);
|
{
|
||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
WriteToUart((const char*)UpdateData, 100);
|
WriteToUart((const char*)send_data, 100);
|
||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
WriteToUart((const char*)UpdateData, 100);
|
WriteToUart((const char*)send_data, 100);
|
||||||
|
}else {
|
||||||
|
map_send_data[scheduleTask.shortAddr] = std::vector<uint8_t>(send_data, send_data + 100);
|
||||||
|
}
|
||||||
|
mssleep(50000);
|
||||||
|
WriteToUart((const char*)send_data, 100);
|
||||||
|
|
||||||
int iRet = CheckZigbeeACK();
|
int iRet = CheckZigbeeACK();
|
||||||
if (iRet == 0) {
|
if (iRet == 0) {
|
||||||
zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));
|
zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user