Commanding Record And Replay With Command Line Tools

To replay data, runtime nodes need to be told which logfile session to load. Sensor and hardware nodes subscribe to the `ps_rnr_msg` to receive commands to enter record or replay modes and know when to start reading or writing the data. PolySync provides both GUI and command line tools to command runtime nodes to record and replay data. This article shows how to use the supplied C API `rnr_control` example application to command nodes to replay an existing logfile session. ### 1. Clone the repo The `rnr_control` code is in the [PolySync C Examples](https://github.com/PolySync/PolySync-C-Examples) GitHub repo. ```bash $ git clone https://github.com/PolySync/PolySync-C-Examples ``` ### 2. Build the application The project uses Make to build, and places the binary in the `bin/` directory. ```bash $ cd PolySync-C-Examples/rnr_control $ make $ make install # copies to /usr/local/polysync/bin/ ``` The binary is built and is named `polysync-rnr-control-c`. ### 3. Record and replay sessions directory Each host has a defined record and replay (rnr) sessions directory defined in the SDF. The rnr directory is defined and viewed in the SDF configurator, and can also be printed by the license tool: ```bash $ polysync-license-tool ***************************** *** PolySync License Tool *** API Build Version: 2.0.8-1478129437 Host ID: '(Ethernet) XXXXXXXXXXXX' Installation Directory (PSYNC_HOME): '/usr/local/polysync' System Design File: '/usr/local/polysync/db/psync.sdf' Record and Replay Sessions Directory: '/usr/local/polysync/rnr_logs' IP Address: '127.0.0.1' License Server: 'not used' License file specified in SDF: 'not used' Current license status: valid ***************************** ``` The default directory is `/usr/local/polysync/rnr_logs`. The `polysync-rnr-control-c` application can only command runtime nodes to replay data contained in this directory. ### 4. Replay a PolySync logfile Now that the `polysync-rnr-control-c` application has been built, we can use it to command nodes to replay PolySync logfiles. #### 4.1 Starting runtime nodes Use the manager to start all runtime nodes defined in the system SDF in the replay context. ```bash $ polysync-manager -n -w ``` If the manager is already running, stop it and associated runtime nodes first with the `-q`. ```bash $ polysync-manager -q $ polysync-manager -n -w ``` Nodes are now in the standby state, waiting to be told which PolySync logfile to load. #### 4.2 Commanding replay The `polysync-rnr-control-c` application uses the `-t` flag to indicate which logfile session to replay. All other flags are optional while commanding runtime nodes to replay data. ```bash $ polysync-rnr-control-c -t 1000 ``` This command will replay the default logfile session that ships with PolySync. It's important to note that the `rnr_control` application has no knowledge of the nodes on the PolySync bus. It's simply packaging and publishing a `ps_rnr_msg` that active nodes subscribe and react to. For systems that have a couple dozen nodes, or limited compute resources, it's nice to provide a loading grace period. Pass in the `-s ` flag to specify a relative start time (microseconds), or the `-S ` flag to specify an absolute UTC microsecond start time. ```bash $ polysync-rnr-control-c -t 1000 -s 3000000 # 3 seconds ``` To stop replay at any time, use the applications `-q` flag. ```bash $ polysync-rnr-control-c -q ``` ### 5. Record a PolySync logfile #### 5.1 Starting runtime nodes Use the manager to start all runtime nodes defined in the system SDF in the hardware context. ```bash $ polysync-manager -n ``` If the manager is already running stop it, as well as associated runtime nodes, first with the `-q` flag. ```bash $ polysync-manager -q $ polysync-manager -n ``` Nodes are now in the standby state, waiting to be told which PolySync logfile to load. #### 5.2 Commanding replay The `polysync-rnr-control-c` application uses the `-t` flag to indicate which logfile session is being referenced, and the `-w` flag to indicate that we want to enable record mode. ```bash $ polysync-rnr-control-c -t 2001 -w ``` This command will tell nodes to begin recording data to the logfile session `polysync/rnr_logs/2001/`. It's important to note that the `rnr_control` application has no knowledge of the nodes on the PolySync bus. It's simply packaging and publishing a `ps_rnr_msg` that active nodes subscribe and react to. To command nodes to stop recording data, use the application's `-q` flag. ```bash $ polysync-rnr-control-c -q ```