Advice for PropTCP use
grindel
Posts: 68
So when proptcp first came out, I think it would actually reference a html file. I've since lost those files, but now the web page is imbedded inline with the code as small sections of information, I don't know if the size of the packet of information has anything to do with the buffer size yet. Anyway, I think I can get buttons to do things pretty easilly to do forward backwards and turn left and right on the robot. But I think I would like to experiment further with using java sliders as a more intuitive input. I envision a up and down slider for forward and backeards, left and right slider to turn and a full stop button that would return the sliders to neutral. I've found a tutorial here: http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html for sliders. The full stop button might be an issue because it has to effect the user side as well as the server side. What do you think...any advice? I'm at the infant stages of this and I have the unfortunate habit of bumbling through things without really knowing what is going on. I'll poke at it some more and maybe it is easier than I think. Has this been done before? Has someone already written a robot interface for propTCP?
Thanks,
Thanks,
Comments
One thing I have figured out is that when you hit submit the computer sends the server a text string and that ends up in the @reqstr variable. so, for instance, I move the slider half way and hit submit, @reqstr looks like this: "GET /sb2.html?up=50 HTTP/1.1" where 50 is the slider position.
I try to parse this string with the following code:
panda:=@reqstr
kung:=byte [panda] [17]-48
foo:=byte [panda] [18]-48
ups:=kung*10+foo
kung and foo seem to output correctly when I display their individual decimal values to the web page, (kung appears to =5 and foo appears to equal 0) but ups always seems to be 0 or -1. All variables are declared as longs. I also have no idea why I have to subtract 48...
I hate asking for help, considering the depths of my ignorance, but I appreciate the advice and expertise
This is not how you should parse a string, as it is to much hardcoded. Whenever you change the name of the slider (make it longer or shorter) you have to adapt the indexes. You should have a function which searches for a name and returns the value.
getRequestLong( "up" ) for example.
This will search for "up" in the request string, skip the "=" and convert the following bytes into a long. The end of that value would be a space (seems to be the separator between 50 and HTTP) or a "&" (this would be the separator between 2 different input-fields if send with the same form).
The -48 comes from the fact that you have the number in a string representation. "0" has the ASCII-value 48. So, "5" - 48 is the same as "5"-"0" which is 5. "0" - "0" = 0
Your method will definitely fail when you send 100, as it'll return 10 in this case.
Why it fails at the moment I can't tell you currently, have to be back home to do some more investigations/testing.
It will also allow you to do some fancy things with graphics and feedback that would otherwise be highly involved.
http://jquery.com
If you can work out a way to read the http files from an SD card, I am happy to write the interface for you, if you're interested.
But again, having a parser which parses the request is important. Because the parser has to return the name of the HTML or JS that has been requested.
I guess I'd try it with a simple solution:
Let's say the maximum number of parameters you want to pass to a single request is 10. I'd create a word array with 11 elements (1 for the page name).
for example: GET /sb2.html?up=50&left=20 HTTP/1.1 RESULT (let's say # would be a real 0 byte, not a "0" character):
GET /sb2.html#up=50#left=20#HTTP/1.1
par_list[0] contains @request_buffer + 5
par_list[1] contains @request_buffer + 14
par_list[2] contains @request_buffer + 20
par_list[3-10] should be 0
If you also plan to have text-input containing spaces and special-characters there is some additional work needed, as you'd have to convert these from URL encoding to an ASCII string.
Now you can use each par_list-entry with all the available string functions. SD-card open for example also expects the filename as a string. There are string libraries which convert a character number into a long ...
You'll propably have different requests which don't send a page but different AJAX data. An easy solution would be to use a naming convention for this:
GET /ajax_nn?up=50&left=20 HTTP/1.1
nn being 00-99
So, you simply need to check whether par_list[0] points to an "ajax_" string and do a string to number conversion of par_list[0]+5.
Then you can have a case statement which returns the data according to the ajax request number.
The SD-code itself is easy. Just grab one of the SD card drivers, open the file with par_list[0] (if it is NOT an ajax-request), read the file into a buffer and send it. There needs to be some knowledge of how to do that if the file is bigger than the buffer. Reading in bunches is not a problem, but I don't know enough about propTCP. So I can't tell you how you can send TCP packages in junks. And I don't have a setup for testing.
The package attached shall contain demos using SD card and AJAX