add error message

This commit is contained in:
Ryan Tang 2024-02-08 17:34:00 -05:00
parent 26ce8e88a4
commit a63db5b0a4
6 changed files with 197 additions and 25 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
display display
.gdb_history .gdb_history
data.txt

57
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,57 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}

View File

@ -9,28 +9,72 @@ outFile = "/home/pi02/data.txt"
cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt' cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt'
OPEN = 0
CLOSED = 1
input_normal= [
OPEN, #// Reset switch
CLOSED, #// Emergency source trip switch
CLOSED, #// Cage door contact
CLOSED, #// Fume hood flow switch
OPEN, #// Vacuum condition - gnd
CLOSED, #// Tritium monitor
OPEN, #// UNUSED
CLOSED, #// Power failure
CLOSED, #// Coolant flow - gnd
OPEN, #// Vacuum condition - mid
OPEN, #// UNUSED
CLOSED, #// Coolant flow - high
OPEN, #// Smoke detector - high
OPEN, #// UNUSED
OPEN, #// UNUSED
OPEN #// UNUSED
]
in_txt = [ "Reset Button",
"Emergency Switch",
"Cage Door Open",
"Fume Hood Flow",
"Vacuum Gauge 2",
"Tritium Monitor",
"error: port map",
"Bldg Power Fail",
"Coolant Flow 2",
"Vacuum Gauge 1",
"error: port map",
"Coolant Flow 1",
"Smoke at Source",
"error: port map",
"error: port map",
"error: port map",
""]
while True: while True:
if ser.in_waiting > 0: if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip() line = ser.readline().decode('utf-8').rstrip()
list = []
components = line.split(';') components = line.split(';')
format_value = {} format_value = {}
for component in components: for component in components:
#print(component)
parts = component.strip().split(': ') parts = component.strip().split(': ')
if len(parts) == 2: if len(parts) == 2:
key, valueUnit = parts key, valueUnit = parts
part2 = valueUnit.split(' ') part2 = valueUnit.split(' ')
if len(part2) == 2: if len(part2) == 2:
value, unit = part2 value, unit = part2
if value == "ovf" :
value = 99999
format_value[key] = value format_value[key] = value
else: else:
format_value[key] = valueUnit format_value[key] = valueUnit
else:
list.append(component)
#print(line) # print(line)
#for key, value in format_value.items(): # for key, value in format_value.items():
# print(f"{key} value={value}") # print(f"{key} value={value}")
with open(outFile, "w") as file: with open(outFile, "w") as file:
@ -66,4 +110,8 @@ while True:
file.write(f"boiler value=0\n") file.write(f"boiler value=0\n")
file.write(f"ion value=0\n") file.write(f"ion value=0\n")
for i in range(16):
if int(list[i]) != input_normal[i]:
file.write(f"#{i}--{in_txt[i]}\n")
os.system(cmd) os.system(cmd)

View File

@ -130,7 +130,13 @@ void loop() {
Serial.print("SubPump: "); Serial.print("SubPump: ");
Serial.print(subPump); Serial.print(subPump);
Serial.println(" amp;"); Serial.print(" amp;");
for( int i = 0; i < 16; i++ ){
Serial.print(input[i]);
Serial.print(";");
}
Serial.println("");
previousMillis = currentMillis; // Reset the timer previousMillis = currentMillis; // Reset the timer
} }

View File

@ -126,24 +126,24 @@ void app_Interfaces(void) {
} }
// Webpage function // // Webpage function
serve_webpage(); // serve_webpage();
// Diagnostics -> Serial Output // // Diagnostics -> Serial Output
if (digitalRead(SWITCH_BUILTIN) == 0){ // if (digitalRead(SWITCH_BUILTIN) == 0){
if ((millis()-printerPace)>3000) { // if ((millis()-printerPace)>3000) {
print_states(); // print_states();
printerPace = millis(); // printerPace = millis();
} // }
} // }
// Heartbeat // // Heartbeat
if ((millis()-heartBeat)>1200) { // if ((millis()-heartBeat)>1200) {
for (int i=0; i<4; i++){ // for (int i=0; i<4; i++){
digitalWrite(heartbeat, !digitalRead(heartbeat)); // digitalWrite(heartbeat, !digitalRead(heartbeat));
delay(100); // delay(100);
} // }
heartBeat = millis(); // heartBeat = millis();
} // }
} }

