summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-11-25 15:14:28 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-11-25 15:14:28 -0600
commit6b0412f5128e2fdf94852de586b3f90cbf476240 (patch)
tree91ab0edfb4492a25abf3c7e177e102201a77b23f
parentb845f19a3bb200e49a7a314787b3290e3155ce01 (diff)
downloadnuttx-6b0412f5128e2fdf94852de586b3f90cbf476240.tar.gz
nuttx-6b0412f5128e2fdf94852de586b3f90cbf476240.tar.bz2
nuttx-6b0412f5128e2fdf94852de586b3f90cbf476240.zip
Fixes for more cppcheck complaints. Mostly cosmetic
-rw-r--r--apps/graphics/screenshot/screenshot_main.c9
-rw-r--r--apps/interpreters/bas/bas_auto.c12
-rw-r--r--apps/interpreters/bas/bas_program.c1
-rw-r--r--apps/interpreters/bas/bas_statement.c4
-rw-r--r--apps/interpreters/bas/bas_token.c407
-rw-r--r--apps/modbus/functions/mbfuncholding.c159
-rw-r--r--apps/modbus/mb.c115
-rw-r--r--apps/modbus/rtu/mbrtu.c135
8 files changed, 424 insertions, 418 deletions
diff --git a/apps/graphics/screenshot/screenshot_main.c b/apps/graphics/screenshot/screenshot_main.c
index eb4b6d74e..5bc74867c 100644
--- a/apps/graphics/screenshot/screenshot_main.c
+++ b/apps/graphics/screenshot/screenshot_main.c
@@ -119,8 +119,7 @@ int save_screenshot(FAR const char *filename)
{
struct tiff_info_s info;
FAR uint8_t *strip;
- int x;
- int y;
+ int row;
int ret;
char tempf1[64];
char tempf2[64];
@@ -188,15 +187,15 @@ int save_screenshot(FAR const char *filename)
strip = malloc(size.w * 3);
- for (int y = 0; y < size.h; y++)
+ for (row = 0; row < size.h; row++)
{
- struct nxgl_rect_s rect = {{0, y}, {size.w - 1, y}};
+ struct nxgl_rect_s rect = {{0, row}, {size.w - 1, row}};
nx_getrectangle(window, &rect, 0, strip, 0);
ret = tiff_addstrip(&info, strip);
if (ret < 0)
{
- printf("tiff_addstrip() #%d failed: %d\n", y, ret);
+ printf("tiff_addstrip() #%d failed: %d\n", row, ret);
break;
}
}
diff --git a/apps/interpreters/bas/bas_auto.c b/apps/interpreters/bas/bas_auto.c
index 016596c1e..a27481145 100644
--- a/apps/interpreters/bas/bas_auto.c
+++ b/apps/interpreters/bas/bas_auto.c
@@ -190,7 +190,9 @@ struct Var *Auto_local(struct Auto *this, int l)
int Auto_funcReturn(struct Auto *this, struct Pc *pc)
{
- int i, retFrame, retException;
+ int retException;
+ int retFrame;
+ int i;
if (this->stackPointer == 0)
{
@@ -236,8 +238,11 @@ int Auto_gosubReturn(struct Auto *this, struct Pc *pc)
void Auto_frameToError(struct Auto *this, struct Program *program, struct Value *v)
{
- int i = this->stackPointer, framePointer, frameSize, retFrame;
struct Pc p;
+ int framePointer;
+ int frameSize,;
+ int retFrame;
+ int i = this->stackPointer;
framePointer = this->framePointer;
frameSize = this->frameSize;
@@ -251,10 +256,7 @@ void Auto_frameToError(struct Auto *this, struct Program *program, struct Value
if (i)
{
retFrame = framePointer + frameSize - 1;
- i = framePointer;
p = this->slot[retFrame].retFrame.pc;
- frameSize = this->slot[retFrame].retFrame.frameSize;
- framePointer = this->slot[retFrame].retFrame.framePointer;
Value_errorSuffix(v, _("Proc Called"));
Program_PCtoError(program, &p, v);
}
diff --git a/apps/interpreters/bas/bas_program.c b/apps/interpreters/bas/bas_program.c
index ead14e52f..f132c7b27 100644
--- a/apps/interpreters/bas/bas_program.c
+++ b/apps/interpreters/bas/bas_program.c
@@ -1121,6 +1121,5 @@ void Program_xref(struct Program *this, int chn)
FS_putChars(chn, _("Goto Referenced in line\n"));
Xref_print(goto_, printLine, this, chn);
Xref_destroy(goto_);
- nl = 1;
}
}
diff --git a/apps/interpreters/bas/bas_statement.c b/apps/interpreters/bas/bas_statement.c
index 051d66295..4d72c25e9 100644
--- a/apps/interpreters/bas/bas_statement.c
+++ b/apps/interpreters/bas/bas_statement.c
@@ -836,7 +836,7 @@ struct Value *stmt_DELETE(struct Value *value)
else if (f == 1)
{
to = from;
- t = 1;
+ t = 1;
}
if (!f && !t)
@@ -2415,7 +2415,7 @@ struct Value *stmt_LIST_LLIST(struct Value *value)
else if (f == 1)
{
to = from;
- t = 1;
+ t = 1;
}
if (g_pass == INTERPRET)
diff --git a/apps/interpreters/bas/bas_token.c b/apps/interpreters/bas/bas_token.c
index 8c0e39aa8..dc33ad7a8 100644
--- a/apps/interpreters/bas/bas_token.c
+++ b/apps/interpreters/bas/bas_token.c
@@ -135,7 +135,7 @@ typedef unsigned int flex_uint32_t;
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart(yyin )
+#define YY_NEW_FILE yyrestart(yyin)
#define YY_END_OF_BUFFER_CHAR 0
@@ -189,9 +189,9 @@ extern FILE *yyin, *yyout;
(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
- while ( 0 )
+ while (0)
-#define unput(c) yyunput( c, (yytext_ptr) )
+#define unput(c) yyunput(c, (yytext_ptr))
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
@@ -269,7 +269,7 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
*
* Returns the top of the stack, or NULL.
*/
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+#define YY_CURRENT_BUFFER ((yy_buffer_stack) \
? (yy_buffer_stack)[(yy_buffer_stack_top)] \
: NULL)
@@ -293,46 +293,46 @@ static int yy_start = 0; /* start state number */
*/
static int yy_did_buffer_switch_on_eof;
-void yyrestart (FILE *input_file );
-void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE yy_create_buffer (FILE *file,int size );
-void yy_delete_buffer (YY_BUFFER_STATE b );
-void yy_flush_buffer (YY_BUFFER_STATE b );
-void yypush_buffer_state (YY_BUFFER_STATE new_buffer );
-void yypop_buffer_state (void );
+void yyrestart (FILE *input_file);
+void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer);
+YY_BUFFER_STATE yy_create_buffer (FILE *file,int size);
+void yy_delete_buffer (YY_BUFFER_STATE b);
+void yy_flush_buffer (YY_BUFFER_STATE b);
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer);
+void yypop_buffer_state (void);
-static void yyensure_buffer_stack (void );
-static void yy_load_buffer_state (void );
-static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
+static void yyensure_buffer_stack (void);
+static void yy_load_buffer_state (void);
+static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file);
-#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )
+#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER)
-YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
-YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len );
+YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size);
+YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str);
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len);
-void *yyalloc (yy_size_t );
-void *yyrealloc (void *,yy_size_t );
-void yyfree (void * );
+void *yyalloc (yy_size_t);
+void *yyrealloc (void *,yy_size_t);
+void yyfree (void *);
#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
- if ( ! YY_CURRENT_BUFFER ){ \
+ if (! YY_CURRENT_BUFFER){ \
yyensure_buffer_stack (); \
YY_CURRENT_BUFFER_LVALUE = \
- yy_create_buffer(yyin,YY_BUF_SIZE ); \
+ yy_create_buffer(yyin,YY_BUF_SIZE); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
}
#define yy_set_bol(at_bol) \
{ \
- if ( ! YY_CURRENT_BUFFER ){\
+ if (! YY_CURRENT_BUFFER){\
yyensure_buffer_stack (); \
YY_CURRENT_BUFFER_LVALUE = \
- yy_create_buffer(yyin,YY_BUF_SIZE ); \
+ yy_create_buffer(yyin,YY_BUF_SIZE); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
}
@@ -357,10 +357,10 @@ int yylineno = 1;
extern char *yytext;
#define yytext_ptr yytext
-static yy_state_type yy_get_previous_state (void );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
-static int yy_get_next_buffer (void );
-static void yy_fatal_error (yyconst char msg[] );
+static yy_state_type yy_get_previous_state (void);
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state);
+static int yy_get_next_buffer (void);
+static void yy_fatal_error (yyconst char msg[]);
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -1474,36 +1474,36 @@ static void string2(void) /*{{{*/
#define YY_EXTRA_TYPE void *
#endif
-static int yy_init_globals (void );
+static int yy_init_globals (void);
/* Accessor methods to globals.
These are made visible to non-reentrant scanners for convenience. */
-int yylex_destroy (void );
+int yylex_destroy (void);
-int yyget_debug (void );
+int yyget_debug (void);
-void yyset_debug (int debug_flag );
+void yyset_debug (int debug_flag);
-YY_EXTRA_TYPE yyget_extra (void );
+YY_EXTRA_TYPE yyget_extra (void);
-void yyset_extra (YY_EXTRA_TYPE user_defined );
+void yyset_extra (YY_EXTRA_TYPE user_defined);
-FILE *yyget_in (void );
+FILE *yyget_in (void);
-void yyset_in (FILE * in_str );
+void yyset_in (FILE * in_str);
-FILE *yyget_out (void );
+FILE *yyget_out (void);
-void yyset_out (FILE * out_str );
+void yyset_out (FILE * out_str);
-yy_size_t yyget_leng (void );
+yy_size_t yyget_leng (void);
-char *yyget_text (void );
+char *yyget_text (void);
-int yyget_lineno (void );
+int yyget_lineno (void);
-void yyset_lineno (int line_number );
+void yyset_lineno (int line_number);
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -1511,26 +1511,26 @@ void yyset_lineno (int line_number );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int yywrap (void );
+extern "C" int yywrap (void);
#else
-extern int yywrap (void );
+extern int yywrap (void);
#endif
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int );
+static void yy_flex_strncpy (char *,yyconst char *,int);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * );
+static int yy_flex_strlen (yyconst char *);
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
-static int yyinput (void );
+static int yyinput (void);
#else
-static int input (void );
+static int input (void);
#endif
#endif
@@ -1550,7 +1550,7 @@ static int input (void );
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO do { if (fwrite(yytext, yyleng, 1, yyout)) {} } while (0)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@@ -1558,27 +1558,27 @@ static int input (void );
*/
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) \
{ \
int c = '*'; \
size_t n; \
- for ( n = 0; n < max_size && \
- (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ for (n = 0; n < max_size && \
+ (c = getc(yyin)) != EOF && c != '\n'; ++n) \
buf[n] = (char) c; \
- if ( c == '\n' ) \
+ if (c == '\n') \
buf[n++] = (char) c; \
- if ( c == EOF && ferror( yyin ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ if (c == EOF && ferror(yyin)) \
+ YY_FATAL_ERROR("input in flex scanner failed"); \
result = n; \
} \
else \
{ \
errno=0; \
- while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ((result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
{ \
- if( errno != EINTR) \
+ if(errno != EINTR) \
{ \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ YY_FATAL_ERROR("input in flex scanner failed"); \
break; \
} \
errno=0; \
@@ -1604,7 +1604,7 @@ static int input (void );
/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#define YY_FATAL_ERROR(msg) yy_fatal_error(msg)
#endif
/* end tables serialization structures and prototypes */
@@ -1643,7 +1643,7 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
- if ( !(yy_init) )
+ if (!(yy_init))
{
(yy_init) = 1;
@@ -1651,22 +1651,22 @@ YY_DECL
YY_USER_INIT;
#endif
- if ( ! (yy_start) )
+ if (! (yy_start))
(yy_start) = 1; /* first start state */
- if ( ! yyin )
+ if (! yyin)
yyin = stdin;
- if ( ! yyout )
+ if (! yyout)
yyout = stdout;
- if ( ! YY_CURRENT_BUFFER ) {
+ if (! YY_CURRENT_BUFFER) {
yyensure_buffer_stack ();
YY_CURRENT_BUFFER_LVALUE =
- yy_create_buffer(yyin,YY_BUF_SIZE );
+ yy_create_buffer(yyin,YY_BUF_SIZE);
}
- yy_load_buffer_state( );
+ yy_load_buffer_state();
}
{
@@ -1677,7 +1677,7 @@ YY_DECL
#line 1683 "<stdout>"
- while ( 1 ) /* loops until end-of-file is reached */
+ while (1) /* loops until end-of-file is reached */
{
yy_cp = (yy_c_buf_p);
@@ -1694,25 +1694,25 @@ yy_match:
do
{
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
- if ( yy_accept[yy_current_state] )
+ if (yy_accept[yy_current_state])
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 701 )
+ if (yy_current_state >= 701)
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 3041 );
+ while (yy_base[yy_current_state] != 3041);
yy_find_action:
yy_act = yy_accept[yy_current_state];
- if ( yy_act == 0 )
+ if (yy_act == 0)
{ /* have to back up */
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
@@ -1723,7 +1723,7 @@ yy_find_action:
do_action: /* This label is used only to access EOF actions. */
- switch ( yy_act )
+ switch (yy_act)
{ /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
@@ -3719,7 +3719,7 @@ case YY_STATE_EOF(IMAGEFMT):
*yy_cp = (yy_hold_char);
YY_RESTORE_YY_MORE_OFFSET
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW)
{
/* We're scanning a new file or input source. It's
* possible that this happened because the user
@@ -3742,13 +3742,13 @@ case YY_STATE_EOF(IMAGEFMT):
* end-of-buffer state). Contrast this with the test
* in input().
*/
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ if ((yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)])
{ /* This was really a NUL. */
yy_state_type yy_next_state;
(yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
- yy_current_state = yy_get_previous_state( );
+ yy_current_state = yy_get_previous_state();
/* Okay, we're now positioned to make the NUL
* transition. We couldn't have
@@ -3759,11 +3759,11 @@ case YY_STATE_EOF(IMAGEFMT):
* will run more slowly).
*/
- yy_next_state = yy_try_NUL_trans( yy_current_state );
+ yy_next_state = yy_try_NUL_trans(yy_current_state);
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- if ( yy_next_state )
+ if (yy_next_state)
{
/* Consume the NUL. */
yy_cp = ++(yy_c_buf_p);
@@ -3778,13 +3778,13 @@ case YY_STATE_EOF(IMAGEFMT):
}
}
- else switch ( yy_get_next_buffer( ) )
+ else switch (yy_get_next_buffer())
{
case EOB_ACT_END_OF_FILE:
{
(yy_did_buffer_switch_on_eof) = 0;
- if ( yywrap( ) )
+ if (yywrap())
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -3803,7 +3803,7 @@ case YY_STATE_EOF(IMAGEFMT):
else
{
- if ( ! (yy_did_buffer_switch_on_eof) )
+ if (! (yy_did_buffer_switch_on_eof))
YY_NEW_FILE;
}
break;
@@ -3813,7 +3813,7 @@ case YY_STATE_EOF(IMAGEFMT):
(yy_c_buf_p) =
(yytext_ptr) + yy_amount_of_matched_text;
- yy_current_state = yy_get_previous_state( );
+ yy_current_state = yy_get_previous_state();
yy_cp = (yy_c_buf_p);
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
@@ -3823,7 +3823,7 @@ case YY_STATE_EOF(IMAGEFMT):
(yy_c_buf_p) =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
- yy_current_state = yy_get_previous_state( );
+ yy_current_state = yy_get_previous_state();
yy_cp = (yy_c_buf_p);
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
@@ -3834,7 +3834,7 @@ case YY_STATE_EOF(IMAGEFMT):
default:
YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
+ "fatal flex scanner internal error--no action found");
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
@@ -3849,18 +3849,19 @@ case YY_STATE_EOF(IMAGEFMT):
*/
static int yy_get_next_buffer (void)
{
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
register char *source = (yytext_ptr);
- register int number_to_move, i;
+ register int number_to_move;
+ register int i;
int ret_val;
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ if ((yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1])
YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
+ "fatal flex scanner internal error--end of buffer missed");
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0)
{ /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ if ((yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1)
{
/* We matched a single character, the EOB, so
* treat this as a final EOF.
@@ -3882,10 +3883,10 @@ static int yy_get_next_buffer (void)
/* First move last chars to start of buffer. */
number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
- for ( i = 0; i < number_to_move; ++i )
+ for (i = 0; i < number_to_move; ++i)
*(dest++) = *(source++);
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING)
/* don't do the read, it's not guaranteed to return an EOF,
* just force an EOF
*/
@@ -3896,7 +3897,7 @@ static int yy_get_next_buffer (void)
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
- while ( num_to_read <= 0 )
+ while (num_to_read < 1)
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
@@ -3905,26 +3906,26 @@ static int yy_get_next_buffer (void)
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
- if ( b->yy_is_our_buffer )
+ if (b->yy_is_our_buffer)
{
yy_size_t new_size = b->yy_buf_size * 2;
- if ( new_size <= 0 )
+ if (new_size < 1)
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
- yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2);
}
else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
- if ( ! b->yy_ch_buf )
+ if (! b->yy_ch_buf)
YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
+ "fatal error - scanner input buffer overflow");
(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
@@ -3933,22 +3934,22 @@ static int yy_get_next_buffer (void)
}
- if ( num_to_read > YY_READ_BUF_SIZE )
+ if (num_to_read > YY_READ_BUF_SIZE)
num_to_read = YY_READ_BUF_SIZE;
/* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), num_to_read );
+ YY_INPUT((&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
- if ( (yy_n_chars) == 0 )
+ if ((yy_n_chars) == 0)
{
- if ( number_to_move == YY_MORE_ADJ )
+ if (number_to_move == YY_MORE_ADJ)
{
ret_val = EOB_ACT_END_OF_FILE;
- yyrestart(yyin );
+ yyrestart(yyin);
}
else
@@ -3965,9 +3966,9 @@ static int yy_get_next_buffer (void)
if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, new_size);
+ if (! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()");
}
(yy_n_chars) += number_to_move;
@@ -3988,18 +3989,18 @@ static int yy_get_next_buffer (void)
yy_current_state = (yy_start);
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ for (yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp)
{
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
- if ( yy_accept[yy_current_state] )
+ if (yy_accept[yy_current_state])
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 701 )
+ if (yy_current_state >= 701)
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -4011,23 +4012,23 @@ static int yy_get_next_buffer (void)
/* yy_try_NUL_trans - try to make a transition on the NUL character
*
* synopsis
- * next_state = yy_try_NUL_trans( current_state );
+ * next_state = yy_try_NUL_trans(current_state);
*/
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state)
{
register int yy_is_jam;
register char *yy_cp = (yy_c_buf_p);
register YY_CHAR yy_c = 1;
- if ( yy_accept[yy_current_state] )
+ if (yy_accept[yy_current_state])
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 701 )
+ if (yy_current_state >= 701)
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -4048,13 +4049,13 @@ static int yy_get_next_buffer (void)
*(yy_c_buf_p) = (yy_hold_char);
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ if (*(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR)
{
/* yy_c_buf_p now points to the character we want to return.
* If this occurs *before* the EOB characters, then it's a
* valid NUL; if not, then we've hit the end of the buffer.
*/
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ if ((yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)])
/* This was really a NUL. */
*(yy_c_buf_p) = '\0';
@@ -4063,7 +4064,7 @@ static int yy_get_next_buffer (void)
yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p);
- switch ( yy_get_next_buffer( ) )
+ switch (yy_get_next_buffer())
{
case EOB_ACT_LAST_MATCH:
/* This happens because yy_g_n_b()
@@ -4077,16 +4078,16 @@ static int yy_get_next_buffer (void)
*/
/* Reset buffer status. */
- yyrestart(yyin );
+ yyrestart(yyin);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( yywrap( ) )
+ if (yywrap())
return EOF;
- if ( ! (yy_did_buffer_switch_on_eof) )
+ if (! (yy_did_buffer_switch_on_eof))
YY_NEW_FILE;
#ifdef __cplusplus
return yyinput();
@@ -4115,24 +4116,24 @@ static int yy_get_next_buffer (void)
*
* @note This function does not reset the start condition to @c INITIAL .
*/
- void yyrestart (FILE * input_file )
+ void yyrestart (FILE * input_file)
{
- if ( ! YY_CURRENT_BUFFER ){
+ if (! YY_CURRENT_BUFFER){
yyensure_buffer_stack ();
YY_CURRENT_BUFFER_LVALUE =
- yy_create_buffer(yyin,YY_BUF_SIZE );
+ yy_create_buffer(yyin,YY_BUF_SIZE);
}
- yy_init_buffer(YY_CURRENT_BUFFER,input_file );
- yy_load_buffer_state( );
+ yy_init_buffer(YY_CURRENT_BUFFER,input_file);
+ yy_load_buffer_state();
}
/** Switch to a different input buffer.
* @param new_buffer The new input buffer.
*
*/
- void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer)
{
/* TODO. We should be able to replace this entire function body
@@ -4141,10 +4142,10 @@ static int yy_get_next_buffer (void)
* yypush_buffer_state(new_buffer);
*/
yyensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
+ if (YY_CURRENT_BUFFER == new_buffer)
return;
- if ( YY_CURRENT_BUFFER )
+ if (YY_CURRENT_BUFFER)
{
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
@@ -4153,7 +4154,7 @@ static int yy_get_next_buffer (void)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- yy_load_buffer_state( );
+ yy_load_buffer_state();
/* We don't actually know whether we did this switch during
* EOF (yywrap()) processing, but the only time this flag
@@ -4177,26 +4178,26 @@ static void yy_load_buffer_state (void)
*
* @return the allocated buffer state.
*/
- YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size)
{
YY_BUFFER_STATE b;
- b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+ b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state));
+ if (! b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
*/
- b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+ b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2);
+ if (! b->yy_ch_buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
b->yy_is_our_buffer = 1;
- yy_init_buffer(b,file );
+ yy_init_buffer(b,file);
return b;
}
@@ -4205,19 +4206,19 @@ static void yy_load_buffer_state (void)
* @param b a buffer created with yy_create_buffer()
*
*/
- void yy_delete_buffer (YY_BUFFER_STATE b )
+ void yy_delete_buffer (YY_BUFFER_STATE b)
{
- if ( ! b )
+ if (! b)
return;
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
- if ( b->yy_is_our_buffer )
- yyfree((void *) b->yy_ch_buf );
+ if (b->yy_is_our_buffer)
+ yyfree((void *) b->yy_ch_buf);
- yyfree((void *) b );
+ yyfree((void *) b);
}
/* Initializes or reinitializes a buffer.
@@ -4225,11 +4226,11 @@ static void yy_load_buffer_state (void)
* such as during a yyrestart() or at EOF.
*/
-static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
+static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file)
{
int oerrno = errno;
- yy_flush_buffer(b );
+ yy_flush_buffer(b);
b->yy_input_file = file;
b->yy_fill_buffer = 1;
@@ -4246,7 +4247,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
}
#ifdef CONFIG_SERIAL_TERMIOS
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+ b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0;
#else
b->yy_is_interactive = 1;
#endif
@@ -4258,9 +4259,9 @@ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
* @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
*
*/
- void yy_flush_buffer (YY_BUFFER_STATE b )
+ void yy_flush_buffer (YY_BUFFER_STATE b)
{
- if ( ! b )
+ if (! b)
return;
b->yy_n_chars = 0;
@@ -4277,8 +4278,8 @@ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
b->yy_at_bol = 1;
b->yy_buffer_status = YY_BUFFER_NEW;
- if ( b == YY_CURRENT_BUFFER )
- yy_load_buffer_state( );
+ if (b == YY_CURRENT_BUFFER)
+ yy_load_buffer_state();
}
/** Pushes the new state onto the stack. The new state becomes
@@ -4287,7 +4288,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
* @param new_buffer The new state.
*
*/
-void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer)
{
if (new_buffer == NULL)
return;
@@ -4295,7 +4296,7 @@ void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
yyensure_buffer_stack();
/* This block is copied from yy_switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
+ if (YY_CURRENT_BUFFER)
{
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
@@ -4309,7 +4310,7 @@ void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
YY_CURRENT_BUFFER_LVALUE = new_buffer;
/* copied from yy_switch_to_buffer. */
- yy_load_buffer_state( );
+ yy_load_buffer_state();
(yy_did_buffer_switch_on_eof) = 1;
}
@@ -4322,13 +4323,13 @@ void yypop_buffer_state (void)
if (!YY_CURRENT_BUFFER)
return;
- yy_delete_buffer(YY_CURRENT_BUFFER );
+ yy_delete_buffer(YY_CURRENT_BUFFER);
YY_CURRENT_BUFFER_LVALUE = NULL;
if ((yy_buffer_stack_top) > 0)
--(yy_buffer_stack_top);
if (YY_CURRENT_BUFFER) {
- yy_load_buffer_state( );
+ yy_load_buffer_state();
(yy_did_buffer_switch_on_eof) = 1;
}
}
@@ -4348,10 +4349,9 @@ static void yyensure_buffer_stack (void)
*/
num_to_alloc = 1;
(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+ (num_to_alloc * sizeof(struct yy_buffer_state*));
+ if (! (yy_buffer_stack))
+ YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()");
memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -4368,10 +4368,9 @@ static void yyensure_buffer_stack (void)
num_to_alloc = (yy_buffer_stack_max) + grow_size;
(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+ num_to_alloc * sizeof(struct yy_buffer_state*));
+ if (! (yy_buffer_stack))
+ YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()");
/* zero only the new slots.*/
memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
@@ -4385,19 +4384,19 @@ static void yyensure_buffer_stack (void)
*
* @return the newly allocated buffer state object.
*/
-YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size)
{
YY_BUFFER_STATE b;
- if ( size < 2 ||
+ if (size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
+ base[size-1] != YY_END_OF_BUFFER_CHAR)
/* They forgot to leave room for the EOB's. */
return 0;
- b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+ b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state));
+ if (! b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()");
b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
b->yy_buf_pos = b->yy_ch_buf = base;
@@ -4409,7 +4408,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- yy_switch_to_buffer(b );
+ yy_switch_to_buffer(b);
return b;
}
@@ -4422,10 +4421,10 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
* @note If you want to scan bytes that may contain NUL values, then use
* yy_scan_bytes() instead.
*/
-YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
+YY_BUFFER_STATE yy_scan_string (yyconst char * yystr)
{
- return yy_scan_bytes(yystr,strlen(yystr) );
+ return yy_scan_bytes(yystr,strlen(yystr));
}
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
@@ -4435,7 +4434,7 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
*
* @return the newly allocated buffer state object.
*/
-YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
+YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len)
{
YY_BUFFER_STATE b;
char *buf;
@@ -4444,18 +4443,18 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
- buf = (char *) yyalloc(n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+ buf = (char *) yyalloc(n);
+ if (! buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()");
- for ( i = 0; i < _yybytes_len; ++i )
+ for (i = 0; i < _yybytes_len; ++i)
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
- b = yy_scan_buffer(buf,n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+ b = yy_scan_buffer(buf,n);
+ if (! b)
+ YY_FATAL_ERROR("bad buffer in yy_scan_bytes()");
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -4469,10 +4468,10 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len
#define YY_EXIT_FAILURE 2
#endif
-static void yy_fatal_error (yyconst char* msg )
+static void yy_fatal_error (yyconst char* msg)
{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
+ (void) fprintf(stderr, "%s\n", msg);
+ exit(YY_EXIT_FAILURE);
}
/* Redefine yyless() so it works in section 3 code. */
@@ -4490,7 +4489,7 @@ static void yy_fatal_error (yyconst char* msg )
*(yy_c_buf_p) = '\0'; \
yyleng = yyless_macro_arg; \
} \
- while ( 0 )
+ while (0)
/* Accessor methods (get/set functions) to struct members. */
@@ -4540,7 +4539,7 @@ char *yyget_text (void)
* @param line_number
*
*/
-void yyset_lineno (int line_number )
+void yyset_lineno (int line_number)
{
yylineno = line_number;
@@ -4552,12 +4551,12 @@ void yyset_lineno (int line_number )
*
* @see yy_switch_to_buffer
*/
-void yyset_in (FILE * in_str )
+void yyset_in (FILE * in_str)
{
yyin = in_str ;
}
-void yyset_out (FILE * out_str )
+void yyset_out (FILE * out_str)
{
yyout = out_str ;
}
@@ -4567,7 +4566,7 @@ int yyget_debug (void)
return yy_flex_debug;
}
-void yyset_debug (int bdebug )
+void yyset_debug (int bdebug)
{
yy_flex_debug = bdebug ;
}
@@ -4606,18 +4605,18 @@ int yylex_destroy (void)
/* Pop the buffer stack, destroying each element. */
while(YY_CURRENT_BUFFER){
- yy_delete_buffer(YY_CURRENT_BUFFER );
+ yy_delete_buffer(YY_CURRENT_BUFFER);
YY_CURRENT_BUFFER_LVALUE = NULL;
yypop_buffer_state();
}
/* Destroy the stack itself. */
- yyfree((yy_buffer_stack) );
+ yyfree((yy_buffer_stack));
(yy_buffer_stack) = NULL;
/* Reset the globals. This is important in a non-reentrant scanner so the next time
* yylex() is called, initialization will occur. */
- yy_init_globals( );
+ yy_init_globals();
return 0;
}
@@ -4627,31 +4626,31 @@ int yylex_destroy (void)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n)
{
register int i;
- for ( i = 0; i < n; ++i )
+ for (i = 0; i < n; ++i)
s1[i] = s2[i];
}
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s )
+static int yy_flex_strlen (yyconst char * s)
{
register int n;
- for ( n = 0; s[n]; ++n )
+ for (n = 0; s[n]; ++n)
;
return n;
}
#endif
-void *yyalloc (yy_size_t size )
+void *yyalloc (yy_size_t size)
{
- return (void *) malloc( size );
+ return (void *) malloc(size);
}
-void *yyrealloc (void * ptr, yy_size_t size )
+void *yyrealloc (void * ptr, yy_size_t size)
{
/* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and those
@@ -4660,12 +4659,12 @@ void *yyrealloc (void * ptr, yy_size_t size )
* any pointer type to void*, and deal with argument conversions
* as though doing an assignment.
*/
- return (void *) realloc( (char *) ptr, size );
+ return (void *) realloc((char *) ptr, size);
}
-void yyfree (void * ptr )
+void yyfree (void * ptr)
{
- free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
+ free((char *) ptr); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
diff --git a/apps/modbus/functions/mbfuncholding.c b/apps/modbus/functions/mbfuncholding.c
index 7e0dee86b..28693d0f5 100644
--- a/apps/modbus/functions/mbfuncholding.c
+++ b/apps/modbus/functions/mbfuncholding.c
@@ -42,58 +42,58 @@
#include <apps/modbus/mbproto.h>
/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
-
-#define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_SIZE ( 4 )
-
-#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_FUNC_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
-#define MB_PDU_FUNC_WRITE_MUL_SIZE_MIN ( 5 )
-#define MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX ( 0x0078 )
-
-#define MB_PDU_FUNC_READWRITE_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF ( MB_PDU_DATA_OFF + 6 )
-#define MB_PDU_FUNC_READWRITE_BYTECNT_OFF ( MB_PDU_DATA_OFF + 8 )
-#define MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF ( MB_PDU_DATA_OFF + 9 )
-#define MB_PDU_FUNC_READWRITE_SIZE_MIN ( 9 )
+#define MB_PDU_FUNC_READ_ADDR_OFF (MB_PDU_DATA_OFF + 0)
+#define MB_PDU_FUNC_READ_REGCNT_OFF (MB_PDU_DATA_OFF + 2)
+#define MB_PDU_FUNC_READ_SIZE (4)
+#define MB_PDU_FUNC_READ_REGCNT_MAX (0x007D)
+
+#define MB_PDU_FUNC_WRITE_ADDR_OFF (MB_PDU_DATA_OFF + 0)
+#define MB_PDU_FUNC_WRITE_VALUE_OFF (MB_PDU_DATA_OFF + 2)
+#define MB_PDU_FUNC_WRITE_SIZE (4)
+
+#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF (MB_PDU_DATA_OFF + 0)
+#define MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF (MB_PDU_DATA_OFF + 2)
+#define MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF (MB_PDU_DATA_OFF + 4)
+#define MB_PDU_FUNC_WRITE_MUL_VALUES_OFF (MB_PDU_DATA_OFF + 5)
+#define MB_PDU_FUNC_WRITE_MUL_SIZE_MIN (5)
+#define MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX (0x0078)
+
+#define MB_PDU_FUNC_READWRITE_READ_ADDR_OFF (MB_PDU_DATA_OFF + 0)
+#define MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF (MB_PDU_DATA_OFF + 2)
+#define MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF (MB_PDU_DATA_OFF + 4)
+#define MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF (MB_PDU_DATA_OFF + 6)
+#define MB_PDU_FUNC_READWRITE_BYTECNT_OFF (MB_PDU_DATA_OFF + 8)
+#define MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF (MB_PDU_DATA_OFF + 9)
+#define MB_PDU_FUNC_READWRITE_SIZE_MIN (9)
/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
+eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
/* ----------------------- Start implementation -----------------------------*/
#ifdef CONFIG_MB_FUNC_WRITE_HOLDING_ENABLED
eMBException
-eMBFuncWriteHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
+eMBFuncWriteHoldingRegister(uint8_t * pucFrame, uint16_t * usLen)
{
uint16_t usRegAddress;
eMBException eStatus = MB_EX_NONE;
eMBErrorCode eRegStatus;
- if( *usLen == ( MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN ) )
+ if (*usLen == (MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN))
{
- usRegAddress = ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
- usRegAddress |= ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
+ usRegAddress = (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8);
+ usRegAddress |= (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1]);
usRegAddress++;
/* Make callback to update the value. */
- eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF],
- usRegAddress, 1, MB_REG_WRITE );
+ eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF],
+ usRegAddress, 1, MB_REG_WRITE);
/* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
+ if (eRegStatus != MB_ENOERR)
{
- eStatus = prveMBError2Exception( eRegStatus );
+ eStatus = prveMBError2Exception(eRegStatus);
}
}
else
@@ -107,7 +107,7 @@ eMBFuncWriteHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
eMBException
-eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
+eMBFuncWriteMultipleHoldingRegister(uint8_t * pucFrame, uint16_t * usLen)
{
uint16_t usRegAddress;
uint16_t usRegCount;
@@ -116,30 +116,31 @@ eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
eMBException eStatus = MB_EX_NONE;
eMBErrorCode eRegStatus;
- if( *usLen >= ( MB_PDU_FUNC_WRITE_MUL_SIZE_MIN + MB_PDU_SIZE_MIN ) )
+ if (*usLen >= (MB_PDU_FUNC_WRITE_MUL_SIZE_MIN + MB_PDU_SIZE_MIN))
{
- usRegAddress = ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8 );
- usRegAddress |= ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1] );
+ usRegAddress = (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8);
+ usRegAddress |= (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1]);
usRegAddress++;
- usRegCount = ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF] << 8 );
- usRegCount |= ( uint16_t )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF + 1] );
+ usRegCount = (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF] << 8);
+ usRegCount |= (uint16_t)(pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF + 1]);
ucRegByteCount = pucFrame[MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF];
- if( ( usRegCount >= 1 ) &&
- ( usRegCount <= MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX ) &&
- ( ucRegByteCount == ( uint8_t ) ( 2 * usRegCount ) ) )
+ if ((usRegCount >= 1) &&
+ (usRegCount <= MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX) &&
+ (ucRegByteCount == (uint8_t) (2 * usRegCount)))
{
/* Make callback to update the register values. */
eRegStatus =
- eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
- usRegAddress, usRegCount, MB_REG_WRITE );
+ eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
+ usRegAddress, usRegCount, MB_REG_WRITE);
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
+ /* If an error occurred convert it into a Modbus exception. */
+
+ if (eRegStatus != MB_ENOERR)
{
- eStatus = prveMBError2Exception( eRegStatus );
+ eStatus = prveMBError2Exception(eRegStatus);
}
else
{
@@ -147,6 +148,7 @@ eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
* address and the quantity of registers. We reuse the
* old values in the buffer because they are still valid.
*/
+
*usLen = MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF;
}
}
@@ -167,7 +169,7 @@ eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
#ifdef CONFIG_MB_FUNC_READ_HOLDING_ENABLED
eMBException
-eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
+eMBFuncReadHoldingRegister(uint8_t * pucFrame, uint16_t * usLen)
{
uint16_t usRegAddress;
uint16_t usRegCount;
@@ -176,19 +178,20 @@ eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
eMBException eStatus = MB_EX_NONE;
eMBErrorCode eRegStatus;
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
+ if (*usLen == (MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN))
{
- usRegAddress = ( uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( uint16_t )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
+ usRegAddress = (uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8);
+ usRegAddress |= (uint16_t)(pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1]);
usRegAddress++;
- usRegCount = ( uint16_t )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
- usRegCount = ( uint16_t )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
+ usRegCount = (uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8);
+ usRegCount |= (uint16_t)(pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1]);
/* Check if the number of registers to read is valid. If not
* return Modbus illegal data value exception.
*/
- if( ( usRegCount >= 1 ) && ( usRegCount <= MB_PDU_FUNC_READ_REGCNT_MAX ) )
+
+ if ((usRegCount >= 1) && (usRegCount <= MB_PDU_FUNC_READ_REGCNT_MAX))
{
/* Set the current PDU data pointer to the beginning. */
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
@@ -199,15 +202,15 @@ eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
*usLen += 1;
/* Second byte in the response contain the number of bytes. */
- *pucFrameCur++ = ( uint8_t ) ( usRegCount * 2 );
+ *pucFrameCur++ = (uint8_t) (usRegCount * 2);
*usLen += 1;
/* Make callback to fill the buffer. */
- eRegStatus = eMBRegHoldingCB( pucFrameCur, usRegAddress, usRegCount, MB_REG_READ );
+ eRegStatus = eMBRegHoldingCB(pucFrameCur, usRegAddress, usRegCount, MB_REG_READ);
/* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
+ if (eRegStatus != MB_ENOERR)
{
- eStatus = prveMBError2Exception( eRegStatus );
+ eStatus = prveMBError2Exception(eRegStatus);
}
else
{
@@ -232,7 +235,7 @@ eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
#ifdef CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED
eMBException
-eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
+eMBFuncReadWriteMultipleHoldingRegister(uint8_t * pucFrame, uint16_t * usLen)
{
uint16_t usRegReadAddress;
uint16_t usRegReadCount;
@@ -244,33 +247,33 @@ eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
eMBException eStatus = MB_EX_NONE;
eMBErrorCode eRegStatus;
- if( *usLen >= ( MB_PDU_FUNC_READWRITE_SIZE_MIN + MB_PDU_SIZE_MIN ) )
+ if (*usLen >= (MB_PDU_FUNC_READWRITE_SIZE_MIN + MB_PDU_SIZE_MIN))
{
- usRegReadAddress = ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF] << 8U );
- usRegReadAddress |= ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF + 1] );
+ usRegReadAddress = (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF] << 8U);
+ usRegReadAddress |= (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF + 1]);
usRegReadAddress++;
- usRegReadCount = ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF] << 8U );
- usRegReadCount |= ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF + 1] );
+ usRegReadCount = (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF] << 8U);
+ usRegReadCount |= (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF + 1]);
- usRegWriteAddress = ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF] << 8U );
- usRegWriteAddress |= ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF + 1] );
+ usRegWriteAddress = (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF] << 8U);
+ usRegWriteAddress |= (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF + 1]);
usRegWriteAddress++;
- usRegWriteCount = ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF] << 8U );
- usRegWriteCount |= ( uint16_t )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF + 1] );
+ usRegWriteCount = (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF] << 8U);
+ usRegWriteCount |= (uint16_t)(pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF + 1]);
ucRegWriteByteCount = pucFrame[MB_PDU_FUNC_READWRITE_BYTECNT_OFF];
- if( ( usRegReadCount >= 1 ) && ( usRegReadCount <= 0x7D ) &&
- ( usRegWriteCount >= 1 ) && ( usRegWriteCount <= 0x79 ) &&
- ( ( 2 * usRegWriteCount ) == ucRegWriteByteCount ) )
+ if ((usRegReadCount >= 1) && (usRegReadCount <= 0x7D) &&
+ (usRegWriteCount >= 1) && (usRegWriteCount <= 0x79) &&
+ ((2 * usRegWriteCount) == ucRegWriteByteCount))
{
/* Make callback to update the register values. */
- eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF],
- usRegWriteAddress, usRegWriteCount, MB_REG_WRITE );
+ eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF],
+ usRegWriteAddress, usRegWriteCount, MB_REG_WRITE);
- if( eRegStatus == MB_ENOERR )
+ if (eRegStatus == MB_ENOERR)
{
/* Set the current PDU data pointer to the beginning. */
pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
@@ -281,20 +284,20 @@ eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen )
*usLen += 1;
/* Second byte in the response contain the number of bytes. */
- *pucFrameCur++ = ( uint8_t ) ( usRegReadCount * 2 );
+ *pucFrameCur++ = (uint8_t) (usRegReadCount * 2);
*usLen += 1;
/* Make the read callback. */
eRegStatus =
- eMBRegHoldingCB( pucFrameCur, usRegReadAddress, usRegReadCount, MB_REG_READ );
- if( eRegStatus == MB_ENOERR )
+ eMBRegHoldingCB(pucFrameCur, usRegReadAddress, usRegReadCount, MB_REG_READ);
+ if (eRegStatus == MB_ENOERR)
{
*usLen += 2 * usRegReadCount;
}
}
- if( eRegStatus != MB_ENOERR )
+ if (eRegStatus != MB_ENOERR)
{
- eStatus = prveMBError2Exception( eRegStatus );
+ eStatus = prveMBError2Exception(eRegStatus);
}
}
else
diff --git a/apps/modbus/mb.c b/apps/modbus/mb.c
index a86ce343f..9cb0543d8 100644
--- a/apps/modbus/mb.c
+++ b/apps/modbus/mb.c
@@ -72,7 +72,7 @@ static enum
STATE_NOT_INITIALIZED
} eMBState = STATE_NOT_INITIALIZED;
-/* Functions pointer which are initialized in eMBInit( ). Depending on the
+/* Functions pointer which are initialized in eMBInit(). Depending on the
* mode (RTU or ASCII) the are set to the correct implementations.
*/
static peMBFrameSend peMBFrameSendCur;
@@ -85,12 +85,12 @@ static pvMBFrameClose pvMBFrameCloseCur;
* an external event has happend which includes a timeout or the reception
* or transmission of a character.
*/
-bool( *pxMBFrameCBByteReceived ) ( void );
-bool( *pxMBFrameCBTransmitterEmpty ) ( void );
-bool( *pxMBPortCBTimerExpired ) ( void );
+bool(*pxMBFrameCBByteReceived)(void);
+bool(*pxMBFrameCBTransmitterEmpty)(void);
+bool(*pxMBPortCBTimerExpired)(void);
-bool( *pxMBFrameCBReceiveFSMCur ) ( void );
-bool( *pxMBFrameCBTransmitFSMCur ) ( void );
+bool(*pxMBFrameCBReceiveFSMCur)(void);
+bool(*pxMBFrameCBTransmitFSMCur)(void);
/* An array of Modbus functions handlers which associates Modbus function
* codes with implementing functions.
@@ -130,13 +130,14 @@ static xMBFunctionHandler xFuncHandlers[CONFIG_MB_FUNC_HANDLERS_MAX] = {
/* ----------------------- Start implementation -----------------------------*/
eMBErrorCode
-eMBInit( eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity )
+eMBInit(eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity)
{
eMBErrorCode eStatus = MB_ENOERR;
/* check preconditions */
- if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
- ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
+
+ if ((ucSlaveAddress == MB_ADDRESS_BROADCAST) ||
+ (ucSlaveAddress < MB_ADDRESS_MIN) || (ucSlaveAddress > MB_ADDRESS_MAX))
{
eStatus = MB_EINVAL;
}
@@ -144,7 +145,7 @@ eMBInit( eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRa
{
ucMBAddress = ucSlaveAddress;
- switch ( eMode )
+ switch (eMode)
{
#ifdef CONFIG_MB_RTU_ENABLED
case MB_RTU:
@@ -157,7 +158,7 @@ eMBInit( eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRa
pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
- eStatus = eMBRTUInit( ucMBAddress, ucPort, ulBaudRate, eParity );
+ eStatus = eMBRTUInit(ucMBAddress, ucPort, ulBaudRate, eParity);
break;
#endif
#ifdef CONFIG_MB_ASCII_ENABLED
@@ -171,16 +172,16 @@ eMBInit( eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRa
pxMBFrameCBTransmitterEmpty = xMBASCIITransmitFSM;
pxMBPortCBTimerExpired = xMBASCIITimerT1SExpired;
- eStatus = eMBASCIIInit( ucMBAddress, ucPort, ulBaudRate, eParity );
+ eStatus = eMBASCIIInit(ucMBAddress, ucPort, ulBaudRate, eParity);
break;
#endif
default:
eStatus = MB_EINVAL;
}
- if( eStatus == MB_ENOERR )
+ if (eStatus == MB_ENOERR)
{
- if( !xMBPortEventInit( ) )
+ if (!xMBPortEventInit())
{
/* port dependent event module initalization failed. */
eStatus = MB_EPORTERR;
@@ -197,15 +198,15 @@ eMBInit( eMBMode eMode, uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRa
#ifdef CONFIG_MB_TCP_ENABLED
eMBErrorCode
-eMBTCPInit( uint16_t ucTCPPort )
+eMBTCPInit(uint16_t ucTCPPort)
{
eMBErrorCode eStatus = MB_ENOERR;
- if( ( eStatus = eMBTCPDoInit( ucTCPPort ) ) != MB_ENOERR )
+ if ((eStatus = eMBTCPDoInit(ucTCPPort)) != MB_ENOERR)
{
eMBState = STATE_DISABLED;
}
- else if( !xMBPortEventInit( ) )
+ else if (!xMBPortEventInit())
{
/* Port dependent event module initalization failed. */
eStatus = MB_EPORTERR;
@@ -226,33 +227,33 @@ eMBTCPInit( uint16_t ucTCPPort )
#endif
eMBErrorCode
-eMBRegisterCB( uint8_t ucFunctionCode, pxMBFunctionHandler pxHandler )
+eMBRegisterCB(uint8_t ucFunctionCode, pxMBFunctionHandler pxHandler)
{
int i;
eMBErrorCode eStatus;
- if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= 127 ) )
+ if ((0 < ucFunctionCode) && (ucFunctionCode <= 127))
{
- ENTER_CRITICAL_SECTION( );
- if( pxHandler != NULL )
+ ENTER_CRITICAL_SECTION();
+ if (pxHandler != NULL)
{
- for( i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++ )
+ for(i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++)
{
- if( ( xFuncHandlers[i].pxHandler == NULL ) ||
- ( xFuncHandlers[i].pxHandler == pxHandler ) )
+ if ((xFuncHandlers[i].pxHandler == NULL) ||
+ (xFuncHandlers[i].pxHandler == pxHandler))
{
xFuncHandlers[i].ucFunctionCode = ucFunctionCode;
xFuncHandlers[i].pxHandler = pxHandler;
break;
}
}
- eStatus = ( i != CONFIG_MB_FUNC_HANDLERS_MAX ) ? MB_ENOERR : MB_ENORES;
+ eStatus = (i != CONFIG_MB_FUNC_HANDLERS_MAX) ? MB_ENOERR : MB_ENORES;
}
else
{
- for( i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++ )
+ for(i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++)
{
- if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
+ if (xFuncHandlers[i].ucFunctionCode == ucFunctionCode)
{
xFuncHandlers[i].ucFunctionCode = 0;
xFuncHandlers[i].pxHandler = NULL;
@@ -262,7 +263,7 @@ eMBRegisterCB( uint8_t ucFunctionCode, pxMBFunctionHandler pxHandler )
/* Remove can't fail. */
eStatus = MB_ENOERR;
}
- EXIT_CRITICAL_SECTION( );
+ EXIT_CRITICAL_SECTION();
}
else
{
@@ -273,15 +274,15 @@ eMBRegisterCB( uint8_t ucFunctionCode, pxMBFunctionHandler pxHandler )
eMBErrorCode
-eMBClose( void )
+eMBClose(void)
{
eMBErrorCode eStatus = MB_ENOERR;
- if( eMBState == STATE_DISABLED )
+ if (eMBState == STATE_DISABLED)
{
- if( pvMBFrameCloseCur != NULL )
+ if (pvMBFrameCloseCur != NULL)
{
- pvMBFrameCloseCur( );
+ pvMBFrameCloseCur();
}
}
else
@@ -292,14 +293,14 @@ eMBClose( void )
}
eMBErrorCode
-eMBEnable( void )
+eMBEnable(void)
{
eMBErrorCode eStatus = MB_ENOERR;
- if( eMBState == STATE_DISABLED )
+ if (eMBState == STATE_DISABLED)
{
/* Activate the protocol stack. */
- pvMBFrameStartCur( );
+ pvMBFrameStartCur();
eMBState = STATE_ENABLED;
}
else
@@ -310,17 +311,17 @@ eMBEnable( void )
}
eMBErrorCode
-eMBDisable( void )
+eMBDisable(void)
{
eMBErrorCode eStatus;
- if( eMBState == STATE_ENABLED )
+ if (eMBState == STATE_ENABLED)
{
- pvMBFrameStopCur( );
+ pvMBFrameStopCur();
eMBState = STATE_DISABLED;
eStatus = MB_ENOERR;
}
- else if( eMBState == STATE_DISABLED )
+ else if (eMBState == STATE_DISABLED)
{
eStatus = MB_ENOERR;
}
@@ -332,7 +333,7 @@ eMBDisable( void )
}
eMBErrorCode
-eMBPoll( void )
+eMBPoll(void)
{
static uint8_t *ucMBFrame;
static uint8_t ucRcvAddress;
@@ -345,28 +346,28 @@ eMBPoll( void )
eMBEventType eEvent;
/* Check if the protocol stack is ready. */
- if( eMBState != STATE_ENABLED )
+ if (eMBState != STATE_ENABLED)
{
return MB_EILLSTATE;
}
/* Check if there is a event available. If not return control to caller.
* Otherwise we will handle the event. */
- if( xMBPortEventGet( &eEvent ) == true )
+ if (xMBPortEventGet(&eEvent) == true)
{
- switch ( eEvent )
+ switch (eEvent)
{
case EV_READY:
break;
case EV_FRAME_RECEIVED:
- eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
- if( eStatus == MB_ENOERR )
+ eStatus = peMBFrameReceiveCur(&ucRcvAddress, &ucMBFrame, &usLength);
+ if (eStatus == MB_ENOERR)
{
/* Check if the frame is for us. If not ignore the frame. */
- if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
+ if ((ucRcvAddress == ucMBAddress) || (ucRcvAddress == MB_ADDRESS_BROADCAST))
{
- ( void )xMBPortEventPost( EV_EXECUTE );
+ (void)xMBPortEventPost(EV_EXECUTE);
}
}
break;
@@ -374,38 +375,38 @@ eMBPoll( void )
case EV_EXECUTE:
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
eException = MB_EX_ILLEGAL_FUNCTION;
- for( i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++ )
+ for(i = 0; i < CONFIG_MB_FUNC_HANDLERS_MAX; i++)
{
/* No more function handlers registered. Abort. */
- if( xFuncHandlers[i].ucFunctionCode == 0 )
+ if (xFuncHandlers[i].ucFunctionCode == 0)
{
break;
}
- else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
+ else if (xFuncHandlers[i].ucFunctionCode == ucFunctionCode)
{
- eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
+ eException = xFuncHandlers[i].pxHandler(ucMBFrame, &usLength);
break;
}
}
/* If the request was not sent to the broadcast address we
* return a reply. */
- if( ucRcvAddress != MB_ADDRESS_BROADCAST )
+ if (ucRcvAddress != MB_ADDRESS_BROADCAST)
{
- if( eException != MB_EX_NONE )
+ if (eException != MB_EX_NONE)
{
/* An exception occured. Build an error frame. */
usLength = 0;
- ucMBFrame[usLength++] = ( uint8_t )( ucFunctionCode | MB_FUNC_ERROR );
+ ucMBFrame[usLength++] = (uint8_t)(ucFunctionCode | MB_FUNC_ERROR);
ucMBFrame[usLength++] = eException;
}
#ifdef CONFIG_MB_ASCII_ENABLED
- if( ( eMBCurrentMode == MB_ASCII ) && CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS )
+ if ((eMBCurrentMode == MB_ASCII) && CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS)
{
- vMBPortTimersDelay( CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS );
+ vMBPortTimersDelay(CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS);
}
#endif
- eStatus = peMBFrameSendCur( ucMBAddress, ucMBFrame, usLength );
+ (void)peMBFrameSendCur(ucMBAddress, ucMBFrame, usLength);
}
break;
diff --git a/apps/modbus/rtu/mbrtu.c b/apps/modbus/rtu/mbrtu.c
index ee4f95fca..5bbf8c23d 100644
--- a/apps/modbus/rtu/mbrtu.c
+++ b/apps/modbus/rtu/mbrtu.c
@@ -80,16 +80,17 @@ static volatile uint16_t usRcvBufferPos;
/* ----------------------- Start implementation -----------------------------*/
eMBErrorCode
-eMBRTUInit( uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity )
+eMBRTUInit(uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity)
{
eMBErrorCode eStatus = MB_ENOERR;
uint32_t usTimerT35_50us;
- ( void )ucSlaveAddress;
- ENTER_CRITICAL_SECTION( );
+ (void)ucSlaveAddress;
+ ENTER_CRITICAL_SECTION();
/* Modbus RTU uses 8 Databits. */
- if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != true )
+
+ if (xMBPortSerialInit(ucPort, ulBaudRate, 8, eParity) != true)
{
eStatus = MB_EPORTERR;
}
@@ -98,7 +99,7 @@ eMBRTUInit( uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParit
/* If baudrate > 19200 then we should use the fixed timer values
* t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
*/
- if( ulBaudRate > 19200 )
+ if (ulBaudRate > 19200)
{
usTimerT35_50us = 35; /* 1800us. */
}
@@ -106,101 +107,103 @@ eMBRTUInit( uint8_t ucSlaveAddress, uint8_t ucPort, speed_t ulBaudRate, eMBParit
{
/* The timer reload value for a character is given by:
*
- * ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
+ * ChTimeValue = Ticks_per_1s / (Baudrate / 11)
* = 11 * Ticks_per_1s / Baudrate
* = 220000 / Baudrate
* The reload for t3.5 is 1.5 times this value and similary
* for t3.5.
*/
- usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
+ usTimerT35_50us = (7UL * 220000UL) / (2UL * ulBaudRate);
}
- if( xMBPortTimersInit( ( uint16_t ) usTimerT35_50us ) != true )
+ if (xMBPortTimersInit((uint16_t) usTimerT35_50us) != true)
{
eStatus = MB_EPORTERR;
}
}
- EXIT_CRITICAL_SECTION( );
+ EXIT_CRITICAL_SECTION();
return eStatus;
}
void
-eMBRTUStart( void )
+eMBRTUStart(void)
{
- ENTER_CRITICAL_SECTION( );
+ ENTER_CRITICAL_SECTION();
/* Initially the receiver is in the state STATE_RX_INIT. we start
* the timer and if no character is received within t3.5 we change
* to STATE_RX_IDLE. This makes sure that we delay startup of the
* modbus protocol stack until the bus is free.
*/
eRcvState = STATE_RX_INIT;
- vMBPortSerialEnable( true, false );
- vMBPortTimersEnable( );
+ vMBPortSerialEnable(true, false);
+ vMBPortTimersEnable();
- EXIT_CRITICAL_SECTION( );
+ EXIT_CRITICAL_SECTION();
}
void
-eMBRTUStop( void )
+eMBRTUStop(void)
{
- ENTER_CRITICAL_SECTION( );
- vMBPortSerialEnable( false, false );
- vMBPortTimersDisable( );
- EXIT_CRITICAL_SECTION( );
+ ENTER_CRITICAL_SECTION();
+ vMBPortSerialEnable(false, false);
+ vMBPortTimersDisable();
+ EXIT_CRITICAL_SECTION();
}
eMBErrorCode
-eMBRTUReceive( uint8_t * pucRcvAddress, uint8_t ** pucFrame, uint16_t * pusLength )
+eMBRTUReceive(uint8_t * pucRcvAddress, uint8_t ** pucFrame, uint16_t * pusLength)
{
- bool xFrameReceived = false;
- eMBErrorCode eStatus = MB_ENOERR;
+ eMBErrorCode eStatus = MB_ENOERR;
- ENTER_CRITICAL_SECTION( );
- ASSERT( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
+ ENTER_CRITICAL_SECTION();
+ ASSERT(usRcvBufferPos < MB_SER_PDU_SIZE_MAX);
/* Length and CRC check */
- if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
- && ( usMBCRC16( ( uint8_t * ) ucRTUBuf, usRcvBufferPos ) == 0 ) )
+
+ if ((usRcvBufferPos >= MB_SER_PDU_SIZE_MIN)
+ && (usMBCRC16((uint8_t *) ucRTUBuf, usRcvBufferPos) == 0))
{
/* Save the address field. All frames are passed to the upper layed
* and the decision if a frame is used is done there.
*/
- *pucRcvAddress = ucRTUBuf[MB_SER_PDU_ADDR_OFF];
+
+ *pucRcvAddress = ucRTUBuf[MB_SER_PDU_ADDR_OFF];
/* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus
* size of address field and CRC checksum.
*/
- *pusLength = ( uint16_t )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
+
+ *pusLength = (uint16_t)(usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC);
/* Return the start of the Modbus PDU to the caller. */
- *pucFrame = ( uint8_t * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
- xFrameReceived = true;
+
+ *pucFrame = (uint8_t *) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
}
else
{
eStatus = MB_EIO;
}
- EXIT_CRITICAL_SECTION( );
+ EXIT_CRITICAL_SECTION();
return eStatus;
}
eMBErrorCode
-eMBRTUSend( uint8_t ucSlaveAddress, const uint8_t * pucFrame, uint16_t usLength )
+eMBRTUSend(uint8_t ucSlaveAddress, const uint8_t * pucFrame, uint16_t usLength)
{
- eMBErrorCode eStatus = MB_ENOERR;
- uint16_t usCRC16;
+ eMBErrorCode eStatus = MB_ENOERR;
+ uint16_t usCRC16;
- ENTER_CRITICAL_SECTION( );
+ ENTER_CRITICAL_SECTION();
/* Check if the receiver is still in idle state. If not we where to
* slow with processing the received frame and the master sent another
* frame on the network. We have to abort sending the frame.
*/
- if( eRcvState == STATE_RX_IDLE )
+ if (eRcvState == STATE_RX_IDLE)
{
/* First byte before the Modbus-PDU is the slave address. */
- pucSndBufferCur = ( uint8_t * ) pucFrame - 1;
+ pucSndBufferCur = (uint8_t *) pucFrame - 1;
usSndBufferCount = 1;
/* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
@@ -208,47 +211,47 @@ eMBRTUSend( uint8_t ucSlaveAddress, const uint8_t * pucFrame, uint16_t usLength
usSndBufferCount += usLength;
/* Calculate CRC16 checksum for Modbus-Serial-Line-PDU. */
- usCRC16 = usMBCRC16( ( uint8_t * ) pucSndBufferCur, usSndBufferCount );
- ucRTUBuf[usSndBufferCount++] = ( uint8_t )( usCRC16 & 0xFF );
- ucRTUBuf[usSndBufferCount++] = ( uint8_t )( usCRC16 >> 8 );
+ usCRC16 = usMBCRC16((uint8_t *) pucSndBufferCur, usSndBufferCount);
+ ucRTUBuf[usSndBufferCount++] = (uint8_t)(usCRC16 & 0xFF);
+ ucRTUBuf[usSndBufferCount++] = (uint8_t)(usCRC16 >> 8);
/* Activate the transmitter. */
eSndState = STATE_TX_XMIT;
- vMBPortSerialEnable( false, true );
+ vMBPortSerialEnable(false, true);
}
else
{
eStatus = MB_EIO;
}
- EXIT_CRITICAL_SECTION( );
+ EXIT_CRITICAL_SECTION();
return eStatus;
}
bool
-xMBRTUReceiveFSM( void )
+xMBRTUReceiveFSM(void)
{
bool xTaskNeedSwitch = false;
uint8_t ucByte;
- ASSERT( eSndState == STATE_TX_IDLE );
+ ASSERT(eSndState == STATE_TX_IDLE);
/* Always read the character. */
- ( void )xMBPortSerialGetByte( ( int8_t * ) & ucByte );
+ (void)xMBPortSerialGetByte((int8_t *) & ucByte);
- switch ( eRcvState )
+ switch (eRcvState)
{
/* If we have received a character in the init state we have to
* wait until the frame is finished.
*/
case STATE_RX_INIT:
- vMBPortTimersEnable( );
+ vMBPortTimersEnable();
break;
/* In the error state we wait until all characters in the
* damaged frame are transmitted.
*/
case STATE_RX_ERROR:
- vMBPortTimersEnable( );
+ vMBPortTimersEnable();
break;
/* In the idle state we wait for a new character. If a character
@@ -261,7 +264,7 @@ xMBRTUReceiveFSM( void )
eRcvState = STATE_RX_RCV;
/* Enable t3.5 timers. */
- vMBPortTimersEnable( );
+ vMBPortTimersEnable();
break;
/* We are currently receiving a frame. Reset the timer after
@@ -270,7 +273,7 @@ xMBRTUReceiveFSM( void )
* ignored.
*/
case STATE_RX_RCV:
- if( usRcvBufferPos < MB_SER_PDU_SIZE_MAX )
+ if (usRcvBufferPos < MB_SER_PDU_SIZE_MAX)
{
ucRTUBuf[usRcvBufferPos++] = ucByte;
}
@@ -278,42 +281,42 @@ xMBRTUReceiveFSM( void )
{
eRcvState = STATE_RX_ERROR;
}
- vMBPortTimersEnable( );
+ vMBPortTimersEnable();
break;
}
return xTaskNeedSwitch;
}
bool
-xMBRTUTransmitFSM( void )
+xMBRTUTransmitFSM(void)
{
bool xNeedPoll = false;
- ASSERT( eRcvState == STATE_RX_IDLE );
+ ASSERT(eRcvState == STATE_RX_IDLE);
- switch ( eSndState )
+ switch (eSndState)
{
/* We should not get a transmitter event if the transmitter is in
* idle state. */
case STATE_TX_IDLE:
/* enable receiver/disable transmitter. */
- vMBPortSerialEnable( true, false );
+ vMBPortSerialEnable(true, false);
break;
case STATE_TX_XMIT:
/* check if we are finished. */
- if( usSndBufferCount != 0 )
+ if (usSndBufferCount != 0)
{
- xMBPortSerialPutByte( ( int8_t )*pucSndBufferCur );
+ xMBPortSerialPutByte((int8_t)*pucSndBufferCur);
pucSndBufferCur++; /* next byte in sendbuffer. */
usSndBufferCount--;
}
else
{
- xNeedPoll = xMBPortEventPost( EV_FRAME_SENT );
+ xNeedPoll = xMBPortEventPost(EV_FRAME_SENT);
/* Disable transmitter. This prevents another transmit buffer
* empty interrupt. */
- vMBPortSerialEnable( true, false );
+ vMBPortSerialEnable(true, false);
eSndState = STATE_TX_IDLE;
}
break;
@@ -323,21 +326,21 @@ xMBRTUTransmitFSM( void )
}
bool
-xMBRTUTimerT35Expired( void )
+xMBRTUTimerT35Expired(void)
{
bool xNeedPoll = false;
- switch ( eRcvState )
+ switch (eRcvState)
{
/* Timer t35 expired. Startup phase is finished. */
case STATE_RX_INIT:
- xNeedPoll = xMBPortEventPost( EV_READY );
+ xNeedPoll = xMBPortEventPost(EV_READY);
break;
/* A frame was received and t35 expired. Notify the listener that
* a new frame was received. */
case STATE_RX_RCV:
- xNeedPoll = xMBPortEventPost( EV_FRAME_RECEIVED );
+ xNeedPoll = xMBPortEventPost(EV_FRAME_RECEIVED);
break;
/* An error occured while receiving the frame. */
@@ -346,11 +349,11 @@ xMBRTUTimerT35Expired( void )
/* Function called in an illegal state. */
default:
- ASSERT( ( eRcvState == STATE_RX_INIT ) ||
- ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
+ ASSERT((eRcvState == STATE_RX_INIT) ||
+ (eRcvState == STATE_RX_RCV) || (eRcvState == STATE_RX_ERROR));
}
- vMBPortTimersDisable( );
+ vMBPortTimersDisable();
eRcvState = STATE_RX_IDLE;
return xNeedPoll;