37
37
#include "config.h"
38
38
39
39
#include <stdlib.h>
40
+ #include <stdint.h>
40
41
#include <stdio.h>
41
42
#include <unistd.h>
42
43
#include <string.h>
@@ -67,14 +68,14 @@ static char Name[] = "TeakLCM";
67
68
static int global_reset_rx_flag = 0 ;
68
69
69
70
70
- #define HI8 (value ) ((u_int8_t )(((value)>>8) & 0xff))
71
- #define LO8 (value ) ((u_int8_t )((value) & 0xff))
71
+ #define HI8 (value ) ((uint8_t )(((value)>>8) & 0xff))
72
+ #define LO8 (value ) ((uint8_t )((value) & 0xff))
72
73
73
74
74
- static u_int16_t CRC16 (u_int8_t value , u_int16_t crcin )
75
+ static uint16_t CRC16 (uint8_t value , uint16_t crcin )
75
76
{
76
- u_int16_t k = (((crcin >> 8 ) ^ value ) & 255 ) << 8 ;
77
- u_int16_t crc = 0 ;
77
+ uint16_t k = (((crcin >> 8 ) ^ value ) & 255 ) << 8 ;
78
+ uint16_t crc = 0 ;
78
79
int bits ;
79
80
for (bits = 8 ; bits ; -- bits ) {
80
81
if ((crc ^ k ) & 0x8000 )
@@ -100,7 +101,7 @@ static char printable(const char ch)
100
101
101
102
static void debug_data_int (const char * prefix , const void * data , const size_t size , const unsigned int delta )
102
103
{
103
- const u_int8_t * b = (const u_int8_t * ) data ;
104
+ const uint8_t * b = (const uint8_t * ) data ;
104
105
size_t y ;
105
106
assert (delta <= 24 );
106
107
for (y = 0 ; y < size ; y += delta ) {
@@ -284,7 +285,7 @@ static
284
285
void fsm_handle_cmd (lcm_fsm_t * fsm , const lcm_cmd_t cmd );
285
286
286
287
static
287
- void fsm_handle_datacmd (lcm_fsm_t * fsm , const lcm_cmd_t cmd , const u_int8_t * payload , const unsigned int payload_len );
288
+ void fsm_handle_datacmd (lcm_fsm_t * fsm , const lcm_cmd_t cmd , const uint8_t * payload , const unsigned int payload_len );
288
289
289
290
static
290
291
void try_reset (void );
@@ -304,7 +305,7 @@ void fsm_trans_data(lcm_fsm_t * fsm,
304
305
305
306
306
307
static
307
- void fsm_handle_bytes (lcm_fsm_t * fsm , u_int8_t * rxbuf , const unsigned int buflen )
308
+ void fsm_handle_bytes (lcm_fsm_t * fsm , uint8_t * rxbuf , const unsigned int buflen )
308
309
{
309
310
if ((buflen >= 3 ) && (rxbuf [0 ] == LCM_FRAME_MASK ) && (rxbuf [2 ] == LCM_FRAME_MASK )) {
310
311
const lcm_cmd_t cmd = rxbuf [1 ];
@@ -322,7 +323,7 @@ void fsm_handle_bytes(lcm_fsm_t * fsm, u_int8_t * rxbuf, const unsigned int bufl
322
323
debug ("%s Received possible data frame" , __FUNCTION__ );
323
324
324
325
/* unescape rxframe data in place */
325
- u_int16_t crc0 = 0 , crc1 = 0 , crc2 = 0 , crc3 = 0 ;
326
+ uint16_t crc0 = 0 , crc1 = 0 , crc2 = 0 , crc3 = 0 ;
326
327
for (ri = 1 , ci = 1 ; ri < buflen ; ri ++ ) {
327
328
switch (rxbuf [ri ]) {
328
329
case LCM_ESC :
@@ -339,7 +340,7 @@ void fsm_handle_bytes(lcm_fsm_t * fsm, u_int8_t * rxbuf, const unsigned int bufl
339
340
if ((rxbuf [ci - 1 ] == LCM_FRAME_MASK ) && (rxbuf [ci - 2 ] == LO8 (crc3 )) && (rxbuf [ci - 3 ] == HI8 (crc3 ))) {
340
341
/* looks like a complete data frame */
341
342
lcm_cmd_t cmd = rxbuf [1 ];
342
- u_int16_t len = (rxbuf [3 ] << 8 ) + rxbuf [2 ];
343
+ uint16_t len = (rxbuf [3 ] << 8 ) + rxbuf [2 ];
343
344
assert (ci == (unsigned int ) (1 + 1 + 2 + len + 2 + 1 ));
344
345
fsm_handle_datacmd (fsm , cmd , & rxbuf [4 ], len );
345
346
if (ri + 1 < buflen ) {
@@ -420,7 +421,7 @@ static void fsm_handle_cmd(lcm_fsm_t * fsm, lcm_cmd_t cmd)
420
421
421
422
422
423
static
423
- void fsm_handle_datacmd (lcm_fsm_t * fsm , const lcm_cmd_t cmd , const u_int8_t * payload , unsigned int payload_len )
424
+ void fsm_handle_datacmd (lcm_fsm_t * fsm , const lcm_cmd_t cmd , const uint8_t * payload , unsigned int payload_len )
424
425
{
425
426
const lcm_state_t old_state = fsm_get_state (fsm );
426
427
debug ("fsm_handle_datacmd: old state 0x%02x %s" , old_state , state2str (old_state ));
@@ -677,7 +678,7 @@ void raw_send_data_frame(lcm_cmd_t cmd, const char *data, const unsigned int len
677
678
unsigned int di ; /* data index */
678
679
unsigned int fi ; /* frame index */
679
680
static char frame [32 ];
680
- u_int16_t crc = 0 ;
681
+ uint16_t crc = 0 ;
681
682
682
683
frame [0 ] = LCM_FRAME_MASK ;
683
684
@@ -740,7 +741,7 @@ void lcm_event_callback(event_flags_t flags, void *data)
740
741
lcm_fsm_t * fsm = (lcm_fsm_t * ) data ;
741
742
debug ("%s: flags=%d, data=%p" , __FUNCTION__ , flags , data );
742
743
if (flags & EVENT_READ ) {
743
- static u_int8_t rxbuf [32 ];
744
+ static uint8_t rxbuf [32 ];
744
745
const int readlen = drv_generic_serial_poll ((void * ) rxbuf , sizeof (rxbuf ));
745
746
if (readlen <= 0 ) {
746
747
debug ("%s Received no data" , __FUNCTION__ );
@@ -901,7 +902,7 @@ static int drv_TeakLCM_start(const char *section)
901
902
debug ("%s: %s opened" , Name , __FUNCTION__ );
902
903
903
904
/* read initial garbage data */
904
- static u_int8_t rxbuf [32 ];
905
+ static uint8_t rxbuf [32 ];
905
906
const int readlen = drv_generic_serial_poll ((void * ) rxbuf , sizeof (rxbuf ));
906
907
if (readlen >= 0 ) {
907
908
debug_data (" initial RX garbage " , rxbuf , readlen );
0 commit comments