From df3f71cdff442547c8606520a5342ebfc149e527 Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Sun, 30 Nov 2025 21:20:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B0=20write=20?= =?UTF-8?q?=D0=B2=20MB=5FDefineRegistersAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit И рефакторинг дефайнов размеров сообщения --- Inc/__modbus_compat.h | 3 +++ Inc/modbus_core.h | 38 ++++++++++++++++++++------------------ Inc/rs_message.h | 8 ++++---- Src/modbus_devid.c | 4 ++-- Src/modbus_holdregs.c | 10 +++++----- Src/modbus_inputregs.c | 6 +++--- Src/modbus_master.c | 10 +++++----- Src/modbus_slave.c | 18 +++++++++--------- Src/rs_message.c | 10 +++++----- __modbus_data.c | 4 ++-- 10 files changed, 58 insertions(+), 53 deletions(-) diff --git a/Inc/__modbus_compat.h b/Inc/__modbus_compat.h index f1a00a8..1526622 100644 --- a/Inc/__modbus_compat.h +++ b/Inc/__modbus_compat.h @@ -65,6 +65,9 @@ CREATE_DEPRECATED_ALIAS(MB_EXTENDED_IDENTIFICATIONS, RID_EXTENDED_IDENTIFICATIO CREATE_DEPRECATED_ALIAS(MB_SPEDIFIC_IDENTIFICATIONS, RID_SPEDIFIC_IDENTIFICATIONS, MB_ReadDevId); +#define MbAddr DeviceAddr + + /** MODBUS_LEGACY_API * @} */ diff --git a/Inc/modbus_core.h b/Inc/modbus_core.h index 8b26730..d87cd76 100644 --- a/Inc/modbus_core.h +++ b/Inc/modbus_core.h @@ -41,31 +41,31 @@ ////////////////////---MODBUS MESSAGE DEFINES---///////////////////// //-------------DEFINES FOR STRUCTURE---------------- /* defines for structure of modbus message */ -#define TransactionID_size 2 ///< size of (Transaction ID) -#define ProtocolID_size 2 ///< size of (Protocol ID) -#define PDULength_size 2 ///< size of (PDU Length) -#define MbAddr_SIZE 1 ///< size of (Slave Addr) -#define Func_Code_SIZE 1 ///< size of (Function Code) -#define Addr_SIZE 2 ///< size of (Address) -#define Qnt_SIZE 2 ///< size of (Quantity) -#define ByteCnt_SIZE 1 ///< size of (Byte Count) -#define DATA_SIZE 125 ///< maximum number of data: DWORD (NOT MESSAGE SIZE) -#define CRC_SIZE 2 ///< size of (MbCRC) in bytes +#define MbTransactionID_size 2 ///< size of (Transaction ID) +#define MbProtocolID_size 2 ///< size of (Protocol ID) +#define MbPDULength_size 2 ///< size of (PDU Length) +#define MbDeviceAddr_size 1 ///< size of (Slave Addr) +#define MbFuncCode_size 1 ///< size of (Function Code) +#define MbAddr_size 2 ///< size of (Address) +#define MbQnt_size 2 ///< size of (Quantity) +#define MbByteCnt_size 1 ///< size of (Byte Count) +#define MbData_size 125 ///< maximum number of data: DWORD (NOT MESSAGE SIZE) +#define MbCRC_size 2 ///< size of (MbCRC) in bytes #ifndef MODBUS_PROTOCOL_TCP /** @brief Size of whole RTU message */ -#define INFO_SIZE_MAX (MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE) +#define RS_INFO_SIZE_MAX (MbDeviceAddr_size+MbFuncCode_size+MbAddr_size+MbQnt_size+MbByteCnt_size) #else /** @brief Size of whole TCP message */ -#define INFO_SIZE_MAX (TransactionID_size+ProtocolID_size+PDULength_size+MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE) +#define RS_INFO_SIZE_MAX (MbTransactionID_size+MbProtocolID_size+MbPDULength_size+MbDeviceAddr_size+MbFuncCode_size+MbAddr_size+MbQnt_size) #endif /** @brief Size of first part of message that will be received first receive info part of message, than defines size of rest message*/ -#define RX_FIRST_PART_SIZE INFO_SIZE_MAX +#define RS_RX_FIRST_PART_SIZE RS_INFO_SIZE_MAX /** @brief Size of buffer: max size of whole message */ -#define MSG_SIZE_MAX (INFO_SIZE_MAX + DATA_SIZE*2 + CRC_SIZE) // max possible size of message +#define RS_MSG_SIZE_MAX (RS_INFO_SIZE_MAX + MbData_size*2 + MbCRC_size) // max possible size of message /** * @brief Enum for modbus exception codes @@ -129,7 +129,9 @@ typedef enum //MB_FunctonTypeDef FC_ERR_R_DEVICE_INFO = FC_R_DEVICE_ID + FC_ERR_VALUES_START, ///< Ошибка чтения информации об устройстве }MB_FunctonTypeDef; -/** @brief Enum for MEI func codes */ +/** + * @brief Enum for MEI func codes + */ typedef enum //MB_FunctonTypeDef { MEI_DEVICE_IDENTIFICATIONS = 0x0E, @@ -180,14 +182,14 @@ typedef struct // RS_MsgTypeDef uint16_t PDULength; ///< Modbus TCP: PDU Length #endif - uint8_t MbAddr; ///< Modbus Slave Address + uint8_t DeviceAddr; ///< Modbus Slave Address MB_FunctonTypeDef FuncCode; ///< Modbus Function Code MB_DevIdMsgTypeDef DevId; ///< Read Device Identifications Header struct uint16_t Addr; ///< Modbus Address of data uint16_t Qnt; ///< Quantity of modbus data uint8_t ByteCnt; ///< Quantity of bytes of data in message to transmit/receive - uint16_t MbData[DATA_SIZE]; ///< Modbus Data + uint16_t MbData[MbData_size]; ///< Modbus Data MB_ExceptionTypeDef Except_Code; ///< Exception Code for the command uint16_t MbCRC; ///< Modbus CRC @@ -298,7 +300,7 @@ extern RS_MsgTypeDef MODBUS_MSG; /* Check is address valid for certain array */ MB_ExceptionTypeDef MB_Check_Address_For_Arr(uint16_t Addr, uint16_t Qnt, uint16_t R_ARR_ADDR, uint16_t R_ARR_NUMB); /* Define Address Origin for Input/Holding Registers */ -MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType); +MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType, uint8_t WriteFlag); /* Define Address Origin for coils */ MB_ExceptionTypeDef MB_DefineCoilsAddress(uint16_t **pCoils, uint16_t Addr, uint16_t Qnt, uint16_t *start_shift, uint8_t WriteFlag); /** MODBUS_CMD_PROCESS_FUNCTIONS diff --git a/Inc/rs_message.h b/Inc/rs_message.h index 8723a98..3d4fee1 100644 --- a/Inc/rs_message.h +++ b/Inc/rs_message.h @@ -24,7 +24,7 @@ 4. Инициализировать через RS_Init() и запустить прием RS_Receive_IT() @section features Особенности: -- Буфер: RS_Buffer[MSG_SIZE_MAX] Общий для приема/передачи +- Буфер: RS_Buffer[RS_MSG_SIZE_MAX] Общий для приема/передачи - Состояния: отслеживается через флаги в RS_HandleTypeDef - Таймауты: контролируют максимальное время ожидания фрейма ******************************************************************************/ @@ -36,8 +36,8 @@ ///////////////////////////////////////////////////////////////////// ////////////////////////////---DEFINES---//////////////////////////// /* Check that all defines required by RS are defined */ -#ifndef MSG_SIZE_MAX -#error Define MSG_SIZE_MAX (Maximum size of message). This is necessary to create buffer for UART. +#ifndef RS_MSG_SIZE_MAX +#error Define RS_MSG_SIZE_MAX (Maximum size of message). This is necessary to create buffer for UART. #endif /** @@ -45,7 +45,7 @@ */ /* Clear message-uart buffer */ -#define RS_Clear_Buff(_buff_) for(int i=0; if.RS_Busy = 0 diff --git a/Src/modbus_devid.c b/Src/modbus_devid.c index 45453b7..92d435a 100644 --- a/Src/modbus_devid.c +++ b/Src/modbus_devid.c @@ -51,7 +51,7 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj) /* Define number of object in one message */ unsigned lastobjid = 0; - for(int i = 0; i < DATA_SIZE*2;) + for(int i = 0; i < MbData_size*2;) { /* Если объект за пределами допутимого - выходим из цикла */ if(objidtmp >= 0xFF + MODBUS_NUMB_OF_USEROBJECTS) @@ -60,7 +60,7 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj) i += 2; i += obj[objidtmp].length; /* Если все еще помещается в массив переходим на следующий объект */ - if(i < DATA_SIZE*2) + if(i < MbData_size*2) { objidtmp++; } diff --git a/Src/modbus_holdregs.c b/Src/modbus_holdregs.c index 88ab7f7..90b1c96 100644 --- a/Src/modbus_holdregs.c +++ b/Src/modbus_holdregs.c @@ -40,7 +40,7 @@ MB_ExceptionTypeDef MB_Holding_Write_Global(uint16_t Addr, uint16_t WriteVal) uint16_t *pHoldRegs; //------------WRITE COIL------------- - Exception = MB_DefineRegistersAddress(&pHoldRegs, Addr, 1, RegisterType_Holding); + Exception = MB_DefineRegistersAddress(&pHoldRegs, Addr, 1, RegisterType_Holding, 1); if(Exception == ET_NO_ERRORS) { *(pHoldRegs) = WriteVal; @@ -66,7 +66,7 @@ uint16_t MB_Holding_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) uint16_t *pHoldRegs; //------------READ COIL-------------- - Exception_tmp = MB_DefineRegistersAddress(&pHoldRegs, Addr, 1, RegisterType_Holding); + Exception_tmp = MB_DefineRegistersAddress(&pHoldRegs, Addr, 1, RegisterType_Holding, 0); if(Exception) // if exception is not given to func fill it *Exception = Exception_tmp; @@ -94,7 +94,7 @@ uint8_t MB_Process_Read_Hold_Regs(RS_MsgTypeDef *modbus_msg) //---------CHECK FOR ERRORS---------- // get origin address for data uint16_t *pHoldRegs; - modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding); // определение адреса регистров + modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding, 0); // определение адреса регистров if(modbus_msg->Except_Code != ET_NO_ERRORS) return 0; @@ -121,7 +121,7 @@ uint8_t MB_Process_Write_Single_Reg(RS_MsgTypeDef *modbus_msg) { // get origin address for data uint16_t *pHoldRegs; - modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, 1, RegisterType_Holding); // определение адреса регистров + modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, 1, RegisterType_Holding, 1); // определение адреса регистров if(modbus_msg->Except_Code != ET_NO_ERRORS) return 0; @@ -146,7 +146,7 @@ uint8_t MB_Process_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg) } // get origin address for data uint16_t *pHoldRegs; - modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding); // определение адреса регистров + modbus_msg->Except_Code = MB_DefineRegistersAddress(&pHoldRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Holding, 1); // определение адреса регистров if(modbus_msg->Except_Code != ET_NO_ERRORS) return 0; diff --git a/Src/modbus_inputregs.c b/Src/modbus_inputregs.c index 41081d6..4218323 100644 --- a/Src/modbus_inputregs.c +++ b/Src/modbus_inputregs.c @@ -36,7 +36,7 @@ MB_ExceptionTypeDef MB_Input_Write_Global(uint16_t Addr, uint16_t WriteVal) uint16_t *pInRegs; //------------WRITE COIL------------- - Exception = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input); + Exception = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input, 1); if(Exception == ET_NO_ERRORS) { *(pInRegs) = WriteVal; @@ -62,7 +62,7 @@ uint16_t MB_Input_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) uint16_t *pInRegs; //------------READ COIL-------------- - Exception_tmp = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input); + Exception_tmp = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input, 0); if(Exception) // if exception is not given to func fill it *Exception = Exception_tmp; @@ -89,7 +89,7 @@ uint8_t MB_Process_Read_Input_Regs(RS_MsgTypeDef *modbus_msg) //---------CHECK FOR ERRORS---------- // get origin address for data uint16_t *pInRegs; - modbus_msg->Except_Code = MB_DefineRegistersAddress(&pInRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Input); // определение адреса регистров + modbus_msg->Except_Code = MB_DefineRegistersAddress(&pInRegs, modbus_msg->Addr, modbus_msg->Qnt, RegisterType_Input, 0); // определение адреса регистров if(modbus_msg->Except_Code != ET_NO_ERRORS) return 0; diff --git a/Src/modbus_master.c b/Src/modbus_master.c index e5305ad..71c72ea 100644 --- a/Src/modbus_master.c +++ b/Src/modbus_master.c @@ -374,7 +374,7 @@ static int MB_Define_Size_of_Function(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef * } } - mb_func_size = RX_FIRST_PART_SIZE + mb_func_size; // size of whole message + mb_func_size = RS_RX_FIRST_PART_SIZE + mb_func_size; // size of whole message return mb_func_size; } @@ -392,7 +392,7 @@ RS_StatusTypeDef MB_Master_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgType //------INFO ABOUT DATA/MESSAGE------ //-----------[first bytes]----------- // set ID of slave device - modbus_uart_buff[ind++] = modbus_msg->MbAddr; + modbus_uart_buff[ind++] = modbus_msg->DeviceAddr; // set function code modbus_uart_buff[ind++] = modbus_msg->FuncCode; @@ -472,7 +472,7 @@ RS_StatusTypeDef MB_Master_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDe int expected_size = 0; // get ID of slave device - modbus_msg->MbAddr = modbus_uart_buff[ind++]; + modbus_msg->DeviceAddr = modbus_uart_buff[ind++]; // get function code (check if error response) modbus_msg->FuncCode = modbus_uart_buff[ind++]; @@ -633,7 +633,7 @@ RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_COILS(uint8_t slave_addr, uint16_t start // Copy coil data to message MbData array for(int i = 0; i < byte_count; i++) { - if(i < DATA_SIZE) { + if(i < MbData_size) { msg.MbData[i] = coils_data[i]; } } @@ -649,7 +649,7 @@ RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_REGS(uint8_t slave_addr, uint16_t start_ msg.ByteCnt = quantity * 2; // Each register is 2 bytes // Copy register data to message MbData array - for(int i = 0; i < quantity && i < DATA_SIZE; i++) { + for(int i = 0; i < quantity && i < MbData_size; i++) { msg.MbData[i] = regs_data[i]; } diff --git a/Src/modbus_slave.c b/Src/modbus_slave.c index 77fa6fb..7d81c21 100644 --- a/Src/modbus_slave.c +++ b/Src/modbus_slave.c @@ -29,7 +29,7 @@ RS_StatusTypeDef MB_Slave_Response(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *mod RS_Reset_TX_Flags(hmodbus); // reset flag for correct transmit MB_Diagnostics_BusMessageCnt(); - if(hmodbus->ID == 0 || modbus_msg->MbAddr == 0) + if(hmodbus->ID == 0 || modbus_msg->DeviceAddr == 0) { MB_Diagnostics_SlaveNoResponseCnt(); // <-- Устройство не отвечает на широковещательные сообщения hmodbus->RS_STATUS = RS_SKIP; @@ -185,7 +185,7 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD #endif //-----------[first bytes]----------- // set ID of message/user - modbus_uart_buff[ind++] = modbus_msg->MbAddr; + modbus_uart_buff[ind++] = modbus_msg->DeviceAddr; // set dat or err response modbus_uart_buff[ind++] = modbus_msg->FuncCode; @@ -204,7 +204,7 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD modbus_uart_buff[ind++] = modbus_msg->DevId.NextObjId; modbus_uart_buff[ind++] = modbus_msg->DevId.NumbOfObj; - if (modbus_msg->ByteCnt > DATA_SIZE*2) // if ByteCnt less than DATA_SIZE + if (modbus_msg->ByteCnt > MbData_size*2) // if ByteCnt less than MbData_size { TrackerCnt_Err(hmodbus->rs_err); return RS_COLLECT_MSG_ERR; @@ -235,7 +235,7 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD else // modbus data header { // set size of received data - if (modbus_msg->ByteCnt <= DATA_SIZE*2) // if ByteCnt less than DATA_SIZE + if (modbus_msg->ByteCnt <= MbData_size*2) // if ByteCnt less than MbData_size modbus_uart_buff[ind++] = modbus_msg->ByteCnt; else // otherwise return data_size err { @@ -314,7 +314,7 @@ static int MB_Define_Size_of_Function(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef * } - mb_func_size = RX_FIRST_PART_SIZE + mb_func_size; // size of whole message + mb_func_size = RS_RX_FIRST_PART_SIZE + mb_func_size; // size of whole message return mb_func_size; } @@ -348,12 +348,12 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef // get ID of message/user if(modbus_uart_buff[ind] != hmodbus->ID) { - modbus_msg->MbAddr = 0; + modbus_msg->DeviceAddr = 0; ind++; } else { - modbus_msg->MbAddr = modbus_uart_buff[ind++]; + modbus_msg->DeviceAddr = modbus_uart_buff[ind++]; } // get func code @@ -361,7 +361,7 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef if(modbus_msg->FuncCode & FC_ERR_VALUES_START) // явная херня { MB_Diagnostics_SlaveNAKCnt(); - modbus_msg->MbAddr = 0; + modbus_msg->DeviceAddr = 0; return RS_SKIP; } @@ -424,7 +424,7 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef if (modbus_msg->ByteCnt != 0) { //check that data size is correct - if (modbus_msg->ByteCnt > DATA_SIZE*2) + if (modbus_msg->ByteCnt > MbData_size*2) { TrackerCnt_Err(hmodbus->rs_err); modbus_msg->FuncCode |= FC_ERR_VALUES_START; diff --git a/Src/rs_message.c b/Src/rs_message.c index ed5d801..b8dd9bb 100644 --- a/Src/rs_message.c +++ b/Src/rs_message.c @@ -12,10 +12,10 @@ @section arch Архитектура: В режиме слейв: - - Инициализация приема с сообщения с максимальным размером MSG_SIZE_MAX + - Инициализация приема с сообщения с максимальным размером RS_MSG_SIZE_MAX - При срабатывании прерывания IDLE - обработка полученного сообщения В режиме мастер (пока не реализовано): - - Отправка запроса и переход в режим приема сообщения с максимальным размером MSG_SIZE_MAX + - Отправка запроса и переход в режим приема сообщения с максимальным размером RS_MSG_SIZE_MAX - При срабатывании прерывания IDLE - обработка полученного ответа @section ithandler Необходимые обработчики: @@ -25,7 +25,7 @@ #include "rs_message.h" #include "modbus_diag.h" -uint8_t RS_Buffer[MSG_SIZE_MAX]; // uart buffer +uint8_t RS_Buffer[RS_MSG_SIZE_MAX]; // uart buffer extern void RS_UART_Init(void); extern void RS_UART_DeInit(UART_HandleTypeDef *huart); @@ -61,7 +61,7 @@ RS_StatusTypeDef RS_Receive_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg) // start receiving __HAL_UART_ENABLE_IT(hRS->huart, UART_IT_IDLE); - uart_res = HAL_UART_Receive_IT(hRS->huart, &hRS->pBufferPtr[hRS->RS_Message_Size], MSG_SIZE_MAX); // receive until ByteCnt+1 byte, + uart_res = HAL_UART_Receive_IT(hRS->huart, &hRS->pBufferPtr[hRS->RS_Message_Size], RS_MSG_SIZE_MAX); // receive until ByteCnt+1 byte, // then in Callback restart receive for rest bytes // if receive isnt started - abort RS @@ -445,7 +445,7 @@ void RS_TIM_Handler(RS_HandleTypeDef *hRS) hRS->RS_STATUS = RS_TIMEOUT; if(hRS->sRS_Mode < RS_MASTER_MODE_START) - if(hRS->pMessagePtr->MbAddr == hRS->ID) // ошибка если таймаут по нашему сообщению + if(hRS->pMessagePtr->DeviceAddr == hRS->ID) // ошибка если таймаут по нашему сообщению TrackerCnt_Err(hRS->rs_err); if(hRS->sRS_Mode >= RS_MASTER_MODE_START) diff --git a/__modbus_data.c b/__modbus_data.c index 8ef9fef..a333a82 100644 --- a/__modbus_data.c +++ b/__modbus_data.c @@ -65,10 +65,10 @@ MB_ExceptionTypeDef MB_Check_Address_For_Arr(uint16_t Addr, uint16_t Qnt, uint16 * @details Определение адреса начального регистра. * @note WriteFlag пока не используется. */ -MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType) +MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, uint16_t Qnt, uint8_t RegisterType, uint8_t WriteFlag) { /* check quantity error */ - if (Qnt > DATA_SIZE) + if (Qnt > MbData_size) { return ET_ILLEGAL_DATA_VALUE; // return exception code }