Shop OBEX P1 Docs P2 Docs Learn Events
code for hello + world — Parallax Forums

code for hello + world

topherslatertopherslater Posts: 3
edited 2010-08-05 23:18 in Propeller 1
I am working with the Ps2 controller object and i need both blocks of data PSX_Data1 and PSX_Data2. I need to join these 2 chunks of data together into one 32 bit binary chunk to send over xbee.
i am new to C, any advice world be greatly appreciated.

in short i need:


long Hello
long World

Pub | Block-0-Data
join "Hello" + "World" into "Block-O-Data"
return

Comments

  • w8anw8an Posts: 176
    edited 2010-08-05 03:27
    Completely untested, but perhaps what you are looking for:

    VAR
      byte  helloBuffer[noparse][[/noparse]20]
            
    PUB begin
    
      bytemove(@helloBuffer, string("Hello "), 7)          'Put "Hello " into helloBuffer (including the terminating \0 is 7 bytes)
      strAppend(@helloBuffer, string("World"))             'Append "World" to sring in the helloBuffer
                                                           'helloBuffer now contains "Hello World\0"
      repeat  'forever                                     'End of story
    
    PRI strAppend(strBuffer, strTail) | sizeBuff, sizeTail
       sizeBuff := strsize(strBuffer)
       sizeTail := strsize(strTail)
       bytemove(strBuffer+sizeBuff, strTail, sizeTail)
    
    
    



    Steve
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-05 03:29
    How do you want to join them? The "containers" Hello and World are both 32-bit and the result container Block-0-Data is also 32-bits. What parts of which values do you want to put into Block-0-Data and how do you want them arranged?
  • legoman132legoman132 Posts: 87
    edited 2010-08-05 14:00
    What ps2 controller data do you want to send?
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-05 15:07
    @w8an:

    In your example, willl not the final result be ""Hello \0World\0"?

    I'm still learning, so I might be wrong...

    JM
  • w8anw8an Posts: 176
    edited 2010-08-05 23:18
    The "W" in World should overwrite the "\0" at the end of "Hello ", but it looks like the command should be
    bytemove(strBuffer+sizeBuff, strTail, sizeTail+1)
    
    


    to get the termination character from "World\0"

    Of course my disclaimer protects me from any errors [noparse]:)[/noparse]
Sign In or Register to comment.