Fix nxstyle warning

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-03-20 01:25:22 +08:00 committed by patacongo
parent 86080a110e
commit f3c104b99a
6 changed files with 55 additions and 33 deletions

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* apps/examples/modbus/main.c * apps/examples/modbus/modbus_main.c
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@ -140,7 +140,10 @@ static void modbus_showusage(FAR const char *progname, int exitcode);
****************************************************************************/ ****************************************************************************/
static struct modbus_state_s g_modbus; static struct modbus_state_s g_modbus;
static const uint8_t g_slaveid[] = { 0xaa, 0xbb, 0xcc }; static const uint8_t g_slaveid[] =
{
0xaa, 0xbb, 0xcc
};
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -191,7 +194,8 @@ static inline int modbus_initialize(void)
*/ */
mberr = eMBInit(MB_RTU, 0x0a, CONFIG_EXAMPLES_MODBUS_PORT, mberr = eMBInit(MB_RTU, 0x0a, CONFIG_EXAMPLES_MODBUS_PORT,
CONFIG_EXAMPLES_MODBUS_BAUD, CONFIG_EXAMPLES_MODBUS_PARITY); CONFIG_EXAMPLES_MODBUS_BAUD,
CONFIG_EXAMPLES_MODBUS_PARITY);
if (mberr != MB_ENOERR) if (mberr != MB_ENOERR)
{ {
fprintf(stderr, "modbus_main: " fprintf(stderr, "modbus_main: "
@ -231,6 +235,7 @@ static inline int modbus_initialize(void)
return OK; return OK;
errout_with_modbus: errout_with_modbus:
/* Release hardware resources. */ /* Release hardware resources. */
eMBClose(); eMBClose();
@ -376,7 +381,8 @@ static inline int modbus_create_pollthread(void)
if (g_modbus.threadstate == STOPPED) if (g_modbus.threadstate == STOPPED)
{ {
ret = pthread_create(&g_modbus.threadid, NULL, modbus_pollthread, NULL); ret = pthread_create(&g_modbus.threadid, NULL,
modbus_pollthread, NULL);
} }
else else
{ {
@ -444,7 +450,8 @@ int main(int argc, FAR char *argv[])
if (ret != OK) if (ret != OK)
{ {
fprintf(stderr, "modbus_main: " fprintf(stderr, "modbus_main: "
"ERROR: modbus_create_pollthread failed: %d\n", ret); "ERROR: modbus_create_pollthread failed: %d\n",
ret);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -536,8 +543,8 @@ eMBErrorCode eMBRegInputCB(uint8_t *buffer, uint16_t address, uint16_t nregs)
* *
****************************************************************************/ ****************************************************************************/
eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs, eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address,
eMBRegisterMode mode) uint16_t nregs, eMBRegisterMode mode)
{ {
eMBErrorCode mberr = MB_ENOERR; eMBErrorCode mberr = MB_ENOERR;
int index; int index;
@ -551,6 +558,7 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
switch (mode) switch (mode)
{ {
/* Pass current register values to the protocol stack. */ /* Pass current register values to the protocol stack. */
case MB_REG_READ: case MB_REG_READ:
while (nregs > 0) while (nregs > 0)
{ {
@ -592,8 +600,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
* *
****************************************************************************/ ****************************************************************************/
eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, uint16_t ncoils, eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address,
eMBRegisterMode mode) uint16_t ncoils, eMBRegisterMode mode)
{ {
eMBErrorCode mberr = MB_ENOERR; eMBErrorCode mberr = MB_ENOERR;
int index; int index;
@ -649,7 +657,8 @@ eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, uint16_t ncoils,
* *
****************************************************************************/ ****************************************************************************/
eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address, uint16_t ndiscrete) eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address,
uint16_t ndiscrete)
{ {
return MB_ENOREG; return MB_ENOREG;
} }

View File

@ -13,8 +13,8 @@
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
@ -69,20 +69,24 @@
struct FileStream struct FileStream
{ {
int dev,tty; int dev;
int tty;
int recLength; int recLength;
int infd; int infd;
char inBuf[1024]; char inBuf[1024];
size_t inSize,inCapacity; size_t inSize;
size_t inCapacity;
int outfd; int outfd;
int outPos; int outPos;
int outLineWidth; int outLineWidth;
int outColWidth; int outColWidth;
char outBuf[1024]; char outBuf[1024];
size_t outSize,outCapacity; size_t outSize;
int outforeground,outbackground; size_t outCapacity;
int outforeground;
int outbackground;
int randomfd; int randomfd;
int recPos; int recPos;

View File

@ -214,7 +214,8 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
} }
else if (tcgetattr(iSerialFd, &xOldTIO) != 0) else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
{ {
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n", vMBPortLog(MB_LOG_ERROR,
"SER-INIT", "Can't get settings from port %s: %d\n",
szDevice, errno); szDevice, errno);
} }
else else
@ -261,22 +262,24 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
* *
* (1) In NuttX, cfset[i|o]speed always return OK so failures will * (1) In NuttX, cfset[i|o]speed always return OK so failures will
* really only be reported when tcsetattr() is called. * really only be reported when tcsetattr() is called.
* (2) NuttX does not support separate input and output speeds so it * (2) NuttX does not support separate input and output speeds so
* is not necessary to call both cfsetispeed() and * it is not necessary to call both cfsetispeed() and
* cfsetospeed(), and * cfsetospeed(), and
* (3) In NuttX, the input value to cfiset[i|o]speed is not * (3) In NuttX, the input value to cfiset[i|o]speed is not
* encoded, but is the absolute baud value. The following might * encoded, but is the absolute baud value. The following
* not be * might not be
*/ */
if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */) if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */)
{ {
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n", vMBPortLog(MB_LOG_ERROR, "SER-INIT",
"Can't set baud rate %ld for port %s: %d\n",
ulBaudRate, szDevice, errno); ulBaudRate, szDevice, errno);
} }
else if (tcsetattr(iSerialFd, TCSANOW, &xNewTIO) != 0) else if (tcsetattr(iSerialFd, TCSANOW, &xNewTIO) != 0)
{ {
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set settings for port %s: %d\n", vMBPortLog(MB_LOG_ERROR,
"SER-INIT", "Can't set settings for port %s: %d\n",
szDevice, errno); szDevice, errno);
} }
else else
@ -344,7 +347,8 @@ bool xMBPortSerialPoll(void)
} }
else else
{ {
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "read failed on serial device: %d\n", vMBPortLog(MB_LOG_ERROR,
"SER-POLL", "read failed on serial device: %d\n",
errno); errno);
bStatus = false; bStatus = false;
} }
@ -361,7 +365,8 @@ bool xMBPortSerialPoll(void)
if (!prvbMBPortSerialWrite(&ucBuffer[0], uiTxBufferPos)) if (!prvbMBPortSerialWrite(&ucBuffer[0], uiTxBufferPos))
{ {
vMBPortLog(MB_LOG_ERROR, "SER-POLL", "write failed on serial device: %d\n", vMBPortLog(MB_LOG_ERROR,
"SER-POLL", "write failed on serial device: %d\n",
errno); errno);
bStatus = false; bStatus = false;
} }

