ptolemy.domains.ptinyos.util.ncapp2moml
Class NCApp2MoML

java.lang.Object
  extended by ptolemy.domains.ptinyos.util.ncapp2moml.NCApp2MoML

public class NCApp2MoML
extends java.lang.Object

Generate a .moml file for each .nc application file in the input list. Usage:

 java -classpath $PTII ptolemy.domains.ptinyos.util.ncapp2moml.NCApp2MoML \
 <.nc source prefix> \
 <.nc xml input prefix> \
 <.nc xml input suffix> \
 <opts input suffix> \
 <moml output prefix> \
 <long path to file containing list of .nc files using short path> \
 path to MicaBoard.xml if you want the generated file to include the Wireless domain wrapper
 
Example:
 java -classpath $PTII ptolemy.domains.ptinyos.util.ncapp2moml.NCApp2MoML \
 /home/celaine/ptII/vendors/ptinyos/tinyos-1.x \
 /home/celaine/ptII/vendors/ptinyos/momlapp \
 .ncxml \
 .opts \
 /home/celaine/ptII/vendors/ptinyos/momlapp \
 /home/celaine/ptII/vendors/ptinyos/momlapp/.ncapp2moml-tempfile
 
.tempfile contains:
 apps/CntToLeds/CntToLeds.nc
 
Example output for CntToLeds.nc:
 <?xml version="1.0"?>
 <!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd">

 <entity name="CntToLeds" class="ptolemy.domains.ptinyos.kernel.NCCompositeActor">
 <property name="PtinyOSDirector" class="ptolemy.domains.ptinyos.kernel.PtinyOSDirector" />
 <entity name="Counter" class="tos.lib.Counters.Counter" />
 <entity name="IntToLeds" class="tos.lib.Counters.IntToLeds" />
 <entity name="TimerC" class="tos.system.TimerC" />
 <entity name="Main" class="tos.system.Main" />
 <relation name="relation1" class="ptolemy.actor.IORelation" />
 <relation name="relation2" class="ptolemy.actor.IORelation" />
 <relation name="relation3" class="ptolemy.actor.IORelation" />
 <link port="Counter.IntOutput" relation="relation3" />
 <link port="Counter.Timer" relation="relation2" />
 <link port="IntToLeds.StdControl" relation="relation1" />
 <link port="TimerC.Timer" relation="relation2" />
 <link port="Counter.StdControl" relation="relation1" />
 <link port="TimerC.StdControl" relation="relation1" />
 <link port="IntToLeds.IntOutput" relation="relation3" />
 <link port="Main.StdControl" relation="relation1" />
 </entity>
 
