Skip to content

Commit 950f028

Browse files
Refactor to allow 10 characters over UART.
1 parent 68bc14f commit 950f028

File tree

1 file changed

+16
-23
lines changed
  • secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X

1 file changed

+16
-23
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/main.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static void MoveCursor(int row);
3232
static void HideCursor(void);
3333
static void PrintWarning(void);
3434
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex);
35-
static void ResetWindowOnMismatch(char *window, int *windowIndex, char receivedChar);
36-
static void CheckForUnlockCommand(char *window, int windowIndex);
35+
static void ResetWindowOnMismatch(char *window, int *windowIndex);
36+
static void CheckForUnlockCommand(char *window, int *windowIndex);
3737

3838
int main(void)
3939
{
@@ -85,48 +85,41 @@ static void PrintWarning(void)
8585
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex)
8686
{
8787
MoveCursor(10);
88-
printf("%c", receivedChar);
89-
if (receivedChar == UNLOCK_COMMAND[*windowIndex])
88+
89+
if (*windowIndex < WINDOW_SIZE && receivedChar == UNLOCK_COMMAND[*windowIndex])
9090
{
91+
printf("%c", receivedChar);
9192
window[(*windowIndex)++] = receivedChar;
9293
window[*windowIndex] = '\0';
93-
94-
CheckForUnlockCommand(window, *windowIndex);
94+
CheckForUnlockCommand(window, windowIndex);
9595
}
9696
else
9797
{
98-
ResetWindowOnMismatch(window, windowIndex, receivedChar);
98+
ClearTerminalLine();
99+
ResetWindowOnMismatch(window, windowIndex);
99100
}
100101
}
101102

102-
static void ResetWindowOnMismatch(char *window, int *windowIndex, char receivedChar)
103+
static void ResetWindowOnMismatch(char *window, int *windowIndex)
103104
{
104105
MoveCursor(5);
105106
ClearTerminalLine();
106-
printf("Incorrect command received. Try again.");
107-
if(receivedChar == UNLOCK_COMMAND[0])
108-
{
109-
*windowIndex = 1;
110-
window[0] = receivedChar;
111-
}
112-
else
113-
{
114-
*windowIndex = 0;
115-
window[0] = '\0';
116-
}
107+
printf("Invalid character entered. Try again.");
108+
*windowIndex = 0;
109+
memset(window, 0, WINDOW_SIZE + 1);
117110
}
118111

119-
static void CheckForUnlockCommand(char *window, int windowIndex)
112+
static void CheckForUnlockCommand(char *window, int *windowIndex)
120113
{
121114
int patternLength = strlen(UNLOCK_COMMAND);
122115

123-
if (windowIndex == patternLength)
116+
if (*windowIndex == patternLength)
124117
{
125118
MoveCursor(5);
126119
ClearTerminalLine();
127120
printf("Unlock command for ICSP Inhibit received.\n");
128121
HideCursor();
129-
memset(window, 0, WINDOW_SIZE + 1); // Clear the window buffer
130-
windowIndex = 0;
122+
*windowIndex = 0;
123+
memset(window, 0, WINDOW_SIZE + 1);
131124
}
132125
}

0 commit comments

Comments
 (0)