parts of p60dock handler
This commit is contained in:
parent
fa58479b34
commit
87e121f016
@ -129,6 +129,14 @@ void InitMission::initTasks(){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
/* Device Handler */
|
||||
PeriodicTaskIF* DeviceHandler = TaskFactory::instance()->
|
||||
createPeriodicTask("Device Handler", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
1, nullptr);
|
||||
result = DeviceHandler->addComponent(objects::P60DOCK_HANDLER);
|
||||
if(result!=HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
#if ADD_TEST_CODE == 1
|
||||
// FixedTimeslotTaskIF* TestTimeslotTask = TaskFactory::instance()->
|
||||
@ -160,6 +168,8 @@ void InitMission::initTasks(){
|
||||
PusHighPrio->startTask();
|
||||
PusMedPrio->startTask();
|
||||
PusLowPrio->startTask();
|
||||
|
||||
DeviceHandler->startTask();
|
||||
#if ADD_TEST_CODE == 1
|
||||
// TestTimeslotTask->startTask();
|
||||
P60DockTestTask->startTask();
|
||||
|
@ -1,4 +1,6 @@
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp)
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/comIF/cookies/*.cpp)
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/comIF/*.cpp)
|
||||
CSRC += $(wildcard $(CURRENTPATH)/*.c)
|
||||
|
||||
CSRC += $(wildcard $(CURRENTPATH)/boardconfig/*.c)
|
@ -1,324 +1,324 @@
|
||||
#include "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;
|
||||
}
|
||||
}
|
||||
//#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;
|
||||
// }
|
||||
//}
|
||||
|
120
bsp_linux/comIF/P60DockComIF.cpp
Normal file
120
bsp_linux/comIF/P60DockComIF.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#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);
|
||||
uint8_t cspAddress = p60DockCookie->getCspAddress();
|
||||
char* canInterface = p60DockCookie->getCanIf();
|
||||
int bitrate = p60DockCookie->getBitrate();
|
||||
|
||||
int buf_count = 10;
|
||||
int buf_size = 300;
|
||||
/* Init CSP and CSP buffer system */
|
||||
if (csp_init(cspAddress) != 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 = 512;
|
||||
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) {
|
||||
P60DockCookie* p60DockCookie = dynamic_cast<P60DockCookie*> (cookie);
|
||||
MessageType_t messageType = p60DockCookie->getMessageType();
|
||||
|
||||
switch(messageType){
|
||||
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) {
|
||||
P60DockCookie* p60DockCookie = dynamic_cast<P60DockCookie*> (cookie);
|
||||
MessageType_t messageType = p60DockCookie->getMessageType();
|
||||
|
||||
switch(messageType){
|
||||
case(P60DockCookie::READ_MODULE_CONFIG):{
|
||||
uint32_t timeout = 1000;
|
||||
uint8_t p60dockAddress = p60DockCookie->getCspAddress();
|
||||
gs_param_table_instance_t moduleConfig;
|
||||
moduleConfig.rows = moduleConfigTable;
|
||||
moduleConfig.id = p60dockAddress;
|
||||
moduleConfig.row_count = p60dock_hk_count;
|
||||
moduleConfig.memory_size = P60DOCK_HK_SIZE;
|
||||
moduleConfig.memory = *buffer;
|
||||
/* Read complete module configuration table from P60 Dock and store data
|
||||
* in buffer */
|
||||
int result = gs_rparam_get_full_table(&moduleConfig, p60dockAddress,
|
||||
node_hk.id, GS_RPARAM_MAGIC_CHECKSUM, timeout);
|
||||
*size = P60DOCK_HK_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;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
52
bsp_linux/comIF/P60DockComIF.h
Normal file
52
bsp_linux/comIF/P60DockComIF.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
/**
|
||||
* @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:
|
||||
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:
|
||||
/* 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 boardConfigTable = 0;
|
||||
uint8_t modulConfigTable = 1;
|
||||
uint8_t calibrationParamTable = 2;
|
||||
uint8_t tmDataTable = 4;
|
||||
unsigned int moduleConfigTableRows = 32;
|
||||
|
||||
};
|
||||
|
||||
#endif /* BSP_LINUX_COMIF_P60DOCKCOMIF_H_ */
|
38
bsp_linux/comIF/cookies/P60DockCookie.cpp
Normal file
38
bsp_linux/comIF/cookies/P60DockCookie.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "bsp_linux/comIF/cookies/P60DockCookie.h"
|
||||
|
||||
|
||||
P60DockCookie::P60DockCookie(char* canInterface_, uint8_t cspAddress_) :
|
||||
canInterface(canInterface_), cspAddress(cspAddress_) {
|
||||
|
||||
}
|
||||
|
||||
P60DockCookie::~P60DockCookie() {
|
||||
}
|
||||
|
||||
uint8_t P60DockCookie::getCspAddress(){
|
||||
return cspAddress;
|
||||
}
|
||||
|
||||
char* P60DockCookie::getCanIf(){
|
||||
return canInterface;
|
||||
}
|
||||
|
||||
int P60DockCookie::getBitrate(){
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
void P60DockCookie::setPingMessage(){
|
||||
nextMessage = PING;
|
||||
}
|
||||
|
||||
void P60DockCookie::setRebootMessage(){
|
||||
nextMessage = REBOOT;
|
||||
}
|
||||
|
||||
void P60DockCookie::setReadModuleCfgMessage(){
|
||||
nextMessage = READ_MODULE_CONFIG;
|
||||
}
|
||||
|
||||
MessageType_t P60DockCookie::getMessageType(){
|
||||
return nextMessage;
|
||||
}
|
49
bsp_linux/comIF/cookies/P60DockCookie.h
Normal file
49
bsp_linux/comIF/cookies/P60DockCookie.h
Normal file
@ -0,0 +1,49 @@
|
||||
#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 canInterface_ The CAN interface to use. E.g. "can0" or "can1".
|
||||
* @param cspAddress_ The CSP address of the target device.
|
||||
*/
|
||||
P60DockCookie(char* canInterface_, uint8_t cspAddress_);
|
||||
virtual ~P60DockCookie();
|
||||
|
||||
uint8_t getCspAddress();
|
||||
char* getCanIf();
|
||||
int getBitrate();
|
||||
void setPingMessage();
|
||||
void setRebootMessage();
|
||||
void setReadModuleCfgMessage();
|
||||
MessageType_t getMessageType();
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
char* canInterface;
|
||||
uint8_t cspAddress;
|
||||
int bitrate = 1000;
|
||||
MessageType_t nextMessage = MESSAGE_NONE;
|
||||
};
|
||||
|
||||
#endif /* BSP_LINUX_COMIF_COOKIES_P60DockCookie_H_ */
|
@ -6,7 +6,7 @@
|
||||
#ifndef FSFWCONFIG_OBSWCONFIG_H_
|
||||
#define FSFWCONFIG_OBSWCONFIG_H_
|
||||
|
||||
#define ADD_TEST_CODE 1
|
||||
#define ADD_TEST_CODE 0
|
||||
|
||||
// Define not used yet, PUS stack and TMTC tasks are always started
|
||||
#define ADD_PUS_STACK 1
|
||||
|
@ -4,7 +4,7 @@
|
||||
* \date 06.11.2019
|
||||
*/
|
||||
|
||||
#include <fsfwconfig/devices/logicalAddresses.h>
|
||||
#include "addresses.h"
|
||||
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* \file logicalAddresses.cpp
|
||||
* \file addresses.cpp
|
||||
*
|
||||
* \date 07.11.2019
|
||||
*/
|
||||
|
||||
#ifndef FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_
|
||||
#define FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_
|
||||
#ifndef FSFWCONFIG_DEVICES_ADDRESSES_H_
|
||||
#define FSFWCONFIG_DEVICES_ADDRESSES_H_
|
||||
#include <stdint.h>
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <fsfwconfig/objects/systemObjectList.h>
|
||||
@ -20,7 +20,14 @@ namespace addresses {
|
||||
DUMMY_GPS0 = 130,
|
||||
DUMMY_GPS1 = 131,
|
||||
};
|
||||
|
||||
/* Addresses of devices supporting the CSP protocol */
|
||||
enum cspAddresses: uint8_t {
|
||||
P60DOCK = 4,
|
||||
/* PDU2 occupies X4 slot of P60Dock */
|
||||
PDU2 = 6
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_ */
|
||||
#endif /* FSFWCONFIG_DEVICES_ADDRESSES_H_ */
|
@ -27,10 +27,14 @@ namespace objects {
|
||||
TEST_TASK = 0x42694269,
|
||||
DUMMY_INTERFACE = 0xCAFECAFE,
|
||||
DUMMY_HANDLER = 0x4400AFFE,
|
||||
P60DOCK_TEST_TASK = 0x00005060,
|
||||
|
||||
/* 0x49 ('I') for Communication Interfaces **/
|
||||
ARDUINO_COM_IF = 0x49000001,
|
||||
P60DOCK_TEST_TASK = 0x00005060
|
||||
P60_DOCK_COM_IF = 0x49000002,
|
||||
|
||||
/* 0x44 ('D') for device handlers */
|
||||
P60DOCK_HANDLER = 0x44000001
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <fsfwconfig/tmtc/apid.h>
|
||||
#include <fsfwconfig/tmtc/pusIds.h>
|
||||
#include <fsfwconfig/OBSWconfig.h>
|
||||
#include <fsfwconfig/devices/addresses.h>
|
||||
|
||||
#include <fsfw/events/EventManager.h>
|
||||
#include <fsfw/health/HealthTable.h>
|
||||
@ -19,6 +20,9 @@
|
||||
#include <fsfw/tcdistribution/PUSDistributor.h>
|
||||
#include <fsfw/timemanager/TimeStamper.h>
|
||||
#include <mission/utility/TmFunnel.h>
|
||||
#include <mission/devices/P60DockHandler.h>
|
||||
#include <bsp_linux/comIF/cookies/P60DockCookie.h>
|
||||
#include <bsp_linux/comIF/P60DockComIF.h>
|
||||
|
||||
#if ADD_TEST_CODE == 1
|
||||
//#include <test/testtasks/TestTask.h>
|
||||
@ -81,6 +85,17 @@ void ObjectFactory::produceGenericObjects() {
|
||||
new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT,
|
||||
apid::EIVE_OBSW, pus::PUS_SERVICE_200);
|
||||
|
||||
char canInterface[] = "can0";
|
||||
/* Cookies */
|
||||
P60DockCookie* p60DockCookie = new P60DockCookie(canInterface, addresses::P60DOCK);
|
||||
|
||||
/* Communication interfaces */
|
||||
new P60DockComIF(objects::P60_DOCK_COM_IF);
|
||||
|
||||
/* Device Handler */
|
||||
new P60DockHandler(objects::P60DOCK_HANDLER, objects::P60_DOCK_COM_IF,
|
||||
p60DockCookie);
|
||||
|
||||
/* Test Device Handler */
|
||||
#if ADD_TEST_CODE == 1
|
||||
// new TestTask(objects::TEST_TASK);
|
||||
|
@ -1,23 +1,84 @@
|
||||
/*
|
||||
* P60DockHandler.cpp
|
||||
*
|
||||
* Created on: 18.11.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/interfaces/csp_if_can.h>
|
||||
#include "P60DockHandler.h"
|
||||
#include <mission/devices/P60DockHandler.h>
|
||||
#include "bsp_linux/comIF/cookies/P60DockCookie.h"
|
||||
#include "bsp_linux/comIF/P60DockComIF.h"
|
||||
|
||||
P60DockHandler::P60DockHandler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * comCookie):DeviceHandlerBase(objectId, comIF, comCookie) {
|
||||
}
|
||||
|
||||
P60DockHandler::~P60DockHandler() {
|
||||
}
|
||||
|
||||
|
||||
void P60DockHandler::doStartUp(){
|
||||
|
||||
}
|
||||
|
||||
void P60DockHandler::doShutDown(){
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockHandler::buildNormalDeviceCommand(DeviceCommandId_t * id){
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockHandler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t * id){
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockHandler::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(READ_MODULE_CFG):{
|
||||
internalState = InternalStates::READ_MODULE_CFG;
|
||||
break;
|
||||
}
|
||||
case(PING): {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void P60DockHandler::fillCommandAndReplyMap(){
|
||||
this->insertInCommandAndReplyMap(READ_MODULE_CFG, 3);
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start,
|
||||
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
switch(internalState) {
|
||||
case(InternalStates::READ_MODULE_CFG): {
|
||||
*foundId = READ_MODULE_CFG;
|
||||
*foundLen = moduleCfgTableSize;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IGNORE_REPLY_DATA;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
switch(id) {
|
||||
case(READ_MODULE_CFG): {
|
||||
handleDeviceTM((SerializeIF*)packet, id, true, true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void setNormalDatapoolEntriesInvalid(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//P60DockHandler::P60DockHandler() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
//P60DockHandler::~P60DockHandler() {
|
||||
//}
|
||||
//
|
||||
//
|
||||
//P60DockHandler::performOperation(uint8_t operationCode) {
|
||||
//
|
||||
//}
|
||||
|
@ -1,18 +1,40 @@
|
||||
/*
|
||||
* P60DockHandler.h
|
||||
*
|
||||
* Created on: 18.11.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#ifndef MISSION_DEVICES_P60DOCKHANDLER_H_
|
||||
#define MISSION_DEVICES_P60DOCKHANDLER_H_
|
||||
|
||||
//class P60DockHandler: public DeviceHandlerBase {
|
||||
//public:
|
||||
// P60DockHandler();
|
||||
// virtual ~P60DockHandler();
|
||||
// virtual ReturnValue_t performOperation(uint8_t operationCode = 0);
|
||||
//};
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
|
||||
class P60DockHandler: public DeviceHandlerBase {
|
||||
public:
|
||||
P60DockHandler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * comCookie);
|
||||
virtual ~P60DockHandler();
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t * commandData,size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
void setNormalDatapoolEntriesInvalid() override;
|
||||
|
||||
private:
|
||||
|
||||
static const DeviceCommandId_t PING = 0x1; //!< [EXPORT] : [COMMAND]
|
||||
static const DeviceCommandId_t READ_MODULE_CFG = 0xE; //!< [EXPORT] : [COMMAND]
|
||||
|
||||
enum class InternalStates {
|
||||
STATE_NONE,
|
||||
READ_MODULE_CFG
|
||||
};
|
||||
InternalStates internalState = InternalStates::STATE_NONE;
|
||||
|
||||
size_t moduleCfgTableSize = 188;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_P60DOCKHANDLER_H_ */
|
||||
|
@ -0,0 +1,58 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_P60DOCKHANDLERDEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_P60DOCKHANDLERDEFINITIONS_H_
|
||||
|
||||
/**
|
||||
* @brief This class helps to serialize and deserialze the P60 dock packet
|
||||
* holding information about the module configuration. The parameters
|
||||
* of this table are described in the gs-man-nanopower-p60-dock-2.2.9.pdf
|
||||
* on page 16.
|
||||
*/
|
||||
//class ModuleConfigTable : public SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 2
|
||||
//public:
|
||||
// typedef char dataBufferType;
|
||||
// typedef uint8_t typeOfMaxData;
|
||||
//
|
||||
// ModuleConfigTable() {
|
||||
// setStart(&objectId);
|
||||
// objectId.setNext(&sizeOfRepositoryPath);
|
||||
// sizeOfRepositoryPath.setNext(&repositoryPath);
|
||||
// repositoryPath.setNext(&sizeOfFilename);
|
||||
// sizeOfFilename.setNext(&filename);
|
||||
// /* Add string terminator to filename and repository path */
|
||||
// repositoryPath.entry.insert('\0');
|
||||
// filename.entry.insert('\0');
|
||||
// }
|
||||
//
|
||||
// uint32_t getSizeOfRepositoryPath() {
|
||||
// return sizeOfRepositoryPath;
|
||||
// }
|
||||
//
|
||||
// uint32_t getSizeOfFilename() {
|
||||
// return sizeOfFilename;
|
||||
// }
|
||||
//
|
||||
// uint8_t * getRepositoryPath() {
|
||||
// return repositoryPath.entry.front();
|
||||
// }
|
||||
//
|
||||
// uint8_t getFilename() {
|
||||
// return filename.entry.front();
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
// /* Prevent object copying */
|
||||
// ModuleConfigTable(const ModuleConfigTable &obj);
|
||||
//
|
||||
// SerializeElement<SerialBufferAdapter<char>> out_name;
|
||||
// SerializeElement<SerialBufferAdapter<uint8_t>> out_en;
|
||||
// SerializeElement<SerialBufferAdapter<uint16_t>> out_on_cnt;
|
||||
// SerializeElement<SerialBufferAdapter<uint16_t>> out_on_cnt;
|
||||
// SerializeElement<uint16_t> sizeOfRepositoryPath;
|
||||
// SerializeElement<SerialFixedArrayListAdapter<dataBufferType, FN_MAXPATHNAME, typeOfMaxData>> repositoryPath;
|
||||
// SerializeElement<uint8_t> sizeOfFilename;
|
||||
// SerializeElement<SerialFixedArrayListAdapter<dataBufferType, FN_MAXNAME, typeOfMaxData>> filename;
|
||||
//};
|
||||
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_P60DOCKHANDLERDEFINITIONS_H_ */
|
@ -20,7 +20,7 @@ SystemObject(objectId_){
|
||||
|
||||
ReturnValue_t P60DockTestTask::performOperation(uint8_t operationCode) {
|
||||
|
||||
if(sendPacket() != HasReturnvaluesIF::RETURN_OK){
|
||||
if(pingP60dock() != HasReturnvaluesIF::RETURN_OK){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -31,43 +31,7 @@ ReturnValue_t P60DockTestTask::performOperation(uint8_t operationCode) {
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t P60DockTestTask::sendPacket(void){
|
||||
|
||||
// char *msg = "HELLO";
|
||||
// /* Get packet buffer for data */
|
||||
// csp_packet_t *packet = csp_buffer_get(strlen(msg));
|
||||
// if (packet == NULL) {
|
||||
// /* Could not get buffer element */
|
||||
// sif::error("Failed to get buffer element\\n");
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
//
|
||||
// /* Connect P60 Dock */
|
||||
// csp_conn_t *conn = csp_connect(CSP_PRIO_NORM, c, CSP_PING,
|
||||
// 1000, CSP_O_NONE);
|
||||
//
|
||||
// if (conn == NULL) {
|
||||
// /* Connect failed */
|
||||
// sif::error("Connection failed\\n");
|
||||
// /* Remember to free packet buffer */
|
||||
// csp_buffer_free(packet);
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
//
|
||||
// /* Copy message to packet */
|
||||
// strcpy(packet->data, msg);
|
||||
// /* Set packet length */
|
||||
// packet->length = strlen(msg);
|
||||
//
|
||||
// /* Send packet */
|
||||
// if (!csp_send(conn, packet, 1000)) {
|
||||
// /* Send failed */
|
||||
// sif::error("Send failed\\n");
|
||||
// csp_buffer_free(packet);
|
||||
// }
|
||||
// /* Close connection */
|
||||
// csp_close(conn);
|
||||
|
||||
ReturnValue_t P60DockTestTask::pingP60dock(void){
|
||||
uint32_t timeout = 1000;
|
||||
unsigned int pingSize = 100; // 100 bytes
|
||||
uint32_t replyTime = csp_ping(p60dockAddress, timeout, pingSize, CSP_O_NONE);
|
||||
@ -78,54 +42,35 @@ ReturnValue_t P60DockTestTask::sendPacket(void){
|
||||
|
||||
|
||||
ReturnValue_t P60DockTestTask::getParameters(void) {
|
||||
// int result = rparam_get_full_table(&node_hk, p60dock_node, P60_PORT_RPARAM,
|
||||
uint32_t timeout = 1000;
|
||||
node_hk.rows = (gs_param_table_row_t*)p60dock_hk;
|
||||
node_hk.id = P60DOCK_HK;
|
||||
node_hk.row_count = p60dock_hk_count;
|
||||
node_hk.memory_size = P60DOCK_HK_SIZE;
|
||||
node_hk.memory = hk_mem;
|
||||
node_hk.memory = hkMem;
|
||||
/* Retriev all houskeeping data from the P60 dock and store it in hkMem
|
||||
* array */
|
||||
int result = gs_rparam_get_full_table(&node_hk, p60dockAddress, node_hk.id,
|
||||
GS_RPARAM_MAGIC_CHECKSUM, timeout);
|
||||
|
||||
if (result != 0) {
|
||||
sif::info << "Error retrieving P60 Dock housekeeping\n" << std::endl;
|
||||
sif::info << "Error retrieving P60 Dock housekeeping" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
} else {
|
||||
uint8_t tableOffsetTemperature = 0x44;
|
||||
int16_t temperature[2];
|
||||
int16_t temperature;
|
||||
size_t parameterSize = sizeof(temperature);
|
||||
uint32_t flags = 0;
|
||||
result = gs_param_get_data((gs_param_table_instance_t*) &node_hk,
|
||||
tableOffsetTemperature, temperature, parameterSize, flags);
|
||||
sif::info << "P60 Dock Temperature 1: " << temperature[0] << std::endl;
|
||||
sif::info << "P60 Dock Temperature 2: " << temperature[1] << std::endl;
|
||||
tableOffsetTemperature, &temperature, parameterSize, flags);
|
||||
sif::info << "P60 Dock Temperature: " << temperature << std::endl;
|
||||
|
||||
// sif::info << "Retrieved P60 Dock housekeeping\n" << std::endl;
|
||||
// /* List all out_en[] values, using parameter name */
|
||||
// const param_table_t * param = param_find_name(node_hk.table,
|
||||
// node_hk.count, "out_en");
|
||||
// if (param != NULL) {
|
||||
// for (uint8_t index = 0; index < 13; index++) {
|
||||
// /* Read parameter using name */
|
||||
// uint8_t *out_en = param_read_addr(
|
||||
// param->addr + param->size * index, &node_hk,
|
||||
// param->size);
|
||||
// sif::info << "out_en" << index << ": " << *out_en << std::endl;
|
||||
// }
|
||||
// }
|
||||
// /* List all c_out[] values, using parameter address */
|
||||
// param = param_find_addr(node_hk.table, node_hk.count, 0x0000);
|
||||
// if (param != NULL) {
|
||||
// for (uint8_t index = 0; index < 13; index++) {
|
||||
// /* Read parameter using address */
|
||||
// int16_t *c_out = param_read_addr(
|
||||
// param->addr + param->size * index, &node_hk,
|
||||
// param->size);
|
||||
// sif::info << "c_out" << index << ": " << *c_out << "mA"
|
||||
// << std::endl;
|
||||
// }
|
||||
// }
|
||||
uint16_t vbat_v;
|
||||
parameterSize = sizeof(vbat_v);
|
||||
uint8_t vbat_v_offset = 0x74;
|
||||
result = gs_param_get_data((gs_param_table_instance_t*) &node_hk,
|
||||
vbat_v_offset, &vbat_v, parameterSize, flags);
|
||||
sif::info << "VBAT_V: " << vbat_v << std::endl;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -133,7 +78,7 @@ ReturnValue_t P60DockTestTask::getParameters(void) {
|
||||
|
||||
ReturnValue_t P60DockTestTask::initializeCSPStack(void){
|
||||
/* Init CSP and CSP buffer system */
|
||||
if (csp_init(cspAddress) != CSP_ERR_NONE
|
||||
if (csp_init(cspClientAddress) != CSP_ERR_NONE
|
||||
|| csp_buffer_init(10, 300) != CSP_ERR_NONE) {
|
||||
sif::error << "Failed to init CSP\r\n" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
@ -30,21 +30,26 @@ public:
|
||||
private:
|
||||
/* Interface struct for csp protocol stack */
|
||||
csp_iface_t csp_if;
|
||||
/* CSP address of P60 dock */
|
||||
uint8_t p60dockAddress = 4;
|
||||
uint8_t CSP_PING = 1;
|
||||
uint8_t cspAddress = 1;
|
||||
/* Client CSP address */
|
||||
uint8_t cspClientAddress = 1;
|
||||
/* CAN interface used by CSP */
|
||||
const char* canIf = "can0";
|
||||
int bitrate = 1000; // bitrate of can
|
||||
int promisc = 0; // set to 0 to enable filter mode
|
||||
|
||||
uint8_t hk_mem[P60DOCK_HK_SIZE];
|
||||
uint8_t p60dock_node = 4;
|
||||
/* P60 Dock houskeeping parameters will be stored in this buffer */
|
||||
uint8_t hkMem[P60DOCK_HK_SIZE];
|
||||
gs_param_table_instance_t node_hk;
|
||||
/* Port of CSP ping requests on P60 dock */
|
||||
uint8_t CSP_PING = 1;
|
||||
|
||||
ReturnValue_t sendPacket(void);
|
||||
/* Sends ping request and receives ping reply */
|
||||
ReturnValue_t pingP60dock(void);
|
||||
ReturnValue_t initializeCSPStack(void);
|
||||
/* Temperature and raw battery voltage are read from the P60 dock by this
|
||||
* function */
|
||||
ReturnValue_t getParameters(void);
|
||||
|
||||
};
|
||||
|
||||
#endif /* TEST_TESTTASKS_P60DOCKTESTTASK_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user