eive-obsw/test/testtasks/P60DockTestTask.cpp

110 lines
3.2 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>
2020-11-28 13:41:30 +01:00
#include "P60DockTestTask.h"
2020-11-23 11:42:22 +01:00
#include <csp/drivers/can_socketcan.h>
2020-11-19 18:24:03 +01:00
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-12-04 14:14:08 +01:00
if(pingP60dock() != HasReturnvaluesIF::RETURN_OK){
2020-11-23 11:42:22 +01:00
return HasReturnvaluesIF::RETURN_FAILED;
2020-11-19 18:24:03 +01:00
}
2020-11-28 13:41:30 +01:00
if(getParameters() != HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED;
}
2020-11-23 11:42:22 +01:00
return HasReturnvaluesIF::RETURN_OK;
2020-11-19 18:24:03 +01:00
}
2020-12-04 14:14:08 +01:00
ReturnValue_t P60DockTestTask::pingP60dock(void){
2020-11-23 11:42:22 +01:00
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;
}
2020-11-26 10:24:23 +01:00
ReturnValue_t P60DockTestTask::getParameters(void) {
2020-11-28 13:41:30 +01:00
uint32_t timeout = 1000;
node_hk.rows = (gs_param_table_row_t*)p60dock_hk;
node_hk.id = P60DOCK_HK;
node_hk.row_count = p60dock_hk_count;
node_hk.memory_size = P60DOCK_HK_SIZE;
2020-12-04 14:14:08 +01:00
node_hk.memory = hkMem;
/* Retriev all houskeeping data from the P60 dock and store it in hkMem
* array */
2020-11-28 13:41:30 +01:00
int result = gs_rparam_get_full_table(&node_hk, p60dockAddress, node_hk.id,
GS_RPARAM_MAGIC_CHECKSUM, timeout);
2020-11-26 10:24:23 +01:00
if (result != 0) {
2020-12-04 14:14:08 +01:00
sif::info << "Error retrieving P60 Dock housekeeping" << std::endl;
2020-11-26 10:24:23 +01:00
return HasReturnvaluesIF::RETURN_FAILED;
} else {
uint8_t tableOffsetTemperature = 0x44;
2020-12-04 14:14:08 +01:00
int16_t temperature;
2020-11-28 13:41:30 +01:00
size_t parameterSize = sizeof(temperature);
2020-11-26 10:24:23 +01:00
uint32_t flags = 0;
result = gs_param_get_data((gs_param_table_instance_t*) &node_hk,
2020-12-04 14:14:08 +01:00
tableOffsetTemperature, &temperature, parameterSize, flags);
sif::info << "P60 Dock Temperature: " << temperature << std::endl;
uint16_t vbat_v;
parameterSize = sizeof(vbat_v);
uint8_t vbat_v_offset = 0x74;
result = gs_param_get_data((gs_param_table_instance_t*) &node_hk,
vbat_v_offset, &vbat_v, parameterSize, flags);
sif::info << "VBAT_V: " << vbat_v << std::endl;
2020-11-26 10:24:23 +01:00
}
return HasReturnvaluesIF::RETURN_OK;
}
2020-11-23 11:42:22 +01:00
ReturnValue_t P60DockTestTask::initializeCSPStack(void){
/* Init CSP and CSP buffer system */
2020-12-04 14:14:08 +01:00
if (csp_init(cspClientAddress) != CSP_ERR_NONE
2020-11-23 11:42:22 +01:00
|| 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
}