Spinroot

A forum for Spin users

You are not logged in.

#1 Re: General » basic help with modex/feaver » 2011-01-25 14:45:06

Hi again!, What im trying to do now is use the test driver to read from a .PRN file and input those values into the state machine. I inserted an array bounds error in the update method to see if spin will pick it up, after running pan.exe spin doesnt seem to find the error. My question is: does it look like my test driver correctly driving my code through its states?
one more thing would it be incorrect to use a large c_code{} statement to do the file input? doing it that way picks up the array bounds error.


c_decl{
\#include "header.h"
\#include <stdio.h>
\#include <stdlib.h>
extern void myFuncInitialize(myStr *inst)
extern void myFunc2Update(myStr *inst, int num)
extern void myFunc3(myStr *inst)
extern myStr structure;
extern myStr1 str
int inputValue;
int ig;
char inputValuesArray [2];
FILE *inputFile;
};
c_track "&structure" "sizeof(myStr)";
c_track "&str" "sizeof(myStr1)";
init
{        //READS IN VALUES FROM A .PRN FILE AND INPUTS THEM TO THE STATE MAHCINE
    c_code
        {               
        inputFile = fopen("input.prn","r");
        myFunc1Initialize(&structure); //INITIALIZES THE STATE MACHINE WITH DEFAULTS           
        };
        if
        :: c_expr { (inputFile != NULL)} -> do::c_expr{(!feof(inputFile))} ->  c_code  {
                                                                                fgets(inputValuesArray,20,inputFile);
                                                                                ig = 0;
                                                                                        };
            do::c_expr{ig <=2} -> c_code {
                inputValue = inputValuesArray[ig];                   
                    switch (ig)
                {                   
                    break;                                   
                    case 1:   
                    structure.amount = (int)inputValue;
                    break;
                    case 2:    
                    structure.value = (int)inputValue;
                    break;               
                }   
                    ig++;
                myFunc2Update(structure,120);// UPDATES THE STATE MACHINE
                };
                :: else -> break
                od;
       
            c_code {
                    fclose(inputFile);
                   };   
        :: else ->  break
        od;
        ::else printf("cannot open file")
        fi;   
}

#2 Re: General » basic help with modex/feaver » 2011-01-20 14:57:00

Hi again, Am i suppose to include header files of my source code in promela driver or pan.c? Reason im asking is coz when i compile gcc -o pan pan.c mycode.c i get parse errors for myFunc and  " data definition has no storage type or class " warnings for the struct instance it seems the compiler doesnt seem to know about my struct.

im doing something like this
promela driver
c_decl
{
extern void myFunc(myStruct *strInst);
extern myStruct mst;
}

init{
blah blah..
}

myCode.c

void myFunc(myStruct *st)
{

blah blah
}

myCode.h

typedef struct
{
int name;
}myStruct;

#3 Re: General » basic help with modex/feaver » 2011-01-19 12:46:31

Ok, i seem to be getting a better understanding now! I do have one question though, the promela driver would basically become the 'main', how do i include a .c file that has my functions in promela?

#4 Re: General » basic help with modex/feaver » 2011-01-18 07:33:53

Thanks again for your help, I had a look at those papers. The way i understood what was going on in there was that you need to rewrite the source code in promela with the ability to include c code, I was trying to avoid coding in promela by using modex. So i guess i do not have a choice but to code the state machine in promela.

#5 Re: General » basic help with modex/feaver » 2011-01-12 13:54:39

Thanks for your prompt reply
I tried what you suggested and with a little tweaking of the "model" file it compiles now although Its still not clear to me how the model is extracted.
I am now trying to use modex with another program.
My state machine has a main.c where inputs are fed into the state machine, then there is another source file with functions that initialize the state machine,update its state and check whether inputs are vaild.

My question now is, do i extract the functions that make up the state machine or the main.c that inputs into my state machine.   

You said that modex is no longer maintained, has something replaced it? you also mentioned that modex has some limitations could you please elaborate on that.

#6 General » basic help with modex/feaver » 2011-01-11 07:24:47

crazyHorse
Replies: 14

Hi, i'm trying to use modex/feaver to generate my model to be used in spin, but i keep getting an undeclared error or parse error in pan.m . After using these commmands

$ modex main.prx
and
$ sh _modex_.run
In file included from pan.c:5320:
pan.m: In function `do_transit':
pan.m:23: error: `gate' undeclared (first use in this function)
pan.m:23: error: (Each undeclared identifier is reported only on
pan.m:23: error: for each function it appears in.)
pan.m:66: error: `gC' undeclared (first use in this function)
pan.m:78: error: `n' undeclared (first use in this function)
pan.m:116: error: `gS' undeclared (first use in this function)

Here are my source files
// main.c
#include "gate.h"
#define MAX 2

int main()
{
    int x;
    int y;
    int z;
    struct GATE_CONTROL gate;
   
    gate.numberOfEntries = 22;
    gate.maxNumber = 23;
    gate.state = OPEN;
    printf("%d",gate.state);
return 0;
}
// end main.c


// Gate.H
#ifndef GATE_H
#define GATE_H

int n;

typedef enum
{
   OPEN = 1,
   CLOSE = 0
}GATE_STATE;

struct GATE_CONTROL
{
  int numberOfEntries;
  int maxNumber;
  GATE_STATE state;
} ;

void setState(struct GATE_CONTROL gC, GATE_STATE gS);
int getState(struct GATE_CONTROL gC);
void Init(struct GATE_CONTROL gC, int n);

void setState(struct GATE_CONTROL gC, GATE_STATE gS)
{
    gC.state = gS;
}

int getState(struct GATE_CONTROL gC)
{
    return gC.state;
}

void Init(struct GATE_CONTROL gC, int n)
{
   
        gC.numberOfEntries = 0;
        gC.maxNumber = n;
        gC.state = OPEN;

}

#endif
//end Gate.H

//My test harnes file main.prx
%F main.c
%X -x
%L
import _all_
%%
//end main.prx

I'm sure something is missing in my test harness file, any help would be sincerely appreciated.

Board footer

Powered by FluxBB