release 0.3.1
doxygen + refactoring
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
* @details Позволяет обратиться к любому коилу по его глобальному адрессу.
|
||||
Вне зависимости от того как коилы размещены в памяти.
|
||||
*/
|
||||
MB_ExceptionTypeDef MB_Write_Coil_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal)
|
||||
MB_ExceptionTypeDef MB_Coil_Write_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal)
|
||||
{
|
||||
//---------CHECK FOR ERRORS----------
|
||||
MB_ExceptionTypeDef Exception = NO_ERRORS;
|
||||
@@ -63,7 +63,7 @@ MB_ExceptionTypeDef MB_Write_Coil_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteV
|
||||
* @details Позволяет обратиться к любому коилу по его глобальному адрессу.
|
||||
Вне зависимости от того как коилы размещены в памяти.
|
||||
*/
|
||||
uint16_t MB_Read_Coil_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception)
|
||||
uint16_t MB_Coil_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception)
|
||||
{
|
||||
//---------CHECK FOR ERRORS----------
|
||||
MB_ExceptionTypeDef Exception_tmp;
|
||||
@@ -94,11 +94,17 @@ uint16_t MB_Read_Coil_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception)
|
||||
* @param coil_state Указатель для состояния coil (1 - ON, 0 - OFF)
|
||||
* @return 1 - успех, 0 - ошибка или coil_addr вне диапазона запроса
|
||||
*/
|
||||
int MB_GetCoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_state)
|
||||
int MB_RespGet_CoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_state)
|
||||
{
|
||||
if(modbus_msg == NULL || coil_state == NULL)
|
||||
return 0;
|
||||
|
||||
// Проверяем что ответ связан с коилами
|
||||
if(modbus_msg->Func_Code != MB_R_COILS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Проверяем что coil_addr в пределах запрошенного диапазона
|
||||
if(coil_addr < modbus_msg->Addr || coil_addr >= modbus_msg->Addr + modbus_msg->Qnt)
|
||||
return 0;
|
||||
@@ -108,15 +114,19 @@ int MB_GetCoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_sta
|
||||
|
||||
// Вычисляем байт и бит
|
||||
uint8_t byte_index = coil_index / 8;
|
||||
uint8_t bit_index = coil_index % 8;
|
||||
uint8_t data_index = coil_index / 16;
|
||||
uint8_t bit_index = coil_index % 16;
|
||||
|
||||
// Проверяем что байт существует в данных
|
||||
if(byte_index >= modbus_msg->ByteCnt)
|
||||
return 0;
|
||||
|
||||
// Получаем байт и проверяем бит
|
||||
uint8_t coil_byte = modbus_msg->DATA[byte_index] & 0xFF;
|
||||
*coil_state = (coil_byte >> bit_index) & 0x01;
|
||||
// Получаем байт и проверяем бит
|
||||
if(bit_index < 8)
|
||||
*coil_state = (modbus_msg->DATA[data_index] >> (bit_index+8)) & 0x01;
|
||||
else
|
||||
*coil_state = (modbus_msg->DATA[data_index] >> bit_index) & 0x01;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -211,7 +221,7 @@ uint8_t MB_Process_Write_Single_Coil(RS_MsgTypeDef *modbus_msg)
|
||||
* @return fMessageHandled Статус о результате обработки комманды.
|
||||
* @details Обработка команды Write Multiple Coils.
|
||||
*/
|
||||
uint8_t MB_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg)
|
||||
uint8_t MB_Process_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg)
|
||||
{
|
||||
//---------CHECK FOR ERRORS----------
|
||||
if (modbus_msg->ByteCnt != Divide_Up(modbus_msg->Qnt, 8))
|
||||
@@ -274,11 +284,11 @@ uint8_t MB_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg)
|
||||
#else //MODBUS_ENABLE_COILS
|
||||
|
||||
|
||||
int MB_GetCoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_state) {return 0;}
|
||||
MB_ExceptionTypeDef MB_Write_Coil_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal) {return ILLEGAL_FUNCTION;}
|
||||
uint16_t MB_Read_Coil_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
||||
int MB_RespGet_CoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_state) {return 0;}
|
||||
MB_ExceptionTypeDef MB_Coil_Write_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal) {return ILLEGAL_FUNCTION;}
|
||||
uint16_t MB_Coil_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
||||
uint8_t MB_Process_Read_Coils(RS_MsgTypeDef *modbus_msg) {return 0;}
|
||||
uint8_t MB_Process_Write_Single_Coil(RS_MsgTypeDef *modbus_msg) {return 0;}
|
||||
uint8_t MB_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg) {return 0;}
|
||||
uint8_t MB_Process_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg) {return 0;}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user