failed approach
This commit is contained in:
88
test/testtasks/P60DockTestTask.cpp
Normal file
88
test/testtasks/P60DockTestTask.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* P60DockTestTask.cpp
|
||||
*
|
||||
* Created on: 18.11.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#include <gs/csp/drivers/can/can.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
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);
|
||||
|
||||
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 */
|
||||
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);
|
||||
}
|
||||
/* Close connection */
|
||||
csp_close(conn);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
P60DockTestTask::~P60DockTestTask() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
35
test/testtasks/P60DockTestTask.h
Normal file
35
test/testtasks/P60DockTestTask.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* P60DockTestTask.h
|
||||
*
|
||||
* Created on: 18.11.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#ifndef TEST_TESTTASKS_P60DOCKTESTTASK_H_
|
||||
#define TEST_TESTTASKS_P60DOCKTESTTASK_H_
|
||||
|
||||
extern "C" {
|
||||
#include <csp/csp.h>
|
||||
#include <csp/interfaces/csp_if_can.h>
|
||||
}
|
||||
|
||||
|
||||
class P60DockTestTask: public ExecutableObjectIF {
|
||||
public:
|
||||
P60DockTestTask();
|
||||
virtual ~P60DockTestTask();
|
||||
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0);
|
||||
|
||||
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"};
|
||||
|
||||
ReturnValue_t sendPacket(void);
|
||||
|
||||
};
|
||||
|
||||
#endif /* TEST_TESTTASKS_P60DOCKTESTTASK_H_ */
|
Reference in New Issue
Block a user