Skip to content

Helpers (and docs) to create system needed files from VSCP class documentation


Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit


Repository files navigation

This is the original class and type specification for VSCP. Documents and source files are generated from this info. The 'scripts' folder holds scripts to generate different output.

The current autogenerated files can be found here

The folder classes holds class definitions as xml files with the following structure

<class id="0"
    name="VSCP Protocol Functionality"
    alternative-token="other token"

<type id="12"
    name="Enter boot loader mode."
    token="" />


<events> used when this class have the same events as anohter class n.

<alternative-token> used to set an alternative token. hoilds class description in Markdown format holds description for types of this class.

Links to other classes should have this format


Render templates

A structure

    <vscpworks template="......." />

holds one or more mustache named templates used to display information about an events dynamic data content. The first template defined is vscpworks. This template is used to display HTML based info about an event. The event is used as argument when the mustache expression is parsed. Meaning all parts of the event can be used. So for example {{vscpData[0]}} is data byte 0, vscpClass is the class, vscpGuid is the GUID and so on. A typical example is this visualization for CLASS1.MEASUREMENT

<vscpworks template="&lt;b&gt;Unit: &lt;/b&gt; = {{unitstr}} [{{unit}}]&lt;br&gt; &lt;b&gt;Sensorindex: &lt;/b&gt; = {{sensorindex}}&lt;br&gt; &lt;b&gt;Value: &lt;/b&gt; = {{val}}{{symbol-utf8}}&lt;br&gt;"


The measurement class (10) has a <unit> token that is used to describe units. Attributes are

  • name Name for the unit.
  • description Description of the unit.
  • symbol-ascii Symbol in ASCII format
  • symbol-utf8 Symbol in UTF8 format
  • conversion Conversion code to convert a value of the specific unit to a value of unit 0. Javascript mustache format is used as pseudo code for the conversion and value is specified as {{val}} in this code. mathjs is used to parse the expression after mustache parser is run. Set to {{val}} if a conversion is not possible.

This is how this looks for the temperature measurement type

<type id="6" name="Temperature" token="VSCP_TYPE_MEASUREMENT_TEMPERATURE" >
            <unit id="0" 
                    description="Degrees Kelvin"
            <unit id="1" 
                    description="Degrees Celsius"
                    conversion="{{val}} + 273.15 "/>
            <unit id="2" 
                    description="Degrees Fahrenheit"
                    conversion="({{val}} + 459.67) * 5/9"/>

Note that unit can be in the interval 0-255 as class=10 is used to describe also Level II measurement classes. For Level I classes only unit 0-3 is valid of course.


  • classes - VSCP class and type definitions.
  • scripts - Python scripts that generate output
  • cheaders - templates for c-headers.
  • python - Templates for Python.
  • javascript - Templates for JavaScript.
  • db - Templates for VSCP database.
  • json -- Templates for JSON file.


Make the vscp_class.h header file.

Usage >path/vscp_class.h

Make vscp_type.h header file.

Usage >path/vscp_ctype.h

Make the header file.

Usage >path/

Make header file.

Usage >path/

Make m_hashclass definitions for vscphelper.cpp.

Usage >path/vscp_ctype.h

Make m_hashtype definitions for vscphelper.cpp.

Usage path/vscp_hash_type.h

Generate sql for creation of sqlite db.

Usage path/dbfile.sql

Generate sql for creation of mysql db.

Usage path/dbfile.sql

Make JSON/JSONP data. Use arg "jsonp" for JSONP.

Usage >path/events.json
or jsonp >path/events.jsonp

Make XML data.

Usage >path/events.xml

Make sidebar content for specification document.

Usage >path/

Generate documentation for specification document.

Usage -v -o <output-folder> -h
-h/--help    - This text.
-v/--verbose - Print output also to screen.
-o/--outdir  - Folder to write output files to.
               defaults to current folder.

Make class constants for the Javascript library.

Usage >path/output

Make type constants for the Javascript library.

Usage >path/output

Make class constants module for node.js.

Usage >path/output

