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.
139 lines
4.9 KiB
139 lines
4.9 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 "../../hardware/soc/general/3DLRF.h"
|
|
|
|
#ifdef PRU_SLAVE
|
|
#define SEND_TAG 0x00
|
|
#else
|
|
#define SEND_TAG 0x80
|
|
#endif
|
|
|
|
#define TWI_TARGET_QUEUE_SIZE 128
|
|
#define TWI_MAX_PACKAGE_SIZE_BYTES ( PROTOCOL_PARSER_BUFFER_SIZE >> 1 )
|
|
|
|
typedef enum E_TWIN_COMMAND{
|
|
TWC_NO_COMMAND = 0,
|
|
TWC_GET_STATUS = 1,
|
|
TWC_GET_TARGETS = 2,
|
|
TWC_GET_CONFIG = 3,
|
|
TWC_SET_CONFIG = 4,
|
|
TWC_GET_THDRAW = 5,
|
|
TWC_SET_THDRAW = 6,
|
|
TWC_PUSH_TARGET = 7,
|
|
TWC_DO_REBOOT = 255
|
|
} TWIN_COMMAND;
|
|
|
|
typedef struct S_TWIN_CMD_RECORD{
|
|
TWIN_COMMAND CMD;
|
|
void * PTR;
|
|
} TWIN_CMD_REC;
|
|
|
|
typedef std::queue<TWIN_CMD_REC *> TWIN_COMMAND_QUEUE;
|
|
|
|
typedef enum E_TWIN_PCMD{
|
|
TWIN_NO_CMD = 0,
|
|
TWIN_STATUS_REQ = 1,
|
|
TWIN_STATUS_ACK = 2,
|
|
TWIN_TH_GETDATA,
|
|
TWIN_TH_DATA,
|
|
TWIN_TARGETS_REQ,
|
|
TWIN_TARGETS_DATA
|
|
} TWIN_PCMD;
|
|
|
|
#define TWI_STATUS_ERROR_MASK 0x000000ff
|
|
#define TWI_STATUS_TARGET_MASK 0x0000ff00
|
|
#define TWI_STATUS_KERNEL_MASK 0xffff0000
|
|
|
|
#define TWI_STATUS_KERNEL_00_RDY 0x00010000
|
|
#define TWI_STATUS_KERNEL_01_RDY 0x00020000
|
|
#define TWI_STATUS_KERNEL_02_RDY 0x00040000
|
|
#define TWI_STATUS_KERNEL_03_RDY 0x00080000
|
|
#define TWI_STATUS_KERNEL_04_RDY 0x00100000
|
|
#define TWI_STATUS_KERNEL_05_RDY 0x00200000
|
|
#define TWI_STATUS_KERNEL_06_RDY 0x00400000
|
|
#define TWI_STATUS_KERNEL_07_RDY 0x00800000
|
|
#define TWI_STATUS_KERNEL_08_RDY 0x01000000
|
|
#define TWI_STATUS_KERNEL_09_RDY 0x02000000
|
|
#define TWI_STATUS_KERNEL_10_RDY 0x04000000
|
|
#define TWI_STATUS_KERNEL_11_RDY 0x08000000
|
|
#define TWI_STATUS_KERNEL_12_RDY 0x10000000
|
|
#define TWI_STATUS_KERNEL_13_RDY 0x20000000
|
|
#define TWI_STATUS_KERNEL_14_RDY 0x40000000
|
|
#define TWI_STATUS_KERNEL_15_RDY 0x80000000
|
|
|
|
class protocolInternalLRF3D: public protocolParser {
|
|
private:
|
|
basicLogCollection *m_pLog;
|
|
protected:
|
|
uint32_t m_nStatus;
|
|
basicMutex m_mStatusProtector;
|
|
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;
|
|
};
|
|
public:
|
|
protocolInternalLRF3D();
|
|
virtual ~protocolInternalLRF3D();
|
|
virtual bool create(){ return protocolParser::create(); };
|
|
uint32_t getStatus();
|
|
};
|
|
#ifdef PRU_SLAVE
|
|
class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{
|
|
private:
|
|
basicLogCollection *m_pLog;
|
|
thresholdNode *m_pThresholds[16]; // 8 - learning 8 - working
|
|
targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE];
|
|
uint8_t m_nTargetCount;
|
|
basicMutex m_mTargetProtector;
|
|
basicMutex m_mData;
|
|
bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 );
|
|
bool sendTargets( void );
|
|
bool sendStatus( void );
|
|
protected:
|
|
virtual bool packetHandler( protocolPackage *Package );
|
|
public:
|
|
protocolInternalLRF3D_SLAVE();
|
|
virtual ~protocolInternalLRF3D_SLAVE();
|
|
virtual bool create( void );
|
|
bool setTrasholdData( uint8_t lrf_id, uint32_t *ptr );
|
|
bool enqueueTarget( targetRecord *ptr );
|
|
};
|
|
#else //!PRU_SLAVE
|
|
class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{
|
|
private:
|
|
basicLogCollection * m_pLog;
|
|
TWIN_PCMD m_bLastPackageType;
|
|
basicMutex m_mLastTypeProtector;
|
|
targetRecord * m_pTargets;
|
|
thresholdNode * m_pTrashold;
|
|
protected:
|
|
bool packetHandler( protocolPackage *Package );
|
|
public:
|
|
protocolInternalLRF3D_MASTER();
|
|
virtual ~protocolInternalLRF3D_MASTER();
|
|
virtual bool create(void);
|
|
bool ackDataSegment( uint32_t dataIdx = 0 );
|
|
bool ackTargets( uint32_t pkgId );
|
|
TWIN_PCMD getLastPackageType( void );
|
|
bool requestSoftwareVersion(void);
|
|
bool requestStatus( void );
|
|
bool requestTargets(void);
|
|
bool requestTrasholdData( uint8_t lrf_id );
|
|
bool sendSoftwareUpdate( uint8_t *ptr );
|
|
bool setTData( targetRecord *ptr ){ m_pTargets = ptr; return m_pTargets!=NULL; };
|
|
bool setTHData( thresholdNode *ptr ){ m_pTrashold = ptr; return m_pTrashold!=NULL; };
|
|
};
|
|
#endif //!PRU_SLAVE
|
|
//https://www.exler.ru/blog/kak-vernut-staryy-interfeys-facebook.htm
|
|
#endif
|