2

So I finally decided to bite the bullet and rewrite my company's terrible Trace32 scripts. I'm trying to use a data file to save the pertinent information between runs so we can just run a Redo script to repeat any action without having to navigate a mess of dialog boxes and select our workspace files after every power cycle. In order to do this, I will need to save the user defined variables from the previous run (including file locations) to file so I have them in the next run. For reference, here is a part of my menu script.

; File: Do.cmm
GLOBAL &WORKSPACE
GLOBAL &FILETOLOAD
GLOBAL &TARGETSELVAL

&WORKSPACE="//tsclient\Z\Product_trunk_MS" ; Not the ideal solution

PRINT "Workspace is &WORKSPACE"

DIALOG
(
    HEADER "Do one of the following"

    POS 0. 0. 23.
    COMMAND.PREVIOUS: CHOOSEBOX "Repeat Last Command" ""
    POS 24. 0. 23.
    COMMAND.WORKSPACE: CHOOSEBOX "Change Workspace Location" ""

    POS 0. 3. 25.
    TEXT "Connect To an R7 Proc:"
    POS 0. 4. 6.
    COMMAND.IP0: CHOOSEBOX "IP0" ""
    POS 8. 4. 7.
    COMMAND.IP1: CHOOSEBOX "IP1" ""

    ; And a lot more of the same...

    POS 17. 16. 15.
    DEFBUTTON "OK" "continue"
)
DIALOG.SET COMMAND.PREVIOUS
STOP

IF DIALOG.BOOLEAN(COMMAND.IP0)
(
 &TARGETSELVAL=0x00030000
 &FILETOLOAD="&WORKSPACE\CPUs\IP0\build\output\IP0.axf"
)
IF DIALOG.BOOLEAN(COMMAND.IP1)
(
 &TARGETSELVAL=0x0003001
 &FILETOLOAD=&WORKSPACE\CPUs\IP1\build\output\IP1.axf
)
... And so on

The problem with this is that I have to edit the script every time I change workspaces. I want to be able to set this in the script above by selecting COMMAND.PREVIOUS and then selecting my new workspace root with the Windows selection dialog. I don't have a working implementation for that function, but I want it to look something like this:

IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
    PRINT "Select the new root directory that you would like to work out of."
    OPEN  #1 workspace.dat /Create
    &WORKSPACE= C/*/ ; I don't know how to do this here.
    WRITE #1 &WORKSPACE
    CLOSE #1
    ENDDO
)

Obviously, Data.load.binary "*.bin" is able to load a file to memory, but I don't need the file loaded yet, I just want the path. I did find that symbol.SOURCEPATH.SETBASEDIR c:\* will open a dialog box, but I am still having trouble getting at that information.

Additional Info

I have read through a lot of this and this while trying to find a solution. If there is a built in path variable that I should be using (like the aforementioned SOURCEPATH.SETBASEDIR, I wouldn't mind doing that instead. This is my first day writing Trace32 scripts, so I apologize in advance for my naivete. If it matters, I am using Trace32 Powerview for ARM Release Feb 2017 SP2 (32 bit) (So, the latest)

MPStoering
  • 184
  • 2
  • 12

2 Answers2

3

TRACE32 has the concept of a working directory. The command ChDir can be used to change the current directory:

 ChDir <path>

The current working directory can be retrieved with the PRACTICE function OS.PWD():

 &WORKSPACE=OS.PWD()

The script example above could be extended like this:

IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
  PRIVATE &old_directory

  &old_directory=OS.PWD()         // Save current directory
  ChDir *                         // Open directory selection dialog

  &WORKSPACE=OS.PWD()             // Update working directory
  OPEN #1 workspace.dat /Create
  WRITE #1 &WORKSPACE
  CLOSE #1

  ChDir &old_directory            // Restore previous directory selection
)
xasc
  • 181
  • 5
1

I ended up finding a solution to my problem that was a little different than xasc's, so I thought I'd share it.

IF DIALOG.BOOLEAN(COMMAND.WORKSPACE)
(
    PRINT "Select the new root directory that you would like to work out of."
    DIALOG.DIR *
    ENTRY %LINE &WORKSPACE

    OPEN  #1 workspace.dat /Create
    WRITE #1 "&WORKSPACE"
    CLOSE #1
)

This was a little cleaner for my purposes because it didn't require me to change the working directory. DIALOG seems to be the interface I was looking for, with the ability to open files, directories, and more and save them into variables.

MPStoering
  • 184
  • 2
  • 12
  • 2
    Hint 1: Add command `WinPOS ,,,,,,,,"Select the new root directory..."` before your command `DIALOG.DIR *` and the text will show up inside the dialog to choose a directory. (Yes, you need all the commas in the command.) – Holger Aug 11 '17 at 22:21
  • 2
    Hint 2: I assume you want to have the file workspace.dat created in the same directory than your CMM script. But in your script it will be generated in the current working directory, which is not necessarily the same. Change the OPEN command to `OPEN #1 "~~~~/workspace.dat" /Create` and your file will be created in the directory of the active CMM script. (Another trick would be to use the user directory you can get with `&uad=VERSION.ENVironment(UAD)` followed by `OPEN #1 "&uad/workspace.dat"`) – Holger Aug 11 '17 at 22:25