123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #pragma once
- #include "LibmodbusWrapper.h"
- #include "Runnable.h"
- //#include "CriticalSection.h"
- #include "Spinlock.h"
- #include <vector>
- #include <time.h>
- struct whiskboom_laser_value
- {
- float x;
- float y;
- float a;
- float l;
- float w;
- float h;
- BOOL corrected;
- };
- #define WM_LOG_MSG WM_USER+1001
- #define WM_MONITOR_MSG WM_USER+1002
- namespace modbus
- {
- #define REG_PARKSTATUS (42)
- #define REG_WHISKBOOMLASER_STATUS (43)
- #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);
- class CPLCMonitor :
- public CRunnable
- {
- public:
- CPLCMonitor(void* pOwnerObject=NULL);
- ~CPLCMonitor();
- public:
- int connect(const char *ip, int port, int slave_id);
- void disconnect();
- int reconnect();
- void set_callback(CommandCallback func, void* pointer);
- private:
- SpinLock cs_cmd;
- volatile LONG m_lock_cmd_Value;
- private:
- BOOL _measure_finished;
- struct whiskboom_laser_value _value;
- public:
- // void setMeasureResult(BOOL corrected = FALSE, struct whiskboom_laser_value * value = NULL);
- 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;
- 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 clock_t PLC_LASER_TIMEOUT_READY;
- static const clock_t PLC_LASER_TIMEOUT_PINGPANG;
- static const clock_t PLC_LASER_TIMEOUT_START;
- static const clock_t PLC_LASER_TIMEOUT_MAXMEASURE;
- public:
- virtual void Run();
- void SetLogWnd(CWnd* wnd,CWnd* laser_wnd=0) {
- m_logWnd = wnd;
- m_laser_data_wnd = laser_wnd;
- }
- private:
- void Monitoring();
- static UINT thread_monitor(LPVOID lp);
- CWnd* m_logWnd;
- CWnd* m_laser_data_wnd;
- CWinThread* m_thread_read;
- private:
- //CCriticalSection cs;
- SpinLock cs_pcl;
- volatile LONG m_lockValue;
- std::string m_strIP;
- int m_port;
- int m_slave_id;
- };
- }
|