extended p60 dock test task

This commit is contained in:
Jakob Meier 2020-11-26 18:13:20 +01:00
parent 473aa805c0
commit 3b992f7651
4 changed files with 322 additions and 0 deletions

111
gomspace/include/port.h Normal file
View File

@ -0,0 +1,111 @@
#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

141
gomspace/include/rparam.h Normal file
View File

@ -0,0 +1,141 @@
#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

@ -9,6 +9,7 @@
#include <csp/drivers/can_socketcan.h> #include <csp/drivers/can_socketcan.h>
#include "P60DockTestTask.h" #include "P60DockTestTask.h"
#include "gomspace/include/rparam.h"
P60DockTestTask::P60DockTestTask(object_id_t objectId_): P60DockTestTask::P60DockTestTask(object_id_t objectId_):
SystemObject(objectId_){ SystemObject(objectId_){
@ -73,6 +74,74 @@ ReturnValue_t P60DockTestTask::sendPacket(void){
} }
ReturnValue_t P60DockTestTask::getParameterTable(unit8_t tableId){
gs_rparam_query_t * query;
csp_packet_t * request = csp_buffer_get(RPARAM_QUERY_LENGTH(query, 0));
if (request == NULL) {
sif::error << "Failed to get buffer for csp packet" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, node, GS_CSP_PORT_RPARAM, timeout_ms, CSP_O_CRC32);
if (!conn) {
csp_buffer_free(request);
sif::error << "CSP connection failure" << sif::error << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
query = (gs_rparam_query_t *) request->data;
query->action = RPARAM_GET;
query->table_id = table_id;
query->length = 0; // == get full table
query->checksum = csp_hton16(checksum);
query->seq = 0;
query->total = 0;
request->length = RPARAM_QUERY_LENGTH(query, 0);
if (!csp_send(conn, request, timeout_ms)) {
csp_buffer_free(request);
csp_close(conn);
sif::error << "CSP failed to send packet" << sif::error;
return HasReturnvaluesIF::RETURN_FAILED;
}
csp_packet_t * reply;
unsigned int total_bytes = 0;
while ((reply = csp_read(conn, timeout_ms)) != NULL) {
/* We have a reply */
query = (void *) reply->data;
const uint16_t qlength = csp_ntoh16(query->length);
total_bytes += qlength;
const uint16_t seq = csp_ntoh16(query->seq);
const uint16_t total = csp_ntoh16(query->total);
if (query->action == RPARAM_REPLY) {
error = gs_param_deserialize(tinst, query->payload.packed, qlength, F_FROM_BIG_ENDIAN);
}
csp_buffer_free(reply);
if (error || (seq >= total)) {
break;
}
}
if (reply == NULL) {
error = GS_ERROR_TIMEOUT;
}
if ((error == GS_OK) && (expected_bytes != total_bytes)) {
log_warning("%s: expected %u != received %u bytes", __FUNCTION__, expected_bytes, total_bytes);
error = GS_ERROR_DATA;
}
csp_close(conn);
return error;
}
ReturnValue_t P60DockTestTask::initializeCSPStack(void){ ReturnValue_t P60DockTestTask::initializeCSPStack(void){
/* Init CSP and CSP buffer system */ /* Init CSP and CSP buffer system */
if (csp_init(cspAddress) != CSP_ERR_NONE if (csp_init(cspAddress) != CSP_ERR_NONE

View File

@ -39,6 +39,7 @@ private:
ReturnValue_t sendPacket(void); ReturnValue_t sendPacket(void);
ReturnValue_t initializeCSPStack(void); ReturnValue_t initializeCSPStack(void);
ReturnValue_t getParameterTable(unit8_t tableId);
}; };