diff --git a/README.txt b/README.txt deleted file mode 100644 index 2423904..0000000 --- a/README.txt +++ /dev/null @@ -1,276 +0,0 @@ -================================================== -SIMUINO is a Arduino Simulator. -Code: c++ -Platform: Linux (Ubuntu) -Version: 0.0.6 - -Developed by Benny Saxen, ADCAJO -================================================== - -Content: - -1. Get started -2. Commands -3. Display -4. Sketch information -5. Configuration -6. Scenarios -7. Supported language functions - --------------------------------------------------- -1. Get started --------------------------------------------------- -Quick starter guide: - -1. Download simuino zip-file from Google Code, project simuino - -2. Unzip the file. A directory named simuino will be created. - -3. Go to directory simuino. Compile: g++ -O2 -o simuino simuino.c -lncurses - You need to have installed packages for ncurses-dev. - -4. Run Simuino: ./simuino - Note - expand the size of your terminal first. Why not maximize it. - Simuino will start in Admin Mode. - -5. If this is the first time you start Simuino. - Enter 'conf' - the configuration is shown in the message window. - Enter 'sketch '. This will be saved in the config. - Simuino will use this information when loading the sketch. - -6. Enter 'load 300' . This will create simulation of 300 steps. Max steps is 2000 - -7. Type 'run' to enter Run Mode. In the message window is a list of avaiable commands. - Press 's' to step or 'r' to complete a loop. Press 'a' to reset and start from step 1. - -8. Press 'q' to leave Run Mode. - -9. Enter 'exit' if you want to exit Simuino - -In parallell, you can edit your sketch in a editor. Type 'load 123' for loading the sketch and creat -a simulation of 123 steps. In your sketch, you are able to add/update the scenario data (i.e. digital -pin reads, Analog pin reads and Interrupts. The possibility to customize log-text, is also done in the -sketch. - --------------------------------------------------- -2. Commands --------------------------------------------------- -Commands in Run Mode: - s step - r run/complete a loop - g run complete simulation - a re-run simulation - q enter Admin Mode, not during stepping - h show this information - -Commands in Admin Mode: -ex exit Simuino -help show this information -load load configured sketch file -run enter Run Mode -scen show scenario data -conf display configuration -loop show loop information -clear delete local sketch file and simulation file - -sketch set sketch source file, saved in config -serv set Servuino data file, saved in config -delay set delay to x (ms), saved in config -log set log level to x (0,1,2,3), saved in config -record record log to file: log.txt (1/0), saved in config - --------------------------------------------------- -3. Display --------------------------------------------------- -The SIMUNIO displays 4 windows - - - The Arduino board with the pin-layout - - Serial Interface - - Logs - - Messages - -3.1 Arduino board Window - - For each pin the following data will be displayed: - Input or Output pin (in/out) - Reading or writing (r/w) - Digital HIGH or LOW value (1 or 0) and values of analog pin (0 - 1023) - -3.2 Serial Interface - - Anything printed on this interface will be shown here. - -3.3 Logs - - Most functions in the Arduino reference library will be displayed. - Every line has two index: loop number, pseudo-time-elapsed, i.e steps/instructions. - The log-text can be customized to be more readable for the specific appliaction, see chapter 4 below. - -3.4 Message - - Used to show misc. information, such as configuration, errors, scenario data, etc. - - --------------------------------------------------- -4. Sketch information --------------------------------------------------- - -Customized logging: - -Add the following rows in your sketch with suitable log-text according to your specific application. - -Example: -// SKETCH_NAME My_sketch_name -// PINMODE_OUT 2 "your log text for pin 2" -// PINMODE_IN 4 "your log text for pin 4" -// DIGITALWRITE_LOW 11 "your log text for pin 11 when HIGH" -// DIGITALWRITE_HIGH 11 "your log text for pin 11 when LOW" -// ANALOGREAD 1 "your log text for pin 1" -// DIGITALREAD 10 "your log text for pin 10" -// ANALOGWRITE 14 "your log text for pin 14" - -This will make Simuino show your text in the log window. - --------------------------------------------------- -5. Configuration --------------------------------------------------- - -The following parameters are configured in the file, config.txt : - -LOG_LEVEL 2 // Level of information to be displayed during simulation (0,1,2,3) -DELAY 100 // Delay in ms between each step/instruction (0 - 1000) -LOG_FILE 0 // Save the log information to the file: log.txt (YES=1,NO=0) -SKETCH // file name of source of the sketch (used when loading) -SERVUINO servuino/data.se // where to find simulation data --------------------------------------------------- -6. Scenarios --------------------------------------------------- - -In order to be able to run specific scenarios, controlled by values read from pins, -it is possible to specify what value shall be read per step/instruction and pin. -Only changes is needed to be specified, example: - -10 123 -14 150 -20 45 - -will generate: - -10 123 -11 123 -12 123 -13 123 -14 150 -15 150 -16 150 -17 150 -18 150 -19 150 -20 45 -21 45 - -and so on... - -The scenario data is specified in your sketch-file, se example below.. - -Below is an example of a scenario file. ------------------------------------------ -// digital_pins -// step 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -// --- ------------------------------------------- -// SCENDIGPIN 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 -// SCENDIGPIN 100 0 1 0 0 0 0 0 0 0 0 0 0 0 0 -// SCENDIGPIN 200 1 0 1 0 0 0 0 0 0 0 0 0 0 0 -// SCENDIGPIN 300 1 1 0 0 0 0 0 0 0 0 0 0 0 0 -// -// analog_pins -// step 0 1 2 3 4 5 -// ------------------------------ -// SCENANAPIN 0 37 0 0 0 0 11 -// SCENANAPIN 100 56 0 0 0 0 12 -// SCENANAPIN 200 0 0 0 0 0 13 -// SCENANAPIN 300 123 0 0 0 0 14 -// -// interrupts -// step 0 1 -// ---------- -// SCENINRPT 16 1 0 -// SCENINRPT 19 0 0 -// SCENINRPT 25 1 0 -// SCENINRPT 30 1 1 -// SCENINRPT 40 0 1 -// SCENINRPT 55 1 1 -------------------- -End of example - - -Note - The data has to be given in ascending step order. - --------------------------------------------------- -7. Supported language functions --------------------------------------------------- -Unsupported functions are implemented with a dummy, in order to compile without errors. - -Digital I/O - pinMode() Yes - digitalWrite() Yes - digitalRead() Yes -Analog I/O - analogReference() No - analogRead() Yes - analogWrite() - PWM Yes -Advanced I/O - tone() No - noTone() No - shiftOut() No - shiftIn() No - pulseIn() No -Time - millis() Yes - micros() Yes - delay() Yes - delayMicroseconds() Yes -Math - min() Yes - max() Yes - abs() Yes - constrain() Yes - map() Yes - pow() Yes - sqrt() Yes -Trigonometry - sin() Yes - cos() Yes - tan() Yes - Random Numbers - randomSeed() Yes - random() Yes -Bits and Bytes - lowByte() No - highByte() No - bitRead() No - bitWrite() No - bitSet() No - bitClear() No - bit() No -External Interrupts - attachInterrupt() Yes - detachInterrupt() Yes -Interrupts - interrupts() No - noInterrupts() No -Communication - Serial - begin() Yes - end() Yes - available() No - read() No - peek() No - flush() Yes - print() Yes - println() Yes - write() Yes - --------------------------------------------------- -End of README --------------------------------------------------- diff --git a/decode_lib.c b/decode_lib.c index 27adb40..b8620f3 100644 --- a/decode_lib.c +++ b/decode_lib.c @@ -1,7 +1,18 @@ -//================================================ -// Developed by Benny Saxen, ADCAJO -//================================================ +/* Simuino is a Arduino Simulator based on Servuino Engine + Copyright (C) 2011 Benny Saxen + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ //===================================== // Functions diff --git a/help.txt b/help.txt index f88a956..9157faf 100644 --- a/help.txt +++ b/help.txt @@ -9,6 +9,8 @@ a re-run simulation + v set value in next analogRead/digitalRead + w toggles window layout mode. l show loop information diff --git a/simuino.c b/simuino.c index 87dc449..0eea1c0 100644 --- a/simuino.c +++ b/simuino.c @@ -1,6 +1,19 @@ -//================================================ -// Developed by Benny Saxen, ADCAJO -//================================================ +/* Simuino is a Arduino Simulator based on Servuino Engine + Copyright (C) 2011 Benny Saxen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + #include #include #include @@ -40,8 +53,6 @@ #define CHANGE 1 #define RISING 2 #define FALLING 3 -//#define MAX_SERIAL 100 -//#define MAX_LOG 200 #define MAX_STEP 2000 #define MAX_LOOP 2000 #define MAX_PIN_ANALOG 6 @@ -103,6 +114,9 @@ int s_mode = ADMIN; int g_warning = YES; int g_silent = 0; int g_scenSource = 0; +int g_pinType = 0; +int g_pinNo = 0; +int g_pinValue = 0; void (*interrupt0)(); void (*interrupt1)(); @@ -125,11 +139,9 @@ int baud = 0; int error = 0; // Log -//int logging = YES; char logBlankRow[500]; // Serial Interface -//int serialSize = 1; int serialMode = OFF; char prevSerial[SIZE_ROW]; char serBlankRow[500]; @@ -166,6 +178,7 @@ WINDOW *uno,*ser,*slog,*msg; static struct termios orig, nnew; char stemp[80]; +char gplFile[80]; #include "simuino.h" #include "simuino_lib.c" @@ -359,7 +372,7 @@ void openCommand() s_mode = ADMIN; g_silent = 0; - readMsg(listConf); + readMsg(gplFile); while(strstr(str,"ex") == NULL) { @@ -385,11 +398,16 @@ void openCommand() g_silent++;; if(g_silent > 1)g_silent = 0; } + else if(strstr(sstr,"gpl")) + { + readMsg(gplFile); + } else if(strstr(sstr,"run")) { stop = 0; if(n == 2)stop = atoi(command[1]); runMode(stop); + if(stop==0)putMsg(4,"Back in Run Mode!"); } else if(strstr(sstr,"res")) // reset simulation { @@ -599,7 +617,7 @@ void openCommand() // strcpy(confSketchFile,command[1]); confSteps = atoi(command[1]); } - + g_scenSource = 0; loadCurrentProj(); } else if(projNo > 0 && projNo < 10) @@ -612,7 +630,7 @@ void openCommand() } else { - putMsg(msg_h-2,"Unknown command"); + putMsg(msg_h-2,"Unknown A command"); } } } @@ -621,7 +639,7 @@ void openCommand() void runMode(int stop) //==================================== { - int ch,x; + int ch,x,step; char tempName[80],syscom[120],temp[80]; strcpy(tempName,"help.txt"); @@ -636,23 +654,28 @@ void runMode(int stop) return; } - readMsg(tempName); - - wmove(uno,UNO_H-2,1); - wprintw(uno," "); - if(g_silent==0)mvwprintw(uno,UNO_H-2,1,"R%1d>",confWinMode); - if(g_silent==1)mvwprintw(uno,UNO_H-2,1,"R%1d<",confWinMode); - show(uno); - wmove(uno,UNO_H-2,4); + //readMsg(tempName); + putMsg(4,"Run Mode. Press h for help."); - while((ch!='q')&&(ch!='x')) + while(1) { + wmove(uno,UNO_H-2,1); + wprintw(uno," "); + if(g_silent==0)mvwprintw(uno,UNO_H-2,1,"R%1d>",confWinMode); + if(g_silent==1)mvwprintw(uno,UNO_H-2,1,"R%1d<",confWinMode); + show(uno); + //wmove(uno,UNO_H-2,4); + ch = getchar(); - if (ch=='h') + if (ch=='q' || ch=='x') { - readMsg(tempName); + return; } + if (ch=='h') + { + readMsg(tempName); + } else if(ch=='z')//silent mode { g_silent++;; @@ -699,17 +722,26 @@ void runMode(int stop) } else if (ch=='v') { + step = currentStep + 1; + putMsg(4," Enter value to be read"); + analyzeEvent(simulation[step]); wgetstr(uno,temp); x = atoi(temp); - //setNextRead(currentStep+1,currentPin,x); g_scenSource = 1; // steps, source, pintype, pinno, pinvalue, pinstep - sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d;",confSteps,g_scenSource,ANA,5,x,currentStep+1); - x=system(syscom); + sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,x,currentStep+1); + putMsg(5,syscom); + x=system(syscom); init(confWinMode); initSim(); resetSim(); + readSketchInfo(); readSimulation(confServuinoFile); + g_warning = NO; + x = confDelay; + confDelay = 0; + runMode(step); + confDelay = x; unoInfo(); } else if (ch=='l') @@ -737,8 +769,9 @@ void runMode(int stop) // Todo save to conf } else - putMsg(msg_h-2,"Unknown command"); + putMsg(msg_h-2,"Unknown R command"); } + return; } //==================================== int main(int argc, char *argv[]) @@ -747,6 +780,8 @@ int main(int argc, char *argv[]) char syscom[120]; int ch,i,x; + strcpy(gplFile,"gpl.txt"); + if(argc == 2) { strcpy(currentConf,argv[1]); @@ -773,6 +808,8 @@ int main(int argc, char *argv[]) if(confLogFile == YES)resetFile("log.txt"); + readMsg(gplFile); + openCommand(); //tcsetattr(0,TCSANOW, &orig); diff --git a/simuino.h b/simuino.h index 10dd90b..0874f99 100644 --- a/simuino.h +++ b/simuino.h @@ -1,3 +1,19 @@ +/* Simuino is a Arduino Simulator based on Servuino Engine + Copyright (C) 2011 Benny Saxen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ +void analyzeEvent(char *Event); int readEvent(char *ev, int step); int readComment(int step); void mLog0(const char *p); diff --git a/simuino_lib.c b/simuino_lib.c index 98749e2..e3162a9 100644 --- a/simuino_lib.c +++ b/simuino_lib.c @@ -1,7 +1,18 @@ -//================================================ -// Developed by Benny Saxen, ADCAJO -//================================================ +/* Simuino is a Arduino Simulator based on Servuino Engine + Copyright (C) 2011 Benny Saxen + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ //==================================== int __nsleep(const struct timespec *req, struct timespec *rem) @@ -34,6 +45,24 @@ void iDelay(int ms) msleep(ms); } +//==================================== +void analyzeEvent(char *event) +//==================================== +{ +int step,pin,value; +char str[80]; +{ + if(strstr(event,"analogRead") || strstr(event,"digitalRead")) + { + sscanf(event,"%d %s %d %d",&step,str,&pin,&value); + g_pinNo = pin; + g_pinValue = value; + if(strstr(event,"analog")) g_pinType = ANA; + if(strstr(event,"digital")) g_pinType = DIG; + if(currentStep+1 != step) putMsg(5,"Step No Mismatch in analyzeEvent"); + } +} +} //==================================== void show(WINDOW *win) //==================================== @@ -59,7 +88,8 @@ void show(WINDOW *win) wmove(win,0,2); wprintw(win,"Messages"); } - + + wmove(uno,UNO_H-2,4); wrefresh(win); iDelay(confDelay); } @@ -962,7 +992,8 @@ void readMsg(char *fileName) { wmove(msg,msg_h-2,1); wprintw(msg,"press any key for next page >>"); - show(msg); + // wmove(msg,msg_h-2,1); + wrefresh(msg); ch = getchar(); wscrl(msg,msg_h-2); i = 1;