Overview
The WNC M18Qx Module, running Embedded Linux, provides access to the hardware either through the Hardware Library, the Modem Abstraction Layer (MAL)--both of which are provided by the WNC SDK--and by using the Azure SDK (which provides the Application Programming Interfaces (APIs) to interact with Azure). The overall organization for the application is:
The Azure SDK is well defined and documented by Microsoft so I skip over it.
Overall Program Flow
In the following sections, I review each of the major areas of the application to give you a sense of the organization and function.
Main
The main function is located in the azIoTClient.cpp file and it is of course, where it all starts. I create several objects prior to program execution--the WNC GPS, LIS2DW12, ADC, LED, BAROMETER, HTS221 (for humidity), and BUTTON (to capture user key-press) object. The reason these are created with a global scope is so that they are accessible throughout the application.
Several functions are also defined:
- button_press - A function is called when a user depresses the USR button. All it does is set the LED to WHITE to indicate the button is pressed.
- button_release - The function is called to restore the LED color back to its original color prior to being depressed and check to see if the button was pressed for >3 seconds signaling program termination.
- make_message - This function creates the message that is sent to Azure.
Once main begins, it creates DEVINFO (WNC Device Info), the WWAN (controlls WWAN LED), and an NTPClient object. These are created within main because they are only are used within the scope of the main function.
Threads Used
Several of the objects create threads that run concurrently.
Thread | File Location | Description |
---|---|---|
Button | button.* | This thread runs when a button gpio interrupt occurs. It is called on both depress and release and calculates the time between press and release so it is known how long the button was pressed. |
GPS | gps.* | Because the GPS function in the WNC device can take a long time to complete, this task is set to run once per second. |
LED | led.hpp | Runs at an interval set by a caller. The default is 500ms (1/2 second) unless someone has set a different interval. |
LIS2DW12 | lis2dw12.* | Handles the motion sensor. It runs when an interrupt is generated by the LIS2DW12 and reads the position of the SOM. |
WWAN | wwan.hpp | Runs every 2 seconds and monitors the status of the LTE connection so the WWAN LED can be illuminated as appropriate. |
Hardware Interfaces
The hardware interfaces are provided as a link-library that is provided with the WNC SDK. These functions are detailed in the Avnet M18Qx Perpherial IoT Guide.docx that is included as part of the SDK.
Interrupts
This application implements the interrupt service routines (ISR) as private functions in various classes, but for the functions to have access to the class data, a pointer to the class must be provided. This is similar to how threads are handled in standard pthread programming. To handle this in the ISRs, a function address to object address association was needed so I created a set of C++ functions (fos.*) to handle this. It simply creates a linked-list of object address-with-function address table that can be called at the beginning of the ISR so class functions can be utilized seamlessly.
Binary I/O's
Binary I/O's are used for interrupt inputs as well as LED control. The I/Os that are used as interrupts are located in the Binary IO class and the LIS2DW12 class. Simple I/O control is utilized in the LED class.
I2C Interface
There is a single I2C Bus which is connected to the LIS2DW12 and Click Modules (hts221 & barometer). All I2C devices utilize the I2C_interface controls access to the I2C bus.
I realize this is a pretty brief overview, but once you know where functionality is located (which files) and a general description of what is happening, hopefully the code itself is pretty easily understood.