Shop OBEX P1 Docs P2 Docs Learn Events
How do you compile individual bytes into a string so you can use STRCOMP? — Parallax Forums

How do you compile individual bytes into a string so you can use STRCOMP?

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2009-10-10 01:42 in Propeller 1
The title says it all. I have to compare bytes that are collected from keyboard presses and compile them into strings so that they can be compared to other words using STRCOMP. All help is appreciated.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.

Robots are microcontrolled.
I am microcontrolled.

But you·can·call me micro.

Want to·experiment with the SX or just put together a cool project?
SX Spinning light display·


Comments

  • JonnyMacJonnyMac Posts: 9,202
    edited 2009-10-07 15:40
    Declare an array larger than your longest target string (by at least one character; for the terminating zero). Fill the string with zeroes. Starting from position 0 add in your keyboard bytes and do the comparison between your array and the known string(s).
  • mctriviamctrivia Posts: 3,772
    edited 2009-10-07 15:41
    If you write the bytes to a space in memmory in order and then write a 0 after it you will have made into a string.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • mctriviamctrivia Posts: 3,772
    edited 2009-10-07 15:45
    There is no need to prefill the array as long as you write 0 after data

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-07 15:50
    One reason to "prefill" the string is that BYTEFILL is very fast. I haven't looked at a comparison of execution times, but BYTEFILL and just storing a zero byte at the end of a string of bytes are similar in execution time.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-10-07 16:01
    Thanks for the help! I have a buffer for up to 5000 keystokes to be kept so are you saying that if I terminate it with a zero then I have a string that can be compared?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·


  • he1957he1957 Posts: 58
    edited 2009-10-09 12:40
    micro,

    5000 keystrokes is a _lot_ to buffer but I guess you have a reason for having so many.

    A byte (8 bits) can hold a value between 0 and 255 (256). The ASCII "character set" [noparse][[/noparse]string] is defined as the "printable" characters represented as values between 32(10) and 127(10) - generally <SPACE> through the numeric values and the UPPER and lower case characters of the English alphabet; including typical symbols and sometimes 'graphic' characters. Values between 0 and 31, and beyond 127 but less than 256 are generally used as control or 'special graphic' characters and may or may not be "printable" - on any given [noparse][[/noparse]Human readable] display unit.

    Commonly, the NULL (0) value is defined as a 'terminator' for byte [noparse][[/noparse]string] sequences of consecutive register locations containing values between 32(10) and 127(10) - mostly because a "zero" character does not have a "visible" representation on a Human readable display. Humans determined what is displayable, a control character or perhaps a "special" graphic character. To a computer, a byte holds a value between 0 and 255 (unsigned). Zero; the "ASCII" number of 48 (10) is not to be confused with "NULL" 0 (0).

    Determinations such as this are "defined" in libraries, compilers or ROM as appropriate according to "standards".

    Routines like STRCOMP, strcmp(3) and similar can generally use any value between 1 and 255 (unsigned char) as a valid comparison value and _expect_ a NULL to be at some sensible count value between the beginning (zero) and end value of the "string" length. Most do not check length.

    It would be (sensibly) rare to see an end value exceed 255 + 1 (which includes a NULL byte); but a Programmer can do as they see fit if they are not using any "standard" and do not expect or desire any portability or cross-platform interoperability.
  • KyeKye Posts: 2,200
    edited 2009-10-09 12:46
    Use my string library. Its everything you need!

    I have a function that takes indiviual bytes and builds a string for you out of them. I also have triming functions an tokenization functions for word processing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-10-09 16:56
    Where is your string liberary? ----Searching OBEX Now...----

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·


  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-10-09 17:00
    Just found it! Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·


  • jazzedjazzed Posts: 11,803
    edited 2009-10-09 17:16
    Usually a programmer can ask the user to type a number of characters and "enter" for input. This way the input can come in more manageable slices ... less than 128 characters for example. There are many variations of readLine or getString, etc... for doing what you need that can be used with normal serial objects.

    Generally, relying on 5000 bytes of input to be correct without some kind of an integrity check is trouble. As an example, Internet Protocol packets have a maximum transfer unit size for segmentation/reassembly of large packets. Each resulting packet carries a 32 bit "CRC" for integrity checks. An mp3 file will be segmented into packets for transmission by the sender; the receiver will reassemble the packets into your mp3 file. The underlying TCP protocol will ensure that all good packets are delivered to the application. Your job for 5000 bytes on a serial stream is similar to this one way or another [noparse]:)[/noparse]
  • KyeKye Posts: 2,200
    edited 2009-10-10 01:42
    Oh, sorry. use this newer version. It is much better! (Forgot to attach it.)





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.