Bluetooth Development Insights: Challenges and Solutions

Bluetooth Development Insights: Challenges and Solutions

Recently, I have been using Chipsea’s Bluetooth chip to develop a small project. The functionality is quite simple, similar to a lost item tracker, but in this project, the host is also a Bluetooth chip instead of a smartphone. This necessitates learning more about protocol stacks.

However, the most frustrating part is not learning the Bluetooth protocol itself, as this is a standardized protocol stack published by SIG that all Bluetooth devices should comply with.
The real headache is that each manufacturer of Bluetooth chips has its own implementation of the SIG BLE protocol stack source code, which really shows that all roads lead to Rome.
Bluetooth Development Insights: Challenges and Solutions
To use a hardware analogy, it’s like SIG released a schematic, and each manufacturer drew their own circuit board based on that schematic. Learning Bluetooth development is akin to deciphering a messy PCB Gerber file; each one is different.
I first got involved with Bluetooth using Nordic, and I pestered the FAE for a month to get familiar with their code. Later, I even restructured their DFU to fit my company’s OTA protocol.
Then, when developing with Tailing Micro, it was a whole new set of things. Not only was the entire source code framework different, but even the IDE was changed, making it feel like going from modern civilization to primitive farming. Since then, whenever someone recommends a Bluetooth solution, I first ask if it can be developed on MDK; it’s better to stick with tools I am comfortable with; I am no longer in the age of experimenting with various tools.
Another point is that these Bluetooth protocol stacks need to run on a small operating system. Strictly speaking, this is just a slightly complex scheduling system, which is also a non-standard thing. Therefore, the interface at the system layer varies among manufacturers. For example, the Bluetooth from Panqi Micro is based on an open-source Zephyr system. When I first received the manufacturer’s SDK, I didn’t know where to start; finding the first function was a challenge. This is why many people prefer using MDK, even if companies use pirated versions, they are reluctant to use those various open-source solutions; simplicity means lower overall costs.
Bluetooth Development Insights: Challenges and Solutions
Angry Micro’s Bluetooth is somewhat similar to Nordic’s, but Jerry’s development tools require a bit more effort. Now, with Chipsea’s Bluetooth, I am unsure which company’s protocol stack it references. Although there are many log messages, it took me a week to finally understand the flow from startup to broadcasting, and then from initiating a connection to sending data to the slave. It was truly a maze; sometimes I was processing OSAL messages, and other times handling messages for a specific application, all taken from a queue of messages at the lower level. Different places had the same events, and then processed again in the callback functions, which was really dizzying.
Therefore, for Bluetooth, choosing two or three platforms is enough to keep one busy.
Last year, when I was promoting a solution, my sales colleagues could bring in two Bluetooth orders every three days, and I couldn’t keep up with learning. The key is that learning these unique protocol stacks with no overlap is meaningless; I am more interested in how to write the applications.
Looking back, GD’s decision to design the register addresses to be identical to ST’s was indeed visionary, as it played a decisive role in promotion. However, in the Bluetooth industry, there is no single dominant player; even Nordic, TI, Cypress, and NXP can only be considered to share the market equally.
Returning to application development, the protocol stack has truly made my head spin, leaving me with little motivation to write applications.
Just now, the RSSI data had a problem. It was supposed to be around -30dBm, but suddenly it jumped to -90. I must add a filter. After thinking it over, I chose a sliding window filter to discard the maximum and minimum values within the window.
I had written it before, but I really didn’t want to dig it up (I must create an algorithm library that I can easily drag into projects). Just when I was anxious, I thought of GPT. I am still not used to having such a genius around.
I asked GPT for advice:
Bluetooth Development Insights: Challenges and Solutions
Bluetooth Development Insights: Challenges and Solutions
#include <stdio.h>
#include <limits.h>

#define WINDOW_SIZE 10

int window[WINDOW_SIZE];
int num_elements = 0;

void update_window(int new_value) {
    if (num_elements < WINDOW_SIZE) {
        window[num_elements++] = new_value;
    } else {
        // Window is full, slide the window and discard the oldest value
        for (int i = 1; i < WINDOW_SIZE; i++) {
            window[i-1] = window[i];
        }
        window[WINDOW_SIZE-1] = new_value;
    }
}

double compute_filtered_output() {
    if (num_elements == 0) return 0.0; // No data

    int max = INT_MIN;
    int min = INT_MAX;
    int sum = 0;
  
    for (int i = 0; i < num_elements; i++) {
        if (window[i] > max) max = window[i];
        if (window[i] < min) min = window[i];
        sum += window[i];
    }
  
    // Subtract max and min, then calculate average
    sum -= (max + min);
    return (double)sum / (num_elements - 2);
}

int main() {
    // Simulate input data
    int data[] = {5, 10, 8, 12, 20, 1, 30, 25, 15, 50, 45, 20, 25, 10, 5};
    int n = sizeof(data) / sizeof(data[0]);

    for (int i = 0; i < n; i++) {
        update_window(data[i]);
        if (num_elements > 2) {
            printf("Filtered output: %.2f\n", compute_filtered_output());
        }
    }

    return 0;
}
It even kindly provided an explanation:
Bluetooth Development Insights: Challenges and Solutions
How thoughtful!
Recommended Articles
  • Russia Achieves “Washing Machine Chip” Freedom, First 0.35μm Lithography Machine Emerges

  • Dissecting the Hot 38 Yuan McDonald’s Intercom, Circuit Cost Surprisingly Low…

  • Intel’s Most Failed Processor! The Aborted First Generation 10nm Suddenly Emerges

  • 74 Series Digital Chip Models and Chinese Names Collection, Valuable Resource!

  • Intercom, What High Technology Does It Have? Dissecting a Learning Model

Bluetooth Development Insights: Challenges and Solutions

Bluetooth Development Insights: Challenges and Solutions

Leave a Comment