resolved merge conflict

This commit is contained in:
Jakob Meier 2020-12-21 10:29:44 +01:00
commit dce00e9b53
165 changed files with 1385 additions and 2209 deletions

View File

@ -25,7 +25,7 @@ MISSION_PATH = mission
CONFIG_PATH = fsfwconfig
TEST_PATH = test
UNITTEST_PATH = unittest
GOMSPACE_PATH = gomspace
LIBCSP_PATH = libcsp
# Board specific paths
BSP_PATH = $(BOARD_FILE_ROOT)
@ -114,7 +114,7 @@ INCLUDES :=
# Directories where $(directoryname).mk files should be included from
SUBDIRS := $(FRAMEWORK_PATH) $(TEST_PATH) $(BSP_PATH) $(UNITTEST_PATH)\
$(CONFIG_PATH) $(MISSION_PATH) $(GOMSPACE_PATH)
$(CONFIG_PATH) $(MISSION_PATH) $(LIBCSP_PATH)
# INCLUDES += framework/test/catch2
# ETL library include.

View File

@ -323,3 +323,28 @@ git merge upstream/master
Alternatively, changes from other upstreams (forks) and branches can be merged like that in
the same way.
## PCDU
Connect to serial console of P60 Dock
````
picocom -b 500000 /dev/ttyUSBx
````
General information
````
cmp ident
````
List parameter table:
x values: 1,2 or 4
````
param table x
````
Table 4 lists HK parameters
Changing parameters
First switch to table where parameter shall be changed (here table id is 1)
````
p60-dock # param mem 1
p60-dock # param set out_en[0] 1
p60-dock # param get out_en[0]
GET out_en[0] = 1
````

View File

@ -11,6 +11,7 @@
#include <fsfw/tasks/TaskFactory.h>
#include <fsfwconfig/objects/systemObjectList.h>
#include <fsfwconfig/OBSWConfig.h>
#include <fsfwconfig/pollingsequence/PollingSequenceFactory.h>
#include <iostream>
@ -129,6 +130,23 @@ void InitMission::initTasks(){
sif::error << "Object add component failed" << std::endl;
}
// PeriodicTaskIF* P60DockTask = TaskFactory::instance()->
// createPeriodicTask("P60Dock Task", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE*4,
// 1.6, nullptr);
// result = P60DockTask->addComponent(objects::P60DOCK_HANDLER);
// if(result!=HasReturnvaluesIF::RETURN_OK){
// sif::error << "Object add component failed" << std::endl;
// }
FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()->
createFixedTimeslotTask("GS_PST_TASK", 50,
PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 1.0, nullptr);
result = pst::gomspacePstInit(GomSpacePstTask);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "InitMission::initTasks: GomSpace PST initialization "
<< "failed!" << std::endl;
}
#if ADD_TEST_CODE == 1
// FixedTimeslotTaskIF* TestTimeslotTask = TaskFactory::instance()->
@ -140,13 +158,6 @@ void InitMission::initTasks(){
// << "failed!" << std::endl;
// }
PeriodicTaskIF* P60DockTestTask =
TaskFactory::instance()->createPeriodicTask("P60 Dock", 50,
PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, nullptr);
result = PusLowPrio->addComponent(objects::P60DOCK_TEST_TASK);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
#endif
//Main thread sleep
@ -155,15 +166,18 @@ void InitMission::initTasks(){
UdpBridgeTask->startTask();
UdpPollingTask->startTask();
GomSpacePstTask->startTask();
PusVerification->startTask();
PusEvents->startTask();
PusHighPrio->startTask();
PusMedPrio->startTask();
PusLowPrio->startTask();
// P60DockTask->startTask();
#if ADD_TEST_CODE == 1
// TestTimeslotTask->startTask();
P60DockTestTask->startTask();
#endif
sif::info << "Tasks started.." << std::endl;
}

View File

@ -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)

View File

@ -1,324 +0,0 @@
#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;
}
}

View File

@ -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_ */

View File

@ -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;
//}

View File

@ -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_ */

View File

