TechNinjutsu‎ > ‎

Scripting with IronPython in cdmaDevTerm

posted Jan 3, 2013, 10:06 PM by d graham   [ updated Feb 27, 2013, 6:02 PM ]
The new version of cdmaDevTerm(2.85 as of writing) features the ability to use iron python and script against cdmaDevLib directly.  Using IronPython finally provides the power and expressiveness required to script cdma flashes for carriers like PagePlus, MetroPCS and others(which I had received a few emails about with the previous xml based scripting system). I'm no IronPython guru, and you don't have to be either to achieve most basic tasks with cdmaDevLib--but the power of IronPython really does mean the only limit is that of your imagination.

There are two scripts included with .2.85: an attempt at a Cricket flashing script(untested), and a script to show a few examples of how to use the scripting system that comes up by default.

Here's the cricket script:

# sample carrier(cricket) flashing
# cdmaDevTerm ironPython script
# copyright 2012 dg,
mdn = "0000000000"
min = "0000000000"
user = mdn + ""
password = "cricket"

cdmaTerm.Connect(phone.ComPortName)#selected port in cdmaDevTerm
#cdmaTerm.UnlockMotoEvdo() #uncomment for moto nvitem 8035

The cricket script shows a few basic ideas too, like how to declare a variable(ex mdn = "0000000000") and that a comment starts with the # character. You may also realize if you read the cdmaDevTerm source that cdmaTerm.thePhone has been aliased to phone and cdmaTerm.Q has been aliased to q because of frequent use in scripts.

#cdmaDevTerm sample ironPython script #2
#copyright 2013 DG,

#nv = CommandFactory.GetCommand(NvItems.NvItems.NV_SCM_I)
nv = CommandFactory.GetCommand(NvItems.NvItems.NV_MEID_I)
#clear the default system log data
phone.LogData = ""

#this bit seems to show either a badly named method, bug or both

This script shows how a command object is passed by ref and can be used to retrieve the result of the serial IO from the command(it is returned as a byte[] which has the extension method .ToHexString()).

It also seems to show a bug in the .2.85 release, though I need to track down just where that bytesRxdLessHdlc is actually being used.

These few examples came up in an issue discussion re: nv items on google code.
To write an nv item using the decimal value of the nv item, one can do something like this:

     cdmaTerm.WriteNv(906,"505050617373776F7264".ToHexBytes()) which is using cdmaTerm.WriteNv(ByVal nv As Integer, writeData() As Byte) also I think there is a helper method(GetNvWriteDataByteList) for the cdamDevTerm ui which allows the(slightly hacky) but equivalent:     cdmaTerm.WriteNv(906,"0x505050617373776F7264")