# HG changeset patch # User Paul LEROY # Date 2012-12-10 12:51:09 # Node ID 7f877774dc5c76cc35421818ba228eb85c8f850a # Parent 7c1589fec151f2e7199a64688b7c02b69ae1430c # Parent ead10fa095b76ba291ac53eaed6cf3e8dea4c8c1 Merge diff --git a/PAULs_LPPMON_PLUGINS.pro b/PAULs_LPPMON_PLUGINS.pro --- a/PAULs_LPPMON_PLUGINS.pro +++ b/PAULs_LPPMON_PLUGINS.pro @@ -7,5 +7,4 @@ unix:LPPMONCFG = /etc/lppmon SUBDIRS = \ rmapplugin - #include( $${LPPMONCFG}/lppmonplugin.prf) diff --git a/rmapplugin/bridge.cpp b/rmapplugin/bridge.cpp --- a/rmapplugin/bridge.cpp +++ b/rmapplugin/bridge.cpp @@ -3,4 +3,154 @@ bridge::bridge(QWidget *parent) : QWidget(parent) { + // Packet receiver + rmapPacketSEMAPHORE = new QSemaphore; + ccsdsPacketSEMAPHORE = new QSemaphore; + rmapPacket = (char*) malloc(RMAP_MAX_PACKET_LENGTH); + ccsdsPacket = (unsigned char*) malloc(CCSDS_MAX_PACKET_LENGTH); + spwPacket = (char*) malloc( qMax(RMAP_MAX_PACKET_LENGTH, CCSDS_MAX_PACKET_LENGTH) ); + + bridge_LAYOUT = new QGridLayout; } + +bridge::~bridge() +{ + free(rmapPacket); + free(ccsdsPacket); + free(spwPacket); +} + +unsigned int bridge::Write(unsigned int *Value, unsigned int count, unsigned int address) +{ + unsigned int remainingCount = count; + unsigned int iOffset = 0; + QString console_message; + char* data; + + if(rmapPacketSEMAPHORE->available()!=0) + { + emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP request already running, WRITE access stopped"); + return 1; + } + + emit this->RMAP_write_reply_setText("reply to the write command required\nlast reply status: unavailable"); + + data = (char*) malloc(READ_WRITE_MAX_COUNTS*4); + + emit appendToLog(QString("*** START *** WRITE ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16)); + + while (remainingCount > READ_WRITE_MAX_COUNTS) + { + for (int i = 0; i>8); + data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16); + data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24); + } + + console_message.sprintf("remainingCount: %d => ", remainingCount); + emit appendToLog(console_message + QString("Write ")+ QString::number(READ_WRITE_MAX_COUNTS*4) + QString(" byte(s) @0x")+ QString::number(address,16)); + + if(WriteBLOCK(data, READ_WRITE_MAX_COUNTS*4, address)==0) + { + emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed"); + return 1; + } + + remainingCount = remainingCount - READ_WRITE_MAX_COUNTS; + address = address + READ_WRITE_MAX_COUNTS * 4; + iOffset = iOffset + READ_WRITE_MAX_COUNTS; + } + + if (remainingCount > 0) + { + for (unsigned int i = 0; i>8); + data[i*4+1] = (char) ((unsigned int) Value[i+iOffset]>>16); + data[i*4+0] = (char) ((unsigned int) Value[i+iOffset]>>24); + } + + console_message.sprintf("remainingCount: %d => ", remainingCount); + emit appendToLog(console_message + QString("Write ")+ QString::number(remainingCount*4) + QString(" byte(s) @0x")+ QString::number(address,16)); + + if (WriteBLOCK(data, remainingCount*4, address)==0) + { + emit appendToLog("WARNING === in function WRITE of rmapplugin *** RMAP write command failed"); + return 1; + } + } + + emit appendToLog(QString("*** STOP *** WRITE")); + free(data); + return count; +} + +unsigned int bridge::Read(unsigned int *Value, unsigned int count, unsigned int address) +{ + unsigned int remainingCount = count; + unsigned int iOffset = 0; + QString console_message; + + if(rmapPacketSEMAPHORE->available()!=0) + { + emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP request already running, READ access stopped"); + return 1; + } + emit appendToLog(QString("*** START *** READ ")+ QString::number(count) + QString(" word(s) @0x")+ QString::number(address,16)); + + while (remainingCount > READ_WRITE_MAX_COUNTS) + { + console_message.sprintf("remainingCount: %d => ", remainingCount); + emit appendToLog(console_message + QString("Read ")+ QString::number(4*READ_WRITE_MAX_COUNTS) + QString(" byte(s) @0x")+ QString::number(address,16)); + + if (this->ReadBLOCK(READ_WRITE_MAX_COUNTS*4, address)==0) + { + emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received"); + return 1; + } + + for(int i=0;iacquire(); + } + + if (remainingCount > 0) + { + console_message.sprintf("remainingCount: %d => ", remainingCount); + emit appendToLog(console_message + QString("Read ")+ QString::number(4*remainingCount) + QString(" byte(s) @0x")+ QString::number(address,16)); + + if (this->ReadBLOCK(4*remainingCount, address)==0) + { + emit appendToLog("WARNING === in function READ of rmapplugin *** RMAP packet not received"); + return 1; + } + + for(unsigned int i=0;iacquire(); + } + + emit appendToLog(QString("*** STOP *** READ ")); + return count; +} + diff --git a/rmapplugin/bridge.h b/rmapplugin/bridge.h --- a/rmapplugin/bridge.h +++ b/rmapplugin/bridge.h @@ -2,17 +2,53 @@ #define BRIDGE_H #include +#include +#include +#include "rmapoperations.h" class bridge : public QWidget { Q_OBJECT public: explicit bridge(QWidget *parent = 0); - + ~bridge(); + unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0); + unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0); + virtual unsigned int WriteSPW(char *Value, unsigned int count, char targetLogicalAddress, char userApplication); + virtual unsigned int WriteBLOCK(char *data,unsigned int nbBytes,unsigned int address=0) = 0; + virtual unsigned int ReadBLOCK(unsigned int nbBytes,unsigned int address=0) = 0; + virtual unsigned int getLinkStatus(unsigned char link) = 0; + + unsigned char rmapTargetLogicalAddress ; + unsigned char rmapSourceLogicalAddress ; + + RMAP_command_codes commandCode; + + QGridLayout *bridge_LAYOUT; + + QSemaphore *rmapPacketSEMAPHORE; + QSemaphore *ccsdsPacketSEMAPHORE; + + char *spwPacket; + char* rmapPacket; + unsigned char *ccsdsPacket; + signals: + void sendMessage(QString message); + void isOpen(bool); + void RMAP_write_reply_setText(QString); + void appendToLog(QString); + void ccsdsPacketAvailable(unsigned char*, unsigned int); public slots: - + unsigned int Open(); + unsigned int Close(); + virtual int receiveSPWPacket(unsigned char requestID) = 0; + void commandCodeHasChanged(RMAP_command_codes code) {this->commandCode = code;} + void targetHasChanged(int target) {rmapTargetLogicalAddress = (unsigned char) target;} + void sourceHasChanged(int target) {rmapSourceLogicalAddress = (unsigned char) target;} + +private: }; #endif // BRIDGE_H diff --git a/rmapplugin/rmapplugin.pro b/rmapplugin/rmapplugin.pro --- a/rmapplugin/rmapplugin.pro +++ b/rmapplugin/rmapplugin.pro @@ -18,10 +18,8 @@ DEFINES += driver_can_be_child=0 DEFINES += driver_VID=0 DEFINES += driver_PID=0 - QT += network - LIBS += ../spw_usb_driver_v2.61/lib/x86_64/libSpaceWireUSBAPI.so \ ../spw_usb_driver_v2.61/lib/x86_64/libConfigLibraryUSB.so @@ -72,4 +70,3 @@ SOURCES += \ -