Need advice on eetest2 experiment
Rsadeika
Posts: 3,837
I guess what I need are some ideas as to how to "run" a file that is created with echo() command. I will be using the QuickStart board, so that is why I will be working with eetest2(filetest.c that uses the EEPROM) for the start of this project. Basically what I would like to accomplish is to create a batch file of sorts that will run the commands that are listed in the file, so for example:
run flashLED.bat
And flashLED.bat would contain:
high(16)
sleep(4)
low(16)
Of course this will be done in C, using eetest2 as example code. I was looking at Cat() command, trying to get an idea as to how I would change that around, so it would just execute the lines as opposed to printing them on the screen, nothing seems to be jumping out at me at the moment. I guess I need a nudge in the right direction.
Thanks
Ray
run flashLED.bat
And flashLED.bat would contain:
high(16)
sleep(4)
low(16)
Of course this will be done in C, using eetest2 as example code. I was looking at Cat() command, trying to get an idea as to how I would change that around, so it would just execute the lines as opposed to printing them on the screen, nothing seems to be jumping out at me at the moment. I guess I need a nudge in the right direction.
Thanks
Ray
Comments
As far as executing high, sleep and low it would be easier if they worked like the other commands. That is, flashLED.bat would look like:
high 16
sleep 4
low 16
Ray
The last line of the Run routine is just "buff2". All that does is get the address of buff2. Does that compile? The compiler should be issuing a warning on that at the very least. What you really need to do is loop on the strings in buff2, and then you need to parse them, and then you need to call some function to execute the various commands.
I think I can quickly modify the filetest program to do what you want to do. I take a look at it later today.
My thought process on this was, trying to get it down to the simplest form. I started with:
Run(...)
{
high(22);
}
which ran correctly, it lit the LED. So, if I were to capture high(22) in the buff2, and then have buff2, in the code, it would act just like high(22)? Which I guess is not the correct way of thinking about this? I guess that if buff2 is just an address, then of course it will not run the command. I guess I have to think about this some more.
Ray
So the easier way to implement this would be to make your batch file commands conform to the same syntax. So "high(22)" would be "high 22", which would then call the "High" function, which would convert argv[1] to a number and call the high function with that number.
EDIT: There should be an "fclose(cmdfilein)" after hitting the end-of-file on the batch file. You would also need to close the current batch file if you allow calling another batch file. Of course, if you call another batch file none of the lines after that will be executed in the original batch file unless you put the file handles on a queue.
echo ledon 22 > test.bat
echo wait 5000 >> test.bat
echo ledoff 22 >> test.bat
This sequence adds the commands to the test.bat file. The next step is to run the .bat file:
run test.bat
After running the test.bat file it does, in fact work, as expected. At least, with Dave Hein's help, I am seeing some satisfactory results.
This is a very crude and simplistic scripting attempt, now what it needs is a very crude and simplistic editor or some means by which you can edit the .bat file. I think it would get very tiresome if you had to keep making a new .bat file using the echo way. The other problem is, when you run the .bat file, it runs in the foreground, you have to wait the five seconds before you can get the keyboard back. I guess this could be taken care of by using some pthreads in the program.
If somebody has some ideas for improving the code, I would appreciate the ideas.
Ray
a, If you use pthreads, I could not find a solution for getting around the gets() problem, lack of C knowledge on this one.
b, If you use cognew, then you are locked into CMM. The use of cognew, the way I see it, will not run in XMM, and therefore you are locked into CMM limits.
The reason I am experimenting with this is, I thought it would be great to have a batch/script facility for easy manipulation of a boebot, or other such device(s). I was thinking of coming up with some suitable commands to control the motion of the robot for a batch/script file coordinated session, or movement of the device. Anybody have some thoughts on this?
Ray
The problem is whether or not a function "blocks" other threads from running. Generally pthreads is an advanced subject that is made available for those who know how to use them.
This is a misunderstanding. XMM/XMMC programs must copy code from the external storage to HUB space before doing cognew. I have several projects that do this.
I am probably going to go with the cognew concept and just stick with the CMM constraint, maybe it will force me to create some very tight code.
Just to remind everybody, any original code that I come up with, is not MIT or Public domain, it is just Open Source, no license, if you have any use for it, use it.
Ray
Again, thanks for all your help.
Ray
Fair enough. Maybe it's not so clear because it is not in the xmm example ....
https://code.google.com/p/propgcc/source/browse/demos/toggle/cog_c_toggle/toggle.c
Look at the start function. Looks like the pasm_toggle example does not have it.
When you combine code in an original way, the work you did is most certainly yours. I'm sorry that things have to get weird around here sometimes (not a statement about Dave's license or otherwise). Almost all code in propeller-gcc demos is Copyright Parallax, and they want you to use it to your advantage.
Please do not scrub or remove your code from the forum. I have found it extemely helpful.
I have decided to continue with this project, after putting in my order for a boebot from Parallax. Since I have a PropBoe, that will be put on the robot, along with an Xbee module, I feel my idea to control it remotely is a sound one. Now I just have to work out the new code, with no license attached, just my new statement. So, for now, I have to wait for my boebot, before any serious code gets developed, and find some C examples as to how to control the servos so I can get the robot to move. Since the boebot will have "whiskers", and the wheel encoder, I guess I will need some C example code for that also. After thinking about what I just mentioned, I will probably need some super tight code, if I want it to fit in the CMM model.
Ray