# DAL-CLI to IPC-CLI Migration

## Overriding itp and itpii

The ipccli will be somewhat backwards compatible with the itp. It is recommended that you change “import itp” to “import ipccli”, but this may not always be feasible. In order for the “ipccli” to takeover the itp module, you can run:

    ipccli.override_itpii()

And scripts importing the itp module will now get the ipccli instead.

Below is some assistance with some of the not-supported commands to show how to get the equivalent functionality in the IPC-CLI.

## Python Equivalent Commands

- itp.printf

- itp.sleep

- itp.pause

- itp.exit

## IPC-CLI Equivalent Commands

- itp.irscan / itp.drscan

- itp.threads[#].isvalid

- itp.threads[#].isenabled

- BitData not defined

- Event Subscription

- Logging

### itp.printf

This command provided C-style printf function in Python.

Replacement Use native python print statement. Example:

    >>> integer = 10
    >>> string = "Hello World"
    >>> print("%d %s %x" % (integer, string, integer))
    10 Hello world 0xa

Note that print will by default add a newline. If that is not desired, then you can either add a “,” after the print:

    >>> for i in range(10):
    ...   print(i, end="")  #  this syntax is for python3.x and greater
    ...
    0 1 2 3 4 5 6 7 8 9 10

Or use sys.stdout directly:

    >>> import sys
    >>> for i in range(10):
    ...    sys.stdout.write(i)
    ...
    012345678910

### itp.sleep

This command provided a timeout/pause for a specified number of seconds.

Replacement

use the time.sleep command that does the same thing:

    >>> import time
    >>> time.sleep(2)

### itp.pause

This command printed a message to the screen and waited for user input followed by an Enter key press (i.e. unlimited pause until user explicit action). The command returned the string typed by the user before Enter key press.

Replacement

Use native python raw_input command:

    >>> raw_input("Enter selection and press Enter:")
    >>> Enter selection and press Enter:

### itp.exit

This command exited the shell with a specified exit status.

Replacement

Use python sys module exit command:

    >>> import sys
    >>> sys.exit(status)

Note

this will exit the current interactive session if it is called from within a script that you are running on the command line.

### itp.irscan / itp.drscan

The IPC considers the jtag chain itself a device that you can address. So to get the equivalent of a rawirscan (that will not do serialization), you can target the chain using the device alias of the chain (but be sure to use a lock statement):

    >>> with ipc.device_lock():
    ...     ipc.irscan('JtagScanChain0,2,8)
    ...     print ipc.drscan('JtagScanChain0,32)
    ...
    [32b] 0x00A84013

### itp.threads[#].isenabled

The IPC CLI does not copy the device information to the node, but both the Intel(R) DFx Abstraction Layer and IPC CLI have the device object available in this case.

Replacement:

    >>> itp.threads[0].device.isenabled

### itp.threads[#].isvalid

The Intel(R) DFx Abstraction Layer had nodes that would sometimes not have an actual Intel(R) DFx Abstraction Layer object associated with them. The IPC-CLI does not have this, the nodes are all in the python layer. Therefore it does not have an isvalid. The equivalent code that would work in both Intel(R) DFx Abstraction Layer and IPC-CLI is:

    >>> getattr(itp.threads[0],"isvalid",True)
    True

### BitData not defined

The Intel(R) DFx Abstraction Layer itpii added BitData to the python builtin name space so it was immediately accessible. The IPC CLI does not add anything to the Python global name space. You can still get to the BitData via the itp (or ipc) object, as well as the itpii or ipccli modules. Either of these will work:

    >>> itp.BitData(32,0xa5)
    >>> itpii.BitData(32,0xa5)

### Event Subscription

The Intel(R) DFx Abstraction Layer event subscription subsystem had multiple functions. Each subscribe function allowed you to register a handler, which took a single argument. The OpenIPC + IPC CLI has similar capabilities but the functions for subscribing are slightly different:

> - itpii.subscribeToHardwareEvents => ipc.events.SubscribeTargetEvents

> - itpii.subscribeToReconfigEvents => ipc.events.SubscribeReconfigurationEvents

> - itpii.subscribeToRunControlEvents => ipc.events.SubscribeRunControlEvents

> - itpii.subscribeToBreakEvents => ipc.events.SubscribeRunControlEvents

>     - this is not 100% the same, but it is the closest equivalent

> - itpii.subscribeToErrorEvents => ipc.events.SubscribeMessageEvents

>     - this is not 100% the same, but it is the closest equivalent

The handlers passed in to support these events take two parameters instead of one now as well. For complete documentation on how IPC CLI event subscriptions work, see the full Events documentation.

### Logging

The IPC logging API is similar to the ITP one, but with some small changes.

> - itp.log == ipc.log

> - itp.nolog == ipc.nlog

> - itp.loggercho => ipc.logger.echo

> - itp.loggerlevel => ipc.logger.level