@ -0,0 +1,211 @@
#include "CspComIF.h"
#include <bsp_linux/comIF/cookies/CspCookie.h>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <csp/drivers/can_socketcan.h>
#include <fsfw/serialize/SerializeAdapter.h>
CspComIF::CspComIF(object_id_t objectId) :
SystemObject(objectId) {
}
CspComIF::~CspComIF() {
}
ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) {
if(cookie == nullptr) {
return NULLPOINTER;
}
CspCookie* cspCookie = dynamic_cast<CspCookie*>(cookie);
if(cspCookie == nullptr) {
return NULLPOINTER;
}
/* Perform CAN and CSP initialization only once */
if(cspDeviceMap.empty()){
/* 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;
}
}
uint8_t cspAddress = cspCookie->getCspAddress();
uint16_t maxReplyLength = cspCookie->getMaxReplyLength();
if(cspDeviceMap.find(cspAddress) == cspDeviceMap.end()){
/* Insert device information in CSP map */
cspDeviceMap.emplace(cspAddress, vectorBuffer(maxReplyLength));
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CspComIF::sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) {
int result;
if(cookie == NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
CspCookie* cspCookie = dynamic_cast<CspCookie*> (cookie);
if(cspCookie == NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
/* Extract csp port and bytes to query from command buffer */
uint8_t cspPort;
uint16_t querySize;
result = getPortAndQuerySize(&sendData, &sendLen, &cspPort, &querySize);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t cspAddress = cspCookie->getCspAddress();
switch(cspPort) {
case(Ports::CSP_PING): {
initiatePingRequest(cspAddress, querySize);
break;
}
case(Ports::CSP_REBOOT): {
csp_reboot(cspAddress);
break;
}
case(Ports::P60_PORT_GNDWDT_RESET):
case(Ports::P60_PORT_RPARAM): {
/* No CSP fixed port was selected. Send data to the specified port and
* wait for querySize number of bytes */
result = cspTransfer(cspAddress, cspPort, sendData, sendLen,
querySize);
if(result != HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED;
}
replySize = querySize;
break;
}
default:
sif::error << "CspComIF: Invalid port specified" << std::endl;
break;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CspComIF::getSendSuccess(CookieIF *cookie) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CspComIF::requestReceiveMessage(CookieIF *cookie,
size_t requestLen) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CspComIF::readReceivedMessage(CookieIF *cookie,
uint8_t** buffer, size_t* size) {
if(cookie == NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
CspCookie* cspCookie = dynamic_cast<CspCookie*> (cookie);
if(cspCookie == NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
uint8_t cspAddress = cspCookie->getCspAddress();
*buffer = cspDeviceMap[cspAddress].data();
*size = replySize;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort,
const uint8_t* cmdBuffer, int cmdBufferLen, uint16_t querySize) {
uint32_t timeout_ms = 500;
vectorBufferIter iter = cspDeviceMap.find(cspAddress);
if(iter == cspDeviceMap.end()){
sif::error << "CSP device with address " << cspAddress << " no found in"
<< " device map" << std::endl;
}
uint8_t* replyBuffer = iter->second.data();
uint8_t tmpCmdBuffer[cmdBufferLen];
memcpy(tmpCmdBuffer, cmdBuffer, cmdBufferLen);
csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, cspAddress, cspPort, 0,
CSP_O_NONE);
int result = csp_transaction_persistent(conn, timeout_ms,
tmpCmdBuffer, cmdBufferLen, replyBuffer, querySize);
if(querySize != 0){
if(result != querySize){
sif::error << "CSP transfer failed to receive all requested bytes "
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
} else {
if(result != 1){
sif::error << "CSP transfer failed" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
}
csp_close(conn);
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);
}

View File

@ -0,0 +1,89 @@
#ifndef BSP_LINUX_COMIF_COOKIES_CSPCOMIF_H_
#define BSP_LINUX_COMIF_COOKIES_CSPCOMIF_H_
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <csp/csp.h>
#include <vector>
#include <unordered_map>
/**
* @brief This class serves as the communication interface to devices
* supporting the CSP protocol. As physical layer can0 is used
* in this implementation.
* @author J. Meier
*/
class CspComIF: public DeviceCommunicationIF, public SystemObject {
public:
CspComIF(object_id_t objectId);
virtual ~CspComIF();
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:
/**
* @brief This function initiates the CSP transfer.
*
* @param cspAddress The CSP address of the target device.
* @param cspPort The port of the target device.
* @param timeout The timeout to wait for csp_send and csp_read
* functions. Specifies how long the functions wait
* for a successful operation.
* @param cmdBuffer The data to send.
* @param cmpBuffer The number of bytes to send.
* @param querySize The size of the requested message.
*/
ReturnValue_t cspTransfer(uint8_t cspAddress, uint8_t cspPort,
const uint8_t* cmdBuffer, int cmdBufferLen, uint16_t querySize);
enum Ports {
CSP_PING = 1,
CSP_REBOOT = 4,
P60_PORT_RPARAM = 7,
P60_PORT_GNDWDT_RESET = 9
};
typedef uint8_t node_t;
using vectorBuffer = std::vector<uint8_t>;
using VectorBufferMap = std::unordered_map<node_t, vectorBuffer>;
using vectorBufferIter = VectorBufferMap::iterator;
/* In this map assigns reply buffers to a CSP device */
VectorBufferMap cspDeviceMap;
uint16_t replySize = 0;
/* This is the CSP address of the OBC. */
node_t cspClientAddress = 1;
/* Interface struct for csp protocol stack */
csp_iface_t csp_if;
char canInterface[5] = "can0";
int bitrate = 1000;
/**
* @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_ */

View File

@ -0,0 +1,16 @@
#include "CspCookie.h"
CspCookie::CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_) :
maxReplyLength(maxReplyLength_), cspAddress(cspAddress_) {
}
CspCookie::~CspCookie() {
}
uint16_t CspCookie::getMaxReplyLength(){
return maxReplyLength;
}
uint8_t CspCookie::getCspAddress(){
return cspAddress;
}

View File

@ -0,0 +1,27 @@
#ifndef BSP_LINUX_COMIF_COOKIES_CSPCOOKIE_H_
#define BSP_LINUX_COMIF_COOKIES_CSPCOOKIE_H_
#include <fsfw/devicehandlers/CookieIF.h>
#include <stdint.h>
/**
* @brief This is the cookie for devices supporting the CSP (CubeSat Space
* Protocol).
* @author J. Meier
*/
class CspCookie: public CookieIF {
public:
CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_);
virtual ~CspCookie();
uint16_t getMaxReplyLength();
uint8_t getCspAddress();
private:
uint16_t maxReplyLength;
uint8_t cspAddress;
};
#endif /* BSP_LINUX_COMIF_COOKIES_CSPCOOKIE_H_ */

2
fsfw

@ -1 +1 @@
Subproject commit 6bedc9b805d9e51fbca0d4b881fab39f52b59a07
Subproject commit 113397c6c6ae4c46341f4880710e4e4d9b6e7630

View File

@ -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

View File

@ -4,7 +4,7 @@
* \date 06.11.2019
*/
#include <fsfwconfig/devices/logicalAddresses.h>
#include "addresses.h"

View File

@ -0,0 +1,35 @@
/**
* \file addresses.cpp
*
* \date 07.11.2019
*/
#ifndef FSFWCONFIG_DEVICES_ADDRESSES_H_
#define FSFWCONFIG_DEVICES_ADDRESSES_H_
#include <stdint.h>
#include <fsfw/devicehandlers/CookieIF.h>
#include <fsfwconfig/objects/systemObjectList.h>
namespace addresses {
/* Logical addresses have uint32_t datatype */
enum logicalAddresses: address_t {
PCDU,
/* Dummy and Test Addresses */
DUMMY_ECHO = 129,
DUMMY_GPS0 = 130,
DUMMY_GPS1 = 131,
};
/* Addresses of devices supporting the CSP protocol */
enum cspAddresses: uint8_t {
P60DOCK = 4,
ACU = 2,
PDU1 = 3,
/* PDU2 occupies X4 slot of P60Dock */
PDU2 = 6
};
}
#endif /* FSFWCONFIG_DEVICES_ADDRESSES_H_ */

View File

@ -1,26 +0,0 @@
/**
* \file logicalAddresses.cpp
*
* \date 07.11.2019
*/
#ifndef FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_
#define FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_
#include <stdint.h>
#include <fsfw/devicehandlers/CookieIF.h>
#include <fsfwconfig/objects/systemObjectList.h>
namespace addresses {
/* Logical addresses have uint32_t datatype */
enum logicalAddresses: address_t {
PCDU,
/* Dummy and Test Addresses */
DUMMY_ECHO = 129,
DUMMY_GPS0 = 130,
DUMMY_GPS1 = 131,
};
}
#endif /* FSFWCONFIG_DEVICES_LOGICALADDRESSES_H_ */

View File

@ -27,10 +27,17 @@ 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
CSP_COM_IF = 0x49000002,
/* 0x44 ('D') for device handlers */
P60DOCK_HANDLER = 0x44000001,
PDU1_HANDLER = 0x44000002,
PDU2_HANDLER = 0x44000003,
ACU_HANDLER = 0x44000004
};
}

View File

@ -28,3 +28,52 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence)
}
}
ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){
uint32_t length = thisSequence->getPeriodMs();
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::ACU_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK;
}
else {
sif::error << "Initialization of GomSpace PST failed" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
}

