08.02.2010 - version 0.1.2
This commit is contained in:
17
piprotocol.h
17
piprotocol.h
@@ -37,10 +37,10 @@ public:
|
||||
~PIMultiProtocolBase() {;}
|
||||
|
||||
protected:
|
||||
virtual void received(PIProtocol * prot, bool corrected, char * data, int size) {;}
|
||||
virtual void received(PIProtocol * prot, bool corrected, uchar * data, int size) {;}
|
||||
|
||||
private:
|
||||
static void receiveEvent(PIMultiProtocolBase * p, PIProtocol * prot, bool corrected, char * data, int size) {p->mutex_receive.lock(); p->received(prot, corrected, data, size); p->mutex_receive.unlock();}
|
||||
static void receiveEvent(PIMultiProtocolBase * p, PIProtocol * prot, bool corrected, uchar * data, int size) {p->mutex_receive.lock(); p->received(prot, corrected, data, size); p->mutex_receive.unlock();}
|
||||
|
||||
PIMutex mutex_receive;
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
void setExpectedFrequency(float frequency); // for connection quality diagnostic
|
||||
void setReceiverDevice(const PIString & device, PISerial::Speed speed, bool force = false); // for Serial
|
||||
void setReceiverData(void * dataPtr, int dataSize) {this->dataPtr = (uchar * )dataPtr; this->dataSize = dataSize; if (type_rec == PIProtocol::Serial || type_send == PIProtocol::Serial) ser->setReadData(headerPtr, headerSize, dataSize);}
|
||||
void setReceiverDataHeader(void * headerPtr, int headerSize) {this->headerPtr = (uchar * )dataPtr; this->headerSize = headerSize; if (type_rec == PIProtocol::Serial || type_send == PIProtocol::Serial) ser->setReadData(headerPtr, headerSize, dataSize);}
|
||||
void setReceiverDataHeader(void * headerPtr, int headerSize) {this->headerPtr = (uchar * )headerPtr; this->headerSize = headerSize; if (type_rec == PIProtocol::Serial || type_send == PIProtocol::Serial) ser->setReadData(headerPtr, headerSize, dataSize);}
|
||||
void setReceiverAddress(const PIString & ip, int port, bool force = false); // for Ethernet
|
||||
void setReceiverParameters(PIFlags<PISerial::Parameters> parameters) {if (type_rec == PIProtocol::Serial || type_send == PIProtocol::Serial) ser->setParameters(parameters);} // for Serial
|
||||
void setReceiveSlot(ReceiveFunc slot) {ret_func = slot;}
|
||||
@@ -104,6 +104,8 @@ public:
|
||||
ullong * wrongCount_ptr() {return &wrong_count;}
|
||||
ullong sendCount() const {return send_count;}
|
||||
ullong * sendCount_ptr() {return &send_count;}
|
||||
ullong missedCount() const {return missed_count;}
|
||||
ullong * missedCount_ptr() {return &missed_count;}
|
||||
PIProtocol::Quality quality() const {return net_diag;} // receive quality
|
||||
int * quality_ptr() {return (int * )&net_diag;} // receive quality pointer
|
||||
PIString receiverDeviceName() const {return devReceiverName;}
|
||||
@@ -125,11 +127,11 @@ public:
|
||||
void * sendData() {return sendDataPtr;}
|
||||
|
||||
PIByteArray lastHeader() {if (ser != 0) return ser->lastHeader(); return PIByteArray();}
|
||||
PIByteArray internalBuffer() {if (ser != 0) return ser->internalBuffer(); return PIByteArray();}
|
||||
|
||||
protected:
|
||||
virtual bool receive(char * data, int size) {if (dataPtr != 0) memcpy(dataPtr, data, size); return true;} // executed when raw data received, break if 'false' return
|
||||
virtual bool receive(uchar * data, int size) {if (dataPtr != 0) memcpy(dataPtr, data, size); return true;} // executed when raw data received, break if 'false' return
|
||||
virtual bool validate() {return true;} // function for validate algorithm and save data from dataPtr to external struct
|
||||
virtual bool headerValidate(uchar * src, uchar * rec, int size) {for (int i = 0; i < size; ++i) if (src[i] != rec[i]) return false; return true;} // function for validate header (COM-port and headerSize > 0)
|
||||
virtual uint checksum_i(void * data, int size) { // function for checksum (uint)
|
||||
uint c = 0;
|
||||
for (int i = 0; i < size; ++i)
|
||||
@@ -158,7 +160,8 @@ protected:
|
||||
|
||||
private:
|
||||
static void sendEvent(void * e, int) {((PIProtocol * )e)->send();}
|
||||
static bool receiveEvent(void * t, char * data, int size);
|
||||
static bool receiveEvent(void * t, uchar * data, int size);
|
||||
static bool headerValidateEvent(void * t, uchar * src, uchar * rec, int size);
|
||||
static void diagEvent(void * t, int);
|
||||
|
||||
void setMultiProtocolOwner(PIMultiProtocolBase * mp) {mp_owner = mp;}
|
||||
@@ -180,7 +183,7 @@ private:
|
||||
float exp_freq, send_freq, immediate_freq, integral_freq, timeout_;
|
||||
int packets[2], pckt_cnt, pckt_cnt_max;
|
||||
char * packet, cur_pckt;
|
||||
ullong wrong_count, receive_count, send_count;
|
||||
ullong wrong_count, receive_count, send_count, missed_count;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user