??? 10/25/11 07:21 Read: times |
#184351 - programming language - not really Responding to: ???'s previous message |
Hi Jan
Not really inventing a programming language, just a method to execut a sequence of functions that I don't know in advance - I suppose that is a programming language..... heres what I have come up with based on the last excellent idea, about a rules engine, once mentioned it seems so simple. #include "c8051F040.h" #include "ports.h" #include "smoker_iopoints.h" #include "nib.h" #include "LCD.h" #include "time.h" #include "recipes.h" #define NUM_OF_RULES_PER_RECIPE 10 //this file handles the saving / restoring and control of the recipes for the smoker. //in short we have only a few variables that we are able to control we can load these in a struct and save the whole struct to flash. #define RULE_ACTION_ON 1 #define RULE_ACTION_OFF 2 #define RULE_ACTION_REGULATE 3 #define RULE_ACTION_PULSE 4 #define RULE_START_COND_ABSOLUTE 1 #define RULE_START_COND_PRIOR_RULE 2 #define RULE_START_COND_ANY_RULE 3 #define RULE_FEEDBACK_EXTERNAL_IO 1 #define RULE_FEEDBACK_TIME_OFF 2 #define RULE_FEEDBACK_TIME_ON 3 #define RULE_NOT_STARTED 0 #define RULE_IN_PROGRESS 1 #define RULE_COMPLETED 2 struct strct_rules{ unsigned char out_point; unsigned char action; unsigned char start_condition; unsigned char start_time; unsigned char stop_time; unsigned char feedback_rule; unsigned char feedback_point; }; struct recipe{ char title[16]; // RECIPE TITLE unsigned int run_time; struct strct_rules rules[NUM_OF_RULES_PER_RECIPE]; //each recipe has 10 rules that it can have. }; code struct recipe salmon = { "SALMON", //nice title 20, //run for 20mins { {HEAT_OUTPUT, RULE_ACTION_REGULATE, RULE_START_COND_ABSOLUTE, 0, 0, RULE_FEEDBACK_EXTERNAL_IO, THERMOSTAT_INPUT}, //turn on the element {SMOKE_OUTPUT, RULE_ACTION_ON, RULE_START_COND_ABSOLUTE, 0, 5, RULE_FEEDBACK_TIME_OFF, 0}, //turn on the smoke for 5mins {PUMP_OUTPUT, RULE_ACTION_PULSE, RULE_START_COND_PRIOR_RULE, 0, 1, RULE_FEEDBACK_TIME_OFF, 0}, //start the pump pulsing for 1 min on / off after smoke has been on for 5mins {SMOKE_OUTPUT, RULE_ACTION_PULSE, RULE_START_COND_PRIOR_RULE, 0, 1, RULE_FEEDBACK_TIME_OFF, 0} //start the smoke pulsing for 1 min on / off after pump has been on for 1mins } }; struct strct_running_recipe { struct recipe *recipe_in_flash; unsigned int recipe_elapsed_time; unsigned int rule_elapsed_time[NUM_OF_RULES_PER_RECIPE]; //hold variable for the elapsed time in a rule unsigned char rule_holding_var[NUM_OF_RULES_PER_RECIPE]; unsigned char rule_active[NUM_OF_RULES_PER_RECIPE]; }; //load a few defaults for us //bacon //salmon //kahawai //snapper //chicken //cheese //sausages //salami //cold smoke //hot smoke struct strct_running_recipe current_recipe; void funInitRecipe(void){ unsigned char i; static unsigned char j; current_recipe.recipe_in_flash = &salmon; current_recipe.recipe_elapsed_time = 0; for (i = 0; i< NUM_OF_RULES_PER_RECIPE; i++){ current_recipe.rule_elapsed_time[i] = 0; current_recipe.rule_holding_var[i] = NULL; current_recipe.rule_active[i] = RULE_NOT_STARTED; } i = current_recipe.recipe_in_flash->rules[1].stop_time; j = i; } void funExecuteRecipe(void){ //this function assumes that current_recipe is loaded with a recipe and is //available, we could have had it accept a recipe pointer but that seems kind of redunant //as we can only run one recipe at a time. static unsigned long start_time = 0; unsigned char rule_index = 0; if (start_time == 0){ start_time = sysTime; } //whip through all the rules and look for the inactive rules. for (rule_index = 0 ; rule_index < NUM_OF_RULES_PER_RECIPE; rule_index++){ if (current_recipe.rule_active[rule_index]== RULE_NOT_STARTED){ //rule is not active if (current_recipe.recipe_in_flash->rules[rule_index].start_condition == RULE_START_COND_ABSOLUTE){ //se if we are supposed to start on a time stamp. //obviously more to do in here. } } } } It's miles away from being finished as I want to load the structs from flash, and enter them from a keypad etc, rather than the hard coded method they are at the moment, but it allows me to prove it before adding the fluff. Feel free to critque the code. always interested. Hope it helps someone. Regards Marshall |
Topic | Author | Date |
User entered recipes ??? | 01/01/70 00:00 | |
Just create array of regular rules | 01/01/70 00:00 | |
Thanks - that's great | 01/01/70 00:00 | |
programming language | 01/01/70 00:00 | |
programming language - not really | 01/01/70 00:00 | |
consider enum | 01/01/70 00:00 | |
thanks - implemented. | 01/01/70 00:00 | |
Intelligence | 01/01/70 00:00 | |
I must have a stupid compiler | 01/01/70 00:00 | |
Not all compilers are as good at generate warnings | 01/01/70 00:00 | |
no warning/error on the compiler | 01/01/70 00:00 | |
response from Raisonance | 01/01/70 00:00 | |
enumerations on 8051 | 01/01/70 00:00 | |
enums are 8bit by default on Raisonance | 01/01/70 00:00 | |
NULL | 01/01/70 00:00 | |
Could you show me the code | 01/01/70 00:00 | |
compatibility et al | 01/01/70 00:00 | |
why change pointer to CODE? | 01/01/70 00:00 | |
enum advantage | 01/01/70 00:00 | |
user page does not work (at least for me) | 01/01/70 00:00 | |
try it now | 01/01/70 00:00 | |
re: enumerations on 8051 | 01/01/70 00:00 | |
Article on Hierarchical Menu Structure | 01/01/70 00:00 |