08.02.2010 - version 0.1.2

This commit is contained in:
peri4
2012-02-08 19:39:21 +04:00
parent 8bb8287dcb
commit 5558add03e
10 changed files with 169 additions and 156 deletions

View File

@@ -118,7 +118,7 @@ PIProtocol::PIProtocol(const PIString & config, const PIString & name, void * re
}
type_rec = PIProtocol::Serial;
type_send = PIProtocol::Serial;
ser = new PISerial(dev, this, receiveEvent);
ser = new PISerial(dev, this, receiveEvent, headerValidateEvent);
setReceiverDevice(dev, (PISerial::Speed)ps);
setSenderDevice(dev, (PISerial::Speed)ps);
ser->setInSpeed((PISerial::Speed)ps);
@@ -256,7 +256,7 @@ PIProtocol::PIProtocol(const PIString & config, const PIString & name, void * re
return;
}
type_send = PIProtocol::Serial;
if (ser == 0) ser = new PISerial(dev, this, receiveEvent);
if (ser == 0) ser = new PISerial(dev, this, receiveEvent, headerValidateEvent);
setSenderDevice(dev, (PISerial::Speed)ps);
ser->setOutSpeed((PISerial::Speed)ps);
ser->setParameters(pp);
@@ -353,7 +353,7 @@ void PIProtocol::init() {
timeout_ = 3.f;
sendTimer = new PITimer(sendEvent, this);
diagTimer = new PITimer(diagEvent, this);
wrong_count = receive_count = send_count = 0;
wrong_count = receive_count = send_count = missed_count = 0;
immediate_freq = integral_freq = 0.f;
headerPtr = dataPtr = sendDataPtr = 0;
headerSize = dataSize = sendDataSize = 0;
@@ -378,13 +378,14 @@ void PIProtocol::init() {
void PIProtocol::setReceiverDevice(const PIString & device, PISerial::Speed speed, bool force) {
if (force) {
type_rec = PIProtocol::Serial;
if (ser == 0) ser = new PISerial("", this, receiveEvent);
type_send = type_rec = PIProtocol::Serial;
if (ser == 0) ser = new PISerial("", this, receiveEvent, headerValidateEvent);
}
if (type_rec == PIProtocol::Serial && ser != 0) {
ser->setDevice(device);
ser->setSpeed(speed);
devReceiverName = device;
devSenderName = device;
}
}
@@ -404,8 +405,8 @@ void PIProtocol::setReceiverAddress(const PIString & ip, int port, bool force) {
void PIProtocol::setSenderDevice(const PIString & device, PISerial::Speed speed, bool force) {
if (force) {
type_send = PIProtocol::Serial;
if (ser == 0) ser = new PISerial("", this, receiveEvent);
type_send = type_rec = PIProtocol::Serial;
if (ser == 0) ser = new PISerial("", this, receiveEvent, headerValidateEvent);
}
if (type_send == PIProtocol::Serial && ser != 0) {
ser->setDevice(device);
@@ -469,7 +470,7 @@ void PIProtocol::stopReceive() {
}
bool PIProtocol::receiveEvent(void * t, char * data, int size) {
bool PIProtocol::receiveEvent(void * t, uchar * data, int size) {
PIProtocol * p = (PIProtocol * )t;
if (!p->receive(data, size)) return false;
p->work = true;
@@ -495,11 +496,19 @@ bool PIProtocol::receiveEvent(void * t, char * data, int size) {
}
bool PIProtocol::headerValidateEvent(void * t, uchar * src, uchar * rec, int size) {
PIProtocol * p = (PIProtocol * )t;
//cout << "validate\n";
return p->headerValidate(src, rec, size);
}
void PIProtocol::diagEvent(void * t, int) {
PIProtocol * p = (PIProtocol * )t;
p->calc_freq();
p->calc_diag();
p->check_state();
if (p->ser != 0) p->missed_count = p->ser->missedPackets();
}
@@ -586,10 +595,10 @@ void PIProtocol::send(const void * data, int size) {
history_rsize_send.setReadableSize(history_file_send.pos());
}
if (type_send == PIProtocol::Serial)
if (ser->send((char * )data, size))
if (ser->send((uchar * )data, size))
send_count++;
if (type_send == PIProtocol::Ethernet)
if (eth->send((char * )data, size))
if (eth->send((uchar * )data, size))
send_count++;
}
@@ -605,9 +614,9 @@ void PIProtocol::send() {
history_rsize_send.setReadableSize(history_file_send.pos());
}
if (type_send == PIProtocol::Serial)
if (ser->send((char * )sendDataPtr, sendDataSize))
if (ser->send((uchar * )sendDataPtr, sendDataSize))
send_count++;
if (type_send == PIProtocol::Ethernet)
if (eth->send((char * )sendDataPtr, sendDataSize))
if (eth->send((uchar * )sendDataPtr, sendDataSize))
send_count++;
}