summaryrefslogtreecommitdiffstats
path: root/communication/server/src/CAN/Delivery
diff options
context:
space:
mode:
Diffstat (limited to 'communication/server/src/CAN/Delivery')
-rw-r--r--communication/server/src/CAN/Delivery/CAN_Delivery.cpp684
-rw-r--r--communication/server/src/CAN/Delivery/CAN_DeliveryData.cpp214
2 files changed, 370 insertions, 528 deletions
diff --git a/communication/server/src/CAN/Delivery/CAN_Delivery.cpp b/communication/server/src/CAN/Delivery/CAN_Delivery.cpp
index f4ee1f82..b9914313 100644
--- a/communication/server/src/CAN/Delivery/CAN_Delivery.cpp
+++ b/communication/server/src/CAN/Delivery/CAN_Delivery.cpp
@@ -1,5 +1,5 @@
/*
- * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION.
+ * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,336 +14,392 @@
* limitations under the License.
*/
-/*******************************************************************************
- * Module configuration :CANDataReceiveMsg() CANDataProcess of Received Messages
- * CANDlcCheck() DLC check process
- * CANDeliveryEntryMsgCheck() CANDataDelivery registration message check process
- * CAN_DeliveryCtrlMsg() CANDataDelivery control message processing Not mounted
- * CAN_DeliveryCtrlMsgCheck() CANDataDelivery control message check processing Not mounted
- * CANCanidIfToUserCvt() CAN ID Conversion Process 1
- ******************************************************************************/
-/*!-----------------------------------------------------------------------------
- * @file CAN_Delivery.cpp
- * @~english
- * @brief CAN Delivery process
- */
#include "CAN_Delivery.h"
-#include <native_service/frameworkunified_types.h> // NOLINT(build/include)
-#include <string.h>
-#include "CAN_DeliveryData.h"
-#include "CAN_CommWatch.h"
+
+#include <can_hal.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <peripheral_service/Canif_API.h>
+#include <can_hal.h>
+#include <utility>
+#include <map>
+#include <string>
#include "CAN_TxMsg.h"
+#include "CAN_CommWatch.h"
+#include "Canif_API_Local.h"
+#include "API_Local_Common.h"
+#include "Thread_Common.h"
-/*************************************************/
-/* Global variables */
-/*************************************************/
-const CANID kCulCanidCsumTbl[] = {/* CAN ID table that performs CSUM checks */
- (CANID)CAN_CSUM_CHECKTBL_STOP_CODE /* Stop code */
-};
-
-CAN_MSG_CANGWDATA g_cangw_msg_data; /* CANdata to be sent to the CANGW */
-/*******************************************************************************
- * MODULE : CANDataReceiveMsg
- ******************************************************************************/
-/*!-----------------------------------------------------------------------------
- * @~english
- * @brief CAN data reply processing
- *
- * CAN data reply processing
- *
- * CANDataReceive processing
- *
- * @~english
- * @note
- * -# OPC check
- * -# DLC check
- * -# CSUM check
- * -# Communication blackout clearness
- * -# Filter processing
- * -# ID list making for delivery
- * -# Message sending
- *
- * @~english
- * @return Data reception result
- * @retval <RET_CAN_NORMAL> Normality
- * @retval <RET_CAN_ERROR_CANCEL> Data annulment
- *
- * @~english
- * @param[in] <pst_rcv_msg> Reception message
- */
-RET_CAN CANDataReceiveMsg(HANDLE h_app, CAN_MSG_DATA *pst_rcv_msg) {
- RET_CAN ret = RET_CAN_NORMAL; /* Return value of this function */
-// T_ICR_CMD_DATA *pst_msg_data; /* Data part structure pointer */
- CANID can_id; /* CAN ID */
- uint8_t n_ta = CAN_NTA_INVALID; /* N_TA */
- uint8_t uc_dlc; /* DLC */
- uint8_t *puc_data_pos; /* Data */
- uint8_t i;
-
-// pst_msg_data = reinterpret_cast<T_ICR_CMD_DATA *>(reinterpret_cast<void *>(&pst_rcv_msg->ucData[0]));
- g_cangw_msg_data.num = 0;
-
- /****** OPC check process ******/
-// switch (pst_msg_data->opc) {
-// case CAN_OPC_RX: /* CANData reception notice */
-#if 0
- /****** DLC check process ******/
- if (RET_CAN_NORMAL != (ret = CANDlcCheck(pst_msg_data))) {
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery DLC Error");
- CANDebugLogOut(CAN_DELIVERY_DLCERR, reinterpret_cast<void *>(pst_rcv_msg));
+static CAN_DeliveryEntryList g_map_delivery_list_can;
+// Member of g_msg_rx_msg exist as long as communication exists.
+static std::map<CANID, CanMessage *> g_can_rx_msg;
+
+void CANDeliveryInit(void) {
+ g_map_delivery_list_can.clear();
+ return;
+}
+
+static CanMessage *CANMsgFind(CANID k) {
+ std::map<CANID, CanMessage *>::iterator it;
+
+ it = g_can_rx_msg.find(k);
+ if (it == g_can_rx_msg.end())
+ return NULL;
+ return it->second;
+}
+
+static void CANMsgInsert(CANID k, CanMessage *msg) {
+ CanMessage *latest = CANMsgFind(k);
+ if (!latest) {
+ latest = new CanMessage();
+ }
+ g_can_rx_msg[k] = latest;
+ memcpy(latest, msg, sizeof(CanMessage));
+}
+
+static CAN_DeliveryEntryListIt CANDeliveryFind(CANID canid, std::string s) {
+ std::pair<CAN_DeliveryEntryListIt, CAN_DeliveryEntryListIt> range;
+ CAN_DeliveryEntryListPair p = std::make_pair(canid, s);
+ CAN_DeliveryEntryListIt it;
+ bool found = false;
+ range = g_map_delivery_list_can.equal_range(canid);
+ for (it = range.first; it != range.second; ++it) {
+ if (*it == p) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ it = g_map_delivery_list_can.end();
+
+ return it;
+}
+
+bool CANDeliveryInsert(CANID canid, std::string s) {
+ CAN_DeliveryEntryListIt it = CANDeliveryFind(canid, s);
+ CAN_DeliveryEntryListPair p = std::make_pair(canid, s);
+ bool inserted = false;
+
+ if (it == g_map_delivery_list_can.end()) {
+ g_map_delivery_list_can.insert(p);
+ inserted = true;
+ }
+
+ return inserted;
+}
+
+static EFrameworkunifiedStatus CANDeliverySndCmdSingle(HANDLE h_app, CANID cmd,
+ CanMessage *msg, std::string dest) {
+ CAN_MSG_CANCMD st_delivery_msg;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail;
+ HANDLE h_client;
+ uint16_t len = 0;
+
+ // Create delivery data
+ memset(&st_delivery_msg, 0, sizeof(st_delivery_msg));
+ switch (cmd) {
+ case CAN_CMDID_FUELCALC_RST_REQ_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_FUELCALC_RST_SIZE;
+ break;
+ case CAN_CMDID_STARTUP_FIN_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_STARTUP_FIN_SIZE;
+ break;
+ case CAN_CMDID_MRST_INFO_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_MRST_INFO_SIZE;
+ break;
+ case CAN_CMDID_VERSION_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_VERSION_SIZE;
+ break;
+ case CAN_CMDID_CONNECTION_NODE_RESP_RX:
+ len = (uint16_t)(CAN_TX_CMD_DELIVERY_SIZE + msg->data[0] + 1);
+ break;
+ default:
+ return e_status;
+ }
+ st_delivery_msg.hdr.hdr.rid = 0;
+ st_delivery_msg.hdr.hdr.cid = (uint16_t)CID_CAN_CMD_DELIVERY;
+ st_delivery_msg.hdr.hdr.msgbodysize = len;
+ st_delivery_msg.data.cmd_id = (uint8_t)cmd;
+ memcpy(&st_delivery_msg.data.data, msg->data,
+ (size_t)(len - CAN_TX_CMD_DELIVERY_SIZE));
+
+ h_client = CommonFindSender(h_app, dest);
+ if (!h_client) {
+ return e_status;
+ }
+
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "cid=%x msgbodysize=%x cmd_id=%x",
+ st_delivery_msg.hdr.hdr.cid, st_delivery_msg.hdr.hdr.msgbodysize,
+ st_delivery_msg.data.cmd_id);
+ FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s",
+ MessageDataOutputLog(st_delivery_msg.data.data, len).c_str());
+
+ e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CMD_DELIVERY,
+ sizeof(st_delivery_msg), &st_delivery_msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(e_status:%d to:%s)",
+ e_status, dest.c_str());
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__,
+ "CAN Delivery : dst = %s, CMD = %x, DLC = %x",
+ dest.c_str(), cmd, msg->dlc);
+ }
+ return e_status;
+}
+
+static EFrameworkunifiedStatus CANDeliverySndMsgSingle(HANDLE h_app, CANID ul_canid,
+ uint8_t uc_dlc, const uint8_t *puc_data,
+ enum CanIfEchoBackFlags flag, std::string dest) {
+ CAN_MSG_CANDATA st_delivery_msg;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail;
+ HANDLE h_client;
+ uint8_t uc_size = uc_dlc;
+
+ // Create delivery data
+ memset(&st_delivery_msg, 0, sizeof(st_delivery_msg));
+ st_delivery_msg.hdr.hdr.cid = CID_CAN_DATA_DELIVERY;
+ st_delivery_msg.hdr.hdr.msgbodysize = (uint16_t)(CAN_TRX_CANID_SIZE +
+ CAN_TRX_DLC_SIZE +
+ (uint32_t)uc_size);
+ st_delivery_msg.hdr.hdr.rid = 0;
+ st_delivery_msg.data.can_id = ul_canid;
+ st_delivery_msg.data.dlc = uc_size;
+ st_delivery_msg.echoback = flag;
+ if (uc_size > (uint8_t)CAN_DATA_SIZE)
+ uc_size = CAN_DATA_SIZE;
+ memcpy(st_delivery_msg.data.data, puc_data, (size_t)uc_size);
+
+ h_client = CommonFindSender(h_app, dest);
+ if (!h_client) {
+ return e_status;
+ }
+
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "can_id=%x dlc=%x echoback=%d",
+ st_delivery_msg.data.can_id, st_delivery_msg.data.dlc,
+ st_delivery_msg.echoback);
+ FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s",
+ MessageDataOutputLog(st_delivery_msg.data.data, uc_size).c_str());
+
+ e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_DATA_DELIVERY,
+ sizeof(st_delivery_msg), &st_delivery_msg);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(e_status:%d to:%s)",
+ e_status, dest.c_str());
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__,
+ "CAN Delivery : dst = %s, CANID = %x, DLC = %x",
+ dest.c_str(), ul_canid, uc_dlc);
+ }
+ return e_status;
+}
+
+EFrameworkunifiedStatus CANDeliveryEntry(HANDLE h_app) {
+ FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "@@@ Start communication CanRecv");
+
+ uint16_t i;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ CAN_DELIVERY_ENTRY rcv_msg;
+ CAN_DeliveryEntryListIt it;
+ bool fail = false;
+
+ memset(&rcv_msg, 0, sizeof(rcv_msg));
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg,
+ sizeof(rcv_msg), eSMRRelease);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__,
+ "CAN DeliveryEntry FrameworkunifiedGetMsgDataOfSize Error(%d)", e_status);
+ if (e_status == eFrameworkunifiedStatusInvldBufSize) {
+ FrameworkunifiedClearMsgData(h_app);
+ }
+ goto cleanup;
+ }
+
+ for (i = 0; i < rcv_msg.usCanNum; i++) {
+ CANID canid = rcv_msg.ulCanid[i];
+ CanMessage *latest = CANMsgFind(canid);
+
+ if (CANDeliveryInsert(canid, rcv_msg.notifyName)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "(cnd:%lu) : CANID=0x%x, dst=%s",
+ g_map_delivery_list_can.size(), canid, rcv_msg.notifyName);
+ }
+
+ if (latest) {
+ switch (canid) {
+ case CAN_CMDID_FUELCALC_RST_REQ_RX:
+ case CAN_CMDID_STARTUP_FIN_RESP_RX:
+ case CAN_CMDID_MRST_INFO_RESP_RX:
+ case CAN_CMDID_VERSION_RESP_RX:
+ case CAN_CMDID_CONNECTION_NODE_RESP_RX:
+ if (eFrameworkunifiedStatusOK != CANDeliverySndCmdSingle(h_app, canid,
+ latest, rcv_msg.notifyName)) {
+ fail = true;
+ }
+ break;
+ default:
+ if (eFrameworkunifiedStatusOK != CANDeliverySndMsgSingle(h_app, canid,
+ static_cast<uint8_t>(latest->dlc),
+ latest->data, CANIF_PURERECV, rcv_msg.notifyName)) {
+ fail = true;
+ }
break;
}
-#endif
-
-// can_id = CANCanidIfToUserCvt(&(pst_msg_data->data[0]));
-
-// if (pst_msg_data->opc == CAN_OPC_RX) {
-// uc_dlc = pst_msg_data->data[CAN_MSGBUF_DLC_POS];
-// puc_data_pos = &pst_msg_data->data[CAN_MSGBUF_DATA_POS];
-// }
-
-// ret = CANDeliveryRcvData(h_app, can_id, n_ta, uc_dlc, puc_data_pos, pst_msg_data->opc);
-// if (ret != RET_CAN_NORMAL) { // LCOV_EXCL_BR_LINE 4: NSFW error case
-// AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
-// FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery Error"); // LCOV_EXCL_LINE 4: NSFW error case
-// CANDebugLogOut(CAN_DELIVERY_ERR, reinterpret_cast<void *>(pst_rcv_msg)); /* Delivery destination unregistered log output */ // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
-// }
-// break;
-// case CAN_OPC_PAC_RX:
- /* Check CAN Data num */
-// if (0 >= pst_msg_data->data[0] || CAN_EXRCV_DATA_NUM < pst_msg_data->data[0]) {
-// FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery CAN Data num Error CAN Data num=%02X",
-// pst_msg_data->data[0]); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h" // NOLINT (whitespace/line_length)
-// break;
-// }
-#if 0
- /****** DLC check process ******/
- if (RET_CAN_NORMAL != (ret = CANDlcCheck(pst_msg_data))) {
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery CAN Data size over");
- CANDebugLogOut(CAN_DELIVERY_DLCERR, reinterpret_cast<void *>(pst_rcv_msg));
- }
-
-#endif
-// for (i = 0; i < pst_msg_data->data[0]; i++) {
-// can_id = CANPacCanidIfToUserCvt(&pst_msg_data->data[i * CAN_EXRCV_DATA_SIZE + CAN_MSGBUF_PAC_CANID_POS]);
-
-// uc_dlc = pst_msg_data->data[i * CAN_EXRCV_DATA_SIZE + CAN_MSGBUF_PAC_DLC_POS];
-// puc_data_pos = &pst_msg_data->data[i * CAN_EXRCV_DATA_SIZE + CAN_MSGBUF_PAC_DATA_POS];
-
-// if (RET_CAN_NORMAL != CANDeliveryRcvData(h_app, can_id, n_ta, uc_dlc, puc_data_pos, pst_msg_data->opc)) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
-// AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
-// ret = RET_CAN_ERROR_CANCEL; // LCOV_EXCL_LINE 4: NSFW error case
-// FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery Error"); // LCOV_EXCL_LINE 4: NSFW error case
-// CANDebugLogOut(CAN_DELIVERY_ERR, reinterpret_cast<void *>(pst_rcv_msg)); /* Delivery destination unregistered log output */ // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
-// }
-// }
-// break;
-// default:
-// ret = RET_CAN_ERROR_CANCEL;
-// break;
-// }
- // When the number of data to be delivered to CANGW_M is 1 or more, the data is sent to CANGW_M by CANDeliverySndMsgToCANGW.
- if (0 < g_cangw_msg_data.num) {
- // Sending CAN-data delivery messages to the CANGW
- if (FALSE == CANDeliverySndMsgToCANGW(h_app, &g_cangw_msg_data)) { // LCOV_EXCL_BR_LINE 4: NSFW error case
- AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery Error"); // LCOV_EXCL_LINE 4: NSFW error case
- ret = RET_CAN_ERROR_CANCEL; // LCOV_EXCL_LINE 4: NSFW error case
}
}
- return (ret);
+
+ if (fail)
+ e_status = eFrameworkunifiedStatusFail;
+
+cleanup:
+ return e_status;
}
-/*!-----------------------------------------------------------------------------
- * @~english
- * @brief Recieve data delivery before processing
- *
- * @~english
- * @return Return value
- * @retval <RET_CAN_NORMAL> OK
- * @retval <RET_CAN_ERROR_CANCEL> Delivery Error
- *
- * @~english
- * @param[in] <h_app> Application handle
- * @param[in] <ul_canid> CAN ID
- * @param[in] <n_ta> N_TA
- * @param[in] <uc_dlc> DLC
- * @param[in] <puc_data_pos> CAN Data
- * @param[in] <opc> OPC
- */
-RET_CAN CANDeliveryRcvData(HANDLE h_app, CANID ul_canid, uint8_t n_ta,
- uint8_t uc_dlc, uint8_t *puc_data_pos, uint8_t opc) {
- RET_CAN ret = RET_CAN_NORMAL;
-
- /****** Communication interruption clear processing ******/
- CANCommWatchClear(h_app, ul_canid);
-
- /****** CANDataSending a delivery message ******/
- if (FALSE == CANDeliverySndMsg(h_app, ul_canid, uc_dlc, puc_data_pos, opc, n_ta)) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
- /* CANDataDelivery message transmission processing */
- AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery Error"); // LCOV_EXCL_LINE 4: NSFW error case
- ret = RET_CAN_ERROR_CANCEL; // LCOV_EXCL_LINE 4: NSFW error case
+static EFrameworkunifiedStatus CANDeliverySndMsgToClient(HANDLE h_app, CANID ul_canid,
+ void *data, size_t size, PS_CommunicationProtocol cid) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail;
+ HANDLE h_client = NULL;
+ CAN_DeliveryEntryListIt it;
+ std::pair<CAN_DeliveryEntryListIt, CAN_DeliveryEntryListIt> range;
+ bool fail = false;
+
+ it = g_map_delivery_list_can.find(ul_canid);
+ range = g_map_delivery_list_can.equal_range(ul_canid);
+ for (it = range.first; it != range.second; ++it) {
+ h_client = CommonFindSender(h_app, it->second);
+ if (!h_client) {
+ continue;
+ }
+
+ e_status = FrameworkunifiedSendMsg(h_client, cid, (UI_32)size, data);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(e_status:%d to:%s)",
+ e_status, it->second.c_str());
+ fail = true;
+ }
}
+ return fail ? eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus CANDeliverySndMsg(HANDLE h_app, CANID ul_canid, uint8_t n_ta,
+ uint8_t uc_dlc, const uint8_t *puc_data,
+ PS_CommunicationProtocol cid, enum CanIfEchoBackFlags flag) {
+ CAN_MSG_CANDATA st_delivery_msg;
+ uint8_t uc_size = uc_dlc;
+
+ // Create delivery data
+ memset(&st_delivery_msg, 0, sizeof(st_delivery_msg));
+ st_delivery_msg.hdr.hdr.cid = cid;
+ st_delivery_msg.hdr.hdr.msgbodysize = (uint16_t)(CAN_TRX_CANID_SIZE +
+ CAN_TRX_DLC_SIZE +
+ (uint32_t)uc_size);
+ st_delivery_msg.hdr.hdr.rid = 0;
+ st_delivery_msg.data.can_id = ul_canid;
+ st_delivery_msg.data.dlc = uc_size;
+ st_delivery_msg.echoback = flag;
+
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "can_id=%x dlc=%x echoback=%d",
+ st_delivery_msg.data.can_id, st_delivery_msg.data.dlc,
+ st_delivery_msg.echoback);
+ FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s",
+ MessageDataOutputLog(st_delivery_msg.data.data, uc_size).c_str());
- return ret;
+
+ if (uc_size > (uint8_t)CAN_DATA_SIZE)
+ uc_size = CAN_DATA_SIZE;
+ memcpy(st_delivery_msg.data.data, puc_data, (size_t)uc_size);
+
+ return CANDeliverySndMsgToClient(h_app, ul_canid, &st_delivery_msg,
+ sizeof(st_delivery_msg), cid);
}
-/*!-----------------------------------------------------------------------------
- * @~english
- * @brief Recieve _CWORD29_ data delivery before processing
- *
- * @~english
- * @return Return value
- * @retval <RET_CAN_NORMAL> OK
- * @retval <RET_CAN_ERROR_CANCEL> Delivery Error
- *
- * @~english
- * @param[in] <h_app> Application handle
- * @param[in] <us_opc> OPC
- * @param[in] <uc_dlc> DLC
- * @param[in] <puc_data_pos> CAN Data
- */
-RET_CAN CANDeliveryRcv_CWORD29_Data(HANDLE h_app, const uint16_t us_opc, uint32_t uc_dlc, uint8_t *puc_data_pos) {
- RET_CAN ret = RET_CAN_NORMAL;
-
- /****** CANDataSending a delivery message ******/
- if (FALSE == CANDelivery_CWORD29_SndMsg(h_app, us_opc, uc_dlc, puc_data_pos)) {
- /* CANDataDelivery message transmission processing */
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN Delivery Error");
- ret = RET_CAN_ERROR_CANCEL;
+EFrameworkunifiedStatus CANCommandDeliveryRcvProcess(HANDLE h_app,
+ CanMessage *msg, uint8_t cmd) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail;
+ CAN_MSG_CANCMD st_delivery_msg;
+ uint16_t len = 0;
+
+ memset(&st_delivery_msg, 0, sizeof(st_delivery_msg));
+ switch (cmd) {
+ case CAN_CMDID_FUELCALC_RST_REQ_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_FUELCALC_RST_SIZE;
+ break;
+ case CAN_CMDID_STARTUP_FIN_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_STARTUP_FIN_SIZE;
+ break;
+ case CAN_CMDID_MRST_INFO_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_MRST_INFO_SIZE;
+ break;
+ case CAN_CMDID_VERSION_RESP_RX:
+ len = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_VERSION_SIZE;
+ break;
+ case CAN_CMDID_CONNECTION_NODE_RESP_RX:
+ len = (uint16_t)(CAN_TX_CMD_DELIVERY_SIZE + msg->data[0] + 1);
+ break;
+ default:
+ return e_status;
}
+ st_delivery_msg.hdr.hdr.rid = 0;
+ st_delivery_msg.hdr.hdr.cid = (uint16_t)CID_CAN_CMD_DELIVERY;
+ st_delivery_msg.hdr.hdr.msgbodysize = len;
+ st_delivery_msg.data.cmd_id = cmd;
+ memcpy(&st_delivery_msg.data.data, msg->data,
+ (size_t)(len - CAN_TX_CMD_DELIVERY_SIZE));
+ CANMsgInsert(cmd, msg);
+
+ FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "cid=%x msgbodysize=%x cmd_id=%x",
+ st_delivery_msg.hdr.hdr.cid, st_delivery_msg.hdr.hdr.msgbodysize,
+ st_delivery_msg.data.cmd_id);
+ FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s",
+ MessageDataOutputLog(st_delivery_msg.data.data, len).c_str());
- return ret;
+ return CANDeliverySndMsgToClient(h_app, msg->can_id, &st_delivery_msg,
+ sizeof(st_delivery_msg), CID_CAN_CMD_DELIVERY);
}
-/*******************************************************************************
- * MODULE : CANDlcCheck
- ******************************************************************************/
-/*!-----------------------------------------------------------------------------
- * @~english
- * @brief DLC check processing
- *
- * DLC check processing of received CAN data
- *
- * CANDataCheck the PROCESS
- *
- * @~english
- * @note
- * -# Length acquisition of header
- * -# Positional change of DLC
- * -# Data length calculation
- * -# Data length comparison
- *
- * @~english
- * @param[in] <pst_msg_data> Pointer of reference to data division of reception message
- */
-//RET_CAN CANDlcCheck(const T_ICR_CMD_DATA *pst_msg_data) { // LCOV_EXCL_START 8: dead code
-// AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
-// RET_CAN ret = RET_CAN_NORMAL; /* Return value of this function */
-// int32_t l_len1; /* For data length calculation */
-// int32_t l_len2; /* For data length calculation */
-// uint8_t offset = 0; /* N_TA offset size */
-// uint8_t uc_dlc; /* DLC value */
-
- /* Length collection of headers */
-// l_len1 = (int32_t)pst_msg_data->d_length;
-
-// if ((uint8_t)CAN_OPC_PAC_RX == pst_msg_data->opc) {
-// l_len2 = (int32_t)(CAN_EXRCV_DATA_SIZE * pst_msg_data->data[0] + CAN_EXRCV_CANNUM_SIZE);
-
- /* DLC check of pacaging CAN data */
-// if (l_len1 != l_len2) {
-// ret = RET_CAN_ERROR_CANCEL; /* DLC error */
-// }
-// } else {
-// uc_dlc = (uint8_t)pst_msg_data->data[CAN_MSGBUF_DLC_POS];
- /* Data length considered from the DLC */
-// l_len2 = (int32_t)CAN_TRX_CANID_SIZE /* CAN ID sizes */
-// + (int32_t)CAN_TRX_DLC_SIZE /* Size of the DLC */
-// + (int32_t)offset /* Size of N_TA */
-// + (int32_t)uc_dlc; /* CANDataLength: DLC content */
-
- /* "Comparison of Length of headers and data length considered from DLCs */
- /* "Valid if the actual data length is equal to or less than the DLC */
-// if (l_len1 < l_len2) {
-// ret = RET_CAN_ERROR_CANCEL; /* DLC error */
-// } else if (uc_dlc > (uint8_t)CAN_DATA_SIZE) {
- /* CANDataDisabled when exceeding maximum size */
-// ret = RET_CAN_ERROR_CANCEL; /* DLC error */
-// } else {
- /* No DLC error */
-// }
-// }
-
-// return (ret);
-//}
-// LCOV_EXCL_STOP
-
-/*******************************************************************************
- * MODULE : CANCanidIfToUserCvt
- * ABSTRACT : CAN ID Conversion Process 1
- * FUNCTION : Convert CAN ID for interfaces to CAN ID for USER
- * ARGUMENT : *puc_operand :Operand reference pointer
- * NOTE :
- * RETURN : CAN ID
- ******************************************************************************/
-CANID CANCanidIfToUserCvt(uint8_t *puc_operand) {
- CANID can_id = 0; /* CAN ID */
- uint8_t *puc; /* Generic pointer */
- uint32_t ul = 0; /* General Variables */
-
- /* Concept of conversion
- Input data format (8-bit data with the following structure)
- Base Address +0 :ext_flag, CAN ID[10:4]
- +1 :CAN ID[3:0], Empty[1:0], CAN ID[28:27]
- +2 :CAN ID[26:19]
- +3 :CAN ID[18:11]
- Output data format (32-bit data)
- Bit assignment [31:29] [28:0]
- CAN ID Empty[2:0] CAN ID[28:0]
-*/
-
- puc = &puc_operand[CAN_MSGBUF_CANID_POS]; /* Get Base Address of CAN ID */
- ul = (uint32_t)puc[0] & 0x7F; /* Contain [10:4] data */
- ul <<= 4;
- can_id |= (CANID)ul;
- ul = (uint32_t)puc[1] & 0xF0; /* Insert data of [3:0] */
- ul >>= 4;
- can_id |= (CANID)ul;
- ul = (uint32_t)puc[1] & 0x03; /* Populate [28:27] */
- ul <<= 27;
- can_id |= (CANID)ul;
- ul = (uint32_t)puc[2]; /* Contain [26:19] data */
- ul <<= 19;
- can_id |= (CANID)ul;
- ul = (uint32_t)puc[3]; /* Populate [18:11] */
- ul <<= 11;
- can_id |= (CANID)ul;
-
- return (can_id);
+EFrameworkunifiedStatus CANDeliveryRcvProcess(HANDLE h_app, CanMessage *msg) {
+ if (!Canif_CheckCanID(msg->can_id)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "CANID is invalid (%x)", msg->can_id);
+ return eFrameworkunifiedStatusFail;
+ }
+
+ CANCommWatchClear(h_app, msg->can_id);
+ CANMsgInsert(msg->can_id, msg);
+ if (eFrameworkunifiedStatusOK != CANDeliverySndMsg(h_app, msg->can_id, CAN_NTA_INVALID,
+ (uint8_t)msg->dlc, msg->data, CID_CAN_DATA_DELIVERY)) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "CAN Delivery Error");
+ return eFrameworkunifiedStatusFail;
+ }
+
+ return eFrameworkunifiedStatusOK;
}
-/*******************************************************************************
- * MODULE : CANPacCanidIfToUserCvt
- * ABSTRACT : CAN ID Conversion Process 1
- * FUNCTION : Convert CAN ID for interfaces to CAN ID for USER
- * ARGUMENT : *puc_operand :Operand reference pointer
- * NOTE :
- * RETURN : CAN ID
- ******************************************************************************/
-CANID CANPacCanidIfToUserCvt(uint8_t *puc_operand) {
- CANID can_id = 0;
- uint8_t *puc;
- uint32_t ul = 0;
-
- puc = &puc_operand[0];
- ul = (uint32_t)puc[0] & 0x7F;
- ul <<= 4;
- can_id |= (CANID)ul;
- ul = (uint32_t)puc[1] & 0xF0;
- ul >>= 4;
- can_id |= (CANID)ul;
-
- return (can_id);
+EFrameworkunifiedStatus CANClearEntry(HANDLE h_app) {
+ char notify_name[CANIF_NOTIFY_NAME_MAX_SIZE + 1] = {0};
+ CAN_DeliveryEntryListIt it;
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+
+ e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &notify_name,
+ CANIF_NOTIFY_NAME_MAX_SIZE, eSMRRelease);
+ if (e_status != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__,
+ "#CAN thread# FrameworkunifiedGetMsgDataOfSize Error(%d)", e_status);
+ if (e_status == eFrameworkunifiedStatusInvldBufSize) {
+ FrameworkunifiedClearMsgData(h_app);
+ }
+ return e_status;
+ }
+
+ FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "notify_name=%s", notify_name);
+
+ // To avoid destruction of iterator.
+ it = g_map_delivery_list_can.begin();
+ while (it != g_map_delivery_list_can.end()) {
+ size_t n = strnlen(it->second.c_str(), CANIF_NOTIFY_NAME_MAX_SIZE);
+ if (!strncmp(it->second.c_str(), notify_name, n)) {
+ g_map_delivery_list_can.erase(it++);
+ } else {
+ ++it;
+ }
+ }
+
+ return eFrameworkunifiedStatusOK;
}
diff --git a/communication/server/src/CAN/Delivery/CAN_DeliveryData.cpp b/communication/server/src/CAN/Delivery/CAN_DeliveryData.cpp
deleted file mode 100644
index a0bc1f0f..00000000
--- a/communication/server/src/CAN/Delivery/CAN_DeliveryData.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*******************************************************************************
- * FILE :CAN_DeliveryData.cpp
- * SYSTEM :_CWORD107_
- * SUBSYSTEM :EXL process
- * PROGRAM :CAN thread CAN data delivery data management
- * Module configuration :CANDeliveryDataInit( ) CANDataDelivery Management Data Initialization Process
- * CAN_DeliveryCanidCheck( ) CAN ID registration and delivery registration checking process
- * CAN_DeliveryListCapacityCheck( ) CANDataDistribution destination management table free space confirmation processing
- * CAN_DeliveryCanidEntryCheck( ) CANDataChecking the status of delivery CAN ID control table entries
- * CANDeliveryEntry( ) CANDataDelivery registration process
- * CAN_SndListGenerate( ) CANData ID List Creation Process for Delivery
- ******************************************************************************/
-#include "CAN_DeliveryData.h"
-
-#include <string.h> // NOLINT(build/include)
-#include <native_service/frameworkunified_framework_if.h>
-#include <other_service/strlcpy.h>
-
-#include <utility>
-#include <string>
-#include <map>
-
-#include "CAN_Thread.h"
-#include "CAN_Delivery.h"
-#include "Canif_API_Local.h"
-//#include "can_hal.h"
-
-/*************************************************/
-/* Global variables */
-/*************************************************/
-std::multimap<CANID, std::string> g_map_delivery_list;
-std::multimap<uint16_t, std::string> g_map__CWORD29__delivery_list;
-
-/*******************************************************************************
- * MODULE : CANDeliveryDataInit
- * ABSTRACT : CANDataDelivery Management Data Initialization Process
- * FUNCTION : CANDataInitialize delivery management data for
- * ARGUMENT : void
- * NOTE :
- * RETURN : void
- ******************************************************************************/
-void CANDeliveryDataInit(void) {
- return;
-}
-
-/*******************************************************************************
- * MODULE : CANDeliveryEntry
- * ABSTRACT : CANDataDelivery registration process
- * FUNCTION : CANDataRegister delivery
- * ARGUMENT : notifyId : Addresses for delivery ID
- * usCanNum : Registered number
- * *pulCanid : CAN ID array pointers
- * NOTE :
- * RETURN : void
- ******************************************************************************/
-EFrameworkunifiedStatus CANDeliveryEntry(HANDLE h_app) {
- uint16_t i;
- EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
- CAN_DELIVERY_ENTRY rcv_msg;
- std::string notify_name;
- std::multimap<CANID, std::string>::iterator it;
-
- e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg, sizeof(rcv_msg), eSMRRelease); // LCOV_EXCL_BR_LINE 200: unexpect branch // NOLINT (whitespace/line_length)
- if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case
- AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN DeliveryEntry FrameworkunifiedGetMsgDataOfSize Error"); // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
- goto exit; // LCOV_EXCL_LINE 4: NSFW error case
- }
-
- for (i = 0; (i < rcv_msg.usCanNum) && (i < static_cast<uint16_t>(CAN_DELIVERY_CANID_ENTRY_MAX)); i++) {
- // Check for duplicate data
- // If the data to be registered is duplicated, an eFrameworkunifiedStatusOK is returned and the data is not registered.
- bool isDuplication = false;
- it = g_map_delivery_list.find(static_cast<std::multimap<CANID, std::string>::key_type>(rcv_msg.ulCanid[i]));
- for (; it != g_map_delivery_list.end(); ++it) {
- if (it->second == rcv_msg.notifyName) {
- isDuplication = true;
- break;
- }
- }
- if (isDuplication) {
- continue;
- }
-
- if ((uint32_t)g_map_delivery_list.size() >= CAN_DELIVERY_LIST_NUM) {
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN DeliveryEntry Table MAX size over"); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h" // NOLINT (whitespace/line_length)
- e_status = eFrameworkunifiedStatusFail;
- break;
- }
- FRAMEWORKUNIFIEDLOG(ZONE_ENTRY, "", "[CAN] %04x %s", rcv_msg.ulCanid[i], rcv_msg.notifyName); // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length)
- notify_name = rcv_msg.notifyName;
- g_map_delivery_list.insert(std::make_pair(rcv_msg.ulCanid[i], notify_name)); // LCOV_EXCL_BR_LINE 200: unexpect branch // NOLINT (whitespace/line_length)
- }
-
-exit:
- return e_status;
-}
-
-/*******************************************************************************
- * MODULE : CAN_CWORD29_DeliveryEntry
- * ABSTRACT : Process of registering the delivery of _CWORD29_ data
- * FUNCTION : Register the delivery of _CWORD29_ data
- * ARGUMENT : h_app : HANDLE
- * NOTE :
- * RETURN : EFrameworkunifiedStatus
- ******************************************************************************/
-EFrameworkunifiedStatus CAN_CWORD29_DeliveryEntry(HANDLE h_app) {
- uint16_t i;
- EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
- CAN__CWORD29__DELIVERY_ENTRY rcv_msg;
- std::string notify_name;
- std::multimap<uint16_t, std::string>::iterator it;
-
- if (reinterpret_cast<HANDLE>(NULL) == h_app) {
- return eFrameworkunifiedStatusFail;
- }
-
- e_status = FrameworkunifiedGetMsgDataOfSize(h_app, reinterpret_cast<PVOID>(&rcv_msg),
- static_cast<UI_32>(sizeof(CAN__CWORD29__DELIVERY_ENTRY)), eSMRRelease);
- if (e_status != eFrameworkunifiedStatusOK) {
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN DeliveryEntry FrameworkunifiedGetMsgDataOfSize Error");
- return e_status;
- }
-
- if (CAN_DELIVERY_OPC_ENTRY_MAX <= rcv_msg.usOpcNum) {
- e_status = eFrameworkunifiedStatusFail;
- return e_status;
- }
-
- for (i = 0; i < rcv_msg.usOpcNum; i++) {
- // Check for duplicate data
- // If the data to be registered is duplicated, an eFrameworkunifiedStatusOK is returned and the data is not registered.
- bool isDuplication = false;
- it = g_map__CWORD29__delivery_list.find(static_cast<std::multimap<uint16_t, std::string>::key_type>(rcv_msg.usOpc[i]));
- for (; it != g_map__CWORD29__delivery_list.end(); ++it) {
- if (it->second == rcv_msg.notifyName) {
- isDuplication = true;
- break;
- }
- }
- if (isDuplication) {
- continue;
- }
-
- if (static_cast<uint32_t>(g_map__CWORD29__delivery_list.size()) >= CAN_DELIVERY_LIST_NUM) {
- FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# _CWORD29_DeliveryEntry Table MAX size over");
- e_status = eFrameworkunifiedStatusFail;
- break;
- }
- FRAMEWORKUNIFIEDLOG(ZONE_ENTRY, "", "[OPC] %04x %s", rcv_msg.usOpc[i], rcv_msg.notifyName);
- notify_name = rcv_msg.notifyName;
- g_map__CWORD29__delivery_list.insert(std::make_pair(rcv_msg.usOpc[i], notify_name));
- }
-
- return e_status;
-}
-
-/*******************************************************************************
- * MODULE : CANDeliveryBufferOut
- * ABSTRACT : CAN shipping table log output processing
- * FUNCTION : Output the CAN shipping table log
- * ARGUMENT : FILE *fp_log : File pointer of the log output file
- * NOTE :
- * RETURN : Thread ID
- ******************************************************************************/
-void CANDeliveryBufferOut(FILE *fp_log) { // LCOV_EXCL_START 8:dead code
- AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
- uint32_t usage_rate;
- std::multimap<CANID, std::string>::iterator it;
-
- if (NULL != fp_log) {
- /* Destination management table output */
- usage_rate = (((uint32_t)g_map_delivery_list.size() * 100) / CAN_DELIVERY_LIST_NUM);
- (void)fprintf(fp_log, "CAN DeliveryList_Buffer \n");
- (void)fprintf(fp_log, "BUFFER_Use: %04zu BUFFER_Max: %04d Usage_Rate: %04u \n",
- g_map_delivery_list.size(), CAN_DELIVERY_LIST_NUM, usage_rate);
- if (usage_rate >= CAN_USAGE_RATE_THRESHOLD) {
- (void)fprintf(fp_log, "Warning: Buffer utilization exceeds a threshold.\n");
- }
- (void)fprintf(fp_log, "CanID: notifyId:\n");
-
- for (it = g_map_delivery_list.begin(); it != g_map_delivery_list.end(); it++) {
- (void)fprintf(fp_log, "%08x %s\n",
- it->first,
- it->second.c_str());
- }
- }
-}
-// LCOV_EXCL_STOP
-
-#ifdef CAN_DEBUG
-EFrameworkunifiedStatus CANAllDeleteDeliveryEntry(HANDLE h_app) {
- g_map_delivery_list.clear();
- g_map__CWORD29__delivery_list.clear();
-
- return eFrameworkunifiedStatusOK;
-} // LCOV_EXCL_BR_LINE 10 last Line
-#endif