Skip to content

Commit

Permalink
Got string quoting and macro expansion working
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern authored and fifieldt committed Nov 30, 2024
1 parent 0f20870 commit 469740e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 148 deletions.
2 changes: 1 addition & 1 deletion bin/build-userprefs-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def write_macros_to_json(macros, output_file):

def main():
header_file = 'userPrefs.h'
output_file = 'userPrefs.json'
output_file = 'userPrefs.jsonc'
# Uncomment all macros in the header file
with open(header_file, 'r') as file:
lines = file.readlines()
Expand Down
26 changes: 22 additions & 4 deletions bin/platformio-custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from os.path import join
import json
import re

from readprops import readProps

Expand Down Expand Up @@ -91,19 +92,36 @@ def esp32_create_combined_bin(source, target, env):
verObj = readProps(prefsLoc)
print("Using meshtastic platformio-custom.py, firmware version " + verObj["long"] + " on " + env.get("PIOENV"))

jsonLoc = projenv["PROJECT_DIR"] + "/userPrefs.json"
jsonLoc = env["PROJECT_DIR"] + "/userPrefs.json"
with open(jsonLoc) as f:
userPrefs = json.load(f)
jsonStr = re.sub("//.*","", f.read(), flags=re.MULTILINE)
userPrefs = json.loads(jsonStr)

pref_flags = []
# Pre-process the userPrefs
for pref in userPrefs:
if userPrefs[pref].startswith("{"):
pref_flags.append("-D" + pref + "=" + userPrefs[pref])
elif userPrefs[pref].replace(".", "").isdigit():
pref_flags.append("-D" + pref + "=" + userPrefs[pref])
elif userPrefs[pref] == "true" or userPrefs[pref] == "false":
pref_flags.append("-D" + pref + "=" + userPrefs[pref])
elif userPrefs[pref].startswith("meshtastic_"):
pref_flags.append("-D" + pref + "=" + userPrefs[pref])
# If the value is a string, we need to wrap it in quotes
else:
pref_flags.append("-D" + pref + "=" + env.StringifyMacro(userPrefs[pref]) + "")

# General options that are passed to the C and C++ compilers
flags = [
"-DAPP_VERSION=" + verObj["long"],
"-DAPP_VERSION_SHORT=" + verObj["short"],
"-DAPP_ENV=" + env.get("PIOENV"),
] + ["-D" + key + "=" + userPrefs[key] for key in userPrefs]
] + pref_flags

print ("Using flags:")
for flag in flags:
print(flag.replace("-D", ""))
print(flag)

