fix bugs
This commit is contained in:
parent
2781b79775
commit
762b1e4899
@ -230,8 +230,8 @@ int config_uart(const char *port, int speed) {
|
|||||||
opt.c_oflag &= ~(OPOST);
|
opt.c_oflag &= ~(OPOST);
|
||||||
opt.c_cflag &= ~(CSIZE | PARENB | CBAUD);
|
opt.c_cflag &= ~(CSIZE | PARENB | CBAUD);
|
||||||
opt.c_cflag |= (CS8 | speed);
|
opt.c_cflag |= (CS8 | speed);
|
||||||
opt.c_cc[VMIN] = 255;
|
opt.c_cc[VMIN] = 1;
|
||||||
opt.c_cc[VTIME] = 5;
|
opt.c_cc[VTIME] = 1;
|
||||||
if (tcsetattr(iFd, TCSANOW, &opt) < 0) {
|
if (tcsetattr(iFd, TCSANOW, &opt) < 0) {
|
||||||
zlog_error(zbt, "tcsetattr failed");
|
zlog_error(zbt, "tcsetattr failed");
|
||||||
return -2;
|
return -2;
|
||||||
|
|||||||
@ -80,7 +80,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
ret = read_data(fd, buff, BUF_LENGTH, 50);
|
ret = read_data(fd, buff, BUF_LENGTH, 10);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -120,6 +120,8 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
|
|||||||
VecWaveDataY.reserve(1000);
|
VecWaveDataY.reserve(1000);
|
||||||
VecWaveDataZ.reserve(1500);
|
VecWaveDataZ.reserve(1500);
|
||||||
memset(send_data, 0, sizeof(send_data));
|
memset(send_data, 0, sizeof(send_data));
|
||||||
|
last_short_addr = 0;
|
||||||
|
last_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uart::~Uart() {
|
Uart::~Uart() {
|
||||||
@ -552,6 +554,30 @@ int Uart::DealUpgrade(uint16_t ushortAdd,int status){
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
|
||||||
|
zlog_info(zct, "DealFeatureValue ");
|
||||||
|
char localtimestamp[32] = {0};
|
||||||
|
GetTimeNet(localtimestamp, 1);
|
||||||
|
std::string nowTimetamp = std::string(localtimestamp);
|
||||||
|
long now_time = atol(nowTimetamp.c_str());
|
||||||
|
if(ushortAdd == last_short_addr && (now_time - last_time) < 5){
|
||||||
|
zlog_info(zct, "DealFeatureValue short_addr_last = %02x%02x,timestamp_last = %ld,nowTime = %ld",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd),last_time,now_time);
|
||||||
|
int iRet = DealDataNodeFeature(pData, 0);
|
||||||
|
if (iRet != 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
DealAskTask(ushortAdd);
|
||||||
|
}else {
|
||||||
|
DealAskTask(ushortAdd);
|
||||||
|
DealDataNodeFeature(pData, 0);
|
||||||
|
}
|
||||||
|
last_short_addr = ushortAdd;
|
||||||
|
GetTimeNet(localtimestamp, 1);
|
||||||
|
nowTimetamp = std::string(localtimestamp);
|
||||||
|
last_time = atol(nowTimetamp.c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void Uart::DealRecvData(const char *pData) {
|
void Uart::DealRecvData(const char *pData) {
|
||||||
|
|
||||||
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
|
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
|
||||||
@ -564,7 +590,7 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
ModifyDistAddr(ushortAdd);
|
ModifyDistAddr(ushortAdd);
|
||||||
mssleep(50000);
|
mssleep(50000);
|
||||||
int iRet = 0;
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case DEVICE_INF:
|
case DEVICE_INF:
|
||||||
DealDataNodeInfo(pData);
|
DealDataNodeInfo(pData);
|
||||||
@ -579,10 +605,7 @@ void Uart::DealRecvData(const char *pData) {
|
|||||||
DealException(pData);
|
DealException(pData);
|
||||||
break;
|
break;
|
||||||
case MEAS_EVAL:
|
case MEAS_EVAL:
|
||||||
iRet = DealDataNodeFeature(pData, 0);
|
DealFeatureValue(pData, ushortAdd);
|
||||||
if (iRet == 0){
|
|
||||||
DealAskTask(ushortAdd);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case UPGRADE:
|
case UPGRADE:
|
||||||
if (recvcode == 0){
|
if (recvcode == 0){
|
||||||
|
|||||||
@ -175,6 +175,7 @@ public:
|
|||||||
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
|
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
|
||||||
|
|
||||||
int DealAskTask(uint16_t ushortAdd);
|
int DealAskTask(uint16_t ushortAdd);
|
||||||
|
int DealFeatureValue(const char* pData, uint16_t ushortAdd);
|
||||||
int DealException(const char* pData);
|
int DealException(const char* pData);
|
||||||
int DealReviveDuration(uint16_t ushortAdd);
|
int DealReviveDuration(uint16_t ushortAdd);
|
||||||
int DealConfig(uint16_t ushortAdd);
|
int DealConfig(uint16_t ushortAdd);
|
||||||
@ -264,6 +265,8 @@ private:
|
|||||||
std::vector<RecvData> VecWaveDataZ;
|
std::vector<RecvData> VecWaveDataZ;
|
||||||
|
|
||||||
uint8_t send_data[100];
|
uint8_t send_data[100];
|
||||||
|
uint16_t last_short_addr;
|
||||||
|
long last_time;
|
||||||
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user