@@ -281,9 +281,9 @@ void nmbs_set_platform_arg(nmbs_t* nmbs, void* arg) {
281281uint16_t nmbs_crc_calc (const uint8_t * data , uint32_t length , void * arg ) {
282282 NMBS_UNUSED_PARAM (arg );
283283 uint16_t crc = 0xFFFF ;
284- for (uint32_t i = 0 ; i < length ; i ++ ) {
284+ for (uint_fast32_t i = 0 ; i < length ; i ++ ) {
285285 crc ^= (uint16_t ) data [i ];
286- for (int j = 8 ; j != 0 ; j -- ) {
286+ for (uint_fast8_t j = 8 ; j != 0 ; j -- ) {
287287 if ((crc & 0x0001 ) != 0 ) {
288288 crc >>= 1 ;
289289 crc ^= 0xA001 ;
@@ -560,7 +560,7 @@ static nmbs_error recv_read_discrete_res(nmbs_t* nmbs, nmbs_bitfield values) {
560560 return err ;
561561
562562 NMBS_DEBUG_PRINT ("coils " );
563- for (int i = 0 ; i < coils_bytes ; i ++ ) {
563+ for (uint_fast8_t i = 0 ; i < coils_bytes ; i ++ ) {
564564 const uint8_t coil = get_1 (nmbs );
565565 if (values )
566566 values [i ] = coil ;
@@ -599,8 +599,8 @@ static nmbs_error recv_read_registers_res(nmbs_t* nmbs, uint16_t quantity, uint1
599599 return err ;
600600
601601 NMBS_DEBUG_PRINT ("regs " );
602- for (int i = 0 ; i < registers_bytes / 2 ; i ++ ) {
603- uint16_t reg = get_2 (nmbs );
602+ for (uint_fast8_t i = 0 ; i < registers_bytes / 2 ; i ++ ) {
603+ const uint16_t reg = get_2 (nmbs );
604604 if (registers )
605605 registers [i ] = reg ;
606606 NMBS_DEBUG_PRINT ("%d " , reg );
@@ -863,7 +863,7 @@ nmbs_error recv_read_device_identification_res(nmbs_t* nmbs, uint8_t buffers_cou
863863 * next_object_id_out = next_object_id ;
864864
865865 uint8_t res_size_left = 253 - 7 ;
866- for (int i = 0 ; i < objects_count ; i ++ ) {
866+ for (uint_fast8_t i = 0 ; i < objects_count ; i ++ ) {
867867 err = recv (nmbs , 2 );
868868 if (err != NMBS_ERROR_NONE )
869869 return err ;
@@ -936,15 +936,15 @@ static nmbs_error handle_read_discrete(nmbs_t* nmbs,
936936 }
937937
938938 if (!nmbs -> msg .broadcast ) {
939- uint8_t discrete_bytes = (quantity + 7 ) / 8 ;
939+ const uint8_t discrete_bytes = (quantity + 7 ) / 8 ;
940940 put_res_header (nmbs , 1 + discrete_bytes );
941941
942942 put_1 (nmbs , discrete_bytes );
943943
944944 NMBS_DEBUG_PRINT ("b %d\t" , discrete_bytes );
945945
946946 NMBS_DEBUG_PRINT ("coils " );
947- for (int i = 0 ; i < discrete_bytes ; i ++ ) {
947+ for (uint_fast8_t i = 0 ; i < discrete_bytes ; i ++ ) {
948948 put_1 (nmbs , bitfield [i ]);
949949 NMBS_DEBUG_PRINT ("%d " , bitfield [i ]);
950950 }
@@ -1010,7 +1010,7 @@ static nmbs_error handle_read_registers(nmbs_t* nmbs,
10101010 NMBS_DEBUG_PRINT ("b %d\t" , regs_bytes );
10111011
10121012 NMBS_DEBUG_PRINT ("regs " );
1013- for (int i = 0 ; i < quantity ; i ++ ) {
1013+ for (uint_fast16_t i = 0 ; i < quantity ; i ++ ) {
10141014 put_2 (nmbs , regs [i ]);
10151015 NMBS_DEBUG_PRINT ("%d " , regs [i ]);
10161016 }
@@ -1173,7 +1173,7 @@ static nmbs_error handle_write_multiple_coils(nmbs_t* nmbs) {
11731173
11741174 const uint16_t address = get_2 (nmbs );
11751175 const uint16_t quantity = get_2 (nmbs );
1176- uint8_t coils_bytes = get_1 (nmbs );
1176+ const uint8_t coils_bytes = get_1 (nmbs );
11771177
11781178 NMBS_DEBUG_PRINT ("a %d\tq %d\tb %d\tcoils " , address , quantity , coils_bytes );
11791179
@@ -1185,7 +1185,7 @@ static nmbs_error handle_write_multiple_coils(nmbs_t* nmbs) {
11851185 return err ;
11861186
11871187 nmbs_bitfield coils = {0 };
1188- for (int i = 0 ; i < coils_bytes ; i ++ ) {
1188+ for (uint_fast8_t i = 0 ; i < coils_bytes ; i ++ ) {
11891189 coils [i ] = get_1 (nmbs );
11901190 NMBS_DEBUG_PRINT ("%d " , coils [i ]);
11911191 }
@@ -1262,7 +1262,7 @@ static nmbs_error handle_write_multiple_registers(nmbs_t* nmbs) {
12621262 return NMBS_ERROR_INVALID_REQUEST ;
12631263
12641264 uint16_t registers [0x007B ];
1265- for (int i = 0 ; i < registers_bytes / 2 ; i ++ ) {
1265+ for (uint_fast8_t i = 0 ; i < registers_bytes / 2 ; i ++ ) {
12661266 registers [i ] = get_2 (nmbs );
12671267 NMBS_DEBUG_PRINT ("%d " , registers [i ]);
12681268 }
@@ -1564,7 +1564,7 @@ static nmbs_error handle_read_write_registers(nmbs_t* nmbs) {
15641564#else
15651565 uint16_t registers [byte_count_write / 2 ];
15661566#endif
1567- for (int i = 0 ; i < byte_count_write / 2 ; i ++ ) {
1567+ for (uint_fast8_t i = 0 ; i < byte_count_write / 2 ; i ++ ) {
15681568 registers [i ] = get_2 (nmbs );
15691569 NMBS_DEBUG_PRINT ("%d " , registers [i ]);
15701570 }
@@ -1624,7 +1624,7 @@ static nmbs_error handle_read_write_registers(nmbs_t* nmbs) {
16241624 NMBS_DEBUG_PRINT ("b %d\t" , regs_bytes );
16251625
16261626 NMBS_DEBUG_PRINT ("regs " );
1627- for (int i = 0 ; i < read_quantity ; i ++ ) {
1627+ for (uint_fast16_t i = 0 ; i < read_quantity ; i ++ ) {
16281628 put_2 (nmbs , regs [i ]);
16291629 NMBS_DEBUG_PRINT ("%d " , regs [i ]);
16301630 }
0 commit comments