|
@@ -9,6 +9,7 @@
|
|
|
#include "mbrtu.h"
|
|
|
#include "tim_delay.h"
|
|
|
#include "settings_api.h"
|
|
|
+#include "iap.h"
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include <stdbool.h>
|
|
@@ -39,15 +40,20 @@ bool mb_package_flag = false;
|
|
|
//
|
|
|
void mb_init(void)
|
|
|
{
|
|
|
- uint32_t baud = 115200;
|
|
|
- eMBParity par = MB_PAR_NONE;
|
|
|
+ uint32_t baud;
|
|
|
+ eMBParity par;
|
|
|
UCHAR mb_addr = 1;
|
|
|
unsigned int stop_bits = 1;
|
|
|
const UCHAR ucSlaveID[] = {0xAA, 0xBB, 0xCC};
|
|
|
+
|
|
|
+ iap_init();
|
|
|
|
|
|
mb_init_params();
|
|
|
|
|
|
settings_set_modbus_params(settings.com_settings.mb_port);
|
|
|
+
|
|
|
+ baud = settings_get_mb_baud(&mb_port_settings);
|
|
|
+ par = settings_get_mb_par(&mb_port_settings);
|
|
|
|
|
|
mb_helper_tim_init(baud);
|
|
|
eMBInit(MB_RTU, mb_addr, 4, baud, par, stop_bits);
|
|
@@ -220,24 +226,48 @@ void modbus_port_timer(void const * params)
|
|
|
// Modbus callback's
|
|
|
// ------------------------------------------------------------------- //
|
|
|
|
|
|
-//
|
|
|
-// 65 (0x41) Read Input Registers
|
|
|
+
|
|
|
+// 04 (0x04) Read Input Registers
|
|
|
eMBErrorCode
|
|
|
-eMBUpdateCB( UCHAR * pucFrame, USHORT * usLen)
|
|
|
+eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
|
|
|
{
|
|
|
- eMBErrorCode eStatus = MB_ENOERR;
|
|
|
+ return MB_ENOREG;
|
|
|
+}
|
|
|
|
|
|
- mb_package_flag = true;
|
|
|
-
|
|
|
- return eStatus;
|
|
|
+
|
|
|
+// 03 (0x03) Read Holding Registers
|
|
|
+// 16 (0x10) Write Multiple registers
|
|
|
+#if 0
|
|
|
+eMBErrorCode
|
|
|
+eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
|
|
|
+{
|
|
|
+ return MB_ENOREG;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+// 17 (0x11) Report Slave ID (Serial Line only)
|
|
|
+eMBException
|
|
|
+eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
|
|
|
+{
|
|
|
+ return MB_EX_ILLEGAL_FUNCTION;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// чтение/запись значений из нескольких регистров флагов (Coil Status).
|
|
|
+// чтения N регистров параметров
|
|
|
eMBErrorCode
|
|
|
-eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
|
|
|
+eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
|
|
|
{
|
|
|
- return MB_ENOREG;
|
|
|
+ return MB_ENOREG;
|
|
|
}
|
|
|
|
|
|
+eMBErrorCode
|
|
|
+eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
|
|
|
+{
|
|
|
+ return MB_ENOREG;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 03 (0x03) Read Holding Registers
|
|
|
// чтение N регистров управления и уставок
|
|
@@ -323,93 +353,5 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
|
|
|
return eStatus;
|
|
|
}
|
|
|
|
|
|
-// 17 (0x11) Report Slave ID (Serial Line only)
|
|
|
-// чтение информации об устройстве (0x11)
|
|
|
-eMBException
|
|
|
-eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
|
|
|
-{
|
|
|
-#if 0
|
|
|
- mb_package_flag = true;
|
|
|
-
|
|
|
- *usLen = mb_get_info(&pucFrame[1]) + 3;
|
|
|
-#endif
|
|
|
- return MB_EX_NONE;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// чтение/запись значений из нескольких регистров флагов (Coil Status).
|
|
|
-// чтения N регистров параметров
|
|
|
-eMBErrorCode
|
|
|
-eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
|
|
|
-{
|
|
|
- return MB_ENOREG;
|
|
|
-}
|
|
|
-
|
|
|
-eMBErrorCode
|
|
|
-eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
|
|
|
-{
|
|
|
- return MB_ENOREG;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// 0x42
|
|
|
-// Запрос на изменение адреса
|
|
|
-// Если запрос широковещательный, то нужно проверить присланный ID.
|
|
|
-eMBException
|
|
|
-eMBSetAddrIdCB( UCHAR * pucFrame, USHORT * usLen )
|
|
|
-{
|
|
|
-#if 0
|
|
|
- mb_package_flag = true;
|
|
|
-
|
|
|
- if (rcvAddress == MB_ADDRESS_BROADCAST)
|
|
|
- {
|
|
|
- if (mb_set_addr_id(&pucFrame[1], &new_slave_addr))
|
|
|
- mb_action = MB_CHANGE_ADDR;
|
|
|
- }
|
|
|
- // Адресный запрос. ID не проверяем
|
|
|
- else
|
|
|
- {
|
|
|
- if (mb_set_addr(&pucFrame[1], &new_slave_addr))
|
|
|
- {
|
|
|
- pucFrame[1] = new_slave_addr;
|
|
|
- mb_action = MB_CHANGE_ADDR;
|
|
|
- }
|
|
|
- else
|
|
|
- pucFrame[1] = MB_BOOT_ERR_WRONG_CONTENT;
|
|
|
- }
|
|
|
-
|
|
|
- *usLen = 2;
|
|
|
-#endif
|
|
|
- return MB_EX_NONE;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
-// 0x43
|
|
|
-eMBException
|
|
|
-eMBSetAddrSerialCB( UCHAR * pucFrame, USHORT * usLen )
|
|
|
-{
|
|
|
-#if 0
|
|
|
- mb_package_flag = true;
|
|
|
-
|
|
|
- if (rcvAddress == MB_ADDRESS_BROADCAST)
|
|
|
- {
|
|
|
- if (mb_set_addr_serial(&pucFrame[1], &new_slave_addr))
|
|
|
- mb_action = MB_CHANGE_ADDR;
|
|
|
- }
|
|
|
- // Адресный запрос. ID не проверяем
|
|
|
- else
|
|
|
- {
|
|
|
- if (mb_set_addr(&pucFrame[1], &new_slave_addr))
|
|
|
- {
|
|
|
- pucFrame[1] = new_slave_addr;
|
|
|
- mb_action = MB_CHANGE_ADDR;
|
|
|
- }
|
|
|
- else
|
|
|
- pucFrame[1] = MB_BOOT_ERR_WRONG_CONTENT;
|
|
|
- }
|
|
|
-
|
|
|
- *usLen = 2;
|
|
|
-#endif
|
|
|
- return MB_EX_NONE;
|
|
|
-}
|
|
|
|