Shop OBEX P1 Docs P2 Docs Learn Events
MultiCogSerialDebug object — Parallax Forums

MultiCogSerialDebug object

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2007-12-20 22:59 in Propeller 1
I wrote a MultiCogSerialDebug object, derived from SerialMirror, that uses
my Format object to print formatted messages.
There is only one print function, cprintf, that does the formatting and printing.
It acts as printf with one argument, but takes an additional boolean parameter, more, that allows
to print compound messages. While more == true, other COGs are prohibited from printing.
The attached picture shows the debug output for the test program.

regards peter

Post Edited (Peter Verkaik) : 12/17/2007 6:20:53 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-17 19:02
    Thanks, Peter. This will be handy.
  • mirrormirror Posts: 322
    edited 2007-12-17 22:21
    Hi Peter,

    I had a look. Do you realise there'll be an instance of printbuf for every reference to this object. I don't think it will cause any problems as is, but you could think about moving printbuf to the DAT section for the same reason that all the other variables are in the DAT section.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Harrison.Harrison. Posts: 484
    edited 2007-12-17 22:30
    You can also take a shortcut when defining 'arrays' in the DAT sections.

    The normal (messy) way:
    DAT
    myvar byte 0,0,0,0
    
    



    The Propeller Tool way:
    CON
       LENGTH = 4
    
    DAT
    myvar byte 0[noparse][[/noparse]LENGTH]
    
    



    I made extensive use of this feature in my PropTCP stuff. I didn't know this was possible until I stumbled onto a post where someone posted some example code that utilized this ingenious feature.

    Harrison
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-17 23:03
    Harrison,
    Thanks for that pointer. It was in VAR because previous there was no lock.
    Now that cprintf is the only print function and there is a lock, it can be moved
    to DAT.
    I also realized that the lock in method rxcheck is not required as there should
    be only one cog that must handle incoming messages.
    I have put a new version in the object exchange. And attached it here also.

    regards peter
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-12-18 03:04
    Where does the 'Debug Terminal #1' window come from?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-12-18 03:15
    BASIC Stamp IDE (Maybe it's in the Javalin Stamp's IDE as well, Im not sure)

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

    Parallax, Inc.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-12-18 04:16
    Well. Well. My mental map of the prop neighborhood has suffered a drastic reversal -- it's us that are on the wrong side of the tracks.
  • simonlsimonl Posts: 866
    edited 2007-12-18 10:41
    Hi Paul,

    Any news on when the IDE will include the debug window?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-12-19 02:37
    No specific timeframe I'm afraid, but it is #2 on the to-do llist and #1 is nearing completion.

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

    Parallax, Inc.
  • simonlsimonl Posts: 866
    edited 2007-12-19 10:11
    Hey, thanks Paul.

    You've got me curious now - what's #1 !?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-19 15:19
    Here is a little problem.
    My main code is

    · buf[noparse][[/noparse]0] := $41
    · buf[noparse][[/noparse]1] := $42
    · buf[noparse][[/noparse]2] := 0
    · debug.cprintf(string("1st char is %c\r"),buf[noparse][[/noparse]0],false)
    · debug.cprintf(string("2nd char is %c\r"),buf[noparse][[/noparse]1],false)
    · debug.cprintf(string("total string is %s\r"),@buf,false)
    · debug.cprintf(string("1st char is %c\r"),$41,false)
    · debug.cprintf(string("2nd char is %c\r"),$42,false)

    The first 2 cprintf calls do not print the characters A and B
    and the 3rd cprintf call does not print the string AB.
    The last 2 cprintf calls do print the characters A and B.

    The first 2 should have done also, as buf[noparse][[/noparse]0] == $41 and buf[noparse][[/noparse]1] == $42

    What is going on here?
    The picture shows the debug output.

    regards peter

    Post Edited (Peter Verkaik) : 12/19/2007 3:24:18 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-19 17:53
    This really is a serious problem.
    The attached test program has main code

    · 'send welcome message
    · debug.str(string("MultiCogSerialDebug_test3 program"))
    · debug.tx(13)
    · buf[noparse][[/noparse]0] := $41
    · if buf[noparse][[/noparse]0] == $41
    ··· debug.str(string("1st character loaded correctly"))
    ··· debug.tx(13)
    · debug.str(string("Program finished"))
    · debug.tx(13)
    · repeat

    It uses SerialMirror to display output.
    The above outputs
    MultiCogSerialDebug_test3 program
    Program finished

    Apparently buf[noparse][[/noparse]0] does not get $41 assigned.
    However, disabling the first debug call,
    the output becomes
    1st character loaded correctly
    Program finished

    Could this be a compiler bug?

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-12-19 18:24
    Problem solved.
    Increasing the atnStack to 5 longs made the error disappear.

    regards peter
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-12-19 19:37
    simonl said...
    Hey, thanks Paul.

    You've got me curious now - what's #1 !?

    COM port management

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

    Parallax, Inc.
  • mirrormirror Posts: 322
    edited 2007-12-20 22:59
    Of course the object could also have been written as:
    OBJ
      fmt: "Format"
      sm: "SerialMirror"
        
    DAT
      lockCOG     byte  255
      semID       byte  0
     
    VAR
      byte printfbuf[noparse][[/noparse]64] 
     
    PUB start(rxpin, txpin, mode, baudrate, semaphore) : okay
      okay := sm.start(rxpin, txpin, mode, baudrate)
      semID := semaphore
      
    PUB cprintf(format,arg,more)
      if lockCOG <> cogid
        repeat until not lockset(semID)
        fmt.sprintf(@printfbuf,string("[noparse][[/noparse]COG%1d]:"),cogid)
        sm.str(@printfbuf)
      lockCOG := cogid
      fmt.sprintf(@printfbuf,format,arg)
      sm.str(@printfbuf)
      if !more
        lockCOG := 255
        lockclr(semID)
     
    
Sign In or Register to comment.