diff --git a/src/index.js b/src/index.js index 61bd055..bbfeb2a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ +const fs = require("fs"); const path = require('path'); const express = require('express'); const compression = require('compression'); -const protobufjs = require("protobufjs"); const commandLineArgs = require("command-line-args"); const commandLineUsage = require("command-line-usage"); @@ -50,24 +50,21 @@ if(options.help){ // get options and fallback to default values const port = options["port"] ?? 8080; -// load protobufs -const root = new protobufjs.Root(); -root.resolvePath = (origin, target) => path.join(__dirname, "protos", target); -root.loadSync('meshtastic/mqtt.proto'); -const HardwareModel = root.lookupEnum("HardwareModel"); -const Role = root.lookupEnum("Config.DeviceConfig.Role"); -const RegionCode = root.lookupEnum("Config.LoRaConfig.RegionCode"); -const ModemPreset = root.lookupEnum("Config.LoRaConfig.ModemPreset"); +// load json +const hardwareModels = JSON.parse(fs.readFileSync(path.join(__dirname, "json/hardware_models.json"), "utf-8")); +const roles = JSON.parse(fs.readFileSync(path.join(__dirname, "json/roles.json"), "utf-8")); +const regionCodes = JSON.parse(fs.readFileSync(path.join(__dirname, "json/region_codes.json"), "utf-8")); +const modemPresets = JSON.parse(fs.readFileSync(path.join(__dirname, "json/modem_presets.json"), "utf-8")); // appends extra info for node objects returned from api function formatNodeInfo(node) { return { ...node, node_id_hex: "!" + node.node_id.toString(16), - hardware_model_name: HardwareModel.valuesById[node.hardware_model] ?? null, - role_name: Role.valuesById[node.role] ?? null, - region_name: RegionCode.valuesById[node.region] ?? null, - modem_preset_name: ModemPreset.valuesById[node.modem_preset] ?? null, + hardware_model_name: hardwareModels[node.hardware_model] ?? null, + role_name: roles[node.role] ?? null, + region_name: regionCodes[node.region] ?? null, + modem_preset_name: modemPresets[node.modem_preset] ?? null, }; } @@ -666,7 +663,7 @@ app.get('/api/v1/stats/hardware-models', async (req, res) => { return { count: result._count.hardware_model, hardware_model: result.hardware_model, - hardware_model_name: HardwareModel.valuesById[result.hardware_model] ?? "UNKNOWN", + hardware_model_name: hardwareModels[result.hardware_model] ?? "UNKNOWN", }; }); diff --git a/src/json/hardware_models.json b/src/json/hardware_models.json new file mode 100644 index 0000000..6f4187f --- /dev/null +++ b/src/json/hardware_models.json @@ -0,0 +1,108 @@ +{ + "0": "UNSET", + "1": "TLORA_V2", + "2": "TLORA_V1", + "3": "TLORA_V2_1_1P6", + "4": "TBEAM", + "5": "HELTEC_V2_0", + "6": "TBEAM_V0P7", + "7": "T_ECHO", + "8": "TLORA_V1_1P3", + "9": "RAK4631", + "10": "HELTEC_V2_1", + "11": "HELTEC_V1", + "12": "LILYGO_TBEAM_S3_CORE", + "13": "RAK11200", + "14": "NANO_G1", + "15": "TLORA_V2_1_1P8", + "16": "TLORA_T3_S3", + "17": "NANO_G1_EXPLORER", + "18": "NANO_G2_ULTRA", + "19": "LORA_TYPE", + "20": "WIPHONE", + "21": "WIO_WM1110", + "22": "RAK2560", + "23": "HELTEC_HRU_3601", + "24": "HELTEC_WIRELESS_BRIDGE", + "25": "STATION_G1", + "26": "RAK11310", + "27": "SENSELORA_RP2040", + "28": "SENSELORA_S3", + "29": "CANARYONE", + "30": "RP2040_LORA", + "31": "STATION_G2", + "32": "LORA_RELAY_V1", + "33": "NRF52840DK", + "34": "PPR", + "35": "GENIEBLOCKS", + "36": "NRF52_UNKNOWN", + "37": "PORTDUINO", + "38": "ANDROID_SIM", + "39": "DIY_V1", + "40": "NRF52840_PCA10059", + "41": "DR_DEV", + "42": "M5STACK", + "43": "HELTEC_V3", + "44": "HELTEC_WSL_V3", + "45": "BETAFPV_2400_TX", + "46": "BETAFPV_900_NANO_TX", + "47": "RPI_PICO", + "48": "HELTEC_WIRELESS_TRACKER", + "49": "HELTEC_WIRELESS_PAPER", + "50": "T_DECK", + "51": "T_WATCH_S3", + "52": "PICOMPUTER_S3", + "53": "HELTEC_HT62", + "54": "EBYTE_ESP32_S3", + "55": "ESP32_S3_PICO", + "56": "CHATTER_2", + "57": "HELTEC_WIRELESS_PAPER_V1_0", + "58": "HELTEC_WIRELESS_TRACKER_V1_0", + "59": "UNPHONE", + "60": "TD_LORAC", + "61": "CDEBYTE_EORA_S3", + "62": "TWC_MESH_V4", + "63": "NRF52_PROMICRO_DIY", + "64": "RADIOMASTER_900_BANDIT_NANO", + "65": "HELTEC_CAPSULE_SENSOR_V3", + "66": "HELTEC_VISION_MASTER_T190", + "67": "HELTEC_VISION_MASTER_E213", + "68": "HELTEC_VISION_MASTER_E290", + "69": "HELTEC_MESH_NODE_T114", + "70": "SENSECAP_INDICATOR", + "71": "TRACKER_T1000_E", + "72": "RAK3172", + "73": "WIO_E5", + "74": "RADIOMASTER_900_BANDIT", + "75": "ME25LS01_4Y10TD", + "76": "RP2040_FEATHER_RFM95", + "77": "M5STACK_COREBASIC", + "78": "M5STACK_CORE2", + "79": "RPI_PICO2", + "80": "M5STACK_CORES3", + "81": "SEEED_XIAO_S3", + "82": "MS24SF1", + "83": "TLORA_C6", + "84": "WISMESH_TAP", + "85": "ROUTASTIC", + "86": "MESH_TAB", + "87": "MESHLINK", + "88": "XIAO_NRF52_KIT", + "89": "THINKNODE_M1", + "90": "THINKNODE_M2", + "91": "T_ETH_ELITE", + "92": "HELTEC_SENSOR_HUB", + "93": "RESERVED_FRIED_CHICKEN", + "94": "HELTEC_MESH_POCKET", + "95": "SEEED_SOLAR_NODE", + "96": "NOMADSTAR_METEOR_PRO", + "97": "CROWPANEL", + "98": "LINK_32", + "99": "SEEED_WIO_TRACKER_L1", + "100": "SEEED_WIO_TRACKER_L1_EINK", + "101": "QWANTZ_TINY_ARMS", + "102": "T_DECK_PRO", + "103": "T_LORA_PAGER", + "104": "GAT562_MESH_TRIAL_TRACKER", + "255": "PRIVATE_HW" +} diff --git a/src/json/modem_presets.json b/src/json/modem_presets.json new file mode 100644 index 0000000..75c1ba4 --- /dev/null +++ b/src/json/modem_presets.json @@ -0,0 +1,11 @@ +{ + "0": "LONG_FAST", + "1": "LONG_SLOW", + "2": "VERY_LONG_SLOW", + "3": "MEDIUM_SLOW", + "4": "MEDIUM_FAST", + "5": "SHORT_SLOW", + "6": "SHORT_FAST", + "7": "LONG_MODERATE", + "8": "SHORT_TURBO" +} diff --git a/src/json/region_codes.json b/src/json/region_codes.json new file mode 100644 index 0000000..d63c276 --- /dev/null +++ b/src/json/region_codes.json @@ -0,0 +1,24 @@ +{ + "0": "UNSET", + "1": "US", + "2": "EU_433", + "3": "EU_868", + "4": "CN", + "5": "JP", + "6": "ANZ", + "7": "KR", + "8": "TW", + "9": "RU", + "10": "IN", + "11": "NZ_865", + "12": "TH", + "13": "LORA_24", + "14": "UA_433", + "15": "UA_868", + "16": "MY_433", + "17": "MY_919", + "18": "SG_923", + "19": "PH_433", + "20": "PH_868", + "21": "PH_915" +} diff --git a/src/json/roles.json b/src/json/roles.json new file mode 100644 index 0000000..1fe96fd --- /dev/null +++ b/src/json/roles.json @@ -0,0 +1,14 @@ +{ + "0": "CLIENT", + "1": "CLIENT_MUTE", + "2": "ROUTER", + "3": "ROUTER_CLIENT", + "4": "REPEATER", + "5": "TRACKER", + "6": "SENSOR", + "7": "TAK", + "8": "CLIENT_HIDDEN", + "9": "LOST_AND_FOUND", + "10": "TAK_TRACKER", + "11": "ROUTER_LATE" +}