Streamlining Data Flow: Core Software Functionality Complete!

June 05, 2024 — Written by Haris Turkmanovic


Share this article

Streamlining Data Flow: Core Software Functionality Complete!

We have previously announced the PCB design is completed and boards are sent to manufacturing. Fabricated PCB boards have arrived! However, while we're all set to begin assembly, some key components are still coming. While we await the arrival of some essential elements, we've shifted our focus to completing the data streaming functionalities. Completing this core software functionality is a major milestone, bringing us closer to achieving all the project's core functionalities. Once the remaining components are received, we can proceed with the final assembly and testing.

This post dives into the details of how the voltage and current streaming feature works. We'll begin by focusing on the firmware implementation, followed by a detailed look at the GUI application development. We'll also point you to the relevant code in our GitHub repository for easy reference. To conclude, we'll showcase a short video presentation demonstrating the developed streaming functionalities.

Firmware implementation details

Figure 1 illustrates all firmware software blocks that are parts of streaming functionalities.
StreamingFIrmwarePartFigure 1 - Streaming feature's related software blocks

Presented blocks are:

  • Analog IN
    In charge of acquiring voltage and current samples and storing them in corresponding buffers
    Relevant directory:
    - Firmware/ADFirmware/CM7/Core/Drivers/Platform/AnalogIN

  • Ethernet Interface and Network service
    Software IP stack.  Initially developed and described in this post

    Relevant directory:
    - Firmware/ADFirmware/CM7/Core/Drivers/Platform/LwIP
    - Firmware/ADFirmware/CM7/Core/Middlewares/Services/Network

  • Samples Stream Service
    In charge of receiving sample data packets from lower software layers, processing them, and forwarding them to the host side
    Relevant directory:
    - Firmware/ADFirmware/CM7/Core/Middlewares/Services/SamplesStream

  • Control Service
    In charge of parsing control commands. Initially developed and described in this post.
    Relevant directory:
    - Firmware/ADFirmware/CM7/Core/Middlewares/Services/SamplesStream

Firmware side of data streaming logic – main working principles

After MCU firmware is successfully run and the ethernet link is established, the host initiates the data streaming process by transmitting a control message. This message, as defined within the Commands Description file, contains the server’s IP address where obtained samples should be sent. This established streaming channel facilitates the continuous transmission of data from the MCU to the server for real-time processing or further analysis. For clarity, the "create stream" command format with some IP address information is provided below:

device stream create -ip= -port=5000

Upon receiving the control message, the Control Service parses it and forwards the "Create Stream" action to the Samples Stream Service. This service, based on the message content, creates a stream for sending data to the server at, port 5000.

The main service task, implemented within the prvSSTREAM_ControlTaskFunc function, handles the "Create Stream" command. Each established stream triggers the creation of a separate FreeRTOS task. This task efficiently gathers samples from underlying software layers, performs any necessary processing, and transmits the data to the previously defined server IP. When a stream is created, a Unique stream ID (SID) value is assigned to each stream, and it is used by stream-related commands to reference specific streams. This architecture facilitates the establishment of multiple concurrent streams, enabling the system to handle diverse data types and target various servers simultaneously. However, for testing purposes, this software version creates a single stream specifically for acquiring and transmitting voltage and current samples.

Following stream creation, the host can send commands for configuring parameters like sampling rate and resolution. The current software version supports the configuration of the following stream parameters:

  • Sampling rate

  • ADC resolution

  • ADC averaging ratio

  • Offset value

  • Sampling time

The Commands Description file provides a comprehensive list of commands used to configure specific parameter values.

After the data stream is established and configured, the host may trigger data transmission by sending a "Start Stream" command. Upon receiving this command, the Stream Service leverages the Stream ID (SID) value to identify the relevant stream. The designated stream then begins continuous sample acquisition and transmits the data to the pre-configured server. This ongoing data transmission process can be dynamically controlled by the host through specific pause or stop commands.

Continuous voltage and current sample acquisition is implemented within the Analog IN driver’s software block whose main components are illustrated in Figure 2. This software block utilizes different peripherals to continuously, with minimal software assistance, acquire and store multiple voltage and current samples into a single packet of data. For such actions, the Timer and DMA peripherals – both connected with ADC. Timer peripheral is configured to periodically, with a period defined by the host side with corresponding control command, trigger sample conversion. Voltage and current sampling are performed sequentially after the request to start conversion. Each end of the sampling process triggers DMA to store voltage current samples to the specific part inside MCU memory. When the buffer is filled with several samples defined with   DRV_AIN_ADC_BUFFER_MAX_SIZE macro, an interrupt is generated. Inside ISR is called the previously registered callback function from the Samples Stream service which is forwarded buffer address value. 

Analog IN componentsFigure 2 - Analog In software block's components

When current and voltage samples are stored inside a corresponding buffer, the corresponding stream task is triggered for further processing. This processing logic implemented inside this task includes two steps:

  1. Incrementing the Message ID (MID) sequentially

  2. Appending a Message Type (MTI)

The sequential MID allows the host system to detect potential packet loss during transmission because unreliable, very fast, UDP protocol is used for packet transmission. The MTI serves to identify the specific data type contained within the packet. While the current version handles only one data type, this design offers flexibility for future implementations that may include different data streaming types. Data samples, together with MID and MTI, create a Stream message packet which is forwarded to the network service where it is encapsulated inside the corresponding ethernet packet and sent to the host side.  Stream message packet creation over different software services is illustrated in Figure 3.

