config table retrieval works
This commit is contained in:
@ -71,7 +71,7 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF* cookie) {
|
||||
uint16_t maxReplyLength = cspCookie->getMaxReplyLength();
|
||||
if (cspDeviceMap.find(cspAddress) == cspDeviceMap.end()) {
|
||||
/* Insert device information in CSP map */
|
||||
cspDeviceMap.emplace(cspAddress, vectorBuffer(maxReplyLength));
|
||||
cspDeviceMap.emplace(cspAddress, ReplyInfo(maxReplyLength));
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
@ -104,6 +104,10 @@ ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
uint8_t cspAddress = cspCookie->getCspAddress();
|
||||
auto iter = cspDeviceMap.find(cspAddress);
|
||||
if (iter == cspDeviceMap.end()) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
switch (cspPort) {
|
||||
case (CspPorts::CSP_PING): {
|
||||
initiatePingRequest(cspAddress, querySize);
|
||||
@ -117,7 +121,7 @@ ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
||||
case (CspPorts::P60_PORT_RPARAM_ENUM): {
|
||||
if (cspCookie->getRequest() != SpecialRequestTypes::DEFAULT_COM_IF) {
|
||||
param_index_t requestStruct{};
|
||||
requestStruct.physaddr = cspDeviceMap[cspAddress].data();
|
||||
requestStruct.physaddr = iter->second.replyBuf.data();
|
||||
auto req = cspCookie->getRequest();
|
||||
if (req == GOMSPACE::SpecialRequestTypes::GET_PDU_HK) {
|
||||
if (!p60pdu_get_hk(&requestStruct, cspAddress, cspCookie->getTimeout())) {
|
||||
@ -139,8 +143,29 @@ ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
||||
requestStruct.size = P60PDU_PARAM_SIZE;
|
||||
int result = rparam_get_full_table(&requestStruct, cspAddress, P60_PORT_RPARAM,
|
||||
requestStruct.mem_id, cspCookie->getTimeout());
|
||||
param_list(&requestStruct, 1);
|
||||
return (result == 0);
|
||||
if (result != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
} else if (req == GOMSPACE::SpecialRequestTypes::GET_ACU_CONFIG) {
|
||||
requestStruct.table = p60acu_config;
|
||||
requestStruct.mem_id = P60ACU_PARAM;
|
||||
requestStruct.count = p60acu_config_count;
|
||||
requestStruct.size = P60ACU_PARAM_SIZE;
|
||||
int result = rparam_get_full_table(&requestStruct, cspAddress, P60_PORT_RPARAM,
|
||||
requestStruct.mem_id, cspCookie->getTimeout());
|
||||
if (result != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
} else if (req == GOMSPACE::SpecialRequestTypes::GET_P60DOCK_CONFIG) {
|
||||
requestStruct.table = p60dock_config;
|
||||
requestStruct.mem_id = P60DOCK_PARAM;
|
||||
requestStruct.count = p60dock_config_count;
|
||||
requestStruct.size = P60DOCK_PARAM_SIZE;
|
||||
int result = rparam_get_full_table(&requestStruct, cspAddress, P60_PORT_RPARAM,
|
||||
requestStruct.mem_id, cspCookie->getTimeout());
|
||||
if (result != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No CSP fixed port was selected. Send data to the specified port and
|
||||
@ -150,7 +175,7 @@ ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
}
|
||||
replySize = querySize;
|
||||
iter->second.replyLen = querySize;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -176,9 +201,12 @@ ReturnValue_t CspComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
||||
}
|
||||
|
||||
uint8_t cspAddress = cspCookie->getCspAddress();
|
||||
|
||||
*buffer = cspDeviceMap[cspAddress].data();
|
||||
*size = replySize;
|
||||
auto iter = cspDeviceMap.find(cspAddress);
|
||||
if (iter == cspDeviceMap.end()) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
*buffer = iter->second.replyBuf.data();
|
||||
*size = iter->second.replyLen;
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
@ -188,13 +216,13 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, const u
|
||||
uint32_t timeout_ms = 1000;
|
||||
uint16_t bytesRead = 0;
|
||||
int32_t expectedSize = static_cast<int32_t>(querySize);
|
||||
vectorBufferIter iter = cspDeviceMap.find(cspAddress);
|
||||
auto iter = cspDeviceMap.find(cspAddress);
|
||||
if (iter == cspDeviceMap.end()) {
|
||||
sif::error << "CSP device with address " << cspAddress << " no found in"
|
||||
<< " device map" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
uint8_t* replyBuffer = iter->second.data();
|
||||
uint8_t* replyBuffer = iter->second.replyBuf.data();
|
||||
|
||||
csp_conn_t* conn = csp_connect(CSP_PRIO_HIGH, cspAddress, cspPort, 0, CSP_O_NONE);
|
||||
|
||||
@ -239,7 +267,7 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, const u
|
||||
csp_close(conn);
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
if ((reply->length + bytesRead) > iter->second.size()) {
|
||||
if ((reply->length + bytesRead) > iter->second.replyBuf.size()) {
|
||||
sif::error << "CspComIF::cspTransfer: Reply buffer to short" << std::endl;
|
||||
csp_buffer_free(reply);
|
||||
csp_close(conn);
|
||||
@ -286,8 +314,12 @@ void CspComIF::initiatePingRequest(uint8_t cspAddress, uint16_t querySize) {
|
||||
uint32_t replyTime = csp_ping(cspAddress, timeout_ms, querySize, CSP_O_NONE);
|
||||
sif::info << "Ping address: " << cspAddress << ", reply after " << replyTime << " ms"
|
||||
<< std::endl;
|
||||
auto iter = cspDeviceMap.find(cspAddress);
|
||||
if (iter == cspDeviceMap.end()) {
|
||||
return;
|
||||
}
|
||||
/* Store reply time in reply buffer * */
|
||||
uint8_t* replyBuffer = cspDeviceMap[cspAddress].data();
|
||||
uint8_t* replyBuffer = iter->second.replyBuf.data();
|
||||
memcpy(replyBuffer, &replyTime, sizeof(replyTime));
|
||||
replySize = sizeof(replyTime);
|
||||
iter->second.replyLen = sizeof(replyTime);
|
||||
}
|
||||
|
@ -43,15 +43,16 @@ class CspComIF : public DeviceCommunicationIF, public SystemObject {
|
||||
int cmdLen, uint16_t querySize);
|
||||
|
||||
typedef uint8_t node_t;
|
||||
using vectorBuffer = std::vector<uint8_t>;
|
||||
using VectorBufferMap = std::unordered_map<node_t, vectorBuffer>;
|
||||
using vectorBufferIter = VectorBufferMap::iterator;
|
||||
struct ReplyInfo {
|
||||
ReplyInfo(size_t maxLen) : replyBuf(maxLen){};
|
||||
std::vector<uint8_t> replyBuf;
|
||||
size_t replyLen = 0;
|
||||
};
|
||||
using VectorBufferMap = std::unordered_map<node_t, ReplyInfo>;
|
||||
|
||||
/* In this map assigns reply buffers to a CSP device */
|
||||
VectorBufferMap cspDeviceMap;
|
||||
|
||||
uint16_t replySize = 0;
|
||||
|
||||
/* This is the CSP address of the OBC. */
|
||||
node_t cspOwnAddress = 1;
|
||||
|
||||
|
Reference in New Issue
Block a user