projenv.Append(
CCFLAGS=flags,
Expand Down
107 changes: 0 additions & 107 deletions userPrefs.h

This file was deleted.

71 changes: 35 additions & 36 deletions userPrefs.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
{
"USERPREFS_BUTTON_PIN": "36",
"USERPREFS_CHANNELS_TO_WRITE": "3",
"USERPREFS_CHANNEL_0_DOWNLINK_ENABLED": "true",
"USERPREFS_CHANNEL_0_NAME": "\"DEFCONnect\"",
"USERPREFS_CHANNEL_0_PRECISION": "14",
"USERPREFS_CHANNEL_0_PSK": "{ 0x38, 0x4b, 0xbc, 0xc0, 0x1d, 0xc0, 0x22, 0xd1, 0x81, 0xbf, 0x36, 0xb8, 0x61, 0x21, 0xe1, 0xfb, 0x96, 0xb7, 0x2e, 0x55, 0xbf, 0x74, 0x22, 0x7e, 0x9d, 0x6a, 0xfb, 0x48, 0xd6, 0x4c, 0xb1, 0xa1 }",
"USERPREFS_CHANNEL_0_UPLINK_ENABLED": "true",
"USERPREFS_CHANNEL_1_DOWNLINK_ENABLED": "true",
"USERPREFS_CHANNEL_1_NAME": "\"REPLACEME\"",
"USERPREFS_CHANNEL_1_PRECISION": "14",
"USERPREFS_CHANNEL_1_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
"USERPREFS_CHANNEL_1_UPLINK_ENABLED": "true",
"USERPREFS_CHANNEL_2_DOWNLINK_ENABLED": "true",
"USERPREFS_CHANNEL_2_NAME": "\"REPLACEME\"",
"USERPREFS_CHANNEL_2_PRECISION": "14",
"USERPREFS_CHANNEL_2_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
"USERPREFS_CHANNEL_2_UPLINK_ENABLED": "true",
"USERPREFS_CONFIG_GPS_MODE": "meshtastic_Config_PositionConfig_GpsMode_ENABLED",
"USERPREFS_CONFIG_LORA_IGNORE_MQTT": "true",
"USERPREFS_CONFIG_LORA_REGION": "meshtastic_Config_LoRaConfig_RegionCode_US",
"USERPREFS_CONFIG_OWNER_LONG_NAME": "\"My Long Name\"",
"USERPREFS_CONFIG_OWNER_SHORT_NAME": "\"MLN\"",
"USERPREFS_EVENT_MODE": "1",
"USERPREFS_FIXED_BLUETOOTH": "121212",
"USERPREFS_FIXED_GPS": "",
"USERPREFS_FIXED_GPS_ALT": "0",
"USERPREFS_FIXED_GPS_LAT": "48.85873920",
"USERPREFS_FIXED_GPS_LON": "2.294508368",
"USERPREFS_HAS_SPLASH": "",
"USERPREFS_LORACONFIG_CHANNEL_NUM": "31",
"USERPREFS_LORACONFIG_MODEM_PRESET": "meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST",
"USERPREFS_SPLASH_TITLE": "\"DEFCONtastic\"",
"USERPREFS_TZ_STRING": "\"tzplaceholder \"",
"USERPREFS_USE_ADMIN_KEY_0": "{ 0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c };",
"USERPREFS_USE_ADMIN_KEY_1": "{};",
"USERPREFS_USE_ADMIN_KEY_2": "{};"
// "USERPREFS_BUTTON_PIN": "36",
// "USERPREFS_CHANNELS_TO_WRITE": "3",
// "USERPREFS_CHANNEL_0_DOWNLINK_ENABLED": "true",
// "USERPREFS_CHANNEL_0_NAME": "DEFCONnect",
// "USERPREFS_CHANNEL_0_PRECISION": "14",
// "USERPREFS_CHANNEL_0_PSK": "{ 0x38, 0x4b, 0xbc, 0xc0, 0x1d, 0xc0, 0x22, 0xd1, 0x81, 0xbf, 0x36, 0xb8, 0x61, 0x21, 0xe1, 0xfb, 0x96, 0xb7, 0x2e, 0x55, 0xbf, 0x74, 0x22, 0x7e, 0x9d, 0x6a, 0xfb, 0x48, 0xd6, 0x4c, 0xb1, 0xa1 }",
// "USERPREFS_CHANNEL_0_UPLINK_ENABLED": "true",
// "USERPREFS_CHANNEL_1_DOWNLINK_ENABLED": "true",
// "USERPREFS_CHANNEL_1_NAME": "REPLACEME",
// "USERPREFS_CHANNEL_1_PRECISION": "14",
// "USERPREFS_CHANNEL_1_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
// "USERPREFS_CHANNEL_1_UPLINK_ENABLED": "true",
// "USERPREFS_CHANNEL_2_DOWNLINK_ENABLED": "true",
// "USERPREFS_CHANNEL_2_NAME": "REPLACEME",
// "USERPREFS_CHANNEL_2_PRECISION": "14",
// "USERPREFS_CHANNEL_2_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
// "USERPREFS_CHANNEL_2_UPLINK_ENABLED": "true",
// "USERPREFS_CONFIG_GPS_MODE": "meshtastic_Config_PositionConfig_GpsMode_ENABLED",
// "USERPREFS_CONFIG_LORA_IGNORE_MQTT": "true",
// "USERPREFS_CONFIG_LORA_REGION": "meshtastic_Config_LoRaConfig_RegionCode_US",
// "USERPREFS_CONFIG_OWNER_LONG_NAME": "My Long Name",
// "USERPREFS_CONFIG_OWNER_SHORT_NAME": "MLN",
// "USERPREFS_EVENT_MODE": "1",
// "USERPREFS_FIXED_BLUETOOTH": "121212",
// "USERPREFS_FIXED_GPS": "",
// "USERPREFS_FIXED_GPS_ALT": "0",
// "USERPREFS_FIXED_GPS_LAT": "48.85873920",
// "USERPREFS_FIXED_GPS_LON": "2.294508368",
// "USERPREFS_LORACONFIG_CHANNEL_NUM": "31",
// "USERPREFS_LORACONFIG_MODEM_PRESET": "meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST",
// "USERPREFS_SPLASH_TITLE": "DEFCONtastic",
// "USERPREFS_TZ_STRING": "tzplaceholder ",
// "USERPREFS_USE_ADMIN_KEY_0": "{ 0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c }"
// "USERPREFS_USE_ADMIN_KEY_1": "{};",
// "USERPREFS_USE_ADMIN_KEY_2": "{};"
}

0 comments on commit 469740e

Please sign in to comment.