2024-10-22 19:04:25 +08:00
|
|
|
#ifndef UART_HPP_
|
|
|
|
|
#define UART_HPP_
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
|
#include <boost/container/detail/singleton.hpp>
|
2024-10-23 09:22:06 +08:00
|
|
|
#include "common/common_func.hpp"
|
|
|
|
|
#include "common/global.hpp"
|
|
|
|
|
#include "dbaccess/sql_db.hpp"
|
|
|
|
|
#include "utility/calculation.hpp"
|
2024-10-22 19:04:25 +08:00
|
|
|
|
|
|
|
|
typedef void (*pTestRecvCallBack)(int Status);
|
|
|
|
|
|
|
|
|
|
class Uart {
|
|
|
|
|
public:
|
|
|
|
|
Uart();
|
|
|
|
|
~Uart();
|
|
|
|
|
|
|
|
|
|
void InitZigbeeHW();
|
|
|
|
|
void InitUart(speed_t speed);
|
|
|
|
|
void Close();
|
|
|
|
|
void InitTestUart(speed_t speed);
|
|
|
|
|
void ReadTestUart();
|
|
|
|
|
|
|
|
|
|
void WriteToUart(const char* strSend, int pLen);
|
|
|
|
|
int ReadFromUart();
|
|
|
|
|
void setCallBack(onReceiveUart _callback);
|
|
|
|
|
void Run();
|
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
|
|
void UpdateZigbeeInfo(const char* pData);
|
|
|
|
|
void DealRecvData(const char* pData);
|
|
|
|
|
void DealDataNodeInfo(const char* pData);
|
|
|
|
|
void DealDataNodeName(const char* pData);
|
|
|
|
|
void ZigbeeParameterConfig();
|
|
|
|
|
int ZigbeeTest();
|
|
|
|
|
int UartRecv(int fd, char srcshow, char* buffer);
|
|
|
|
|
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
|
|
|
|
|
|
|
|
|
|
// feature parse
|
|
|
|
|
void DealDataNodeFeature(const char* pData, int flag);
|
2024-10-23 22:25:03 +08:00
|
|
|
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
|
2024-10-22 19:04:25 +08:00
|
|
|
void DealDataNodeWave(const char* pData, int comand);
|
|
|
|
|
void DealWaveThread();
|
|
|
|
|
void DealWave();
|
2024-10-23 22:25:03 +08:00
|
|
|
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
|
|
|
|
|
float Calcoe(int ran, int iChannel, std::string& product, int range);
|
|
|
|
|
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData);
|
2024-10-22 19:04:25 +08:00
|
|
|
float ScaleConvert(int highbit);
|
|
|
|
|
|
|
|
|
|
// command category
|
|
|
|
|
void modify_info(unsigned short id, char* zigbee);
|
|
|
|
|
void modify_distaddr_info(unsigned short id, char* zigbee, unsigned char* distAddr);
|
|
|
|
|
void modify_LocalAddr(unsigned short id);
|
|
|
|
|
void modify_DistAddr(unsigned char* distAddr);
|
|
|
|
|
void modify_Localchannel(unsigned char pad);
|
|
|
|
|
void modify_LocalPanID(unsigned short padID);
|
|
|
|
|
void getZigbeeSignal(unsigned char* distAddr);
|
|
|
|
|
void zigbee_reset(unsigned short pad, unsigned short type);
|
|
|
|
|
void WriteChanl2Zigbee(unsigned char pad);
|
|
|
|
|
void WritePanId2Zigbee(unsigned short pad);
|
|
|
|
|
void WriteSpeed2Zigbee();
|
|
|
|
|
void WriteTranTimeout2Zigbee(unsigned char Time);
|
|
|
|
|
void WriteShortAddr2Zigbee(unsigned short pad);
|
|
|
|
|
void WriteShortAddr_DistAddr2Zigbee(unsigned short pad, unsigned char* pDestShortAddr);
|
|
|
|
|
bool CheckCrc(char* pCheckBuff, int No);
|
|
|
|
|
void UpdateZigbeeInfoCtrl();
|
|
|
|
|
|
|
|
|
|
// tranducer parameter config
|
|
|
|
|
void UpdateWirelessNode(unsigned short shortAdd);
|
|
|
|
|
int UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr);
|
|
|
|
|
int UpdateConfig(unsigned char* pDestShortAddr);
|
|
|
|
|
bool ReadUpdatePackge(unsigned char* shortAddr);
|
|
|
|
|
void openSwitch();
|
|
|
|
|
int CheckZigbeeACK();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
int fd, TestFd;
|
|
|
|
|
bool bUpdate;
|
|
|
|
|
bool bUpdatePre;
|
|
|
|
|
bool bUpdateconfig;
|
|
|
|
|
bool bTest;
|
|
|
|
|
bool bZigbeeSinal;
|
|
|
|
|
bool bModifyAddr;
|
|
|
|
|
bool bSendTimeStamp;
|
|
|
|
|
std::string DataNodeUpdateFile;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
boost::posix_time::ptime mLocalTime;
|
|
|
|
|
boost::asio::io_service mIoSev;
|
|
|
|
|
boost::asio::serial_port mUart;
|
|
|
|
|
int mRdLength;
|
|
|
|
|
int mlastSize;
|
|
|
|
|
int mPackgeIndex;
|
2024-10-23 22:25:03 +08:00
|
|
|
std::string strTimetamp;
|
2024-10-22 19:04:25 +08:00
|
|
|
|
|
|
|
|
std::string m_strDestShortAddr;
|
|
|
|
|
|
|
|
|
|
int waittime;
|
|
|
|
|
enum { BUF_LENGTH = 40960 };
|
|
|
|
|
unsigned char mUartRecvBuf[BUF_LENGTH];
|
|
|
|
|
char mUartRecvTmpBuf[BUF_LENGTH * 15];
|
|
|
|
|
boost::asio::io_service::strand mStrand;
|
|
|
|
|
|
|
|
|
|
onReceiveUart m_callback;
|
|
|
|
|
|
|
|
|
|
unsigned long m_TimeStamp;
|
|
|
|
|
bool wave_trans_;
|
|
|
|
|
int m_waveCountX;
|
|
|
|
|
int m_waveCountY;
|
|
|
|
|
int m_waveCountZ;
|
|
|
|
|
std::vector<RecvData> VecWaveDataX;
|
|
|
|
|
std::vector<RecvData> VecWaveDataY;
|
|
|
|
|
std::vector<RecvData> VecWaveDataZ;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef boost::container::dtl::singleton_default<Uart> uart_inst;
|
|
|
|
|
#endif // UART_HPP_
|