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.
115 lines
3.0 KiB
115 lines
3.0 KiB
#include "protocolMastBaum.h"
|
|
#include "../../hardware/uart/serialPort.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "MastBaumPoroto", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "MastBaumPoroto", this, _LOG_ERROR, X )
|
|
|
|
protocolMastBaum::protocolMastBaum( config_setting_t *Settings ): protocolParser( Settings ){
|
|
m_pDataTransport = NULL;
|
|
m_bDeviceID = 0; // Broadcast or Future use
|
|
};
|
|
|
|
protocolMastBaum::~protocolMastBaum(){
|
|
if (m_pDataTransport != NULL) delete((serialPort*)m_pDataTransport);
|
|
};
|
|
|
|
bool protocolMastBaum::completePackage( U8 *Buffer, size_t BufferSize ){
|
|
if( BufferSize > ( 0xFF - 3 ) ) return false;
|
|
Buffer[0] = MASTBAUM_PACKAGE_START_TAG;
|
|
Buffer[1] = MASTBAUM_MASTER_TAG | m_bDeviceID;
|
|
Buffer[2] = ( BufferSize - 3 ) & 0xFF;
|
|
Buffer[BufferSize] = checksumLGS( Buffer, BufferSize );
|
|
return true;
|
|
};
|
|
|
|
int protocolMastBaum::packetChecker( unsigned char *Buffer, size_t BufferSize ){
|
|
if( Buffer[0] == 0xAA ) {
|
|
if( BufferSize > 1 ) {
|
|
if( BufferSize < 16 ) {
|
|
for( U8 i=1; i< BufferSize; i++ ){
|
|
if( Buffer[i] == 0xFF ) {
|
|
#ifdef DEBUG
|
|
LOG("PacketChecker: Packet Is Recognized");
|
|
#endif
|
|
return 0;
|
|
};
|
|
};
|
|
} else {
|
|
for( U8 i=1; i< 16; i++ ){
|
|
if( Buffer[i] == 0xFF ) {
|
|
#ifdef DEBUG
|
|
LOG("PacketChecker: Packet Is Recognized");
|
|
#endif
|
|
return 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("PacketChecker: Packet Not Recognized");
|
|
#endif
|
|
return 1;
|
|
};
|
|
|
|
//int protocolPTZ_VISCA::packetExtractor(unsigned char *Buffer, size_t BufferSize)
|
|
protocolPackage *protocolMastBaum::packetExtractor(unsigned char *Buffer, size_t BufferSize){
|
|
U8 i;
|
|
protocolPackage *RetVal;
|
|
RetVal = (protocolPackage*)malloc(sizeof(protocolPackage));
|
|
if (RetVal != NULL){
|
|
RetVal->m_pData = (unsigned char *) malloc(16);
|
|
for (i = 0; i < 16; i++){
|
|
RetVal->m_pData[i] = Buffer[i];
|
|
if (Buffer[i] == 0xFF) {
|
|
LOG("PacketExtractor: Packet Is Extracted");
|
|
break;
|
|
};
|
|
};
|
|
RetVal->m_nSize = i + 1;
|
|
}
|
|
LOG("PacketExtractor: Packet Not Extracted");
|
|
return RetVal;
|
|
};
|
|
|
|
bool protocolMastBaum::packetHandler(protocolPackage *Package){
|
|
U8 Com_Mode;
|
|
U8 Cat_Code;
|
|
LOG("PacketHandler: Packet Is Handling");
|
|
Com_Mode = Package->m_pData[1];
|
|
Cat_Code = Package->m_pData[2];
|
|
|
|
free( Package->m_pData );
|
|
free( Package );
|
|
return true;
|
|
};
|
|
|
|
|
|
bool protocolMastBaum::create(void){
|
|
config_setting_t *pSetting;
|
|
int tPort, tSpeed;
|
|
if (!protocolParser::create()) return false;
|
|
pSetting = config_setting_get_member(m_pSettings, MASTBAUM_TAG_COM_PORT);
|
|
if (pSetting == NULL) return false;
|
|
tPort = config_setting_get_int(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, MASTBAUM_TAG_COM_SPEED);
|
|
if (pSetting == NULL) return false;
|
|
tSpeed = config_setting_get_int(pSetting);
|
|
char tBuf[16];
|
|
#ifdef __linux__
|
|
sprintf( tBuf,"/dev/ttyS%d",tPort);
|
|
#else
|
|
sprintf(tBuf, "com%d", tPort);
|
|
#endif
|
|
m_pDataTransport = new serialPort(tBuf,tSpeed);
|
|
if (m_pDataTransport != NULL){
|
|
if (m_pDataTransport->addRecipient(this)){
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|