Skip to content

Commit 99fc018

Browse files
Done with interactive serial console
1 parent 5f5ae65 commit 99fc018

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

‎fault_injector/fault_injector.ino‎

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
*/
2020

2121
// Notes: For Analog Fault Injections, use PWM Signals and a Low Pass Filter
22+
2223
// Add Setp by Step Incremental and Decremental Functions, but first test the current functionalities
2324
// Initial Duration and Increment Factor or Decrement Factor must be the arguements
25+
2426
// Add 2 modes of usage
2527
// 1. IC2 Display mode: A portable fault injection device
2628
// 2. Serial Communication Control: Fault Injection Attacks with Serial Console (work on this one first)
@@ -55,7 +57,7 @@ int lastStepperState = LOW;
5557

5658
unsigned long lastStepperDebounceTime = 0;
5759
unsigned long lastTriggerDebounceTime = 0; // Last time when the Trigger was pressed
58-
int universalDebounceDelay = 10; // Debounce Delay time for all buttons
60+
int universalDebounceDelay = 10; // Debounce Delay time for all buttons
5961

6062
int counter = 0;
6163
int state = 0;
@@ -201,18 +203,23 @@ void serial_console() {
201203

202204
Serial.flush();
203205
const char* setCommands[] = {
204-
"TP", // Set Trigger Pin
205-
"DFP", // Set Digital Fault Pin
206-
"AFP", // Set Analog Fault Pin
207-
"IP", // Set Interrupt Pin
208206
"ST", // Set State
209207
"MFD", // Set Maximum Fault Duration
210-
"UDD" // Set Universal Debounce Delay
208+
"UDD", // Set Universal Debounce Delay
211209
"IF", // Set Increment Factor
212210
"DF", // Set Decrement Factor
213211
"ID", // Set Initial Duration
214212
};
215213

214+
const char* commandInfo[] = {
215+
"Set State (0 for Fault Pin to be LOW in normal state and 1 for Fault Pin to be HIGH in normal state)",
216+
"Maximum Fault Duration (Maximum Fault Duration to permit for incremental stepping)",
217+
"Universal Debounce Delay (Debounce Period for buttons in the circuit",
218+
"Increment Factor (Time Period to increment in incremental stepping)",
219+
"Decrement Factor (Time Period to decrement in decremental stepping",
220+
"Initial Duration (Initial Duration for incremental and decremental stepping)",
221+
};
222+
216223
if (Serial.available()) { // Check the availability of Serial Console
217224
String command = Serial.readStringUntil('\n'); // Take commands from the Serial Console
218225

@@ -222,26 +229,11 @@ void serial_console() {
222229
String valueString = command.substring(command.lastIndexOf(' ') + 1);
223230
int value = valueString.toInt();
224231

232+
225233
if (variableName == setCommands[0]) {
226-
TRIGGER_PIN = value;
227-
Serial.print("Trigger Pin = ");
228-
Serial.println(value);
229-
} else if (variableName == setCommands[1]) {
230-
DIGITAL_FAULT_PIN = value;
231-
Serial.print("Digital Fault Pin = ");
232-
Serial.println(value);
233-
} else if (variableName == setCommands[2]) {
234-
ANALOG_FAULT_PIN = value;
235-
Serial.print("Analog Fault Pin = ");
236-
Serial.println(value);
237-
} else if (variableName == setCommands[3]) {
238-
INTERRUPT_PIN = value;
239-
Serial.print("Interrupt Pin = ");
240-
Serial.println(value);
241-
} else if (variableName == setCommands[4]) {
242234
state = value;
243235
Serial.print("State = ");
244-
Serial.print(value);
236+
Serial.println(value);
245237
if (state == 0) {
246238
Serial.println(" - Normal State = LOW and Fault State = HIGH");
247239
} else if (state == 1) {
@@ -253,23 +245,23 @@ void serial_console() {
253245
Serial.println(state);
254246
Serial.println("Normal State = LOW and Fault State = HIGH");
255247
}
256-
} else if (variableName == setCommands[5]) {
248+
} else if (variableName == setCommands[1]) {
257249
maxFaultDuration = value;
258250
Serial.print("Maximum Fault Duration = ");
259251
Serial.println(maxFaultDuration);
260-
} else if (variableName == setCommands[6]) {
252+
} else if (variableName == setCommands[2]) {
261253
universalDebounceDelay = value;
262254
Serial.print("Universal Debounce Delay = ");
263255
Serial.println(universalDebounceDelay);
264-
} else if (variableName == setCommands[7]) {
256+
} else if (variableName == setCommands[3]) {
265257
incrementFactor = value;
266258
Serial.print("Increment Factor = ");
267259
Serial.println(incrementFactor);
268-
} else if (variableName == setCommands[8]) {
260+
} else if (variableName == setCommands[4]) {
269261
decrementFactor = value;
270262
Serial.print("Decrement Factor = ");
271263
Serial.println(decrementFactor);
272-
} else if (variableName == setCommands[9]) {
264+
} else if (variableName == setCommands[5]) {
273265
initialDuration = value;
274266
Serial.print("Initial Duration = ");
275267
Serial.println(initialDuration);
@@ -296,7 +288,6 @@ void serial_console() {
296288
} else if (state == 1) {
297289
Serial.println(" - Normal State = HIGH and Fault State = LOW");
298290
}
299-
300291
Serial.print("Maximum Fault Duration = ");
301292
Serial.println(maxFaultDuration);
302293

@@ -311,10 +302,20 @@ void serial_console() {
311302

312303
Serial.print("Initial Duration = ");
313304
Serial.println(initialDuration);
314-
}
315-
else if (command.startsWith("execute")) {
305+
306+
} else if (command.startsWith("execute")) {
316307
Serial.println("Under Development!");
317-
}
308+
} else if (command.startsWith("HELP")) {
309+
Serial.println("Fault Injector - A Fault Injection Toolkit\n");
310+
Serial.println("- All time values are in Mircoseconds\n");
311+
for (int index = 0; index < 5; index++) {
312+
Serial.print(setCommands[index]);
313+
Serial.print(" - ");
314+
Serial.println(commandInfo[index]);
315+
}
316+
} else if (command.startsWith("EXIT")) {
317+
Serial.println("Exiting Serial Console");
318+
}
318319
Serial.println("");
319320
}
320321
}

0 commit comments

Comments
 (0)