Shop OBEX P1 Docs P2 Docs Learn Events
Variable Length Strings, No Delimiter — Parallax Forums

Variable Length Strings, No Delimiter

T ChapT Chap Posts: 4,223
edited 2008-09-20 02:04 in Propeller 1
Is there some method already worked out for reading varying lengths of strings that don't have any termination?

Next, anyone know what the theoretical maximum string length is on the Propeller?

Thanks

Comments

  • SapiehaSapieha Posts: 2,964
    edited 2008-09-19 22:11
    Hi Originator.

    One metod of having varying lengths of strings is to have length pointers at the beginning of that strings.
    But I have not see that Obiect on Forum

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer
    If you don't ask you wont know
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible


    Sapieha
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-19 22:18
    How would the system know where the string ends?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • SapiehaSapieha Posts: 2,964
    edited 2008-09-19 22:21
    Hi Paul Baker.

    It is not simple metod.
    It must scan for string Line Number and length.
    In principle it is many old Basic computers have that system.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer
    If you don't ask you wont know
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible


    Sapieha

    Post Edited (Sapieha) : 9/19/2008 10:42:28 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-19 22:25
    Originator,

    To answer your second question, strings like those in Spin that use a terminator have no theoretical maximum length. The downside is that you can't use the terminator (in Spin's case, $00) as an element of the string. Also, you have to know ahead of time how long your longest strings will be, so you can allocate big enough arrays to hold them.

    For strings like Sapieha is talking about, the maximum length would depend on the size of the length indicator. One byte is common, in which case the maximum length would be 255 characters; for two bytes, 65535 characters; and so on.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 9/19/2008 10:30:36 PM GMT
  • SapiehaSapieha Posts: 2,964
    edited 2008-09-19 22:32
    Hi Phil Pilgrim..

    I have that system on My Control system that have Tiny Basic as its base.
    It was more efective in in speed that systems based on delimiters to scan for next Line of program code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer
    If you don't ask you wont know
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible


    Sapieha
  • T ChapT Chap Posts: 4,223
    edited 2008-09-19 22:38
    I am testing this concept that seems like a good idea:

    crude concept:


    Pub Read
    array[noparse][[/noparse] 0] := ser.rx 'wait until string starts
    array[noparse][[/noparse] 1] := ser.rxtime(1) ' if there is a byte, read it, if not, waits 1ms then next line (returns)
    array[noparse][[/noparse] 2] := ser.rxtime(1) ' waits 1ms
    ....
    array[noparse][[/noparse] 1000] := ser.rxtime(1) ' waits 1ms

    When it gets to the end, done, return and do other stuff


    Thanks for that info Phil, I do have an occasional payload string of 934 bytes to manage, so trying to look for ways to get it, and send it somewhere else. All responses from a certain device are different lengths with no delimeter. Using time seems to be a solution, just return if it waits too long for a byte.

    Post Edited (Originator) : 9/19/2008 11:13:39 PM GMT
  • SapiehaSapieha Posts: 2,964
    edited 2008-09-19 22:53
    Hi Originator..

    In system I scribe on it is not necessary that strings must have given positions in file/minnen type arays.
    It is not necessary Line numbers from (1-X). It can have Line numbers type (1, 5, 3, 10 etc... ).
    You only scan for Line number and if it is not what you want ad pointer length for Line and test for next Line number etc...



    Ps. Line length pointer is Line number + line length pointer·+ Chars

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer
    If you don't ask you wont know
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible


    Sapieha
  • T ChapT Chap Posts: 4,223
    edited 2008-09-20 02:04
    This reads any number of bytes in a string up to 1024, using rxtime.



    PRI Read   |  i, val 
    
         'array 1
         ResponseArray1[noparse][[/noparse]0] := ser.rx(0)  'wait here for first byte
         i := 1
         Repeat 254                      'look for more, else return      
           Val :=  ser.rxtime(0,2)       'read more, port 0, wait 2 ms if no byte  
           If val == -1                       '-1 means it waited over 2ms and bailed
             Return
           ResponseArray1[noparse][[/noparse] i] := Val     
           i := i + 1
           
         'Go to Array 2 if needed
         i := 0  
         Repeat 255                      'look for more, else return      
           Val :=  ser.rxtime(0,2)       'read more, port 0, wait 2 ms if no byte
           If val == -1
             Return
           ResponseArray2[noparse][[/noparse] i] := Val     
           i := i + 1
           
         'Go to Array 3 if needed 
         i := 0  
         Repeat 255                      'look for more, else return      
           Val :=  ser.rxtime(0,2)       'read more, port 0, wait 2 ms if no byte 
           If val == -1
             Return
           ResponseArray3[noparse][[/noparse] i] := Val     
           i := i + 1 
    
      
    
         'Go to Array 4 if needed 
         i := 0   
         Repeat 255                      'look for more, else return      
           Val :=  ser.rxtime(0,2)       'read more, port 0, wait 2 ms if no byte 
           If val == -1
             Return
           ResponseArray4[noparse][[/noparse] i] := Val     
           i := i + 1 
    
    
     
    
    

    Post Edited (Originator) : 9/20/2008 3:28:18 AM GMT
Sign In or Register to comment.