Stream PacketsFigure 3 - Stream message flow between firmware service

From Figure 2, it is obvious that two buffers, located in subsequent memory spaces, are used. This is done to achieve simultaneous data processing and transmission. In other words, while DMA fills the second buffer, the first buffer is processed and transmitted, and vice versa. To achieve this, DMA is configured in circular double buffer mode.

GUI implementation details

Figure 4 illustrates all GUI software blocks that are parts of streaming functionalities.

Streaming GUI ParrFigure 4 - Streaming feature's related GUI software blocks

  • Stream Link
    Receive Stream Message packet and extract MID and MTI
    Relevant directories:
    - GUI/OpenEPT/Links

  • Control Link
    Receive and send control messages. Here is a detailed description.
    Relevant directories:
    - GUI/OpenEPT/Links

  • Stream Message Processing
    Receive preprocessed Stream Packet Message and perform additional processing
    Relevant directories:
    - GUI/OpenEPT/Processing

  • Control Message Processing
    In charge of parsing control commands. Initially developed and described here
    Relevant directories:
    - GUI/OpenEPT/Processing

  • File parser

    Receive voltage, current, and consumption data samples and write them to the corresponding files
    Relevant directories:
    - GUI/OpenEPT/Windows/Device

  • GUI task

    Integrate all graphic components
    Relevant directories:
    - GUI/OpenEPT/Windows/Device

    GUI side of data streaming logic – main working principles

Once you launch the GUI application and successfully establish a connection with your data acquisition device, a "Device" window will appear. Here's how to configure data reception: 

  1. Select the Network Interface: Under the "Samples Stream Server Interface" dropdown menu, you'll see a list of all available Ethernet interfaces on your computer. Choose the interface where you want to receive the data streamed from your device.

  2. Prepare for Data Stream: Upon selecting the desired interface, the application automatically creates a "Stream Message Processing (SMP)" service with a corresponding "Stream Link (SL)" channel. This channel is ready to receive incoming data.

For optimal performance, the SMP service and SL channel operate on separate threads. They communicate with each other using a queued signal-slot connection mechanism, ensuring efficient data transfer. The device window is illustrated in Figure 5.

InterfaceFigure 5 - Device window

Following the selection of the network interface and the creation of the SMP service and SL channel, an initial handshake occurs between the host application and the data acquisition device. This handshake retrieves the default configuration settings from the device. Consequently, after configuration is obtained, the user can configure the following parameters:

  • Sampling period

  • ADC Resolution

  • ADC Sample time

  • ADC Clock div

The Device window lets you fine-tune the data acquisition process. Here's how it works:

  1. Basic Settings: Each parameter has a corresponding field where you can enter a value. Once you've adjusted a parameter, the software automatically generates control messages and sends them to your acquisition device, updating its configuration in real time.

  2. Advanced Options:  For more in-depth control, you can access the Advanced Options window. Here, you'll find additional parameters to configure. However, after making changes in this window, you'll need to click the "Configure" button to send the updated settings to your device. The advanced configuration window is illustrated in Figure 6.

Advance WindowFigure 6 - Advanced configuration window

Once the device configuration is complete, you can initiate data streaming by clicking the "Play" button within the Device window. Upon receiving this command, the acquisition device begins transmitting data samples encapsulated within Streaming Message Packets. These packets are firstly received inside the Stream Link thread where MID and MTI are extracted and together with data samples forwarded to a Stream Message Processing thread. Inside this thread are performed following actions:

  • The thread accumulates incoming data samples until a predefined maximum number of buffers (set within the GUI application) is reached. This buffering ensures smooth data processing.

  • After receiving each data sample packet, the thread calculates relevant statistics such as drop rate and number of successfully received packets.

  • Voltage and current samples are extracted from the packets and then scaled to appropriate ranges for accurate calculations

  • Finally, the thread calculates the device's power consumption based on the processed data.

Once the "Stream Message Processing" thread accumulates the maximum number of data buffers (as defined in the GUI application), it assembles everything into a single, larger data packet. This packet includes the processed data samples, along with relevant statistical information. The entire data packet is then forwarded to the main user interface (UI) task where:

  1. The data samples are used to update the corresponding real-time (RT) plots within the GUI, allowing you to visualize the incoming data stream

  2. The statistical information is presented within the acquisition status bar, providing you with a summary of the data acquisition process.

Figure 7 illustrates the data flow within the GUI application

aaFigure 7 - Stream message flow between GUI threads

With the "Log to file" option enabled and a valid file path configured, data samples displayed in the real-time plot will be written to a corresponding log file.  For each session will be created two files:

  • File for voltage and current samples

  • File for calculated consumption

Overall streaming feature demonstration

Our latest video, available on our brand-new YouTube channel, showcases the functionality of our implemented features. Since the full PCB is still under development, a signal generator was used to simulate voltage and current inputs on the STM32H755ZIQ development board. During the demonstration, the video highlights how the GUI application responds to changes in voltage and current frequency, amplitude, and offset.


Overall streaming feature demonstration

While we finalize the applications, we highly encourage you to explore the project by cloning the developed solution and testing it on your system. This allows you to familiarize yourself with the core functionalities and potentially identify areas for improvement.

Detailed instructions on how to clone and run the solution are provided here.

We encourage your active participation, through code contributions, testing, feedback, or simply spreading the word. Your support, in any form, is invaluable.

© 2023 Open Energy Profiler Toolset. All Rights Reserved. made by