123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #ifndef __PLC_MONITOR__HH_
- #define __PLC_MONITOR__HH_
- #include "LibmodbusWrapper.h"
- #include "Runnable.h"
- #include <string.h>
- #include <mutex>
- #include <vector>
- #include <time.h>
- #include "qtmessagedef.h"
- struct whiskboom_laser_value
- {
- float x;
- float y;
- float a;
- float l;
- float w;
- float h;
- int corrected;
- };
- #define WM_LOG_MSG WM_USER+1001
- #define WM_MONITOR_MSG WM_USER+1002
- namespace modbus
- {
- #define REG_PARKSTATUS (0)
- #define REG_WHISKBOOMLASER_STATUS (1)
- #define REG_WHISKBOOMLASER_CENTERX (2)
- #define REG_WHISKBOOMLASER_CENTERY (3)
- #define REG_WHISKBOOMLASER_ANGLEA (4)
- #define REG_WHISKBOOMLASER_LENGTH (5)
- #define REG_WHISKBOOMLASER_WIDTH (6)
- #define REG_WHISKBOOMLASER_HEIGHT (7)
- enum PLC_PARKING_STATUS
- {
- PLC_PARKING_WAIT = 0,
- PCL_PARKING_REQUEST,
- PCL_PARKING_ERROR
- };
- enum LASER_DATA_CORRECT
- {
- eLaser_data_init=0,
- eLaser_data_ok,
- eLaser_data_failed
- };
- enum PCL_LASER_STATUS
- {
- PLC_LASER_READY = 0,
- PLC_LASER_START,
- PLC_LASER_WORKING,
- PLC_LASER_FINISH_OK,
- PLC_LASER_FINISH_FAILED,
- PLC_LASER_ERROR,
- PLC_LASER_PING=254,
- PLC_LASER_PONG
- };
- typedef void(*CommandCallback)(bool On, uint16_t param,void* pointer,int action_type);
- typedef void(*PLCMonitorCallback)(QtMessageData data,void* pointer);
- class CPLCMonitor :
- public CRunnable
- {
- public:
- CPLCMonitor(void* pMainObject=NULL);
- ~CPLCMonitor();
- public:
- int connect(const char *ip, int port, int slave_id);
- void disconnect();
- int reconnect();
- void set_callback(CommandCallback func, PLCMonitorCallback monitorCallback,void* pointer);
- private:
- std::mutex cs_cmd;
- private:
- bool _measure_finished;
- struct whiskboom_laser_value _value;
- public:
- bool setMeasureResult(int addr, struct whiskboom_laser_value * value = NULL);
- void MeasureComplete(bool bOK=true);
- public:
- int write_laserstatus_register(uint16_t value);
- protected:
- CommandCallback m_callback;
- void* m_pointer;
- PLCMonitorCallback m_PlcDataCallback;
- public:
- bool isMonitor() { return _monitoring == true; };
- private:
- bool _monitoring;
- private:
- CLibmodbusWrapper dev;
-
- private:
- clock_t _heartbeat_write_clock;
- private:
- int read_registers(int addr, int nb, uint16_t *dest);
- int write_registers(int addr, int nb, uint16_t *dest);
- int read_register(int addr, uint16_t *dest);
- int write_register(int addr, uint16_t *dest);
- int clear_laserstatus_register(uint16_t value);
- int write_laserresult_register(int addr ,uint16_t *pvalue);
- private:
- static const double PLC_LASER_TIMEOUT_READY;
- static const double PLC_LASER_TIMEOUT_PINGPANG;
- static const double PLC_LASER_TIMEOUT_START;
- static const double PLC_LASER_TIMEOUT_MAXMEASURE;
- public:
- virtual void Run();
- private:
- void Monitoring();
- static void thread_monitor(void* lp);
- void* m_logWnd;
- void* m_laser_data_wnd;
- std::thread* m_thread_read;
- private:
- std::mutex cs_pcl;
- std::string m_strIP;
- int m_port;
- int m_slave_id;
- };
- }
- #endif
|