Make type constants module for the node.js.

Usage >path/output

Convert XML file to JSON

Usage ../classes/../classes/class_10_measurement.xml >outfile.json
  • -v - Verbose
  • -h - Help

In Python one can now use statements like the following to access information

# - Class token
print( o['class']['@token'])

# - All types
print( o['class']['type'])

# - Name for Type=6
print( o['class']['type'][6]

# - Unit =  Degrees celsius
print( o['class']['type'][6]['units']['unit'][1])  

# - # UTF8 symbol for degrees celsius
print( o['class']['type'][6]

# - Conversion formula to unit = 0
print( o['class']['type'][6]['units']['unit'][1]['@conversion'])

for conversions a mustache template is used where {{val}} is the floating point value.


This is an internal bash script that is used on our internal development system to generate files for different projects and site.

Usage <ftp-server> <user> <password>


It is possible to specify how user level software should render the data part of an event. It is possible to define many renderings but one is always available for VSCP Works. A typical event definition looks like this

<type  id="51"
    name="Request new security token"
                opt: function() { return e.vscpData[0]; },
                zone: function() { return e.vscpData[1]; },
                subzone: function() { return e.vscpData[2]; },
                {{lbl-start}}Opt : {{lbl-end}} {{val-start}}{{opt}}{{val-end}}{{newline}}               
                {{lbl-start}}Zone : {{lbl-end}} {{val-start}}{{zone}}{{val-end}}{{newline}}
                {{lbl-start}}Subzone : {{lbl-end}} {{val-start}}{{subzone}}{{val-end}}{{newline}}

The rendering for VSCP Works is defined here. Each rendering definition consist of two parts.

The first part is a variable substitution and define part that have access to the current event as the object e and therefore all it's data. As a variable also can be defined as a function you can assign values using functions which do calculations on the dynamic data that is provided by the environnement. A function here has access to standard Javascript functionality and the node-vscp package functionality or similar.

The second part is the actual rendering on mustache format. A defined variable should be written as {{variablename}} and will be substituted with the variable as of above.

There are some special substitution's available

variables and templates can have there definition strings prefixed with "BASE64:" to signal that they are encoded in BASE64. That is the example above will look like

<type  id="51"
    name="Request new security token"

Base64 coded data may be simpler to handle and get things working for all codings (JSON, XML, SQL etc).

Expression Will be replaced with
{{lbl-start}} Start of label (set to bold/color...)
{{lbl-end}} End of label (Restet bold/color...)
{{val-start}} Start of value (set to bold/color...)
{{val-end}} End of value (Restet bold/color...)
{{newline}} New line
{{ident}} Default ident (what is default is defined by application)
{{unit}} Unit as numerical (if defined)
{{unitstr}} Unit name
{{unit_description}} Unit description
{{unit_comment}} Unit comment
{{unit_ascii}} Unit in ASCII. Use if the environment cant handel Unicode.
{{unit_utf8}} Unit in UTF8. Use in Unicode aware environments.

This is another example of variable definitions

   crc8:             : function() { return e.vscpData[0]; }
   time_epoch        : function() { return e.vscpData[1]&lt;&lt;24 +
   				         e.vscpData[2]&lt;&lt;16 +
   				         e.vscpData[3]&lt;&lt;8 +
   				         e.vscpData[4]] }

and another

                    opt: function() { return e.vscpData[0]; },
                    zone: function() { return e.vscpData[1]; },
                    subzone: function() { return e.vscpData[2]; },
                    password: function() {
                        var rval = &quot;&quot;;
                        for ( i=3;i&lt;e.vscpData.length;i++) {
                            rval += String.fromCharCode(e.vscpData[i]);
                        return rval;

Note that some characters has to be coded as they are reserved in XML. For completeness they are listed here

Character Encode as
< &lt;
> &gt;
& &amp;
" &quot;
' &apos;

Technically variables are evaluated using the math.js package. The (mustache.js)[] package is then used to obtain render information.


Helpers (and docs) to create system needed files from VSCP class documentation








No releases published

Sponsor this project