diff options
Diffstat (limited to 'communication/server/src/CAN/TxMsg/CAN_TxMsg.cpp')
-rw-r--r-- | communication/server/src/CAN/TxMsg/CAN_TxMsg.cpp | 1201 |
1 files changed, 328 insertions, 873 deletions
diff --git a/communication/server/src/CAN/TxMsg/CAN_TxMsg.cpp b/communication/server/src/CAN/TxMsg/CAN_TxMsg.cpp index 36ddc6d8..fa5d61d6 100644 --- a/communication/server/src/CAN/TxMsg/CAN_TxMsg.cpp +++ b/communication/server/src/CAN/TxMsg/CAN_TxMsg.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. @@ -13,949 +13,404 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/******************************************************************************* - * SYSTEM :_CWORD107_ - * SUBSYSTEM :EXL process - * Module configuration :CANDeliverySndMsg( ) CANDataDelivery message transmission processing - * CANFreqTransStartTxMsg( ) CANDataPeriodic transmission start message transmission processing - * CAN1TimeTransStartTxMsg( ) CANDataSend one transmission start message processing - * CANCommWatchSndMsg( ) CANDataTransmission of communication interruption detection/recovery message - * CANTxRsltSndMsg( ) CANDataTransmission result notification message transmission processing - * CANCanidUserToIfCvt( ) CAN ID Conversion Process 2 - * CANCommandDeliverySndMsg( ) CAN command delivery message transmission processing - * CANCommandTxRsltSndMsg( ) CAN command transmission result notification message transmission processing - * CANCommandTransmissionSndMsg( ) CAN command message transmission processing - * CANCommandFuelCalcRstReqSndMsg( ) CAN section flame reset request reception message transmission processing - * CANCommandidOpcToUserCvt( ) CAN Command ID Conversion Processing 1 - * CANCommandidUserToOpcCvt( ) CAN command ID conversion process 2 - ******************************************************************************/ -/*!----------------------------------------------------------------------------- - * @file CAN_TxMsg.cpp - * @~english - * @brief CAN Thread Message transmission process - */ #include "CAN_TxMsg.h" - -#include <string.h> // NOLINT (build/include) -#include <other_service/strlcpy.h> +#include "CAN_Delivery.h" +#include <string.h> #include <native_service/frameworkunified_types.h> -#include <agl_thread.h> #include <native_service/frameworkunified_framework_if.h> #include <peripheral_service/Canif_API.h> -//#include <can_hal.h> +#include <can_hal.h> #include <map> -#include <utility> #include <string> -#include "ICR_Common.h" - #include "CAN_Thread.h" -#include "CAN_DeliveryData.h" -#include "CAN_TransmissionData.h" -#include "CAN_CommWatchData.h" -#include "CAN_CommandData.h" - -/*************************************************/ -/* Prototype declaration */ -/*************************************************/ - -/*************************************************/ -/* Global variable */ -/*************************************************/ -static std::map<std::string, HANDLE_DAT> g_map_handler; -extern std::multimap<CANID, std::string> g_map_delivery_list; -extern std::multimap<uint16_t, std::string> g_map__CWORD29__delivery_list; -extern CAN_MSG_CANGWDATA g_cangw_msg_data; /* CANdata to be sent to the CANGW */ -extern BOOL g_isaccoff; // Declared in communication_application.cpp -/******************************************************************************* - * MODULE : CANDeliverySndMsg - * ABSTRACT : CANDataDelivery message transmission processing - * FUNCTION : CANDataSending a Delivery Message - * ARGUMENT : can_id : CAN ID - * uc_dlc : DLC - * *puc_data : CANDataPart pointer - * uc_opc : OPC - * n_ta : N_TA - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANDeliverySndMsg(HANDLE h_app, CANID can_id, uint8_t uc_dlc, - const uint8_t *puc_data, uint8_t uc_opc, uint8_t n_ta) { - BOOL ret = TRUE; - CAN_MSG_CANDATA st_delivery_msg; - uint8_t uc_size; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - BOOL q_full = FALSE; - uint16_t can_id_shift = 0; - std::multimap<CANID, std::string>::iterator it; - std::pair<std::multimap<CANID, std::string>::iterator, std::multimap<CANID, std::string>::iterator> rang; - - /* Initialization of delivery-message-structure to user */ - (void)memset(reinterpret_cast<void *>(&st_delivery_msg), (int32_t)0, (size_t)sizeof(st_delivery_msg)); - - /****** Header section creation (excluding response destination process No.) ******/ - switch (uc_opc) { - default: /* CAN_OPC_RX */ -// st_delivery_msg.hdr.hdr.cid = (uint16_t)CID_CAN_DATA_DELIVERY; /* CANDataDelivery notice */ - break; - } - /* Message data size */ -// st_delivery_msg.hdr.hdr.msgbodysize = (uint16_t)(CAN_TRX_CANID_SIZE + CAN_TRX_DLC_SIZE + -// CAN_TRX_DLC_RESERVE_SIZE + (uint32_t)uc_dlc); -// st_delivery_msg.hdr.hdr.rid = 0; /* Resource ID (not used) */ - - /****** Creation of data section ******/ - st_delivery_msg.data.can_id = can_id; /* CAN ID */ - st_delivery_msg.data.dlc = uc_dlc; /* DLC */ - if ((uint8_t)CAN_DATA_SIZE < uc_dlc) { - AGL_ASSERT_NOT_TESTED(); - uc_size = (uint8_t)CAN_DATA_SIZE; - } else { - uc_size = uc_dlc; - } - memcpy(st_delivery_msg.data.data, puc_data, (size_t)uc_size); +#include "Thread_Common.h" +#include "Canif_API_Local.h" +#include "CAN_TxMsg.h" +#include "Canif_TransmissionData.h" - it = g_map_delivery_list.find(can_id); - if (it == g_map_delivery_list.end()) { - /* Delivery destination unregistered log output */ - FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "#CAN_thread# CAN ID 0x%x not found in CAN Delivery entry table", can_id); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT (whitespace/line_length) - } +static std::map<CANID, CAN_SEND_STATUS_DAT> g_m_send_sts; +static bool can_cmd_rst_rcv = false; +static std::map<CANID, CAN_TRANS_START_TABLE_VAL *> g_map_trans_data; - /****** Messaging ******/ - rang = g_map_delivery_list.equal_range(can_id); - for (it = rang.first; it != rang.second; ++it) { - // If the delivery destination is other than CANGW, datum is sent. - if (TN_CANGW_M_RCV != it->second) { - if (g_map_handler.count(it->second) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, it->second.c_str()); - if (h_client == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - continue; // LCOV_EXCL_LINE 4: NSFW error case - } - g_map_handler[it->second].handle = h_client; - g_map_handler[it->second].is_q_full = FALSE; - } else { - h_client = g_map_handler[it->second].handle; - q_full = g_map_handler[it->second].is_q_full; - } +void CANTxMsgInit(void) { + g_m_send_sts.clear(); + uint32_t i; - if (g_isaccoff && q_full) { - /* Once queue full has occured during ACC OFF, do nothing */ - } else { -// e_status = FrameworkunifiedSendMsg(h_client, st_delivery_msg.hdr.hdr.cid, sizeof(st_delivery_msg), &st_delivery_msg); - if (eFrameworkunifiedStatusMsgQFull == e_status) { // LCOV_EXCL_BR_LINE 4: NSFW error case - /* eFrameworkunifiedStatusMsgQFull */ - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - g_map_handler[it->second].is_q_full = TRUE; // LCOV_EXCL_LINE 4: NSFW error case - } - if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# FrameworkunifiedSendMsg Error(e_status:%d to:%s)", e_status, it->second.c_str()); // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length) - } - } - } else { // If the destination is CANGW, the data is stored in the buffers. - can_id_shift = (uint16_t)(can_id << 4); - g_cangw_msg_data.data[g_cangw_msg_data.num].can_id_high = (uint8_t)(can_id_shift >> 8); - g_cangw_msg_data.data[g_cangw_msg_data.num].can_id_low = (uint8_t)(can_id_shift & 0xFF); - if (CANGW_DLC_MAX_SIZE < uc_dlc) { // LCOV_EXCL_BR_LINE 6: already checked in CANHalRcvProcess - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - g_cangw_msg_data.data[g_cangw_msg_data.num].dlc = CANGW_DLC_MAX_SIZE; // LCOV_EXCL_LINE 6: same as above - } else { - g_cangw_msg_data.data[g_cangw_msg_data.num].dlc = uc_dlc; - } - memcpy(g_cangw_msg_data.data[g_cangw_msg_data.num].data, puc_data, (size_t)CANGW_DLC_MAX_SIZE); - g_cangw_msg_data.num++; - } + for (i = 0; i < _countof(Can_TransInitData_21PF); i++) { + CANID canid = Can_TransInitData_21PF[i].canid; + CAN_TRANS_START_TABLE_VAL *val = &(Can_TransInitData_21PF[i].val); + g_map_trans_data[canid] = val; } - return (ret); + return; } -/******************************************************************************* - * MODULE : CANDelivery_CWORD29_SndMsg - * ABSTRACT : CAN_CWORD29_ delivery messaging process - * FUNCTION : Send CAN_CWORD29_ delivery messages - * ARGUMENT : h_app : HANDLE - * us_opc : OPC - * uc_dlc : DLC - * *puc_data : CANDataPart pointer - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANDelivery_CWORD29_SndMsg(HANDLE h_app, const uint16_t us_opc, uint32_t uc_dlc, const uint8_t *puc_data) { - BOOL ret = TRUE; - CAN_MSG_CAN__CWORD29_DATA st_delivery_msg; - uint32_t uc_size; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - BOOL q_full = FALSE; - std::multimap<uint16_t, std::string>::iterator it; - std::pair<std::multimap<uint16_t, std::string>::iterator, std::multimap<uint16_t, std::string>::iterator> rang; - /* Initialization of delivery-message-structure to user */ - (void)memset(reinterpret_cast<void *>(&st_delivery_msg), (int32_t)0, (size_t)sizeof(st_delivery_msg)); - - /****** Creation of data section ******/ - st_delivery_msg.opc = us_opc; /* OPC */ - st_delivery_msg.dlc = uc_dlc; /* DLC */ - if ((uint32_t)CAN__CWORD29__MEM_SZ < uc_dlc) { - uc_size = (uint32_t)CAN__CWORD29__MEM_SZ; - } else { - uc_size = uc_dlc; - } - memcpy(st_delivery_msg.data, puc_data, (size_t)uc_size); - it = g_map__CWORD29__delivery_list.find(static_cast<const uint16_t>(us_opc)); - if (it == g_map__CWORD29__delivery_list.end()) { - /* Delivery destination unregistered log output */ - FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "#CAN_thread# OPC 0x%x not found in CAN Delivery entry table", us_opc); - } +static bool CANCommandFuelCalcRstReqCheck(void) { + return can_cmd_rst_rcv; +} - /****** Messaging ******/ - rang = g_map__CWORD29__delivery_list.equal_range(static_cast<const uint16_t>(us_opc)); - for (it = rang.first; it != rang.second; ++it) { - if (g_map_handler.count(it->second) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, it->second.c_str()); - if (h_client == NULL) { - ret = FALSE; - continue; - } - g_map_handler[it->second].handle = h_client; - g_map_handler[it->second].is_q_full = FALSE; - } else { - h_client = g_map_handler[it->second].handle; - q_full = g_map_handler[it->second].is_q_full; - } +void CANCommandSetFuelCalcRstReq(void) { + can_cmd_rst_rcv = true; +} - if (g_isaccoff && q_full) { - /* Once queue full has occured during ACC OFF, do nothing */ - } else { - e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_DIAG_CWORD29__DELIVERY, sizeof(CAN_MSG_CAN__CWORD29_DATA), &st_delivery_msg); - if (eFrameworkunifiedStatusMsgQFull == e_status) { - /* eFrameworkunifiedStatusMsgQFull */ - g_map_handler[it->second].is_q_full = TRUE; - } - if (e_status != eFrameworkunifiedStatusOK) { - ret = FALSE; - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# FrameworkunifiedSendMsg Error(e_status:%d to:%s)", e_status, it->second.c_str()); // NOLINT (whitespace/line_length) - } - } - } - return (ret); +static void CANTxMsgErrorLog(const char *reason, const char *func, + CANID id, uint16_t len, HANDLE h_app) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, func, "%s Frame(0x%x) length=%hu from %s is ignored.", + reason, id, len, FrameworkunifiedGetMsgSrc(h_app)); } -/******************************************************************************* - * MODULE : CANDeliverySndMsgToCANGW - * ABSTRACT : CAN-data-delivery-messaging process to the CANGW - * FUNCTION : CANDataSending Delivery Messages to a CANGW - * ARGUMENT : h_app : HANDLE - * cangw_data : CAN_MSG_CANGWDATA - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANDeliverySndMsgToCANGW(HANDLE h_app, CAN_MSG_CANGWDATA *cangw_data) { - BOOL ret = TRUE; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - BOOL q_full = FALSE; - uint8_t data_count; - - // Memset unused space - data_count = cangw_data->num; - memset(reinterpret_cast<void *>(&cangw_data->data[data_count]), (int32_t)0, - (size_t)sizeof(cangw_data->data[data_count]) * (CANGW_SND_NUM_MAX - data_count)); - - if (g_map_handler.count(TN_CANGW_M_RCV) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, TN_CANGW_M_RCV); - if (h_client == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - goto exit; // LCOV_EXCL_LINE 4: NSFW error case - } - g_map_handler[TN_CANGW_M_RCV].handle = h_client; // LCOV_EXCL_BR_LINE 200 unexpect branch - g_map_handler[TN_CANGW_M_RCV].is_q_full = FALSE; // LCOV_EXCL_BR_LINE 200 unexpect branch - } else { - h_client = g_map_handler[TN_CANGW_M_RCV].handle; // LCOV_EXCL_BR_LINE 200 unexpect branch - q_full = g_map_handler[TN_CANGW_M_RCV].is_q_full; // LCOV_EXCL_BR_LINE 200 unexpect branch - } +static EFrameworkunifiedStatus CANCommandResponse(HANDLE h_app, CAN_MSG_CANCMD *msg, + size_t len, char *notifyName) { + HANDLE h_client = NULL; + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; - if (g_isaccoff && q_full) { - /* Once queue full has occured during ACC OFF, do nothing */ - } else { - e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CANGW_DELIVERY, sizeof(CAN_MSG_CANGWDATA), cangw_data); - if (eFrameworkunifiedStatusMsgQFull == e_status) { // LCOV_EXCL_BR_LINE 4: NSFW error case - /* eFrameworkunifiedStatusMsgQFull */ - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - g_map_handler[TN_CANGW_M_RCV].is_q_full = TRUE; // LCOV_EXCL_LINE 4: NSFW error case - } - if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# FrameworkunifiedSendMsg Error(e_status:%d to:%s)", e_status, TN_CANGW_M_RCV); // LCOV_EXCL_LINE 4: NSFW error case // NOLINT (whitespace/line_length) - } + h_client = CommonFindSender(h_app, notifyName); + if (!h_client) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Cannot open sender handle."); + return e_status; } -exit: - return (ret); + + msg->hdr.hdr.cid = (uint16_t)CID_CAN_CMD_DELIVERY; + e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CMD_DELIVERY, (uint32_t)len, msg); + if (e_status != eFrameworkunifiedStatusOK) + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg is failed."); + + return e_status; } -/******************************************************************************* - * MODULE : CANFreqTransStartTxMsg - * ABSTRACT : CANDataPeriodic transmission start message transmission processing - * FUNCTION : CANDataSending Periodic Send Data as a Send Message - * ARGUMENT : uc_index : Indexed - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANFreqTransStartTxMsg(HANDLE h_app, uint8_t uc_index) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_FREQ_TRANSMISSION_DAT st_data; /* Periodic send data acquisition buffer */ - - /****** Data acquisition ******/ - CANFreqTransDataGet(uc_index, &st_data); /* Periodic transmission data acquisition */ - - /****** Messaging ******/ - if ((uint8_t)0 == st_data.uc_resp_num) { - uc_index = (uint8_t)CAN_RID_NOTUSE_CODE; +static EFrameworkunifiedStatus CANCommandVersionReq(HANDLE h_app, char *notifyName) { + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + CANHAL_RET_API ret = CANHAL_RET_NORMAL; + std::string version_info; + CAN_MSG_CANCMD msg; + + memset(&msg, 0, sizeof(msg)); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "@@@ Call CanGetVersion for can_hal"); + ret = CanGetVersion(h_app, &version_info); + if (ret != CANHAL_RET_NORMAL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Cannot get version from can_hal."); + return e_status; } - /* CANDataSend one transmission start message processing */ - if (FALSE == CAN1TimeTransStartTxMsg(h_app, uc_index, &st_data.st_can_data)) { - ret = FALSE; /* Return value of this function */ + if (CAN_TX_CMD_VERSION_SIZE != version_info.length()) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Invalid length of version."); + return e_status; } - return (ret); + msg.hdr.hdr.rid = 0; + msg.hdr.hdr.msgbodysize = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_VERSION_SIZE; + msg.data.cmd_id = CAN_CMDID_VERSION_RESP_RX; + strncpy((char *)msg.data.data, version_info.c_str(), CAN_TX_CMD_VERSION_SIZE); + return CANCommandResponse(h_app, &msg, sizeof(msg), notifyName); } -/******************************************************************************* - * MODULE : CAN1TimeTransStartTxMsg - ******************************************************************************/ -/*!----------------------------------------------------------------------------- - * @~english - * @brief The transmission of CAN data transmission start message - * - * @~english - * The transmission of CAN data transmission start message - * - * @~english - * @note Details of process - * -# Creating of data division - * -# Message sending - * - * @~english - * @return Message transmission success/failure - * @retval <1> Message transmission success - * @retval <0> Message transmission failure - * - * @~english - * @param[in] <uc_can_rid> Index - * @param[in] <*pst_data> Pointer of transmission data - * @param[in] <uc_opc> Operation code - * @param[in] <n_ta> Target address - */ -BOOL CAN1TimeTransStartTxMsg(HANDLE h_app, uint8_t uc_can_rid, const CAN_DATA *pst_data) { - BOOL b_ret = TRUE; -// CanMessage st_can_data; -// -// if (pst_data != NULL) { // LCOV_EXCL_BR_LINE 200 (the caller always use the pointer of object) -// st_can_data.can_id = pst_data->can_id; -// st_can_data.dlc = pst_data->dlc; -// st_can_data.rid = uc_can_rid; -// if (pst_data->dlc < 8) { -// memcpy(st_can_data.data, pst_data->data, pst_data->dlc); -// } - -// if (CanSend(&st_can_data, CAN_HAL_TYPE_CAN) != CANHAL_RET_NORMAL) { -// b_ret = FALSE; -// } -// } - return b_ret; -} - -/******************************************************************************* - * MODULE : CANCommWatchSndMsg - * ABSTRACT : CANDataTransmission of communication interruption detection/recovery message - * FUNCTION : CANDataSend disconnection detection messages or recovery messages - * ARGUMENT : uc_index : Indexed - * NOTE : - * RETURN : None - ******************************************************************************/ -void CANCommWatchSndMsg(HANDLE h_app, uint8_t uc_index) { - DID ul_did; /* Data ID */ - uint8_t uc_comm_stop; /* Communication status */ - CAN_MSG_COMM_WATCHSTS st_comm_watch_sts; /* Communication Disruption Detection/Recovery Message Structures to the user */ - // int32_t ret_api; /* Return Values of System API Functions */ - char notify_name[MAX_NAME_SIZE_APP]; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - - /* Message structure initialization */ - memset(reinterpret_cast<void *>(&st_comm_watch_sts), (int32_t)0, (size_t)sizeof(st_comm_watch_sts)); - /* Buffer initialization */ - - /* Acquisition of the communication status of the target index */ - CANCommWatchDataGet(uc_index, notify_name, &ul_did, &uc_comm_stop, CAN_PROTOCOL_TYPE_CAN); - - /* Message creation */ - /* Creation of header part (CAN -> Monitoring Requester)*/ -// if ((uint8_t)CAN_COMM_NORMAL == uc_comm_stop) { /* Command ID */ - /* During communication -> Send data communication recovery notification message */ -// st_comm_watch_sts.hdr.hdr.cid = (uint16_t)CID_CAN_COMM_RESTORE; -// } else { - /* When communication is interrupted -> Send data communication interruption notification message */ -// st_comm_watch_sts.hdr.hdr.cid = (uint16_t)CID_CAN_COMM_STOP; -// } -// st_comm_watch_sts.hdr.hdr.msgbodysize = sizeof(CAN_MSG_COMM_WATCHSTS_DAT); /* Message data size */ -// st_comm_watch_sts.hdr.hdr.rid = 0; /* Resource ID (not used) */ - st_comm_watch_sts.data.ulDid = ul_did; /* Creation of data section */ - - if (g_map_handler.count(notify_name) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, notify_name); - if (h_client == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - goto exit; // LCOV_EXCL_LINE 4: NSFW error case - } - g_map_handler[notify_name].handle = h_client; // LCOV_EXCL_BR_LINE 200 unexpect branch - g_map_handler[notify_name].is_q_full = FALSE; // LCOV_EXCL_BR_LINE 200 unexpect branch +static EFrameworkunifiedStatus CANCommandFuelcalcRstReq(HANDLE h_app, char *notifyName) { + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + if (CANCommandFuelCalcRstReqCheck()) { + // CAN_CMDID_FUELCALC_RST_REQ_RX is already received from can_hal. + // so response it in direct. + CAN_MSG_CANCMD msg; + memset(&msg, 0, sizeof(msg)); + msg.hdr.hdr.rid = 0; + msg.hdr.hdr.msgbodysize = CAN_TX_CMD_DELIVERY_SIZE + + CAN_TX_CMD_FUELCALC_RST_SIZE; + msg.data.cmd_id = CAN_CMDID_FUELCALC_RST_REQ_RX; + e_status = CANCommandResponse(h_app, &msg, sizeof(msg), notifyName); } else { - h_client = g_map_handler[notify_name].handle; // LCOV_EXCL_BR_LINE 200 unexpect branch - } -// e_status = FrameworkunifiedSendMsg(h_client, st_comm_watch_sts.hdr.hdr.cid, sizeof(st_comm_watch_sts), &st_comm_watch_sts); - if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - CANCommWatchDelete(uc_index, CAN_PROTOCOL_TYPE_CAN); // LCOV_EXCL_LINE 4: NSFW error case - goto exit; // LCOV_EXCL_LINE 4: NSFW error case + CANDeliveryInsert(CAN_CMDID_FUELCALC_RST_REQ_RX, notifyName); + e_status = eFrameworkunifiedStatusOK; } -exit: - return; + return e_status; } -/******************************************************************************* - * MODULE : CANTxRsltSndMsg - * ABSTRACT : CANDataTransmission result notification message transmission processing - * FUNCTION : CANDataSend a transmission result notification message - * ARGUMENT : uc_can_rid : Resource ID from CAN - * uc_status : Transmission result status - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANTxRsltSndMsg(HANDLE h_app, uint8_t uc_can_rid, uint8_t uc_status) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_MSG_SENDSTS st_txrslt_msg; /* Transmission result notification message structure */ - CAN_1TIME_TXRSLT_DAT st_data; /* Transmission result data */ - int32_t ret_api = RET_NORMAL; /* Return Values of System API Functions */ - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; +static EFrameworkunifiedStatus CANCommandOther(HANDLE h_app, char *notifyName, + uint8_t cmd, uint8_t rid) { + CanMessage msg; + CANID wait = 0; + CANID can_id = (CANID)cmd; + + memset(&msg, 0, sizeof(msg)); + switch (cmd) { + case CAN_CMDID_STARTUP_FIN_REQ_TX: + wait = CAN_CMDID_STARTUP_FIN_RESP_RX; + break; + case CAN_CMDID_MRST_INFO_REQ_TX: + wait = CAN_CMDID_MRST_INFO_RESP_RX; + break; + case CAN_CMDID_CONNECTION_NODE_REQ_TX: + wait = CAN_CMDID_CONNECTION_NODE_RESP_RX; + break; + case CAN_CMDID_FUELCALC_REQ_TX: + wait = CAN_CMDID_FUELCALC_RST_REQ_RX; + break; + default: + CANTxMsgErrorLog("Unsupported cmd requested", __func__, cmd, 0, h_app); + return eFrameworkunifiedStatusFail; + } - if (static_cast<const uint8_t>(CAN_TXRSLT_CANRID__CWORD29__START) <= uc_can_rid) { - return (FALSE); + if (cmd != CAN_CMDID_FUELCALC_REQ_TX) { + CANDeliveryInsert(wait, notifyName); } - memset(reinterpret_cast<void *>(&st_txrslt_msg), 0, sizeof(CAN_MSG_SENDSTS)); - /* Message structure initialization */ - /****** Data acquisition ******/ - CANTxRsltDataGet(uc_can_rid, &st_data); - - /****** Creation of header section ******/ -// st_txrslt_msg.hdr.hdr.cid = static_cast<uint16_t>(CID_CAN_TX_RESULT); /* Command ID */ -// st_txrslt_msg.hdr.hdr.msgbodysize = static_cast<uint16_t>(sizeof(CAN_MSG_SENDSTS_DAT)); /* Message data size */ - - /****** Creation of data section ******/ -// st_txrslt_msg.hdr.hdr.rid = st_data.uc_rid; /* Resources ID */ - st_txrslt_msg.data.ulCanid = st_data.ul_canid; /* CAN ID */ - st_txrslt_msg.data.ucStatus = uc_status; /* Transmission result status */ - - FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "Rid:%02x Canid:%08x Status:%02x", st_data.uc_rid, st_data.ul_canid, uc_status); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT (whitespace/line_length) - /****** Messaging ******/ - if (g_map_handler.count(st_data.notify_name) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, reinterpret_cast<const char *>(st_data.notify_name)); - if (h_client == reinterpret_cast<HANDLE>(NULL)) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender Error(name=%s)", st_data.notify_name); - ret_api = RET_ERROR; + if (rid != CAN_RID_NOTUSE_CODE) { + // cmd can be assumed same as can_id. + if (0 < g_m_send_sts.count(can_id)) { + if (g_m_send_sts[can_id].notify_name[0] != 0x00) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, + "Not yet deliver SendSts but updated(SendID=%x, CAN ID=%x, Nane=%s)", + g_m_send_sts[can_id].rid, can_id, g_m_send_sts[can_id].notify_name); + } } - g_map_handler[st_data.notify_name].handle = h_client; // LCOV_EXCL_BR_LINE 200: unexpect branch - g_map_handler[st_data.notify_name].is_q_full = FALSE; // LCOV_EXCL_BR_LINE 200: unexpect branch - } else { - h_client = g_map_handler[st_data.notify_name].handle; // LCOV_EXCL_BR_LINE 200: unexpect branch + g_m_send_sts[can_id].rid = rid; + memcpy(g_m_send_sts[can_id].notify_name, notifyName, + sizeof(g_m_send_sts[can_id].notify_name)); } -// e_status = FrameworkunifiedSendMsg(h_client, st_txrslt_msg.hdr.hdr.cid, -// static_cast<UI_32>(sizeof(CAN_MSG_SENDSTS)), reinterpret_cast<PCVOID>(&st_txrslt_msg)); - if (e_status != eFrameworkunifiedStatusOK) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error"); - ret_api = RET_ERROR; - } + msg.can_id = (CANID)cmd; + msg.rid = rid; + msg.dlc = (uint8_t)CAN_CMDSND_DATA_SIZE; - if (RET_NORMAL != ret_api) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(ret_api=%d)", ret_api); - /* Check for message transmission and reception errors */ - CANMsgErrChk(ret_api, 0); - ret = FALSE; /* Message transmission failure */ + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "@@@ Call CanSend for can_hal"); + if (CANHAL_RET_NORMAL != CanSend(h_app, &msg, CAN_HAL_TYPE_CAN)) { + CANTxMsgErrorLog("CAN CanSend failed", __func__, msg.can_id, + (uint16_t)msg.dlc, h_app); + return eFrameworkunifiedStatusFail; } - return (ret); + return eFrameworkunifiedStatusOK; } -/******************************************************************************* - * MODULE : CAN_CWORD29_TxRsltSndMsg - * ABSTRACT : _CWORD29_ data transmission result notification message transmission process - * FUNCTION : Send _CWORD29_ transmission result notification messages - * ARGUMENT : uc_can_rid : Resource ID from CAN - * uc_status : Transmission result status - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CAN_CWORD29_TxRsltSndMsg(const HANDLE h_app, const uint8_t uc_can_rid, const uint8_t uc_status) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_MSG__CWORD29__SENDSTS st_txrslt_msg; /* _CWORD29_ send result notification messaging structures */ - CAN__CWORD29__TXRSLT_DAT st_data; /* _CWORD29_ transmission result data */ - int32_t ret_api = RET_NORMAL; /* Return Values of System API Functions */ - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; +EFrameworkunifiedStatus CANTxMsgCommand(HANDLE h_app) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "@@@ Start communication CanCommandCtl"); - if (reinterpret_cast<HANDLE>(NULL) == h_app) { - return (FALSE); - } + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + CAN_CMD_CTRL_MSG_DAT rcv_msg; - memset(reinterpret_cast<void *>(&st_txrslt_msg), 0, sizeof(CAN_MSG__CWORD29__SENDSTS)); - /* Message structure initialization */ - /****** Data acquisition ******/ - CAN_CWORD29_TxRsltDataGet(uc_can_rid, &st_data); - - /****** Creation of header section ******/ -// st_txrslt_msg.hdr.hdr.cid = CID_CAN__CWORD29__TX_RESULT; /* Command ID */ - /* Message data size */ -// st_txrslt_msg.hdr.hdr.msgbodysize = static_cast<uint16_t>(sizeof(CAN_MSG__CWORD29__SENDSTS_DAT)); - - /****** Creation of data section ******/ -// st_txrslt_msg.hdr.hdr.rid = st_data.uc_rid; /* Resources ID */ - st_txrslt_msg.data.usOpc = st_data.opc; /* OPC */ - st_txrslt_msg.data.ucStatus = uc_status; /* Transmission result status */ - - FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "Rid:%02x OPC:%08x Status:%02x", st_data.uc_rid, st_data.opc, uc_status); - /****** Messaging ******/ - if (g_map_handler.count(reinterpret_cast<const char *>(st_data.notify_name)) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, st_data.notify_name); - if (h_client == reinterpret_cast<HANDLE>(NULL)) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender Error(name=%s)", st_data.notify_name); - ret_api = RET_ERROR; - } - g_map_handler[st_data.notify_name].handle = h_client; - g_map_handler[st_data.notify_name].is_q_full = FALSE; - } else { - h_client = g_map_handler[st_data.notify_name].handle; - } + memset(&rcv_msg, 0, sizeof(rcv_msg)); -// e_status = FrameworkunifiedSendMsg(h_client, static_cast<UI_32>(st_txrslt_msg.hdr.hdr.cid), sizeof(CAN_MSG__CWORD29__SENDSTS), -// &st_txrslt_msg); + e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg, sizeof(rcv_msg), eSMRRelease); if (e_status != eFrameworkunifiedStatusOK) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error"); - ret_api = RET_ERROR; + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedGetMsgDataOfSize Error(%d)", e_status); + if (e_status == eFrameworkunifiedStatusInvldBufSize) + FrameworkunifiedClearMsgData(h_app); + return e_status; } - /****** NSFW error case ******/ - if (RET_NORMAL != ret_api) { - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(ret_api=%d)", ret_api); - /* Check for message transmission and reception errors */ - CANMsgErrChk(ret_api, 0); - /* Message transmission failure */ - ret = FALSE; // LCOV_EXCL_LINE 8:Due to dead code + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "notify_name=%s ulEvtId=%x ucRid=%x ucCmdid=%x", + rcv_msg.notifyName, rcv_msg.ulEvtId, rcv_msg.ucRid, rcv_msg.ucCmdid); + + switch (rcv_msg.ucCmdid) { + case CAN_CMDID_VERSION_REQ_TX: + e_status = CANCommandVersionReq(h_app, rcv_msg.notifyName); + break; + case CAN_CMDID_FUELCALC_RST_REQ_DELIVERY: + e_status = CANCommandFuelcalcRstReq(h_app, rcv_msg.notifyName); + break; + default: + e_status = CANCommandOther(h_app, + rcv_msg.notifyName, rcv_msg.ucCmdid, rcv_msg.ucRid); + break; } + return e_status; +} - return (ret); +static CAN_TRANS_START_TABLE_VAL *CANTxMsgFindMap(CAN_TRANS_START_MSG_DAT *msg) { + std::map<CANID, CAN_TRANS_START_TABLE_VAL *>::iterator it; + it = g_map_trans_data.find(msg->id); + if (it == g_map_trans_data.end()) + return NULL; + return it->second; } -/******************************************************************************* - * MODULE : CANCanidUserToIfCvt - * ABSTRACT : CAN ID Conversion Process 2 - * FUNCTION : Convert CAN ID for USER to CAN ID for interfaces - * ARGUMENT : can_id : CAN ID - * *puc_buf : CAN ID Array Pointers (Data-Out) - * NOTE : - * RETURN : None - ******************************************************************************/ -void CANCanidUserToIfCvt(CANID can_id, uint8_t *puc_buf) { - int32_t i; /* Generic counters */ - uint8_t *puc; /* Generic pointer */ - uint32_t ul1; /* General Variables */ - uint32_t ul2; /* General Variables */ - uint32_t ul3; /* General Variables */ - - /* Concept of conversion - Input data format (32-bit data) - Bit assignment [31:29] [28:0] - CAN ID free [2:0] CAN ID [28:0] - Output 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] -*/ - ul1 = (uint32_t)can_id; /* Type conversion */ - ul2 = (ul1 << 20) & 0x7FF00000; /* Insert data of [10:0] */ - ul3 = (ul1 >> 11) & 0x0003FFFF; /* Populate [28:11] */ - ul2 |= ul3; /* Combine */ - /* Check of ext_flag */ - if (0 != ul3) { - ul2 |= CAN_ID_EXT_FLAG; /* Add Extended Flag */ - } else { - /* Do nothing */ - } - puc = puc_buf; /* Get array pointers */ - for (i = 0; i < 4; i++) { - ul3 = ul2 >> (uint32_t)((3 - i) * 8); - *puc = (uint8_t)ul3; /* Data storage */ - puc++; - } - return; +static CAN_TRANS_START_TABLE_VAL *CanSendFind(CAN_TRANS_START_MSG_DAT *msg) { + return CANTxMsgFindMap(msg); } -/******************************************************************************* - * MODULE : CANCommandDeliverySndMsg - * ABSTRACT : CAN command delivery message transmission processing - * FUNCTION : CAN command delivery (CAN thread-> user) - * ARGUMENT : uc_cmd_id : CAN command ID - * puc_data : Receive data reference pointer - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANCommandDeliverySndMsg(HANDLE h_app, uint8_t uc_cmd_id, const uint8_t *puc_data) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_MSG_CANCMD st_snd_msg; /* CAN Command Delivery Notification Message Structure */ - int32_t l_cnt = 0; /* Counter */ - uint32_t ul = 0; /* General Variables */ - // int32_t ret_api; /* Return Values of System API Functions */ - CAN_COMMAND_DELIVERY_LIST_DAT list; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - - /* Get Shipping ID List */ - (void)CANCommandDeliveryDataGet(uc_cmd_id, &list); - - /* Messaging */ - for (l_cnt = 0; l_cnt < (int32_t)list.notify_name_num; l_cnt++) { - /* Data size setting */ - switch (uc_cmd_id) { // LCOV_EXCL_BR_LINE 6:Excluded because the value is not currently passed - case CAN_CMDID_FUELCALC_RST_REQ_RX: - ul = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_FUELCALC_RST_SIZE; - break; - case CAN_CMDID_STARTUP_FIN_RESP_RX: - ul = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_STARTUP_FIN_SIZE; - break; - case CAN_CMDID_MRST_INFO_RESP_RX: - ul = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_MRST_INFO_SIZE; - break; - case CAN_CMDID_VERSION_RESP_RX: - ul = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_VERSION_SIZE; - break; - case CAN_CMDID_CONNECTION_NODE_RESP_RX: - ul = CAN_TX_CMD_DELIVERY_SIZE + (uint32_t)puc_data[0] + 1; - break; - default: - // LCOV_EXCL_START 6 Excluded because the value is not currently passed - AGL_ASSERT_NOT_TESTED(); - ul = (uint32_t)sizeof(st_snd_msg.data); - break; - // LCOV_EXCL_STOP6 Excluded because the value is not currently passed - } +EFrameworkunifiedStatus CANTxMsgBit(HANDLE h_app) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "@@@ Start communication CanSend(bit)"); - (void)memset(reinterpret_cast<void *>(&st_snd_msg), (int32_t)0, (size_t)sizeof(st_snd_msg)); - /* Message structure initialization */ - /****** Creation of header section ******/ -// st_snd_msg.hdr.hdr.rid = 0; /* Resource ID (not used) */ -// st_snd_msg.hdr.hdr.cid = (uint16_t)CID_CAN_CMD_DELIVERY; /* Command ID */ -// st_snd_msg.hdr.hdr.msgbodysize = (uint16_t)ul; /* Message data size */ - - /****** Creation of data section ******/ - st_snd_msg.data.cmd_id = uc_cmd_id; /* CAN command ID */ - memcpy(&st_snd_msg.data.data[0], puc_data, (ul - CAN_TX_CMD_DELIVERY_SIZE)); /* Received data */ - - /****** Messaging ******/ - if (g_map_handler.count(list.notify_name_list[l_cnt]) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, list.notify_name_list[l_cnt]); - if (h_client == NULL) { - ret = FALSE; - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender Error(notify_name=%s)", list.notify_name_list[l_cnt]); - break; - } - g_map_handler[list.notify_name_list[l_cnt]].handle = h_client; - g_map_handler[list.notify_name_list[l_cnt]].is_q_full = FALSE; - } else { - h_client = g_map_handler[list.notify_name_list[l_cnt]].handle; - } - e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CMD_DELIVERY, sizeof(st_snd_msg), &st_snd_msg); - if (e_status != eFrameworkunifiedStatusOK) { - CANCommandDeliveryDeletesingle(uc_cmd_id, list.notify_name_list[l_cnt]); - ret = FALSE; - FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(e_status=%d)", e_status); - break; - } + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + CAN_TRANS_START_MSG_DAT rcv_msg; + CanMessage snd_msg; + CAN_TRANS_START_TABLE_VAL *store; + int32_t i = 0; + uint8_t *store_p; + uint8_t *data_p; + uint8_t *mask_p; + + memset(&rcv_msg, 0, sizeof(rcv_msg)); + memset(&snd_msg, 0, sizeof(snd_msg)); + + e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg, sizeof(rcv_msg), eSMRRelease); + if (e_status != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedGetMsgDataOfSize Error(%d)", e_status); + if (e_status == eFrameworkunifiedStatusInvldBufSize) + FrameworkunifiedClearMsgData(h_app); + goto cleanup; } - return (ret); -} + e_status = eFrameworkunifiedStatusFail; -/******************************************************************************* - * MODULE : CANCommandTxRsltSndMsg - * ABSTRACT : CAN command transmission result notification message transmission processing - * FUNCTION : Send CAN command send result notification (CAN thread-> user) - * ARGUMENT : uc_can_rid : Resource ID from CAN - * uc_status : Transmission result status - * NOTE : - * RETURN : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANCommandTxRsltSndMsg(HANDLE h_app, uint8_t uc_can_rid, uint8_t uc_status) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_CMD_MSG_SENDSTS st_snd_msg; /* CAN command transmission result notification message structure */ - uint8_t uc_rid; /* Resources ID */ - uint8_t uc_cmd_id; /* CAN command ID */ - // int32_t ret_api; /* Return Values of System API Functions */ - char notify_name[MAX_NAME_SIZE_APP]; - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - - /* Data acquisition */ - CANCommandTxRsltDataGet(uc_can_rid, notify_name, &uc_rid, &uc_cmd_id); - - memset(reinterpret_cast<void *>(&st_snd_msg), (int32_t)0, (size_t)sizeof(st_snd_msg)); - /* Message structure initialization */ - /****** Creation of header section ******/ -// st_snd_msg.hdr.hdr.rid = uc_rid; /* Resources ID */ -// st_snd_msg.hdr.hdr.cid = (uint16_t)CID_CAN_CMD_TX_RESULT; /* Command ID */ -// st_snd_msg.hdr.hdr.msgbodysize = (size_t)sizeof(st_snd_msg.data); /* Message data size */ - - /****** Creation of data section ******/ - st_snd_msg.data.cmd_id = (uint32_t)uc_cmd_id; /* CAN command ID */ - st_snd_msg.data.status = uc_status; /* Transmission result status */ - - /****** Messaging ******/ - if (g_map_handler.count(notify_name) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, notify_name); - if (h_client == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - return (ret); // LCOV_EXCL_LINE 4: NSFW error case - } - g_map_handler[notify_name].handle = h_client; // LCOV_EXCL_BR_LINE 200: unexpect branch - g_map_handler[notify_name].is_q_full = FALSE; // LCOV_EXCL_BR_LINE 200: unexpect branch - } else { - h_client = g_map_handler[notify_name].handle; // LCOV_EXCL_BR_LINE 200: unexpect branch + if (TRUE != CommGetAvailabilityCurrent(CAN_AVAILABILITY)) { + CANTxMsgErrorLog("CAN is not ready", __func__, 0, 0, h_app); + goto cleanup; } - e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CMD_TX_RESULT, sizeof(st_snd_msg), &st_snd_msg); - if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - CANCommandTxRsltDelete(uc_can_rid); // LCOV_EXCL_LINE 4: NSFW error case - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - return (ret); // LCOV_EXCL_LINE 4: NSFW error case + + store = CanSendFind(&rcv_msg); + if (!store) { + CANTxMsgErrorLog("No initial value", __func__, + rcv_msg.id, sizeof(rcv_msg.dat), h_app); + goto cleanup; } - return (ret); -} -/******************************************************************************* - * MODULE : CANCommandTransmissionSndMsg - ******************************************************************************/ -/*!----------------------------------------------------------------------------- - * @~english - * @brief Transmission of CAN command - * - * @~english - * Transmission of CAN command (DISP Microcomputer -> SYS Microcomputer) - * - * @~english - * @note Details of process - * -# Creating of data division - * -# Message sending - * - * @~english - * @return Message transmission success/failure - * @retval <1> Message transmission success - * @retval <0> Message transmission failure - * - * @~english - * @param[in] <uc_opc> Operation code - * @param[in] <uc_can_rid> Resource ID - */ -BOOL CANCommandTransmissionSndMsg(uint8_t uc_opc, uint8_t uc_can_rid) { // LCOV_EXCL_START 8: dead code - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - BOOL ret = TRUE; /* Return value of this function */ -// T_ICR_CMD st_tx_can_data; /* Transmit data structure */ - -// (void)memset(reinterpret_cast<void *>(&st_tx_can_data), (int32_t)0, (size_t)sizeof(st_tx_can_data)); - /* Message structure initialization */ - /****** Creation of data section ******/ -// st_tx_can_data.cmd_data.phyadr_from = CAN_TX_PHYS_ADRS; /* Physical address */ -// st_tx_can_data.cmd_data.service_type = CAN_TX_COMM_KIND; /* Communication type 0x00: Individual */ -// st_tx_can_data.cmd_data.lgadr_from = CAN_TX_FROM_ADRS; /* Source Logical Address */ -// st_tx_can_data.cmd_data.lgadr_to = CAN_TX_TO_ADRS; /* Destination logical address */ -// st_tx_can_data.cmd_data.opc = uc_opc; /* Operation code */ -// st_tx_can_data.cmd_data.d_length = (uint16_t)CAN_CMDSND_DATA_SIZE; /* Data length (data section only) */ - - /****** Messaging ******/ - return (ret); -} -// LCOV_EXCL_STOP - -/******************************************************************************* - * MODULE : CANCommandFuelCalcRstReqSndMsg - * ABSTRACT : CAN section flame reset request reception message transmission processing - * FUNCTION : Send CAN interval flame reset request reception message (CAN thread-> user) - * ARGUMENT : notifyId : Message Destination ID - * NOTE : - * RETURN : TRUE : Message transmission success - * FALSE : Message transmission failure - ******************************************************************************/ -BOOL CANCommandFuelCalcRstReqSndMsg(HANDLE h_app, PCSTR notify_name) { - BOOL ret = TRUE; /* Return value of this function */ - CAN_MSG_CANCMD st_snd_msg; /* CAN Command Delivery Notification Message Structure */ - // int32_t ret_api = RET_NORMAL; /* Return Values of System API Functions */ - EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; - HANDLE h_client; - - (void)memset(reinterpret_cast<void *>(&st_snd_msg), (int32_t)0, (size_t)sizeof(st_snd_msg)); - /* Message structure initialization */ - /****** Creation of header section ******/ -// st_snd_msg.hdr.hdr.rid = 0; /* Resource ID (not used) */ -// st_snd_msg.hdr.hdr.cid = (uint16_t)CID_CAN_CMD_DELIVERY; /* Command ID */ -// st_snd_msg.hdr.hdr.msgbodysize = CAN_TX_CMD_DELIVERY_SIZE + CAN_TX_CMD_FUELCALC_RST_SIZE; /* Message data size */ - - /****** Creation of data section ******/ - st_snd_msg.data.cmd_id = CAN_CMDID_FUELCALC_RST_REQ_RX; /* CAN command ID */ - - if (g_map_handler.count(notify_name) == 0) { - h_client = FrameworkunifiedMcOpenSender(h_app, notify_name); - if (h_client == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - return (ret); // LCOV_EXCL_LINE 4: NSFW error case - } - g_map_handler[notify_name].handle = h_client; // LCOV_EXCL_BR_LINE 11:except,C++ STL - g_map_handler[notify_name].is_q_full = FALSE; // LCOV_EXCL_BR_LINE 11:except,C++ STL - } else { - h_client = g_map_handler[notify_name].handle; // LCOV_EXCL_BR_LINE 11:except,C++ STL + store_p = store->dat.dat; + data_p = rcv_msg.dat.dat; + mask_p = rcv_msg.mask.dat; + for (i = 0; i < store->dlc; i++) { + *store_p &= (uint8_t)(~(*mask_p)); + *store_p |= ((*mask_p) & (*data_p)); + ++store_p; + ++data_p; + ++mask_p; } - e_status = FrameworkunifiedSendMsg(h_client, CID_CAN_CMD_DELIVERY, sizeof(st_snd_msg), &st_snd_msg); - if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case - AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert - ret = FALSE; // LCOV_EXCL_LINE 4: NSFW error case - return (ret); // LCOV_EXCL_LINE 4: NSFW error case + + snd_msg.can_id = rcv_msg.id; + snd_msg.dlc = store->dlc; + snd_msg.rid = CAN_RID_NOTUSE_CODE; + memcpy(snd_msg.data, store->dat.dat, snd_msg.dlc); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, + "@@@ Call CanSend for can_hal : " + "can_id=%x dlc=%d rid=%x", snd_msg.can_id, snd_msg.dlc, snd_msg.rid); + FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s", + MessageDataOutputLog(snd_msg.data, snd_msg.dlc).c_str()); + + if (CANHAL_RET_NORMAL != CanSend(h_app, &snd_msg, CAN_HAL_TYPE_CAN)) { + CANTxMsgErrorLog("CAN CanSend failed", __func__, snd_msg.can_id, + (uint16_t)snd_msg.dlc, h_app); + goto cleanup; } - return (ret); + // echoback + e_status = CANDeliverySndMsg(h_app, snd_msg.can_id, 0, (uint8_t)snd_msg.dlc, + (const uint8_t *)snd_msg.data, + CID_CAN_DATA_DELIVERY, CANIF_ECHOBACK); +cleanup: + return e_status; } -/******************************************************************************* - * MODULE : CANCommandidOpcToUserCvt - * ABSTRACT : CAN Command ID Conversion Processing 1 - * FUNCTION : Convert the opcode to the corresponding CAN command ID - * ARGUMENT : uc_opc : Opcode - * puc_cmd_id : CAN command ID return pointer - * NOTE : - * RETURN : TRUE : Predefined opcodes - * FALSE : Undefined opcode - ******************************************************************************/ -BOOL CANCommandidOpcToUserCvt(uint8_t uc_opc, uint8_t *puc_cmd_id) { - BOOL ret = TRUE; /* Return value of this function */ - - switch (uc_opc) { - case CAN_OPC_COMMAND_STARTUP_FIN_RESP_RX: /* CAN startup completion notice received */ - *puc_cmd_id = CAN_CMDID_STARTUP_FIN_RESP_RX; - break; - case CAN_OPC_COMMAND_MRST_INFO_RESP_RX: /* CAN Master Reset Information Notification Reception */ - *puc_cmd_id = CAN_CMDID_MRST_INFO_RESP_RX; - break; - case CAN_OPC_COMMAND_VERSION_RESP_RX: /* CAN Version Response Reception */ - *puc_cmd_id = CAN_CMDID_VERSION_RESP_RX; - break; - case CAN_OPC_COMMAND_CONNECTION_NODE_RESP_RX: /* Receive CAN Connection Node Notification Response */ - *puc_cmd_id = CAN_CMDID_CONNECTION_NODE_RESP_RX; - break; - case CAN_OPC_COMMAND_FUELCALC_RST_REQ_RX: /* RECEIVE REQUEST FREE OF CAN SECTION */ - *puc_cmd_id = CAN_CMDID_FUELCALC_RST_REQ_RX; - break; - default: - ret = FALSE; /* Undefined opcode */ - break; +EFrameworkunifiedStatus CANTxMsg(HANDLE h_app) { + FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __func__, "@@@ Start communication CanSend"); + + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + CAN_TRANSMISSION_START_MSG_DAT rcv_msg; + CanMessage snd_msg; + memset(&rcv_msg, 0, sizeof(rcv_msg)); + memset(&snd_msg, 0, sizeof(snd_msg)); + + e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg, sizeof(rcv_msg), eSMRRelease); + if (e_status != eFrameworkunifiedStatusOK) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedGetMsgDataOfSize Error(%d)", e_status); + if (e_status == eFrameworkunifiedStatusInvldBufSize) + FrameworkunifiedClearMsgData(h_app); + goto cleanup; } - return (ret); -} + e_status = eFrameworkunifiedStatusFail; -/******************************************************************************* - * MODULE : CANCommandidUserToOpcCvt - * ABSTRACT : CAN command ID conversion process 2 - * FUNCTION : Convert the CAN command ID to the corresponding opcode - * ARGUMENT : uc_cmd_id : CAN command ID - * puc_opc : Opcode return pointer - * NOTE : - * RETURN : TRUE : Predefined ID - * FALSE : Undefined ID - ******************************************************************************/ -BOOL CANCommandidUserToOpcCvt(uint8_t uc_cmd_id, uint8_t *puc_opc) { - BOOL ret = TRUE; /* Return value of this function */ - - switch (uc_cmd_id) { - case CAN_CMDID_STARTUP_FIN_REQ_TX: /* CAN start completion notification request transmission */ - *puc_opc = CAN_OPC_COMMAND_STARTUP_FIN_REQ_TX; - break; - case CAN_CMDID_MRST_INFO_REQ_TX: /* CAN master reset information notification request transmission */ - *puc_opc = CAN_OPC_COMMAND_MRST_INFO_REQ_TX; - break; - case CAN_CMDID_VERSION_REQ_TX: /* CAN Version Request Send */ - *puc_opc = CAN_OPC_COMMAND_VERSION_REQ_TX; - break; - case CAN_CMDID_CONNECTION_NODE_REQ_TX: /* CAN connection node notification request transmission */ - *puc_opc = CAN_OPC_COMMAND_CONNECTION_NODE_REQ_TX; - break; - case CAN_CMDID_FUELCALC_REQ_TX: /* CAN section flame reset response transmission */ - *puc_opc = CAN_OPC_COMMAND_FUELCALC_REQ_TX; - break; - default: - ret = FALSE; /* Undefined ID */ - break; + if (TRUE != CommGetAvailabilityCurrent(CAN_AVAILABILITY)) { + CANTxMsgErrorLog("CAN is not ready", __func__, 0, 0, h_app); + goto cleanup; } - return (ret); + snd_msg.can_id = rcv_msg.stCandata.can_id; + snd_msg.dlc = rcv_msg.stCandata.dlc; + snd_msg.rid = rcv_msg.ucRid; + memcpy(snd_msg.data, rcv_msg.stCandata.data, snd_msg.dlc); + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "@@@ Call CanSend for can_hal : " + "can_id=%x dlc=%d rid=%x", snd_msg.can_id, snd_msg.dlc, snd_msg.rid); + FRAMEWORKUNIFIEDLOG(ZONE_DEBUG, __func__, "msg_data=%s", + MessageDataOutputLog(snd_msg.data, snd_msg.dlc).c_str()); + + if (CANHAL_RET_NORMAL != CanSend(h_app, &snd_msg, CAN_HAL_TYPE_CAN)) { + CANTxMsgErrorLog("CAN CanSend failed", __func__, snd_msg.can_id, + (uint16_t)snd_msg.dlc, h_app); + goto cleanup; + } + + // echoback + e_status = CANDeliverySndMsg(h_app, snd_msg.can_id, 0, (uint8_t)snd_msg.dlc, + (const uint8_t *)snd_msg.data, + CID_CAN_DATA_DELIVERY, CANIF_ECHOBACK); + if (rcv_msg.ucRid == (uint8_t)CAN_RID_NOTUSE_CODE) + goto cleanup; + + if (0 < g_m_send_sts.count(snd_msg.can_id)) { + if (g_m_send_sts[snd_msg.can_id].notify_name[0] != 0x00) { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, + "Not yet deliver SendSts but updated(SendID=%x, CAN ID=%x, Nane=%s)", + g_m_send_sts[snd_msg.can_id].rid, snd_msg.can_id, + g_m_send_sts[snd_msg.can_id].notify_name); + } + } + + g_m_send_sts[snd_msg.can_id].rid = rcv_msg.ucRid; + memcpy(g_m_send_sts[snd_msg.can_id].notify_name, + rcv_msg.notifyName, + sizeof(g_m_send_sts[snd_msg.can_id].notify_name)); +cleanup: + return e_status; } -/*!----------------------------------------------------------------------------- - * @~english - * @brief Transmission CAN Command - * - * @~english - * @return Return value - * @retval <TRUE> Transmission success - * @retval <FALSE> Transmission failed - * - * @~english - * @param[in] <id> CAN ID - * @param[in] <dlc> DLC - * @param[in] <pst_data> CAN Data structure - */ -BOOL CANTransStartTxMsgCore(HANDLE h_app, CANID id, uint8_t dlc, CAN_DATA_BIT *pst_data) { - BOOL b_ret = FALSE; -// CanMessage st_can_data; -// -// if (pst_data != NULL) { // LCOV_EXCL_BR_LINE 200: puc_data is a pointer of global variable -// st_can_data.can_id = id; -// st_can_data.rid = CAN_RID_NOTUSE_CODE; -// st_can_data.dlc = dlc; -// memcpy(st_can_data.data, pst_data->dat, dlc); - -// if (CanSend(&st_can_data, CAN_HAL_TYPE_CAN) != CANHAL_RET_NORMAL) { -// b_ret = FALSE; -// } else { -// b_ret = TRUE; -// } -// } - - return b_ret; -} // LCOV_EXCL_BR_LINE 10: end of line unknown branch +EFrameworkunifiedStatus CANSndStsProcess(HANDLE h_app, CanSendResult *rcv_msg, + PS_CommunicationProtocol cid) { + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; + CAN_MSG_SENDSTS snd_msg; + CANID can_id = rcv_msg->can_id; + HANDLE sender = NULL; + memset(&snd_msg, 0, sizeof(snd_msg)); + + if (0 == g_m_send_sts.count(can_id)) + goto cleanup; + + if (0x00 == (g_m_send_sts[can_id].notify_name[0])) + goto cleanup; + + if (rcv_msg->rid != g_m_send_sts[can_id].rid) + goto cleanup; + + snd_msg.hdr.hdr.cid = (uint16_t)cid; + snd_msg.hdr.hdr.msgbodysize = (uint16_t)(sizeof(snd_msg.data)); + snd_msg.hdr.hdr.rid = rcv_msg->rid; + snd_msg.data.ulCanid = can_id; + snd_msg.data.ucStatus = + (CAN_SEND_RESULT_SUCCESS == rcv_msg->result) ? CAN_SUCCESS : CAN_RETRYOUT; + + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "cid=%x msgbodysize=%d rid=%x can_id=%x ucStatus=%x", + snd_msg.hdr.hdr.cid, snd_msg.hdr.hdr.msgbodysize, snd_msg.hdr.hdr.rid, + snd_msg.data.ulCanid, snd_msg.data.ucStatus); + + sender = CommonFindSender(h_app, g_m_send_sts[can_id].notify_name); + if (!sender) { + CANTxMsgErrorLog("Could not open sender.", __func__, can_id, + sizeof(snd_msg), h_app); + goto cleanup; + } + + e_status = FrameworkunifiedSendMsg(sender, cid, sizeof(snd_msg), &snd_msg); + if (eFrameworkunifiedStatusOK != e_status) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSendMsg Error(e_status:%d to:%s)", + e_status, g_m_send_sts[can_id].notify_name); + g_m_send_sts[can_id].notify_name[0] = 0x00; + g_m_send_sts[can_id].rid = 0x00; + goto cleanup; + } + g_m_send_sts[can_id].notify_name[0] = 0x00; + g_m_send_sts[can_id].rid = 0x00; + + e_status = eFrameworkunifiedStatusOK; +cleanup: + return e_status; +} |