Overview & Code Organization

The

SmartMesh C Library

 abstracts the serial API of SmartMesh devices into a set of functions your application can call.

  • To issue to a command to a device over its serial API, your application calls the corresponding function. The

    SmartMesh C Library

     handles formatting serial frames and HDLC framing, as well as matching commands and responses.
  • Notifications received from the device result in a callback function being called. The

    SmartMesh C Library

     handles parsing the serial notification frames and sending a serial API acknowledgement to the device when necessary.
The 

SmartMesh C Library

 is designed with the following constraints in mind:
  • It is written in pure C. In particular, no hardware-specific code is present in the 

    SmartMesh C Library

    , allowing it to be used as-is in any C-based platforms. To use the 

    SmartMesh C Library

     on your platform, you have to implement a handful of functions (see Porting).
  • It is not tied to any operating system. The 

    SmartMesh C Library

     only deals with formatting and parsing serial frames. It can be used as-is in single threaded environments (see for example the Arduino Example Applications section). If you are operating in a multi-threaded environment (e.g. you are using a Real-Time Operating System), you can use locking functions (see the Porting section).

Source Code Organization

The

SmartMesh C Library

 can be downloaded at https://github.com/dustcloud/sm_clib.

Directory Structure

That repository contains the following directories:

  • the sm_clib/ directory contains the library itself, as a collection of headers (.h) and source code files (.c):
    • main modules:
      • dn_ipmg.c implements the SmartMesh IP Manager serial API.
      • dn_ipmt.c implements the SmartMesh IP Mote serial API.
      • dn_whmt.c implements the SmartMesh WirelessHART Mote serial API.
    • helper modules:
      • dn_serial_mg.c implements low-level serial formatting for communicating with the SmartMesh IP Manager.
      • dn_serial_mt.c implements low-level serial formatting for communicating with the SmartMesh IP Mote and SmartMesh WirelessHART mote.
      • dn_hdlc.c implements HDLC framing over a serial connection, following RFC1662.
    • header files for porting:
      • dn_endianness.h contains the prototypes of the functions you need to implement to support different endianness.
      • dn_lock.h contains the prototypes of the functions you need to implement to support a multi-threaded environment.
      • dn_uart.h contains the prototypes of the functions you need to allow the

        SmartMesh C Library

         to communicate over your (micro-)processor's serial port.

        For more information about porting, see the Porting section.

  • the examples/ directory contains sample applications which use the

    SmartMesh C Library

    . These examples are built for the Arduino Due.
    • The arduino/Libraries/ directory contains the libraries used by the sample applications.
    • The arduino/MoteBlink/ directory contains the MoteBlink sample application.
    • The arduino/Triangle2manager/ directory contains the Triangle2manager sample application.

      For more information about the Arduino sample applications, see the Arduino Example Applications section.

What about the SmartMesh WirelessHART manager?

Interacting with the SmartMesh WirelessHART manager is best done through its XML-RPC interface. The

SmartMesh C Library

targets serial API interfaces, and hence does not support the SmartMesh WirelessHART manager.