Shop OBEX P1 Docs P2 Docs Learn Events
One of those 'passing strings' questions... — Parallax Forums

One of those 'passing strings' questions...

HughHugh Posts: 362
edited 2014-05-26 11:07 in Propeller 1
Sorry, another silly question...

I am trying to select a number of characters from a string (to be sent via simple_debug). The code is below but instead of extracting ten characters as intended I only receive four - do commas have an impact on the way strings are handled?
PUB BTSendGPSorFF (a, b, c, prefix) | indexC , scratch

' ~Scratchpad2~ is a global long, size "[50]"
bytemove(@scratchpad2, string("$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230313,003.1,W*6A"), 50)


' Fill ~scratch~ with zeroes - anything we move to it subsequently will be zero-terminated, allowing us to treat it as a string    
bytefill(@scratch, 0, 50)                                                                              


'Move ten bytes of ~scratchpad2~ into ~scratch~
bytemove(@scratch, @scratchpad2 + 20, 10)


' Send the prefix (string) passed in the call to this PUB.
      debug.str(prefix)


' Send ~scratch~ as a string. Because we filled ~scratch~ with zeroes it will be zero-terminated                                                                                 '
      debug.str(@scratch)


' Send a CR      
      debug.tx(13)

I thought I'd finally got my head around strings and things but apparently not.

Any help would be really appreciated.

Thanks
Hugh

Comments

  • T ChapT Chap Posts: 4,223
    edited 2014-05-26 05:58
    Sorry I misread and removed my reply. Not enough info to help.
  • Mike GMike G Posts: 2,702
    edited 2014-05-26 05:58
    The local pointer variable, scratch, is not initialized,

    There's not enough code posted to determine what "prefix" is doing or pointing to. Please post all your code!
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-05-26 06:06
    Your local variable, scratch, is a long (4 bytes) and you start by attempting to fill it with 50 zeroes -- this is overwriting your the first part code (remember, everything runs from RAM).

    You need a second byte array in the global space.
  • HughHugh Posts: 362
    edited 2014-05-26 06:50
    JonnyMac wrote: »
    Your local variable, scratch, is a long (4 bytes) and you start by attempting to fill it with 50 zeroes -- this is overwriting your the first part code (remember, everything runs from RAM).

    You need a second byte array in the global space.

    Thank you Jonny - that fixed it. :thumb:
  • HughHugh Posts: 362
    edited 2014-05-26 06:51
    Mike G wrote: »
    Please post all your code!

    With comments the top files is currently 1,356 lines so I thought better of posting all of it. :smile:
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-05-26 06:57
    You can always archive and post as an attachment when having others see your full source is useful.

    My name is Jon.
  • HughHugh Posts: 362
    edited 2014-05-26 07:27
    JonnyMac wrote: »
    My name is Jon.

    Sorry. I went by your user name rather than that in your sig.
  • Mike GMike G Posts: 2,702
    edited 2014-05-26 09:51
    Hugh wrote: »
    With comments the top files is currently 1,356 lines so I thought better of posting all of it. :smile:
    It's practically impossible to provide a solution without all the source code. Often the problem lies elsewhere in the code base which is the situation here. My response assumed the code base contained a global buffer but the local pointer "scratch" was not initialized to the buffer address. I was wrong...a global buffer did not exist at all.

    I've been trying very hard to provide more gentle responses to posts. When requesting "All the code" and receiving a response of "It's too big" is actually insulting and shows a disregard for the folks trying to help.

    Please realize, I had to fill in the logic gaps by make assumptions about the code base and your programming ability which I know nothing about. Given an incomplete view of the logic I had to come up with a guess and a thoughtful response. Please keep this in mind for future posts.
  • HughHugh Posts: 362
    edited 2014-05-26 11:07
    Crikey, that's two people I've annoyed in one thread - apologies all. Can we start again?!

    I thought that the comments in the code would be sufficient but my over-familiarity with the code meant that in trying to include only that immediately relevant I omitted some information with which anyone coming to it cold would not be familiar. Sorry

    As will be apparent from the attached code, my 'programming ability' is 'not a lot'; I am possibly being over-ambitious with what is the third generation of the same idea.

    Hugh

    FFGPS202 - New board, tacho - Archive [Date 2014.05.26 Time 18.58].zip
Sign In or Register to comment.