|
|
#ifndef __OBJECT_NET_NODE_2D_HEADERS__
#define __OBJECT_NET_NODE_2D_HEADERS__
#include "../../alg/lgs/mask.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMutex.h"
#include "../../components/base/basicObject.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicThread.h"
#include "../../data/protocol/protocolLGS2D.h"
#include "../../data/rfs/fs_helper.h"
#include "deviceNodeSensor.h"
#include <cfloat> //For DBL_MAX
#include <stdlib.h>
#include <sys/stat.h>
#define SEND_MASKS_VIA_FILE
// #define SIMULATE_2D_TARGETS
#ifdef SIMULATE_2D_TARGETS
#define PERSISTED_TARGET_SIM
#endif
// To Save rasterized masks
#ifndef LRF_PROXY_ONLY
#ifdef DEBUG
#include <opencv2/opencv.hpp>
#endif
#endif
typedef enum E_WORKING_STATE_LRF2D{ WS_2D_BEFORE_START = 0, WS_2D_CREATE_PORT = 1, WS_2D_CONNECT, WS_2D_WAIT_CONNECT, WS_2D_SET_BORDER_MODE, WS_2D_SET_DETECTION_MODE, WS_2D_SET_GETFILE_MODE, WS_2D_SET_FILESYSTEM_MODE, WS_2D_GET_SERIAL_NUM, WS_2D_GET_VERSION, WS_2D_GET_DETECTION_PROFILE, WS_2D_GET_MASTER_PARAM, WS_2D_GET_SLAVE_PARAM, WS_2D_GET_MASK_INFO, WS_2D_SET_MASK_INFO, WS_2D_GET_FAST_DRAW, WS_2D_SET_SHADOW_DONE, WS_2D_GET_SHADOW_POLY_INFO, WS_2D_GET_SHADOW_POLY_POINT, WS_2D_SET_SHADOW_POLY_INFO, WS_2D_SET_SHADOW_POLY_POINT, WS_2D_SET_SHADOW_RAY_LINE, WS_2D_SET_SHADOW_RAY, WS_2D_SEND_GETFILE_MODE, WS_2D_SET_MASTER_PARAM, WS_2D_SET_SLAVE_PARAM, WS_2D_ISSUE_FULL_RESET, WS_2D_ISSUE_RESET, WS_2D_FS_READY, WS_2D_GET_FS_CURDIR, WS_2D_READ_FILE, WS_2D_SAVE_FILE, WS_2D_FS_FETCH_NEXT_PART, WS_2D_FS_OPERATION_FINISHED, WS_2D_FS_OPERATION_ABORTED, WS_2D_PING, WS_2D_PONG, WS_2D_SLEEP_AND_RECONNECT, WS_2D_WAIT_DEVICE_REPLAY, WS_2D_WAIT_CHECK_REPLAY} WORKING_STATE_LRF2D;
typedef struct S_SHADOW_IO_HELPER{ uint16_t m_nCurrentPolygon; uint16_t m_nCurrentPoint; uint16_t m_nCurrentRayLine; uint16_t m_nCurrentRay; uint8_t m_bSequence;} SHADOW_IO_HELPER;
typedef struct S_GETFILE_IO_HELPER{ uint32_t fileSize; uint8_t index; char destName[33]; char sourceName[33]; uint8_t state; uint32_t db_id; FILE * fd; uint8_t data[250]; uint8_t data_size;} GETFILE_IO_HELPER;
typedef std::vector<GETFILE_IO_HELPER *> VECTOR_GF_HELPERS;
typedef enum E_GF_ENDING_MODE{ GF_EM_DO_NOTHING = 0, GF_EM_ISSUE_RESET = 1, GF_EM_ISSUE_SAVE_FW = 2,} GF_ENDING_MODE;
typedef struct S_GF_HELPER_STRUCT{ VECTOR_GF_HELPERS helpers; uint8_t current; uint8_t transfer_ending_mode;} GF_HELPER_STRUCT;
typedef struct S_TEST_POINT{ float x; float y;} TEST_POINT;
typedef enum E_COMMAND_SEQUENCE_TYPE{ NO_SEQUENCE = 0, SET_DEVICE_ID = 1, SET_DEVCOM_SPEED, SET_DETECTION_PARAMETERS, SET_SHADOWS, SET_HW_PARAMS, FREEZE_TH, SAVE_ALL_TO_FLESH} COMMAND_SEQUENCE_TYPE;
class device2DSensor : public deviceNodeSensor, public protocolLGS_2D{ private:
uint8_t m_bPortType; basicTransport * m_pPort; uint32_t m_nSleepTime; uint8_t m_bInitialFlips; uint16_t m_nCurrentAngle; uint8_t m_bDrawType; uint32_t m_nProcessingCmdId; uint32_t m_vDrawRanges[ANODE_2D_MAX_DRAW_ANGLES];
uint8_t m_bCurShadowMask; bool m_bDeviceIsSynced; bool m_bForceSync; bool m_bSerialStringValid; bool m_bVersionStringValid; bool m_bTargetArived; char m_tSN[65]; char m_tSV[129];
uint8_t m_nActiveDetectionProfile; // Shadow
SHADOW_IO_HELPER m_sShadowHelper; SHADOW m_sShadow; // GetFile
// GETFILE_IO_HELPER m_sGetFileHelper;
GF_HELPER_STRUCT m_sGetFileTransfers; uint8_t m_bGetFileTransferRetryCount;
/*
FS_IO_HELPER * m_pFSHelper;bool m_bSupportedFS;uint8_t m_pFsPackageBuffer[MAX_PATH];uint8_t m_bCurrentOperationFS;FS_DATA_EX m_sInFSData;FS_DATA_EX m_sOutFSData;*/#ifdef PERSISTED_TARGET_SIM
uint16_t m_nTargSimAngle; uint16_t m_nTargSimRange;#endif
WORKING_STATE_LRF2D m_eWState;
TARGET_DATA * prepareTargetData(uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0); WIDTH_TABLE * prepareWidthTable(); GETFILE_IO_HELPER * prepareFileTransfer(CSTR lname, CSTR rname); void fileTransferSpecialWait(); // void saveRawDrawData( uint16_t alngles );
void cleanShadowStructs(); bool PtInPolygons(TEST_POINT & point, uint8_t F); bool PtInPolygon(SHADOW_POLY & Poly, TEST_POINT & point); bool rasterizeShadow(); bool saveShadowToDB(void); bool loadShadowFromDB(void); bool cleanShadowInDB(void); // bool downloadFile( CSTR fname );
// COMMAND_SEQUENCE_TYPE m_eCurrentSequence;
// uint8_t m_bSequenceStep;
// bool runSequence( COMMAND_SEQUENCE_TYPE SequenceID );
#ifndef LRF_PROXY_ONLY
#ifdef DEBUG
void makeShadowPic(CSTR picname); #endif
#endif
#ifdef SEND_MASKS_VIA_FILE
bool generateMaskFiles(CSTR vname, CSTR bname);#endif
protected:
virtual void connectMode(); virtual void handshakeMode(); virtual void readMode(); virtual void fileTransferMode(); virtual void syncMode(); virtual void drawMode(); virtual void fullDrawMode(); virtual void maskMode(); virtual void alarmMode(); virtual void idleMode(); virtual void getfileMode(); virtual void proceedDBCommands(); virtual void cleanupDeviceStructures(); virtual void save_ini(); virtual void save_detection(); virtual void save_masks(); virtual void save_eprom(); virtual void wait_device(); virtual void wait_channel(); virtual bool validateCommunicationRessource(); virtual bool packetHandler(protocolPackage * Package);
public:
explicit device2DSensor(uint32_t id); ~device2DSensor(); virtual bool startService(); virtual bool stopService(); virtual bool reset(); virtual bool validate(); virtual void simulateTarget(void); //virtual uint32_t getChannelId( void );
virtual void setChannelBusy( uint32_t channelID, uint8_t seconds_TO ); virtual void setChannelReady( uint32_t channelID );};
#endif
|