add roll thread
This commit is contained in:
@@ -11,10 +11,10 @@
|
||||
#include <rtdbg.h>
|
||||
|
||||
rt_uint16_t usSDiscInStart = S_DISCRETE_INPUT_START;
|
||||
rt_uint8_t ucSDiscInBuf[(S_DISCRETE_INPUT_NDISCRETES+7)/8];
|
||||
rt_uint8_t ucSDiscInBuf[(S_DISCRETE_INPUT_NDISCRETES+BITS_UCHAR-1)/BITS_UCHAR];
|
||||
|
||||
rt_uint16_t usSCoilStart = S_COIL_START;
|
||||
rt_uint8_t ucSCoilBuf[(S_COIL_NCOILS+7)/8];
|
||||
rt_uint8_t ucSCoilBuf[(S_COIL_NCOILS+BITS_UCHAR-1)/BITS_UCHAR];
|
||||
|
||||
rt_uint16_t usSRegInStart = S_REG_INPUT_START;
|
||||
rt_uint16_t usSRegInBuf[S_REG_INPUT_NREGS];
|
||||
@@ -22,7 +22,7 @@ rt_uint16_t usSRegInBuf[S_REG_INPUT_NREGS];
|
||||
rt_uint16_t usSRegHoldStart = S_REG_HOLDING_START;
|
||||
rt_uint16_t usSRegHoldBuf[S_REG_HOLDING_NREGS];
|
||||
|
||||
#define BITS_UCHAR 8U
|
||||
|
||||
|
||||
struct chrg_comm_t chrgcomm = {
|
||||
.name = THR_NAME_COMM,
|
||||
@@ -58,16 +58,16 @@ struct chrg_comm_t chrgcomm = {
|
||||
* ucBits[2] = {0, 0};
|
||||
*
|
||||
* // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
|
||||
* xMBUtilSetBits( ucBits, 4, 1, 1 );
|
||||
* mb_set_bits( ucBits, 4, 1, 1 );
|
||||
*
|
||||
* // Set bit 7 to 1 and bit 8 to 0.
|
||||
* xMBUtilSetBits( ucBits, 7, 2, 0x01 );
|
||||
* mb_set_bits( ucBits, 7, 2, 0x01 );
|
||||
*
|
||||
* // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
|
||||
* xMBUtilSetBits( ucBits, 8, 8, 0x5A);
|
||||
* mb_set_bits( ucBits, 8, 8, 0x5A);
|
||||
* \endcode
|
||||
*/
|
||||
void xMBUtilSetBits (rt_uint8_t *ucByteBuf, rt_uint16_t usBitOffset,
|
||||
void mb_set_bits (rt_uint8_t *ucByteBuf, rt_uint16_t usBitOffset,
|
||||
rt_uint8_t ucNBits, rt_uint8_t ucValue)
|
||||
{
|
||||
rt_uint16_t usWordBuf;
|
||||
@@ -76,7 +76,7 @@ void xMBUtilSetBits (rt_uint8_t *ucByteBuf, rt_uint16_t usBitOffset,
|
||||
rt_uint16_t usNPreBits;
|
||||
rt_uint16_t usValue = ucValue;
|
||||
|
||||
RT_ASSERT(ucNBits <= 8);
|
||||
RT_ASSERT(ucNBits <= BITS_UCHAR);
|
||||
RT_ASSERT((size_t)BITS_UCHAR == sizeof(rt_uint8_t) * 8);
|
||||
|
||||
/* Calculate byte offset for first byte containing the bit values starting
|
||||
@@ -121,10 +121,10 @@ void xMBUtilSetBits (rt_uint8_t *ucByteBuf, rt_uint16_t usBitOffset,
|
||||
* rt_uint8_t ucResult;
|
||||
*
|
||||
* // Extract the bits 3 - 10.
|
||||
* ucResult = xMBUtilGetBits( ucBits, 3, 8 );
|
||||
* ucResult = mb_get_bits( ucBits, 3, 8 );
|
||||
* \endcode
|
||||
*/
|
||||
rt_uint8_t xMBUtilGetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_uint8_t ucNBits)
|
||||
rt_uint8_t mb_get_bits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_uint8_t ucNBits)
|
||||
{
|
||||
rt_uint16_t usWordBuf;
|
||||
rt_uint16_t usMask;
|
||||
@@ -154,7 +154,7 @@ rt_uint8_t xMBUtilGetBits (rt_uint8_t * ucByteBuf, rt_uint16_t usBitOffset, rt_u
|
||||
return (rt_uint8_t)usWordBuf;
|
||||
}
|
||||
|
||||
static eMBException prveMBError2Exception (eMBErrorCode eErrorCode)
|
||||
static eMBException mb_error (eMBErrorCode eErrorCode)
|
||||
{
|
||||
eMBException eStatus;
|
||||
|
||||
@@ -180,17 +180,7 @@ static eMBException prveMBError2Exception (eMBErrorCode eErrorCode)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Modbus slave input register callback function.
|
||||
*
|
||||
* @param pucRegBuffer input register buffer
|
||||
* @param usAddress input register address
|
||||
* @param usNRegs input register number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegInputCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs)
|
||||
eMBErrorCode mb_reg_input_cb (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex;
|
||||
@@ -203,7 +193,7 @@ eMBErrorCode eMBRegInputCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_
|
||||
&& (usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS)) {
|
||||
iRegIndex = usAddress - usRegInStart;
|
||||
while (usNRegs > 0) {
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegInputBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegInputBuf[iRegIndex] >> BITS_UCHAR);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegInputBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
@@ -215,17 +205,7 @@ eMBErrorCode eMBRegInputCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave holding register callback function.
|
||||
*
|
||||
* @param pucRegBuffer holding register buffer
|
||||
* @param usAddress holding register address
|
||||
* @param usNRegs holding register number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegHoldingCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
eMBErrorCode mb_reg_holding_cb (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNRegs, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
@@ -242,7 +222,7 @@ eMBErrorCode eMBRegHoldingCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint
|
||||
/* read current register values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (usNRegs > 0) {
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegHoldingBuf[iRegIndex] >> 8);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegHoldingBuf[iRegIndex] >> BITS_UCHAR);
|
||||
*pucRegBuffer++ = (rt_uint8_t)(pusRegHoldingBuf[iRegIndex] & 0xFF);
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
@@ -252,7 +232,7 @@ eMBErrorCode eMBRegHoldingCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint
|
||||
/* write current register values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (usNRegs > 0) {
|
||||
pusRegHoldingBuf[iRegIndex] = *req++ << 8;
|
||||
pusRegHoldingBuf[iRegIndex] = *req++ << BITS_UCHAR;
|
||||
pusRegHoldingBuf[iRegIndex] |= *req++;
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
@@ -266,17 +246,7 @@ eMBErrorCode eMBRegHoldingCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave coils callback function.
|
||||
*
|
||||
* @param pucRegBuffer coils buffer
|
||||
* @param usAddress coils address
|
||||
* @param usNCoils coils number
|
||||
* @param eMode read or write
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegCoilsCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
eMBErrorCode mb_reg_coils_cb (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t usNCoils, eMBRegisterMode eMode)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
@@ -286,37 +256,37 @@ eMBErrorCode eMBRegCoilsCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16
|
||||
rt_uint16_t COIL_NCOILS = S_COIL_NCOILS;
|
||||
rt_uint16_t usCoilStart = usSCoilStart;
|
||||
|
||||
iNReg = (usNCoils+7)/8;
|
||||
iNReg = (usNCoils+BITS_UCHAR-1)/BITS_UCHAR;
|
||||
|
||||
if ((usAddress >= COIL_START) && (usAddress + usNCoils <= COIL_START + COIL_NCOILS)) {
|
||||
iRegIndex = (rt_uint16_t)(usAddress - usCoilStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t)(usAddress - usCoilStart) % 8;
|
||||
iRegIndex = (rt_uint16_t)(usAddress - usCoilStart) / BITS_UCHAR;
|
||||
iRegBitIndex = (rt_uint16_t)(usAddress - usCoilStart) % BITS_UCHAR;
|
||||
switch (eMode) {
|
||||
/* read current coil values from the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while (iNReg > 0) {
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8);
|
||||
*pucRegBuffer++ = mb_get_bits(&pucCoilBuf[iRegIndex++], iRegBitIndex, BITS_UCHAR);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
usNCoils = usNCoils % BITS_UCHAR;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNCoils);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNCoils);
|
||||
*pucRegBuffer = *pucRegBuffer << (BITS_UCHAR - usNCoils);
|
||||
*pucRegBuffer = *pucRegBuffer >> (BITS_UCHAR - usNCoils);
|
||||
break;
|
||||
|
||||
/* write current coil values with new values from the protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while (iNReg > 1) {
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8, *req++);
|
||||
mb_set_bits(&pucCoilBuf[iRegIndex++], iRegBitIndex, BITS_UCHAR, *req++);
|
||||
iNReg--;
|
||||
}
|
||||
/* last coils */
|
||||
usNCoils = usNCoils % 8;
|
||||
/* xMBUtilSetBits has bug when ucNBits is zero */
|
||||
usNCoils = usNCoils % BITS_UCHAR;
|
||||
/* mb_set_bits has bug when ucNBits is zero */
|
||||
if (usNCoils != 0) {
|
||||
xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils, *req++);
|
||||
mb_set_bits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils, *req++);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -327,16 +297,7 @@ eMBErrorCode eMBRegCoilsCB (rt_uint8_t *req, rt_uint8_t *pucRegBuffer, rt_uint16
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modbus slave discrete callback function.
|
||||
*
|
||||
* @param pucRegBuffer discrete buffer
|
||||
* @param usAddress discrete address
|
||||
* @param usNDiscrete discrete number
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
eMBErrorCode eMBRegDiscreteCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNDiscrete)
|
||||
eMBErrorCode mb_reg_discrete_cb (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNDiscrete)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
rt_uint16_t iRegIndex , iRegBitIndex , iNReg;
|
||||
@@ -344,23 +305,23 @@ eMBErrorCode eMBRegDiscreteCB (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress,
|
||||
rt_uint16_t DISCRETE_INPUT_START = S_DISCRETE_INPUT_START;
|
||||
rt_uint16_t DISCRETE_INPUT_NDISCRETES = S_DISCRETE_INPUT_NDISCRETES;
|
||||
rt_uint16_t usDiscreteInputStart = usSDiscInStart;
|
||||
iNReg = usNDiscrete / 8 + 1;
|
||||
iNReg = (usNDiscrete+BITS_UCHAR-1) / BITS_UCHAR;
|
||||
|
||||
if ((usAddress >= DISCRETE_INPUT_START)
|
||||
&& ((usAddress + usNDiscrete) <= (DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))) {
|
||||
iRegIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) / 8;
|
||||
iRegBitIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) % 8;
|
||||
iRegIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) / BITS_UCHAR;
|
||||
iRegBitIndex = (rt_uint16_t) (usAddress - usDiscreteInputStart) % BITS_UCHAR;
|
||||
|
||||
while (iNReg > 0) {
|
||||
*pucRegBuffer++ = xMBUtilGetBits(&pucDiscreteInputBuf[iRegIndex++], iRegBitIndex, 8);
|
||||
*pucRegBuffer++ = mb_get_bits(&pucDiscreteInputBuf[iRegIndex++], iRegBitIndex, BITS_UCHAR);
|
||||
iNReg--;
|
||||
}
|
||||
pucRegBuffer--;
|
||||
/* last discrete */
|
||||
usNDiscrete = usNDiscrete % 8;
|
||||
usNDiscrete = usNDiscrete % BITS_UCHAR;
|
||||
/* filling zero to high bit */
|
||||
*pucRegBuffer = *pucRegBuffer << (8 - usNDiscrete);
|
||||
*pucRegBuffer = *pucRegBuffer >> (8 - usNDiscrete);
|
||||
*pucRegBuffer = *pucRegBuffer << (BITS_UCHAR - usNDiscrete);
|
||||
*pucRegBuffer = *pucRegBuffer >> (BITS_UCHAR - usNDiscrete);
|
||||
} else {
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
@@ -387,13 +348,13 @@ eMBException funcReadCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
ucNBytes = (cntCoils+7)/8;
|
||||
ucNBytes = (cntCoils+BITS_UCHAR-1)/BITS_UCHAR;
|
||||
|
||||
resFrame[1] = MB_READ_COILS;
|
||||
resFrame[2] = ucNBytes;
|
||||
eRegStatus = eMBRegCoilsCB(RT_NULL, &resFrame[3], regAddress, cntCoils, MB_REG_READ);
|
||||
eRegStatus = mb_reg_coils_cb(RT_NULL, &resFrame[3], regAddress, cntCoils, MB_REG_READ);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
} else {
|
||||
*resLen = 3+ucNBytes;
|
||||
}
|
||||
@@ -420,13 +381,13 @@ eMBException funcReadDiscreteInputs (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return MB_EX_ILLEGAL_DATA_VALUE;
|
||||
}
|
||||
|
||||
ucNBytes = (cntDisCrete+7)/8;
|
||||
ucNBytes = (cntDisCrete+BITS_UCHAR-1)/BITS_UCHAR;
|
||||
|
||||
resFrame[1] = MB_READ_DISCRETE_INPUTS;
|
||||
resFrame[2] = ucNBytes;
|
||||
eRegStatus = eMBRegDiscreteCB(&resFrame[3], regAddress, cntDisCrete);
|
||||
eRegStatus = mb_reg_discrete_cb(&resFrame[3], regAddress, cntDisCrete);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
} else {
|
||||
*resLen = 3+ucNBytes;
|
||||
}
|
||||
@@ -456,9 +417,9 @@ eMBException funcReadHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
resFrame[1] = MB_READ_HOLDING_REGISTER;
|
||||
resFrame[2] = cntReg * 2;
|
||||
|
||||
eRegStatus = eMBRegHoldingCB(RT_NULL, &resFrame[3], regAddress, cntReg, MB_REG_READ);
|
||||
eRegStatus = mb_reg_holding_cb(RT_NULL, &resFrame[3], regAddress, cntReg, MB_REG_READ);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
} else {
|
||||
*resLen = 3+cntReg * 2;
|
||||
}
|
||||
@@ -488,9 +449,9 @@ eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
resFrame[1] = MB_READ_INPUT_REGISTER;
|
||||
resFrame[2] = cntReg * 2;
|
||||
|
||||
eRegStatus = eMBRegDiscreteCB(&resFrame[3], regAddress, cntReg);
|
||||
eRegStatus = mb_reg_discrete_cb(&resFrame[3], regAddress, cntReg);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
} else {
|
||||
*resLen = 3+cntReg*2;
|
||||
}
|
||||
@@ -527,9 +488,9 @@ eMBException funcWriteCoil (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
memcpy(resFrame, reqFrame, reqLen);
|
||||
*resLen = reqLen-2;
|
||||
|
||||
eRegStatus = eMBRegCoilsCB(RT_NULL, ucBuf, regAddress, 1, MB_REG_WRITE);
|
||||
eRegStatus = mb_reg_coils_cb(RT_NULL, ucBuf, regAddress, 1, MB_REG_WRITE);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
@@ -552,9 +513,9 @@ eMBException funcWriteHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
memcpy(resFrame, reqFrame, reqLen);
|
||||
*resLen = reqLen-2;
|
||||
|
||||
eRegStatus = eMBRegHoldingCB(&reqFrame[4], &resFrame[3], regAddress, 1, MB_REG_WRITE);
|
||||
eRegStatus = mb_reg_holding_cb(&reqFrame[4], &resFrame[3], regAddress, 1, MB_REG_WRITE);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
@@ -577,7 +538,7 @@ eMBException funcWriteMultipleCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
regAddress = u8v_to_u16(&reqFrame[2]);
|
||||
cntCoils = u8v_to_u16(&reqFrame[4]);
|
||||
ucByteCount = reqFrame[6];
|
||||
ucByteCountVerify = (cntCoils+7)/8;
|
||||
ucByteCountVerify = (cntCoils+BITS_UCHAR-1)/BITS_UCHAR;
|
||||
|
||||
if ((0 == cntCoils)
|
||||
||(cntCoils > MB_PDU_FUNC_WRITE_MUL_COILCNT_MAX)
|
||||
@@ -588,9 +549,9 @@ eMBException funcWriteMultipleCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
memcpy(resFrame, reqFrame, reqLen);
|
||||
*resLen = 6;
|
||||
|
||||
eRegStatus = eMBRegCoilsCB(reqFrame, &resFrame[3], regAddress, cntCoils, MB_REG_WRITE);
|
||||
eRegStatus = mb_reg_coils_cb(reqFrame, &resFrame[3], regAddress, cntCoils, MB_REG_WRITE);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
@@ -622,9 +583,9 @@ eMBException funcWriteMultipleHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t
|
||||
memcpy(resFrame, reqFrame, reqLen);
|
||||
*resLen = 6;
|
||||
|
||||
eRegStatus = eMBRegHoldingCB(reqFrame, &resFrame[3], regAddress, cntReg, MB_REG_WRITE);
|
||||
eRegStatus = mb_reg_holding_cb(reqFrame, &resFrame[3], regAddress, cntReg, MB_REG_WRITE);
|
||||
if (eRegStatus != MB_ENOERR) {
|
||||
eStatus = prveMBError2Exception(eRegStatus);
|
||||
eStatus = mb_error(eRegStatus);
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
@@ -654,8 +615,8 @@ static int chrg_comm_parse_msg (struct chrg_comm_t *pCOMM)
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (0 != usMBCRC16(pCOMM->rx_buf, pCOMM->rx_len)) {
|
||||
rt_kprintf("crc %04X ", usMBCRC16(pCOMM->rx_buf, pCOMM->rx_len-2));
|
||||
if (0 != mb_crc16(pCOMM->rx_buf, pCOMM->rx_len)) {
|
||||
rt_kprintf("crc %04X ", mb_crc16(pCOMM->rx_buf, pCOMM->rx_len-2));
|
||||
return -3;
|
||||
}
|
||||
|
||||
@@ -692,7 +653,7 @@ static int chrg_comm_parse_msg (struct chrg_comm_t *pCOMM)
|
||||
pCOMM->tx_len = 3;
|
||||
}
|
||||
|
||||
crc = usMBCRC16(pCOMM->tx_buf, pCOMM->tx_len);
|
||||
crc = mb_crc16(pCOMM->tx_buf, pCOMM->tx_len);
|
||||
u16_to_u8v(crc, &pCOMM->tx_buf[pCOMM->tx_len]);
|
||||
pCOMM->tx_len += 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user