311 lines
8.3 KiB
C++
311 lines
8.3 KiB
C++
#include <EEPROM.h>
|
|
|
|
struct DeviceData {
|
|
char deviceId[20];
|
|
// int intValue;
|
|
// float floatValue;
|
|
};
|
|
|
|
|
|
void writeDataToEEPROM(DeviceData data, int address) {
|
|
EEPROM.put(address, data);
|
|
}
|
|
|
|
void readDataFromEEPROM(DeviceData &data, int address) {
|
|
EEPROM.get(address, data);
|
|
}
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
Serial.begin(115200);
|
|
|
|
// Serial.begin(9600);
|
|
|
|
// DeviceData myDevice;
|
|
// strcpy(myDevice.deviceId, "HCV-000-3001");
|
|
// writeDataToEEPROM(myDevice, 0);
|
|
|
|
// // Read data from EEPROM
|
|
// DeviceData readDevice;
|
|
// readDataFromEEPROM(readDevice, 0);
|
|
// Serial.print("Device ID: ");
|
|
// Serial.println(readDevice.deviceId);
|
|
}
|
|
|
|
void loop() {
|
|
mockV0Device();
|
|
// mockV1Device();
|
|
|
|
// mockV2Device();
|
|
}
|
|
|
|
void mockV0Device() {
|
|
// // TEST: Buffer + Sample
|
|
while (Serial.available() == 0) {} //wait for data available
|
|
String bufferCommand = Serial.readString(); //read until timeout
|
|
bufferCommand.trim(); // remove any \r \n whitespace at the end of the String
|
|
if (bufferCommand == "B") {
|
|
Serial.println("#Start Buffer");
|
|
delay(2000);
|
|
Serial.println("#Buffer Completed");
|
|
}
|
|
|
|
while (Serial.available() == 0) {} //wait for data available
|
|
String SampleCommand = Serial.readString(); //read until timeout
|
|
SampleCommand.trim(); // remove any \r \n whitespace at the end of the String
|
|
if (SampleCommand == "S") {
|
|
Serial.println("#Sample Started");
|
|
delay(2000);
|
|
Serial.println("#Sample Completed");
|
|
}
|
|
|
|
while (Serial.available() == 0) {} //wait for data available
|
|
String resultCommand = Serial.readString(); //read until timeout
|
|
resultCommand.trim(); // remove any \r \n whitespace at the end of the String
|
|
if (resultCommand == "P") {
|
|
delay(3000);
|
|
// RESULT SN HCV1002 BUFFER_555_GREEN_INTENSITY BUFFER_427_BLUE_INTENSITY SAMPLE_555_GREEN_INTENSITY SAMPLE_427_BLUE_INTENSITY REND
|
|
// Serial.println("RESULT SN HCV1002 23729 24801.67 19190.67 6995.67 REND"); // normal
|
|
// Serial.println("RESULT SN HCV1002 24900.67 26578.33 19760.00 9071.67 REND"); // NBL
|
|
Serial.println("RESULT SN HCV1002 17974.33 9247.67 19952 12217 REND"); // negative abs
|
|
delay(15000);
|
|
}
|
|
|
|
|
|
|
|
// TEST: Device diagonistics
|
|
while (Serial.available() == 0) {} //wait for data available
|
|
String infoCommand = Serial.readString(); //read until timeout
|
|
infoCommand.trim(); // remove any \r \n whitespace at the end of the String
|
|
if (infoCommand == "I") {
|
|
Serial.println("SN HCV2002");
|
|
}
|
|
while (Serial.available() == 0) {} //wait for data available
|
|
String diagnosticsCommand = Serial.readString(); //read until timeout
|
|
diagnosticsCommand.trim(); // remove any \r \n whitespace at the end of the String
|
|
if (diagnosticsCommand == "D") {
|
|
Serial.println("PG 7016");
|
|
delay(500);
|
|
Serial.println("PG 10668");
|
|
delay(500);
|
|
Serial.println("PG 14294");
|
|
delay(500);
|
|
Serial.println("PG 17875");
|
|
delay(500);
|
|
Serial.println("PG 21470");
|
|
delay(500);
|
|
|
|
Serial.println("PB 17");
|
|
delay(500);
|
|
Serial.println("PB 3225");
|
|
delay(500);
|
|
Serial.println("PB 6776");
|
|
delay(500);
|
|
Serial.println("PB 10429");
|
|
delay(500);
|
|
Serial.println("END");
|
|
}
|
|
}
|
|
|
|
void mockV1Device() {
|
|
// two path length device
|
|
// TEST: Device Info + Buffer + Sample
|
|
while (Serial.available() == 0) {}
|
|
String infoCommand = Serial.readString();
|
|
infoCommand.trim();
|
|
if (infoCommand == "I") {
|
|
Serial.println("SN HCV-000-3001");
|
|
}
|
|
|
|
while (Serial.available() == 0) {}
|
|
String bufferCommand = Serial.readString();
|
|
bufferCommand.trim();
|
|
if (bufferCommand == "B") {
|
|
Serial.println("#BS");
|
|
delay(2000);
|
|
Serial.println("#BC");
|
|
}
|
|
|
|
while (Serial.available() == 0) {}
|
|
String SampleCommand = Serial.readString();
|
|
SampleCommand.trim();
|
|
if (SampleCommand == "S") {
|
|
Serial.println("#SS");
|
|
delay(2000);
|
|
Serial.println("#SC");
|
|
}
|
|
|
|
while (Serial.available() == 0) {}
|
|
String resultCommand = Serial.readString();
|
|
resultCommand.trim();
|
|
if (resultCommand == "P") {
|
|
delay(3000);
|
|
Serial.println("RESULT");
|
|
|
|
// // deoxy error
|
|
// Serial.println("LB1 25215");
|
|
// Serial.println("LB2 25599");
|
|
// Serial.println("LB3 24856");
|
|
// Serial.println("LB4 25584");
|
|
// Serial.println("LS1 560");
|
|
// Serial.println("LS2 71");
|
|
// Serial.println("LS3 3447");
|
|
// Serial.println("LS4 4092");
|
|
|
|
// // // SCT, no error
|
|
Serial.println("LB1 23777");
|
|
Serial.println("LB2 24130");
|
|
Serial.println("LB3 23442");
|
|
Serial.println("LB4 23945");
|
|
Serial.println("LS1 2521");
|
|
Serial.println("LS2 973");
|
|
Serial.println("LS3 10252");
|
|
Serial.println("LS4 11017");
|
|
|
|
// buffer high error
|
|
// Serial.println("LB1 21616");
|
|
// Serial.println("LB2 21002");
|
|
// Serial.println("LB3 24402");
|
|
// Serial.println("LB4 24076");
|
|
// Serial.println("LS1 507");
|
|
// Serial.println("LS2 720");
|
|
// Serial.println("LS3 2293");
|
|
// Serial.println("LS4 6601");
|
|
|
|
Serial.println("REND");
|
|
delay(15000);
|
|
}
|
|
}
|
|
|
|
void mockV2Device() {
|
|
// V2 Device
|
|
// TEST: Device Info + Buffer + Sample
|
|
while (Serial.available() == 0) {
|
|
String command = Serial.readString();
|
|
command.trim();
|
|
|
|
if (command == "I") {
|
|
DeviceData readDevice;
|
|
readDataFromEEPROM(readDevice, 0);
|
|
// Serial.print("SNS "); Serial.print(readDevice.deviceId); Serial.print(" SNE");
|
|
// Serial.print("SN HCV-000-3001");
|
|
// Serial.print("SNS HPP1-0111-0009 SNE");
|
|
Serial.print("SNS HCV-000-3998 SNE");
|
|
// Serial.print("SNS HCV-000-3013 SNE");
|
|
}
|
|
|
|
if (command == "E") {
|
|
Serial.println("#RS");
|
|
// delay(2000);
|
|
Serial.println("#RC");
|
|
}
|
|
|
|
if (command == "R") {
|
|
delay(2000);
|
|
Serial.println("#LED1 DAC: 2021");
|
|
Serial.println("#LED2 DAC: 2022");
|
|
Serial.println("#LED3 DAC: 2023");
|
|
Serial.println("#LED4 DAC: 2024");
|
|
}
|
|
|
|
if (command == "B") {
|
|
Serial.println("#BS");
|
|
delay(2000);
|
|
Serial.println("#BC");
|
|
}
|
|
|
|
if (command == "C") {
|
|
Serial.println("#CS");
|
|
delay(2000);
|
|
Serial.println("LED1_DAC: 1856");
|
|
Serial.println("LED2_DAC: 824");
|
|
Serial.println("LED3_DAC: 2400");
|
|
Serial.println("LED4_DAC: 1992");
|
|
Serial.println("#CC");
|
|
}
|
|
|
|
if (command == "G") {
|
|
Serial.println("#WS");
|
|
delay(2000);
|
|
Serial.println("#WC");
|
|
}
|
|
|
|
if (command == "D") {
|
|
Serial.println("#CS");
|
|
delay(2000);
|
|
Serial.println("LED1_DAC: 1856");
|
|
Serial.println("LED2_DAC: 824");
|
|
Serial.println("LED3_DAC: 2400");
|
|
Serial.println("LED4_DAC: 1992");
|
|
Serial.println("#CC");
|
|
}
|
|
|
|
if (command == "S") {
|
|
Serial.println("#SS1");
|
|
delay(2000);
|
|
Serial.println("#SC1");
|
|
}
|
|
|
|
if (command == "T") {
|
|
Serial.println("#SS2");
|
|
delay(3000);
|
|
Serial.println("#SC2");
|
|
}
|
|
|
|
if (command == "U") {
|
|
Serial.println("#SS3");
|
|
delay(3000);
|
|
Serial.println("#SC3");
|
|
}
|
|
|
|
// if (command == "V") {
|
|
// Serial.println("#SS4");
|
|
// delay(5000);
|
|
// Serial.println("#SC4");
|
|
// }
|
|
|
|
if (command == "W") {
|
|
Serial.println("#SS5");
|
|
delay(3000);
|
|
Serial.println("#SC5");
|
|
}
|
|
|
|
if (command == "P") {
|
|
delay(1000);
|
|
Serial.println("RESULT");
|
|
|
|
// // deoxy error
|
|
// Serial.println("LB1 25215");
|
|
// Serial.println("LB2 25599");
|
|
// Serial.println("LB3 24856");
|
|
// Serial.println("LB4 25584");
|
|
// Serial.println("LS1 560");
|
|
// Serial.println("LS2 71");
|
|
// Serial.println("LS3 3447");
|
|
// Serial.println("LS4 4092");
|
|
|
|
// // // SCT, no error
|
|
Serial.println("LB1 23777");
|
|
Serial.println("LB2 24130");
|
|
Serial.println("LB3 23442");
|
|
Serial.println("LB4 23945");
|
|
Serial.println("LS1 2521");
|
|
Serial.println("LS2 973");
|
|
Serial.println("LS3 10252");
|
|
Serial.println("LS4 11017");
|
|
|
|
// buffer high error
|
|
// Serial.println("LB1 21616");
|
|
// Serial.println("LB2 21002");
|
|
// Serial.println("LB3 24402");
|
|
// Serial.println("LB4 24076");
|
|
// Serial.println("LS1 507");
|
|
// Serial.println("LS2 720");
|
|
// Serial.println("LS3 2293");
|
|
// Serial.println("LS4 6601");
|
|
|
|
Serial.println("REND");
|
|
}
|
|
}
|
|
}
|