eive-obsw/test/testtasks/P60DockTestTask.cpp

107 lines
2.8 KiB
C++
Raw Normal View History

2020-11-19 18:24:03 +01:00
/*
* P60DockTestTask.cpp
*
* Created on: 18.11.2020
2020-11-23 11:42:22 +01:00
* Author: Jakob Meier
2020-11-19 18:24:03 +01:00
*/
2020-11-23 11:42:22 +01:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <csp/drivers/can_socketcan.h>
2020-11-19 18:24:03 +01:00
#include "P60DockTestTask.h"
P60DockTestTask::P60DockTestTask(object_id_t objectId_):
SystemObject(objectId_){
2020-11-23 11:42:22 +01:00
if(initializeCSPStack() != HasReturnvaluesIF::RETURN_OK){
sif::error << "P60DockTestTask creation failed" << std::endl;
2020-11-19 18:24:03 +01:00
}
}
ReturnValue_t P60DockTestTask::performOperation(uint8_t operationCode) {
2020-11-23 11:42:22 +01:00
if(sendPacket() != HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED;
2020-11-19 18:24:03 +01:00
}
2020-11-23 11:42:22 +01:00
return HasReturnvaluesIF::RETURN_OK;
2020-11-19 18:24:03 +01:00
}
ReturnValue_t P60DockTestTask::sendPacket(void){
2020-11-23 11:42:22 +01:00
// 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;
2020-11-19 18:24:03 +01:00
return HasReturnvaluesIF::RETURN_FAILED;
}
2020-11-23 11:42:22 +01:00
csp_iface_t *csp_if_ptr = &csp_if;
csp_if_ptr = csp_can_socketcan_init("can0", bitrate, promisc);
2020-11-19 18:24:03 +01:00
2020-11-23 11:42:22 +01:00
/* 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;
2020-11-19 18:24:03 +01:00
}
2020-11-23 11:42:22 +01:00
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;
2020-11-19 18:24:03 +01:00
}
return HasReturnvaluesIF::RETURN_OK;
}
P60DockTestTask::~P60DockTestTask() {
// TODO Auto-generated destructor stub
}