Shop OBEX P1 Docs P2 Docs Learn Events
Advice for PropTCP use — Parallax Forums

Advice for PropTCP use

grindelgrindel Posts: 68
edited 2012-11-26 02:49 in Propeller 1
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,

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2012-11-18 14:45
    Java is out in browser-based applications! Nowadays it should be possible to have sliders in HTML maybe with the help of a little bit JavaScript. But from my point of view this should be the prefered solution. Then your android or tablet would also be able to run the robot interface.
  • grindelgrindel Posts: 68
    edited 2012-11-22 04:05
    OK, I'm hanging in there, but I've a couple questions that are driving me up the wall. One is an issue on the HTML side. I've got the slider to display, but I don't think there is a way to work around hitting a separate submit button so the prop can see the change. Does anyone have advice on this?

    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
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-11-22 07:05
    I don't know which sliders you use, but it should also be possible to add a JavaScript handler which attaches to the onChange -event. This could then do an automatic submit, so each single change will be directly send to the server.

    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.
  • computer guycomputer guy Posts: 1,113
    edited 2012-11-22 20:26
    Is it possible to place the html files onto an SD card or something? I think the best way to do this would be to use jQuery, this will allow you to adjust the sliders and send the new values to the prop without having to submit the page. jQuery however will take up a lot of space as it is 32KB in size.
    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-11-23 01:13
    Of course it's possible!
    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
     0. initialize the par_list setting all to 0
     1. loop over all bytes in the request buffer
        2. if the character is "/" store position +1 in 1st array element -> in the end this will point to the page-name without rest of URL
        3. if "?" then replace with 0 -> this converts the page-name to a valid string
        4. if "=" then store position + 1 in next available array element -> this will then give you the address of a parameter (input field)
        5. if "&" or " " then replace with 0 -> this converts the current parameter to a valid string
    
    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-11-23 01:19
    Did you see this: http://forums.parallax.com/showthread.php?118193-PropTCP-Beta-Now-fully-MIT-Licensed-(w-AJAX-Enabled-HTTP-Server-Example!)
    The package attached shall contain demos using SD card and AJAX
  • grindelgrindel Posts: 68
    edited 2012-11-26 02:49
    Thanks for the help, sounds like everything is certainly do-able, I'll post results when I get it all figured out and cleaned up.
Sign In or Register to comment.