pdock 60 test task

This commit is contained in:
2020-11-23 11:42:22 +01:00
parent 6c23b00c22
commit 9d092edda4
323 changed files with 132 additions and 41250 deletions

View File

@ -2,82 +2,100 @@
* P60DockTestTask.cpp
*
* Created on: 18.11.2020
* Author: jakob
* Author: Jakob Meier
*/
#include <gs/csp/drivers/can/can.h>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <csp/drivers/can_socketcan.h>
#include "P60DockTestTask.h"
P60DockTestTask::P60DockTestTask(object_id_t objectId_):
SystemObject(objectId_){
/* Init buffer system with 10 packets of maximum 320 bytes each */
// csp_buffer_init(10, 320);
uint8_t device = 0;
uint8_t csp_addr = 4; /* Current address of p60 dock */
uint8_t mtu = 320; /* Packets larger than the set mtu will be discarded */
char name[5] = "can0";
/* Init the CAN interface */
gs_error_t result = gs_csp_can_init(device, csp_addr, mtu, name, csp_if);
if(result != GS_OK){
sif::error << "gs_csp_can_init failed with error code: " << result
<< std::endl;
if(initializeCSPStack() != HasReturnvaluesIF::RETURN_OK){
sif::error << "P60DockTestTask creation failed" << std::endl;
}
}
ReturnValue_t P60DockTestTask::performOperation(uint8_t operationCode) {
char data[5] = "test";
int timeout_ms = 1000;
/* Send a csp packet to the can interface */
g_error_t result = csp_can_tx_frame(csp_if, canExtMsgId, (uint8*) data, sizeof(data),
timeout_ms);
if(result != GS_OK){
sif::error << "csp_can_tx_frame failed with error code " << result
<< std::endl;
if(sendPacket() != HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t P60DockTestTask::sendPacket(void){
/* Get packet buffer for data */
csp_packet_t *packet = csp_buffer_get(data_size);
if (packet == NULL) {
/* Could not get buffer element */
sif::error("Failed to get buffer element\\n");
// 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);
uint32_t timeout = 1000;
unsigned int pingSize = 100; // 100 bytes
uint32_t replyTime = csp_ping(p60dockAddress, timeout, pingSize, CSP_O_NONE);
sif::info << "Ping address: " << p60dockAddress << ", reply after "
<< replyTime << "ms" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t P60DockTestTask::initializeCSPStack(void){
/* Init CSP and CSP buffer system */
if (csp_init(cspAddress) != 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;
}
/* Connect to host HOST, port PORT with regular UDP-like protocol and
* 1000 ms timeout */
csp_conn_t *conn = csp_connect(CSP_PRIO_NORM, HOST, PORT, 1000, CSP_O_NONE);
csp_iface_t *csp_if_ptr = &csp_if;
csp_if_ptr = csp_can_socketcan_init("can0", bitrate, promisc);
if (conn == NULL) {
/* Connect failed */
sif::error("Connection failed\\n");
/* Remember to free packet buffer */
csp_buffer_free(packet);
return HasReturnvaluesIF::RETURN_FAILED;
/* Set default route and start router */
int result = csp_rtable_set(CSP_DEFAULT_ROUTE, 0, csp_if_ptr, CSP_NODE_MAC);
if(result != CSP_ERR_NONE){
sif::error << "Failed to add can interface to router table"
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
/* Copy message to packet */
char *msg = "HELLO";
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);
result = csp_route_start_task(500, 0);
if(result != CSP_ERR_NONE){
sif::error << "Failed to start route task" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
/* Close connection */
csp_close(conn);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -8,15 +8,21 @@
#ifndef TEST_TESTTASKS_P60DOCKTESTTASK_H_
#define TEST_TESTTASKS_P60DOCKTESTTASK_H_
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/objectmanager/SystemObject.h>
extern "C" {
#include <csp/csp.h>
#include <csp/interfaces/csp_if_can.h>
}
class P60DockTestTask: public ExecutableObjectIF {
class P60DockTestTask: public SystemObject,
public ExecutableObjectIF,
public HasReturnvaluesIF {
public:
P60DockTestTask();
P60DockTestTask(object_id_t objectId_);
virtual ~P60DockTestTask();
virtual ReturnValue_t performOperation(uint8_t operationCode = 0);
@ -24,11 +30,15 @@ public:
private:
/* Interface struct for csp protocol stack */
csp_iface_t csp_if;
uint32_t canExtMsgId = 4;
/* CAN configuration struct for SocketCAN interface "can0" */
struct csp_can_config can_conf = {.ifc = "can0"};
uint8_t p60dockAddress = 4;
uint8_t CSP_PING = 1;
uint8_t cspAddress = 1;
const char* canIf = "can0";
int bitrate = 1000; // bitrate of can
int promisc = 0; // set to 0 to enable filter mode
ReturnValue_t sendPacket(void);
ReturnValue_t initializeCSPStack(void);
};