- Joined
- Jun 7, 2018
- Messages
- 1,050
- Reaction score
- 953
I have written some Pseudo code and would like to convert it to Apex. Please take a look and let me know how. I have included a picture to help.
Pseudo Code:
# System Variable(s)
Variable System-Time
# Sensor Variable(s)
Variable Sensor-ATO-AWC-Level-Normal
Variable Sensor-ATO-AWC-Level-High
Variable Sensor-ATO-Reservoir-Level
Variable Sensor-AWC-Reservoir-Level
Variable Sensor-AWC-Remove-Level-Normal
Variable Sensor-AWC-Remove-Level-Low
# Pump Variable(s)
Variable Pump-ATO-Add
Variable Pump-AWC-Add
Variable Pump-AWC-Remove
# Switch Variable(s)
Variable Switch-ATO-Process
Variable Switch-Reset-ATO-Process
Variable Switch-AWC-Process
Variable Switch-AWC-Remove-Process
Variable Switch-AWC-Add-Process
Variable Switch-Reset-AWC-Process
Variable Switch-Force-AWC-Process
#########################################
# Kick Off ATO Process
#########################################
IF(Sensor-ATO-AWC-Level-Normal == Off && Sensor-ATO-AWC-Level-High = Off && Switch-AWC-Process !== "Failed"){
# Call Do ATO Process
Call SUB Do-ATO-Process();
}
#########################################
# Kick Off AWC Process
#########################################
IF((System-Time == 4:00PM || Switch-AWC-Process == "Started" || Force-AWC-Process == True) && Switch-AWC-Process !== "Failed"){
# Call Do AWC Process
Call SUB Do-AWC-Process();
}
#########################################
# Reset ATO Process After Failure
#########################################
IF(Switch-Reset-ATO-Process == "True"){
# Reset AWC Process To Enable Process For Next Run
Set Switch-ATO-Process = "";
Set Switch-Reset-ATO-Process == ""
}
#########################################
# Reset AWC Process After Failure
#########################################
IF(Switch-Reset-AWC-Process == "True"){
# Reset AWC Process To Enable Process For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";
Set Switch-Reset-AWC-Process == ""
}
#########################################
# AWC Process
#########################################
SUB Do-AWC-Process(){
# Set AWC In Process Switch
Set Switch-AWC-Process = "Started";
# If AWC Reservoir Has Water
IF(Sensor-AWC-Reservoir-Level == On){
# If Water Level Is Low And Water Level Is Not High
IF(Sensor-ATO-AWC-Level-Normal !== On && Sensor-ATO-AWC-Level-High !== On){
# Turn On ATO Process To Fill Water To Normal Level
Call SUB Do-ATO-Process ();
}
# ATO Level Is Normal Or High
ELSE{
# If ATO Fill Level Is Normal
IF(Sensor-ATO-AWC-Level-Normal == On && Sensor-ATO-AWC-Level-High !== On){
# If AWC Remove Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process !== "Complete"){
# Call Remove Water For AWC Process
Call SUB Do-AWC-Remove-Water-Process();
}
# If AWC Add Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process == "Complete"){
# Call Add Water For AWC Process
Call SUB Do-AWC-Add-Water-Process();
}
}
# ATO Fill Level Is High
ELSE{
# Send Error Notification - Water Level To High
Send Notification: "Could Not Complete AWC Because Water Level Is Too High";
# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";
}
}
}
# AWC Reservoir Does Not Have Enough Water
ELSE{
# Send Error Notification - Low AWC Water Level
Send Notification: "Could Not Complete AWC Because Reservoir Water Level Was Low";
# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";
}
}
#########################################
# ATO Process
#########################################
SUB Do-ATO-Process(){
# Set ATO Process To Started
Set Switch-ATO-Process = "Started";
# If ATO Reservoir Has Water
IF(Sensor-ATO-Reservoir-Level == On){
# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-ATO-Add UNTIL (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On);
# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
if(Switch-ATO-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){
# Set AWC Remove Water Process To Complete
Set Switch-ATO-Process = "Complete";
}
}
# ATO Reservoir Does Not Have Enough Water
ELSE{
# Send Error Notification - Low ATO Water Level
Send Notification: "Could Not Complete ATO Because Reservoir Water Level Was Low";
# Update ATO Process To Failed
Set Switch-ATO-Process = "Failed";
}
}
#########################################
# AWC Remove Water Process
#########################################
SUB Do-AWC-Remove-Water-Process(){
# Set AWC Remove Water Process To Started
Set Switch-AWC-Remove-Process = "Started";
# Turn On AWC Remove Water Pump Until Water Level Down To Normal Or Low Sensor
Turn On Pump-AWC-Remove UNTIL (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off);
# If AWC Level Normal Or ATO Level High
if(Switch-AWC-Remove-Process == "Started" && (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off)){
# Set AWC Remove Water Process To Complete
Set Switch-AWC-Remove-Process = "Complete";
}
}
#########################################
# AWC Add Water Process
#########################################
SUB Do-AWC-Add-Water-Process(){
# Set AWC Add Water Process To Started
Set Switch-AWC-Add-Process = "Started";
# Turn On AWC Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-AWC-Add UNTIL (Sensor-AWC-Add-Level-Normal == On || Sensor-AWC-Add-Level-High == On);
# If AWC Add Started And Normal Or High Water Level Sensor Is On
if(Switch-AWC-Add-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){
# Rest AWC Switch Variables For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";
}
}
Pseudo Code:
# System Variable(s)
Variable System-Time
# Sensor Variable(s)
Variable Sensor-ATO-AWC-Level-Normal
Variable Sensor-ATO-AWC-Level-High
Variable Sensor-ATO-Reservoir-Level
Variable Sensor-AWC-Reservoir-Level
Variable Sensor-AWC-Remove-Level-Normal
Variable Sensor-AWC-Remove-Level-Low
# Pump Variable(s)
Variable Pump-ATO-Add
Variable Pump-AWC-Add
Variable Pump-AWC-Remove
# Switch Variable(s)
Variable Switch-ATO-Process
Variable Switch-Reset-ATO-Process
Variable Switch-AWC-Process
Variable Switch-AWC-Remove-Process
Variable Switch-AWC-Add-Process
Variable Switch-Reset-AWC-Process
Variable Switch-Force-AWC-Process
#########################################
# Kick Off ATO Process
#########################################
IF(Sensor-ATO-AWC-Level-Normal == Off && Sensor-ATO-AWC-Level-High = Off && Switch-AWC-Process !== "Failed"){
# Call Do ATO Process
Call SUB Do-ATO-Process();
}
#########################################
# Kick Off AWC Process
#########################################
IF((System-Time == 4:00PM || Switch-AWC-Process == "Started" || Force-AWC-Process == True) && Switch-AWC-Process !== "Failed"){
# Call Do AWC Process
Call SUB Do-AWC-Process();
}
#########################################
# Reset ATO Process After Failure
#########################################
IF(Switch-Reset-ATO-Process == "True"){
# Reset AWC Process To Enable Process For Next Run
Set Switch-ATO-Process = "";
Set Switch-Reset-ATO-Process == ""
}
#########################################
# Reset AWC Process After Failure
#########################################
IF(Switch-Reset-AWC-Process == "True"){
# Reset AWC Process To Enable Process For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";
Set Switch-Reset-AWC-Process == ""
}
#########################################
# AWC Process
#########################################
SUB Do-AWC-Process(){
# Set AWC In Process Switch
Set Switch-AWC-Process = "Started";
# If AWC Reservoir Has Water
IF(Sensor-AWC-Reservoir-Level == On){
# If Water Level Is Low And Water Level Is Not High
IF(Sensor-ATO-AWC-Level-Normal !== On && Sensor-ATO-AWC-Level-High !== On){
# Turn On ATO Process To Fill Water To Normal Level
Call SUB Do-ATO-Process ();
}
# ATO Level Is Normal Or High
ELSE{
# If ATO Fill Level Is Normal
IF(Sensor-ATO-AWC-Level-Normal == On && Sensor-ATO-AWC-Level-High !== On){
# If AWC Remove Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process !== "Complete"){
# Call Remove Water For AWC Process
Call SUB Do-AWC-Remove-Water-Process();
}
# If AWC Add Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process == "Complete"){
# Call Add Water For AWC Process
Call SUB Do-AWC-Add-Water-Process();
}
}
# ATO Fill Level Is High
ELSE{
# Send Error Notification - Water Level To High
Send Notification: "Could Not Complete AWC Because Water Level Is Too High";
# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";
}
}
}
# AWC Reservoir Does Not Have Enough Water
ELSE{
# Send Error Notification - Low AWC Water Level
Send Notification: "Could Not Complete AWC Because Reservoir Water Level Was Low";
# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";
}
}
#########################################
# ATO Process
#########################################
SUB Do-ATO-Process(){
# Set ATO Process To Started
Set Switch-ATO-Process = "Started";
# If ATO Reservoir Has Water
IF(Sensor-ATO-Reservoir-Level == On){
# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-ATO-Add UNTIL (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On);
# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
if(Switch-ATO-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){
# Set AWC Remove Water Process To Complete
Set Switch-ATO-Process = "Complete";
}
}
# ATO Reservoir Does Not Have Enough Water
ELSE{
# Send Error Notification - Low ATO Water Level
Send Notification: "Could Not Complete ATO Because Reservoir Water Level Was Low";
# Update ATO Process To Failed
Set Switch-ATO-Process = "Failed";
}
}
#########################################
# AWC Remove Water Process
#########################################
SUB Do-AWC-Remove-Water-Process(){
# Set AWC Remove Water Process To Started
Set Switch-AWC-Remove-Process = "Started";
# Turn On AWC Remove Water Pump Until Water Level Down To Normal Or Low Sensor
Turn On Pump-AWC-Remove UNTIL (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off);
# If AWC Level Normal Or ATO Level High
if(Switch-AWC-Remove-Process == "Started" && (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off)){
# Set AWC Remove Water Process To Complete
Set Switch-AWC-Remove-Process = "Complete";
}
}
#########################################
# AWC Add Water Process
#########################################
SUB Do-AWC-Add-Water-Process(){
# Set AWC Add Water Process To Started
Set Switch-AWC-Add-Process = "Started";
# Turn On AWC Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-AWC-Add UNTIL (Sensor-AWC-Add-Level-Normal == On || Sensor-AWC-Add-Level-High == On);
# If AWC Add Started And Normal Or High Water Level Sensor Is On
if(Switch-AWC-Add-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){
# Rest AWC Switch Variables For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";
}
}