Expects <xml input prefix> to contain files with <xml input suffix> containing an xml dump with the following parameters:
 -fnesc-dump=components(wiring, file(filename.nc)
 -fnesc-dump=referenced(interfaces)
 
Example call to ncc:
 ncc '-fnesc-dump=components(wiring, file(/home/celaine/tinyos/tinyos/tinyos-1.x-scratch/apps/CntToLeds/CntToLeds.nc))' '-fnesc-dump=referenced(interfaces)' -fnesc-dumpfile=/home/celaine/ptII/vendors/moml/apps/CntToLeds/CntToLeds.ncxml /home/celaine/tinyos/tinyos/tinyos-1.x-scratch/apps/CntToLeds/CntToLeds.nc -I/home/celaine/tinyos/tinyos/tinyos-1.x-scratch/tos/lib/Counters/
 

Since:
Ptolemy II 5.1
Version:
$Id: NCApp2MoML.java 47513 2007-12-07 06:32:21Z cxh $
Author:
Elaine Cheong
Accepted Rating:
Red (celaine)
Proposed Rating:
Red (celaine)

Nested Class Summary
private static class NCApp2MoML._ComponentFile
          Class to store the file location of the specified component.
private static class NCApp2MoML._Link
          Class to represent link between ports and relations.
private static class NCApp2MoML._Relations
          Class to create new relation names.
 
Field Summary
private  java.util.Hashtable _componentActorTable
          Contains (key, value) pairs of type (Xcomponent, AtomicActor).
private  java.util.Hashtable _componentFileTable
          Contains (key, value) pairs of type (Xcomponent, _ComponentFile).
private  CompositeActor _compositeActor
          CompositeActor to hold each AtomicActor that represents a nesC component.
private static java.lang.String _FILESEPARATOR
          File separator to use, currently "/".
private  java.util.Hashtable _interfaceIOPortTable
          Contains (key, value) pairs of type (Xinterface, IOPort).
private  java.util.Hashtable _interfaceRelationTable
          Contains (key, value) pairs of type (Xinterface, List(Relation)) if single port, or (Xinterface, Relation) if multi-port.
private static java.lang.String _INWIRELESS
          Name to add to items that use the Wireless wrapper.
private  java.util.ArrayList _linkList
          Contains list of Links (links between ports/relations).
private static java.lang.String _ncSourcePrefix
          File prefix for .nc source files.
private  NCApp2MoML._Relations _relations
          Class to create new relation names.
 
Constructor Summary
NCApp2MoML()
           
 
Method Summary
protected  void createConnection(net.tinyos.nesc.dump.xml.Xinterface interfaceFrom, net.tinyos.nesc.dump.xml.Xinterface interfaceTo)
          Create all the relations and links needed to form the connection between interfaceFrom and interfaceTo.
protected  void createInterfaceIOPort(net.tinyos.nesc.dump.xml.Xinterface intf)
          Create an IOPort that represents this interface.
 void generatePtinyOSModel(java.lang.String componentName, java.lang.String outputFile, java.lang.String directorOutputDir, java.lang.String opts, java.lang.String micaboardFile)
          Generate the .moml file for this nesC application.
static void main(java.lang.String[] args)
          Read in .nc application xml files, generate .moml files.
protected  void readLinks()
          Traverse the configuration wiring graph and set up the component and relation data structures.
static java.lang.String readOptsFile(java.lang.String optsInputFile)
          Read in the opts file.
protected  void saveInterfaceContainer(net.tinyos.nesc.dump.xml.Xinterface intf)
          Store the container of the interface (a component) and path to source file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_FILESEPARATOR

private static java.lang.String _FILESEPARATOR
File separator to use, currently "/".


_INWIRELESS

private static java.lang.String _INWIRELESS
Name to add to items that use the Wireless wrapper.


_ncSourcePrefix

private static java.lang.String _ncSourcePrefix
File prefix for .nc source files.


_componentFileTable

private java.util.Hashtable _componentFileTable
Contains (key, value) pairs of type (Xcomponent, _ComponentFile).


_componentActorTable

private java.util.Hashtable _componentActorTable
Contains (key, value) pairs of type (Xcomponent, AtomicActor).


_compositeActor

private CompositeActor _compositeActor
CompositeActor to hold each AtomicActor that represents a nesC component.


_linkList

private java.util.ArrayList _linkList
Contains list of Links (links between ports/relations).


_interfaceRelationTable

private java.util.Hashtable _interfaceRelationTable
Contains (key, value) pairs of type (Xinterface, List(Relation)) if single port, or (Xinterface, Relation) if multi-port.


_interfaceIOPortTable

private java.util.Hashtable _interfaceIOPortTable
Contains (key, value) pairs of type (Xinterface, IOPort).


_relations

private NCApp2MoML._Relations _relations
Class to create new relation names.

Constructor Detail

NCApp2MoML

public NCApp2MoML()
Method Detail

generatePtinyOSModel

public void generatePtinyOSModel(java.lang.String componentName,
                                 java.lang.String outputFile,
                                 java.lang.String directorOutputDir,
                                 java.lang.String opts,
                                 java.lang.String micaboardFile)
                          throws IllegalActionException,
                                 NameDuplicationException
Generate the .moml file for this nesC application.

Parameters:
componentName - The name of the component (no suffix).
outputFile - The file to generate.
directorOutputDir - The output directory to pass to the PtinyOSDirector.
opts - The compiler options (PFLAGS) to pass to the PtinyOSDirector.
micaboardFile - Path to the MoML file that contains the Wireless wrapper. Null if wrapper should not be generated.
Throws:
IllegalActionException - If there is a problem creating an interface IOport or connection.
NameDuplicationException - If there is a problem creating an interface IOport or connection.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Read in .nc application xml files, generate .moml files.

Parameters:
args - A series of command line arguments, see the class comment for details.
Throws:
java.io.IOException - If there is a problem reading or writing a file.

readOptsFile

public static java.lang.String readOptsFile(java.lang.String optsInputFile)
Read in the opts file.

Parameters:
optsInputFile - The file to read.
Returns:
The opts string, or empty string if there is none.

createConnection

protected void createConnection(net.tinyos.nesc.dump.xml.Xinterface interfaceFrom,
                                net.tinyos.nesc.dump.xml.Xinterface interfaceTo)
                         throws IllegalActionException,
                                NameDuplicationException
Create all the relations and links needed to form the connection between interfaceFrom and interfaceTo.

Parameters:
interfaceFrom - The source interface of the connection.
interfaceTo - The destination interface of the connection.
Throws:
IllegalActionException - If thrown while creating a relation or linking to a port.
NameDuplicationException - If thrown while creating a relation or linking to a port.

createInterfaceIOPort

protected void createInterfaceIOPort(net.tinyos.nesc.dump.xml.Xinterface intf)
                              throws IllegalActionException,
                                     NameDuplicationException
Create an IOPort that represents this interface.

Parameters:
intf - interface that represents IOPort to be created.
Throws:
IllegalActionException - If there is a problem creating the port.
NameDuplicationException - If there is a problem creating the port.

readLinks

protected void readLinks()
                  throws IllegalActionException,
                         NameDuplicationException
Traverse the configuration wiring graph and set up the component and relation data structures.

Throws:
IllegalActionException - If there is a problem creating an interface IOport or connection.
NameDuplicationException - If there is a problem creating an interface IOport or connection.

saveInterfaceContainer

protected void saveInterfaceContainer(net.tinyos.nesc.dump.xml.Xinterface intf)
                               throws IllegalActionException,
                                      NameDuplicationException
Store the container of the interface (a component) and path to source file.

Parameters:
intf - interface of the component to be stored
Throws:
IllegalActionException - If there is a problem creating the atomic actor.
NameDuplicationException - If there is a problem creating the atomic actor.