#include #include #include #include #include struct scada_point{ char name[35]; char tag[20]; double current_value; double next_value; unsigned char write_to_driver; //set to 1 to write to driver, set to 0 to write to real time DB unsigned int checksum; }; /* Internal scada variables and functions exit_loop : initialized at 0,on stop of driver its value is 1 scada_db : scada vector of struct scada_point items int numSamplePoints; : number of sample point inside scada database int processed_id; : itemID of the processed value void scan_rate(void) : scan rate void lock(void) : lock access of other threads to scada_db void unlock(void) : let other threads to access scada_db void post_value() : post the processed value to real time DB or to driver */ int calc_output_from_one_input(char* name_output, char* tag_output, char* name_input, int processed_id, char* processed_name, char* processed_tag, double delta); int main(int argc, char **argv) { int itemID; //index of item in database int r; double delta = 0.1; for(itemID = 0; ;) { if(exit_loop) { break; } lock(); processed_id = itemID; //////////Add your code from here///////////////////// //Example code calc_output_from_one_input("TempCVTPoint01","VALUE", "HVACTemp19Point01", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); calc_output_from_one_input("TempCVTPoint02","VALUE", "HVACTemp19Point02", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); calc_output_from_one_input("TempCVTPoint03","VALUE", "HVACTemp19Point03", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); calc_output_from_one_input("TempCVTPoint04","VALUE", "HVACTemp19Point04", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); calc_output_from_one_input("TempCVTPoint05","VALUE", "HVACTemp19Point05", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); calc_output_from_one_input("TempCVTPoint06","VALUE", "HVACTemp19Point06", itemID, scada_db[itemID].name, scada_db[itemID].tag, delta); //Uncomment this to see relation between itemID and sample point name e tag name //printf("itemID = %d\n", itemID); //printf("scada_db[%d].name = %s\n", itemID, scada_db[itemID].name); //printf("scada_db[%d].tag = %s\n", itemID, scada_db[itemID].tag); //printf("scada_db[%d].current_value = %lf\n", itemID, scada_db[itemID].current_value); ///////////////////to here////////////////////////////////////////////// unlock(); fflush(stdout); if(itemID == 0) { scan_rate(); } itemID++; if(itemID == numSamplePoints) { itemID = 0; } } return 0; } int calc_output_from_one_input(char* name_output, char* tag_output, char* name_input, int processed_id, char* processed_name, char* processed_tag, double delta) { int r; int item_id_input; double calculated; double input_value; if((r = strcmp(processed_name, name_output) == 0) && (r = strcmp(processed_tag, tag_output) == 0)) { for(item_id_input = 0; item_id_input < numSamplePoints; item_id_input++) { if(r = strcmp(scada_db[item_id_input].name, name_input) == 0) { printf("scada_db[%d].current_value = %lf\n", processed_id, scada_db[processed_id].current_value); printf("scada_db[%d].current_value = %lf\n", item_id_input, scada_db[item_id_input].current_value); printf("\n"); input_value = scada_db[item_id_input].current_value; //////////Edit here your calculation//////////////////// calculated = ((input_value-16384)/327.68* 9/5) + 32; if((abs(scada_db[processed_id].current_value - calculated) > delta)) { scada_db[processed_id].write_to_driver = 0; scada_db[processed_id].current_value = calculated; post_value(); } return 1; } } } return 0; }