ping test

This commit is contained in:
2020-12-16 15:17:10 +01:00
parent 380543756d
commit 32bd57d6d1
4 changed files with 107 additions and 15 deletions

View File

@ -34,6 +34,22 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
size_t commandDataLen) {
switch(deviceCommand) {
case(PING): {
PingMessageUnpacker pingMessageUnpacker(commandData, commandDataLen);
const uint8_t* pingData = pingMessageUnpacker.getPingData();
uint8_t pingDataSz = pingMessageUnpacker.getPingDataSz();
CspPingCommand cspPingCommand(pingDataSz, pingData);
size_t cspPacketLen = 0;
uint8_t* buffer = cspPacket;
cspPingCommand.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
SerializeIF::Endianness::BIG);
if(cspPacketLen > MAX_PACKET_LEN){
sif::error << "P60DockHandler: Received invalid ping message"
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
rawPacket = cspPacket;
rawPacketLen = cspPacketLen;
rememberCommandId = PING;
break;
}
case(PARAM_SET):{
@ -63,16 +79,16 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
}
rawPacket = cspPacket;
rawPacketLen = cspPacketLen;
rememberRequestedSize = querySize;
rememberCommandId = PARAM_SET;
break;
}
case(PARAM_GET):{
/* Unpack the received action message */
GetParamMessageUnpacker getParamMessage(commandData, commandDataLen);
uint8_t tableId = getParamMessage.getTableId();
uint16_t address = EndianConverter::convertLittleEndian<uint16_t>(
getParamMessage.getAddress());
uint16_t length = EndianConverter::convertLittleEndian<uint16_t>(
sizeof(address));
uint16_t address = getParamMessage.getAddress();
uint16_t length = sizeof(address);
uint16_t checksum = GOMSPACE::IGNORE_CHECKSUM;
uint16_t seq = 0;
uint16_t total = 0;
@ -113,7 +129,7 @@ ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start,
switch(rememberCommandId) {
case(PING):
*foundId = PING;
*foundLen = rememberRequestedSize;
*foundLen = PING_REPLY_SIZE;
rememberCommandId = NONE;
break;
case(PARAM_GET): {
@ -122,6 +138,12 @@ ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start,
rememberCommandId = NONE;
break;
}
case(PARAM_SET): {
*foundId = PARAM_SET;
*foundLen = rememberRequestedSize;
rememberCommandId = NONE;
break;
}
default:
return IGNORE_REPLY_DATA;
}
@ -132,13 +154,15 @@ ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch(id) {
case(PING): {
handleDeviceTM((SerializeIF*)packet, id, true, true);
PingReply pingReply(*packet, *(packet + 1));
handleDeviceTM(&pingReply, id, true, true);
break;
}
case(PARAM_GET): {
// -2 to subtract address size from gomspace parameter reply packet
uint16_t payloadLength = (*(packet + 2) << 8 | *(packet + 3)) - 2;
uint8_t tempPayloadBuffer[payloadLength];
/* Extract information from received data */
CspGetParamReply cspGetParamReply(tempPayloadBuffer, payloadLength);
size_t size = CspGetParamReply::GS_HDR_LENGTH + payloadLength;
cspGetParamReply.deSerialize(&packet, &size,
@ -146,11 +170,20 @@ ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id,
uint8_t action = cspGetParamReply.getAction();
uint8_t tableId = cspGetParamReply.getTableId();
uint16_t address = cspGetParamReply.getAddress();
/* Pack relevant information into a tm reply packet */
ParamReply paramReply(action, tableId, address, payloadLength,
tempPayloadBuffer);
handleDeviceTM(&paramReply, id, true);
break;
}
case(PARAM_SET): {
/* When setting a parameter, the p60dock sends back the state of the
* operation */
if(*packet != PARAM_SET_OK){
return HasReturnvaluesIF::RETURN_FAILED;
}
break;
}
default:
break;
}