Shop OBEX P1 Docs P2 Docs Learn Events
Vmusic2 Messages — Parallax Forums

Vmusic2 Messages

BTXBTX Posts: 674
edited 2008-04-08 01:13 in Propeller 1
Hi all !

I'm still playing with a vmusic2 module to get a full and improved mp3 player, well, although I've posted a code for an mp3 player, I found too dificult to manage the vmusic messages.
I've tried looking at the Mike's "Prism project" but I can't really get good ideas from that code (seems to be more complicated for me).

My original code manage the vmusic messages in a repeat loop, waiting for a byte recieved through serial port, .......that works, but I can't add more messages in the display at any time, because the rx loop is waiting for the vmusic messages.... (I hope you understand me ...what I mean).

I'm trying to controll now the vmusic using the handshake signals....to see if it lets me to modify my code and take more control of the data recieved (or the eactly time of it)...but I can see, that the "RTS out" in the vmusic, never changes the logic state, and also I can't found info about this, in all the vmusic & firmaware documents....

I suppose that Mike is the most experience with this module, but if somebody more have more suggests or experiences, I will be thanks this.

The exactly question is: How to ??? manage the vmusic messages and How to ?? use correctly the handshake signals.

Thanks all in advance !!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.

Alberto.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-07 16:29
    Alberto,
    Yes, the Prism project routines are fairly complicated because they are designed for two VMusic2 modules operating simultaneously with a shared status display. Try stripping out all of the code for the parts you don't need. You need the modified FullDuplexSerial object and a simplified VMusic2 object. I didn't find a need for the handshake lines. The RTS line is only to stop the Propeller from sending to a busy VMusic2. The FullDuplexSerial routines are fast and buffered. I increased the buffer sizes to 64 bytes which takes care of the largest command and status response I expected.

    Look particularly at playTheFile and the routines it calls. You'll see that, after sending a command to the VMusic2, it receives all characters until a timeout occurs, then looks for a match at the end of the buffered text. Most responses end with a specific prompt sequence and that's what is looked for.
  • BTXBTX Posts: 674
    edited 2008-04-07 16:35
    Thanks so much again Mike !!!
    I will try all you commented .

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-07 17:08
    Alberto,
    I've stripped out most of the unneeded methods and modified a couple of them.
    I haven't tested it, but look through it. It should be much more understandable.

    I include the program here. It doesn't work to try to attach the file:
    ' VMusic2 Driver for Prism Project
    
    CON
       Cr       = $0D                       ' New line / Return
       Lf       = $0A                       ' Line feed
       Del      = $7F                       ' Delete
    
       cmdChDir = $02                       ' Change directory
       cmdOpen  = $0E                       ' Open file for reading
       cmdRead  = $04                       ' Read file
       cmdClose = $0A                       ' Close file
       cmdDir   = $01                       ' Directory listing
       cmdPlay  = $1D                       ' Play file
       cmdStop  = $20                       ' Stop plays
    
       maxLine  = 80                        ' Maximum line / pattern length
       maxTime  = 100                       ' Maximum time for VMusic2 response
    
    OBJ
       ser : "FullDuplexSerialMod"          ' Serial link to VMusic2
    
    VAR
       byte line[noparse][[/noparse]maxLine]                   ' Input line buffer (from VMusic2)
       byte lineLen                         ' Current length of input line buffer
    
    DAT
    echoUp    byte "E",Cr,0                 ' Upper case echo command / response
    echoLow   byte "e",Cr,0                 ' Lower case echo command / response
    chkStat   byte Cr,0                     ' Check drive status command
    longSCS   byte "SCS",Cr,0               ' Long form SCS command
    shortUp   byte cmdChDir," ..",Cr,0      ' Short form change directory upwards
    shortOK   byte ">",Cr,0                 ' Short form normal response
    shortND   byte "ND",Cr,0                ' Short form No Disk response
    shortCF   byte "CF",Cr,0                ' Short form Command Failure response
    stopMsg   byte "S>",Cr,0                ' Stop play message
    
    PUB start(TxD,RxD)
       ser.start(TxD,RxD,%0000,9600)        ' Start the serial port
       ser.str(string(cmdStop,Cr))          ' Try forcing a stop command
       repeat until cmdResp(@echoUp,@echoUp)
       ifnot cmdResp(@echoLow,@echoLow)     ' Send "E" until we get a response
          abort string("Missed 'e'")        '  then send "e" and check for echo
       ifnot cmdResp(@longSCS,@shortOK)     ' Put VMusic2 into short command mode
          abort string("SCS not OK")
       if cmdResp(@chkStat,@shortND)        ' See if a drive is present
          abort string("No Disk Present")
       ifnot endsWith(@shortOK)
          abort string("Status Not OK")
       repeat while cmdResp(@shortUp,@shortOK)
       ifnot endsWith(@shortCF)             ' Make sure current directory is root
          abort string("Can't CD Root")
    
    PUB stop
       ser.stop                             ' Stop the serial port
    
    PUB playMusic(theDirStr, theFileStr) | t
       if theDirStr                         ' Check for a directory change
          ifnot setDirectory(theDirStr)     ' Change to requested directory
             abort string("CD File Error")
       if (t := playTheFile(theFileStr)) <> true
          abort t
       if theDirStr                         ' Check for a directory change
          ifnot setDirectory(-1)            ' Change back to root directory
             abort string("CD Root Error")
    
    PRI clearLine                           ' Clear input line
       lineLen := 0
    
    PRI cmdResp(cmd,ans)
       clearLine
       ser.str(cmd)                         ' Transmit command
       repeat while bufferFill              ' Fill buffer
       return endsWith(ans)                 ' Return match to response
       
    PRI endsWith(str) | s
       if lineLen == maxLine                ' Is there room for a zero terminator?
          return false
       line[noparse][[/noparse]lineLen] := 0                   ' Put it in
       s := strsize(str)                    ' Get length of pattern
       if s > lineLen                       ' Make sure input is long enough
          return false
       return strcomp(str,@line+lineLen-s)  ' Return result of string compare
       
    PRI bufferFill | c                      ' Attempt to read a new input character
       if lineLen < maxLine                 ' Don't read a character if buffer full
          if (c := ser.rxtime(maxTime)) => 0
             line[noparse][[/noparse]lineLen++] := c           ' Save new character in buffer
             return true
    
    PRI endNumber(pos)                      ' Get 4 byte value relative to end of buffer
       repeat 4
          result := result << 8 | line[noparse][[/noparse]lineLen-(++pos)]
    
    PRI playTheFile(theFileStr) | timeout
       clearLine
       ser.str(string(cmdPlay," "))         ' Initiate playing of a track
       ser.str(theFileStr)
       repeat while bufferFill
       ifnot endsWith(theFileStr)           ' Response should end with track name
          return string("No Track Play Error")
       clearLine
       timeout := 0
       repeat while timeout++ < 20          ' Timeout if no response in 2 seconds
          repeat while bufferFill
          if endsWith(@stopMsg)             ' At end of track ... "S>"
             return true
          if endsWith(string(Cr))           ' Otherwise, it's two bytes with time
             timeout := 0                   ' Reset the timeout
       return string("Timeout Play Error")
    
    PRI setDirectory(theDirStr)
       clearLine
       ser.str(string(cmdChDir," "))        ' Change directory
       if subdirNo < 0
          ser.str(string("..",Cr))          ' Either go up one level
       else
          ser.str(theDirStr)                ' Or use a specific directory
       repeat while bufferFill
       return endsWith(@shortOK)            ' Make sure response is OK
    
    
  • BTXBTX Posts: 674
    edited 2008-04-08 01:13
    Thanks so much Mike !!!!!
    Your code was a big help for me, to understand more the vmusic !!
    I also discovered that the RTS line only activates when you send "Disk" commands... but not when vmusic ones are sent.
    Anyway I didn't use the handshaking.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
Sign In or Register to comment.