View File

@ -87,7 +87,8 @@ static struct termios xOldTIO;
static bool prvbMBMasterPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes, static bool prvbMBMasterPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes,
uint16_t *usNBytesRead); uint16_t *usNBytesRead);
static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes); static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer,
uint16_t usNBytes);
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -142,7 +143,8 @@ static bool prvbMBMasterPortSerialRead(uint8_t *pucBuffer, uint16_t usNBytes,
return bResult; return bResult;
} }
static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer, uint16_t usNBytes) static bool prvbMBMasterPortSerialWrite(uint8_t *pucBuffer,
uint16_t usNBytes)
{ {
ssize_t res; ssize_t res;
size_t left = (size_t) usNBytes; size_t left = (size_t) usNBytes;
@ -268,12 +270,12 @@ bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
* *
* (1) In NuttX, cfset[i|o]speed always return OK so failures will * (1) In NuttX, cfset[i|o]speed always return OK so failures will
* really only be reported when tcsetattr() is called. * really only be reported when tcsetattr() is called.
* (2) NuttX does not support separate input and output speeds so it * (2) NuttX does not support separate input and output speeds so
* is not necessary to call both cfsetispeed() and * it is not necessary to call both cfsetispeed() and
* cfsetospeed(), and * cfsetospeed(), and
* (3) In NuttX, the input value to cfiset[i|o]speed is not * (3) In NuttX, the input value to cfiset[i|o]speed is not
* encoded, but is the absolute baud value. The following might * encoded, but is the absolute baud value. The following
* not be * might not be
*/ */
if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */) if (cfsetispeed(&xNewTIO, ulBaudRate) != 0 /* || cfsetospeed(&xNewTIO, ulBaudRate) != 0 */)
@ -313,7 +315,7 @@ bool xMBMasterPortSerialSetTimeout(uint32_t ulNewTimeoutMs)
return true; return true;
} }
void vMBMasterPortClose( void ) void vMBMasterPortClose(void)
{ {
if (iSerialFd != -1) if (iSerialFd != -1)
{ {
@ -323,7 +325,7 @@ void vMBMasterPortClose( void )
} }
} }
bool xMBMasterPortSerialPoll( void ) bool xMBMasterPortSerialPoll(void)
{ {
bool bStatus = true; bool bStatus = true;
uint16_t usBytesRead; uint16_t usBytesRead;

View File

@ -160,6 +160,7 @@ errout_with_zmodem:
zmr_release(handle); zmr_release(handle);
errout_with_device: errout_with_device:
/* Flush the serial output to assure do not hang trying to drain it */ /* Flush the serial output to assure do not hang trying to drain it */
tcflush(fd, TCIOFLUSH); tcflush(fd, TCIOFLUSH);

View File

@ -260,6 +260,7 @@ errout_with_zmodem:
zms_release(handle); zms_release(handle);
errout_with_device: errout_with_device:
/* Flush the serial output to assure do not hang trying to drain it */ /* Flush the serial output to assure do not hang trying to drain it */
tcflush(fd, TCIOFLUSH); tcflush(fd, TCIOFLUSH);