1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
27
28
29
30
31
32
33
34
40
60
61
68
69
70
71
72
73
98
99
100
101
102
108
114
120
124
130
131
132
133
134
135
136
137
142
152
153
158
167
/* ... */
/* ... */
#include "common.h"
#include "main.h"
Includes
/* ... */
void Int2Str(uint8_t *p_str, uint32_t intnum)
{
uint32_t i, divider = 1000000000, pos = 0, status = 0;
for (i = 0; i < 10; i++)
{
p_str[pos++] = (intnum / divider) + 48;
intnum = intnum % divider;
divider /= 10;
if ((p_str[pos-1] == '0') & (status == 0))
{
pos = 0;
}if ((p_str[pos-1] == '0') & (status == 0)) { ... }
else
{
status++;
}else { ... }
}for (i = 0; i < 10; i++) { ... }
}{ ... }
/* ... */
uint32_t Str2Int(uint8_t *p_inputstr, uint32_t *p_intnum)
{
uint32_t i = 0, res = 0;
uint32_t val = 0;
if ((p_inputstr[0] == '0') && ((p_inputstr[1] == 'x') || (p_inputstr[1] == 'X')))
{
i = 2;
while ( ( i < 11 ) && ( p_inputstr[i] != '\0' ) )
{
if (ISVALIDHEX(p_inputstr[i]))
{
val = (val << 4) + CONVERTHEX(p_inputstr[i]);
}if (ISVALIDHEX(p_inputstr[i])) { ... }
else
{
res = 0;
break;
}else { ... }
i++;
}while (( i < 11 ) && ( p_inputstr[i] != '\0' )) { ... }
if (p_inputstr[i] == '\0')
{
*p_intnum = val;
res = 1;
}if (p_inputstr[i] == '\0') { ... }
}if ((p_inputstr[0] == '0') && ((p_inputstr[1] == 'x') || (p_inputstr[1] == 'X'))) { ... }
else
{
while ( ( i < 11 ) && ( res != 1 ) )
{
if (p_inputstr[i] == '\0')
{
*p_intnum = val;
res = 1;
}if (p_inputstr[i] == '\0') { ... }
else if (((p_inputstr[i] == 'k') || (p_inputstr[i] == 'K')) && (i > 0))
{
val = val << 10;
*p_intnum = val;
res = 1;
}else if (((p_inputstr[i] == 'k') || (p_inputstr[i] == 'K')) && (i > 0)) { ... }
else if (((p_inputstr[i] == 'm') || (p_inputstr[i] == 'M')) && (i > 0))
{
val = val << 20;
*p_intnum = val;
res = 1;
}else if (((p_inputstr[i] == 'm') || (p_inputstr[i] == 'M')) && (i > 0)) { ... }
else if (ISVALIDDEC(p_inputstr[i]))
{
val = val * 10 + CONVERTDEC(p_inputstr[i]);
}else if (ISVALIDDEC(p_inputstr[i])) { ... }
else
{
res = 0;
break;
}else { ... }
i++;
}while (( i < 11 ) && ( res != 1 )) { ... }
}else { ... }
return res;
}{ ... }
/* ... */
void Serial_PutString(uint8_t *p_string)
{
uint16_t length = 0;
while (p_string[length] != '\0')
{
length++;
}while (p_string[length] != '\0') { ... }
HAL_UART_Transmit(&UartHandle, p_string, length, TX_TIMEOUT);
}{ ... }
/* ... */
HAL_StatusTypeDef Serial_PutByte( uint8_t param )
{
if ( UartHandle.gState == HAL_UART_STATE_TIMEOUT )
{
UartHandle.gState = HAL_UART_STATE_READY;
}if (UartHandle.gState == HAL_UART_STATE_TIMEOUT) { ... }
return HAL_UART_Transmit(&UartHandle, ¶m, 1, TX_TIMEOUT);
}{ ... }
/* ... */