118 lines
3.9 KiB
C++
118 lines
3.9 KiB
C++
#ifndef _UART_H_
|
|
#define _UART_H_
|
|
#include <list>
|
|
#include <map>
|
|
#include <iostream>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/thread/mutex.hpp>
|
|
#include <boost/unordered_set.hpp>
|
|
#include <boost/unordered_map.hpp>
|
|
#include "../utility/SH_MySingleton.hpp"
|
|
#include "../common/SH_CommonFunc.hpp"
|
|
#include "../common/SH_global.h"
|
|
#include "../dbaccess/SH_SqlDB.hpp"
|
|
#include "../calculation/Calculation.hpp"
|
|
|
|
|
|
|
|
//using namespace boost::asio;
|
|
//using std::string;
|
|
//using boost::system::error_code;
|
|
typedef unsigned int UINT;
|
|
|
|
typedef void (*pTestRecvCallBack)(int Status);
|
|
|
|
class Uart : public MySingleton<Uart>
|
|
{
|
|
private :
|
|
boost::posix_time::ptime mLocalTime;
|
|
boost::asio::io_service mIoSev;
|
|
boost::asio::serial_port mUart;
|
|
int mRdLength;
|
|
int mlastSize;
|
|
int mPackgeIndex;
|
|
string strTimetamp;
|
|
|
|
//DataNodeInfo dataNodeInfo;
|
|
std::string m_strDestShortAddr;
|
|
int waittime;
|
|
enum{BUF_LENGTH = 40960};
|
|
unsigned char mUartRecvBuf[BUF_LENGTH];
|
|
char mUartRecvTmpBuf[BUF_LENGTH*15];
|
|
boost::mutex mLock;
|
|
boost::asio::io_service::strand mStrand;
|
|
|
|
public :
|
|
Uart();
|
|
~Uart();
|
|
void InitZigbee();
|
|
void InitUart(speed_t speed);
|
|
void Close();
|
|
void InitTestUart(speed_t speed);
|
|
void ReadTestUart();
|
|
int fd,TestFd;
|
|
bool bUpdate;
|
|
bool bUpdatePre;
|
|
bool bUpdateconfig;
|
|
bool bTest;
|
|
bool bZigbeeSinal;
|
|
bool bModifyAddr;
|
|
bool bSendTimeStamp;
|
|
std::string DataNodeUpdateFile;
|
|
void WriteToUart(const char *strSend,int pLen);
|
|
int ReadFromUart();
|
|
void setCallBack(onReceiveUart _callback);
|
|
void Run();
|
|
void Stop();
|
|
void UpdateZigbeeInfoCtrl();
|
|
void UpdateZigbeeInfo(const char *pData);
|
|
void DealRecvData(const char *pData);
|
|
void DealDataNodeInfo(const char *pData);
|
|
void DealDataNodeName(const char *pData);
|
|
void DealDataNodeFeature(const char *pData, int flag);
|
|
void DealDataNodeWave(const char *pData);
|
|
void DealWaveThread();
|
|
void DealWave();
|
|
void DealNodeSendTime(unsigned char* shortaddr);
|
|
void ZigbeeInit();
|
|
int ZigbeeTest();
|
|
void RecordBattery(string & strLongAddr,DataRecvStatic& dataStatic,string& nowTimetamp);
|
|
|
|
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 WriteLocalAddr(unsigned short id);
|
|
void WriteTranTimeout2Zigbee(unsigned char Time);
|
|
void WriteShortAddr2Zigbee(unsigned short pad);
|
|
void WriteShortAddr_DistAddr2Zigbee(unsigned short pad,unsigned char* pDestShortAddr);
|
|
void UpdateWirelessNode(unsigned short shortAdd);
|
|
void UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*,int nodewaveindex,int nodetime,int nodeindex*/);
|
|
int UpdateConfig(unsigned char* pDestShortAddr);
|
|
bool ReadUpdatePackge(unsigned char* shortAddr);
|
|
bool CheckCrc(char* pCheckBuff,int No);
|
|
int FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head);
|
|
virtual void DataAnalysis_R(DevDataOfGwid &pData);
|
|
virtual void DataAnalysis_W(DevData &pData,bool pFlag);
|
|
virtual void ThreadInit();
|
|
int UartRecv(int fd, char srcshow,char* buffer);
|
|
void openSwitch();
|
|
private :
|
|
void ReadHandle(char* pUartRecvBuf,size_t bytesRead);
|
|
void WriteHandle(const char *strSend,const boost::system::error_code &ec,size_t bytesWrite);
|
|
onReceiveUart m_callback;
|
|
std::vector<RecvData> m_VecWaveData;
|
|
unsigned long m_TimeStamp;
|
|
bool m_waveTrans;
|
|
};
|
|
|
|
|
|
#endif
|