issue with makefile
This commit is contained in:
@ -1,324 +0,0 @@
|
||||
//#include "cookies/ArduinoCookie.h"
|
||||
//#include "ArduinoComIF.h"
|
||||
//
|
||||
//#include <fsfw/globalfunctions/DleEncoder.h>
|
||||
//#include <stdio.h>
|
||||
//#include <string.h>
|
||||
//#include <unistd.h>
|
||||
//#include <fcntl.h>
|
||||
//#include <errno.h>
|
||||
//#include <fsfw/globalfunctions/CRC.h>
|
||||
//
|
||||
//#include <termios.h>
|
||||
//
|
||||
//ArduinoCommInterface::ArduinoCommInterface(object_id_t setObjectId,
|
||||
// const char *serialDevice) :
|
||||
// spiMap(MAX_NUMBER_OF_SPI_DEVICES), rxBuffer(
|
||||
// MAX_PACKET_SIZE * MAX_NUMBER_OF_SPI_DEVICES*10, true), SystemObject(setObjectId) {
|
||||
// initialized = false;
|
||||
// serialPort = ::open("/dev/ttyUSB0", O_RDWR);
|
||||
//
|
||||
// if (serialPort < 0) {
|
||||
// //configuration error
|
||||
// printf("Error %i from open: %s\n", errno, strerror(errno));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// struct termios tty;
|
||||
// memset(&tty, 0, sizeof tty);
|
||||
//
|
||||
// // Read in existing settings, and handle any error
|
||||
// if (tcgetattr(serialPort, &tty) != 0) {
|
||||
// printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity
|
||||
// tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
||||
// tty.c_cflag |= CS8; // 8 bits per byte
|
||||
// tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
||||
// tty.c_lflag &= ~ICANON; //Disable Canonical Mode
|
||||
// tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
||||
// tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
||||
// tty.c_cc[VTIME] = 0; // Non Blocking
|
||||
// tty.c_cc[VMIN] = 0;
|
||||
//
|
||||
// cfsetispeed(&tty, B9600); //Baudrate
|
||||
//
|
||||
// if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
||||
// //printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// initialized = true;
|
||||
//
|
||||
//}
|
||||
//
|
||||
//ArduinoCommInterface::~ArduinoCommInterface() {
|
||||
// ::close(serialPort);
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::open(Cookie **cookie, uint32_t address,
|
||||
// uint32_t maxReplyLen) {
|
||||
// //This is a hack, will be gone with https://egit.irs.uni-stuttgart.de/fsfw/fsfw/issues/19
|
||||
// switch ((address >> 8) & 0xff) {
|
||||
// case 0:
|
||||
// *cookie = new ArduinoCookie(ArduinoCookie::SPI, address, maxReplyLen);
|
||||
// spiMap.insert(address, (ArduinoCookie*) *cookie); //Yes, I *do* know that it is an ArduinoSpiCookie, I just new'd it
|
||||
// break;
|
||||
// default:
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::reOpen(Cookie *cookie, uint32_t address,
|
||||
// uint32_t maxReplyLen) {
|
||||
// //too lazy right now will be irrelevant with https://egit.irs.uni-stuttgart.de/fsfw/fsfw/issues/19
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
//}
|
||||
//
|
||||
//void ArduinoCommInterface::close(Cookie *cookie) {
|
||||
// //too lazy as well, find the correct Map, delete it there, then the cookie...
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::sendMessage(Cookie *cookie, uint8_t *data,
|
||||
// uint32_t len) {
|
||||
// ArduinoCookie *arduinoCookie = dynamic_cast<ArduinoCookie*>(cookie);
|
||||
// if (arduinoCookie == NULL) {
|
||||
// return INVALID_COOKIE_TYPE;
|
||||
// }
|
||||
//
|
||||
// return sendMessage(arduinoCookie->command, arduinoCookie->address, data,
|
||||
// len);
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::getSendSuccess(Cookie *cookie) {
|
||||
// return RETURN_OK;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::requestReceiveMessage(Cookie *cookie) {
|
||||
// return RETURN_OK;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::readReceivedMessage(Cookie *cookie,
|
||||
// uint8_t **buffer, uint32_t *size) {
|
||||
//
|
||||
// handleSerialPortRx();
|
||||
//
|
||||
// ArduinoCookie *arduinoCookie = dynamic_cast<ArduinoCookie*>(cookie);
|
||||
// if (arduinoCookie == NULL) {
|
||||
// return INVALID_COOKIE_TYPE;
|
||||
// }
|
||||
//
|
||||
// *buffer = arduinoCookie->replyBuffer;
|
||||
// *size = arduinoCookie->receivedDataLen;
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::setAddress(Cookie *cookie,
|
||||
// uint32_t address) {
|
||||
// //not implemented
|
||||
// return RETURN_FAILED;
|
||||
//}
|
||||
//
|
||||
//uint32_t ArduinoCommInterface::getAddress(Cookie *cookie) {
|
||||
// //not implemented
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::setParameter(Cookie *cookie,
|
||||
// uint32_t parameter) {
|
||||
// //not implemented
|
||||
// return RETURN_FAILED;
|
||||
//}
|
||||
//
|
||||
//uint32_t ArduinoCommInterface::getParameter(Cookie *cookie) {
|
||||
// //not implemented
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t ArduinoCommInterface::sendMessage(uint8_t command,
|
||||
// uint8_t address, const uint8_t *data, size_t dataLen) {
|
||||
// if (dataLen > UINT16_MAX) {
|
||||
// return TOO_MUCH_DATA;
|
||||
// }
|
||||
//
|
||||
// //being conservative here
|
||||
// uint8_t sendBuffer[(dataLen + 6) * 2 + 2];
|
||||
//
|
||||
// sendBuffer[0] = DleEncoder::STX;
|
||||
//
|
||||
// uint8_t *currentPosition = sendBuffer + 1;
|
||||
// size_t remainingLen = sizeof(sendBuffer) - 1;
|
||||
// uint32_t encodedLen;
|
||||
//
|
||||
// ReturnValue_t result = DleEncoder::encode(&command, 1, currentPosition,
|
||||
// remainingLen, &encodedLen, false);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// currentPosition += encodedLen;
|
||||
// remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen
|
||||
//
|
||||
// result = DleEncoder::encode(&address, 1, currentPosition, remainingLen,
|
||||
// &encodedLen, false);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// currentPosition += encodedLen;
|
||||
// remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen
|
||||
//
|
||||
// uint8_t temporaryBuffer[2];
|
||||
//
|
||||
// //note to Lukas: yes we _could_ use Serialize here, but for 16 bit it is a bit too much...
|
||||
// temporaryBuffer[0] = dataLen >> 8; //we checked dataLen above
|
||||
// temporaryBuffer[1] = dataLen;
|
||||
//
|
||||
// result = DleEncoder::encode(temporaryBuffer, 2, currentPosition,
|
||||
// remainingLen, &encodedLen, false);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// currentPosition += encodedLen;
|
||||
// remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen
|
||||
//
|
||||
// //encoding the actual data
|
||||
// result = DleEncoder::encode(data, dataLen, currentPosition, remainingLen,
|
||||
// &encodedLen, false);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// currentPosition += encodedLen;
|
||||
// remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen
|
||||
//
|
||||
// uint16_t crc = CRC::crc16ccitt(&command, 1);
|
||||
// crc = CRC::crc16ccitt(&address, 1, crc);
|
||||
// //fortunately the length is still there
|
||||
// crc = CRC::crc16ccitt(temporaryBuffer, 2, crc);
|
||||
// crc = CRC::crc16ccitt(data, dataLen, crc);
|
||||
//
|
||||
// temporaryBuffer[0] = crc >> 8;
|
||||
// temporaryBuffer[1] = crc;
|
||||
//
|
||||
// result = DleEncoder::encode(temporaryBuffer, 2, currentPosition,
|
||||
// remainingLen, &encodedLen, false);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// currentPosition += encodedLen;
|
||||
// remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen
|
||||
//
|
||||
// if (remainingLen > 0) {
|
||||
// *currentPosition = DleEncoder::ETX;
|
||||
// }
|
||||
// remainingLen -= 1;
|
||||
//
|
||||
// encodedLen = sizeof(sendBuffer) - remainingLen;
|
||||
//
|
||||
// ssize_t writtenlen = write(serialPort, sendBuffer, encodedLen);
|
||||
// if (writtenlen < 0) {
|
||||
// //we could try to find out what happened...
|
||||
// return RETURN_FAILED;
|
||||
// }
|
||||
// if (writtenlen != encodedLen) {
|
||||
// //the OS failed us, we do not try to block until everything is written, as
|
||||
// //we can not block the whole system here
|
||||
// return RETURN_FAILED;
|
||||
// }
|
||||
// return RETURN_OK;
|
||||
//}
|
||||
//
|
||||
//void ArduinoCommInterface::handleSerialPortRx() {
|
||||
// uint32_t availableSpace = rxBuffer.availableWriteSpace();
|
||||
//
|
||||
// uint8_t dataFromSerial[availableSpace];
|
||||
//
|
||||
// ssize_t bytesRead = read(serialPort, dataFromSerial,
|
||||
// sizeof(dataFromSerial));
|
||||
//
|
||||
// if (bytesRead < 0) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// rxBuffer.writeData(dataFromSerial, bytesRead);
|
||||
//
|
||||
// uint8_t dataReceivedSoFar[rxBuffer.maxSize()];
|
||||
//
|
||||
// uint32_t dataLenReceivedSoFar = 0;
|
||||
//
|
||||
// rxBuffer.readData(dataReceivedSoFar, sizeof(dataReceivedSoFar), true,
|
||||
// &dataLenReceivedSoFar);
|
||||
//
|
||||
// //look for STX
|
||||
// size_t firstSTXinRawData = 0;
|
||||
// while ((firstSTXinRawData < dataLenReceivedSoFar)
|
||||
// && (dataReceivedSoFar[firstSTXinRawData] != DleEncoder::STX)) {
|
||||
// firstSTXinRawData++;
|
||||
// }
|
||||
//
|
||||
// if (dataReceivedSoFar[firstSTXinRawData] != DleEncoder::STX) {
|
||||
// //there is no STX in our data, throw it away...
|
||||
// rxBuffer.deleteData(dataLenReceivedSoFar);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// uint8_t packet[MAX_PACKET_SIZE];
|
||||
// uint32_t packetLen;
|
||||
//
|
||||
// uint32_t readSize;
|
||||
//
|
||||
// ReturnValue_t result = DleEncoder::decode(
|
||||
// dataReceivedSoFar + firstSTXinRawData,
|
||||
// dataLenReceivedSoFar - firstSTXinRawData, &readSize, packet,
|
||||
// sizeof(packet), &packetLen);
|
||||
//
|
||||
// size_t toDelete = firstSTXinRawData;
|
||||
// if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
// handlePacket(packet, packetLen);
|
||||
//
|
||||
// //after handling the packet, we can delete it from the raw stream, it has been copied to packet
|
||||
// toDelete += readSize;
|
||||
// }
|
||||
//
|
||||
// //remove Data which was processed
|
||||
// rxBuffer.deleteData(toDelete);
|
||||
//}
|
||||
//
|
||||
//void ArduinoCommInterface::handlePacket(uint8_t *packet, size_t packetLen) {
|
||||
// uint16_t crc = CRC::crc16ccitt(packet, packetLen);
|
||||
// if (crc != 0) {
|
||||
// //CRC error
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// uint8_t command = packet[0];
|
||||
// uint8_t address = packet[1];
|
||||
//
|
||||
// uint16_t size = (packet[2] << 8) + packet[3];
|
||||
//
|
||||
// if (size != packetLen - 6) {
|
||||
// //Invalid Length
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// switch (command) {
|
||||
// case ArduinoCookie::SPI: {
|
||||
// ArduinoCookie **itsComplicated;
|
||||
// ReturnValue_t result = spiMap.find(address, &itsComplicated);
|
||||
// if (result != RETURN_OK) {
|
||||
// //we do no know this address
|
||||
// return;
|
||||
// }
|
||||
// ArduinoCookie *theActualCookie = *itsComplicated;
|
||||
// if (packetLen > theActualCookie->maxReplySize + 6) {
|
||||
// packetLen = theActualCookie->maxReplySize + 6;
|
||||
// }
|
||||
// memcpy(theActualCookie->replyBuffer, packet + 4, packetLen - 6);
|
||||
// theActualCookie->receivedDataLen = packetLen - 6;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// return;
|
||||
// }
|
||||
//}
|
@ -1,73 +0,0 @@
|
||||
//#ifndef MISSION_ARDUINOCOMMINTERFACE_H_
|
||||
//#define MISSION_ARDUINOCOMMINTERFACE_H_
|
||||
//
|
||||
//#include <bits/stdint-uintn.h>
|
||||
//#include <framework/container/FixedMap.h>
|
||||
//#include <framework/container/SimpleRingBuffer.h>
|
||||
//#include <framework/devicehandlers/DeviceCommunicationIF.h>
|
||||
//#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
//#include <stddef.h>
|
||||
//
|
||||
//#include "../../framework/objectmanager/SystemObject.h"
|
||||
//#include "ArduinoCookie.h"
|
||||
//
|
||||
////Forward declaration, so users don't peek
|
||||
//class ArduinoCookie;
|
||||
//
|
||||
//class ArduinoComIF: public SystemObject,
|
||||
// public DeviceCommunicationIF {
|
||||
//public:
|
||||
// static const uint8_t MAX_NUMBER_OF_SPI_DEVICES = 8;
|
||||
// static const uint8_t MAX_PACKET_SIZE = 64;
|
||||
//
|
||||
// static const uint8_t COMMAND_INVALID = -1;
|
||||
// static const uint8_t COMMAND_SPI = 1;
|
||||
//
|
||||
// ArduinoComIF(object_id_t setObjectId, const char *serialDevice);
|
||||
// virtual ~ArduinoComIF();
|
||||
//
|
||||
// virtual ReturnValue_t open(Cookie **cookie, uint32_t address,
|
||||
// uint32_t maxReplyLen);
|
||||
//
|
||||
// virtual ReturnValue_t reOpen(Cookie *cookie, uint32_t address,
|
||||
// uint32_t maxReplyLen);
|
||||
//
|
||||
// virtual void close(Cookie *cookie);
|
||||
//
|
||||
// //SHOULDDO can data be const?
|
||||
// virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data,
|
||||
// uint32_t len);
|
||||
//
|
||||
// virtual ReturnValue_t getSendSuccess(Cookie *cookie);
|
||||
//
|
||||
// virtual ReturnValue_t requestReceiveMessage(Cookie *cookie);
|
||||
//
|
||||
// virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer,
|
||||
// uint32_t *size);
|
||||
//
|
||||
// virtual ReturnValue_t setAddress(Cookie *cookie, uint32_t address);
|
||||
//
|
||||
// virtual uint32_t getAddress(Cookie *cookie);
|
||||
//
|
||||
// virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter);
|
||||
//
|
||||
// virtual uint32_t getParameter(Cookie *cookie);
|
||||
//private:
|
||||
// //remembering if the initialization in the ctor worked
|
||||
// //if not, all calls are disabled
|
||||
// bool initialized;
|
||||
// int serialPort;
|
||||
// //used to know where to put the data if a reply is received
|
||||
// FixedMap<uint8_t, ArduinoCookie*> spiMap;
|
||||
//
|
||||
// SimpleRingBuffer rxBuffer;
|
||||
//
|
||||
// ReturnValue_t sendMessage(uint8_t command, uint8_t address,
|
||||
// const uint8_t *data, size_t dataLen);
|
||||
//
|
||||
// void handleSerialPortRx();
|
||||
//
|
||||
// void handlePacket(uint8_t *packet, size_t packetLen);
|
||||
//};
|
||||
//
|
||||
//#endif /* MISSION_ARDUINOCOMMINTERFACE_H_ */
|
@ -81,23 +81,28 @@ ReturnValue_t CspComIF::sendMessage(CookieIF *cookie,
|
||||
/* Extract csp port and bytes to query from command buffer */
|
||||
uint8_t cspPort;
|
||||
uint16_t querySize;
|
||||
SerializeAdapter::deSerialize(&cspPort, &sendData, &sendLen,
|
||||
SerializeIF::Endianness::BIG);
|
||||
SerializeAdapter::deSerialize(&querySize, &sendData, &sendLen,
|
||||
SerializeIF::Endianness::BIG);
|
||||
// result = SerializeAdapter::deSerialize(&cspPort, &sendData,
|
||||
// &sendLen, SerializeIF::Endianness::BIG);
|
||||
// if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
// sif::error << "CspComIF: Failed to deserialize CSP port from command "
|
||||
// << "buffer" << std::endl;
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
// SerializeAdapter::deSerialize(&querySize, &sendData, &sendLen,
|
||||
// SerializeIF::Endianness::BIG);
|
||||
// if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
// sif::error << "CspComIF: Failed to deserialize querySize from command "
|
||||
// << "buffer" << std::endl;
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
result = getPortAndQuerySize(&sendData, &sendLen, &cspPort, &querySize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
uint8_t cspAddress = cspCookie->getCspAddress();
|
||||
switch(cspPort) {
|
||||
case(Ports::CSP_PING): {
|
||||
uint32_t timeout = 1000; // ms
|
||||
unsigned int pingSize = 100; // 100 bytes
|
||||
uint32_t replyTime = csp_ping(cspAddress, timeout, pingSize,
|
||||
CSP_O_NONE);
|
||||
sif::info << "Ping address: " << cspAddress << ", reply after "
|
||||
<< replyTime << " ms" << std::endl;
|
||||
/* Store reply time in reply buffer * */
|
||||
uint8_t* replyBuffer = cspDeviceMap[cspAddress].data();
|
||||
memcpy(replyBuffer, &replyTime, sizeof(replyTime));
|
||||
replySize = sizeof(replyTime);
|
||||
initiatePingRequest(cspAddress, querySize);
|
||||
break;
|
||||
}
|
||||
case(Ports::CSP_REBOOT): {
|
||||
@ -153,7 +158,7 @@ ReturnValue_t CspComIF::readReceivedMessage(CookieIF *cookie,
|
||||
ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
|
||||
const uint8_t* cmdBuffer, int cmdBufferLen, uint16_t querySize) {
|
||||
|
||||
uint32_t timeout_ms = 1000;
|
||||
uint32_t timeout_ms = 500;
|
||||
vectorBufferIter iter = cspDeviceMap.find(cspAddress);
|
||||
if(iter == cspDeviceMap.end()){
|
||||
sif::error << "CSP device with address " << cspAddress << " no found in"
|
||||
@ -185,3 +190,34 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CspComIF::getPortAndQuerySize(const uint8_t** sendData,
|
||||
size_t* sendLen, uint8_t* cspPort, uint16_t* querySize) {
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(cspPort, sendData,
|
||||
sendLen, SerializeIF::Endianness::BIG);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "CspComIF: Failed to deserialize CSP port from command "
|
||||
<< "buffer" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
SerializeAdapter::deSerialize(querySize, sendData, sendLen,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "CspComIF: Failed to deserialize querySize from command "
|
||||
<< "buffer" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CspComIF::initiatePingRequest(uint8_t cspAddress, uint16_t querySize){
|
||||
uint32_t timeout_ms = 500;
|
||||
uint32_t replyTime = csp_ping(cspAddress, timeout_ms, querySize,
|
||||
CSP_O_NONE);
|
||||
sif::info << "Ping address: " << cspAddress << ", reply after "
|
||||
<< replyTime << " ms" << std::endl;
|
||||
/* Store reply time in reply buffer * */
|
||||
uint8_t* replyBuffer = cspDeviceMap[cspAddress].data();
|
||||
memcpy(replyBuffer, &replyTime, sizeof(replyTime));
|
||||
replySize = sizeof(replyTime);
|
||||
}
|
||||
|
@ -69,6 +69,18 @@ private:
|
||||
|
||||
/* Interface struct for csp protocol stack */
|
||||
csp_iface_t csp_if;
|
||||
|
||||
/**
|
||||
* @brief Function to extract the csp port and the query size from the
|
||||
* command buffer.
|
||||
*/
|
||||
ReturnValue_t getPortAndQuerySize(const uint8_t** sendData, size_t* sendLen,
|
||||
uint8_t* cspPort, uint16_t* querySize);
|
||||
|
||||
/**
|
||||
* @brief This function initiates the ping request.
|
||||
*/
|
||||
void initiatePingRequest(uint8_t cspAddress, uint16_t querySize);
|
||||
};
|
||||
|
||||
#endif /* BSP_LINUX_COMIF_COOKIES_CSPCOMIF_H_ */
|
||||
|
@ -1,170 +0,0 @@
|
||||
#include "P60DockComIF.h"
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/drivers/can_socketcan.h>
|
||||
#include <bsp_linux/comIF/cookies/P60DockCookie.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <gomspace/libparam_client/include/gs/param/rparam.h>
|
||||
|
||||
P60DockComIF::P60DockComIF(object_id_t objectId) :
|
||||
SystemObject(objectId) {
|
||||
|
||||
}
|
||||
|
||||
P60DockComIF::~P60DockComIF() {
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockComIF::initializeInterface(CookieIF *cookie) {
|
||||
if(cookie == nullptr) {
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
P60DockCookie* p60DockCookie = dynamic_cast<P60DockCookie*>(cookie);
|
||||
if(p60DockCookie == nullptr) {
|
||||
return NULLPOINTER;
|
||||
}
|
||||
char* canInterface = p60DockCookie->getCanIf();
|
||||
int bitrate = p60DockCookie->getBitrate();
|
||||
/* Define the memory to allocate for the CSP stack */
|
||||
int buf_count = 10;
|
||||
int buf_size = 300;
|
||||
/* Init CSP and CSP buffer system */
|
||||
if (csp_init(cspClientAddress) != CSP_ERR_NONE
|
||||
|| csp_buffer_init(buf_count, buf_size) != CSP_ERR_NONE) {
|
||||
sif::error << "Failed to init CSP\r\n" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
int promisc = 0; // Set filter mode on
|
||||
csp_iface_t *csp_if_ptr = &csp_if;
|
||||
csp_if_ptr = csp_can_socketcan_init(canInterface, bitrate, promisc);
|
||||
|
||||
/* Set default route and start router */
|
||||
uint8_t address = CSP_DEFAULT_ROUTE;
|
||||
uint8_t netmask = 0;
|
||||
uint8_t mac = CSP_NODE_MAC;
|
||||
int result = csp_rtable_set(address, netmask, csp_if_ptr, mac);
|
||||
if(result != CSP_ERR_NONE){
|
||||
sif::error << "Failed to add can interface to router table"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/* Start the route task */
|
||||
unsigned int task_stack_size = 500;
|
||||
unsigned int priority = 0;
|
||||
result = csp_route_start_task(task_stack_size, priority);
|
||||
if(result != CSP_ERR_NONE){
|
||||
sif::error << "Failed to start csp route task" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockComIF::sendMessage(CookieIF *cookie,
|
||||
const uint8_t * sendData, size_t sendLen) {
|
||||
if(cookie == NULL){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
P60DockCookie* p60DockCookie = dynamic_cast<P60DockCookie*> (cookie);
|
||||
if(p60DockCookie == NULL){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
MessageType_t messageType = p60DockCookie->getMessageType();
|
||||
|
||||
switch(messageType){
|
||||
case(P60DockCookie::PING):{
|
||||
uint32_t timeout = 1000; // ms
|
||||
unsigned int pingSize = 100; // 100 bytes
|
||||
uint8_t p60DockAddress = p60DockCookie->getCspAddress();
|
||||
uint32_t replyTime = csp_ping(p60DockAddress, timeout, pingSize,
|
||||
CSP_O_NONE);
|
||||
sif::info << "Ping address: " << p60DockAddress << ", reply after "
|
||||
<< replyTime << " ms" << std::endl;
|
||||
/* Store reply time in reply buffer * */
|
||||
memcpy(replyBuffer, &replyTime, sizeof(replyTime));
|
||||
break;
|
||||
}
|
||||
case(P60DockCookie::REBOOT):{
|
||||
csp_reboot(p60DockCookie->getCspAddress());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockComIF::readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t** buffer, size_t* size) {
|
||||
if(cookie == NULL){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
P60DockCookie* p60DockCookie = dynamic_cast<P60DockCookie*> (cookie);
|
||||
if(p60DockCookie == NULL){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
MessageType_t messageType = p60DockCookie->getMessageType();
|
||||
|
||||
switch(messageType){
|
||||
case(P60DockCookie::READ_MODULE_CONFIG):{
|
||||
uint32_t timeout = 1000; // ms
|
||||
uint8_t p60dockAddress = p60DockCookie->getCspAddress();
|
||||
gs_param_table_instance_t table;
|
||||
table.rows = (gs_param_table_row_t*)p60dock_config;
|
||||
table.id = moduleCfgTableNum;
|
||||
table.row_count = p60dock_config_count;
|
||||
table.memory_size = P60DOCK_PARAM_SIZE;
|
||||
table.memory = replyBuffer;
|
||||
/* Read complete module configuration table from P60 Dock and store data
|
||||
* in buffer */
|
||||
int result = gs_rparam_get_full_table(&table, p60dockAddress,
|
||||
table.id, GS_RPARAM_MAGIC_CHECKSUM, timeout);
|
||||
*size = P60DOCK_PARAM_SIZE;
|
||||
if (result != GS_OK) {
|
||||
sif::info
|
||||
<< "Failed retrieving module configuration from P60 dock "
|
||||
<< "with error code " << result << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(P60DockCookie::READ_HK):{
|
||||
uint32_t timeout = 1000; // ms
|
||||
uint8_t p60dockAddress = p60DockCookie->getCspAddress();
|
||||
table.rows = (gs_param_table_row_t*)p60dock_hk;
|
||||
table.id = tmTableNum;
|
||||
table.row_count = p60dock_hk_count;
|
||||
table.memory_size = P60DOCK_HK_SIZE;
|
||||
table.memory = replyBuffer;
|
||||
/* Read complete module configuration table from P60 Dock and store data
|
||||
* in buffer */
|
||||
int result = gs_rparam_get_full_table(&table, p60dockAddress,
|
||||
table.id, GS_RPARAM_MAGIC_CHECKSUM, timeout);
|
||||
*size = P60DOCK_HK_SIZE;
|
||||
if (result != GS_OK) {
|
||||
sif::info
|
||||
<< "Failed retrieving telemetry from P60 dock with error "
|
||||
<< "code " << result << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* P60DockComIF.h
|
||||
*
|
||||
* Created on: 01.12.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#ifndef BSP_LINUX_COMIF_P60DOCKCOMIF_H_
|
||||
#define BSP_LINUX_COMIF_P60DOCKCOMIF_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include <gomspace/libcsp/include/csp/csp_types.h>
|
||||
#include <gomspace/libcsp/include/csp/csp_error.h>
|
||||
#include <gomspace/libparam_client/include/gs/param/types.h>
|
||||
#include <gs/param/internal/types.h>
|
||||
#include <p60dock.h>
|
||||
|
||||
/**
|
||||
* @brief This is the communication interface to the cubesat space protocol
|
||||
* stack. The physical layer used for this implementation is CAN.
|
||||
* @author Jakob Meier
|
||||
*/
|
||||
class P60DockComIF: public DeviceCommunicationIF, public SystemObject {
|
||||
public:
|
||||
static const uint16_t maxReplyLength = 412;
|
||||
|
||||
P60DockComIF(object_id_t objectId);
|
||||
virtual ~P60DockComIF();
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
|
||||
size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **readData, size_t *readLen) override;
|
||||
|
||||
private:
|
||||
/* This is the CSP address of the OBC. */
|
||||
uint8_t cspClientAddress = 1;
|
||||
/* Interface struct for csp protocol stack */
|
||||
csp_iface_t csp_if;
|
||||
/* Table definitions. According to gomspace software documentation there
|
||||
* exist four tables each identified by a number*/
|
||||
uint8_t moduleCfgTableNum = 1;
|
||||
uint8_t calibrationParamTableNum = 2;
|
||||
uint8_t tmTableNum = 4;
|
||||
/* Replies of P60 dock are written to this buffer */
|
||||
uint8_t replyBuffer[P60DockComIF::maxReplyLength];
|
||||
gs_param_table_instance_t table;
|
||||
|
||||
};
|
||||
|
||||
#endif /* BSP_LINUX_COMIF_P60DOCKCOMIF_H_ */
|
@ -1,12 +0,0 @@
|
||||
//#include <mission/Arduino/ArduinoCookie.h>
|
||||
//
|
||||
//ArduinoCookie::ArduinoCookie(Protocol_t protocol, uint8_t address,
|
||||
// size_t maxReplySize) :
|
||||
// command(protocol), address(address), receivedDataLen(0), maxReplySize(
|
||||
// maxReplySize) {
|
||||
// replyBuffer = new uint8_t[maxReplySize];
|
||||
//}
|
||||
//
|
||||
//ArduinoCookie::~ArduinoCookie() {
|
||||
// delete[] replyBuffer;
|
||||
//}
|
@ -1,25 +0,0 @@
|
||||
//#ifndef MISSION_ARDUINO_ARDUINOCOOKIE_H_
|
||||
//#define MISSION_ARDUINO_ARDUINOCOOKIE_H_
|
||||
//
|
||||
//#include <framework/devicehandlers/Cookie.h>
|
||||
//
|
||||
//#include <stdint.h>
|
||||
//#include <stdlib.h>
|
||||
//
|
||||
//class ArduinoCookie: public Cookie {
|
||||
//public:
|
||||
// enum Protocol_t {
|
||||
// INVALID = 0, SPI = 1
|
||||
// };
|
||||
// ArduinoCookie(Protocol_t protocol, uint8_t address, size_t maxReplySize);
|
||||
// virtual ~ArduinoCookie();
|
||||
//
|
||||
// uint8_t command;
|
||||
// uint8_t address;
|
||||
// uint8_t *replyBuffer;
|
||||
// size_t receivedDataLen;
|
||||
// size_t maxReplySize;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//#endif /* MISSION_ARDUINO_ARDUINOCOOKIE_H_ */
|
@ -1,46 +0,0 @@
|
||||
#include "bsp_linux/comIF/cookies/P60DockCookie.h"
|
||||
|
||||
|
||||
P60DockCookie::P60DockCookie(uint8_t cspAddress_) :
|
||||
cspAddress(cspAddress_) {
|
||||
|
||||
}
|
||||
|
||||
P60DockCookie::~P60DockCookie() {
|
||||
}
|
||||
|
||||
uint8_t P60DockCookie::getCspAddress(){
|
||||
return cspAddress;
|
||||
}
|
||||
|
||||
char* P60DockCookie::getCanIf(){
|
||||
return canInterface;
|
||||
}
|
||||
|
||||
int P60DockCookie::getBitrate(){
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
void P60DockCookie::resetMessageType(){
|
||||
nextMessage = MESSAGE_NONE;
|
||||
}
|
||||
|
||||
void P60DockCookie::setPingMessage(){
|
||||
nextMessage = PING;
|
||||
}
|
||||
|
||||
void P60DockCookie::setRebootMessage(){
|
||||
nextMessage = REBOOT;
|
||||
}
|
||||
|
||||
void P60DockCookie::setReadModuleCfgMessage(){
|
||||
nextMessage = READ_MODULE_CONFIG;
|
||||
}
|
||||
|
||||
void P60DockCookie::setReadHkMessage(){
|
||||
nextMessage = READ_HK;
|
||||
}
|
||||
|
||||
MessageType_t P60DockCookie::getMessageType(){
|
||||
return nextMessage;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef BSP_LINUX_COMIF_COOKIES_P60DockCookie_H_
|
||||
#define BSP_LINUX_COMIF_COOKIES_P60DockCookie_H_
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
|
||||
typedef uint32_t MessageType_t;
|
||||
|
||||
/**
|
||||
* @brief This is the cookie for the communication interface to the cubesat
|
||||
* space protocol (CSP) implementation of gomspace. The communication
|
||||
* interface uses CAN as the physical layer. Therefore the cookie also
|
||||
* holds the CAN instance to use.
|
||||
* @author Jakob Meier
|
||||
*/
|
||||
class P60DockCookie: public CookieIF {
|
||||
public:
|
||||
/**
|
||||
* Constructor for the CSP cookie
|
||||
* @param cspAddress_ The CSP address of the target device.
|
||||
*/
|
||||
P60DockCookie(uint8_t cspAddress_);
|
||||
virtual ~P60DockCookie();
|
||||
|
||||
uint8_t getCspAddress();
|
||||
char* getCanIf();
|
||||
int getBitrate();
|
||||
void setPingMessage();
|
||||
void setRebootMessage();
|
||||
void setReadModuleCfgMessage();
|
||||
void setReadHkMessage();
|
||||
MessageType_t getMessageType();
|
||||
void resetMessageType();
|
||||
|
||||
/* Message type defines the type of the next data transfer between the
|
||||
* CSP device and the OBC. */
|
||||
static const MessageType_t MESSAGE_NONE = 0x0;
|
||||
static const MessageType_t PING = 0x1;
|
||||
static const MessageType_t REBOOT = 0x4;
|
||||
static const MessageType_t READ_MODULE_CONFIG = 0x71;
|
||||
static const MessageType_t READ_HK = 0x74;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
char canInterface[5] = "can0";
|
||||
uint8_t cspAddress;
|
||||
int bitrate = 1000;
|
||||
MessageType_t nextMessage = MESSAGE_NONE;
|
||||
};
|
||||
|
||||
#endif /* BSP_LINUX_COMIF_COOKIES_P60DockCookie_H_ */
|
Reference in New Issue
Block a user