[[Include(wiki:WARPnet1/version-note)]] [[TracNav(WARPnet1/TOC)]] = Building and Running WARPnet 1.0 Scripts = Here we will build and run a client script. To see a complete example refer to [wiki:../Example the example script]. == Building the Client Script == === Synchronizing Structs === There are two files that the user control over as the build their custom scripts to control the boards. The first is `warpnet_client_experiment_structs.py`. This file defines the data structures that are sent back and forth between the FPGA design and the client script. The FPGA design and this file must be in sync for data to be accurately transferred between the two. Let us look at an example to understand how this file is built. The following is the ControlStruct that is used to set basic node parameters. First we see the C struct that is stored in the FPGA. {{{ #!c #define STRUCTID_CONTROL 0x13 #define STRUCTID_CONTROL_ACK 0x14 typedef struct { char structID; char nodeID; char txPower; char channel; char modOrderHeader; char modOrderPayload; short reserved; int pktGen_period; int pktGen_length; } warpnetControl; typedef struct { char structID; char nodeID; short cmdID; } warpnetAck; }}} The next is the ControlStruct as seen in `warpnet_client_experiment_structs.py`. {{{ #!python STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_CONTROL self.expectedReturnStructID = STRUCTID_CONTROL_ACK self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 10 self.packetGeneratorLength = 1300 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BH2I', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, \ self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) }}} The `prepToSend` function creates the raw data that is seen by `warpnet.c` in the FPGA. It creates a byte packed data of 6 bytes (6B), 1 short (H) and 2 ints (2I). This is exactly what the node is expecting. A appropriate response from the node is a `warpnetACK` which `updateFromNode` parses in the python file. For a struct that is requesting data the raw data sent would be a `warpnetRequest` struct and expect a response of the appropriate type. === Logging Data === As statistics are received by the client, there is good chance that the data would want to be written to a file. There is a built in method to do this. In the top-level script create a `DataLogger` object like the following. {{{ #!python dataLog = DataLogger('filename.txt', fileRefreshTime) }}} The `fileRefreshTime` is the the interval after which Python will automatically write the file to disk and re-open it. This is very useful when running long tests as the data is constantly being stored even in the event of an error or power outage. To log data to the file pass a formatted string to the `DataLogger` instance. For example: {{{ #!python dataLog.log('Data=%d' % (valueToStore)) }}} == Running the Client Script == 1. Once the client script has been written, navigate to the folder where it is located. 1. Run the following: {{{ python experiment.py }}}