Spinneret SD Card usage problem- help please?
Hey all,
I'm trying to understand the HTTPServer object better, and I'm definitely making some headway. But I am getting myself stumped here.
Where I've listed this <========== in the code is my question. Is this variable equal to 0 when no one is trying to get or post to the server?
The reason I'm asking, is because I need to run a method in another cog that uses the SDcard to write and append static *.xml files. I'm trying to think of a way to ensure that I don't try to use any of the sdcard methods from two cogs at once. I did that today and it made some really interesting files and folders on the sdcard... heh. Had to format it and start over.
So, if fifosocket is equal to 0 when there is no traffic, I can use that as a means to tell my other cog that it's ok to go ahead and write or append files to the sd card. Or at least it's ok to start at that instant.
I hope this question makes sense.
Thanks in advance!
Robert
I'm trying to understand the HTTPServer object better, and I'm definitely making some headway. But I am getting myself stumped here.
PUB Main | packetSize, id, i, reset, j, temp
'' HTTP Service
GetSntp(3)
repeat
repeat until fifoSocket == 0 <================================== does this = 0 when there are no requests to serve up a file?
SDCard.changeDirectory(@approot)
bytefill(@rxdata, 0, RxTx_BUFFER)
if(debug)
'pst..str(string(13, "----- Start of Request----------------------------",13))
QueueDump
else
pause(DELAY)
' Pop the next socket handle
id := DequeueSocket
if(id < 0)
'pst..str(string(13,"Id < 0"))
'pst..dec(id)
'pst..char(13)
nextPUB Main | packetSize, id, i, reset, j, temp
Where I've listed this <========== in the code is my question. Is this variable equal to 0 when no one is trying to get or post to the server?
The reason I'm asking, is because I need to run a method in another cog that uses the SDcard to write and append static *.xml files. I'm trying to think of a way to ensure that I don't try to use any of the sdcard methods from two cogs at once. I did that today and it made some really interesting files and folders on the sdcard... heh. Had to format it and start over.
So, if fifosocket is equal to 0 when there is no traffic, I can use that as a means to tell my other cog that it's ok to go ahead and write or append files to the sd card. Or at least it's ok to start at that instant.
I hope this question makes sense.
Thanks in advance!
Robert

Comments
You'll have to halt the sockets. The following snippet of code will save the run-time TCP socket IDs and halt socket id. If you wanted to halt all 4 sockets you would have to invoke SetTcpSocketMaskById four times. Once for each socket.
'save current socket state tempMask := tcpMask SetTcpSocketMaskById(id, 0)On SD IO completion, we'll have to put the a single socket back in operation.
tcpMask := tempMask 'reset the socket InitializeSocket(id)Keep in mind that halting all the sockets mean HTTP requests can be missed.
PRI LogData|Bcnt,tempMask {{ Every 15 minutes we want to log the latest values in an xml file. }} 'save current socket state tempMask := tcpMask SetTcpSocketMaskById(0, 0) If (Minute==3) OR (Minute==57) OR (Minute==59) OR (Minute==1) repeat while oneshot==0 SDCard.changeDirectory(@approot) 'This one re-writes data with the most current values. SDCard.openFile(@logfile, "W") SDCard.writeString(String("<xml>",13)) SDCard.writeString(String("<root>", 13)) repeat Bcnt from 0 to 44 SDCard.writeString(String("<IOS")) SDCard.writeDec(Bcnt) SDCard.writeString(String(">")) SDCard.writeDec(IOS[Bcnt]) SDCard.writeString(String("</IOS")) SDCard.writeDec(Bcnt) SDCard.writeString(String(">")) SDCard.writeString(String(13)) SDCard.writeString(String("</root>", 13)) SDCard.writeString(String("</xml>", 13)) SDCard.closeFile oneshot:=1 Else oneshot:=0 tcpMask := tempMask 'reset the socket InitializeSocket(0)By doing this, if I try to call up a web page when I'm running this Logdata method- will the webserver just wait and then process the request once I reset the socket? If I used it for all 4 sockets that is (instead of just one as shown)
repeat 'current process repeat until fifoSocket == 0This action will take control until completion making any socket request wait.repeat repeat until lockout== 0 'This will hold us up until the datalogging is completed. 'Method Datalog sets it to 1 as soon as it starts, and 'sets it back to 0 when complete. repeat until fifoSocket == 0But this still seems like it won't really work exactly right. I think I'd still need to do something similar in the datalog method to ensure it doesn't start writing a file at the instant the dispatcher method is fetching one to serve up.
repeat if(isLogEvent) 'process the data log repeat until fifoSocket == 0Keep in mind the data log process will block socket Rx processing. There are 4 Rx socket buffers. Once the 4 Rx buffers are in use any subsequent client requests can produce unexpected requests depending on the persistence of the client.