rmappluginpythonwrapper.cpp
146 lines
| 4.0 KiB
| text/x-c
|
CppLexer
/ rmapplugin / rmappluginpythonwrapper.cpp
r0 | #include "rmappluginpythonwrapper.h" | |||
#include <math.h> | ||||
r11 | #include <QApplication> | |||
r0 | ||||
r58 | rmappluginPythonWrapper::rmappluginPythonWrapper(lppmonplugin *parent) : | |||
r0 | genericPySysdriver(parent) | |||
{ | ||||
r11 | timer = new QTimer; | |||
timer->setSingleShot(true); | ||||
connect(timer, SIGNAL(timeout()), this, SLOT(sendTC())); | ||||
connect(this, SIGNAL(activateTCLoopSig()), this, SLOT(sendTCLoop())); | ||||
r0 | } | |||
r12 | QList<QVariant> rmappluginPythonWrapper::ReadSPW(unsigned int size) // size is not used | |||
r11 | { | |||
QList<QVariant> result; | ||||
r13 | TMPacketToRead *ccsdsPacket; | |||
r11 | ||||
if (!ccsdsPacketStore->isEmpty()) | ||||
{ | ||||
ccsdsPacket = ccsdsPacketStore->takeFirst(); | ||||
r13 | for(unsigned int i = 0;i<ccsdsPacket->size;i++) | |||
r11 | { | |||
r13 | result.append((QVariant)ccsdsPacket->Value[i]); | |||
r11 | } | |||
r13 | delete(ccsdsPacket); | |||
r11 | } | |||
r19 | emit nbPacketHasChanged(ccsdsPacketStore->size()); | |||
r11 | return result; | |||
} | ||||
void rmappluginPythonWrapper::WriteSPW(QList<int> dataList) | ||||
{ | ||||
char targetLogicalAddress; | ||||
char userApplication; | ||||
unsigned int count; | ||||
char *Value; | ||||
unsigned char data[dataList.count()]; | ||||
for(int i = 0; i<dataList.count(); i++) // get the data as unsigned char | ||||
{ | ||||
data[i] = (unsigned char)dataList.at(i); | ||||
} | ||||
// read the first bytes of the data to get the targetLogicalAddress and the userApplication parameters | ||||
targetLogicalAddress = data[0]; | ||||
userApplication = data[3]; | ||||
count = dataList.count() - 4; // the CCSDS header (4 bytes) is added by LPPMON | ||||
Value = (char*) &data[4]; | ||||
emit WriteSPWSig(Value, count, targetLogicalAddress, userApplication); | ||||
} | ||||
void rmappluginPythonWrapper::WriteSPWDelay(QList<int> dataList, unsigned int delay) | ||||
{ | ||||
char targetLogicalAddress; | ||||
char userApplication; | ||||
unsigned int count; | ||||
char *Value; | ||||
TCPacketToSend *packet; | ||||
unsigned char data[dataList.count()]; | ||||
for(int i = 0; i<dataList.count(); i++) // get the data as unsigned char | ||||
{ | ||||
data[i] = (unsigned char)dataList.at(i); | ||||
} | ||||
// read the first bytes of the data to get the targetLogicalAddress and the userApplication parameters | ||||
targetLogicalAddress = data[0]; | ||||
userApplication = data[3]; | ||||
count = dataList.count() - 4; // the CCSDS header (4 bytes) is added by LPPMON | ||||
Value = (char*) &data[4]; | ||||
packet = new TCPacketToSend(Value, count, targetLogicalAddress, userApplication, delay); | ||||
TCPacketStore.append(packet); | ||||
emit(activateTCLoopSig()); | ||||
} | ||||
void rmappluginPythonWrapper::processPacketStoreLater(unsigned int delay) | ||||
{ | ||||
emit sendMessage( | ||||
"*** process packet store in " + QString::number(delay) + " ms" | ||||
); | ||||
QTimer::singleShot(delay, this, SLOT(sendProcessPacketStoreNowSig())); | ||||
} | ||||
void rmappluginPythonWrapper::sendTCLoop() | ||||
{ | ||||
unsigned int delay; | ||||
if (!timer->isActive()) | ||||
{ | ||||
if (!TCPacketStore.isEmpty()) | ||||
{ | ||||
delay = TCPacketStore.at(0)->delay; | ||||
timer->setInterval(delay); | ||||
timer->start(); | ||||
} | ||||
} | ||||
} | ||||
void rmappluginPythonWrapper::sendTC() | ||||
{ | ||||
TCPacketToSend *packet; | ||||
unsigned int delay; | ||||
packet = TCPacketStore.takeFirst(); | ||||
// the signal is connected with the option Qt::DirectConnection, thus it is processed immediately | ||||
emit(WriteSPWSig(packet->Value, packet->count,packet->targetLogicalAddress, packet->userApplication)); | ||||
delete(packet); | ||||
if (!TCPacketStore.isEmpty()) | ||||
{ | ||||
delay = TCPacketStore.at(0)->delay; | ||||
timer->setInterval(delay); | ||||
timer->start(); | ||||
} | ||||
} | ||||
void rmappluginPythonWrapper::processPacketStore() | ||||
{ | ||||
r18 | emit ccsdsPacketIsAvailable(ccsdsPacketStore->at(0)->size); | |||
r11 | } | |||
void rmappluginPythonWrapper::setTargetAddressValue(unsigned int address) | ||||
{ | ||||
unsigned char newAddress; | ||||
newAddress = (unsigned char) address; | ||||
emit updateTargetAddress(newAddress); | ||||
} | ||||
void rmappluginPythonWrapper::setSourceAddressValue(unsigned int address) | ||||
{ | ||||
unsigned char newAddress; | ||||
newAddress = (unsigned char) address; | ||||
emit updateSourceAddress(newAddress); | ||||
} | ||||
void rmappluginPythonWrapper::ProcessPendingEvents() | ||||
{ | ||||
QCoreApplication::processEvents(); | ||||
} | ||||
r12 | ||||