nc2moml and ncapp2moml

Introduction

This document compares nc2moml and ncapp2moml.

Both nc2moml and ncapp2moml convert nesC (.nc) files into MoML (.moml) files. MoML is a specialization of XML used by Ptolemy II. See any Ptolemy II demo .xml file for an example.

nc2moml converts .nc files that have interface(s) into an actor that can be used in Ptolemy II. If you look at it graphically, then the resulting file can be incorporated as an item in the left-hand pane in Vergil (the GUI of ptII) and dragged onto the workspace as a graphical block. (The result is basically a block).

ncapp2moml converts .nc files that do not have interface(s) into a complete Ptolemy II model. It assumes that the source .nc file is a complete TinyOS/nesC application. If you look at it graphically, then the resulting model may have multiple levels of hierarchy, but the bottom-most level of the hierarchy will be a workspace that has all the nesC blocks (the nesC blocks are created from nc2moml above) connected together with lines. (The result is basically a block and line diagram).

The reason why there are two different tools is that the resulting MoML code have very different structures, and the output required from the nesC compiler (it uses the xml output of the nesC compiler) is very different. nc2moml only inspects the interface information from the nesC xml output. ncapp2moml gets the wiring (+ more) information from the nesC xml output. You must pass completely different flags to the nesC compiler to get these different xml outputs.

If you are a Viptos user, then after installing Viptos, you can run nc2moml to convert the .nc files in the tinyos-1.x/tos, etc directories of your TinyOS tree into .xml (moml) files. Then, when you run Viptos, it automatically reads in these .xml (moml) files and will display them in the left hand pane so that you can use them to build block and arrow diagrams by dragging and dropping.

You can also run ncapp2moml to convert existing applications (in tinyos-1.x/apps) into .xml (moml) files. You can open these .xml (moml) files in Viptos, and you will see a block and arrow diagram that represents the original .nc application. You can also run the code generator built into Viptos on the .xml (moml) file/model to generate a .nc file that is equivalent to the original source .nc file.

So, the combination of nc2moml/ncapp2moml/Viptos allows you to convert both ways between .nc and .xml (moml) files. Here, I state (moml) in parentheses to differentiate it from the .xml (nc) file generated from the nesC compiler.

Notes for developers that plan to extend nc2moml or ncapp2moml for use outside of Ptolemy II

nc2moml is easy to use independently of ptII. It basically has no dependencies in the .java file. (Look in ptII/ptolemy/domains/util/nc2moml)

ncapp2moml depends quite a bit on ptII. The implementation basically calls methods in the ptII kernel in order to convert the entire nesC wiring graph into ptII graph (the result is an almost working ptII model). Then it traverse the ptII graph and generate xml code for each element in the xml hierarchy. It would not be difficult to convert the ptII-specific calls into custom calls, because ncapp2moml only uses very basic parts of the ptII kernel.

Neither nc2moml nor ncapp2moml require actually starting up ptII or Vergil (the GUI). In other words, it does not use the ptII runtime. It just depends on some of the methods in the Java classes in ptII.

If you are building a translation tool from .nc to some intermediate language, I recommend at least using the .xml output from the nesC compiler as one of your intermediary steps. I do not recommend using nesC code directly, since the syntax may change, but the routines that generate the nesC xml output will be kept up to date. nc2moml and ncapp2moml extend the these java files. See net.tinyos.nesc.dump.NDReader in the nesC distribution.