BLE-Scanner icon indicating copy to clipboard operation
BLE-Scanner copied to clipboard

ble-manufacturer-list.h missing - create from with bash

Open NOYB4Europe opened this issue 2 years ago • 2 comments

It took me some time to get the file /BLE-Scanner_ESP32/BLE-Scanner/ble-manufacturer-list.h right.

I had to remove \ and " from strings and keep the right format.

This is ble-manufacturer-list.h that works for me:

/*
	updated with ./update-manufacturer-list_yaml.sh
*/


#ifndef BLE_MANUFACTURER_LIST_H
#define BLE_MANUFACTURER_LIST_H
{ 0x0CCF , " Shenzhen CESI Information Techn" },
{ 0x0CCE , " SENOSPACE LLC" },
  ....
  { 0x0000 , " Ericsson AB" },
};
#endif // BLE_MANUFACTURER_LIST_H

I used this bash file :


#!/bin/bash

# Input YAML file and temporary file name
INPUT_FILE="company_identifiers.yaml"
TMP_FILE="tmp_formatted_data.txt"
OUTPUT_FILE="../../BLE-Scanner/ble-manufacturer-list.h"
URL="https://bitbucket.org/bluetooth-SIG/public/src/main/company_identifiers/company_identifiers.yaml"
# was : "https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/CompanyIdentfiers - CSV.csv"

#wget $URL

cat <<EOM
As the offical file with all assigned manufacurer IDs is prevented
to be automatically downloaded, this has to be done manually. So,
please download the yaml file from

 $URL

and store the yaml as

 $INPUT_FILE

Hit return when done, otherwise cancel with <Ctrl-C>
EOM
read

# Process YAML file and generate temporary formatted content
cat > "$TMP_FILE" <<EOM
/*
	updated with $0
	
	$(date)
*/
EOM

# Add include guards to the temporary file
echo "#ifndef BLE_MANUFACTURER_LIST_H" >> "$TMP_FILE"
echo "#define BLE_MANUFACTURER_LIST_H" >> "$TMP_FILE"
#echo "const char* company_identifiers[] = {" >> "$TMP_FILE"

# Process the YAML file using awk with proper escaping of double quotes
while IFS=":," read -r key value _; do
   if [[ "$key" =~ value ]]; then
       hex=$(echo "$value" | tr -d ' ')
       printf "{      %s , " "$hex" >> "$TMP_FILE"
   elif [[ "$key" =~ name ]]; then
       name=$(echo "$value" | tr -d "\"'#\\/,()" | head -c 32)
       if [[ -z "$name" ]]; then
           name="missing_name"
       fi
       printf "\"%s\" },\n" "$name" >> "$TMP_FILE"
   fi
done < "$INPUT_FILE"

# Close the include guards in the temporary file
echo "};" >> "$TMP_FILE"
echo "#endif // BLE_MANUFACTURER_LIST_H" >> "$TMP_FILE"

# Move the temporary file to the output file
mv "$TMP_FILE" "$OUTPUT_FILE"

# Count the number of entries written to the C header file
ITEMS=$(awk '/value:/' "$INPUT_FILE" | wc -l)

echo "Written $ITEMS entries to $OUTPUT_FILE -- recompile the sketch. Close arduino IDE and reopen ../../BLE-Scanner.ino"

# Additional code to read the YAML and rewrite in desired format

NOYB4Europe avatar Aug 06 '23 14:08 NOYB4Europe

echo "};" >> "$TMP_FILE" It is breaking syntax. Works without it.

Paxy avatar Aug 23 '23 18:08 Paxy

Thanks for you contribution.

I solved the problem with commit b12340e

But be aware that the produced file ble-manufacturer-list.h is not strictly a header file, as it doesn't contain any declarations of definitions. These are part of ble-manufacurer.cpp from where the list is included.

This script no longer expects that the source file is downloaded manually -- this is now directly done from the script on the fly.

Please, give me some feedback if this script also works for you.

gromeck avatar Aug 26 '23 17:08 gromeck