View File

@ -9,6 +9,28 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <vector>
const std::string error_txt[16] = {
"Reset Button", //0
"Emergency Switch", //1
"Cage Door Open", //2
"Fume Hood Flow", //3
"Vacuum Gauge 2", //4
"Tritium Monitor", //5
"error: port map", //6
"Bldg Power Fail", //7
"Coolant Flow 2", //8
"Vacuum Gauge 1", //9
"error: port map", //10
"Coolant Flow 1", //11
"Smoke at Source", //12
"error: port map", //13
"error: port map", //14
"error: port map" //15
};
SDL_Window* window = nullptr; SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr; SDL_Renderer* renderer = nullptr;
@ -47,6 +69,10 @@ bool hv = true;
bool boiler = true ; bool boiler = true ;
bool ionizer = true ; bool ionizer = true ;
std::vector<int> error_code;
bool isTritiumError = false;
bool isVaccumError = false;
void readStatus(){ void readStatus(){
std::ifstream file("data.txt"); // Replace "your_file.txt" with your actual file path std::ifstream file("data.txt"); // Replace "your_file.txt" with your actual file path
if (!file.is_open()) { if (!file.is_open()) {
@ -54,6 +80,10 @@ void readStatus(){
return; return;
} }
error_code.clear();
isTritiumError = false;
isVaccumError = false;
std::string line; std::string line;
while (std::getline(file, line)) { while (std::getline(file, line)) {
std::istringstream iss(line); std::istringstream iss(line);
@ -80,6 +110,18 @@ void readStatus(){
} }
} }
} }
if ( line[0] == '#' ) {
int code = line[1] -'0' ;
error_code.push_back( code );
if( code == 9 ) isVaccumError = true;
if( code == 5 ) isTritiumError = true;
// printf("error code : %d, %s\n", error_code.back(), error_txt[error_code.back()].c_str());
}
} }
file.close(); file.close();
@ -119,6 +161,17 @@ void readStatus(){
} }
std::string FormatDouble(double value){
std::string str_value = std::to_string(value);
size_t dot_position = str_value.find('.');
if (dot_position != std::string::npos && str_value.length() > dot_position + 3) {
str_value = str_value.substr(0, dot_position + 3);
}
return str_value;
}
int main() { int main() {
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
@ -197,9 +250,15 @@ int main() {
case 4: textDisplay( "Source (Tripped-3)", 10, 40, redColor); break; case 4: textDisplay( "Source (Tripped-3)", 10, 40, redColor); break;
} }
textDisplay( "Tritium Sensor : " + std::to_string(tritiumReading) + " mCr", 720, 200, blueColor); if( error_code.size() > 0 ){
textDisplay( "Vaccum : " + std::to_string(vaccumReading) + "x1e-6 Torr", 630, 20, blueColor); for( size_t i = 0; i < error_code.size(); i++){
textDisplay( "SubPump : " + std::to_string(subPumpReading*1000) + " mA", 300, 40, blueColor); textDisplay( error_txt[error_code[i]], 10, 80 + 25*i, redColor);
}
}
textDisplay( "Tritium Sensor : " + FormatDouble(tritiumReading) + " mCr", 720, 200, isTritiumError ? redColor : blueColor);
textDisplay( "Vaccum : " + FormatDouble(vaccumReading) + "x1e-6 Torr", 630, 20, isVaccumError ? redColor: blueColor);
textDisplay( "SubPump : " + FormatDouble(subPumpReading*1000) + " mA", 300, 40, blueColor);
textDisplay("update every 5 sec.", 1200, 670, blackColor); textDisplay("update every 5 sec.", 1200, 670, blackColor);