Welcome to the TI_Zigbee_Network_Properties_Cloning_Tool CLI (Command Line Interface)!

This CLI is a python file that performs zigbee coordinator cloning or can be used to read/write from a ZC/ZNP device. 
Python is neccessary for the use of this file, the CLI was created under Python version 3.7.

The CLI uses Python libraries PySerial and Questionary. These libraries must be installed before running the CLI.
The most common ways to install python libraries through terminal is by the following commands:
"pip install X" or "pip easy_install X", where X is the name of a python library. 

Refer to http://www.ti.com/lit/swra671 for details on how to clone a Zigbee ZNP/Coordinator device's network properties.
Note: Before this tool can be used, the ZNP/Coordinator must meet certain requirements, outlined in the setup portion of the Application Report linked above.
Before proceding make sure these requirements are met.  

To view the different configuration options for the device, run the CLI with the '-h' command included.
An example of the terminal command: "py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py -h"
The "py" portion of the command may vary depending on the python installation and version.

The 'config_nv_regions.txt' and 'read_content.txt' files are required to be in the same directory as the CLI unless otherwise specified with the -cf and -rf options
The "config_nv_regions.txt' is the file that contains all of the NV Regions that the tool will preload and use to read/write to and from the ZC/ZNP.
The "read_content.txt" is the file that will contain all of the data read from the ZC.
An example of changing the configuration file path:"py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py -cf X", where X is the path of the config file
An example of changing the read content file: "py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py -rf X", where X is the path of the read content file
The "py" portion of the command may vary depending on the python installation and version.

The amount of output print statements is configurable through the '-q'command. Essentailly running the CLI with this command will quiet the output and only print out
crucial status updates.
An example of the terminal command:"py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py -q"
The "py" portion of the command may vary depending on the python installation and version.

Forming the network upon doing a write or clone procedure is configurable through the '-nfn'command. 
The default setting is True for this flag, meaning anytime there is a write procedure the device will form a new network before content is written to it.
In order to change this to False and have the device not form a network before a write use the '-nfn' command. 
An example of the terminal command:"py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py -nfn"
The "py" portion of the command may vary depending on the python installation and version.
---------------------------------------------------------------------------------------------------------------------------

To get started using this tool:
Run the CLI in a terminal window using the terminal command: "py TI_Zigbee_Network_Properties_Cloning_Tool_CLI.py" assuming no other configuration options are desired. 
The "py" portion of the command may vary depending on the python installation and version.

There are three applications:
1) Reading from a ZC
2) Writing to a ZC
3) Cloning a ZC

When the CLI starts the user will be prompted to choose an application if there any devices connected to the PC that have MT/NPI capability. 
Please refer to http://www.ti.com/lit/swra671 for more details about the MT and NPI requirements. 

Reading:
Upon selecting the reading option by pressing the enter key the next step is to choose a device. Select a device by simply using the arrow keys to navigate through the options.
Once a port is chosen, the CLI shows all of the differnt nv region options. Select items to read by pressing the space bar then enter when finished.
The terminal window should update with success or failure print statements for each of the nv items specified unless the quiet command was ran.

Writing:
Writing to a device requires that the path to a file with content read be specified. This file must have a particular setup which is described in 
Appendix A of the application report found here: http://www.ti.com/lit/swra671 

Cloning:
There are two ways to use this tool to do cloning:
Method 1: Requires both old and new devices at the same time
Method 2: Requires only one device at a time or both

Refer to the text below for the procedure for both methods.

Method 1: Cloning
Old device (ZC1), new device (ZC2)
1) Connect the coordinator/ZNP device (ZC1) to the PC and note the port number.
2) Connect the new coordinator/ZNP device (ZC2) to the PC and note the port number. 
3) Run the TI Zigbee Network Cloning Tool CLI in a terminal window
4) Select the ‘Clone’ application option when prompted, and then the corresponding ports for the devices to be read and written to. 
   Content should be read from ZC1 and written to ZC2. 
5) Watch the output to make sure there are no errors. 
   To view the content that was read from ZC1, open the read file (read_content.txt) once the reading procedure is complete.
   There may not be content for all of the NV regions. This is dependent on the type of application used. 
7) Remove ZC1 from the NWK by powering it off.
8) When the process is complete, power cycle or restart ZC2. This is necessary for the ZC to update its NV content with the new content 
   that was written. Once the device restarts, it will take the place of ZC1. *


Method 2: Read/Write
Old device (ZC1), new device (ZC2)
1) Connect the coordinator/ZNP device (ZC1) to the PC and note the port number.
2) Run the TI Zigbee Network Cloning Tool CLI in a terminal window
3) Select the ‘Read’ application option within the tool, and then the corresponding port for the device to be read. 
4) Choose the 'All Regions'selection or the nv items to read when prompted by pressing the space bar then enter 
5) Watch for errors while reading. To view the content that was read from ZC1, open the read file (read_content.txt) once the reading procedure is complete. There may not be content for all of the NV regions. This is dependent on the type of application used. 
6) Whenever ready, connect ZC2 to the PC and note the port number.
7) Run the TI Zigbee Network Cloning Tool CLI in the terminal window again
8) Select the ‘Write’ application option within the tool, and then the corresponding port for the device to be written to. 
9) Type the path to the file content_read.txt file (or file saved from reading from ZC1). 
10)Watch the output to make sure there are no errors. To view the content that was written to ZC2 check the output 
   display for success or failure status. 
12)Remove ZC1 from the NWK by powering it off.
13) When the process is complete, power cycle or restart ZC2. This is necessary for the ZC to update its NV content with the new content 
   that was written. Once the device restarts, it will take the place of ZC1. *

* If ZC2 was programmed with an XDS110 emulator then the first time the device is reset after programming the reset must be physical. 
For a physical reset, power cycle the device or if using a Launchpad press the reset button. 