View File

@ -26,6 +26,13 @@ namespace pst {
/* 0.4 second period init*/
ReturnValue_t pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence);
/**
* @brief This function creates the PST for all gomspace devices. They are
* scheduled in a separate PST because the gomspace library uses
* blocking calls when requesting data from devices.
*/
ReturnValue_t gomspacePstInit(FixedTimeslotTaskIF *thisSequence);
}
#endif /* POLLINGSEQUENCEINIT_H_ */

View File

@ -1,11 +0,0 @@
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/drivers/can/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/interfaces/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/rtable/csp_rtable_cidr.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/crypto/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/arch/posix/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/transport/*.c)
INCLUDES += $(CURRENTPATH)/libcsp/include
INCLUDES += $(CURRENTPATH)/libcsp/include/csp/crypto
INCLUDES += $(CURRENTPATH)/libcsp

View File

@ -1,111 +0,0 @@
#ifndef LIBGSCSP_INCLUDE_GS_CSP_PORT_H
#define LIBGSCSP_INCLUDE_GS_CSP_PORT_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
Port definitions for standard CSP and GomSpace services.
*/
#include <csp/csp_types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Port definitions for standard CSP and GomSpace services.
*/
typedef enum {
/**
CSP Management Protocol - standard CSP service.
*/
GS_CSP_CMP = CSP_CMP, // 0
/**
Ping - standard CSP service.
*/
GS_CSP_PING = CSP_PING, // 1
/**
Show process status - standard CSP service.
*/
GS_CSP_PS = CSP_PS, // 2
/**
Show memory free - standard CSP service.
*/
GS_CSP_MEM_FREE = CSP_MEMFREE, // 3
GS_CSP_MEMFREE = GS_CSP_MEM_FREE,
/**
Reboot/reset request - standard CSP service.
*/
GS_CSP_REBOOT = CSP_REBOOT, // 4
/**
Show number of free CSP buffers - standard CSP service.
*/
GS_CSP_BUF_FREE = CSP_BUF_FREE, // 5
/**
Show uptime (time since last reset) - standard CSP service.
*/
GS_CSP_UPTIME = CSP_UPTIME, // 6
/**
Parameter service (libparam)
*/
GS_CSP_PORT_RPARAM = 7,
/**
File Transfer Service (libftp)
*/
GS_CSP_PORT_FTP = 9,
/**
Remote log service (liblog)
*/
GS_CSP_PORT_RLOG = 11,
/**
Remote GOSH service (librgosh)
*/
GS_CSP_PORT_RGOSH = 12,
/**
AIS command port (libais).
*/
GS_CSP_PORT_AIS = 13,
/**
ADS-B command port (libadsb).
*/
GS_CSP_PORT_ADSB = 14,
/**
GomSpace Sensor Bus (libgssb).
*/
GS_CSP_PORT_GSSB = 16,
/**
Flight Planner (libfp).
*/
GS_CSP_PORT_FP = 18,
/**
ADCS (libadcs).
*/
GS_CSP_PORT_ADCS = 20,
/**
House Keeping (libhk).
*/
GS_CSP_PORT_HK = 21,
/**
G(omSpace) script service (libgosh)
*/
GS_CSP_PORT_GSCRIPT = 22,
/**
Remote shell (libgosh).
Executes shell commands (linux server only).
Requires CSP_O_RDP.
*/
GS_CSP_PORT_REMOTE_SHELL = 27,
/**
House keeping beacon port (libhk).
Default port for sending beacons from satellite to ground (configurable).
*/
GS_CSP_PORT_HK_BEACON = 30,
} gs_csp_port_t;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,141 +0,0 @@
#ifndef GS_PARAM_INTERNAL_RPARAM_H
#define GS_PARAM_INTERNAL_RPARAM_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#ifdef __cplusplus
extern "C" {
#endif
/**
Max query payload in a single message (bytes).
*/
#define GS_RPARAM_QUERY_MAX_PAYLOAD 180
/**
Macro for calculating total query message size, header + payload.
*/
#define RPARAM_QUERY_LENGTH(query, payload_size) (sizeof(*query) - sizeof(query->payload) + payload_size)
/**
R(emote) parameter request codes.
*/
typedef enum {
/**
Get one or more parameters.
*/
RPARAM_GET = 0x00,
/**
Reply to a request.
*/
RPARAM_REPLY = 0x55,
/**
Set one or more parameters.
*/
RPARAM_SET = 0xFF,
// RPARAM_SET_TO_FILE = 0xEE,
/**
Download table specification.
*/
RPARAM_TABLE = 0x44,
/**
Copy memory slot to memory slot.
@version 4.x: Not supported.
*/
RPARAM_COPY = 0x77,
/**
Load from file (slot) to memory (slot).
@version 4.x: Only load from primary store - file (slot) is ignored.
*/
RPARAM_LOAD = 0x88,
/**
Load from file (slot) to memory (slot).
@version 4.x: load by name(s).
*/
RPARAM_LOAD_FROM_STORE = 0x89,
/**
Save from memory (slot) to file (slot).
@version 4.x: Only save to primary store - file (slot) is ignored.
*/
RPARAM_SAVE = 0x99,
/**
Save from memory (slot) to file (slot).
@version 4.x: save by name(s).
*/
RPARAM_SAVE_TO_STORE = 0x9a,
// RPARAM_CLEAR = 0xAA, - completely removed
} gs_rparam_action_t;
/**
R(emote) parameter reply/completion codes.
*/
typedef enum {
RPARAM_SET_OK = 1,
RPARAM_LOAD_OK = 2,
RPARAM_SAVE_OK = 3,
RPARAM_COPY_OK = 4,
// RPARAM_CLEAR_OK = 5,
RPARAM_ERROR = 0xFF,
} gs_rparam_reply_t;
/**
Payload - save/load to/from stores
@version 4
*/
typedef struct __attribute__ ((packed)) {
char table[25 + 1];
char store[25 + 1];
char slot[25 + 1];
} gs_rparam_query_payload_store_t;
/**
Payload.
*/
typedef union __attribute__ ((packed)) {
uint16_t addr[0]; //! action = RPARAM_GET
uint8_t packed[0]; //! action = RPARAM_REPLY | RPARAM_SET
struct { //! action = RPARAM_COPY | RPARAM_LOAD | RPARM_SAVE
uint8_t from;
uint8_t to;
} copy;
} gs_rparam_query_payload_t;
/**
Protocol between client and server.
@version 4.x: layout (size) has not changed - only naming of certain fields.
*/
typedef struct __attribute__ ((packed)) {
/**
Request (gs_rparam_action_t) or Reply (gs_rparam_reply_t).
*/
uint8_t action;
/**
Table id.
Name changed in 4.0 from \a mem.
*/
uint8_t table_id;
/**
Length/size of \a payload in bytes.
*/
uint16_t length;
/**
Fletcher's checksum.
*/
uint16_t checksum;
/**
Sequence number when split over multiple frames (messages).
*/
uint16_t seq;
/**
Total number of frames.
*/
uint16_t total;
/**
Payload.
*/
gs_rparam_query_payload_t payload;
} gs_rparam_query_t;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,113 +0,0 @@
libcsp 1.4, 07-05-2015
----------------------
- new: General rtable interface with support for STATIC or CIDR format
- new: CIDR (classless interdomain routing) route table format with netmasks
- new: Bridge capability
- new: Added routing table (de)serialization functions for load/save
- new: Automatic packet deduplication using CRC32 (compile time option)
- new: Autogenerated python bindings using ctypesgen
- new: Task-less operation with router invocation from external scheduler function
- api: Refactor route_if_add to csp_iflist_add
- api: Refactor route_set and friends to rtable_set
- api: Refactor csp_fifo_qos to csp_qfifo
- api: Added defined to be backwards compatible with 1.x
- interfaces: Drop packets on LOOP interface not for own address (blackhole)
- interfaces: New ZMQHUB interface (using zeroMQ over TCP)
- other: Increase stack size from 250 to 1100 for csp_can_rx_task
- other: Cleanup in csp_route.c
- other: Show incoming interface name in debug message
- other: Remove newlines from debug calls
- improvement: Reduce debug hook function complexity with valist passing
- fix: csp_sleep_ms did not work
libcsp 1.3, 07-05-2015
----------------------
- new: Split long process lists into multiple packets
- new: Added posix csp_clock.h
- new: cmp clock functions (requires that you provide csp_clock.h implementation)
- new: Added SFP (Small fragmentation protocol) for larger data chunks
- fix: csp_if_fifo example
- fix: NULL char at the end of rps
- doc: Updated mtu documentation
- other: Tested with FreeRTOS 8.0
- other: Added disable-stlib option to build only object files
libcsp 1.2, 25-10-2013
----------------------
- Feature release
- New: CMP service for peek and poke of memory
- New: CMP interface statistics struct is now packed
- New: Faster O(1) buffer system with reference counting and automatic alignment
- New: Thread safe KISS driver with support for multiple interfaces
- New: CSP interface struct now holds an opaque pointer to driver handle
- New: removed TXBUF from KISS driver entirely to minimize stack usage, added TX lock instead
- New: Pre-calculated CRC table .romem or PROGMEM on __avr__
- New: Added buffer overflow protection to KISS interface
- New: Allow posting null pointers on conn RX queues
- New: Lower memory usage on AVR8
- New: csp_route_save and csp_route_load functions
- New: option --disable-verbose to disable filenames and linenumber on debug
- Protocol: KISS uses csp_crc32 instead of it own embedded crc32
- Improvement: Use buffer clone function to copy promisc packets
- Bugfix: Fix pointer size (32/16bit) in cmp_peek/poke
- Bugfix: Issue with double free in KISS fixed
- Bugfix: Change rdp_send timeout from packet to connection timeout to make sending task block longer
- Bugfix: Fix conn pool leak when using security check and discarding new packets
- Bugfix: Add packet too short check for CRC32
- Bugfix: Accept CRC32 responses from nodes without CRC support
- Bugfix: Ensure csp_ping works for packets > 256 bytes
- Bugfix: Cleanup printf inside ISR functions
- Bugfix: Do not add forwarded packets to promisc queue twice
- Bugfix: Fix return value bug of csp_buffer_get when out of buffers
- Bugfix: Always post null pointer with lowest priority, not highest
- Bugfix: Add check on debug level before calling do_csp_debug, fixes #35
- Other: Export csp/arch include files
- Other: Remove the use of bool type from csp_debug
- Other: Moved csp debug functions to csp_debug.h instead of csp.h
- Other: Ensure assignment of id happens using the uint32_t .ext value of the union, quenches warning
libcsp 1.1, 24-08-2012
----------------------
- Feature release
- Defacto stable since Feb 2012
- New: I2C interface
- New: KISS interface
- New: USART drivers for Linux, Mac and Windows
- New: Windows/MinGW support
- New: MacOSX support
- New: Interface register function
- New: Interface search function
- New: CMP service for remote route updating
- New: CMP service for interface statistics
- Improvement: Better QoS support
- Improvement: Send RDP control messages with high priority
- Improvement: WAF distcheck now works
- Improvement: Automatic endian discovery
- Improvement: Accept packets with CRC32 checksum if compiled without CRC32 support
- Improvement: Do not wake the router task if RDP is not enabled
- Improvement: Save 102 bytes of RAM by packing route entries
- Cleanup: Simplify CAN configuration
- Cleanup: Move architecture specific code to src/arch
- Bugfix: CSP_MEMFREE gives wrong answer on freertos AVR due to truncation
- Bugfix: Fixed wrong 64-bit size_t in csp_service_handler
- Bugfix: Fixed problem in csp_if_kiss when out of buffers
- Bigfix: Handle bus-off CAN IRQ for AT90CAN128
libcsp 1.0.1, 30-10-2011
------------------------
- Hotfix release
- Bugfix: missing extern in csp_if_lo.h
libcsp 1.0, 24-10-2011
----------------------
- First official release
- New: CSP 32-bit header 1.0
- Features: Network Router with promiscous mode, broadcast and QoS
- Features: Connection-oriented transport protocol w. flow-control
- Features: Connection-less "UDP" like transport
- Features: Encryption, Authentication and message check
- Features: Loopback interface
- Features: Python Bindings
- Features: CAN interface w. drivers for several chips
- Features: CSP-services (ping, reboot, uptime, memfree, buffree, ident)

View File

@ -1,3 +0,0 @@
Jeppe Ledet-Pedersen <jeppe@ledets.dk>
Johan De Claville Christiansen <johan@gomspace.com>
Dan Erik Holmstrøm <holmstro@stud.ntnu.no>

View File

@ -1,503 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@ -1,30 +0,0 @@
How to install LibCSP
=====================
CSP uses the `waf` build system (http://code.google.com/p/waf/). In order to
compile CSP, you first need to configure the toolchain, what operating system
to compile for, the location of required libraries and whether to enable
certain optional features.
To configure CSP to build with the AVR32 toolchain for FreeRTOS and output
the compiled libcsp.a and header files to the install directory, issue:
.. code-block:: bash
./waf configure --toolchain=avr32- --with-os=freertos --prefix=install
When compiling for FreeRTOS, the path to the FreeRTOS header files must be
specified with `--with-freertos=PATH.`
A number of optional features can be enabled by from the configure script.
Support for XTEA encryption can e.g. be enabled with `--enable-xtea`. Run
`./waf configure --help` to list the available configure options.
The CAN drivers can be enabled by appending the configure option `--with-driver-can=CHIP`,
where CHIP is one of 'socketcan', 'at91sam7a1', 'at91sam7a3' or 'at90can128'.
To build and copy the library to the location specified with --prefix, use:
.. code-block:: bash
./waf build install

View File

@ -1,41 +0,0 @@
The Cubesat Space Protocol
==========================
Cubesat Space Protocol (CSP) is a small protocol stack written in C. CSP is designed to ease communication between distributed embedded systems in smaller networks, such as Cubesats. The design follows the TCP/IP model and includes a transport protocol, a routing protocol and several MAC-layer interfaces. The core of libcsp includes a router, a socket buffer pool and a connection oriented socket API.
The protocol is based on a 32-bit header containing both transport and network-layer information. Its implementation is designed for, but not limited to, embedded systems such as the 8-bit AVR microprocessor and the 32-bit ARM and AVR from Atmel. The implementation is written in GNU C and is currently ported to run on FreeRTOS or POSIX operating systems such as Linux.
The idea is to give sub-system developers of cubesats the same features of a TCP/IP stack, but without adding the huge overhead of the IP header. The small footprint and simple implementation allows a small 8-bit system with less than 4 kB of RAM to be fully connected on the network. This allows all subsystems to provide their services on the same network level, without any master node required. Using a service oriented architecture has several advantages compared to the traditional mater/slave topology used on many cubesats.
* Standardised network protocol: All subsystems can communicate with eachother
* Service loose coupling: Services maintain a relationship that minimizes dependencies between subsystems
* Service abstraction: Beyond descriptions in the service contract, services hide logic from the outside world
* Service reusability: Logic is divided into services with the intention of promoting reuse.
* Service autonomy: Services have control over the logic they encapsulate.
* Service Redundancy: Easily add redundant services to the bus
* Reduces single point of failure: The complexity is moved from a single master node to several well defines services on the network
The implementation of LibCSP is written with simplicity in mind, but it's compile time configuration allows it to have some rather advanced features as well:
Features
--------
* Thread safe Socket API
* Router task with Quality of Services
* Connection-oriented operation (RFC 908 and 1151).
* Connection-less operation (similar to UDP)
* ICMP-like requests such as ping and buffer status.
* Loopback interface
* Very Small Footprint 48 kB code and less that 1kB ram required on ARM
* Zero-copy buffer and queue system
* Modular network interface system
* Modular OS interface, ported to FreeRTOS, windows (cygwin) and Linux
* Broadcast traffic
* Promiscuous mode
* Encrypted packets with XTEA in CTR mode
* Truncated HMAC-SHA1 Authentication (RFC 2104)
LGPL Software license
---------------------
The source code is available under an LGPL 2.1 license. See COPYING for the license text.

170
gomspace/libcsp/waf vendored

File diff suppressed because one or more lines are too long

View File

@ -1,346 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8
# Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
# Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
# Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
APPNAME = 'libcsp'
VERSION = '1.5'
top = '.'
out = 'build'
def options(ctx):
# Load GCC options
ctx.load('gcc')
ctx.add_option('--toolchain', default=None, help='Set toolchain prefix')
# Set libcsp options
gr = ctx.add_option_group('libcsp options')
gr.add_option('--includes', default='', help='Add additional include paths. Separate with comma')
gr.add_option('--install-csp', action='store_true', help='Installs CSP headers and lib')
gr.add_option('--disable-output', action='store_true', help='Disable CSP output')
gr.add_option('--disable-stlib', action='store_true', help='Build objects only')
gr.add_option('--enable-rdp', action='store_true', help='Enable RDP support')
gr.add_option('--enable-qos', action='store_true', help='Enable Quality of Service support')
gr.add_option('--enable-promisc', action='store_true', help='Enable promiscuous mode support')
gr.add_option('--enable-crc32', action='store_true', help='Enable CRC32 support')
gr.add_option('--enable-hmac', action='store_true', help='Enable HMAC-SHA1 support')
gr.add_option('--enable-xtea', action='store_true', help='Enable XTEA support')
gr.add_option('--enable-bindings', action='store_true', help='Enable Python bindings')
gr.add_option('--enable-python3-bindings', action='store_true', help='Enable Python3 bindings')
gr.add_option('--enable-examples', action='store_true', help='Enable examples')
gr.add_option('--enable-dedup', action='store_true', help='Enable packet deduplicator')
# Interfaces
gr.add_option('--enable-if-i2c', action='store_true', help='Enable I2C interface')
gr.add_option('--enable-if-kiss', action='store_true', help='Enable KISS/RS.232 interface')
gr.add_option('--enable-if-can', action='store_true', help='Enable CAN interface')
gr.add_option('--enable-if-zmqhub', action='store_true', help='Enable ZMQHUB interface')
# Drivers
gr.add_option('--enable-can-socketcan', action='store_true', help='Enable Linux socketcan driver')
gr.add_option('--with-driver-usart', default=None, metavar='DRIVER', help='Build USART driver. [windows, linux, None]')
# OS
gr.add_option('--with-os', metavar='OS', default='posix', help='Set operating system. Must be either \'posix\', \'macosx\', \'windows\' or \'freertos\'')
gr.add_option('--enable-init-shutdown', action='store_true', help='Use init system commands for shutdown/reboot')
# Options
gr.add_option('--with-rdp-max-window', metavar='SIZE', type=int, default=20, help='Set maximum window size for RDP')
gr.add_option('--with-max-bind-port', metavar='PORT', type=int, default=31, help='Set maximum bindable port')
gr.add_option('--with-max-connections', metavar='COUNT', type=int, default=10, help='Set maximum number of concurrent connections')
gr.add_option('--with-conn-queue-length', metavar='SIZE', type=int, default=100, help='Set maximum number of packets in queue for a connection')
gr.add_option('--with-router-queue-length', metavar='SIZE', type=int, default=10, help='Set maximum number of packets to be queued at the input of the router')
gr.add_option('--with-padding', metavar='BYTES', type=int, default=8, help='Set padding bytes before packet length field')
gr.add_option('--with-loglevel', metavar='LEVEL', default='debug', help='Set minimum compile time log level. Must be one of \'error\', \'warn\', \'info\' or \'debug\'')
gr.add_option('--with-rtable', metavar='TABLE', default='static', help='Set routing table type')
gr.add_option('--with-connection-so', metavar='CSP_SO', type=int, default='0x0000', help='Set outgoing connection socket options, see csp.h for valid values')
gr.add_option('--with-bufalign', metavar='BYTES', type=int, help='Set buffer alignment')
def configure(ctx):
# Validate OS
if not ctx.options.with_os in ('posix', 'windows', 'freertos', 'macosx'):
ctx.fatal('--with-os must be either \'posix\', \'windows\', \'macosx\' or \'freertos\'')
# Validate USART drivers
if not ctx.options.with_driver_usart in (None, 'windows', 'linux'):
ctx.fatal('--with-driver-usart must be either \'windows\' or \'linux\'')
if not ctx.options.with_loglevel in ('error', 'warn', 'info', 'debug'):
ctx.fatal('--with-loglevel must be either \'error\', \'warn\', \'info\' or \'debug\'')
# Setup and validate toolchain
if (len(ctx.stack_path) <= 1) and ctx.options.toolchain:
ctx.env.CC = ctx.options.toolchain + 'gcc'
ctx.env.AR = ctx.options.toolchain + 'ar'
ctx.load('gcc')
# Set git revision define
git_rev = os.popen('git describe --always 2> /dev/null || echo unknown').read().strip()
# Setup DEFINES
ctx.define('GIT_REV', git_rev)
# Set build output format
ctx.env.FEATURES = ['c']
if not ctx.options.disable_stlib:
ctx.env.FEATURES += ['cstlib']
# Setup CFLAGS
if (len(ctx.stack_path) <= 1) and (len(ctx.env.CFLAGS) == 0):
ctx.env.prepend_value('CFLAGS', ["-std=gnu99", "-g", "-Os", "-Wall", "-Wextra", "-Wshadow", "-Wcast-align", "-Wwrite-strings", "-Wno-unused-parameter"])
# Setup extra includes
ctx.env.append_unique('INCLUDES_CSP', ['include'] + ctx.options.includes.split(','))
# Add default files
ctx.env.append_unique('FILES_CSP', ['src/*.c','src/interfaces/csp_if_lo.c','src/transport/csp_udp.c','src/arch/{0}/**/*.c'.format(ctx.options.with_os)])
# Store OS as env variable
ctx.env.append_unique('OS', ctx.options.with_os)
# Libs
if 'posix' in ctx.env.OS:
ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util'])
elif 'macosx' in ctx.env.OS:
ctx.env.append_unique('LIBS', ['pthread'])
# Check for recursion
if ctx.path == ctx.srcnode:
ctx.options.install_csp = True
# Windows build flags
if ctx.options.with_os == 'windows':
ctx.env.append_unique('CFLAGS', ['-D_WIN32_WINNT=0x0600'])
ctx.define_cond('CSP_FREERTOS', ctx.options.with_os == 'freertos')
ctx.define_cond('CSP_POSIX', ctx.options.with_os == 'posix')
ctx.define_cond('CSP_WINDOWS', ctx.options.with_os == 'windows')
ctx.define_cond('CSP_MACOSX', ctx.options.with_os == 'macosx')
# Add CAN driver
if ctx.options.enable_can_socketcan:
ctx.env.append_unique('FILES_CSP', 'src/drivers/can/can_socketcan.c')
# Add USART driver
if ctx.options.with_driver_usart != None:
ctx.env.append_unique('FILES_CSP', 'src/drivers/usart/usart_{0}.c'.format(ctx.options.with_driver_usart))
# Interfaces
if ctx.options.enable_if_can:
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_can.c')
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_can_pbuf.c')
if ctx.options.enable_if_i2c:
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_i2c.c')
if ctx.options.enable_if_kiss:
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_kiss.c')
if ctx.options.enable_if_zmqhub:
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_zmqhub.c')
ctx.check_cfg(package='libzmq', args='--cflags --libs')
ctx.env.append_unique('LIBS', ctx.env.LIB_LIBZMQ)
# Store configuration options
ctx.env.ENABLE_BINDINGS = ctx.options.enable_bindings
ctx.env.ENABLE_EXAMPLES = ctx.options.enable_examples
# Check for python development
if ctx.options.enable_bindings:
ctx.env.LIBCSP_PYTHON2 = ctx.check_cfg(package='python2', args='--cflags --libs', atleast_version='2.7', mandatory=False)
if ctx.options.enable_python3_bindings:
ctx.env.LIBCSP_PYTHON3 = ctx.check_cfg(package='python3', args='--cflags --libs', atleast_version='3.5', mandatory=False)
# Create config file
if not ctx.options.disable_output:
ctx.env.append_unique('FILES_CSP', 'src/csp_debug.c')
else:
ctx.env.append_unique('EXCL_CSP', 'src/csp_debug.c')
if ctx.options.enable_rdp:
ctx.env.append_unique('FILES_CSP', 'src/transport/csp_rdp.c')
if ctx.options.enable_crc32:
ctx.env.append_unique('FILES_CSP', 'src/csp_crc32.c')
else:
ctx.env.append_unique('EXCL_CSP', 'src/csp_crc32.c')
if not ctx.options.enable_dedup:
ctx.env.append_unique('EXCL_CSP', 'src/csp_dedup.c')
if ctx.options.enable_hmac:
ctx.env.append_unique('FILES_CSP', 'src/crypto/csp_hmac.c')
ctx.env.append_unique('FILES_CSP', 'src/crypto/csp_sha1.c')
if ctx.options.enable_xtea:
ctx.env.append_unique('FILES_CSP', 'src/crypto/csp_xtea.c')
ctx.env.append_unique('FILES_CSP', 'src/crypto/csp_sha1.c')
ctx.env.append_unique('FILES_CSP', 'src/rtable/csp_rtable_' + ctx.options.with_rtable + '.c')
ctx.define_cond('CSP_DEBUG', not ctx.options.disable_output)
ctx.define_cond('CSP_USE_RDP', ctx.options.enable_rdp)
ctx.define_cond('CSP_USE_CRC32', ctx.options.enable_crc32)
ctx.define_cond('CSP_USE_HMAC', ctx.options.enable_hmac)
ctx.define_cond('CSP_USE_XTEA', ctx.options.enable_xtea)
ctx.define_cond('CSP_USE_PROMISC', ctx.options.enable_promisc)
ctx.define_cond('CSP_USE_QOS', ctx.options.enable_qos)
ctx.define_cond('CSP_USE_DEDUP', ctx.options.enable_dedup)
ctx.define_cond('CSP_USE_INIT_SHUTDOWN', ctx.options.enable_init_shutdown)
ctx.define_cond('CSP_USE_CAN', ctx.options.enable_if_can)
ctx.define_cond('CSP_USE_I2C', ctx.options.enable_if_i2c)
ctx.define_cond('CSP_USE_KISS', ctx.options.enable_if_kiss)
ctx.define_cond('CSP_USE_ZMQHUB', ctx.options.enable_if_zmqhub)
ctx.define('CSP_CONN_MAX', ctx.options.with_max_connections)
ctx.define('CSP_CONN_QUEUE_LENGTH', ctx.options.with_conn_queue_length)
ctx.define('CSP_FIFO_INPUT', ctx.options.with_router_queue_length)
ctx.define('CSP_MAX_BIND_PORT', ctx.options.with_max_bind_port)
ctx.define('CSP_RDP_MAX_WINDOW', ctx.options.with_rdp_max_window)
ctx.define('CSP_PADDING_BYTES', ctx.options.with_padding)
ctx.define('CSP_CONNECTION_SO', ctx.options.with_connection_so)
if ctx.options.with_bufalign != None:
ctx.define('CSP_BUFFER_ALIGN', ctx.options.with_bufalign)
# Set logging level
ctx.define_cond('CSP_LOG_LEVEL_DEBUG', ctx.options.with_loglevel in ('debug'))
ctx.define_cond('CSP_LOG_LEVEL_INFO', ctx.options.with_loglevel in ('debug', 'info'))
ctx.define_cond('CSP_LOG_LEVEL_WARN', ctx.options.with_loglevel in ('debug', 'info', 'warn'))
ctx.define_cond('CSP_LOG_LEVEL_ERROR', ctx.options.with_loglevel in ('debug', 'info', 'warn', 'error'))
# Check compiler endianness
endianness = ctx.check_endianness()
ctx.define_cond('CSP_LITTLE_ENDIAN', endianness == 'little')
ctx.define_cond('CSP_BIG_ENDIAN', endianness == 'big')
# Check for stdbool.h
ctx.check_cc(header_name='stdbool.h', mandatory=False, define_name='CSP_HAVE_STDBOOL_H', type='cstlib')
# Check for libsocketcan.h
if ctx.options.enable_if_can and ctx.options.enable_can_socketcan:
have_socketcan = ctx.check_cc(lib='socketcan', mandatory=False, define_name='CSP_HAVE_LIBSOCKETCAN')
if have_socketcan:
ctx.env.append_unique('LIBS', ['socketcan'])
ctx.define('LIBCSP_VERSION', VERSION)
ctx.write_config_header('include/csp/csp_autoconfig.h')
def build(ctx):
# Set install path for header files
install_path = False
if ctx.options.install_csp:
install_path = '${PREFIX}/lib'
ctx.install_files('${PREFIX}/include/csp', ctx.path.ant_glob('include/csp/*.h'))
ctx.install_files('${PREFIX}/include/csp/interfaces', 'include/csp/interfaces/csp_if_lo.h')
if 'src/interfaces/csp_if_can.c' in ctx.env.FILES_CSP:
ctx.install_files('${PREFIX}/include/csp/interfaces', 'include/csp/interfaces/csp_if_can.h')
if 'src/interfaces/csp_if_i2c.c' in ctx.env.FILES_CSP:
ctx.install_files('${PREFIX}/include/csp/interfaces', 'include/csp/interfaces/csp_if_i2c.h')
if 'src/interfaces/csp_if_kiss.c' in ctx.env.FILES_CSP:
ctx.install_files('${PREFIX}/include/csp/interfaces', 'include/csp/interfaces/csp_if_kiss.h')
if 'src/interfaces/csp_if_zmqhub.c' in ctx.env.FILES_CSP:
ctx.install_files('${PREFIX}/include/csp/interfaces', 'include/csp/interfaces/csp_if_zmqhub.h')
if 'src/drivers/usart/usart_{0}.c'.format(ctx.options.with_driver_usart) in ctx.env.FILES_CSP:
ctx.install_as('${PREFIX}/include/csp/drivers/usart.h', 'include/csp/drivers/usart.h')
if 'src/drivers/can/can_socketcan.c' in ctx.env.FILES_CSP:
ctx.install_as('${PREFIX}/include/csp/drivers/can_socketcan.h', 'include/csp/drivers/can_socketcan.h')
ctx.install_files('${PREFIX}/include/csp', 'include/csp/csp_autoconfig.h', cwd=ctx.bldnode)
ctx(export_includes='include', name='csp_h')
ctx(features=ctx.env.FEATURES,
source=ctx.path.ant_glob(ctx.env.FILES_CSP, excl=ctx.env.EXCL_CSP),
target = 'csp',
includes= ctx.env.INCLUDES_CSP,
export_includes = ctx.env.INCLUDES_CSP,
use = 'include freertos_h',
install_path = install_path,
)
# Build shared library for Python bindings
if ctx.env.ENABLE_BINDINGS:
ctx.shlib(source = ctx.path.ant_glob(ctx.env.FILES_CSP, excl=ctx.env.EXCL_CSP),
name = 'csp_shlib',
target = 'csp',
includes = ctx.env.INCLUDES_CSP,
export_includes = 'include',
use = ['include'],
lib = ctx.env.LIBS)
# python3 bindings
if ctx.env.LIBCSP_PYTHON3:
ctx.shlib(source = ['src/bindings/python/pycsp.c'],
target = 'csp_py3',
includes = ctx.env.INCLUDES_CSP + ctx.env.INCLUDES_PYTHON3,
export_includes = 'include',
use = ['csp_shlib', 'include'],
lib = ctx.env.LIBS)
# python2 bindings
if ctx.env.LIBCSP_PYTHON2:
ctx.shlib(source = ['src/bindings/python/pycsp.c'],
target = 'csp_py2',
includes = ctx.env.INCLUDES_CSP + ctx.env.INCLUDES_PYTHON2,
export_includes = 'include',
use = ['csp_shlib', 'include'],
lib = ctx.env.LIBS)
if ctx.env.ENABLE_EXAMPLES:
ctx.program(source = ctx.path.ant_glob('examples/simple.c'),
target = 'simple',
includes = ctx.env.INCLUDES_CSP,
lib = ctx.env.LIBS,
use = 'csp')
if ctx.options.enable_if_kiss:
ctx.program(source = 'examples/kiss.c',
target = 'kiss',
includes = ctx.env.INCLUDES_CSP,
lib = ctx.env.LIBS,
use = 'csp')
if ctx.options.enable_if_zmqhub:
ctx.program(source = 'examples/zmqproxy.c',
target = 'zmqproxy',
includes = ctx.env.INCLUDES_CSP,
lib = ctx.env.LIBS,
use = 'csp')
if 'posix' in ctx.env.OS:
ctx.program(source = 'examples/csp_if_fifo.c',
target = 'fifo',
includes = ctx.env.INCLUDES_CSP,
lib = ctx.env.LIBS,
use = 'csp')
if 'windows' in ctx.env.OS:
ctx.program(source = ctx.path.ant_glob('examples/csp_if_fifo_windows.c'),
target = 'csp_if_fifo',
includes = ctx.env.INCLUDES_CSP,
use = 'csp')
def dist(ctx):
ctx.excl = 'build/* **/.* **/*.pyc **/*.o **/*~ *.tar.gz'

12
libcsp/libcsp.mk Normal file
View File

@ -0,0 +1,12 @@
CSRC += $(wildcard $(CURRENTPATH)/src/drivers/can/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/interfaces/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/rtable/csp_rtable_cidr.c)
CSRC += $(wildcard $(CURRENTPATH)/src/crypto/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/arch/posix/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/transport/*.c)
INCLUDES += $(CURRENTPATH)/include
INCLUDES += $(CURRENTPATH)/include/csp
INCLUDES += $(CURRENTPATH)/include/csp/crypto
INCLUDES += $(CURRENTPATH)

Some files were not shown because too many files have changed in this diff Show More