You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

215 lines
7.5 KiB

#ifndef __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__
#define __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__
//aliona
//https://www.pornhub.com/view_video.php?viewkey=ph5dffcb1983567
#include <queue>
#include "protocol.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../hardware/soc/general/3DLRF.h"
#include "../../alg/lgs/mask.h"
#ifdef PRU_SLAVE
#define SEND_TAG 0x00
#else
#define SEND_TAG 0x80
#endif
#define TWI_TARGET_QUEUE_SIZE 128
#define TWI_CMD_INDEX 3
#define TWI_PLS_INDEX 4
#define TWI_MAX_PACKAGE_SIZE_BYTES 0x8002
#define TWI_MAX_PAYLOAD_SIZE_BYTES 0x7fff
typedef enum E_TWIN_COMMAND{
TWC_NO_COMMAND = 0,
TWC_SET_CMD_MODE = 1,
TWC_SET_EVT_MODE,
TWC_ACK_CMD,
TWC_NACK_CMD,
TWC_GET_MODE,
TWC_CURRENT_MODE,
TWC_GET_STATUS,
TWC_CURRENT_STATUS,
TWC_GET_CONFIG,
TWC_SET_CONFIG,
TWC_GET_VERSION,
TWC_CURRENT_VERSION,
TWC_GET_SHADOW_INFO,
TWC_SHADOW_INFO,
TWC_GET_SHADOW_POLY,
TWC_SET_SHADOW_POLY,
TWC_GET_SHADOW_TRACE,
TWC_SET_SHADOW_TRACE,
TWC_SHADOW_DATA_POLY,
TWC_SHADOW_DATA_RAY,
TWC_GET_THRESHOLD,
TWC_TH_DATA,
TWC_INIT_TSINC,
TWC_TSINC_1,
TWC_TSINC_2,
TWC_PUSH_TARGET,
TWC_DO_REBOOT
} TWIN_COMMAND;
typedef struct S_TWI_CMD_CONTAINER{
TWIN_COMMAND CMD;
size_t SIZE;
void * DATA;
}TWI_CMD_CONTAINER;
typedef struct S_TWI_MASK_INFO{
uint32_t active: 1;
uint32_t poly_cnt: 8;
uint32_t nouse: 7;
uint32_t ray_cnt: 16;
}TWI_MASK_INFO;
typedef struct S_TWI_PEER_STATUS{
LRF_WORK_MODE KRNL_WM;
uint8_t ENABLED;
uint8_t DETECTION;
uint8_t TH_READY;
} TWI_PEER_STATUS;
typedef struct S_TWIN_STATUS{
TWI_PEER_STATUS MASTER_STATUS;
SOFTWARE_INFO MASTER_NFO;
LGS_3D_PARAMETERS MASTER_PARAMS;
TWI_PEER_STATUS SLAVE_STATUS;
SOFTWARE_INFO SLAVE_NFO;
LGS_3D_PARAMETERS SLAVE_PARAMS;
bool VERSION_IS_SYNCED;
bool SETTINGS_IS_SYNCED;
bool SHADOW_IS_SYNCED;
}TWIN_STATUS;
typedef std::queue<TWI_CMD_CONTAINER *> TWI_CMD_QUEUE;
#define TWI_STATUS_ERROR_MASK 0x000000ff
#define TWI_STATUS_TARGET_MASK 0x0000ff00
#define TWI_STATUS_KERNEL_MASK 0xffff0000
#define TWI_STATUS_MASTER_KERNEL_MASK 0x00ff0000
#define TWI_STATUS_SLAVE_KERNEL_MASK 0xff000000
#define TWI_STATUS_KERNEL_00_RDY 0x00000001
#define TWI_STATUS_KERNEL_01_RDY 0x00000002
#define TWI_STATUS_KERNEL_02_RDY 0x00000004
#define TWI_STATUS_KERNEL_03_RDY 0x00000008
#define TWI_STATUS_KERNEL_04_RDY 0x00000010
#define TWI_STATUS_KERNEL_05_RDY 0x00000020
#define TWI_STATUS_KERNEL_06_RDY 0x00000040
#define TWI_STATUS_KERNEL_07_RDY 0x00000080
#define TWI_STATUS_KERNEL_08_RDY 0x00000100
#define TWI_STATUS_KERNEL_09_RDY 0x00000200
#define TWI_STATUS_KERNEL_10_RDY 0x00000400
#define TWI_STATUS_KERNEL_11_RDY 0x00000800
#define TWI_STATUS_KERNEL_12_RDY 0x00001000
#define TWI_STATUS_KERNEL_13_RDY 0x00002000
#define TWI_STATUS_KERNEL_14_RDY 0x00004000
#define TWI_STATUS_KERNEL_15_RDY 0x00008000
#define TWI_STATUS_KERNEL_16_RDY 0x00010000
#define TWI_STATUS_KERNEL_17_RDY 0x00020000
#define TWI_STATUS_KERNEL_18_RDY 0x00040000
#define TWI_STATUS_KERNEL_19_RDY 0x00080000
#define TWI_STATUS_KERNEL_20_RDY 0x00100000
#define TWI_STATUS_KERNEL_21_RDY 0x00200000
#define TWI_STATUS_KERNEL_22_RDY 0x00400000
#define TWI_STATUS_KERNEL_23_RDY 0x00800000
#define TWI_STATUS_KERNEL_24_RDY 0x01000000
#define TWI_STATUS_KERNEL_25_RDY 0x02000000
#define TWI_STATUS_KERNEL_26_RDY 0x04000000
#define TWI_STATUS_KERNEL_27_RDY 0x08000000
#define TWI_STATUS_KERNEL_28_RDY 0x10000000
#define TWI_STATUS_KERNEL_29_RDY 0x20000000
#define TWI_STATUS_KERNEL_30_RDY 0x40000000
#define TWI_STATUS_KERNEL_31_RDY 0x80000000
class protocolInternalLRF3D: public protocolParser {
private:
basicLogCollection * m_pLog;
protected:
int packetChecker( U8 *Buffer, size_t BufferSize );
protocolPackage * packetExtractor( U8 *Buffer, size_t BufferSize );
inline int FinishUpPackage( U8 *Buffer, size_t Size ){
Buffer[0] = 0xAA;
Buffer[1] = ((Size - 3) >> 8) | SEND_TAG;
Buffer[2] = (Size - 3) & 0xFF;
Buffer[Size] = checksumLGS(Buffer, Size);
return Size + 1;
};
bool sendACK( TWIN_COMMAND ACK_CMD );
bool sendNACK( TWIN_COMMAND ACK_CMD );
bool sendPlainCMD( TWIN_COMMAND ACK_CMD );
bool sendDetectionParameters( PLGS_3D_PARAMETERS ptr );
bool sendPolygone( uint8_t polyID, simplePolygone *SP );
bool sendShadowTrace( vectorZoneMask *ZM );
public:
protocolInternalLRF3D();
virtual ~protocolInternalLRF3D();
virtual bool create(){ return protocolParser::create(); };
};
#ifdef PRU_SLAVE
class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{
private:
basicLogCollection * m_pLog;
protected:
//thresholdNode * m_pThresholds[16]; // 8 - learning 8 - working
basicMutex m_mData;
virtual bool packetHandler( protocolPackage *Package ){ return true; };
public:
protocolInternalLRF3D_SLAVE();
virtual ~protocolInternalLRF3D_SLAVE();
virtual bool create( void );
bool ackShadowSegment( uint32_t dataIdx = 0 );
bool resetChannel(void);
bool sendShadowInfo( TWI_MASK_INFO *ptr );
bool sendTarget( targetRecord *ptr );
bool sendTrasholdData( thresholdNode *data, uint32_t dataIdx = 0 );
bool sendCurrentParameters( PLGS_3D_PARAMETERS ptr );
bool sendMode( uint8_t mode );
bool sendStatus( TWI_PEER_STATUS *ptr );
bool sendVersion( SOFTWARE_INFO *sv );
};
#else //!PRU_SLAVE
class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{
private:
basicLogCollection * m_pLog;
protected:
virtual bool packetHandler( protocolPackage *Package ){ return true; };
bool synchTimeStage2();
public:
protocolInternalLRF3D_MASTER();
virtual ~protocolInternalLRF3D_MASTER();
virtual bool create(void);
bool resetChannel(void);
bool getShadowPoly( uint8_t polyID );
bool ackThresholdSegment( uint32_t dataIdx = 0 );
bool ackShadowSegment( uint32_t dataIdx = 0 );
bool getTHData( uint8_t lrf_id );
bool sendMode( uint8_t Mode );
bool sendSoftwareUpdate( uint8_t *ptr );
bool sendShadowData( uint8_t *ptr );
};
#endif //!PRU_SLAVE
//https://www.exler.ru/blog/kak-vernut-staryy-interfeys-facebook.htm
#endif