filetest.spin echo and redirection
Rsadeika
Posts: 3,837
Based on the filetest.spin program, I added a Sensirion, and XBee module(s). What I am trying to do is datalog the temp data as it gets streamed to the master program. I created a getxb command, which captures a slice of the streaming data. When I try getxb > echo > test1.txt, I have two files created, but both are empty of data. I tried different combinations, and the best that I get are some empty files that are created. So, my question is, how can I get the captured slice of data inserted into a file, using getxb as the command? I know getxb works, because when I use getxb, I get the slice of data shown on the console screen.
Thanks
Ray
Thanks
Ray
Comments
Ray
On another note, I tried to run my modified filetest.spin with spin2cpp, and it came up with an error, so not everything can be resolved using spin2cpp.
Ray
One of several ways below. One can also use fgets and atof/strtod.
Ray
You said scanf didn't work; I showed you how it works. The atoi function is in our library; I use it in the simple calculator example. I'm sure Dave will be happy to address other issues.
Edit: I use atof in the simple calculator example. It and atoi are in the library and work fine of course.
Using the above general outline, I would like to have the logger start data logging when logmode gets changed to 1, and stop when it gets changed to a 0. So, far I am unable to get logfile.txt to appear as a valid file name, compiler keeps pointing this out as an error. I thought that the redirection would work within a PUB, but I guess it only works in the console IO mode. Any suggestions as to how I can get this to work as I would like?
Ray
You should be able to do the following:
Note that the file routines in CLIB aren't cog-safe, which means you can only do file I/O in one cog. You could provide your own locking mechanism to make it cog-safe. I also added the call to fflush to ensure that the data get written out to the log file. This wouldn't be necessary if you can ensure that you will cleanly close the file when you shut down.
I added the getxb, setclock, settime, date, and time functions which work as expected on my DNA-RTC board. The slave0 board which has the sensirion module also works as expected. So, the code below works mostly, except for the logger part, and I need more hints as to where I went wrong, to get it too work correctly.
Ray
You can't use stdoutfile for the logfile handle if you are also going to run the code in main. So you should declare a "logfile" variable and use that to write to the log file. This means you'll need to change Date, Time and getxb to write to logfile instead of stdoutfile.
As I said before, the file I/O routines in CLIB are not cog-safe. This means that you can't do file I/O from multiple cogs unless you implement a locking technique. I'll probably add cog-safeness before I update CLIB in the OBEX, but for now I would suggest that you avoid doing file I/O from multiple cogs.
I downloaded and looked at spinix, because it is a large program, I was unable to figure out where to start, too get it too run, on SimpleIDE. I tried shell.spin as a starting point, but did not get anywhere, so it must be another starting point. Since getting my FTm&s program functioning in a very minimal capacity, this might be a good time to explore some ideas about a very minimal OS that uses Spin, and then maybe it would be possible to have a matching version in C. IMHO, with the availability of modules and sensors like the XBee, BT, Sensirion, and others, it seems like a small OS is a necessary thing to have, in order to interact with the modules and sensors. Its either that or creating a program on the PC for controlling and maintaining data flow, which sounds to me like a little overkill for a project, or projects of this size, but I could be wrong. Any ideas about this?
Ray
I ran some tests on the code, and the logfile.txt file grows once per second as expected. You can run the other commands while the logger cog is running. Let me know if you have any questions.
I just ran the program with your two new files, unfortunately it gets to "Load and mount SD:" , and just stays that way. I guess it is not reading or sensing the SD card. I ran the C version of filetest to see if the SD card was corrupted, but that program reads the card OK, so it's not the card. I also tried moving the mount command from Start down to main, and that made it worse it never got to the "Load and mount SD:". I am not sure where the problem is, maybe the new cfileio.spin?
Ray
Ray
I suspect the problem with the date and time is happening when update is called from the logger routine. The first date print is OK because it is obtained before update is called. Since you are calling the I2C routines from two different cogs they might be both controlling the data and clock lines. Maybe cog 0 still have control over the lines when the other cog is trying to use them.
Ray
Ray
I'm now rethinking whether you would be better off using spinix. It would provide all the utilities you need, and they don't use up hub memory until you run them. There's something like 32 apps in the spinix/bin directory that average about 5.5K each. There's no way all of these functions could be included into a single program that would fit in the 32K hub RAM. That's the advantage of an OS than can load an app from the SD card. I'll play around with your logger program some more to see if it can be run under spinix.
Now, the thing I would have to think about is whether I want to have the slave units collect and store the data locally, then the master could, as a scheduled event, ask for the data to be sent to the master. With this scenario, it introduces a new problem, sending a file, which contains data, to the master. I have not seen anybody working on some File Transfer Protocols for the Propeller. In fact that opens up some more ideas, from the master I could instruct/schedule a data collection event to occur on the slave, then the slave, once it is done, could automatically send the data to the master. These are just a few ideas that I have in mind, how feasible, I do not know.
Ray
Ray
cog 0: main program
cog 1: CLIB serial I/O from c.start
cog 2: SD SPI driver from mount
cog 3: logger cog
cog 4: FullDuplexSerial from xb.Start(27, 26, 0, 9600)
You should tell the logger cog to stop logging, and then wait a fraction of a second before stopping the SPI driver. I suspect calling unmount would do an orderly shutdown of the file system.
As far as file transfer protocols, take a look at sb.spin and rb.spin in spinix/src. sb sends a binary file using the YMODEM protocol, and rb will receive a file. I use this with the Windows hyperterminal program to transfer files between my PC and the Prop's SD card.
I think that I will have to redo the slave0 program, using filetest.spin as the basis for IO, in fact maybe I will start calling it ftOS. I just found out that there is a SpinLMM available, will have to check that out to see if there would be any advantages with using it with the redo of the slave0 program. The only problem is, I noticed that SpinLMM can only be used with bst or homespun. I do not want to use bst anymore, and I only use 64 bit Win 7 OS, will the SpinLMM work or compile with SimpleIDE, without any problems?
I would also like to redo my master program in C, but cannot figure out how I could get an equivalent of the logger cog to work in C. I tried once before and I could not seem to get an FDS in main(), and to have an FDS, for the XBee, to work in a seperate cog at the same time. It seemed like it had to be one or the other, but not both at the same time. If I can figure that out, then maybe I can start a rework of my master program.
Ray
Ray
Please offer some details about what did or did not happen. Got a link to the demo?
Ray
SimpleIDE default baud rate is 115200, and seems like the demo is using 57600.
I get this: