Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Marshall Brown
10/25/11 01:21
Read: 586 times
New Zealand

#184351 - programming language - not really
Responding to: Jan Waclawek'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_PULSE       4

#define RULE_START_COND_ANY_RULE       3

#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
        {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
//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

List of 23 messages in thread
User entered recipes ???      Marshall Brown      10/24/11 13:35      
   Just create array of regular rules      Per Westermark      10/24/11 15:30      
      Thanks - that's great      Marshall Brown      10/24/11 17:35      
         programming language      Jan Waclawek      10/25/11 00:55      
            programming language - not really      Marshall Brown      10/25/11 01:21      
               consider enum        Per Westermark      10/25/11 01:48      
                  thanks - implemented.      Marshall Brown      10/25/11 02:23      
                     Intelligence      Per Westermark      10/25/11 02:34      
                        I must have a stupid compiler      Marshall Brown      10/25/11 03:05      
                           Not all compilers are as good at generate warnings      Per Westermark      10/25/11 03:28      
                              no warning/error on the compiler      Marshall Brown      10/25/11 03:55      
                                 response from Raisonance      Marshall Brown      10/27/11 09:51      
                  enumerations on 8051      Andy Peters      10/25/11 12:14      
                     enums are 8bit by default on Raisonance      Marshall Brown      10/25/11 12:42      
                        NULL      Jan Waclawek      10/26/11 04:08      
                           Could you show me the code      Marshall Brown      10/26/11 13:49      
                              compatibility et al      Jan Waclawek      10/27/11 04:15      
                                 why change pointer to CODE?      Marshall Brown      10/27/11 10:21      
                                    enum advantage      Michael Karas      10/27/11 11:18      
                                    user page does not work (at least for me)      Jan Waclawek      10/28/11 15:26      
                                       try it now      Marshall Brown      10/30/11 17:08      
                     re: enumerations on 8051      Andy Peters      11/01/11 15:22      
   Article on Hierarchical Menu Structure      Aubrey Kagan      11/02/11 09:42      

Back to Subject List