diff options
Diffstat (limited to 'communication/server/src/CAN/CommWatch')
-rw-r--r-- | communication/server/src/CAN/CommWatch/CAN_CommWatch.cpp | 268 | ||||
-rw-r--r-- | communication/server/src/CAN/CommWatch/CAN_CommWatchData.cpp | 447 |
2 files changed, 715 insertions, 0 deletions
diff --git a/communication/server/src/CAN/CommWatch/CAN_CommWatch.cpp b/communication/server/src/CAN/CommWatch/CAN_CommWatch.cpp new file mode 100644 index 00000000..abb727bd --- /dev/null +++ b/communication/server/src/CAN/CommWatch/CAN_CommWatch.cpp @@ -0,0 +1,268 @@ +/* + * @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_CommWatch.cpp + * SYSTEM :_CWORD107_ + * SUBSYSTEM :EXL process + * PROGRAM :CAN Thread CAN Data Communication Disruption Monitoring Management Process + * Module configuration :CANCommWatchTimeoutMsg() CANDataCommunication Disruption Timeout Message Processing + * :CAN_CommWatch() CANDataCommunication Disruption Monitoring Message Processing + * :CANCommWatchClear() CANDataCommunication interruption clear processing + * :CANVehicleInfoMsg() Vehicle sensor information notification message processing + * :CANIgStatGet() IG reception status acquisition processing + ******************************************************************************/ +#include "CAN_CommWatch.h" + +#include <native_service/frameworkunified_types.h> // NOLINT (build/include) +#include <native_service/frameworkunified_framework_if.h> + +#include <peripheral_service/Canif_API.h> +#include "CAN_Thread.h" +#include "CAN_CommWatchData.h" +#include "CAN_TxMsg.h" +#include "CAN_TimerCtrl.h" + +/*************************************************/ +/* Global variable */ +/*************************************************/ + +static uint8_t g_uc_comm_watch_ig_stat; /* IG receive mode */ + +/******************************************************************************* + * MODULE : CANCommWatchInit + * ABSTRACT : CANDataCommunication Disruption Monitoring Initialization Process + * FUNCTION : CANDataInitialize communication interruption monitoring + * ARGUMENT : void + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchInit(void) { + g_uc_comm_watch_ig_stat = CAN_COMM_IG_NORCV; /* Initialization of IG reception status */ +} + +/******************************************************************************* + * MODULE : CANCommWatchTimeoutMsg + * ABSTRACT : CANDataCommunication Disruption Timeout Message Processing + * FUNCTION : Send communication interruption message when communication interruption of monitored CAN data is detected. + * ARGUMENT : us_timer_seq_no : Timer sequence number that timed out + * NOTE : + * RETURN : RET_CAN_NORMAL :Normal completion + * : RET_CAN_ERROR_CANCEL :Data destruction + ******************************************************************************/ +RET_CAN CANCommWatchTimeoutMsg(HANDLE h_app, uint16_t us_timer_seq_no) { + RET_CAN ret = RET_CAN_ERROR_CANCEL; /* Return value of this function */ + uint8_t uc_index; /* Index of the corresponding timer sequence number */ + uint8_t uc_comm_stop; /* Communication status of the corresponding timer sequence number */ + + /* Determine whether communication interruption monitoring of the corresponding sequence number is registered. */ + /* Timer Sequence Number Search*/ + if (TRUE == CANCommWatchTimerSeqNoEntryCheck(us_timer_seq_no, &uc_index, &uc_comm_stop, CAN_PROTOCOL_TYPE_CAN)) { + /* Determining whether communication is in progress */ + if ((uint8_t)CAN_COMM_NORMAL == uc_comm_stop) { + /* Change the communication status to "Communication interrupted" */ + (void)CANCommWatchCtrl(uc_index, CAN_COMM_STOP, CAN_PROTOCOL_TYPE_CAN); /* Communication interruption state control processing */ + + /* Send Communication Disruption Detection Message */ + (void)CANCommWatchSndMsg(h_app, uc_index); /* Transmission of communication interruption detection/recovery message */ + + ret = RET_CAN_NORMAL; + } + } + + return (ret); +} + +/******************************************************************************* + * MODULE : CANCommWatch + * ABSTRACT : CANDataCommunication Disruption Monitoring Message Processing + * FUNCTION : CANDataRegister/delete communication disruption monitoring management table + * ARGUMENT : pst_rcv_msg :Received Message Reference Pointer + * NOTE : + * RETURN : RET_CAN_NORMAL :Normal completion + * : RET_CAN_ERROR_SNDID :Distribution destination ID mismatch + * : RET_CAN_ERROR_UNDEF :Unregistered ID + * : RET_CAN_ERROR_TIMER :Timer acquisition failed + * : RET_CAN_ERROR_BUFFULL :Communication Disruption Monitoring Registered Number FULL + ******************************************************************************/ +EFrameworkunifiedStatus CANCommWatch(HANDLE h_app) { + return CANCommWatchCore(h_app, CAN_PROTOCOL_TYPE_CAN); +} + +EFrameworkunifiedStatus CANCommWatchCore(HANDLE h_app, CAN_PROTOCOL_TYPE mode) { + RET_CAN ret = RET_CAN_NORMAL; /* Return value of this function */ + uint8_t uc_cnt; /* Generic counters */ + uint8_t uc_index; /* Indexed */ + uint8_t uc_comm_stop = CAN_COMM_OFF; /* Communication status */ + BOOL b_id_flag = FALSE; /* Variables for Stopping Monitoring */ /* ID match flag */ + BOOL b_snd_id_flag = FALSE; /* Variables for Stopping Monitoring */ /* Destination ID match flag */ + uint16_t us_timer_seq_no; /* Variables for Starting Monitoring */ /* Acquisition Timer Sequence Number */ + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; + CAN_COMM_WATCHEXT_MSG_DAT rcv_msg; + + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "##### CAN COMMWATCH START #####"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + + e_status = FrameworkunifiedGetMsgDataOfSize(h_app, &rcv_msg, sizeof(rcv_msg), eSMRRelease); + if (e_status != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case. + // LCOV_EXCL_START 4: NSFW error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# FrameworkunifiedGetMsgDataOfSize Error"); + if (e_status == eFrameworkunifiedStatusInvldBufSize) { + FrameworkunifiedClearMsgData(h_app); + } + ret = RET_CAN_ERROR_CANCEL; + goto exit; + } + // LCOV_EXCL_STOP 4: NSFW error case. + + /* Monitor Registration/Suspension Determination */ + if ((uint16_t)0 == rcv_msg.usWatchTime) { /* Is the communication interruption time zero? */ + /*** Suspend Monitoring(Communication interruption time = 0) ***/ + + /* Is the delivery destination ID and CANID, DID registered in the disruption monitoring table? */ + for (uc_cnt = 0; uc_cnt < (uint8_t)COMM_WATCH_LIST_NUM; uc_cnt++) { + /* Are data with matching CANID and data IDs registered? ? */ + if (FALSE == CANCommWatchCanidDidEntryCheck(uc_cnt, rcv_msg.ulCanid, rcv_msg.ulDid, mode)) { + continue; + } + b_id_flag = TRUE; /* Set the ID match flag */ + + /* Does the shipping ID match? */ + if (FALSE == CANCommWatchSndCheck(uc_cnt, rcv_msg.notifyName, mode)) { + continue; + } + b_snd_id_flag = TRUE; /* Set the delivery destination ID match flag */ + uc_index = uc_cnt; /* Store the index subject to monitoring termination. */ + break; + } + + if (TRUE != b_id_flag) { /* No matching data */ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN CommWatchStop CanID Error"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + ret = RET_CAN_ERROR_UNDEF; /* Undefined ID error */ + goto exit; + } + if (TRUE != b_snd_id_flag) { /* Distribution destination ID mismatch */ + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN CommWatchStop SNDID Error"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + ret = RET_CAN_ERROR_SNDID; /* Distribution destination ID mismatch */ + goto exit; + } + + /* Suspend Monitoring */ + /* Communication interruption timer stop processing */ + if (RET_CAN_NORMAL == CANCommWatchTimerStop(uc_index, mode)) { // LCOV_EXCL_BR_LINE 200:the function is always returned to RET_CAN_NORMAL //NOLINT (readability/naming) + /* Successful stop -> delete from communication disconnection monitoring management table */ + CANCommWatchDelete(uc_index, mode); + } + + } else { + /* Storage status can be checked? */ + /* No free space */ + if (TRUE != CANCommWatchEntryCheck(rcv_msg.ulCanid, rcv_msg.ulDid, rcv_msg.notifyName, &uc_index, mode)) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "#CAN_thread# CAN CommWatch BufferFull"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + ret = RET_CAN_ERROR_BUFFULL; + goto exit; + } + + /* Timer stop */ + (void)CANCommWatchTimerStop(uc_index, mode); + + /* IG linkage OFF or IG linkage ON and IG reception in progress */ + if ((rcv_msg.ucIg == (uint8_t)CAN_IG_COOPERATION_OFF) || ((rcv_msg.ucIg == (uint8_t)CAN_IG_COOPERATION_ON) && (g_uc_comm_watch_ig_stat == (uint8_t)CAN_COMM_IG_ON))) { // LCOV_EXCL_BR_LINE 200: rcv_msg.ucIg is always be CAN_IG_COOPERATION_OFF //NOLINT (readability/naming) + /* Timer activation */ + /* Communication interruption monitoring timer start processing */ + if (RET_CAN_NORMAL != CANCommWatchTimerStart(uc_index, rcv_msg.usWatchTime, mode)) { // LCOV_EXCL_BR_LINE 200:the function is always returned to RET_CAN_NORMAL //NOLINT (readability/naming) + // LCOV_EXCL_START 200: the function is always returned to RET_CAN_NORMAL + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + ret = RET_CAN_ERROR_TIMER; /* Timer start failure -> Return value setting: Timer acquisition error */ + goto exit; + } // LCOV_EXCL_STOP 200: the function is always returned to RET_CAN_NORMAL + /* Communication type = set during communication */ + uc_comm_stop = CAN_COMM_NORMAL; + } + + /* Timer sequence number acquisition */ + us_timer_seq_no = CANCommWatchTimerSeqNoGet(uc_index, mode); + /* CANDataCommunication Disruption Monitoring Management Table Registration Process */ + CANCommWatchEntry(uc_index, &rcv_msg, us_timer_seq_no, uc_comm_stop, mode); + } + +exit: + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "END(ret=%x)", ret); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + if (ret == RET_CAN_NORMAL) + return eFrameworkunifiedStatusOK; + else + return eFrameworkunifiedStatusFail; + // return RET_CAN_NORMAL; +} + +/******************************************************************************* + * MODULE : CANCommWatchClear + * ABSTRACT : CANDataCommunication interruption clear processing + * FUNCTION : Sends a communication recovery message and restarts the timer. + * ARGUMENT : can_id :Received CAN ID + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchClear(HANDLE h_app, CANID can_id) { + uint8_t uc_cnt; /* Counter */ + uint8_t uc_comm_stop; /* Communication status */ + BOOL ret; + uint16_t us_tbl_chk_cnt = 0; /* Number of effective data checks for communication disruption table */ + + /* Corresponding CAN ID retrieval in communication interruption monitoring control table */ + for (uc_cnt = 0; uc_cnt < (uint8_t)COMM_WATCH_LIST_NUM; uc_cnt++) { + ret = CANCommWatchCanidEntryCheck(uc_cnt, can_id, &uc_comm_stop, &us_tbl_chk_cnt, CAN_PROTOCOL_TYPE_CAN); + /* CAN ID matching ? */ + if (TRUE == ret) { + /* Is communication interrupted? */ + if ((uint8_t)CAN_COMM_STOP == uc_comm_stop) { + /* Change the communication state to "Communicating" */ + (void)CANCommWatchCtrl(uc_cnt, CAN_COMM_NORMAL, CAN_PROTOCOL_TYPE_CAN); /* Communication interruption state control processing */ + uc_comm_stop = CAN_COMM_NORMAL; + /* Send communication disruption recovery message */ + (void)CANCommWatchSndMsg(h_app, uc_cnt); /* Transmission of communication interruption detection/recovery message */ + } + + /* Timer restart only when communication status is in progress */ + if (uc_comm_stop == (uint8_t)CAN_COMM_NORMAL) { + /* Timer restart */ + (void)CANCommWatchTimerRenewal(uc_cnt, CAN_PROTOCOL_TYPE_CAN); /* Communication interruption monitoring timer update processing */ + } + } + /* Check for completion of retrieval of all valid table data */ + if (us_tbl_chk_cnt >= g_us_comm_watch_dat_cnt[CAN_PROTOCOL_TYPE_CAN]) { + /* Completion of retrieval of all valid data for the table */ + break; + } + } + + return; +} + +/******************************************************************************* + * MODULE : CANIgStatGet + * ABSTRACT : IG reception status acquisition processing + * FUNCTION : Obtain IG reception information + * ARGUMENT : void + * NOTE : + * RETURN : IG Information Received + ******************************************************************************/ + +uint8_t CANIgStatGet(void) { // LCOV_EXCL_START 8: for dead code + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + return (g_uc_comm_watch_ig_stat); +} +// LCOV_EXCL_STOP diff --git a/communication/server/src/CAN/CommWatch/CAN_CommWatchData.cpp b/communication/server/src/CAN/CommWatch/CAN_CommWatchData.cpp new file mode 100644 index 00000000..8b5a4681 --- /dev/null +++ b/communication/server/src/CAN/CommWatch/CAN_CommWatchData.cpp @@ -0,0 +1,447 @@ +/* + * @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_CommWatchData.cpp + * SYSTEM :_CWORD107_ + * SUBSYSTEM :EXL process + * PROGRAM :CAN thread CAN data communication interruption monitoring data management + * Module configuration :Can_CommWatchData_Init() CAN Data Communication Disruption Monitoring Management Data Initialization Process + * :CANCommWatchCanidDidEntryCheck() CANDataCommunication Disruption Monitoring Control Table Registration Status Checking Process (CAN ID and DataID Retrieval) + * :CANCommWatchTimerSeqNoEntryCheck() CANDataCommunication Disruption Monitoring Management Table Registration Status Checking Process (Timer Sequence Number Search) + * :CANCommWatchEntryCheck() CANDataCommunication Disruption Monitoring Management Table Registration Destination Confirmation Process + * :CANCommWatchEntry() CANDataCommunication Disruption Monitoring Management Table Registration Process + * :CANCommWatchDelete() CANDataCommunication Disruption Monitoring Management Table Deletion Processing + * :CANCommWatchCtrl() Communication interruption state control processing + * :CANCommWatchDataGet() Communication interruption data acquisition process + * :CANCommWatchTimerSeqNoGet() Acquisition of Communication Disruption Monitor Timer Sequence Number + * :CANCommWatchTimerSeqNoRenwal() Communication interruption monitoring timer sequence number update processing + * :CANCommWatchSndCheck() CANDataCommunication Disruption Monitoring Management Table Delivery Destination ID Confirmation Process + * :CANCommWatchIgcoopGet() IG linkage information acquisition processing of the communication disruption monitoring management table + ******************************************************************************/ +#include "CAN_CommWatchData.h" + +#include <string.h> // NOLINT (build/include) +#include <native_service/frameworkunified_types.h> +#include <other_service/strlcpy.h> + +#include <peripheral_service/Canif_API.h> +#include "CAN_Thread.h" + +/*************************************************/ +/* Global variables */ +/*************************************************/ +/* Timer sequence number increment counter */ +static uint16_t g_us_comm_watch_timer_seq_no = COMM_WATICH_TIMER_SEQ_NO_MIN; +CAN_COMM_WATCH_DAT g_st_comm_watch_dat[CAN_PROTOCOL_TYPE_TERMINATE][COMM_WATCH_LIST_NUM]; /* Communication disruption monitoring management table */ +uint16_t g_us_comm_watch_dat_cnt[CAN_PROTOCOL_TYPE_TERMINATE]; /* Number of effective registrations of communication disruption monitoring management table */ + +/******************************************************************************* + * MODULE : CANCommWatchDataInit + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Data Initialization Process + * FUNCTION : CANDataInitializing management data for communication disruption monitoring + * ARGUMENT : void + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchDataInit(void) { + for (int i = 0; i < CAN_PROTOCOL_TYPE_TERMINATE; i++) { + /* Communication disruption monitoring management table */ + memset(g_st_comm_watch_dat[i], 0x00, sizeof(CAN_COMM_WATCH_DAT) * COMM_WATCH_LIST_NUM); + g_us_comm_watch_dat_cnt[i] = 0; /* Number of effective registrations of communication disruption monitoring management table */ + } + return; +} + +/******************************************************************************* + * MODULE : CAN_CommWatchCanidDidIDEntryCheck + * ABSTRACT : CANDataCommunication Disruption Monitoring Control Table Registration Status Checking Process (CAN ID and DataID Retrieval) + * FUNCTION : Compares the specified indexes of the communication interruption monitoring control table with the CAN ID and data IDs. + * ARGUMENT : uc_index :Indexed + * can_id :CAN ID + * ul_did :Data ID + * NOTE : + * RETURN : TRUE :Data consistency + * FALSE :Data mismatch + ******************************************************************************/ +BOOL CANCommWatchCanidDidEntryCheck(uint8_t uc_index, CANID can_id, DID ul_did, CAN_PROTOCOL_TYPE mode) { + BOOL ret = FALSE; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Is the specified index monitoring interrupted? */ + if ((uint16_t)0 != ptr->us_watch_time) { + /* The CANID and data identifier of the named index data matches the arguments? */ + if (can_id == ptr->ul_can_id) { + if (ul_did == ptr->ul_did) { + ret = TRUE; + } + } + } + + return (ret); +} + +/******************************************************************************* + * MODULE : CANCommWatchTimerSeqNoEntryCheck + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Table Registration Status Checking Process (Timer Sequence Number Search) + * FUNCTION : Returns the index of the communication interruption monitoring management table with the specified timer sequence number + * ARGUMENT : us_timer_seq_no :Search timer sequence number + * puc_index :Index return pointer + * puc_comm_stop :Communication status return pointer + * NOTE : + * RETURN : TRUE :Registered + * FALSE :No registration + ******************************************************************************/ +BOOL CANCommWatchTimerSeqNoEntryCheck(uint16_t us_timer_seq_no, uint8_t *puc_index, + uint8_t *puc_comm_stop, CAN_PROTOCOL_TYPE mode) { + uint32_t ul_cnt; + BOOL ret = FALSE; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][0]; + + /* Timer Sequence Number Search */ + for (ul_cnt = 0; ul_cnt < COMM_WATCH_LIST_NUM; ul_cnt++) { + /* Is monitoring interrupted? */ + if ((uint16_t)0 != ptr[ul_cnt].us_watch_time) { + /* Match Timer Sequence Number */ + if (us_timer_seq_no == ptr[ul_cnt].us_timer_seq_no) { + ret = TRUE; + *puc_index = (uint8_t)ul_cnt; + *puc_comm_stop = ptr[ul_cnt].uc_comm_stop; + + break; + } + } + } + + return (ret); +} + +/******************************************************************************* + * MODULE : CANCommWatchEntryCheck + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Table Registration Destination Confirmation Process + * FUNCTION : Returns the registerable index in the communication disconnection monitoring management table + * ARGUMENT : can_id :CAN ID + * ul_did :Data ID + * notifyId :Addresses for delivery ID + * puc_index :Index return pointer + * NOTE : + * RETURN : TRUE :Can be registered + * FALSE :Unable to register + ******************************************************************************/ +BOOL CANCommWatchEntryCheck(CANID can_id, DID ul_did, PCSTR notify_name, uint8_t *puc_index, CAN_PROTOCOL_TYPE mode) { + uint32_t ul_cnt; + BOOL ret = FALSE; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][0]; + + /* Search duplicate data */ + for (ul_cnt = 0; ul_cnt < COMM_WATCH_LIST_NUM; ul_cnt++) { + /* CANID, DataID, Shipping ID Matching? */ + if ((can_id == ptr[ul_cnt].ul_can_id) && + (ul_did == ptr[ul_cnt].ul_did) && + (strcmp(notify_name, ptr[ul_cnt].notify_name) == 0)) { + ret = TRUE; + *puc_index = (uint8_t)ul_cnt; + + break; + } + } + if (FALSE == ret) { + /* Search for free table */ + for (ul_cnt = 0; ul_cnt < COMM_WATCH_LIST_NUM; ul_cnt++) { + /* Free (communication interruption time = 0)? */ + if ((uint16_t)0 == ptr[ul_cnt].us_watch_time) { + ret = TRUE; + *puc_index = (uint8_t)ul_cnt; + break; + } + } + } + + return (ret); +} + +/******************************************************************************* + * MODULE : CANCommWatchEntry + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Table Registration Process + * FUNCTION : Register data in the communication interruption monitoring management table + * ARGUMENT : uc_index :Index of registration destination + * ul_did :Data to register ID + * notifyId :Process ID to register + * ulCanid :CAN ID to register + * usWatchTime :Communication interruption time to register + * ucIg :IG linkage flag to be registered + * us_timer_seq_no :Timer sequence number to register + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchEntry(uint8_t uc_index, const CAN_COMM_WATCHEXT_MSG_DAT *pst_msg_data, + uint16_t us_timer_seq_no, uint8_t uc_comm_stop, CAN_PROTOCOL_TYPE mode) { + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Confirm whether overwriting or addition of communication disruption monitoring management table */ + if ((uint16_t)0 == ptr->us_watch_time) { + /* In case of additional registration, update the number of registered data */ + g_us_comm_watch_dat_cnt[mode]++; + } + /* Register new monitoring data in communication interruption monitoring management table */ + strlcpy(ptr->notify_name, pst_msg_data->notifyName, sizeof(ptr->notify_name)); /* Store Destination Thread Name */ + ptr->ul_did = pst_msg_data->ulDid; /* Data ID storage */ + ptr->ul_can_id = pst_msg_data->ulCanid; /* CAN ID storage */ + ptr->us_watch_time = pst_msg_data->usWatchTime; /* Communication interruption time storage */ + ptr->uc_comm_stop = uc_comm_stop; /* Communication state storage */ + ptr->uc_ig = pst_msg_data->ucIg; /* IG linkage information storage */ + ptr->us_timer_seq_no = us_timer_seq_no; /* Store timer sequence number */ + /* Log output */ + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, + "##### COMMWaitTable [Index:0x%04x, SndId:0x%s, Did:0x%08x, CanID:0x%08x, Tim:0x%04x, Comm:0x%04x, IG:0x%04x, TimSeq:0x%04x] ##### ", // NOLINT (whitespace/line_length) + uc_index, ptr->notify_name, ptr->ul_did, ptr->ul_can_id, + ptr->us_watch_time, ptr->uc_comm_stop, ptr->uc_ig, ptr->us_timer_seq_no); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + return; +} + +/******************************************************************************* + * MODULE : CANCommWatchDelete + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Table Deletion Processing + * FUNCTION : Delete the data in the communication disconnection monitoring management table. + * ARGUMENT : uc_index :Destination index + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchDelete(uint8_t uc_index, CAN_PROTOCOL_TYPE mode) { + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* To 0 all members of the data for the specified index */ + memset(ptr->notify_name, 0x00, sizeof(ptr->notify_name)); /* Initialization of delivery destination thread name */ + ptr->ul_did = 0; /* Data ID initialization */ + ptr->ul_can_id = 0; /* CAN ID initialization */ + ptr->us_watch_time = 0; /* Communication interruption time initialization */ + ptr->uc_comm_stop = 0; /* Communication status initialization */ + ptr->uc_ig = 0; /* Initialization of IG linkage information */ + ptr->us_timer_seq_no = 0; /* Initialization of timer sequence number */ + + if ((uint16_t)0 != g_us_comm_watch_dat_cnt[mode]) { + g_us_comm_watch_dat_cnt[mode]--; /* Updating the number of registered data */ + } + /* Log output */ + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, "##### COMMWaitTableDel [Index:0x%04x] #####", uc_index); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + + return; +} + +/******************************************************************************* + * MODULE : CANCommWatchCtrl + * ABSTRACT : Communication interruption state control processing + * FUNCTION : Setting communication interruption status + * ARGUMENT : uc_index :Index to set + * uc_comm_stop :Communication status to be set + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchCtrl(uint8_t uc_index, uint8_t uc_comm_stop, CAN_PROTOCOL_TYPE mode) { + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Change communication status */ + ptr->uc_comm_stop = uc_comm_stop; + /* Log output */ + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, + "##### COMMWaitTable [Index:0x%04x, SndId:0x%s, Did:0x%08x, CanID:0x%08x, Tim:0x%04x, Comm:0x%04x, IG:0x%04x, TimSeq:0x%04x] #####", // NOLINT (whitespace/line_length) + uc_index, ptr->notify_name, ptr->ul_did, ptr->ul_can_id, + ptr->us_watch_time, ptr->uc_comm_stop, ptr->uc_ig, ptr->us_timer_seq_no); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + return; +} + +/******************************************************************************* + * MODULE : CANCommWatchDataGet + * ABSTRACT : Communication interruption data acquisition process + * FUNCTION : Returns the disconnected data for the specified index + * ARGUMENT : uc_index :Indexed + * pNotifyId :Destination ID Return Pointer + * pul_did :Data ID return pointer + * puc_comm_stop :Communication status return pointer + * NOTE : + * RETURN : void + ******************************************************************************/ +void CANCommWatchDataGet(uint8_t uc_index, char *p_notify_name, DID *pul_did, + uint8_t *puc_comm_stop, CAN_PROTOCOL_TYPE mode) { + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + snprintf(p_notify_name, strlen(ptr->notify_name) + 1, "%s", ptr->notify_name); + *pul_did = ptr->ul_did; /* Data ID */ + *puc_comm_stop = ptr->uc_comm_stop; /* Communication status */ + + return; +} + +/******************************************************************************* + * MODULE : CANCommWatchTimerSeqNoGet + * ABSTRACT : Acquisition of Communication Disruption Monitor Timer Sequence Number + * FUNCTION : Returns the timer sequence number at the specified index + * ARGUMENT : uc_index :Indexed + * NOTE : + * RETURN : Timer Sequence Number + ******************************************************************************/ +uint16_t CANCommWatchTimerSeqNoGet(uint8_t uc_index, CAN_PROTOCOL_TYPE mode) { + uint16_t us_timer_seq_no; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Timer sequence number of the target index */ + us_timer_seq_no = ptr->us_timer_seq_no; + + return (us_timer_seq_no); +} + +/******************************************************************************* + * MODULE : CANCommWatchTimerSeqNoRenwal + * ABSTRACT : Communication interruption monitoring timer sequence number update processing + * FUNCTION : Updates the timer sequence number at the specified index + * ARGUMENT : uc_index :Indexed + * pus_watch_time :Communication interruption time return pointer + * NOTE : + * RETURN : Timer Sequence Number + ******************************************************************************/ +uint16_t CANCommWatchTimerSeqNoRenwal(uint8_t uc_index, uint16_t *pus_watch_time, CAN_PROTOCOL_TYPE mode) { + uint16_t us_timer_seq_no; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Updating the timer sequence number of the target index */ + ptr->us_timer_seq_no = g_us_comm_watch_timer_seq_no; + + /* Timer sequence number increment counter + 1 */ + g_us_comm_watch_timer_seq_no++; + + /* Check whether it is within the range of the sequence number used for communication interruption monitoring */ + if (g_us_comm_watch_timer_seq_no > (uint16_t)COMM_WATICH_TIMER_SEQ_NO_MAX) { + g_us_comm_watch_timer_seq_no = COMM_WATICH_TIMER_SEQ_NO_MIN; + } + + /* Return value setting */ + us_timer_seq_no = ptr->us_timer_seq_no; + *pus_watch_time = ptr->us_watch_time; + /* Log output */ + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + FRAMEWORKUNIFIEDLOG(ZONE_CAN_DEBUG, __func__, + "##### COMMWaitTable [Index:0x%04x, SndId:0x%s, Did:0x%08x, CanID:0x%08x, Tim:0x%04x, Comm:0x%04x, IG:0x%04x, TimSeq:0x%04x] #####", // NOLINT (whitespace/line_length) + uc_index, ptr->notify_name, ptr->ul_did, ptr->ul_can_id, + ptr->us_watch_time, ptr->uc_comm_stop, ptr->uc_ig, ptr->us_timer_seq_no); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" //NOLINT (readability/naming) + return (us_timer_seq_no); +} + +/******************************************************************************* + * MODULE : CANCommWatchSndCheck + * ABSTRACT : CANDataCommunication Disruption Monitoring Management Table Delivery Destination ID Confirmation Process + * FUNCTION : Compare the specified index of the communication interruption monitoring management table with the delivery destination ID. + * ARGUMENT : uc_index :Indexed + * notifyId :Addresses for delivery ID + * NOTE : + * RETURN : TRUE :Data consistency + * FALSE :Data mismatch + ******************************************************************************/ +BOOL CANCommWatchSndCheck(uint8_t uc_index, PCSTR notify_name, CAN_PROTOCOL_TYPE mode) { + BOOL ret = FALSE; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* Destination ID of specified index data matches argument? */ + if (strcmp(notify_name, ptr->notify_name) == 0) { + ret = TRUE; + } + return (ret); +} + +/******************************************************************************* + * MODULE : CANCommWatchIgcoopGet + * ABSTRACT : IG linkage information acquisition processing of the communication disruption monitoring management table + * FUNCTION : Returns the IG linkage value of the specified index + * ARGUMENT : uc_index :Indexed + * NOTE : + * RETURN : CAN_IG_COOPERATION_OFF :IG no collaboration + * CAN_IG_COOPERATION_ON :IG Has collaborations + ******************************************************************************/ + +uint8_t CANCommWatchIgcoopGet(uint8_t uc_index, CAN_PROTOCOL_TYPE mode) { // LCOV_EXCL_START 8:the function is not used + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + uint8_t uc_ig_cooperation; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][uc_index]; + + /* IG linkage value of the target index */ + uc_ig_cooperation = ptr->uc_ig; + + return (uc_ig_cooperation); +} +// LCOV_EXCL_STOP + +/******************************************************************************* + * MODULE : CANCommWatchBufferOut + * ABSTRACT : CAN communication interruption table log output processing + * FUNCTION : Output CAN communication disruption table log + * ARGUMENT : FILE *fp_log : File pointer of the log output file + * NOTE : + * RETURN : + ******************************************************************************/ + +void CANCommWatchBufferOut(FILE *fp_log, CAN_PROTOCOL_TYPE mode) { // LCOV_EXCL_START 8:the function is not used + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + int32_t usage_rate; + uint16_t i; + uint16_t data_cnt = 0; + CAN_COMM_WATCH_DAT *ptr = &g_st_comm_watch_dat[mode][0]; + + if (NULL != fp_log) { + /* Output of communication disruption management table */ + (void)fprintf(fp_log, "CAN CommWatch Buffer \n"); + (void)fprintf(fp_log, "CanID: SNDID: DID: Time: State: IG_mode: TimeSeq:\n"); + for (i = 0; i < (uint16_t)COMM_WATCH_LIST_NUM; i++) { + /* Free (communication interruption time = 0)? */ + if ((uint16_t)0 != ptr[i].us_watch_time) { + (void)fprintf(fp_log, "%08x %s %08x %04x %04x %04x %04x\n", + ptr[i].ul_can_id, + ptr[i].notify_name, + ptr[i].ul_did, + ptr[i].us_watch_time, + ptr[i].uc_comm_stop, + ptr[i].uc_ig, + ptr[i].us_timer_seq_no); + data_cnt++; + } + } + usage_rate = (((int32_t)data_cnt * 100) / COMM_WATCH_LIST_NUM); + (void)fprintf(fp_log, "BUFFER_Use: %04d BUFFER_Max: %04d Usage_Rate: %04d \n", + data_cnt, COMM_WATCH_LIST_NUM, usage_rate); + if (usage_rate >= CAN_USAGE_RATE_THRESHOLD) { + (void)fprintf(fp_log, "Warning: Buffer utilization exceeds a threshold.\n"); + } + } +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START 7: debug code +EFrameworkunifiedStatus CANCommWatchAllClearDebug(HANDLE h_app) { + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + if (access("/tmp/communication_debug", F_OK) == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __func__, "g_st_comm_watch_dat[CAN]."); + /* Communication disruption monitoring management table */ + memset(g_st_comm_watch_dat[0], 0x00, sizeof(CAN_COMM_WATCH_DAT) * COMM_WATCH_LIST_NUM); + g_us_comm_watch_dat_cnt[0] = 0; /* Number of effective registrations of communication disruption monitoring management table */ + } else { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "/tmp/communication_debug Not found."); + } + return eFrameworkunifiedStatusOK; +} +// LCOV_EXCL_STOP 7: debug code |