From 283b9a10bba96653955fc9a4cba0d0c2f0486bf5 Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Sun, 8 Nov 2026 22:05:52 +0200 Subject: [PATCH 1/3] feat: add LilkaModules library for extension module drivers New PlatformIO library lib/lilka_modules with drivers for the Lilka v2 extension modules: - GPS (NEO-M8N): UART + NMEA parser (GGA, RMC, GSA, GSV) - CAN (SN65HVD232): TWAI wrapper - IR (KY-005 + KY-022): RMT TX/RX, NEC / Samsung / Sony SIRC codec - LORA (SX1262 / SX1268): polled IRQs, TCXO, RF switch - RF: nRF24L01+ and CC1101 - GYRO MAGNET: BMI260 (optional Bosch config blob) and TMAG5273 Also: - lilka::mod::resources: pin/peripheral ownership tracking - LILKA_EXT_RX / LILKA_EXT_TX in config.h (header pins 3 and 4) - LuaLS stubs for the new Keira Lua modules, serial.begin rx/tx args - releases.yml publishes lib/lilka_modules to the registry too --- .github/workflows/releases.yml | 6 +- addons/lualilka/library/can.lua | 67 ++ addons/lualilka/library/cc1101.lua | 66 ++ addons/lualilka/library/gps.lua | 85 +++ addons/lualilka/library/imu.lua | 49 ++ addons/lualilka/library/ir.lua | 55 ++ addons/lualilka/library/lora.lua | 77 ++ addons/lualilka/library/mag.lua | 63 ++ addons/lualilka/library/nrf24.lua | 78 ++ addons/lualilka/library/serial.lua | 16 +- lib/lilka/src/lilka/config.h | 3 + lib/lilka_modules/README.md | 29 + .../examples/lora_beacon/lora_beacon.ino | 37 + lib/lilka_modules/library.json | 21 + lib/lilka_modules/src/lilka_modules.h | 19 + .../src/lilka_modules/BMI260_CONFIG_LICENSE | 32 + .../src/lilka_modules/bmi260.cpp | 195 +++++ lib/lilka_modules/src/lilka_modules/bmi260.h | 68 ++ .../src/lilka_modules/bmi260_config.h | 702 ++++++++++++++++++ lib/lilka_modules/src/lilka_modules/can.cpp | 101 +++ lib/lilka_modules/src/lilka_modules/can.h | 53 ++ .../src/lilka_modules/cc1101.cpp | 368 +++++++++ lib/lilka_modules/src/lilka_modules/cc1101.h | 93 +++ lib/lilka_modules/src/lilka_modules/gps.cpp | 84 +++ lib/lilka_modules/src/lilka_modules/gps.h | 51 ++ lib/lilka_modules/src/lilka_modules/ir.cpp | 164 ++++ lib/lilka_modules/src/lilka_modules/ir.h | 61 ++ .../src/lilka_modules/ir_codec.cpp | 178 +++++ .../src/lilka_modules/ir_codec.h | 44 ++ lib/lilka_modules/src/lilka_modules/nmea.cpp | 182 +++++ lib/lilka_modules/src/lilka_modules/nmea.h | 86 +++ lib/lilka_modules/src/lilka_modules/nrf24.cpp | 279 +++++++ lib/lilka_modules/src/lilka_modules/nrf24.h | 95 +++ lib/lilka_modules/src/lilka_modules/pins.h | 62 ++ .../src/lilka_modules/resources.cpp | 109 +++ .../src/lilka_modules/resources.h | 70 ++ .../src/lilka_modules/sx126x.cpp | 437 +++++++++++ lib/lilka_modules/src/lilka_modules/sx126x.h | 110 +++ .../src/lilka_modules/tmag5273.cpp | 77 ++ .../src/lilka_modules/tmag5273.h | 44 ++ 40 files changed, 4409 insertions(+), 7 deletions(-) create mode 100644 addons/lualilka/library/can.lua create mode 100644 addons/lualilka/library/cc1101.lua create mode 100644 addons/lualilka/library/gps.lua create mode 100644 addons/lualilka/library/imu.lua create mode 100644 addons/lualilka/library/ir.lua create mode 100644 addons/lualilka/library/lora.lua create mode 100644 addons/lualilka/library/mag.lua create mode 100644 addons/lualilka/library/nrf24.lua create mode 100644 lib/lilka_modules/README.md create mode 100644 lib/lilka_modules/examples/lora_beacon/lora_beacon.ino create mode 100644 lib/lilka_modules/library.json create mode 100644 lib/lilka_modules/src/lilka_modules.h create mode 100644 lib/lilka_modules/src/lilka_modules/BMI260_CONFIG_LICENSE create mode 100644 lib/lilka_modules/src/lilka_modules/bmi260.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/bmi260.h create mode 100644 lib/lilka_modules/src/lilka_modules/bmi260_config.h create mode 100644 lib/lilka_modules/src/lilka_modules/can.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/can.h create mode 100644 lib/lilka_modules/src/lilka_modules/cc1101.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/cc1101.h create mode 100644 lib/lilka_modules/src/lilka_modules/gps.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/gps.h create mode 100644 lib/lilka_modules/src/lilka_modules/ir.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/ir.h create mode 100644 lib/lilka_modules/src/lilka_modules/ir_codec.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/ir_codec.h create mode 100644 lib/lilka_modules/src/lilka_modules/nmea.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/nmea.h create mode 100644 lib/lilka_modules/src/lilka_modules/nrf24.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/nrf24.h create mode 100644 lib/lilka_modules/src/lilka_modules/pins.h create mode 100644 lib/lilka_modules/src/lilka_modules/resources.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/resources.h create mode 100644 lib/lilka_modules/src/lilka_modules/sx126x.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/sx126x.h create mode 100644 lib/lilka_modules/src/lilka_modules/tmag5273.cpp create mode 100644 lib/lilka_modules/src/lilka_modules/tmag5273.h diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index fe3b906..26c5ca5 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -90,7 +90,9 @@ jobs: run: | echo "Updating version to ${{ needs.update-version.outputs.version }}" sed -i 's/"version": "[^"]*"/"version": "${{ needs.update-version.outputs.version }}"/' lib/lilka/library.json + sed -i 's/"version": "[^"]*"/"version": "${{ needs.update-version.outputs.version }}"/' lib/lilka_modules/library.json cat lib/lilka/library.json + cat lib/lilka_modules/library.json - name: Generate version_auto_gen.h run: | @@ -113,8 +115,8 @@ jobs: - name: Publish to PlatformIO Registry run: | - cd lib/lilka - pio pkg publish --non-interactive + (cd lib/lilka && pio pkg publish --non-interactive) + (cd lib/lilka_modules && pio pkg publish --non-interactive) echo "Published to PlatformIO Registry" github-releases-to-discord: diff --git a/addons/lualilka/library/can.lua b/addons/lualilka/library/can.lua new file mode 100644 index 0000000..ed2acda --- /dev/null +++ b/addons/lualilka/library/can.lua @@ -0,0 +1,67 @@ +---@meta + +---Шина CAN на вбудованому контролері TWAI (модуль 008 CAN, трансивер SN65HVD232). +---@class can +can = {} + +---@class can.Options +---@field bitrate? integer 25000, 50000, 100000, 125000, 250000, 500000 (за замовчуванням), 800000 або 1000000 +---@field mode? string ``"normal"`` (за замовчуванням), ``"listen"`` (лише прийом, без ACK) або ``"no_ack"`` (самотест) +---@field tx? integer GPIO TX (за замовчуванням 43) +---@field rx? integer GPIO RX (за замовчуванням 44) +---@field filter? can.Filter + +---@class can.Filter +---@field code? integer acceptance code (за замовчуванням 0) +---@field mask? integer acceptance mask, 1 = біт не перевіряється (за замовчуванням 0xFFFFFFFF - приймати все) +---@field single? boolean один 32-бітний фільтр (за замовчуванням true) + +---@class can.SendOptions +---@field extended? boolean 29-бітний ідентифікатор (за замовчуванням - якщо id > 0x7FF) +---@field rtr? boolean remote frame; тоді ``data`` - запитувана довжина (число) +---@field timeout? integer мс очікування місця в черзі (за замовчуванням 100) + +---@class can.Message +---@field id integer +---@field data string до 8 байт +---@field dlc integer +---@field extended boolean +---@field rtr boolean + +---@class can.Bus +local Bus = {} + +---Запускає контролер CAN. +---@param options? can.Options +---@return can.Bus|nil bus +---@return string? error +---@usage +--- local bus = can.new({bitrate = 500000}) +--- bus:send(0x123, "\xAB\xCD") +function can.new(options) end + +---Ставить кадр у чергу на передачу. +---@param id integer +---@param data? string|integer[] до 8 байт +---@param options? can.SendOptions +---@return boolean ok +---@return string? error +function Bus:send(id, data, options) end + +---Повертає прийнятий кадр або ``nil``. +---@param timeout_ms? integer скільки чекати (за замовчуванням 0) +---@return can.Message|nil +function Bus:receive(timeout_ms) end + +---Стан контролера: ``state`` (``"stopped"``, ``"running"``, ``"bus_off"``, ``"recovering"``), лічильники помилок і черг. +---@return table|nil +function Bus:status() end + +---Виходить зі стану BUS_OFF або перезапускає зупинений контролер. +---@return boolean +function Bus:recover() end + +---Зупиняє контролер і звільняє контакти. +function Bus:close() end + +return can diff --git a/addons/lualilka/library/cc1101.lua b/addons/lualilka/library/cc1101.lua new file mode 100644 index 0000000..e38f6bc --- /dev/null +++ b/addons/lualilka/library/cc1101.lua @@ -0,0 +1,66 @@ +---@meta + +---Субгігагерцове радіо CC1101 (модуль 004 RF з CC1101) на шині SPI2. +--- +---Діапазони 300-348, 387-464 і 779-928 МГц. Пакети змінної довжини до 61 байта. +---Перевіряйте, які частоти дозволені у вашій країні. +---@class cc1101 +cc1101 = {} + +---@class cc1101.Options +---@field frequency? number МГц (за замовчуванням 433.92) +---@field modulation? string ``"gfsk"`` (за замовчуванням), ``"2fsk"``, ``"ask"`` (OOK), ``"4fsk"`` або ``"msk"`` +---@field rate? integer бод, 600-500000 (за замовчуванням 38400) +---@field deviation? integer Гц (за замовчуванням 20000) +---@field bandwidth? integer Гц, смуга приймача (за замовчуванням 100000) +---@field power? integer дБм, -30...10 (за замовчуванням 0) +---@field sync_word? integer (за замовчуванням 0xD391) +---@field crc? boolean (за замовчуванням true) + +---@class cc1101.Packet +---@field data string +---@field rssi number дБм +---@field lqi integer +---@field crc_ok boolean + +---@class cc1101.Radio +local Radio = {} + +---@param options? cc1101.Options +---@return cc1101.Radio|nil radio +---@return string? error +---@usage +--- local radio = assert(cc1101.new({frequency = 433.92})) +--- radio:send("hello") +function cc1101.new(options) end + +---Надсилає пакет до 61 байта. +---@param data string|integer[] +---@param timeout_ms? integer (за замовчуванням 500) +---@return boolean +function Radio:send(data, timeout_ms) end + +---Вмикає прийом (``receive()`` теж вмикає його автоматично). +function Radio:listen() end + +---Повертає прийнятий пакет або ``nil`` (без очікування). +---@return cc1101.Packet|nil +function Radio:receive() end + +---Поточний RSSI, дБм. +---@return number +function Radio:rssi() end + +---@param mhz number +---@return boolean +function Radio:set_frequency(mhz) end + +---@param dbm integer +function Radio:set_power(dbm) end + +function Radio:idle() end + +---Звільняє SPI і контакти. +function Radio:close() end + +return cc1101 diff --git a/addons/lualilka/library/gps.lua b/addons/lualilka/library/gps.lua new file mode 100644 index 0000000..83cb3e0 --- /dev/null +++ b/addons/lualilka/library/gps.lua @@ -0,0 +1,85 @@ +---@meta + +---Приймач GNSS (модуль 005 GPS, u-blox NEO-M8N) на UART2. +--- +---Об'єкт тримає контакти зайнятими, доки його не закрито (``close()``) або доки скрипт не завершився. +---@class gps +gps = {} + +---@class gps.Options +---@field baud? integer швидкість UART (за замовчуванням 9600) +---@field rx? integer GPIO входу (TX модуля), за замовчуванням 44 +---@field tx? integer|false GPIO виходу (RX модуля), за замовчуванням 43; ``false`` - лише прийом + +---@class gps.Fix +---@field valid boolean є фіксація (RMC status = A) +---@field latitude number градуси, південь < 0 +---@field longitude number градуси, захід < 0 +---@field altitude number метри над рівнем моря +---@field speed number км/год +---@field course number градуси від півночі +---@field satellites integer супутники, що використовуються +---@field quality integer 0 - немає, 1 - GPS, 2 - DGPS, 4/5 - RTK, 6 - оцінка +---@field fix_type integer 1 - немає, 2 - 2D, 3 - 3D +---@field hdop number +---@field vdop number +---@field pdop number +---@field year integer UTC +---@field month integer +---@field day integer +---@field hour integer +---@field minute integer +---@field second integer +---@field millis integer +---@field updates integer кількість розібраних GGA/RMC + +---@class gps.Satellite +---@field system string ``"gps"``, ``"glonass"``, ``"galileo"``, ``"beidou"`` або ``"other"`` +---@field prn integer +---@field elevation integer градуси +---@field azimuth integer градуси +---@field snr? integer дБГц, відсутній, якщо супутник не відстежується + +---@class gps.Receiver +local Receiver = {} + +---Запускає UART і повертає об'єкт приймача. +---@param options? gps.Options +---@return gps.Receiver|nil receiver +---@return string? error +---@usage +--- local g = gps.new() +function gps.new(options) end + +---Читає все, що надійшло з модуля, і розбирає NMEA. Викликайте часто (наприклад, у ``lilka.update``). +---@return integer sentences кількість нових речень +function Receiver:update() end + +---Повертає останні відомі дані про розташування. +---@return gps.Fix +function Receiver:fix() end + +---Повертає супутники в полі зору (з повідомлень GSV). +---@return gps.Satellite[] +function Receiver:satellites() end + +---Останнє прийняте NMEA-речення (без ``$`` і кінця рядка) - для налагодження. +---@return string +function Receiver:last_sentence() end + +---Надсилає сирі байти в модуль (наприклад, команду ``$PUBX``). +---@param data string +---@return boolean +function Receiver:write(data) end + +---Надсилає UBX-повідомлення (контрольна сума додається автоматично). +---@param class integer +---@param id integer +---@param payload? string +---@return boolean +function Receiver:send_ubx(class, id, payload) end + +---Зупиняє UART і звільняє контакти. +function Receiver:close() end + +return gps diff --git a/addons/lualilka/library/imu.lua b/addons/lualilka/library/imu.lua new file mode 100644 index 0000000..c128107 --- /dev/null +++ b/addons/lualilka/library/imu.lua @@ -0,0 +1,49 @@ +---@meta + +---Акселерометр і гіроскоп BMI260 (модуль 006 GYRO MAGNET) на шині I2C. +---@class imu +imu = {} + +---@class imu.Options +---@field sda? integer (за замовчуванням 44) +---@field scl? integer (за замовчуванням 43) +---@field address? integer 0x68 або 0x69 (за замовчуванням - знайти автоматично) +---@field config? boolean|string ``true`` - вбудований конфігураційний блоб Bosch (за замовчуванням), шлях до файлу - завантажити з файлу, ``false`` - без блобу (не перевірено, чи дані тоді коректні) +---@field accel_range? integer g: 2, 4, 8 (за замовчуванням), 16 +---@field gyro_range? integer °/с: 125, 250, 500, 1000, 2000 (за замовчуванням) +---@field accel_odr? integer Гц: 12, 25, 50, 100 (за замовчуванням), 200, 400, 800, 1600 +---@field gyro_odr? integer Гц: 25, 50, 100, 200 (за замовчуванням), 400, 800, 1600, 3200 + +---@class imu.Data +---@field ax number g +---@field ay number g +---@field az number g +---@field gx number °/с +---@field gy number °/с +---@field gz number °/с + +---@class imu.Sensor +local Sensor = {} + +---@param options? imu.Options +---@return imu.Sensor|nil sensor +---@return string? error +---@usage +--- local sensor = assert(imu.new()) +--- local d = sensor:read() +function imu.new(options) end + +---@return imu.Data|nil +function Sensor:read() end + +---@return number °C +function Sensor:temperature() end + +---``true``, якщо блоб завантажено і чип його прийняв. +---@return boolean +function Sensor:initialized() end + +---Звільняє I2C і контакти. +function Sensor:close() end + +return imu diff --git a/addons/lualilka/library/ir.lua b/addons/lualilka/library/ir.lua new file mode 100644 index 0000000..b12a7ec --- /dev/null +++ b/addons/lualilka/library/ir.lua @@ -0,0 +1,55 @@ +---@meta + +---ІЧ-передавач і приймач (модуль 002 IR: KY-005 + KY-022) на периферії RMT. +--- +---Протоколи: NEC (8- і 16-бітна адреса), Samsung, Sony SIRC (12/15/20 біт). Невідомі протоколи можна приймати +---і відтворювати як сирі тривалості. +---@class ir +ir = {} + +---@class ir.Options +---@field tx? integer|false GPIO передавача (за замовчуванням 43), ``false`` - без передавача +---@field rx? integer|false GPIO приймача (за замовчуванням 44), ``false`` - без приймача +---@field carrier? integer частота несучої, Гц (за замовчуванням 38000) + +---@class ir.Code +---@field protocol string ``"NEC"``, ``"SAMSUNG"``, ``"SONY"`` або ``"UNKNOWN"`` +---@field address? integer +---@field command? integer +---@field ["repeat"]? boolean кадр повторення NEC (кнопку утримують) +---@field bits? integer +---@field raw integer[] тривалості, мкс: імпульс, пауза, імпульс, ... + +---@class ir.Transceiver +local Transceiver = {} + +---@param options? ir.Options +---@return ir.Transceiver|nil transceiver +---@return string? error +---@usage +--- local remote = ir.new() +--- remote:send("NEC", 0x04, 0x08) +function ir.new(options) end + +---Кодує й надсилає кадр. +---@param protocol string ``"NEC"``, ``"SAMSUNG"`` або ``"SONY"`` +---@param address integer +---@param command integer +---@param repeats? integer скільки разів повторити (за замовчуванням 0, для SONY - 2) +---@return boolean +function Transceiver:send(protocol, address, command, repeats) end + +---Надсилає сирі тривалості (до 380), наприклад ``raw`` з ``receive()``. +---@param durations integer[] мкс, починаючи з імпульсу +---@param carrier? integer Гц +---@return boolean +function Transceiver:send_raw(durations, carrier) end + +---Повертає прийнятий кадр або ``nil`` (без очікування). +---@return ir.Code|nil +function Transceiver:receive() end + +---Звільняє RMT і контакти. +function Transceiver:close() end + +return ir diff --git a/addons/lualilka/library/lora.lua b/addons/lualilka/library/lora.lua new file mode 100644 index 0000000..1d778da --- /dev/null +++ b/addons/lualilka/library/lora.lua @@ -0,0 +1,77 @@ +---@meta + +---LoRa-радіо SX1262 / SX1268 (модуль 003 LORA, Ebyte E22-900M / E22-400M) на шині SPI2. +--- +---Перевіряйте, які частоти й потужності дозволені у вашій країні. Не передавайте без антени. +---@class lora +lora = {} + +---@class lora.Options +---@field chip? string ``"sx1262"`` (E22-900M, 850-930 МГц, за замовчуванням) або ``"sx1268"`` (E22-400M, 410-493 МГц) +---@field frequency? integer Гц (за замовчуванням 868100000 або 433175000 для sx1268) +---@field sf? integer коефіцієнт розширення 5-12 (за замовчуванням 7) +---@field bandwidth? integer Гц: 7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000 (за замовчуванням), 250000, 500000 +---@field cr? integer coding rate 5-8 = 4/5...4/8 (за замовчуванням 5) +---@field power? integer дБм, -9...22 (за замовчуванням 0) +---@field sync_word? integer 0x12 - приватна мережа (за замовчуванням), 0x34 - LoRaWAN +---@field preamble? integer символів (за замовчуванням 8) +---@field crc? boolean (за замовчуванням true) +---@field invert_iq? boolean (за замовчуванням false) + +---@class lora.Packet +---@field data string +---@field rssi number дБм +---@field snr number дБ +---@field crc_ok boolean + +---@class lora.Radio +local Radio = {} + +---@param options? lora.Options +---@return lora.Radio|nil radio +---@return string? error +---@usage +--- local radio = assert(lora.new({frequency = 868100000, sf = 9})) +--- radio:send("hello") +function lora.new(options) end + +---Надсилає пакет (до 255 байт) і чекає завершення. Потім повертається в прийом, якщо він був увімкнений. +---@param data string|integer[] +---@param timeout_ms? integer (за замовчуванням 3000) +---@return boolean ok +---@return integer|string time_on_air_ms_or_error +function Radio:send(data, timeout_ms) end + +---Вмикає безперервний прийом (``receive()`` теж вмикає його автоматично). +function Radio:listen() end + +---Повертає прийнятий пакет або ``nil`` (без очікування). +---@return lora.Packet|nil +function Radio:receive() end + +---Поточний RSSI каналу, дБм. +---@return number +function Radio:rssi() end + +---@param hz integer +---@return boolean +function Radio:set_frequency(hz) end + +---@param dbm integer -9...22 +---@return boolean +function Radio:set_power(dbm) end + +---Розрахунковий час у ефірі для пакета заданої довжини. +---@param length integer +---@return integer ms +function Radio:time_on_air(length) end + +function Radio:standby() end + +---Сон із збереженням налаштувань; будь-яка наступна дія будить радіо. +function Radio:sleep() end + +---Присипляє радіо і звільняє SPI та контакти. +function Radio:close() end + +return lora diff --git a/addons/lualilka/library/mag.lua b/addons/lualilka/library/mag.lua new file mode 100644 index 0000000..26fab30 --- /dev/null +++ b/addons/lualilka/library/mag.lua @@ -0,0 +1,63 @@ +---@meta + +---3D-датчик магнітного поля TMAG5273 (модуль 006 GYRO MAGNET) на шині I2C. +--- +---Поруч із платою Лілки поле спотворене, тому перед використанням як компаса потрібне калібрування. +---@class mag +mag = {} + +---@class mag.Options +---@field sda? integer (за замовчуванням 44) +---@field scl? integer (за замовчуванням 43) +---@field address? integer (за замовчуванням 0x35) +---@field range? string ``"low"`` (±40 мТл для A1, за замовчуванням) або ``"high"`` (±80 мТл) +---@field averaging? integer 0-5: 1x ... 32x (за замовчуванням 5) + +---@class mag.Data +---@field x number мкТл +---@field y number мкТл +---@field z number мкТл + +---@class mag.Sensor +local Sensor = {} + +---@param options? mag.Options +---@return mag.Sensor|nil sensor +---@return string? error +function mag.new(options) end + +---Поле з урахуванням зміщення. +---@return mag.Data|nil +function Sensor:read() end + +---Напрямок у площині X/Y, 0-360° (тримайте Лілку горизонтально). +---@return number|nil +function Sensor:heading() end + +---@return number °C +function Sensor:temperature() end + +---Задає зміщення (hard-iron), яке віднімається від кожного вимірювання. +---@param x number мкТл +---@param y number мкТл +---@param z number мкТл +function Sensor:set_offset(x, y, z) end + +---@return number x +---@return number y +---@return number z +function Sensor:get_offset() end + +---Починає калібрування: обертайте Лілку в усіх напрямках, викликаючи ``read()``; зміщення оновлюється автоматично. +function Sensor:start_calibration() end + +---Завершує калібрування і повертає отримане зміщення. +---@return number x +---@return number y +---@return number z +function Sensor:stop_calibration() end + +---Звільняє I2C і контакти. +function Sensor:close() end + +return mag diff --git a/addons/lualilka/library/nrf24.lua b/addons/lualilka/library/nrf24.lua new file mode 100644 index 0000000..85c0f7e --- /dev/null +++ b/addons/lualilka/library/nrf24.lua @@ -0,0 +1,78 @@ +---@meta + +---Радіо 2.4 ГГц nRF24L01+ (модуль 004 RF) на шині SPI2. +---@class nrf24 +nrf24 = {} + +---@class nrf24.Options +---@field channel? integer 0-125, частота = 2400 + channel МГц (за замовчуванням 76) +---@field rate? integer 250000, 1000000 (за замовчуванням) або 2000000 +---@field power? integer 0 (-18 дБм) ... 3 (0 дБм, за замовчуванням) +---@field payload? integer 1-32 (за замовчуванням 32), 0 - динамічна довжина +---@field auto_ack? boolean (за замовчуванням true) +---@field retries? integer 0-15 (за замовчуванням 15) +---@field retry_delay? integer мкс, 250-4000 (за замовчуванням 1500) +---@field address_width? integer 3-5 (за замовчуванням 5) +---@field crc? integer 0, 1 або 2 байти (за замовчуванням 2) + +---@class nrf24.Radio +local Radio = {} + +---@param options? nrf24.Options +---@return nrf24.Radio|nil radio +---@return string? error +---@usage +--- local radio = assert(nrf24.new({channel = 90})) +--- radio:open_tx("1Node") +--- radio:send("ping") +function nrf24.new(options) end + +---Адреса передачі: рядок довжиною ``address_width`` або число. +---@param address string|integer +function Radio:open_tx(address) end + +---Відкриває канал прийому 0-5. Для каналів 2-5 використовується лише перший байт адреси. +---@param pipe integer +---@param address string|integer +function Radio:open_rx(pipe, address) end + +---@param pipe integer +function Radio:close_rx(pipe) end + +---Вмикає прийом. +function Radio:listen() end + +function Radio:stop_listening() end + +---Надсилає пакет до 32 байт. З ``auto_ack`` повертає ``true`` лише після підтвердження. +---@param data string|integer[] +---@param timeout_ms? integer +---@return boolean +function Radio:send(data, timeout_ms) end + +---Номер каналу, у якому є пакет, або ``nil``. +---@return integer|nil +function Radio:available() end + +---Читає пакет: дані і номер каналу, або ``nil``. +---@return string|nil data +---@return integer? pipe +function Radio:read() end + +---@param channel integer 0-125 +function Radio:set_channel(channel) end + +---``true``, якщо на поточному каналі є сигнал, сильніший за -64 дБм (у режимі прийому). +---@return boolean +function Radio:carrier() end + +---Сканує всі 126 каналів і повертає кількість "влучань" на кожному (індекс 1 = канал 0). +---@param passes? integer 1-100 (за замовчуванням 1) +---@param dwell_us? integer 130-10000 (за замовчуванням 260) +---@return integer[] +function Radio:scan(passes, dwell_us) end + +---Вимикає радіо і звільняє SPI та контакти. +function Radio:close() end + +return nrf24 diff --git a/addons/lualilka/library/serial.lua b/addons/lualilka/library/serial.lua index 7c0ea11..f4870b0 100644 --- a/addons/lualilka/library/serial.lua +++ b/addons/lualilka/library/serial.lua @@ -10,12 +10,18 @@ serial = {} --- print("Available bytes:", bytesAvailable) function serial.available() end ----Ініціалізує послідовний порт із заданими параметрами. ----@param baud integer швидкість передачі даних (за замовчуванням 115200) ----@param config integer конфігурація порту (за замовчуванням SERIAL_8N1) +---Ініціалізує послідовний порт (UART1) із заданими параметрами. +--- +---Без ``rx``/``tx`` використовуються GPIO47 (RX) і GPIO48 (TX). Модулі GPS, IR і CAN під'єднані до GPIO44 (RX) і GPIO43 (TX). +---Якщо ці контакти вже використовує інший скрипт (наприклад, сервіс), функція завершиться помилкою. +---@param baud? integer швидкість передачі даних (за замовчуванням 115200) +---@param config? integer конфігурація порту (за замовчуванням SERIAL_8N1) +---@param rx? integer GPIO для прийому (за замовчуванням 47) +---@param tx? integer GPIO для передачі (за замовчуванням 48) ---@usage --- serial.begin(9600, serial.SERIAL_8N1) -function serial.begin(baud, config) end +--- serial.begin(9600, serial.SERIAL_8N1, 44, 43) -- контакти 3 і 4 роз'єму розширення +function serial.begin(baud, config, rx, tx) end ---Зупиняє послідовний порт. ---@usage @@ -49,7 +55,7 @@ function serial.println(...) end ---Читає дані з послідовного порту. ---@param count integer максимальна кількість байтів для читання (опціонально) ----@return string|integer якщо `count` задано, повертає рядок; якщо ні — окремий байт +---@return string|integer якщо `count` задано, повертає рядок (може містити нульові байти); якщо ні — окремий байт ---@usage --- local data = serial.read(10) --- print("Data:", data) diff --git a/lib/lilka/src/lilka/config.h b/lib/lilka/src/lilka/config.h index 661b4e6..b5a4dd8 100644 --- a/lib/lilka/src/lilka/config.h +++ b/lib/lilka/src/lilka/config.h @@ -110,6 +110,9 @@ # define LILKA_P6 14 // ADC2, CH3 # define LILKA_P7 13 // ADC2, CH2 # define LILKA_P8 12 // ADC2, CH1 +// Контакти 3 і 4 роз'єму розширення (U0RXD / U0TXD) +# define LILKA_EXT_RX 44 +# define LILKA_EXT_TX 43 const uint8_t LILKA_EXT_PINS[] = {LILKA_P3, LILKA_P4, LILKA_P5, LILKA_P6, LILKA_P7, LILKA_P8}; #else diff --git a/lib/lilka_modules/README.md b/lib/lilka_modules/README.md new file mode 100644 index 0000000..feb653a --- /dev/null +++ b/lib/lilka_modules/README.md @@ -0,0 +1,29 @@ +# LilkaModules + +Drivers for the Lilka v2 extension modules ([lilka-dev/lilka_modules](https://github.com/lilka-dev)): + +| Module | Class | Bus | +|---|---|---| +| 002 IR (KY-005 + KY-022) | `lilka::mod::Ir`, `IrCodec` (NEC, Samsung, Sony SIRC) | RMT | +| 003 LORA (SX1262 / SX1268) | `lilka::mod::SX126x` | SPI | +| 004 RF (nRF24L01+) | `lilka::mod::Nrf24` | SPI | +| 004 RF (CC1101) | `lilka::mod::Cc1101` | SPI | +| 005 GPS (NEO-M8N) | `lilka::mod::Gps`, `Nmea` | UART | +| 006 GYRO MAGNET | `lilka::mod::Bmi260`, `lilka::mod::Tmag5273` | I2C | +| 008 CAN (SN65HVD232) | `lilka::mod::Can` | TWAI | + +Rules: + +- Plain classes, not singletons: create an instance when the module is plugged in, call `begin()`. + Nothing is started by `lilka::begin()`. +- Default pins come from `lilka_modules/pins.h`; every pin is a `Config` field. +- SPI and I2C drivers take the bus (`SPIClass*`, `TwoWire*`) and never start or stop it: call + `lilka::SPI2.begin(pins::SPI_SCK, pins::SPI_MISO, pins::SPI_MOSI)` / `Wire.begin(pins::I2C_SDA, pins::I2C_SCL)` first. +- `lilka::mod::resources` tracks which pins/peripherals are in use by whom (used by Keira to keep an app + and a service off each other's hardware). Drivers don't use it themselves. +- `Nmea` and `IrCodec` have no hardware access and build on a PC. + +`bmi260_config.h` is Bosch's BMI260 configuration blob (BSD-3-Clause, see `BMI260_CONFIG_LICENSE`). + +Hardware status: SX126x, nRF24 and CC1101 drivers are ported from code tested on the boards; the GPS, IR +and CAN boards haven't been tested on hardware yet. diff --git a/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino b/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino new file mode 100644 index 0000000..ef2169d --- /dev/null +++ b/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino @@ -0,0 +1,37 @@ +// Sends a LoRa beacon every 10 s and prints received packets (003 LORA module, E22-900M). +#include +#include + +using namespace lilka::mod; + +SX126x radio; + +void setup() { + lilka::begin(); + lilka::SPI2.begin(pins::SPI_SCK, pins::SPI_MISO, pins::SPI_MOSI); + SX126x::Config cfg; + cfg.spi = &lilka::SPI2; + cfg.frequencyHz = 868100000; // check what is allowed where you are + cfg.powerDbm = 0; + if (radio.begin(cfg) != SX126x::Result::OK) { + Serial.println("No SX126x found"); + return; + } + radio.startReceive(); +} + +void loop() { + static uint32_t lastTx = 0; + static uint32_t counter = 0; + SX126x::Packet packet; + if (radio.receive(packet)) { + Serial.printf("RX %.*s rssi=%.1f snr=%.1f\n", packet.length, (const char*)packet.data, packet.rssi, packet.snr); + } + if (millis() - lastTx > 10000) { + char msg[32]; + int n = snprintf(msg, sizeof(msg), "LILKA #%lu", (unsigned long)counter++); + radio.send(reinterpret_cast(msg), n); + lastTx = millis(); + } + vTaskDelay(pdMS_TO_TICKS(5)); +} diff --git a/lib/lilka_modules/library.json b/lib/lilka_modules/library.json new file mode 100644 index 0000000..7d9130c --- /dev/null +++ b/lib/lilka_modules/library.json @@ -0,0 +1,21 @@ +{ + "name": "LilkaModules", + "version": "0.1.0", + "description": "Drivers for Lilka v2 extension modules: GPS, CAN, IR, LoRa (SX126x), nRF24L01+, CC1101, BMI260, TMAG5273", + "license": "GPL-2.0", + "repository": { + "type": "git", + "url": "https://github.com/lilka-dev/sdk.git" + }, + "dependencies": { + "lilka/Lilka": "*" + }, + "homepage": "https://github.com/lilka-dev/sdk", + "frameworks": "arduino", + "platforms": "espressif32", + "include": [ + "src", + "examples", + "README.md" + ] +} diff --git a/lib/lilka_modules/src/lilka_modules.h b/lib/lilka_modules/src/lilka_modules.h new file mode 100644 index 0000000..ff2fb2f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules.h @@ -0,0 +1,19 @@ +#pragma once + +/// Драйвери модулів розширення Лілки v2. +/// +/// Кожен модуль - звичайний клас: створіть екземпляр, коли модуль потрібен, і викличте begin(). +/// Нічого не ініціалізується автоматично в lilka::begin(). + +#include "lilka_modules/pins.h" +#include "lilka_modules/resources.h" +#include "lilka_modules/nmea.h" +#include "lilka_modules/gps.h" +#include "lilka_modules/can.h" +#include "lilka_modules/ir_codec.h" +#include "lilka_modules/ir.h" +#include "lilka_modules/sx126x.h" +#include "lilka_modules/nrf24.h" +#include "lilka_modules/cc1101.h" +#include "lilka_modules/bmi260.h" +#include "lilka_modules/tmag5273.h" diff --git a/lib/lilka_modules/src/lilka_modules/BMI260_CONFIG_LICENSE b/lib/lilka_modules/src/lilka_modules/BMI260_CONFIG_LICENSE new file mode 100644 index 0000000..11a00c4 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/BMI260_CONFIG_LICENSE @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ diff --git a/lib/lilka_modules/src/lilka_modules/bmi260.cpp b/lib/lilka_modules/src/lilka_modules/bmi260.cpp new file mode 100644 index 0000000..ef66b55 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/bmi260.cpp @@ -0,0 +1,195 @@ +#include "bmi260.h" + +#include +#include +#include +#include + +#include "bmi260_config.h" + +namespace lilka { +namespace mod { + +enum : uint8_t { + REG_CHIP_ID = 0x00, + REG_ACC_X = 0x0C, + REG_INTERNAL_STATUS = 0x21, + REG_TEMP = 0x22, + REG_ACC_CONF = 0x40, + REG_ACC_RANGE = 0x41, + REG_GYR_CONF = 0x42, + REG_GYR_RANGE = 0x43, + REG_INIT_CTRL = 0x59, + REG_INIT_ADDR_0 = 0x5B, + REG_INIT_DATA = 0x5E, + REG_PWR_CONF = 0x7C, + REG_PWR_CTRL = 0x7D, + REG_CMD = 0x7E, +}; + +const uint8_t* bmi260DefaultConfig(size_t* length) { + if (length) *length = sizeof(g_bmi260_config_tbin); + return g_bmi260_config_tbin; +} + +static bool odrCode(uint16_t hz, uint8_t& code) { + static const uint16_t rates[] = {12, 25, 50, 100, 200, 400, 800, 1600, 3200}; + for (uint8_t i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) { + if (rates[i] == hz) { + code = 0x05 + i; + return true; + } + } + return false; +} + +bool Bmi260::writeRegister(uint8_t reg, const uint8_t* data, size_t n) { + cfg.wire->beginTransmission(cfg.address); + cfg.wire->write(reg); + cfg.wire->write(data, n); + return cfg.wire->endTransmission() == 0; +} + +bool Bmi260::writeRegister(uint8_t reg, uint8_t value) { + return writeRegister(reg, &value, 1); +} + +bool Bmi260::readRegister(uint8_t reg, uint8_t* data, size_t n) { + cfg.wire->beginTransmission(cfg.address); + cfg.wire->write(reg); + if (cfg.wire->endTransmission(false) != 0) return false; + if (cfg.wire->requestFrom(cfg.address, (uint8_t)n) != n) return false; + for (size_t i = 0; i < n; i++) + data[i] = cfg.wire->read(); + return true; +} + +uint8_t Bmi260::readRegister(uint8_t reg) { + uint8_t v = 0xFF; + readRegister(reg, &v, 1); + return v; +} + +uint8_t Bmi260::internalStatus() { + return readRegister(REG_INTERNAL_STATUS); +} + +bool Bmi260::loadConfig() { + writeRegister(REG_PWR_CONF, 0x00); // advanced power save off + delayMicroseconds(450); + writeRegister(REG_INIT_CTRL, 0x00); + const size_t chunk = 64; // fits the Arduino Wire buffer + for (size_t off = 0; off < cfg.blobLength; off += chunk) { + size_t n = cfg.blobLength - off < chunk ? cfg.blobLength - off : chunk; + const uint8_t a[2] = {(uint8_t)((off / 2) & 0x0F), (uint8_t)((off / 2) >> 4)}; + writeRegister(REG_INIT_ADDR_0, a, 2); + if (!writeRegister(REG_INIT_DATA, cfg.blob + off, n)) return false; + } + writeRegister(REG_INIT_CTRL, 0x01); + int64_t t0 = esp_timer_get_time(); + while (esp_timer_get_time() - t0 < 150000) { + if ((internalStatus() & 0x0F) == 0x01) return true; + vTaskDelay(pdMS_TO_TICKS(5)); + } + return false; +} + +Bmi260::Result Bmi260::begin(const Config& config) { + cfg = config; + initialized = false; + uint8_t accOdr, gyrOdr, accRange, gyrRange; + switch (cfg.accelRangeG) { + case 2: + accRange = 0; + break; + case 4: + accRange = 1; + break; + case 8: + accRange = 2; + break; + case 16: + accRange = 3; + break; + default: + return Result::InvalidParam; + } + switch (cfg.gyroRangeDps) { + case 2000: + gyrRange = 0; + break; + case 1000: + gyrRange = 1; + break; + case 500: + gyrRange = 2; + break; + case 250: + gyrRange = 3; + break; + case 125: + gyrRange = 4; + break; + default: + return Result::InvalidParam; + } + if (!odrCode(cfg.accelOdrHz, accOdr) || accOdr > 0x0C || !odrCode(cfg.gyroOdrHz, gyrOdr) || gyrOdr < 0x06) { + return Result::InvalidParam; + } + + if (cfg.address == 0) { + for (uint8_t a : {0x68, 0x69}) { + cfg.address = a; + if (readRegister(REG_CHIP_ID) == CHIP_ID) break; + cfg.address = 0; + } + if (!cfg.address) return Result::NoChip; + } else if (readRegister(REG_CHIP_ID) != CHIP_ID) { + return Result::NoChip; + } + + writeRegister(REG_CMD, 0xB6); // soft reset + vTaskDelay(pdMS_TO_TICKS(2)); + readRegister(REG_CHIP_ID); // dummy read after reset + + if (cfg.blob && cfg.blobLength) { + if (!loadConfig()) return Result::ConfigFailed; + initialized = true; + } else { + writeRegister(REG_PWR_CONF, 0x00); + delayMicroseconds(450); + } + + writeRegister(REG_PWR_CTRL, 0x0E); // acc + gyr + temp on + writeRegister(REG_ACC_CONF, 0xA0 | accOdr); + writeRegister(REG_ACC_RANGE, accRange); + writeRegister(REG_GYR_CONF, 0xA0 | gyrOdr); + writeRegister(REG_GYR_RANGE, gyrRange); + accelScale = cfg.accelRangeG / 32768.0f; + gyroScale = cfg.gyroRangeDps / 32768.0f; + vTaskDelay(pdMS_TO_TICKS(50)); + return Result::OK; +} + +bool Bmi260::read(Data& d) { + uint8_t b[12]; + if (!readRegister(REG_ACC_X, b, 12)) return false; + auto s16 = [&](int i) { return (int16_t)(b[i] | (b[i + 1] << 8)); }; + d.ax = s16(0) * accelScale; + d.ay = s16(2) * accelScale; + d.az = s16(4) * accelScale; + d.gx = s16(6) * gyroScale; + d.gy = s16(8) * gyroScale; + d.gz = s16(10) * gyroScale; + return true; +} + +float Bmi260::temperature() { + uint8_t b[2] = {}; + readRegister(REG_TEMP, b, 2); + int16_t t = (int16_t)(b[0] | (b[1] << 8)); + return t / 512.0f + 23.0f; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/bmi260.h b/lib/lilka_modules/src/lilka_modules/bmi260.h new file mode 100644 index 0000000..ebf78e6 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/bmi260.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include + +namespace lilka { +namespace mod { + +/// Акселерометр і гіроскоп Bosch BMI260 (модуль 006 GYRO MAGNET). +/// +/// Шина I2C має бути вже запущена. Для повноцінної роботи чипу потрібен конфігураційний блоб (8 КБ): +/// його можна взяти з bmi260_config.h (bmi260DefaultConfig()) або завантажити з файлу. +class Bmi260 { +public: + static constexpr uint8_t CHIP_ID = 0x27; + + struct Config { + TwoWire* wire = &Wire; + uint8_t address = 0; ///< 0 - знайти автоматично (0x68 або 0x69) + const uint8_t* blob = nullptr; ///< nullptr - не завантажувати конфігурацію + size_t blobLength = 0; + uint8_t accelRangeG = 8; ///< 2, 4, 8, 16 + uint16_t gyroRangeDps = 2000; ///< 125, 250, 500, 1000, 2000 + uint16_t accelOdrHz = 100; ///< 12 (12.5), 25, 50, 100, 200, 400, 800, 1600 + uint16_t gyroOdrHz = 200; ///< 25 ... 3200 + }; + + struct Data { + float ax, ay, az; ///< g + float gx, gy, gz; ///< °/с + }; + + enum class Result { + OK, + NoChip, + ConfigFailed, ///< блоб не прийнятий (INTERNAL_STATUS != init_ok) + InvalidParam, + }; + + Result begin(const Config& config); + bool read(Data& data); + float temperature(); + /// Блоб завантажено і чип повідомив init_ok. + bool isInitialized() const { + return initialized; + } + uint8_t address() const { + return cfg.address; + } + uint8_t internalStatus(); + +private: + bool writeRegister(uint8_t reg, const uint8_t* data, size_t n); + bool writeRegister(uint8_t reg, uint8_t value); + bool readRegister(uint8_t reg, uint8_t* data, size_t n); + uint8_t readRegister(uint8_t reg); + bool loadConfig(); + + Config cfg; + bool initialized = false; + float accelScale = 1, gyroScale = 1; +}; + +/// Вбудований конфігураційний блоб Bosch (BSD-3-Clause, див. BMI260_CONFIG_LICENSE). +const uint8_t* bmi260DefaultConfig(size_t* length); + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/bmi260_config.h b/lib/lilka_modules/src/lilka_modules/bmi260_config.h new file mode 100644 index 0000000..53e65b6 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/bmi260_config.h @@ -0,0 +1,702 @@ +/* + * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the BMI260_CONFIG_LICENSE file. + * + * @file accelgyro_bmi260_config_tbin.c + * @date 2020-01-10 + * @version v2.46.1 + * + */ + +#pragma once +#include + +// clang-format off +static const uint8_t g_bmi260_config_tbin[8192] = { + 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x63, 0xb3, 0xc8, 0x2e, 0x00, 0x2e, + 0x80, 0x2e, 0x15, 0x03, 0x80, 0x2e, 0xbb, 0xb4, 0x80, 0x2e, 0x91, 0x03, + 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0xe7, 0xb3, 0x50, 0x30, 0x21, 0x2e, + 0x59, 0xf5, 0x10, 0x30, 0x21, 0x2e, 0x4a, 0xf1, 0x21, 0x2e, 0x6a, 0xf5, + 0x80, 0x2e, 0xe0, 0x01, 0x0d, 0x0d, 0x01, 0x00, 0x22, 0x00, 0x76, 0x00, + 0x00, 0x10, 0x00, 0x10, 0xc8, 0x00, 0x01, 0x1c, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0xfd, 0x2d, 0xe4, 0x78, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0d, 0x00, 0x00, + 0x88, 0x00, 0x05, 0xe0, 0xaa, 0x38, 0x05, 0xe0, 0x90, 0x30, 0x86, 0x00, + 0x30, 0x0a, 0x80, 0x40, 0x10, 0x27, 0xe8, 0x73, 0x04, 0x30, 0x00, 0x02, + 0x00, 0x01, 0x00, 0x30, 0x10, 0x0b, 0x09, 0x08, 0xfa, 0x00, 0x96, 0x00, + 0x4b, 0x09, 0x11, 0x00, 0x11, 0x00, 0x02, 0x00, 0x00, 0x00, 0x22, 0x07, + 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, 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, 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x01, + 0xe6, 0x78, 0x84, 0x00, 0x9c, 0x6c, 0x07, 0x00, 0x64, 0x75, 0xaa, 0x7e, + 0x5f, 0x05, 0xbe, 0x0a, 0x5f, 0x05, 0x96, 0xe8, 0xef, 0x41, 0x01, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x4a, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0xf0, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xa1, 0x01, 0x8f, 0x01, + 0x9d, 0x01, 0x8b, 0x01, 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x04, 0xc0, 0x00, + 0x5b, 0xf5, 0x74, 0x01, 0x1e, 0xf2, 0xfd, 0xf5, 0xfc, 0xf5, 0x6f, 0x01, + 0x77, 0x01, 0x80, 0x00, 0xa0, 0x00, 0x5f, 0xff, 0x00, 0x08, 0x00, 0xf8, + 0x7a, 0x01, 0x85, 0x01, 0x7f, 0x01, 0x84, 0x01, 0x4c, 0x04, 0xe8, 0x03, + 0xff, 0x7f, 0xb8, 0x7e, 0xe1, 0x7a, 0x81, 0x01, 0x7c, 0x01, 0x7e, 0x01, + 0xc8, 0x00, 0xcb, 0x00, 0xcb, 0x00, 0xd2, 0x00, 0x88, 0x01, 0x69, 0xf5, + 0xe0, 0x00, 0x3f, 0xff, 0x19, 0xf4, 0x58, 0xf5, 0x66, 0xf5, 0x64, 0xf5, + 0xc0, 0xf1, 0xba, 0xf1, 0xa0, 0x00, 0xa6, 0x01, 0xf7, 0x00, 0xf9, 0x00, + 0xb7, 0x01, 0xff, 0x3f, 0xff, 0xfb, 0x00, 0x38, 0x00, 0x30, 0xb8, 0x01, + 0xbf, 0x01, 0xc1, 0x01, 0xc7, 0x01, 0xcf, 0x01, 0xff, 0x01, 0x95, 0x01, + 0x74, 0xf7, 0x00, 0x40, 0xff, 0x00, 0x00, 0x80, 0x7c, 0x0f, 0xeb, 0x00, + 0x7f, 0xff, 0xc2, 0xf5, 0x68, 0xf7, 0xb3, 0xf1, 0x76, 0x0f, 0x6a, 0x0f, + 0x70, 0x0f, 0x8f, 0x0f, 0x58, 0xf7, 0x5b, 0xf7, 0x92, 0x0f, 0x86, 0x00, + 0x81, 0x0f, 0x94, 0x0f, 0xc6, 0xf1, 0x8e, 0x0f, 0x6c, 0xf7, 0x00, 0xe0, + 0x00, 0xff, 0xd1, 0xf5, 0x96, 0x0f, 0x99, 0x0f, 0xff, 0x03, 0x00, 0xfc, + 0xf0, 0x3f, 0x8b, 0x00, 0x90, 0x00, 0x8f, 0x00, 0x95, 0x00, 0x92, 0x00, + 0x98, 0x00, 0x8d, 0x00, 0xa2, 0x00, 0xb9, 0x00, 0x2d, 0xf5, 0xca, 0xf5, + 0x75, 0x01, 0x20, 0xf2, 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, + 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, 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, 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, + 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, 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, 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1a, 0x24, 0x22, 0x00, 0x80, 0x2e, 0x00, 0xb0, 0x17, 0x52, 0x00, 0x2e, + 0x60, 0x40, 0x41, 0x40, 0x0d, 0xbc, 0x98, 0xbc, 0xc0, 0x2e, 0x01, 0x0a, + 0x0f, 0xb8, 0x19, 0x52, 0x53, 0x3c, 0x52, 0x40, 0x40, 0x40, 0x4b, 0x00, + 0x82, 0x16, 0x26, 0xb9, 0x01, 0xb8, 0x41, 0x40, 0x10, 0x08, 0x97, 0xb8, + 0x01, 0x08, 0xc0, 0x2e, 0x11, 0x30, 0x01, 0x08, 0x43, 0x86, 0x25, 0x40, + 0x04, 0x40, 0xd8, 0xbe, 0x2c, 0x0b, 0x22, 0x11, 0x54, 0x42, 0x03, 0x80, + 0x4b, 0x0e, 0xf6, 0x2f, 0xb8, 0x2e, 0x1b, 0x50, 0x10, 0x50, 0x1d, 0x52, + 0x05, 0x2e, 0xd5, 0x00, 0xfb, 0x7f, 0x00, 0x2e, 0x13, 0x40, 0x93, 0x42, + 0x41, 0x0e, 0xfb, 0x2f, 0x98, 0x2e, 0x0b, 0x03, 0x98, 0x2e, 0x87, 0xcf, + 0x01, 0x2e, 0x6e, 0x01, 0x00, 0xb2, 0xfb, 0x6f, 0x0b, 0x2f, 0x01, 0x2e, + 0x69, 0xf7, 0xb1, 0x3f, 0x01, 0x08, 0x01, 0x30, 0xf0, 0x5f, 0x23, 0x2e, + 0x6e, 0x01, 0x21, 0x2e, 0x69, 0xf7, 0x80, 0x2e, 0x29, 0x02, 0xf0, 0x5f, + 0xb8, 0x2e, 0x01, 0x2e, 0xc0, 0xf8, 0x03, 0x2e, 0xfc, 0xf5, 0x1f, 0x54, + 0x21, 0x56, 0x82, 0x08, 0x0b, 0x2e, 0x69, 0xf7, 0xcb, 0x0a, 0x23, 0x58, + 0x80, 0x90, 0xdd, 0xbe, 0x4c, 0x08, 0x5f, 0xb9, 0x59, 0x22, 0x80, 0x90, + 0x07, 0x2f, 0x03, 0x34, 0xc3, 0x08, 0xf2, 0x3a, 0x0a, 0x08, 0x02, 0x35, + 0xc0, 0x90, 0x4a, 0x0a, 0x48, 0x22, 0xc0, 0x2e, 0x23, 0x2e, 0xfc, 0xf5, + 0x03, 0x2e, 0x77, 0x01, 0x43, 0x40, 0xbf, 0xbc, 0x37, 0xbc, 0x30, 0x50, + 0x40, 0xb2, 0x0c, 0xb8, 0xe0, 0x7f, 0xfb, 0x7f, 0x01, 0x30, 0x23, 0x2f, + 0x01, 0x2e, 0x7c, 0x00, 0x00, 0xb2, 0x04, 0x2f, 0x04, 0x30, 0x98, 0x2e, + 0x7f, 0x02, 0x29, 0x2e, 0x7c, 0x00, 0x3b, 0xbc, 0xbc, 0xbc, 0x0f, 0xb8, + 0x9d, 0xb8, 0x23, 0x2e, 0x78, 0x01, 0xd0, 0x7f, 0x98, 0x2e, 0x77, 0xb1, + 0x10, 0x25, 0xd0, 0x6f, 0x00, 0x90, 0x06, 0x2f, 0xfb, 0x6f, 0xe0, 0x6f, + 0x22, 0x30, 0xd0, 0x5f, 0x4a, 0x08, 0x80, 0x2e, 0x95, 0xcf, 0xfb, 0x6f, + 0xe0, 0x6f, 0x12, 0x30, 0xd0, 0x5f, 0x4a, 0x08, 0x80, 0x2e, 0x95, 0xcf, + 0xe0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0x11, 0x30, 0x23, 0x2e, 0x7c, 0x00, + 0xfb, 0x6f, 0xd0, 0x5f, 0xb8, 0x2e, 0x29, 0x50, 0x25, 0x52, 0x11, 0x42, + 0x00, 0x2e, 0x27, 0x52, 0x01, 0x42, 0x01, 0x30, 0x2b, 0x54, 0x11, 0x42, + 0x42, 0x0e, 0xfc, 0x2f, 0xb8, 0x2e, 0x2d, 0x54, 0x00, 0x2e, 0x83, 0x40, + 0xbd, 0x84, 0x18, 0x1a, 0x80, 0x40, 0x13, 0x2f, 0xc0, 0x90, 0x22, 0x2f, + 0x03, 0x35, 0x03, 0x0f, 0x0a, 0x2f, 0x09, 0x2e, 0x7e, 0x01, 0x00, 0xb3, + 0x01, 0x2f, 0x04, 0xa8, 0x04, 0x2f, 0x00, 0x30, 0x80, 0x42, 0x21, 0x2e, + 0x7f, 0x01, 0xb8, 0x2e, 0x83, 0x42, 0xc0, 0x2e, 0x23, 0x2e, 0x7f, 0x01, + 0x02, 0x35, 0x82, 0x0e, 0x0d, 0x2f, 0x03, 0x3b, 0x03, 0x00, 0x0c, 0xa8, + 0x09, 0x2f, 0x2f, 0x58, 0x3b, 0x81, 0x3d, 0x86, 0x04, 0x41, 0xc2, 0x42, + 0xc8, 0x84, 0x01, 0x87, 0x01, 0x42, 0x83, 0x42, 0xb8, 0x2e, 0xb8, 0x2e, + 0x01, 0x2e, 0x86, 0x01, 0x01, 0x86, 0x13, 0x25, 0xd2, 0x40, 0x50, 0x50, + 0xc3, 0x40, 0x23, 0xbd, 0x2f, 0xb9, 0xbc, 0xb9, 0xfb, 0x7f, 0x80, 0xb2, + 0xe3, 0x7f, 0x0b, 0x30, 0x39, 0x2f, 0x05, 0x2e, 0x7e, 0x00, 0x80, 0x90, + 0x04, 0x2f, 0x81, 0x84, 0x25, 0x2e, 0x7e, 0x00, 0x37, 0x2e, 0x7f, 0x00, + 0x41, 0x40, 0x02, 0x40, 0x02, 0x80, 0x94, 0xbc, 0x94, 0xb9, 0x00, 0x40, + 0x04, 0xbc, 0x21, 0xbd, 0x04, 0xb8, 0x21, 0xb9, 0x07, 0x52, 0xd3, 0x7f, + 0xc2, 0x7f, 0xb0, 0x7f, 0x98, 0x2e, 0xb3, 0xc0, 0xd1, 0x6f, 0xc2, 0x6f, + 0x51, 0x28, 0x41, 0x0f, 0x11, 0x30, 0x0d, 0x2f, 0xc2, 0x0e, 0x07, 0x2e, + 0x7f, 0x00, 0x19, 0x28, 0x04, 0x2f, 0xc0, 0xa6, 0x04, 0x2f, 0x21, 0x2e, + 0x7f, 0x00, 0x02, 0x2d, 0x21, 0x2e, 0x7f, 0x00, 0x04, 0x2c, 0x02, 0x30, + 0x02, 0x30, 0x25, 0x2e, 0x7f, 0x00, 0xb0, 0x6f, 0x07, 0x2e, 0x7f, 0x00, + 0x58, 0x0f, 0xfb, 0x6f, 0xe0, 0x6f, 0xb0, 0x5f, 0x4a, 0x22, 0x80, 0x2e, + 0x95, 0xcf, 0xe0, 0x6f, 0x01, 0x30, 0x98, 0x2e, 0x95, 0xcf, 0x00, 0x30, + 0x21, 0x2e, 0x7e, 0x00, 0xfb, 0x6f, 0xb0, 0x5f, 0xb8, 0x2e, 0x03, 0x2e, + 0xd5, 0x00, 0x16, 0xb8, 0x02, 0x34, 0x4a, 0x0c, 0x21, 0x2e, 0x2d, 0xf5, + 0xc0, 0x2e, 0x23, 0x2e, 0xd5, 0x00, 0x20, 0x50, 0xf6, 0x7f, 0xe7, 0x7f, + 0x00, 0x2e, 0x4b, 0x5c, 0x00, 0x2e, 0x87, 0x41, 0xff, 0xbf, 0xff, 0xbb, + 0xc0, 0x91, 0x02, 0x2f, 0x37, 0x30, 0x2f, 0x2e, 0x69, 0xf5, 0xb8, 0x8f, + 0x06, 0x32, 0xc7, 0x41, 0xfe, 0x09, 0xc0, 0xb3, 0x04, 0x2f, 0x17, 0x30, + 0x2f, 0x2e, 0x9c, 0x01, 0x2d, 0x2e, 0x61, 0xf5, 0xf6, 0x6f, 0xe7, 0x6f, + 0xe0, 0x5f, 0xc8, 0x2e, 0x10, 0x50, 0xfb, 0x7f, 0x98, 0x2e, 0x56, 0xc7, + 0x98, 0x2e, 0x49, 0xc3, 0x00, 0x30, 0xfb, 0x6f, 0xf0, 0x5f, 0x21, 0x2e, + 0x7e, 0x00, 0x21, 0x2e, 0xce, 0x00, 0xb8, 0x2e, 0x21, 0x2e, 0x59, 0xf5, + 0x10, 0x30, 0xc0, 0x2e, 0x21, 0x2e, 0x4a, 0xf1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x9a, 0x01, 0x34, 0x03, 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, 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, + 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, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x30, 0x50, 0xe5, 0x7f, 0xf6, 0x7f, 0xd7, 0x7f, 0x00, 0x2e, + 0x4b, 0x5a, 0x00, 0x2e, 0x46, 0x41, 0x6f, 0xbf, 0x6f, 0xbb, 0x80, 0x91, + 0x02, 0x2f, 0x36, 0x30, 0x2d, 0x2e, 0x69, 0xf5, 0x46, 0x30, 0x0f, 0x2e, + 0xa4, 0xf1, 0xbe, 0x09, 0x77, 0x8b, 0x80, 0xb3, 0x06, 0x2f, 0x0d, 0x2e, + 0xff, 0x00, 0x84, 0xaf, 0x02, 0x2f, 0x16, 0x30, 0x2d, 0x2e, 0xdc, 0x00, + 0x86, 0x30, 0x46, 0x43, 0x00, 0x2e, 0xf6, 0x6f, 0xe5, 0x6f, 0xd7, 0x6f, + 0xd0, 0x5f, 0xc8, 0x2e, 0x03, 0x2e, 0x9f, 0x00, 0x1b, 0xbc, 0x60, 0x50, + 0x9f, 0xbc, 0x0c, 0xb8, 0xf0, 0x7f, 0x40, 0xb2, 0xeb, 0x7f, 0x2b, 0x2f, + 0x03, 0x2e, 0xfc, 0x00, 0x41, 0x40, 0x01, 0x2e, 0xfd, 0x00, 0x01, 0x1a, + 0x11, 0x2f, 0x71, 0x58, 0x23, 0x2e, 0xfd, 0x00, 0x10, 0x41, 0xa0, 0x7f, + 0x38, 0x81, 0x01, 0x41, 0xd0, 0x7f, 0xb1, 0x7f, 0x98, 0x2e, 0x64, 0xcf, + 0xd0, 0x6f, 0x07, 0x80, 0xa1, 0x6f, 0x11, 0x42, 0x00, 0x2e, 0xb1, 0x6f, + 0x01, 0x42, 0x11, 0x30, 0x01, 0x2e, 0xb7, 0x01, 0x00, 0xa8, 0x03, 0x30, + 0xcb, 0x22, 0x4a, 0x25, 0x01, 0x2e, 0xfc, 0x00, 0x3c, 0x89, 0x6f, 0x52, + 0x07, 0x54, 0x98, 0x2e, 0xc4, 0xce, 0xc1, 0x6f, 0xf0, 0x6f, 0x98, 0x2e, + 0x95, 0xcf, 0x04, 0x2d, 0x01, 0x30, 0xf0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, + 0xeb, 0x6f, 0xa0, 0x5f, 0xb8, 0x2e, 0x11, 0x30, 0x81, 0x08, 0x01, 0x2e, + 0x6a, 0xf7, 0x71, 0x3f, 0x23, 0xbd, 0x01, 0x08, 0x02, 0x0a, 0xc0, 0x2e, + 0x21, 0x2e, 0x6a, 0xf7, 0x80, 0x2e, 0x00, 0xc1, 0x30, 0x50, 0x98, 0x2e, + 0xd7, 0x0e, 0x50, 0x32, 0x98, 0x2e, 0x40, 0x03, 0x00, 0x30, 0xf0, 0x7f, + 0x21, 0x2e, 0x69, 0xf5, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x00, 0x2e, + 0x01, 0x80, 0x08, 0xa2, 0xfb, 0x2f, 0x03, 0x2e, 0x8f, 0x00, 0x01, 0x2e, + 0x93, 0x00, 0x9f, 0xbc, 0x9f, 0xb8, 0x0f, 0xb8, 0x08, 0x0a, 0x21, 0x2e, + 0x79, 0x00, 0x98, 0x2e, 0xab, 0xb6, 0x03, 0x2e, 0xa4, 0x01, 0x21, 0x2e, + 0x7a, 0x00, 0x40, 0xb2, 0x10, 0x2f, 0x01, 0x2e, 0x79, 0x00, 0x00, 0xb2, + 0x0c, 0x2f, 0x05, 0x2e, 0x8a, 0x00, 0x01, 0x52, 0x98, 0x2e, 0xc7, 0xc1, + 0xf0, 0x7f, 0x98, 0x2e, 0x46, 0x02, 0x98, 0x2e, 0x34, 0xb2, 0x10, 0x30, + 0x21, 0x2e, 0x7b, 0x00, 0x01, 0x2e, 0xa0, 0x01, 0x00, 0xb2, 0x07, 0x2f, + 0x01, 0x2e, 0x7a, 0x00, 0x00, 0xb2, 0x03, 0x2f, 0x03, 0x50, 0x05, 0x52, + 0x98, 0x2e, 0x07, 0xcc, 0x01, 0x2e, 0x8e, 0x01, 0x00, 0xb2, 0x2c, 0x2f, + 0x05, 0x2e, 0x8a, 0x00, 0x07, 0x52, 0x98, 0x2e, 0xc7, 0xc1, 0x03, 0x2e, + 0x9a, 0x01, 0x40, 0xb2, 0xf0, 0x7f, 0x08, 0x2f, 0x01, 0x2e, 0x7a, 0x00, + 0x00, 0xb2, 0x04, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0x9a, 0x01, 0x98, 0x2e, + 0x48, 0xb6, 0x01, 0x2e, 0x78, 0x00, 0x00, 0xb2, 0x15, 0x2f, 0x98, 0x2e, + 0x81, 0xb5, 0x98, 0x2e, 0xb6, 0x03, 0x07, 0x50, 0x98, 0x2e, 0x4d, 0xc3, + 0x07, 0x50, 0x98, 0x2e, 0x5a, 0xc7, 0x98, 0x2e, 0xb8, 0x02, 0x07, 0x52, + 0x98, 0x2e, 0xff, 0xc5, 0x21, 0x2e, 0x72, 0x01, 0x98, 0x2e, 0xe6, 0xb2, + 0x10, 0x30, 0x21, 0x2e, 0x7b, 0x00, 0x01, 0x2e, 0x9c, 0x01, 0x00, 0xb2, + 0x04, 0x2f, 0x98, 0x2e, 0x29, 0x02, 0x00, 0x30, 0x21, 0x2e, 0x9c, 0x01, + 0x01, 0x2e, 0xff, 0x00, 0x04, 0xae, 0x0b, 0x2f, 0x01, 0x2e, 0x8e, 0x01, + 0x00, 0xb2, 0x07, 0x2f, 0x07, 0x52, 0x98, 0x2e, 0x8e, 0x0e, 0x00, 0xb2, + 0x02, 0x2f, 0x10, 0x30, 0x21, 0x2e, 0xd7, 0x00, 0x01, 0x2e, 0xd7, 0x00, + 0x00, 0x90, 0x90, 0x2e, 0x2b, 0xb1, 0x01, 0x2e, 0x6c, 0x01, 0x00, 0xb2, + 0x04, 0x2f, 0x98, 0x2e, 0x2f, 0x0e, 0x00, 0x30, 0x21, 0x2e, 0xdc, 0x00, + 0x01, 0x2e, 0xdc, 0x00, 0x00, 0xb2, 0x12, 0x2f, 0x01, 0x2e, 0xff, 0x00, + 0x00, 0x90, 0x02, 0x2f, 0x98, 0x2e, 0x1f, 0x0e, 0x09, 0x2d, 0x98, 0x2e, + 0x81, 0x0d, 0x01, 0x2e, 0xff, 0x00, 0x04, 0x90, 0x02, 0x2f, 0x50, 0x32, + 0x98, 0x2e, 0x40, 0x03, 0x00, 0x30, 0x21, 0x2e, 0xdc, 0x00, 0x01, 0x2e, + 0xd6, 0x00, 0x00, 0xb2, 0x90, 0x2e, 0x43, 0xb1, 0x01, 0x2e, 0xd6, 0x00, + 0x01, 0x31, 0x01, 0x08, 0x00, 0xb2, 0x04, 0x2f, 0x98, 0x2e, 0x47, 0xcb, + 0x10, 0x30, 0x21, 0x2e, 0x7b, 0x00, 0x81, 0x30, 0x01, 0x2e, 0xd6, 0x00, + 0x01, 0x08, 0x00, 0xb2, 0x61, 0x2f, 0x03, 0x2e, 0x89, 0x00, 0x01, 0x2e, + 0xff, 0x00, 0x98, 0xbc, 0x98, 0xb8, 0x05, 0xb2, 0x11, 0x58, 0x23, 0x2f, + 0x07, 0x90, 0x0b, 0x54, 0x00, 0x30, 0x37, 0x2f, 0x15, 0x41, 0x04, 0x41, + 0xdc, 0xbe, 0x44, 0xbe, 0xdc, 0xba, 0x2c, 0x01, 0x61, 0x00, 0x11, 0x56, + 0x4a, 0x0f, 0x0c, 0x2f, 0xd1, 0x42, 0x94, 0xb8, 0xc1, 0x42, 0x11, 0x30, + 0x05, 0x2e, 0x6a, 0xf7, 0x2c, 0xbd, 0x2f, 0xb9, 0x80, 0xb2, 0x08, 0x22, + 0x98, 0x2e, 0xf3, 0x03, 0x21, 0x2d, 0x61, 0x30, 0x23, 0x2e, 0xff, 0x00, + 0x98, 0x2e, 0xf3, 0x03, 0x00, 0x30, 0x21, 0x2e, 0x5a, 0xf5, 0x18, 0x2d, + 0xe1, 0x7f, 0x50, 0x30, 0x98, 0x2e, 0x40, 0x03, 0x11, 0x52, 0x09, 0x50, + 0x50, 0x42, 0x70, 0x30, 0x0f, 0x54, 0x42, 0x42, 0x7e, 0x82, 0xe2, 0x6f, + 0x80, 0xb2, 0x42, 0x42, 0x05, 0x2f, 0x21, 0x2e, 0xff, 0x00, 0x10, 0x30, + 0x98, 0x2e, 0xf3, 0x03, 0x03, 0x2d, 0x60, 0x30, 0x21, 0x2e, 0xff, 0x00, + 0x01, 0x2e, 0xff, 0x00, 0x06, 0x90, 0x18, 0x2f, 0x01, 0x2e, 0x77, 0x00, + 0x0d, 0x54, 0x09, 0x52, 0xe0, 0x7f, 0x98, 0x2e, 0x7a, 0xc1, 0xe1, 0x6f, + 0x08, 0x1a, 0x40, 0x30, 0x08, 0x2f, 0x21, 0x2e, 0xff, 0x00, 0x20, 0x30, + 0x98, 0x2e, 0xe4, 0xb6, 0x50, 0x32, 0x98, 0x2e, 0x40, 0x03, 0x05, 0x2d, + 0x98, 0x2e, 0x38, 0x0e, 0x00, 0x30, 0x21, 0x2e, 0xff, 0x00, 0x00, 0x30, + 0x21, 0x2e, 0xd6, 0x00, 0x18, 0x2d, 0x01, 0x2e, 0xff, 0x00, 0x03, 0xaa, + 0x01, 0x2f, 0x98, 0x2e, 0x45, 0x0e, 0x01, 0x2e, 0xff, 0x00, 0x3f, 0x80, + 0x03, 0xa2, 0x01, 0x2f, 0x00, 0x2e, 0x02, 0x2d, 0x98, 0x2e, 0x5b, 0x0e, + 0x30, 0x30, 0x98, 0x2e, 0xf8, 0xb6, 0x00, 0x30, 0x21, 0x2e, 0xd7, 0x00, + 0x50, 0x32, 0x98, 0x2e, 0x40, 0x03, 0x01, 0x2e, 0x7b, 0x00, 0x00, 0xb2, + 0x24, 0x2f, 0x98, 0x2e, 0xf5, 0xcb, 0x03, 0x2e, 0x6a, 0x01, 0x13, 0x54, + 0x01, 0x0a, 0xbb, 0x84, 0x83, 0x86, 0x21, 0x2e, 0x74, 0x01, 0xe0, 0x40, + 0x15, 0x52, 0xc4, 0x40, 0x82, 0x40, 0xa8, 0xb9, 0x52, 0x42, 0x43, 0xbe, + 0x53, 0x42, 0x04, 0x0a, 0x50, 0x42, 0xe1, 0x7f, 0xf0, 0x31, 0x41, 0x40, + 0xf2, 0x6f, 0x25, 0xbd, 0x08, 0x08, 0x02, 0x0a, 0xd0, 0x7f, 0x98, 0x2e, + 0xa8, 0xcf, 0x06, 0xbc, 0xd1, 0x6f, 0xe2, 0x6f, 0x08, 0x0a, 0x80, 0x42, + 0x98, 0x2e, 0x07, 0x02, 0x00, 0x30, 0x21, 0x2e, 0xa4, 0x01, 0x21, 0x2e, + 0xa0, 0x01, 0x21, 0x2e, 0x7b, 0x00, 0x21, 0x2e, 0x8e, 0x01, 0x80, 0x2e, + 0x08, 0xb0, 0x70, 0x50, 0x0b, 0x2e, 0xa3, 0x01, 0x21, 0x50, 0x03, 0x2e, + 0x78, 0x01, 0x08, 0x18, 0x3b, 0x54, 0x31, 0x50, 0x94, 0x40, 0x30, 0x00, + 0x33, 0x52, 0xf0, 0x7f, 0x01, 0x00, 0x4c, 0x16, 0x2c, 0x05, 0xe2, 0x7f, + 0xcd, 0x16, 0x59, 0x07, 0x97, 0x40, 0xd2, 0x7f, 0x67, 0x04, 0x82, 0x40, + 0x35, 0x56, 0xab, 0x7f, 0xc4, 0x7f, 0x90, 0x7f, 0xb5, 0x7f, 0xaa, 0x06, + 0x98, 0x2e, 0x0c, 0xc1, 0x50, 0x25, 0xd0, 0x6f, 0xbb, 0x6f, 0x0b, 0x42, + 0x3e, 0x80, 0xcb, 0x6f, 0x3b, 0x84, 0xe1, 0x6f, 0x83, 0x40, 0x4b, 0x42, + 0xc1, 0x86, 0x03, 0x2e, 0xa3, 0x01, 0x83, 0x42, 0x82, 0x84, 0x01, 0x42, + 0xbc, 0x8e, 0x80, 0x40, 0x00, 0xb2, 0x04, 0x2f, 0x03, 0x2e, 0x7d, 0x01, + 0x41, 0x82, 0x23, 0x2e, 0x7d, 0x01, 0x67, 0x25, 0xe2, 0x41, 0x2a, 0x0f, + 0x92, 0x6f, 0xc1, 0x41, 0xe7, 0x7f, 0x37, 0x2f, 0x07, 0x2e, 0x7b, 0x01, + 0x2b, 0x0e, 0x29, 0x2f, 0x3d, 0x52, 0x02, 0x35, 0x41, 0x40, 0x8a, 0x0e, + 0x03, 0x30, 0x03, 0x2f, 0x05, 0x2e, 0x7f, 0x01, 0x80, 0xb2, 0x1b, 0x2f, + 0xc2, 0x35, 0x8a, 0x0e, 0x2f, 0x2f, 0x2f, 0x54, 0x01, 0x30, 0x83, 0x40, + 0xff, 0x86, 0xc3, 0xa2, 0x02, 0x2f, 0x00, 0x2e, 0x0c, 0x2c, 0x03, 0x30, + 0x00, 0x90, 0x01, 0x2f, 0x23, 0x2e, 0x7d, 0x01, 0x3d, 0x56, 0xc2, 0x86, + 0x01, 0x80, 0xc0, 0x42, 0x23, 0x2e, 0x7c, 0x01, 0x13, 0x30, 0xbb, 0x80, + 0x23, 0x2e, 0x84, 0x01, 0x18, 0x2c, 0x01, 0x42, 0x00, 0x35, 0x21, 0x2e, + 0x7c, 0x01, 0x13, 0x2d, 0x0a, 0x04, 0x28, 0x1e, 0x21, 0x2e, 0x7b, 0x01, + 0x10, 0x30, 0x21, 0x30, 0x98, 0x2e, 0x8b, 0x02, 0x0a, 0x2c, 0x03, 0x30, + 0x0a, 0x00, 0x28, 0x1c, 0x21, 0x2e, 0x7a, 0x01, 0x20, 0x30, 0x11, 0x30, + 0x98, 0x2e, 0x8b, 0x02, 0x03, 0x30, 0xc3, 0x7f, 0xd6, 0x7f, 0x25, 0x25, + 0x37, 0x52, 0xe0, 0x6f, 0x98, 0x2e, 0x0c, 0xb7, 0xe1, 0x6f, 0xd0, 0x6f, + 0x42, 0x40, 0x39, 0x52, 0x98, 0x2e, 0x0c, 0xb7, 0xe1, 0x6f, 0xd0, 0x6f, + 0x42, 0x40, 0x01, 0x40, 0xf3, 0x6f, 0xd3, 0x00, 0xcb, 0x1e, 0x39, 0x52, + 0x13, 0x42, 0xe0, 0x7f, 0x98, 0x2e, 0x0c, 0xb7, 0xe0, 0x6f, 0x3e, 0x84, + 0xf1, 0x6f, 0x82, 0x40, 0x03, 0x40, 0x51, 0x04, 0x59, 0x1c, 0x01, 0x42, + 0x03, 0x82, 0x00, 0x30, 0x42, 0x40, 0x80, 0xb2, 0x12, 0x2f, 0xc1, 0x6f, + 0x40, 0x90, 0x10, 0x22, 0x82, 0xac, 0x01, 0x30, 0x04, 0x2f, 0x05, 0x2e, + 0x7d, 0x01, 0x03, 0x35, 0x13, 0x0e, 0x07, 0x2f, 0x3f, 0x54, 0x86, 0x88, + 0x39, 0x87, 0x01, 0x43, 0xc1, 0x42, 0xc2, 0x86, 0x81, 0x42, 0xc1, 0x42, + 0x00, 0x2e, 0xab, 0x6f, 0x90, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0x85, 0x01, + 0x01, 0x80, 0xf0, 0x50, 0x02, 0x40, 0x04, 0x40, 0x1a, 0x25, 0xa3, 0xbe, + 0x03, 0x40, 0x71, 0x82, 0x12, 0x40, 0xdf, 0xba, 0x42, 0xbe, 0x45, 0x42, + 0x4f, 0xba, 0xb1, 0xbd, 0x00, 0x40, 0xf1, 0x7f, 0xbf, 0xb8, 0x2f, 0xb9, + 0x0c, 0xb8, 0x24, 0x7f, 0xd0, 0x7f, 0x31, 0x7f, 0x80, 0xb2, 0xeb, 0x7f, + 0x08, 0x2f, 0x10, 0x6f, 0x00, 0x90, 0x0b, 0x2f, 0x20, 0x6f, 0x00, 0x90, + 0x08, 0x2f, 0x30, 0x6f, 0x00, 0x90, 0x05, 0x2f, 0x01, 0x30, 0x23, 0x2e, + 0x7d, 0x00, 0xd0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0x05, 0x2e, 0x7d, 0x00, + 0x80, 0x90, 0x00, 0x30, 0x41, 0x52, 0x45, 0x56, 0x07, 0x2f, 0x41, 0x58, + 0x00, 0x2e, 0x10, 0x43, 0x63, 0x0e, 0xfc, 0x2f, 0x81, 0x84, 0x25, 0x2e, + 0x7d, 0x00, 0x09, 0x2e, 0x85, 0x01, 0x01, 0x85, 0xb0, 0x7f, 0xc0, 0x7f, + 0x00, 0x2e, 0x82, 0x40, 0x03, 0x41, 0x02, 0x89, 0x24, 0xbd, 0x05, 0x41, + 0xb1, 0xbd, 0xb1, 0xb9, 0x24, 0xba, 0x54, 0xbd, 0xa3, 0x7f, 0x5c, 0x05, + 0x24, 0xb9, 0x01, 0x56, 0x43, 0x58, 0x82, 0x7f, 0x95, 0x7f, 0x73, 0x7f, + 0x64, 0x7f, 0x00, 0x2e, 0xf2, 0x6f, 0x40, 0x7f, 0x51, 0x7f, 0x00, 0x2e, + 0x90, 0x40, 0xf2, 0x7f, 0x00, 0x90, 0x04, 0x2f, 0x51, 0x6f, 0x00, 0x30, + 0x40, 0x42, 0x44, 0x2c, 0x62, 0x6f, 0xc1, 0x40, 0x98, 0x2e, 0x74, 0xc0, + 0x51, 0x6f, 0x00, 0x2e, 0x44, 0x40, 0x00, 0xb3, 0x2c, 0x2f, 0x62, 0x6f, + 0x95, 0x6f, 0x83, 0x40, 0xc5, 0x0e, 0x07, 0x2f, 0x75, 0x6f, 0x10, 0x30, + 0x45, 0x41, 0x40, 0xa1, 0x05, 0x30, 0x05, 0x22, 0x18, 0x1a, 0x02, 0x2f, + 0x00, 0x30, 0x40, 0x42, 0x2b, 0x2d, 0x10, 0x30, 0x20, 0x28, 0x84, 0x6f, + 0x40, 0x42, 0xc4, 0x0e, 0x24, 0x2f, 0xc0, 0x6f, 0x00, 0x90, 0x21, 0x2f, + 0x45, 0x6f, 0x10, 0x30, 0x05, 0x15, 0xb3, 0xbd, 0xc4, 0x7f, 0xdc, 0x0a, + 0x41, 0x58, 0x65, 0x01, 0x45, 0x5c, 0x0b, 0x30, 0x25, 0x1a, 0x00, 0x2f, + 0x0b, 0x43, 0x01, 0x89, 0x27, 0x2e, 0x73, 0x01, 0x66, 0x0e, 0xf7, 0x2f, + 0xb0, 0x7f, 0x0e, 0x2d, 0xa2, 0x6f, 0xc2, 0x0e, 0x08, 0x2f, 0x10, 0x30, + 0x40, 0x42, 0x02, 0x30, 0x74, 0x6f, 0x63, 0x6f, 0x04, 0x41, 0x00, 0xa1, + 0x02, 0x22, 0xc0, 0x42, 0x00, 0x2e, 0x62, 0x6f, 0x73, 0x6f, 0x40, 0x6f, + 0x01, 0x80, 0xc1, 0x86, 0x81, 0x84, 0x41, 0x82, 0x03, 0xa2, 0x62, 0x7f, + 0x73, 0x7f, 0xa5, 0x2f, 0xeb, 0x6f, 0xd0, 0x6f, 0xb1, 0x6f, 0x10, 0x5f, + 0x80, 0x2e, 0x95, 0xcf, 0x01, 0x2e, 0x87, 0x01, 0x02, 0x40, 0x01, 0x40, + 0x90, 0x50, 0x2f, 0xbd, 0x93, 0xbc, 0x2f, 0xb9, 0x9c, 0xb8, 0xfb, 0x7f, + 0xe1, 0x7f, 0x80, 0xb2, 0x0b, 0x30, 0x65, 0x2f, 0x05, 0x2e, 0xce, 0x00, + 0x47, 0x52, 0x80, 0x90, 0x0b, 0x2f, 0x5b, 0x42, 0x5b, 0x42, 0x81, 0x84, + 0x25, 0x2e, 0xce, 0x00, 0x37, 0x2e, 0xcf, 0x00, 0x37, 0x2e, 0xd0, 0x00, + 0x37, 0x2e, 0xd1, 0x00, 0x4b, 0x42, 0x00, 0x2e, 0x03, 0x40, 0x12, 0x40, + 0x01, 0x40, 0x00, 0x40, 0x0a, 0xbe, 0x27, 0xbd, 0x2e, 0xb8, 0x92, 0xbc, + 0x18, 0xb9, 0xb9, 0xbd, 0xba, 0xb9, 0x4a, 0xba, 0x07, 0x5a, 0x1a, 0x25, + 0x17, 0x2e, 0xcf, 0x00, 0x77, 0x82, 0x83, 0x7f, 0xab, 0x7f, 0x75, 0x7f, + 0x94, 0x7f, 0xd2, 0x7f, 0xc0, 0x7f, 0x98, 0x2e, 0xd1, 0xc3, 0x03, 0x2e, + 0xcf, 0x00, 0x08, 0x1a, 0xb0, 0x7f, 0x01, 0x30, 0x01, 0x2f, 0x23, 0x2e, + 0xd1, 0x00, 0x01, 0x2e, 0xd1, 0x00, 0xd1, 0x6f, 0x41, 0x0e, 0x14, 0x2f, + 0xc1, 0x6f, 0x40, 0xb2, 0x0b, 0x2f, 0x43, 0xb2, 0x09, 0x2f, 0x07, 0x54, + 0x47, 0x56, 0x98, 0x2e, 0x0b, 0xc4, 0x00, 0x90, 0x06, 0x2f, 0xb1, 0x6f, + 0x23, 0x2e, 0xd0, 0x00, 0x03, 0x2d, 0xb1, 0x6f, 0x23, 0x2e, 0xd0, 0x00, + 0xd1, 0x6f, 0x23, 0x2e, 0xd1, 0x00, 0x03, 0x2e, 0xd1, 0x00, 0x41, 0x82, + 0x23, 0x2e, 0xd1, 0x00, 0x07, 0x50, 0x47, 0x52, 0x12, 0x40, 0x52, 0x42, + 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x00, 0x2e, 0x00, 0x40, 0x40, 0x42, + 0x00, 0x2e, 0x03, 0x2e, 0xd0, 0x00, 0xe0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, + 0xb1, 0x6f, 0x23, 0x2e, 0xcf, 0x00, 0x06, 0x2d, 0x37, 0x2e, 0xce, 0x00, + 0xe0, 0x6f, 0x01, 0x30, 0x98, 0x2e, 0x95, 0xcf, 0xfb, 0x6f, 0x70, 0x5f, + 0xb8, 0x2e, 0xd0, 0x50, 0x80, 0x7f, 0x91, 0x7f, 0xd7, 0x7f, 0xc5, 0x7f, + 0xb3, 0x7f, 0xa2, 0x7f, 0xe4, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, + 0x4b, 0x50, 0x00, 0x2e, 0x01, 0x40, 0x9f, 0xbc, 0x9f, 0xb8, 0x40, 0x90, + 0x02, 0x2f, 0x31, 0x30, 0x23, 0x2e, 0x69, 0xf5, 0x38, 0x82, 0x61, 0x7f, + 0x20, 0x30, 0x41, 0x40, 0x23, 0x2e, 0xd6, 0x00, 0x03, 0x2e, 0xd6, 0x00, + 0x08, 0x08, 0x00, 0xb2, 0x0b, 0x2f, 0x49, 0x50, 0x1a, 0x25, 0x12, 0x40, + 0x32, 0x7f, 0x73, 0x82, 0x12, 0x40, 0x42, 0x7f, 0x00, 0x2e, 0x00, 0x40, + 0x50, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x01, 0x2e, 0xd6, 0x00, 0x81, 0x30, + 0x01, 0x08, 0x00, 0xb2, 0x42, 0x2f, 0x03, 0x2e, 0x89, 0x00, 0x01, 0x2e, + 0x89, 0x00, 0x97, 0xbc, 0x06, 0xbc, 0x9f, 0xb8, 0x0f, 0xb8, 0x00, 0x90, + 0x23, 0x2e, 0x6d, 0x01, 0x10, 0x30, 0x01, 0x30, 0x2a, 0x2f, 0x03, 0x2e, + 0xff, 0x00, 0x44, 0xb2, 0x05, 0x2f, 0x47, 0xb2, 0x00, 0x30, 0x2d, 0x2f, + 0x21, 0x2e, 0xd6, 0x00, 0x2b, 0x2d, 0x03, 0x2e, 0xfd, 0xf5, 0x9e, 0xbc, + 0x9f, 0xb8, 0x40, 0x90, 0x14, 0x2f, 0x03, 0x2e, 0xfc, 0xf5, 0x99, 0xbc, + 0x9f, 0xb8, 0x40, 0x90, 0x0e, 0x2f, 0x03, 0x2e, 0x49, 0xf1, 0x4d, 0x54, + 0x4a, 0x08, 0x40, 0x90, 0x08, 0x2f, 0x98, 0x2e, 0xe4, 0x01, 0x00, 0xb2, + 0x10, 0x30, 0x03, 0x2f, 0x50, 0x30, 0x21, 0x2e, 0xff, 0x00, 0x10, 0x2d, + 0x98, 0x2e, 0xe4, 0xb6, 0x00, 0x30, 0x21, 0x2e, 0xd6, 0x00, 0x0a, 0x2d, + 0x05, 0x2e, 0x69, 0xf7, 0x2d, 0xbd, 0x2f, 0xb9, 0x80, 0xb2, 0x01, 0x2f, + 0x21, 0x2e, 0xd7, 0x00, 0x23, 0x2e, 0xd6, 0x00, 0x60, 0x6f, 0xe1, 0x31, + 0x01, 0x42, 0x00, 0x2e, 0xf6, 0x6f, 0xe4, 0x6f, 0x80, 0x6f, 0x91, 0x6f, + 0xa2, 0x6f, 0xb3, 0x6f, 0xc5, 0x6f, 0xd7, 0x6f, 0x7b, 0x6f, 0x30, 0x5f, + 0xc8, 0x2e, 0xa0, 0x50, 0x82, 0x7f, 0x90, 0x7f, 0xd7, 0x7f, 0xc5, 0x7f, + 0xb3, 0x7f, 0xa1, 0x7f, 0xe4, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, + 0x4b, 0x54, 0x00, 0x2e, 0x80, 0x40, 0x0f, 0xbc, 0x0f, 0xb8, 0x00, 0x90, + 0x02, 0x2f, 0x30, 0x30, 0x21, 0x2e, 0x69, 0xf5, 0xb7, 0x84, 0x62, 0x7f, + 0x98, 0x2e, 0xe4, 0x01, 0x00, 0xb2, 0x90, 0x2e, 0x95, 0xb4, 0x03, 0x2e, + 0x8c, 0x00, 0x07, 0x2e, 0x8e, 0x00, 0x3f, 0xba, 0x05, 0x2e, 0xa0, 0x00, + 0xa3, 0xbd, 0x9f, 0xb8, 0x01, 0x2e, 0xa0, 0x00, 0x4c, 0x0a, 0xbf, 0xb9, + 0x04, 0xbe, 0x4b, 0x0a, 0x05, 0x2e, 0xa0, 0x00, 0xcf, 0xb9, 0x01, 0x2e, + 0x96, 0x00, 0x22, 0xbe, 0xcb, 0x0a, 0x4f, 0xba, 0x03, 0xbc, 0x05, 0x2e, + 0x98, 0x00, 0xdc, 0x0a, 0x0f, 0xb8, 0x03, 0x2e, 0x90, 0x00, 0x2f, 0xbe, + 0x18, 0x0a, 0xcf, 0xb9, 0x9f, 0xbc, 0x05, 0x2e, 0x9f, 0x00, 0x9f, 0xb8, + 0x03, 0x0a, 0x2f, 0xbd, 0x01, 0x0a, 0x2f, 0xb9, 0x82, 0x0a, 0x25, 0x2e, + 0x78, 0x00, 0x05, 0x2e, 0xc1, 0xf5, 0x2e, 0xbd, 0x2e, 0xb9, 0x01, 0x2e, + 0x7a, 0x00, 0x31, 0x30, 0x8a, 0x04, 0x00, 0x90, 0x07, 0x2f, 0x01, 0x2e, + 0xff, 0x00, 0x04, 0xa2, 0x03, 0x2f, 0x01, 0x2e, 0x78, 0x00, 0x00, 0xb2, + 0x0c, 0x2f, 0x51, 0x50, 0x07, 0x52, 0x98, 0x2e, 0xfc, 0x01, 0x05, 0x2e, + 0xd8, 0x00, 0x80, 0x90, 0x10, 0x30, 0x01, 0x2f, 0x21, 0x2e, 0xd8, 0x00, + 0x25, 0x2e, 0x8e, 0x01, 0x98, 0x2e, 0xed, 0x01, 0x00, 0xb2, 0x22, 0x30, + 0x21, 0x30, 0x03, 0x2f, 0x01, 0x2e, 0x7a, 0x00, 0x00, 0x90, 0x05, 0x2f, + 0x01, 0x2e, 0x79, 0x00, 0x01, 0xb2, 0x30, 0x30, 0x01, 0x30, 0x41, 0x22, + 0x01, 0x2e, 0x9b, 0x01, 0x08, 0x1a, 0x0e, 0x2f, 0x23, 0x2e, 0x9b, 0x01, + 0x33, 0x30, 0x53, 0x50, 0x0b, 0x09, 0x01, 0x40, 0x4f, 0x56, 0x46, 0xbe, + 0x4b, 0x08, 0x4c, 0x0a, 0x01, 0x42, 0x0a, 0x80, 0x1f, 0x52, 0x01, 0x42, + 0x00, 0x2e, 0x01, 0x2e, 0x78, 0x00, 0x00, 0xb2, 0x1f, 0x2f, 0x03, 0x2e, + 0xc0, 0xf5, 0xf0, 0x30, 0x48, 0x08, 0x47, 0xaa, 0x74, 0x30, 0x07, 0x2e, + 0xdb, 0x00, 0x61, 0x22, 0x4b, 0x1a, 0x05, 0x2f, 0x07, 0x2e, 0x66, 0xf5, + 0xbf, 0xbd, 0xbf, 0xb9, 0xc0, 0x90, 0x0b, 0x2f, 0x55, 0x56, 0x04, 0x30, + 0xd4, 0x42, 0xd2, 0x42, 0x81, 0x04, 0x24, 0xbd, 0xfe, 0x80, 0x81, 0x84, + 0xc4, 0x42, 0x23, 0x2e, 0xdb, 0x00, 0x02, 0x42, 0x02, 0x32, 0x25, 0x2e, + 0x62, 0xf5, 0x05, 0x2e, 0x6b, 0x01, 0x81, 0x80, 0x21, 0x2e, 0x6b, 0x01, + 0x62, 0x6f, 0x00, 0x31, 0x80, 0x42, 0x00, 0x2e, 0x05, 0x2e, 0x8a, 0x00, + 0x0d, 0x50, 0x90, 0x08, 0x80, 0xb2, 0x0b, 0x2f, 0x05, 0x2e, 0xca, 0xf5, + 0xf0, 0x3e, 0x90, 0x08, 0x25, 0x2e, 0xca, 0xf5, 0x05, 0x2e, 0x59, 0xf5, + 0xe0, 0x3f, 0x90, 0x08, 0x25, 0x2e, 0x59, 0xf5, 0xf6, 0x6f, 0xe4, 0x6f, + 0x90, 0x6f, 0xa1, 0x6f, 0xb3, 0x6f, 0xc5, 0x6f, 0xd7, 0x6f, 0x7b, 0x6f, + 0x82, 0x6f, 0x60, 0x5f, 0xc8, 0x2e, 0xc0, 0x50, 0x80, 0x7f, 0x92, 0x7f, + 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0xa1, 0x7f, 0xe7, 0x7f, 0xf6, 0x7f, + 0x7b, 0x7f, 0x00, 0x2e, 0x4b, 0x50, 0x00, 0x2e, 0x02, 0x40, 0x2f, 0xbd, + 0x2f, 0xb9, 0x80, 0x90, 0x02, 0x2f, 0x32, 0x30, 0x25, 0x2e, 0x69, 0xf5, + 0x37, 0x80, 0x00, 0x2e, 0x00, 0x40, 0x60, 0x7f, 0x98, 0x2e, 0xe4, 0x01, + 0x63, 0x6f, 0x02, 0x30, 0x62, 0x7f, 0x50, 0x7f, 0x02, 0x32, 0x1f, 0x52, + 0x80, 0x2e, 0x6e, 0xb5, 0x1a, 0x09, 0x00, 0xb3, 0x14, 0x2f, 0x00, 0xb2, + 0x03, 0x2f, 0x09, 0x2e, 0x78, 0x00, 0x00, 0x91, 0x0c, 0x2f, 0x43, 0x7f, + 0x98, 0x2e, 0x32, 0x03, 0x57, 0x50, 0x02, 0x8a, 0x02, 0x32, 0x04, 0x30, + 0x25, 0x2e, 0x64, 0xf5, 0x1f, 0x52, 0x50, 0x6f, 0x43, 0x6f, 0x44, 0x43, + 0x25, 0x2e, 0x60, 0xf5, 0xd9, 0x08, 0xc0, 0xb2, 0x6d, 0x2f, 0x98, 0x2e, + 0xed, 0x01, 0x00, 0xb2, 0x06, 0x2f, 0x01, 0x2e, 0x7a, 0x00, 0x00, 0xb2, + 0x02, 0x2f, 0x50, 0x6f, 0x00, 0x90, 0x0a, 0x2f, 0x01, 0x2e, 0xda, 0x00, + 0x00, 0x90, 0x19, 0x2f, 0x10, 0x30, 0x21, 0x2e, 0xda, 0x00, 0x00, 0x30, + 0x98, 0x2e, 0xcd, 0xb6, 0x13, 0x2d, 0x01, 0x2e, 0xc3, 0xf5, 0x0c, 0xbc, + 0x0f, 0xb8, 0x12, 0x30, 0x10, 0x04, 0x03, 0xb0, 0x26, 0x25, 0x59, 0x50, + 0x05, 0x52, 0x98, 0x2e, 0xfc, 0x01, 0x10, 0x30, 0x21, 0x2e, 0xa0, 0x01, + 0x02, 0x30, 0x60, 0x7f, 0x25, 0x2e, 0xda, 0x00, 0x50, 0x6f, 0x00, 0xb2, + 0x03, 0x2f, 0x05, 0x2e, 0x79, 0x00, 0x80, 0x90, 0x0e, 0x2f, 0x05, 0x2e, + 0xd9, 0x00, 0x80, 0x90, 0x2c, 0x2f, 0x11, 0x30, 0x02, 0x30, 0x23, 0x2e, + 0xd9, 0x00, 0x23, 0x2e, 0x7c, 0x00, 0x25, 0x2e, 0x7d, 0x00, 0x25, 0x2e, + 0xa5, 0x01, 0x22, 0x2d, 0x05, 0x2e, 0xa5, 0x01, 0x81, 0x82, 0x23, 0x2e, + 0xa5, 0x01, 0x12, 0x30, 0x4a, 0x08, 0x40, 0xb2, 0x05, 0x2f, 0x03, 0x2e, + 0x58, 0xf5, 0x98, 0xbc, 0x9e, 0xb8, 0x43, 0x90, 0x10, 0x2f, 0x01, 0x2e, + 0xc1, 0xf5, 0x0e, 0xbc, 0x0e, 0xb8, 0x32, 0x30, 0x90, 0x04, 0x5b, 0x50, + 0x01, 0x52, 0x98, 0x2e, 0xfc, 0x01, 0x12, 0x30, 0x25, 0x2e, 0xa4, 0x01, + 0x00, 0x30, 0x21, 0x2e, 0xd9, 0x00, 0x50, 0x6f, 0x62, 0x7f, 0x00, 0x2e, + 0x62, 0x6f, 0x80, 0x90, 0x05, 0x2f, 0x02, 0x30, 0x25, 0x2e, 0x9b, 0x01, + 0x1f, 0x54, 0x25, 0x2e, 0x64, 0xf5, 0x1f, 0x52, 0x23, 0x2e, 0x60, 0xf5, + 0x02, 0x32, 0x00, 0x90, 0x02, 0x2f, 0x03, 0x30, 0x27, 0x2e, 0xd8, 0x00, + 0x07, 0x2e, 0x60, 0xf5, 0x1a, 0x09, 0x00, 0x91, 0x90, 0x2e, 0xde, 0xb4, + 0x19, 0x09, 0x00, 0x91, 0x90, 0x2e, 0xde, 0xb4, 0x80, 0x6f, 0x92, 0x6f, + 0xa1, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0x7b, 0x6f, 0xf6, 0x6f, + 0xe7, 0x6f, 0x40, 0x5f, 0xc8, 0x2e, 0x5d, 0x52, 0x00, 0x51, 0x52, 0x40, + 0x47, 0x40, 0xf8, 0xbc, 0x9c, 0xb9, 0x1a, 0x25, 0x01, 0x2e, 0x9f, 0x00, + 0xf3, 0x7f, 0x8f, 0xbe, 0x72, 0x88, 0xeb, 0x7f, 0x5f, 0xbb, 0x0b, 0x30, + 0x78, 0xb8, 0x6b, 0x56, 0xd3, 0x08, 0x70, 0x8a, 0xfc, 0xbf, 0x0b, 0x43, + 0xc4, 0x7f, 0xfc, 0xbb, 0x1e, 0x0b, 0x21, 0x2e, 0xe1, 0x00, 0x1b, 0x7f, + 0x4b, 0x43, 0x00, 0xb3, 0xd6, 0x7f, 0xa7, 0x7f, 0xb5, 0x7f, 0x93, 0x7f, + 0x90, 0x2e, 0x39, 0xb6, 0x01, 0x2e, 0xfb, 0x00, 0x00, 0xb2, 0x0b, 0x2f, + 0x5f, 0x52, 0x01, 0x2e, 0xf6, 0x00, 0x82, 0x7f, 0x98, 0x2e, 0xbb, 0xcc, + 0x0b, 0x30, 0x37, 0x2e, 0xfb, 0x00, 0x82, 0x6f, 0x93, 0x6f, 0x1a, 0x25, + 0xc0, 0xb2, 0x8b, 0x7f, 0x14, 0x2f, 0x26, 0xbc, 0x25, 0xbd, 0x06, 0xb8, + 0x2f, 0xb9, 0x80, 0xb2, 0x14, 0xb0, 0x0c, 0x2f, 0x61, 0x50, 0x63, 0x54, + 0x0b, 0x30, 0x0b, 0x2e, 0xa0, 0x00, 0x69, 0x58, 0x1b, 0x42, 0x9b, 0x42, + 0x6c, 0x09, 0x2b, 0x2e, 0xa0, 0x00, 0x0b, 0x42, 0x8b, 0x42, 0x86, 0x7f, + 0x73, 0x84, 0x6d, 0x50, 0xd8, 0x08, 0x67, 0x52, 0x07, 0x50, 0x72, 0x7f, + 0x63, 0x7f, 0x98, 0x2e, 0xc2, 0xc0, 0xd1, 0x6f, 0x62, 0x6f, 0xd1, 0x0a, + 0x01, 0x2e, 0xf6, 0x00, 0xc5, 0x6f, 0xb4, 0x6f, 0x72, 0x6f, 0x5f, 0x52, + 0x65, 0x5c, 0x98, 0x2e, 0x06, 0xcd, 0x23, 0x6f, 0x90, 0x6f, 0x61, 0x52, + 0xc0, 0xb2, 0x04, 0xbd, 0x54, 0x40, 0xaf, 0xb9, 0x45, 0x40, 0xd1, 0x7f, + 0x02, 0x30, 0x06, 0x2f, 0xc0, 0xb2, 0x02, 0x30, 0x03, 0x2f, 0x63, 0x5c, + 0x12, 0x30, 0x94, 0x43, 0x85, 0x43, 0x03, 0xbf, 0x6f, 0xbb, 0x80, 0xb3, + 0x20, 0x2f, 0x06, 0x6f, 0x26, 0x01, 0x16, 0x6f, 0x6e, 0x03, 0x45, 0x42, + 0xc0, 0x90, 0x29, 0x2e, 0xf7, 0x00, 0x63, 0x52, 0x14, 0x2f, 0x63, 0x5c, + 0x00, 0x2e, 0x93, 0x41, 0x86, 0x41, 0xe3, 0x04, 0xae, 0x07, 0x80, 0xab, + 0x04, 0x2f, 0x80, 0x91, 0x0a, 0x2f, 0x86, 0x6f, 0x73, 0x0f, 0x07, 0x2f, + 0x83, 0x6f, 0xc0, 0xb2, 0x04, 0x2f, 0x54, 0x42, 0x45, 0x42, 0x12, 0x30, + 0x04, 0x2c, 0x11, 0x30, 0x02, 0x2c, 0x11, 0x30, 0x11, 0x30, 0x02, 0xbc, + 0x0f, 0xb8, 0xc2, 0x7f, 0x00, 0xb2, 0x0a, 0x2f, 0x01, 0x2e, 0xb7, 0x01, + 0x05, 0x2e, 0x71, 0x01, 0x10, 0x1a, 0x02, 0x2f, 0x21, 0x2e, 0x71, 0x01, + 0x03, 0x2d, 0x02, 0x2c, 0x01, 0x30, 0x01, 0x30, 0xf0, 0x6f, 0x98, 0x2e, + 0x95, 0xcf, 0xc1, 0x6f, 0xa0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0xd2, 0x6f, + 0x1b, 0x52, 0x01, 0x2e, 0xf7, 0x00, 0x82, 0x40, 0x50, 0x42, 0x0c, 0x2c, + 0x42, 0x42, 0x11, 0x30, 0x23, 0x2e, 0xfb, 0x00, 0x01, 0x30, 0xf0, 0x6f, + 0x98, 0x2e, 0x95, 0xcf, 0xa0, 0x6f, 0x01, 0x30, 0x98, 0x2e, 0x95, 0xcf, + 0x00, 0x2e, 0xeb, 0x6f, 0x00, 0x5f, 0xb8, 0x2e, 0x60, 0x51, 0x0a, 0x25, + 0x36, 0x88, 0xf4, 0x7f, 0xeb, 0x7f, 0x00, 0x32, 0x7b, 0x52, 0x32, 0x30, + 0x13, 0x30, 0x98, 0x2e, 0x15, 0xcb, 0x0a, 0x25, 0x33, 0x84, 0xd2, 0x7f, + 0x43, 0x30, 0x07, 0x50, 0x35, 0x52, 0x98, 0x2e, 0x95, 0xc1, 0xd2, 0x6f, + 0x73, 0x52, 0x98, 0x2e, 0xd7, 0xc7, 0x2a, 0x25, 0xb0, 0x86, 0xc0, 0x7f, + 0xd3, 0x7f, 0xaf, 0x84, 0x75, 0x50, 0xf1, 0x6f, 0x98, 0x2e, 0x4d, 0xc8, + 0x2a, 0x25, 0xae, 0x8a, 0xaa, 0x88, 0xf2, 0x6e, 0x77, 0x50, 0xc1, 0x6f, + 0xd3, 0x6f, 0xf4, 0x7f, 0x98, 0x2e, 0xb6, 0xc8, 0xe0, 0x6e, 0x00, 0xb2, + 0x32, 0x2f, 0x7d, 0x54, 0x83, 0x86, 0xf1, 0x6f, 0xc3, 0x7f, 0x04, 0x30, + 0x30, 0x30, 0xf4, 0x7f, 0xd0, 0x7f, 0xb2, 0x7f, 0xe3, 0x30, 0xc5, 0x6f, + 0x56, 0x40, 0x45, 0x41, 0x28, 0x08, 0x03, 0x14, 0x0e, 0xb4, 0x08, 0xbc, + 0x82, 0x40, 0x10, 0x0a, 0x79, 0x54, 0x26, 0x05, 0x91, 0x7f, 0x44, 0x28, + 0xa3, 0x7f, 0x98, 0x2e, 0xd9, 0xc0, 0x08, 0xb9, 0x33, 0x30, 0x53, 0x09, + 0xc1, 0x6f, 0xd3, 0x6f, 0xf4, 0x6f, 0x83, 0x17, 0x47, 0x40, 0x6c, 0x15, + 0xb2, 0x6f, 0xbe, 0x09, 0x75, 0x0b, 0x90, 0x42, 0x45, 0x42, 0x51, 0x0e, + 0x32, 0xbc, 0x02, 0x89, 0xa1, 0x6f, 0x7e, 0x86, 0xf4, 0x7f, 0xd0, 0x7f, + 0xb2, 0x7f, 0x04, 0x30, 0x91, 0x6f, 0xd6, 0x2f, 0xeb, 0x6f, 0xa0, 0x5e, + 0xb8, 0x2e, 0x01, 0x2e, 0x77, 0xf7, 0x09, 0xbc, 0x0f, 0xb8, 0x00, 0xb2, + 0x10, 0x50, 0xfb, 0x7f, 0x10, 0x30, 0x0b, 0x2f, 0x03, 0x2e, 0x8a, 0x00, + 0x96, 0xbc, 0x9f, 0xb8, 0x40, 0xb2, 0x05, 0x2f, 0x03, 0x2e, 0x68, 0xf7, + 0x9e, 0xbc, 0x9f, 0xb8, 0x40, 0xb2, 0x07, 0x2f, 0x03, 0x2e, 0xfe, 0x00, + 0x41, 0x90, 0x01, 0x2f, 0x98, 0x2e, 0xcd, 0xb6, 0x03, 0x2c, 0x00, 0x30, + 0x21, 0x2e, 0xfe, 0x00, 0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x20, 0x50, + 0xe0, 0x7f, 0xfb, 0x7f, 0x00, 0x2e, 0x73, 0x50, 0x98, 0x2e, 0x3b, 0xc8, + 0x75, 0x50, 0x98, 0x2e, 0xa7, 0xc8, 0x03, 0x50, 0x98, 0x2e, 0x55, 0xcc, + 0xe1, 0x6f, 0x77, 0x50, 0x98, 0x2e, 0xe0, 0xc9, 0xfb, 0x6f, 0x00, 0x30, + 0xe0, 0x5f, 0x21, 0x2e, 0xfe, 0x00, 0xb8, 0x2e, 0x03, 0xbc, 0x21, 0x2e, + 0x6a, 0x01, 0x03, 0x2e, 0x6a, 0x01, 0x40, 0xb2, 0x10, 0x30, 0x21, 0x2e, + 0x7b, 0x00, 0x01, 0x30, 0x05, 0x2f, 0x05, 0x2e, 0x6d, 0x01, 0x80, 0x90, + 0x01, 0x2f, 0x23, 0x2e, 0x6f, 0xf5, 0xc0, 0x2e, 0x21, 0x2e, 0x6e, 0x01, + 0x30, 0x25, 0x00, 0x30, 0x21, 0x2e, 0x5a, 0xf5, 0x10, 0x50, 0x21, 0x2e, + 0xdc, 0x00, 0x21, 0x2e, 0xd6, 0x00, 0xfb, 0x7f, 0x98, 0x2e, 0xf3, 0x03, + 0x40, 0x30, 0x21, 0x2e, 0xff, 0x00, 0xfb, 0x6f, 0xf0, 0x5f, 0x03, 0x25, + 0x80, 0x2e, 0xe4, 0xb6, 0x10, 0x50, 0x03, 0x40, 0x19, 0x18, 0x83, 0x56, + 0x19, 0x05, 0x36, 0x25, 0xf7, 0x7f, 0x4a, 0x17, 0x54, 0x18, 0xec, 0x18, + 0x09, 0x17, 0x01, 0x30, 0x0c, 0x07, 0xe2, 0x18, 0xde, 0x00, 0xf2, 0x6f, + 0x97, 0x02, 0x7f, 0x58, 0xdc, 0x00, 0x91, 0x02, 0xbf, 0xb8, 0x21, 0xbd, + 0x8a, 0x0a, 0xc0, 0x2e, 0x02, 0x42, 0xf0, 0x5f, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, + 0x01, 0x2e, 0x5d, 0xf7, 0x08, 0xbc, 0x80, 0xac, 0x0e, 0xbb, 0x02, 0x2f, + 0x00, 0x30, 0x41, 0x04, 0x82, 0x06, 0xc0, 0xa4, 0x00, 0x30, 0x11, 0x2f, + 0x40, 0xa9, 0x03, 0x2f, 0x40, 0x91, 0x0d, 0x2f, 0x00, 0xa7, 0x0b, 0x2f, + 0x80, 0xb3, 0x7f, 0x58, 0x02, 0x2f, 0x90, 0xa1, 0x26, 0x13, 0x20, 0x23, + 0x80, 0x90, 0x10, 0x30, 0x01, 0x2f, 0xcc, 0x0e, 0x00, 0x2f, 0x00, 0x30, + 0xb8, 0x2e, 0x81, 0x50, 0x18, 0x08, 0x08, 0xbc, 0x88, 0xb6, 0x0d, 0x17, + 0xc6, 0xbd, 0x56, 0xbc, 0x83, 0x58, 0xda, 0xba, 0x04, 0x01, 0x1d, 0x0a, + 0x10, 0x50, 0x05, 0x30, 0x32, 0x25, 0x45, 0x03, 0xfb, 0x7f, 0xf6, 0x30, + 0x21, 0x25, 0x98, 0x2e, 0x37, 0xca, 0x16, 0xb5, 0x9a, 0xbc, 0x06, 0xb8, + 0x80, 0xa8, 0x41, 0x0a, 0x0e, 0x2f, 0x80, 0x90, 0x02, 0x2f, 0x35, 0x50, + 0x48, 0x0f, 0x09, 0x2f, 0xbf, 0xa0, 0x04, 0x2f, 0xbf, 0x90, 0x06, 0x2f, + 0x83, 0x54, 0xca, 0x0f, 0x03, 0x2f, 0x00, 0x2e, 0x02, 0x2c, 0x83, 0x52, + 0x35, 0x52, 0xf2, 0x33, 0x98, 0x2e, 0xd9, 0xc0, 0xfb, 0x6f, 0xf1, 0x37, + 0xc0, 0x2e, 0x01, 0x08, 0xf0, 0x5f, 0x8b, 0x56, 0x85, 0x54, 0xd0, 0x40, + 0xc4, 0x40, 0x0b, 0x2e, 0xfd, 0xf3, 0x8b, 0x52, 0x90, 0x42, 0x94, 0x42, + 0x95, 0x42, 0x05, 0x30, 0x8d, 0x50, 0x0f, 0x88, 0x06, 0x40, 0x04, 0x41, + 0x96, 0x42, 0xc5, 0x42, 0x48, 0xbe, 0x73, 0x30, 0x0d, 0x2e, 0x6d, 0x01, + 0x4f, 0xba, 0x84, 0x42, 0x03, 0x42, 0x81, 0xb3, 0x02, 0x2f, 0x2b, 0x2e, + 0x6f, 0xf5, 0x06, 0x2d, 0x05, 0x2e, 0x77, 0xf7, 0x89, 0x56, 0x93, 0x08, + 0x25, 0x2e, 0x77, 0xf7, 0x87, 0x54, 0x25, 0x2e, 0xc2, 0xf5, 0x07, 0x2e, + 0xfd, 0xf3, 0x42, 0x30, 0xb4, 0x33, 0xda, 0x0a, 0x4c, 0x00, 0x27, 0x2e, + 0xfd, 0xf3, 0x43, 0x40, 0xd4, 0x3f, 0xdc, 0x08, 0x43, 0x42, 0x00, 0x2e, + 0x00, 0x2e, 0x43, 0x40, 0x24, 0x30, 0xdc, 0x0a, 0x43, 0x42, 0x04, 0x80, + 0x03, 0x2e, 0xfd, 0xf3, 0x4a, 0x0a, 0x23, 0x2e, 0xfd, 0xf3, 0x61, 0x34, + 0xc0, 0x2e, 0x01, 0x42, 0x00, 0x2e, 0x60, 0x50, 0x1a, 0x25, 0x7a, 0x86, + 0xe0, 0x7f, 0xf3, 0x7f, 0x03, 0x25, 0x8f, 0x52, 0x41, 0x84, 0xdb, 0x7f, + 0x33, 0x30, 0x98, 0x2e, 0x16, 0xc2, 0x1a, 0x25, 0x7d, 0x82, 0xf0, 0x6f, + 0xe2, 0x6f, 0x32, 0x25, 0x16, 0x40, 0x94, 0x40, 0x26, 0x01, 0x85, 0x40, + 0x8e, 0x17, 0xc4, 0x42, 0x6e, 0x03, 0x95, 0x42, 0x41, 0x0e, 0xf4, 0x2f, + 0xdb, 0x6f, 0xa0, 0x5f, 0xb8, 0x2e, 0xb0, 0x51, 0xfb, 0x7f, 0x98, 0x2e, + 0xe8, 0x0d, 0x5a, 0x25, 0x98, 0x2e, 0x0f, 0x0e, 0x97, 0x58, 0x32, 0x87, + 0xc4, 0x7f, 0x65, 0x89, 0x6b, 0x8d, 0x91, 0x5a, 0x65, 0x7f, 0xe1, 0x7f, + 0x83, 0x7f, 0xa6, 0x7f, 0x74, 0x7f, 0xd0, 0x7f, 0xb6, 0x7f, 0x94, 0x7f, + 0x17, 0x30, 0x93, 0x52, 0x95, 0x54, 0x51, 0x7f, 0x00, 0x2e, 0x85, 0x6f, + 0x42, 0x7f, 0x00, 0x2e, 0x51, 0x41, 0x45, 0x81, 0x42, 0x41, 0x13, 0x40, + 0x3b, 0x8a, 0x00, 0x40, 0x4b, 0x04, 0xd0, 0x06, 0xc0, 0xac, 0x85, 0x7f, + 0x02, 0x2f, 0x02, 0x30, 0x51, 0x04, 0xd3, 0x06, 0x41, 0x84, 0x05, 0x30, + 0x5d, 0x02, 0xc9, 0x16, 0xdf, 0x08, 0xd3, 0x00, 0x8d, 0x02, 0xaf, 0xbc, + 0xb1, 0xb9, 0x59, 0x0a, 0x65, 0x6f, 0x11, 0x43, 0xa1, 0xb4, 0x52, 0x41, + 0x53, 0x41, 0x01, 0x43, 0x34, 0x7f, 0x65, 0x7f, 0x26, 0x31, 0xe5, 0x6f, + 0xd4, 0x6f, 0x98, 0x2e, 0x37, 0xca, 0x32, 0x6f, 0x75, 0x6f, 0x83, 0x40, + 0x42, 0x41, 0x23, 0x7f, 0x12, 0x7f, 0xf6, 0x30, 0x40, 0x25, 0x51, 0x25, + 0x98, 0x2e, 0x37, 0xca, 0x14, 0x6f, 0x20, 0x05, 0x70, 0x6f, 0x25, 0x6f, + 0x69, 0x07, 0xa2, 0x6f, 0x31, 0x6f, 0x0b, 0x30, 0x04, 0x42, 0x9b, 0x42, + 0x8b, 0x42, 0x55, 0x42, 0x32, 0x7f, 0x40, 0xa9, 0xc3, 0x6f, 0x71, 0x7f, + 0x02, 0x30, 0xd0, 0x40, 0xc3, 0x7f, 0x03, 0x2f, 0x40, 0x91, 0x15, 0x2f, + 0x00, 0xa7, 0x13, 0x2f, 0x00, 0xa4, 0x11, 0x2f, 0x84, 0xbd, 0x98, 0x2e, + 0x79, 0xca, 0x55, 0x6f, 0x83, 0x54, 0x54, 0x41, 0x82, 0x00, 0xf3, 0x3f, + 0x45, 0x41, 0xcb, 0x02, 0xf6, 0x30, 0x98, 0x2e, 0x37, 0xca, 0x35, 0x6f, + 0xa4, 0x6f, 0x41, 0x43, 0x03, 0x2c, 0x00, 0x43, 0xa4, 0x6f, 0x35, 0x6f, + 0x17, 0x30, 0x42, 0x6f, 0x51, 0x6f, 0x93, 0x40, 0x42, 0x82, 0x00, 0x41, + 0xc3, 0x00, 0x03, 0x43, 0x51, 0x7f, 0x00, 0x2e, 0x94, 0x40, 0x41, 0x41, + 0x4c, 0x02, 0xc4, 0x6f, 0x9d, 0x56, 0x63, 0x0e, 0x74, 0x6f, 0x51, 0x43, + 0xa5, 0x7f, 0x8a, 0x2f, 0x09, 0x2e, 0x6d, 0x01, 0x01, 0xb3, 0x21, 0x2f, + 0x97, 0x58, 0x90, 0x6f, 0x13, 0x41, 0xb6, 0x6f, 0xe4, 0x7f, 0x00, 0x2e, + 0x91, 0x41, 0x14, 0x40, 0x92, 0x41, 0x15, 0x40, 0x17, 0x2e, 0x6f, 0xf5, + 0xb6, 0x7f, 0xd0, 0x7f, 0xcb, 0x7f, 0x98, 0x2e, 0x00, 0x0c, 0x07, 0x15, + 0xc2, 0x6f, 0x14, 0x0b, 0x29, 0x2e, 0x6f, 0xf5, 0xc3, 0xa3, 0xc1, 0x8f, + 0xe4, 0x6f, 0xd0, 0x6f, 0xe6, 0x2f, 0x14, 0x30, 0x05, 0x2e, 0x6f, 0xf5, + 0x14, 0x0b, 0x29, 0x2e, 0x6f, 0xf5, 0x18, 0x2d, 0x99, 0x56, 0x04, 0x32, + 0xb5, 0x6f, 0x1c, 0x01, 0x51, 0x41, 0x52, 0x41, 0xc3, 0x40, 0xb5, 0x7f, + 0xe4, 0x7f, 0x98, 0x2e, 0x1f, 0x0c, 0xe4, 0x6f, 0x21, 0x87, 0x00, 0x43, + 0x04, 0x32, 0x9b, 0x54, 0x5a, 0x0e, 0xef, 0x2f, 0x1f, 0x54, 0x09, 0x2e, + 0x77, 0xf7, 0x22, 0x0b, 0x29, 0x2e, 0x77, 0xf7, 0xfb, 0x6f, 0x50, 0x5e, + 0xb8, 0x2e, 0x10, 0x50, 0x01, 0x2e, 0xff, 0x00, 0x00, 0xb2, 0xfb, 0x7f, + 0x51, 0x2f, 0x01, 0xb2, 0x48, 0x2f, 0x02, 0xb2, 0x42, 0x2f, 0x03, 0x90, + 0x56, 0x2f, 0xa3, 0x52, 0x79, 0x80, 0x42, 0x40, 0x81, 0x84, 0x00, 0x40, + 0x42, 0x42, 0x98, 0x2e, 0x93, 0x0c, 0xa5, 0x54, 0xa3, 0x50, 0xa1, 0x40, + 0x98, 0xbd, 0x82, 0x40, 0x3e, 0x82, 0xda, 0x0a, 0x44, 0x40, 0x8b, 0x16, + 0xe3, 0x00, 0x53, 0x42, 0x00, 0x2e, 0x43, 0x40, 0x9a, 0x02, 0x52, 0x42, + 0x00, 0x2e, 0x41, 0x40, 0x1f, 0x54, 0x4a, 0x0e, 0x3a, 0x2f, 0x3a, 0x82, + 0x00, 0x30, 0x41, 0x40, 0x21, 0x2e, 0x94, 0x0f, 0x40, 0xb2, 0x0a, 0x2f, + 0x98, 0x2e, 0xb1, 0x0c, 0x98, 0x2e, 0x45, 0x0e, 0x98, 0x2e, 0x5b, 0x0e, + 0xfb, 0x6f, 0xf0, 0x5f, 0x00, 0x30, 0x80, 0x2e, 0xf8, 0xb6, 0xa9, 0x52, + 0x9f, 0x54, 0x42, 0x42, 0x4f, 0x84, 0x73, 0x30, 0xa7, 0x52, 0x83, 0x42, + 0x1b, 0x30, 0x6b, 0x42, 0x23, 0x30, 0x27, 0x2e, 0x6c, 0x01, 0x37, 0x2e, + 0xff, 0x00, 0x21, 0x2e, 0x6b, 0x01, 0x7a, 0x84, 0x17, 0x2c, 0x42, 0x42, + 0x30, 0x30, 0x21, 0x2e, 0xff, 0x00, 0x12, 0x2d, 0x21, 0x30, 0x00, 0x30, + 0x23, 0x2e, 0xff, 0x00, 0x21, 0x2e, 0x7b, 0xf7, 0x0b, 0x2d, 0x17, 0x30, + 0x98, 0x2e, 0x51, 0x0c, 0xa1, 0x50, 0x0c, 0x82, 0x72, 0x30, 0x2f, 0x2e, + 0xff, 0x00, 0x25, 0x2e, 0x7b, 0xf7, 0x40, 0x42, 0x00, 0x2e, 0xfb, 0x6f, + 0xf0, 0x5f, 0xb8, 0x2e, 0x70, 0x50, 0x0a, 0x25, 0x39, 0x86, 0xfb, 0x7f, + 0xe1, 0x32, 0x62, 0x30, 0x98, 0x2e, 0xc2, 0xc4, 0x81, 0x56, 0xa5, 0x6f, + 0xab, 0x08, 0x91, 0x6f, 0x4b, 0x08, 0xab, 0x56, 0xc4, 0x6f, 0x23, 0x09, + 0x4d, 0xba, 0x93, 0xbc, 0x8c, 0x0b, 0xd1, 0x6f, 0x0b, 0x09, 0x97, 0x52, + 0xad, 0x5e, 0x56, 0x42, 0xaf, 0x09, 0x4d, 0xba, 0x23, 0xbd, 0x94, 0x0a, + 0xe5, 0x6f, 0x68, 0xbb, 0xeb, 0x08, 0xbd, 0xb9, 0x63, 0xbe, 0xfb, 0x6f, + 0x52, 0x42, 0xe3, 0x0a, 0xc0, 0x2e, 0x43, 0x42, 0x90, 0x5f, 0x9d, 0x50, + 0x03, 0x2e, 0x25, 0xf3, 0x13, 0x40, 0x00, 0x40, 0x9b, 0xbc, 0x9b, 0xb4, + 0x08, 0xbd, 0xb8, 0xb9, 0x98, 0xbc, 0xda, 0x0a, 0x08, 0xb6, 0x89, 0x16, + 0xc0, 0x2e, 0x19, 0x00, 0x62, 0x02, 0x10, 0x50, 0xfb, 0x7f, 0x98, 0x2e, + 0x81, 0x0d, 0x01, 0x2e, 0xff, 0x00, 0x31, 0x30, 0x08, 0x04, 0xfb, 0x6f, + 0x01, 0x30, 0xf0, 0x5f, 0x23, 0x2e, 0x6b, 0x01, 0x21, 0x2e, 0x6c, 0x01, + 0xb8, 0x2e, 0x01, 0x2e, 0x6c, 0x01, 0x03, 0x2e, 0x6b, 0x01, 0x48, 0x0e, + 0x01, 0x2f, 0x80, 0x2e, 0x1f, 0x0e, 0xb8, 0x2e, 0xaf, 0x50, 0x21, 0x34, + 0x01, 0x42, 0x82, 0x30, 0xc1, 0x32, 0x25, 0x2e, 0x62, 0xf5, 0x01, 0x00, + 0x22, 0x30, 0x01, 0x40, 0x4a, 0x0a, 0x01, 0x42, 0xb8, 0x2e, 0xaf, 0x54, + 0xf0, 0x3b, 0x83, 0x40, 0xd8, 0x08, 0xb1, 0x52, 0x83, 0x42, 0x00, 0x30, + 0x83, 0x30, 0x50, 0x42, 0xc4, 0x32, 0x27, 0x2e, 0x64, 0xf5, 0x94, 0x00, + 0x50, 0x42, 0x40, 0x42, 0xd3, 0x3f, 0x84, 0x40, 0x7d, 0x82, 0xe3, 0x08, + 0x40, 0x42, 0x83, 0x42, 0xb8, 0x2e, 0xa9, 0x52, 0x00, 0x30, 0x40, 0x42, + 0x7c, 0x86, 0x85, 0x52, 0x09, 0x2e, 0x7f, 0x0f, 0x8b, 0x54, 0xc4, 0x42, + 0xd3, 0x86, 0x54, 0x40, 0x55, 0x40, 0x94, 0x42, 0x85, 0x42, 0x21, 0x2e, + 0x6c, 0x01, 0x42, 0x40, 0x25, 0x2e, 0xfd, 0xf3, 0xc0, 0x42, 0x7e, 0x82, + 0x05, 0x2e, 0xd7, 0x00, 0x80, 0xb2, 0x14, 0x2f, 0x05, 0x2e, 0x89, 0x00, + 0x27, 0xbd, 0x2f, 0xb9, 0x80, 0x90, 0x02, 0x2f, 0x21, 0x2e, 0x6f, 0xf5, + 0x0c, 0x2d, 0x07, 0x2e, 0x80, 0x0f, 0x14, 0x30, 0x1c, 0x09, 0x05, 0x2e, + 0x77, 0xf7, 0x89, 0x56, 0x47, 0xbe, 0x93, 0x08, 0x94, 0x0a, 0x25, 0x2e, + 0x77, 0xf7, 0xb3, 0x54, 0x50, 0x42, 0x4a, 0x0e, 0xfc, 0x2f, 0xb8, 0x2e, + 0x50, 0x50, 0x02, 0x30, 0x43, 0x86, 0xb1, 0x50, 0xfb, 0x7f, 0xe3, 0x7f, + 0xd2, 0x7f, 0xc0, 0x7f, 0xb1, 0x7f, 0x00, 0x2e, 0x41, 0x40, 0x00, 0x40, + 0x48, 0x04, 0x98, 0x2e, 0x74, 0xc0, 0x1e, 0xaa, 0xd3, 0x6f, 0x14, 0x30, + 0xb1, 0x6f, 0xe3, 0x22, 0xc0, 0x6f, 0x52, 0x40, 0xe4, 0x6f, 0x4c, 0x0e, + 0x12, 0x42, 0xd3, 0x7f, 0xeb, 0x2f, 0x03, 0x2e, 0x95, 0x0f, 0x40, 0x90, + 0x11, 0x30, 0x03, 0x2f, 0x23, 0x2e, 0x95, 0x0f, 0x02, 0x2c, 0x00, 0x30, + 0xd0, 0x6f, 0xfb, 0x6f, 0xb0, 0x5f, 0xb8, 0x2e, 0x40, 0x50, 0xf1, 0x7f, + 0x0a, 0x25, 0x3c, 0x86, 0xeb, 0x7f, 0x41, 0x33, 0x22, 0x30, 0x98, 0x2e, + 0xc2, 0xc4, 0xd3, 0x6f, 0xf4, 0x30, 0xdc, 0x09, 0xb7, 0x58, 0xc2, 0x6f, + 0x94, 0x09, 0xb9, 0x58, 0x6a, 0xbb, 0xdc, 0x08, 0xb4, 0xb9, 0xb1, 0xbd, + 0xb5, 0x5a, 0x95, 0x08, 0x21, 0xbd, 0xf6, 0xbf, 0x77, 0x0b, 0x51, 0xbe, + 0xf1, 0x6f, 0xeb, 0x6f, 0x52, 0x42, 0x54, 0x42, 0xc0, 0x2e, 0x43, 0x42, + 0xc0, 0x5f, 0x50, 0x50, 0xcd, 0x50, 0x31, 0x30, 0x11, 0x42, 0xfb, 0x7f, + 0x7b, 0x30, 0x0b, 0x42, 0x11, 0x30, 0x02, 0x80, 0x23, 0x33, 0x01, 0x42, + 0x03, 0x00, 0x07, 0x2e, 0x80, 0x03, 0x05, 0x2e, 0xd5, 0x00, 0x49, 0x52, + 0xe2, 0x7f, 0xd3, 0x7f, 0xc0, 0x7f, 0x98, 0x2e, 0xb6, 0x0e, 0xd1, 0x6f, + 0x08, 0x0a, 0x1a, 0x25, 0x7b, 0x86, 0xd0, 0x7f, 0x01, 0x33, 0x12, 0x30, + 0x98, 0x2e, 0xc2, 0xc4, 0xd1, 0x6f, 0x08, 0x0a, 0x00, 0xb2, 0x0d, 0x2f, + 0xe3, 0x6f, 0x01, 0x2e, 0x80, 0x03, 0x51, 0x30, 0xc7, 0x86, 0x23, 0x2e, + 0x21, 0xf2, 0x08, 0xbc, 0xc0, 0x42, 0x98, 0x2e, 0x0b, 0x03, 0x00, 0x2e, + 0x00, 0x2e, 0xd0, 0x2e, 0xb0, 0x6f, 0x0b, 0xb8, 0x03, 0x2e, 0x1b, 0x00, + 0x08, 0x1a, 0xb0, 0x7f, 0x70, 0x30, 0x04, 0x2f, 0x21, 0x2e, 0x21, 0xf2, + 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x98, 0x2e, 0x6d, 0xc0, 0x98, 0x2e, + 0x5d, 0xc0, 0xbb, 0x50, 0x98, 0x2e, 0x46, 0xc3, 0xbd, 0x50, 0x98, 0x2e, + 0xfc, 0xc5, 0xbf, 0x50, 0x21, 0x2e, 0x77, 0x01, 0x6f, 0x50, 0x98, 0x2e, + 0x64, 0xcf, 0xc3, 0x50, 0x21, 0x2e, 0x85, 0x01, 0xc1, 0x56, 0xc5, 0x52, + 0x27, 0x2e, 0x86, 0x01, 0x23, 0x2e, 0x87, 0x01, 0xc7, 0x50, 0x98, 0x2e, + 0x53, 0xc7, 0xc9, 0x50, 0x98, 0x2e, 0x44, 0xcb, 0x10, 0x30, 0x98, 0x2e, + 0xcd, 0xb6, 0x20, 0x26, 0xc0, 0x6f, 0x02, 0x31, 0x12, 0x42, 0xab, 0x33, + 0x0b, 0x42, 0x37, 0x80, 0x01, 0x30, 0x01, 0x42, 0xf3, 0x37, 0xcf, 0x52, + 0xd3, 0x50, 0x44, 0x40, 0xa2, 0x0a, 0x42, 0x42, 0x8b, 0x31, 0x09, 0x2e, + 0x5e, 0xf7, 0xd1, 0x54, 0xe3, 0x08, 0x83, 0x42, 0x1b, 0x42, 0x23, 0x33, + 0x4b, 0x00, 0xbc, 0x84, 0x0b, 0x40, 0x33, 0x30, 0x83, 0x42, 0x0b, 0x42, + 0xe0, 0x7f, 0xd1, 0x7f, 0x98, 0x2e, 0x07, 0x02, 0xd1, 0x6f, 0x80, 0x30, + 0x40, 0x42, 0x03, 0x30, 0xe0, 0x6f, 0xcb, 0x54, 0x04, 0x30, 0x00, 0x2e, + 0x00, 0x2e, 0x01, 0x89, 0x62, 0x0e, 0xfa, 0x2f, 0x43, 0x42, 0x11, 0x30, + 0xfb, 0x6f, 0xc0, 0x2e, 0x01, 0x42, 0xb0, 0x5f, 0xc1, 0x4a, 0x00, 0x00, + 0x6d, 0x57, 0x00, 0x00, 0x77, 0x8e, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xd3, 0xff, 0xff, 0xff, 0xe5, 0xff, 0xff, 0xff, 0xee, 0xe1, 0xff, 0xff, + 0x7c, 0x13, 0x00, 0x00, 0x46, 0xe6, 0xff, 0xff, 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, 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, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, + 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0xfd, 0x2d +}; +// clang-format on diff --git a/lib/lilka_modules/src/lilka_modules/can.cpp b/lib/lilka_modules/src/lilka_modules/can.cpp new file mode 100644 index 0000000..0e83d3d --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/can.cpp @@ -0,0 +1,101 @@ +#include "can.h" + +namespace lilka { +namespace mod { + +Can::~Can() { + end(); +} + +bool Can::timingFor(uint32_t bitrate, twai_timing_config_t& out) { + switch (bitrate) { + case 25000: + out = TWAI_TIMING_CONFIG_25KBITS(); + return true; + case 50000: + out = TWAI_TIMING_CONFIG_50KBITS(); + return true; + case 100000: + out = TWAI_TIMING_CONFIG_100KBITS(); + return true; + case 125000: + out = TWAI_TIMING_CONFIG_125KBITS(); + return true; + case 250000: + out = TWAI_TIMING_CONFIG_250KBITS(); + return true; + case 500000: + out = TWAI_TIMING_CONFIG_500KBITS(); + return true; + case 800000: + out = TWAI_TIMING_CONFIG_800KBITS(); + return true; + case 1000000: + out = TWAI_TIMING_CONFIG_1MBITS(); + return true; + default: + return false; + } +} + +esp_err_t Can::begin(const Config& config) { + end(); + twai_timing_config_t timing; + if (!timingFor(config.bitrate, timing)) return ESP_ERR_INVALID_ARG; + + twai_mode_t mode = TWAI_MODE_NORMAL; + if (config.mode == Mode::ListenOnly) mode = TWAI_MODE_LISTEN_ONLY; + if (config.mode == Mode::NoAck) mode = TWAI_MODE_NO_ACK; + twai_general_config_t general = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)config.tx, (gpio_num_t)config.rx, mode); + general.rx_queue_len = config.rxQueue; + general.tx_queue_len = config.txQueue; + + twai_filter_config_t filter; + filter.acceptance_code = config.filterCode; + filter.acceptance_mask = config.filterMask; + filter.single_filter = config.singleFilter; + + esp_err_t err = twai_driver_install(&general, &timing, &filter); + if (err != ESP_OK) return err; + err = twai_start(); + if (err != ESP_OK) { + twai_driver_uninstall(); + return err; + } + running = true; + return ESP_OK; +} + +void Can::end() { + if (!running) return; + twai_stop(); + twai_driver_uninstall(); + running = false; +} + +esp_err_t Can::send(const twai_message_t& msg, uint32_t timeoutMs) { + if (!running) return ESP_ERR_INVALID_STATE; + return twai_transmit(&msg, pdMS_TO_TICKS(timeoutMs)); +} + +esp_err_t Can::receive(twai_message_t& msg, uint32_t timeoutMs) { + if (!running) return ESP_ERR_INVALID_STATE; + return twai_receive(&msg, pdMS_TO_TICKS(timeoutMs)); +} + +esp_err_t Can::status(twai_status_info_t& info) { + if (!running) return ESP_ERR_INVALID_STATE; + return twai_get_status_info(&info); +} + +esp_err_t Can::recover() { + twai_status_info_t info; + esp_err_t err = status(info); + if (err != ESP_OK) return err; + if (info.state == TWAI_STATE_BUS_OFF) return twai_initiate_recovery(); + if (info.state == TWAI_STATE_STOPPED) return twai_start(); + return ESP_OK; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/can.h b/lib/lilka_modules/src/lilka_modules/can.h new file mode 100644 index 0000000..c9b0a08 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/can.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include + +#include "pins.h" + +namespace lilka { +namespace mod { + +/// Шина CAN на вбудованому контролері TWAI (модуль 008 CAN, трансивер SN65HVD232). +class Can { +public: + enum class Mode { + Normal, + ListenOnly, ///< лише прийом, без ACK - безпечно для чужої шини + NoAck, ///< передача без очікування ACK (самотест) + }; + + struct Config { + int tx = pins::UART_TX; + int rx = pins::UART_RX; + uint32_t bitrate = 500000; ///< 25k, 50k, 100k, 125k, 250k, 500k, 800k або 1M + Mode mode = Mode::Normal; + uint32_t filterCode = 0; + uint32_t filterMask = 0xFFFFFFFF; ///< 1 = біт не перевіряється (за замовчуванням приймаємо все) + bool singleFilter = true; + uint32_t rxQueue = 32; + uint32_t txQueue = 8; + }; + + ~Can(); + esp_err_t begin(const Config& config); + void end(); + bool isRunning() const { + return running; + } + + esp_err_t send(const twai_message_t& msg, uint32_t timeoutMs); + /// ESP_ERR_TIMEOUT, якщо за timeoutMs нічого не прийшло. + esp_err_t receive(twai_message_t& msg, uint32_t timeoutMs); + esp_err_t status(twai_status_info_t& info); + /// Вийти з BUS_OFF або перезапустити зупинений контролер. + esp_err_t recover(); + + static bool timingFor(uint32_t bitrate, twai_timing_config_t& out); + +private: + bool running = false; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/cc1101.cpp b/lib/lilka_modules/src/lilka_modules/cc1101.cpp new file mode 100644 index 0000000..207d29f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/cc1101.cpp @@ -0,0 +1,368 @@ +#include "cc1101.h" + +#include +#include +#include +#include +#include + +namespace lilka { +namespace mod { + +enum : uint8_t { + IOCFG2 = 0x00, + IOCFG0 = 0x02, + FIFOTHR = 0x03, + SYNC1 = 0x04, + SYNC0 = 0x05, + PKTLEN = 0x06, + PKTCTRL1 = 0x07, + PKTCTRL0 = 0x08, + FSCTRL1 = 0x0B, + FREQ2 = 0x0D, + FREQ1 = 0x0E, + FREQ0 = 0x0F, + MDMCFG4 = 0x10, + MDMCFG3 = 0x11, + MDMCFG2 = 0x12, + MDMCFG1 = 0x13, + DEVIATN = 0x15, + MCSM1 = 0x17, + MCSM0 = 0x18, + FOCCFG = 0x19, + AGCCTRL2 = 0x1B, + FREND0 = 0x22, + FSCAL3 = 0x23, + FSCAL2 = 0x24, + FSCAL1 = 0x25, + FSCAL0 = 0x26, + TEST2 = 0x2C, + TEST1 = 0x2D, + TEST0 = 0x2E, + PARTNUM = 0x30, + VERSION = 0x31, + RSSI = 0x34, + MARCSTATE = 0x35, + RXBYTES = 0x3B, + PATABLE = 0x3E, + FIFO = 0x3F, + SRES = 0x30, + SCAL = 0x33, + SRX = 0x34, + STX = 0x35, + SIDLE = 0x36, + SFRX = 0x3A, + SFTX = 0x3B, + BURST = 0x40, + READ = 0x80, + MARC_IDLE = 0x01, + MARC_RX = 0x0D, + MARC_RXFIFO_OVERFLOW = 0x11, + MARC_TXFIFO_UNDERFLOW = 0x16, +}; + +static uint32_t nowMs() { + return (uint32_t)(esp_timer_get_time() / 1000); +} + +Cc1101::~Cc1101() { + end(); +} + +uint8_t Cc1101::xfer(uint8_t header, const uint8_t* tx, uint8_t* rx, size_t n) { + cfg.spi->beginTransaction(settings); + digitalWrite(cfg.csn, LOW); + // CHIP_RDYn: MISO goes low when the crystal is running. + if (cfg.miso >= 0) { + int64_t t0 = esp_timer_get_time(); + while (digitalRead(cfg.miso) && esp_timer_get_time() - t0 < 5000) { + } + } + uint8_t st = cfg.spi->transfer(header); + for (size_t i = 0; i < n; i++) { + uint8_t r = cfg.spi->transfer(tx ? tx[i] : 0); + if (rx) rx[i] = r; + } + digitalWrite(cfg.csn, HIGH); + cfg.spi->endTransaction(); + return st; +} + +uint8_t Cc1101::strobe(uint8_t s) { + return xfer(s, nullptr, nullptr, 0); +} + +void Cc1101::writeRegister(uint8_t reg, uint8_t value) { + xfer(reg, &value, nullptr, 1); +} + +uint8_t Cc1101::readRegister(uint8_t reg) { + uint8_t v = 0; + xfer(reg | READ, nullptr, &v, 1); + return v; +} + +uint8_t Cc1101::readStatus(uint8_t reg) { + uint8_t v = 0; + xfer(reg | READ | BURST, nullptr, &v, 1); + return v; +} + +uint8_t Cc1101::marcState() { + return readStatus(MARCSTATE) & 0x1F; +} + +bool Cc1101::waitMarc(uint8_t state, uint32_t ms) { + uint32_t t0 = nowMs(); + while (marcState() != state) { + if (nowMs() - t0 > ms) return false; + vTaskDelay(1); + } + return true; +} + +uint8_t Cc1101::partNumber() { + return readStatus(PARTNUM); +} + +uint8_t Cc1101::version() { + return readStatus(VERSION); +} + +void Cc1101::reset() { + // Manual power-on reset (datasheet 19.1.2). + digitalWrite(cfg.csn, HIGH); + delayMicroseconds(5); + digitalWrite(cfg.csn, LOW); + delayMicroseconds(10); + digitalWrite(cfg.csn, HIGH); + delayMicroseconds(45); + strobe(SRES); + vTaskDelay(pdMS_TO_TICKS(1)); +} + +bool Cc1101::setFrequency(float mhz) { + bool ok = (mhz >= 300 && mhz <= 348) || (mhz >= 387 && mhz <= 464) || (mhz >= 779 && mhz <= 928); + if (!ok) return false; + cfg.frequencyMhz = mhz; + if (!running) return true; + bool wasReceiving = receiving; + idle(); + uint32_t f = (uint32_t)(mhz * 1e6 * 65536.0 / cfg.xtalHz + 0.5); + writeRegister(FREQ2, (f >> 16) & 0xFF); + writeRegister(FREQ1, (f >> 8) & 0xFF); + writeRegister(FREQ0, f & 0xFF); + setPower(cfg.powerDbm); // PA table depends on the band + strobe(SCAL); + waitMarc(MARC_IDLE, 10); + if (wasReceiving) startReceive(); + return true; +} + +void Cc1101::setPower(int8_t dbm) { + cfg.powerDbm = dbm; + // TI DN013 PA tables for -30, -20, -15, -10, 0, 5, 7, 10 dBm + static const int8_t levels[8] = {-30, -20, -15, -10, 0, 5, 7, 10}; + static const uint8_t t315[8] = {0x12, 0x0D, 0x1C, 0x34, 0x51, 0x85, 0xCB, 0xC2}; + static const uint8_t t433[8] = {0x12, 0x0E, 0x1D, 0x34, 0x60, 0x84, 0xC8, 0xC0}; + static const uint8_t t868[8] = {0x03, 0x0F, 0x1E, 0x27, 0x50, 0x81, 0xCB, 0xC2}; + static const uint8_t t915[8] = {0x03, 0x0E, 0x1E, 0x27, 0x8E, 0xCD, 0xC7, 0xC0}; + const uint8_t* table = t433; + if (cfg.frequencyMhz < 350) { + table = t315; + } else if (cfg.frequencyMhz > 900) { + table = t915; + } else if (cfg.frequencyMhz > 700) { + table = t868; + } + int idx = 0; + for (int i = 0; i < 8; i++) { + if (levels[i] <= dbm) idx = i; + } + const uint8_t pa[2] = {0x00, table[idx]}; + if (cfg.modulation == Modulation::ASK) { + // OOK: PATABLE[0] = off level, PATABLE[1] = on level + xfer(PATABLE | BURST, pa, nullptr, 2); + writeRegister(FREND0, 0x11); + } else { + writeRegister(PATABLE, table[idx]); + writeRegister(FREND0, 0x10); + } +} + +bool Cc1101::configure() { + const double xtal = cfg.xtalHz; + if (cfg.dataRate < 600 || cfg.dataRate > 500000) return false; + + // Data rate: R = (256 + M) * 2^E * fxosc / 2^28 + int drE = (int)floor(log2(cfg.dataRate * pow(2, 20) / xtal)); + int drM = (int)lround(cfg.dataRate * pow(2, 28) / (xtal * pow(2, drE)) - 256); + if (drM == 256) { + drM = 0; + drE++; + } + if (drE < 0 || drE > 15) return false; + + // RX filter bandwidth: BW = fxosc / (8 * (4 + M) * 2^E); pick the narrowest >= requested + int bwE = 0, bwM = 0; + for (int e = 3; e >= 0; e--) { + bool found = false; + for (int m = 3; m >= 0; m--) { + double bw = xtal / (8.0 * (4 + m) * (1 << e)); + if (bw >= cfg.bandwidthHz) { + bwE = e; + bwM = m; + found = true; + break; + } + } + if (found) break; + } + + // Deviation: f = fxosc / 2^17 * (8 + M) * 2^E; pick the closest + int devE = 0, devM = 0; + double best = 1e12; + for (int e = 0; e < 8; e++) { + for (int m = 0; m < 8; m++) { + double d = xtal / 131072.0 * (8 + m) * (1 << e); + if (fabs(d - cfg.deviationHz) < best) { + best = fabs(d - cfg.deviationHz); + devE = e; + devM = m; + } + } + } + + strobe(SIDLE); + writeRegister(IOCFG2, 0x29); // CHIP_RDYn + writeRegister(IOCFG0, 0x06); // asserts on sync word, deasserts at end of packet + writeRegister(FIFOTHR, 0x47); + writeRegister(SYNC1, cfg.syncWord >> 8); + writeRegister(SYNC0, cfg.syncWord & 0xFF); + writeRegister(PKTLEN, MAX_PACKET); + writeRegister(PKTCTRL1, 0x04); // append RSSI/LQI, no address check + writeRegister(PKTCTRL0, cfg.crc ? 0x05 : 0x01); // variable length (+ CRC) + writeRegister(FSCTRL1, cfg.bandwidthHz > 325000 ? 0x0C : 0x06); + writeRegister(MDMCFG4, (uint8_t)((bwE << 6) | (bwM << 4) | drE)); + writeRegister(MDMCFG3, (uint8_t)drM); + // 30/32 sync bits, no Manchester + writeRegister(MDMCFG2, (uint8_t)((static_cast(cfg.modulation) << 4) | 0x03)); + writeRegister(MDMCFG1, 0x22); // 4 preamble bytes + writeRegister(DEVIATN, (uint8_t)((devE << 4) | devM)); + writeRegister(MCSM1, 0x30); // back to IDLE after RX and TX + writeRegister(MCSM0, 0x18); // autocal IDLE -> RX/TX + writeRegister(FOCCFG, 0x16); + writeRegister(AGCCTRL2, 0x43); + writeRegister(FSCAL3, 0xE9); + writeRegister(FSCAL2, 0x2A); + writeRegister(FSCAL1, 0x00); + writeRegister(FSCAL0, 0x1F); + writeRegister(TEST2, 0x81); + writeRegister(TEST1, 0x35); + writeRegister(TEST0, 0x09); + running = true; + return setFrequency(cfg.frequencyMhz); +} + +bool Cc1101::begin(const Config& config) { + end(); + cfg = config; + if (!cfg.spi) return false; + settings = SPISettings(cfg.spiFrequency, MSBFIRST, SPI_MODE0); + pinMode(cfg.csn, OUTPUT); + digitalWrite(cfg.csn, HIGH); + if (cfg.gdo0 >= 0) pinMode(cfg.gdo0, INPUT); + if (cfg.gdo2 >= 0) pinMode(cfg.gdo2, INPUT); + reset(); + uint8_t ver = version(); + if (partNumber() != 0x00 || ver == 0x00 || ver == 0xFF) return false; + if (!configure()) { + running = false; + return false; + } + return true; +} + +void Cc1101::end() { + if (!running) return; + idle(); + running = false; +} + +void Cc1101::idle() { + strobe(SIDLE); + waitMarc(MARC_IDLE, 10); + receiving = false; +} + +void Cc1101::startReceive() { + if (!running) return; + idle(); + strobe(SFRX); + strobe(SRX); + receiving = true; +} + +bool Cc1101::send(const uint8_t* data, uint8_t length, uint32_t timeoutMs) { + if (!running || length > MAX_PACKET) return false; + bool wasReceiving = receiving; + idle(); + strobe(SFTX); + uint8_t buf[MAX_PACKET + 1]; + buf[0] = length; + for (uint8_t i = 0; i < length; i++) + buf[i + 1] = data[i]; + xfer(FIFO | BURST, buf, nullptr, length + 1); + strobe(STX); + // Leaves IDLE for TX, comes back to IDLE (MCSM1) when the packet is out. + vTaskDelay(1); + bool ok = waitMarc(MARC_IDLE, timeoutMs); + if (!ok || marcState() == MARC_TXFIFO_UNDERFLOW) { + strobe(SIDLE); + strobe(SFTX); + ok = false; + } + if (wasReceiving) startReceive(); + return ok; +} + +bool Cc1101::receive(Packet& packet) { + if (!running || !receiving) return false; + uint8_t state = marcState(); + if (state == MARC_RXFIFO_OVERFLOW) { + startReceive(); + return false; + } + if (state != MARC_IDLE) return false; // still receiving + // Errata: read RXBYTES until two reads agree. + uint8_t bytes = readStatus(RXBYTES), again; + while ((again = readStatus(RXBYTES)) != bytes) + bytes = again; + bytes &= 0x7F; + if (bytes < 3) { + startReceive(); + return false; + } + uint8_t len = 0; + xfer(FIFO | READ, nullptr, &len, 1); + if (len == 0 || len > MAX_PACKET || len + 3 > bytes) { + startReceive(); + return false; + } + xfer(FIFO | READ | BURST, nullptr, packet.data, len); + uint8_t st[2]; + xfer(FIFO | READ | BURST, nullptr, st, 2); + packet.length = len; + packet.rssi = (int8_t)st[0] / 2.0f - 74.0f; + packet.lqi = st[1] & 0x7F; + packet.crcOk = st[1] & 0x80; + startReceive(); + return true; +} + +float Cc1101::rssi() { + return (int8_t)readStatus(RSSI) / 2.0f - 74.0f; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/cc1101.h b/lib/lilka_modules/src/lilka_modules/cc1101.h new file mode 100644 index 0000000..c0bed39 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/cc1101.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include + +#include "pins.h" + +namespace lilka { +namespace mod { + +/// Субгігагерцове радіо TI CC1101 (модуль 004 RF з CC1101 у розкладці nRF24). +/// +/// Діапазони: 300-348, 387-464, 779-928 МГц. Кварц 26 МГц. +/// Пакети змінної довжини до 61 байта. Шина SPI має бути вже запущена. +class Cc1101 { +public: + static constexpr uint8_t MAX_PACKET = 61; + + enum class Modulation : uint8_t { + FSK2 = 0, + GFSK = 1, + ASK = 3, ///< ASK/OOK + FSK4 = 4, + MSK = 7, + }; + + struct Config { + SPIClass* spi = nullptr; + int csn = pins::SPI_CS; + int miso = pins::SPI_MISO; ///< для очікування CHIP_RDYn + int gdo0 = pins::RF_CE; + int gdo2 = pins::RF_IRQ; + float frequencyMhz = 433.92f; + Modulation modulation = Modulation::GFSK; + uint32_t dataRate = 38400; ///< бод, 600 ... 500000 + uint32_t deviationHz = 20000; ///< для FSK + uint32_t bandwidthHz = 100000; ///< 58 кГц ... 812 кГц + int8_t powerDbm = 0; ///< -30 ... 10 + uint16_t syncWord = 0xD391; + bool crc = true; + uint32_t xtalHz = 26000000; + uint32_t spiFrequency = 4000000; + }; + + struct Packet { + uint8_t data[MAX_PACKET]; + uint8_t length; + float rssi; + uint8_t lqi; + bool crcOk; + }; + + ~Cc1101(); + /// false - чип не відповідає або параметри поза межами. + bool begin(const Config& config); + void end(); + + bool setFrequency(float mhz); + void setPower(int8_t dbm); + + bool send(const uint8_t* data, uint8_t length, uint32_t timeoutMs = 500); + void startReceive(); + bool receive(Packet& packet); + void idle(); + bool isReceiving() const { + return receiving; + } + + /// RSSI, дБм (у режимі прийому). + float rssi(); + + uint8_t partNumber(); + uint8_t version(); + uint8_t readRegister(uint8_t reg); + void writeRegister(uint8_t reg, uint8_t value); + +private: + uint8_t xfer(uint8_t header, const uint8_t* tx, uint8_t* rx, size_t n); + uint8_t strobe(uint8_t s); + uint8_t readStatus(uint8_t reg); + uint8_t marcState(); + bool waitMarc(uint8_t state, uint32_t ms); + void reset(); + bool configure(); + + Config cfg; + SPISettings settings; + bool running = false; + bool receiving = false; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/gps.cpp b/lib/lilka_modules/src/lilka_modules/gps.cpp new file mode 100644 index 0000000..1965b2c --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/gps.cpp @@ -0,0 +1,84 @@ +#include "gps.h" + +namespace lilka { +namespace mod { + +Gps::~Gps() { + end(); +} + +esp_err_t Gps::begin(const Config& config) { + end(); + cfg = config; + uart_config_t uc = {}; + uc.baud_rate = (int)cfg.baud; + uc.data_bits = UART_DATA_8_BITS; + uc.parity = UART_PARITY_DISABLE; + uc.stop_bits = UART_STOP_BITS_1; + uc.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; + uc.source_clk = UART_SCLK_APB; + esp_err_t err = uart_driver_install(cfg.port, 2048, 0, 0, nullptr, 0); + if (err != ESP_OK) return err; + err = uart_param_config(cfg.port, &uc); + if (err == ESP_OK) { + err = uart_set_pin( + cfg.port, cfg.tx < 0 ? UART_PIN_NO_CHANGE : cfg.tx, cfg.rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE + ); + } + if (err != ESP_OK) { + uart_driver_delete(cfg.port); + return err; + } + parser.reset(); + running = true; + return ESP_OK; +} + +void Gps::end() { + if (!running) return; + uart_driver_delete(cfg.port); + running = false; +} + +int Gps::update() { + if (!running) return 0; + int sentences = 0; + uint8_t chunk[128]; + for (;;) { + int n = uart_read_bytes(cfg.port, chunk, sizeof(chunk), 0); + if (n <= 0) break; + for (int i = 0; i < n; i++) { + if (parser.feed((char)chunk[i])) sentences++; + } + } + return sentences; +} + +esp_err_t Gps::write(const uint8_t* data, size_t len) { + if (!running) return ESP_ERR_INVALID_STATE; + if (cfg.tx < 0) return ESP_ERR_NOT_SUPPORTED; + return uart_write_bytes(cfg.port, data, len) == (int)len ? ESP_OK : ESP_FAIL; +} + +esp_err_t Gps::sendUbx(uint8_t cls, uint8_t id, const uint8_t* payload, uint16_t len) { + uint8_t head[6] = {0xB5, 0x62, cls, id, (uint8_t)(len & 0xFF), (uint8_t)(len >> 8)}; + uint8_t ckA = 0, ckB = 0; + for (int i = 2; i < 6; i++) { + ckA += head[i]; + ckB += ckA; + } + for (uint16_t i = 0; i < len; i++) { + ckA += payload[i]; + ckB += ckA; + } + esp_err_t err = write(head, sizeof(head)); + if (err == ESP_OK && len) err = write(payload, len); + if (err == ESP_OK) { + const uint8_t tail[2] = {ckA, ckB}; + err = write(tail, sizeof(tail)); + } + return err; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/gps.h b/lib/lilka_modules/src/lilka_modules/gps.h new file mode 100644 index 0000000..fca84de --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/gps.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include + +#include "nmea.h" +#include "pins.h" + +namespace lilka { +namespace mod { + +/// GNSS-приймач з NMEA-виходом на UART (модуль 005 GPS, u-blox NEO-M8N). +class Gps { +public: + struct Config { + uart_port_t port = UART_NUM_2; + int rx = pins::UART_RX; ///< Вхід у Лілку (TX модуля) + int tx = pins::UART_TX; ///< Вихід з Лілки (RX модуля), NC - лише прийом + uint32_t baud = 9600; + }; + + ~Gps(); + esp_err_t begin(const Config& config); + void end(); + bool isRunning() const { + return running; + } + + /// Прочитати все, що прийшло з UART, і розібрати. Повертає кількість нових речень. + int update(); + + const Nmea& nmea() const { + return parser; + } + const GpsFix& fix() const { + return parser.fix(); + } + + /// Надіслати сирі байти (наприклад, NMEA-команду PUBX або UBX). + esp_err_t write(const uint8_t* data, size_t len); + /// Надіслати UBX-повідомлення (контрольна сума рахується тут). + esp_err_t sendUbx(uint8_t cls, uint8_t id, const uint8_t* payload, uint16_t len); + +private: + Config cfg; + bool running = false; + Nmea parser; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/ir.cpp b/lib/lilka_modules/src/lilka_modules/ir.cpp new file mode 100644 index 0000000..bcf61c5 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/ir.cpp @@ -0,0 +1,164 @@ +#include "ir.h" + +#if CONFIG_IDF_TARGET_ESP32S3 + +# include +# include + +namespace lilka { +namespace mod { + +static const uint32_t RMT_SRC_HZ = 80000000; // APB +static const uint8_t RMT_DIV = 80; // 1 tick = 1 us +static const uint16_t MAX_TICKS = 32767; + +Ir::~Ir() { + end(); +} + +esp_err_t Ir::begin(const Config& config) { + end(); + cfg = config; + esp_err_t err; + if (cfg.tx >= 0) { + rmt_config_t tx = RMT_DEFAULT_CONFIG_TX((gpio_num_t)cfg.tx, cfg.txChannel); + tx.clk_div = RMT_DIV; + tx.tx_config.carrier_en = true; + tx.tx_config.carrier_freq_hz = cfg.carrierHz; + tx.tx_config.carrier_duty_percent = cfg.dutyPercent; + tx.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH; + tx.tx_config.idle_level = RMT_IDLE_LEVEL_LOW; + tx.tx_config.idle_output_en = true; + err = rmt_config(&tx); + if (err == ESP_OK) err = rmt_driver_install(cfg.txChannel, 0, 0); + if (err != ESP_OK) return err; + txItems = new (std::nothrow) rmt_item32_t[MAX_DURATIONS / 2 + 1]; + if (!txItems) { + end(); + return ESP_ERR_NO_MEM; + } + txReady = true; + currentCarrier = cfg.carrierHz; + } + if (cfg.rx >= 0) { + rmt_config_t rx = RMT_DEFAULT_CONFIG_RX((gpio_num_t)cfg.rx, cfg.rxChannel); + rx.clk_div = RMT_DIV; + rx.mem_block_num = 4; + rx.rx_config.filter_en = true; + rx.rx_config.filter_ticks_thresh = 200; // in APB ticks: drop glitches < 2.5 us + rx.rx_config.idle_threshold = cfg.rxIdleUs; + err = rmt_config(&rx); + if (err == ESP_OK) err = rmt_driver_install(cfg.rxChannel, 4096, 0); + if (err == ESP_OK) err = rmt_get_ringbuf_handle(cfg.rxChannel, &rxBuffer); + if (err == ESP_OK) { + rxReady = true; + err = rmt_rx_start(cfg.rxChannel, true); + } + if (err != ESP_OK) { + end(); + return err; + } + } + return ESP_OK; +} + +void Ir::end() { + if (txReady) { + rmt_driver_uninstall(cfg.txChannel); + txReady = false; + } + if (rxReady) { + rmt_rx_stop(cfg.rxChannel); + rmt_driver_uninstall(cfg.rxChannel); + rxReady = false; + rxBuffer = nullptr; + } + delete[] txItems; + txItems = nullptr; +} + +esp_err_t Ir::sendRaw(const uint16_t* durations, size_t count, uint32_t carrierHz) { + if (!txReady) return ESP_ERR_INVALID_STATE; + if (count == 0) return ESP_OK; + if (count > MAX_DURATIONS) return ESP_ERR_INVALID_SIZE; + if (carrierHz == 0) carrierHz = cfg.carrierHz; + if (carrierHz != currentCarrier) { + uint32_t period = RMT_SRC_HZ / carrierHz; + uint16_t high = period * cfg.dutyPercent / 100; + esp_err_t err = rmt_set_tx_carrier(cfg.txChannel, true, high, period - high, RMT_CARRIER_LEVEL_HIGH); + if (err != ESP_OK) return err; + currentCarrier = carrierHz; + } + size_t items = 0; + for (size_t i = 0; i < count; i += 2) { + rmt_item32_t& it = txItems[items++]; + it.level0 = 1; + it.duration0 = durations[i] > MAX_TICKS ? MAX_TICKS : durations[i]; + it.level1 = 0; + uint16_t space = i + 1 < count ? durations[i + 1] : 0; + it.duration1 = space > MAX_TICKS ? MAX_TICKS : space; + } + if (count % 2 == 0) { + txItems[items++].val = 0; // end marker + } + return rmt_write_items(cfg.txChannel, txItems, items, true); +} + +esp_err_t Ir::send(const IrCode& code, uint8_t repeats) { + uint16_t buf[80]; + size_t n = IrCodec::encode(code, buf, 80); + if (!n) return ESP_ERR_NOT_SUPPORTED; + uint32_t gap = IrCodec::repeatGapMs(code.protocol); + for (int i = 0; i <= repeats; i++) { + if (i) vTaskDelay(pdMS_TO_TICKS(gap)); + size_t len = n; + if (i && code.protocol == IrProtocol::NEC) len = IrCodec::encodeNecRepeat(buf, 80); + esp_err_t err = sendRaw(buf, len); + if (err != ESP_OK) return err; + } + return ESP_OK; +} + +size_t Ir::receiveRaw(uint16_t* out, size_t max) { + if (!rxReady) return 0; + for (;;) { + size_t size = 0; + rmt_item32_t* items = static_cast(xRingbufferReceive(rxBuffer, &size, 0)); + if (!items) return 0; + size_t count = size / sizeof(rmt_item32_t); + size_t n = 0; + bool started = false; + int lastMark = -1; + for (size_t i = 0; i < count && n < max; i++) { + for (int half = 0; half < 2 && n < max; half++) { + uint16_t dur = half ? items[i].duration1 : items[i].duration0; + int level = half ? items[i].level1 : items[i].level0; + if (dur == 0) { + i = count; // end of frame + break; + } + bool mark = cfg.rxActiveLow ? level == 0 : level == 1; + if (!started) { + if (!mark) continue; + started = true; + } + if ((int)mark == lastMark && n) { + uint32_t sum = (uint32_t)out[n - 1] + dur; + out[n - 1] = sum > 0xFFFF ? 0xFFFF : sum; + } else { + out[n++] = dur; + lastMark = mark; + } + } + } + vRingbufferReturnItem(rxBuffer, items); + // Trailing space (if any) is the idle timeout, not part of the frame. + if (n && n % 2 == 0) n--; + if (n >= 3) return n; // anything shorter is noise + } +} + +} // namespace mod +} // namespace lilka + +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/lib/lilka_modules/src/lilka_modules/ir.h b/lib/lilka_modules/src/lilka_modules/ir.h new file mode 100644 index 0000000..734f53a --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/ir.h @@ -0,0 +1,61 @@ +#pragma once + +#include + +// RMT channel layout below is for the ESP32-S3 (Lilka v2). +#if CONFIG_IDF_TARGET_ESP32S3 + +# include +# include +# include + +# include "ir_codec.h" +# include "pins.h" + +namespace lilka { +namespace mod { + +/// ІЧ-передавач і приймач на периферії RMT (модуль 002 IR: KY-005 + KY-022). +/// +/// Використовує канали RMT_CHANNEL_3 (передача) і RMT_CHANNEL_4 (прийом, займає пам'ять каналів 4-7), +/// щоб не заважати драйверам Arduino, які беруть канали з початку. +class Ir { +public: + static constexpr size_t MAX_DURATIONS = 380; + + struct Config { + int tx = pins::UART_TX; ///< NC - без передавача + int rx = pins::UART_RX; ///< NC - без приймача + uint32_t carrierHz = 38000; + uint8_t dutyPercent = 33; + bool rxActiveLow = true; ///< KY-022 / VS1838B тримає 0, поки бачить несучу + uint16_t rxIdleUs = 12000; ///< пауза, що завершує кадр + rmt_channel_t txChannel = RMT_CHANNEL_3; + rmt_channel_t rxChannel = RMT_CHANNEL_4; + }; + + ~Ir(); + esp_err_t begin(const Config& config); + void end(); + + /// Надіслати сирі тривалості (мкс, починаючи з імпульсу). carrierHz = 0 - взяти з конфігурації. + esp_err_t sendRaw(const uint16_t* durations, size_t count, uint32_t carrierHz = 0); + /// Закодувати й надіслати кадр (repeats - скільки разів повторити, для Sony мінімум 3 загалом). + esp_err_t send(const IrCode& code, uint8_t repeats = 0); + + /// Забрати один прийнятий кадр (без очікування). Повертає кількість тривалостей, 0 - нічого немає. + size_t receiveRaw(uint16_t* out, size_t max); + +private: + Config cfg; + bool txReady = false; + bool rxReady = false; + RingbufHandle_t rxBuffer = nullptr; + uint32_t currentCarrier = 0; + rmt_item32_t* txItems = nullptr; +}; + +} // namespace mod +} // namespace lilka + +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/lib/lilka_modules/src/lilka_modules/ir_codec.cpp b/lib/lilka_modules/src/lilka_modules/ir_codec.cpp new file mode 100644 index 0000000..309e93f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/ir_codec.cpp @@ -0,0 +1,178 @@ +#include "ir_codec.h" + +namespace lilka { +namespace mod { +namespace IrCodec { + +// NEC / Samsung timings +static const uint16_t NEC_HDR_MARK = 9000; +static const uint16_t NEC_HDR_SPACE = 4500; +static const uint16_t NEC_RPT_SPACE = 2250; +static const uint16_t SAMSUNG_HDR_MARK = 4500; +static const uint16_t SAMSUNG_HDR_SPACE = 4500; +static const uint16_t PULSE_BIT_MARK = 560; +static const uint16_t PULSE_ONE_SPACE = 1690; +static const uint16_t PULSE_ZERO_SPACE = 560; +// Sony SIRC timings +static const uint16_t SONY_HDR_MARK = 2400; +static const uint16_t SONY_SPACE = 600; +static const uint16_t SONY_ONE_MARK = 1200; +static const uint16_t SONY_ZERO_MARK = 600; + +// Demodulating receivers stretch/shrink marks by ~100 us, so be generous. +static bool match(uint16_t measured, uint16_t expected) { + uint32_t tol = expected * 30 / 100 + 100; + return measured + tol >= expected && measured <= expected + tol; +} + +static size_t encodePulseDistance(uint16_t hdrMark, uint16_t hdrSpace, uint32_t data, uint16_t* out, size_t max) { + const size_t need = 2 + 32 * 2 + 1; + if (max < need) return 0; + size_t n = 0; + out[n++] = hdrMark; + out[n++] = hdrSpace; + for (int i = 0; i < 32; i++) { + out[n++] = PULSE_BIT_MARK; + out[n++] = (data >> i) & 1 ? PULSE_ONE_SPACE : PULSE_ZERO_SPACE; + } + out[n++] = PULSE_BIT_MARK; + return n; +} + +static bool decodePulseDistance(const uint16_t* d, size_t count, uint16_t hdrMark, uint16_t hdrSpace, uint32_t& data) { + if (count < 2 + 32 * 2 + 1) return false; + if (!match(d[0], hdrMark) || !match(d[1], hdrSpace)) return false; + data = 0; + for (int i = 0; i < 32; i++) { + uint16_t mark = d[2 + i * 2], space = d[3 + i * 2]; + if (!match(mark, PULSE_BIT_MARK)) return false; + if (match(space, PULSE_ONE_SPACE)) { + data |= 1UL << i; + } else if (!match(space, PULSE_ZERO_SPACE)) { + return false; + } + } + return match(d[66], PULSE_BIT_MARK); +} + +size_t encode(const IrCode& code, uint16_t* out, size_t max) { + switch (code.protocol) { + case IrProtocol::NEC: { + if (code.repeat) return encodeNecRepeat(out, max); + uint32_t addr = + code.address > 0xFF ? (code.address & 0xFFFF) : ((code.address & 0xFF) | ((~code.address & 0xFF) << 8)); + uint32_t data = addr | ((code.command & 0xFF) << 16) | ((~code.command & 0xFF) << 24); + return encodePulseDistance(NEC_HDR_MARK, NEC_HDR_SPACE, data, out, max); + } + case IrProtocol::Samsung: { + uint32_t a = code.address & 0xFF; + uint32_t data = a | (a << 8) | ((code.command & 0xFF) << 16) | ((~code.command & 0xFF) << 24); + return encodePulseDistance(SAMSUNG_HDR_MARK, SAMSUNG_HDR_SPACE, data, out, max); + } + case IrProtocol::Sony: { + uint8_t bits = code.bits == 15 || code.bits == 20 ? code.bits : 12; + size_t need = 2 + bits * 2 - 1; + if (max < need) return 0; + uint32_t data = (code.command & 0x7F) | (code.address << 7); + size_t n = 0; + out[n++] = SONY_HDR_MARK; + out[n++] = SONY_SPACE; + for (int i = 0; i < bits; i++) { + out[n++] = (data >> i) & 1 ? SONY_ONE_MARK : SONY_ZERO_MARK; + if (i != bits - 1) out[n++] = SONY_SPACE; + } + return n; + } + default: + return 0; + } +} + +size_t encodeNecRepeat(uint16_t* out, size_t max) { + if (max < 3) return 0; + out[0] = NEC_HDR_MARK; + out[1] = NEC_RPT_SPACE; + out[2] = PULSE_BIT_MARK; + return 3; +} + +static bool decodeSony(const uint16_t* d, size_t count, IrCode& out) { + if (count < 2 || !match(d[0], SONY_HDR_MARK) || !match(d[1], SONY_SPACE)) return false; + size_t marks = (count - 1) / 2; // header space + (mark, space)*; the last space may be missing + if (marks != 12 && marks != 15 && marks != 20) return false; + uint32_t data = 0; + for (size_t i = 0; i < marks; i++) { + uint16_t mark = d[2 + i * 2]; + if (match(mark, SONY_ONE_MARK)) { + data |= 1UL << i; + } else if (!match(mark, SONY_ZERO_MARK)) { + return false; + } + if (i != marks - 1 && !match(d[3 + i * 2], SONY_SPACE)) return false; + } + out.protocol = IrProtocol::Sony; + out.command = data & 0x7F; + out.address = data >> 7; + out.bits = marks; + out.repeat = false; + return true; +} + +bool decode(const uint16_t* d, size_t count, IrCode& out) { + out = {}; + uint32_t data; + if (count >= 3 && count < 10 && match(d[0], NEC_HDR_MARK) && match(d[1], NEC_RPT_SPACE) && + match(d[2], PULSE_BIT_MARK)) { + out.protocol = IrProtocol::NEC; + out.repeat = true; + return true; + } + if (decodePulseDistance(d, count, NEC_HDR_MARK, NEC_HDR_SPACE, data)) { + uint8_t a = data & 0xFF, na = (data >> 8) & 0xFF, c = (data >> 16) & 0xFF, nc = data >> 24; + if ((uint8_t)~c != nc) return false; + out.protocol = IrProtocol::NEC; + out.address = (uint8_t)~a == na ? a : (data & 0xFFFF); + out.command = c; + out.bits = 32; + return true; + } + if (decodePulseDistance(d, count, SAMSUNG_HDR_MARK, SAMSUNG_HDR_SPACE, data)) { + uint8_t c = (data >> 16) & 0xFF, nc = data >> 24; + if ((uint8_t)~c != nc) return false; + out.protocol = IrProtocol::Samsung; + out.address = data & 0xFF; + out.command = c; + out.bits = 32; + return true; + } + return decodeSony(d, count, out); +} + +uint32_t repeatGapMs(IrProtocol protocol) { + switch (protocol) { + case IrProtocol::Sony: + return 25; // 45 ms frame period + case IrProtocol::NEC: + case IrProtocol::Samsung: + return 40; // ~108 ms frame period + default: + return 50; + } +} + +const char* name(IrProtocol protocol) { + switch (protocol) { + case IrProtocol::NEC: + return "NEC"; + case IrProtocol::Samsung: + return "SAMSUNG"; + case IrProtocol::Sony: + return "SONY"; + default: + return "UNKNOWN"; + } +} + +} // namespace IrCodec +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/ir_codec.h b/lib/lilka_modules/src/lilka_modules/ir_codec.h new file mode 100644 index 0000000..c5697fa --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/ir_codec.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +namespace lilka { +namespace mod { + +/// ІЧ-протоколи, які вміє кодувати і розпізнавати IrCodec. +enum class IrProtocol : uint8_t { + Unknown, + NEC, ///< 8-бітна адреса (або 16-бітна "extended"), 8-бітна команда + Samsung, ///< 8-бітна адреса, 8-бітна команда + Sony, ///< SIRC: 7-бітна команда, 5/8/13-бітна адреса (12/15/20 біт) +}; + +struct IrCode { + IrProtocol protocol; + uint32_t address; + uint32_t command; + uint8_t bits; ///< для Sony: 12, 15 або 20 + bool repeat; ///< NEC: кадр повторення (кнопку утримують) +}; + +/// Кодування/декодування ІЧ-кадрів у вигляді тривалостей імпульсів (мкс). +/// +/// Тривалості чергуються: імпульс (несуча увімкнена), пауза, імпульс, ...; перший елемент - імпульс. +namespace IrCodec { + +/// Закодувати кадр. Повертає кількість тривалостей або 0, якщо не вистачило місця / протокол невідомий. +size_t encode(const IrCode& code, uint16_t* out, size_t max); +/// Закодувати кадр повторення NEC. +size_t encodeNecRepeat(uint16_t* out, size_t max); +/// Розпізнати кадр. Повертає false, якщо жоден протокол не підійшов. +bool decode(const uint16_t* durations, size_t count, IrCode& out); +/// Рекомендована пауза між повтореннями кадру, мс. +uint32_t repeatGapMs(IrProtocol protocol); +/// Назва протоколу ("NEC", "SAMSUNG", "SONY" або "UNKNOWN"). +const char* name(IrProtocol protocol); + +} // namespace IrCodec + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/nmea.cpp b/lib/lilka_modules/src/lilka_modules/nmea.cpp new file mode 100644 index 0000000..bdcc4fc --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/nmea.cpp @@ -0,0 +1,182 @@ +#include "nmea.h" + +#include +#include + +namespace lilka { +namespace mod { + +static int hexValue(char c) { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + return -1; +} + +// "ddmm.mmmm" + hemisphere -> signed degrees +static double parseCoord(const char* v, const char* hemi) { + if (!*v) return 0; + double raw = strtod(v, nullptr); + int deg = (int)(raw / 100); + double result = deg + (raw - deg * 100) / 60.0; + if (*hemi == 'S' || *hemi == 'W') result = -result; + return result; +} + +static int twoDigits(const char* s) { + return (s[0] - '0') * 10 + (s[1] - '0'); +} + +Nmea::Nmea() : buf{}, len(0), inSentence(false), last{}, badChecksums(0), fixData{}, sats{}, satCount(0) { +} + +void Nmea::reset() { + len = 0; + inSentence = false; + last[0] = 0; + badChecksums = 0; + fixData = {}; + satCount = 0; +} + +bool Nmea::feed(char c) { + if (c == '$') { + inSentence = true; + len = 0; + return false; + } + if (!inSentence) return false; + if (c == '\r' || c == '\n') { + inSentence = false; + return finish(); + } + if (len >= MAX_SENTENCE) { + inSentence = false; // too long, drop + return false; + } + buf[len++] = c; + return false; +} + +bool Nmea::finish() { + buf[len] = 0; + char* star = strchr(buf, '*'); + if (!star || star[1] == 0 || star[2] == 0) return false; + uint8_t sum = 0; + for (const char* p = buf; p < star; p++) + sum ^= (uint8_t)*p; + int hi = hexValue(star[1]), lo = hexValue(star[2]); + if (hi < 0 || lo < 0 || sum != ((hi << 4) | lo)) { + badChecksums++; + return false; + } + memcpy(last, buf, len + 1); + *star = 0; + + // Split in place; empty fields stay as "". + char* fields[24]; + int n = 0; + char* p = buf; + fields[n++] = p; + while (*p && n < 24) { + if (*p == ',') { + *p = 0; + fields[n++] = p + 1; + } + p++; + } + parse(fields, n); + return true; +} + +void Nmea::parse(char** f, int n) { + const char* id = f[0]; + if (strlen(id) != 5) return; // "GPGGA", "GNRMC", ... + const char* type = id + 2; + if (!strcmp(type, "GGA")) { + parseGga(f, n); + } else if (!strcmp(type, "RMC")) { + parseRmc(f, n); + } else if (!strcmp(type, "GSA")) { + parseGsa(f, n); + } else if (!strcmp(type, "GSV")) { + parseGsv(id[1], f, n); + } +} + +void Nmea::parseTime(const char* s) { + if (strlen(s) < 6) return; + fixData.hour = twoDigits(s); + fixData.minute = twoDigits(s + 2); + fixData.second = twoDigits(s + 4); + fixData.millis = s[6] == '.' ? (uint16_t)(strtof(s + 6, nullptr) * 1000) : 0; +} + +// $GPGGA,time,lat,N,lon,E,quality,sats,hdop,alt,M,geoid,M,age,station +void Nmea::parseGga(char** f, int n) { + if (n < 10) return; + parseTime(f[1]); + fixData.quality = atoi(f[6]); + fixData.satellites = atoi(f[7]); + if (*f[8]) fixData.hdop = strtof(f[8], nullptr); + if (fixData.quality) { + fixData.latitude = parseCoord(f[2], f[3]); + fixData.longitude = parseCoord(f[4], f[5]); + fixData.altitude = strtof(f[9], nullptr); + } + fixData.updates++; +} + +// $GPRMC,time,status,lat,N,lon,E,speed_kn,course,date,magvar,E,mode +void Nmea::parseRmc(char** f, int n) { + if (n < 10) return; + parseTime(f[1]); + fixData.valid = f[2][0] == 'A'; + if (fixData.valid) { + fixData.latitude = parseCoord(f[3], f[4]); + fixData.longitude = parseCoord(f[5], f[6]); + fixData.speedKmh = strtof(f[7], nullptr) * 1.852f; + if (*f[8]) fixData.course = strtof(f[8], nullptr); + } + if (strlen(f[9]) == 6) { + fixData.day = twoDigits(f[9]); + fixData.month = twoDigits(f[9] + 2); + fixData.year = 2000 + twoDigits(f[9] + 4); + } + fixData.updates++; +} + +// $GPGSA,mode,fix,sv1..sv12,pdop,hdop,vdop +void Nmea::parseGsa(char** f, int n) { + if (n < 18) return; + fixData.fixType = atoi(f[2]); + if (*f[15]) fixData.pdop = strtof(f[15], nullptr); + if (*f[16]) fixData.hdop = strtof(f[16], nullptr); + if (*f[17]) fixData.vdop = strtof(f[17], nullptr); +} + +// $GPGSV,total,num,inview,{prn,elev,az,snr}x4 +void Nmea::parseGsv(char talker, char** f, int n) { + if (n < 4) return; + int msgNum = atoi(f[2]); + if (msgNum == 1) { + // New cycle for this constellation: drop its old entries. + size_t w = 0; + for (size_t r = 0; r < satCount; r++) { + if (sats[r].system != talker) sats[w++] = sats[r]; + } + satCount = w; + } + for (int i = 4; i < n; i += 4) { + if (!*f[i] || satCount >= MAX_SATELLITES) continue; + GpsSatellite& s = sats[satCount++]; + s.system = talker; + s.prn = atoi(f[i]); + s.elevation = i + 1 < n ? atoi(f[i + 1]) : 0; + s.azimuth = i + 2 < n ? atoi(f[i + 2]) : 0; + s.snr = (i + 3 < n && *f[i + 3]) ? atoi(f[i + 3]) : -1; + } +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/nmea.h b/lib/lilka_modules/src/lilka_modules/nmea.h new file mode 100644 index 0000000..372064f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/nmea.h @@ -0,0 +1,86 @@ +#pragma once + +#include +#include + +namespace lilka { +namespace mod { + +/// Дані про розташування, зібрані з NMEA-речень (GGA, RMC, GSA, GSV). +struct GpsFix { + bool valid; ///< RMC status = A (є фіксація) + uint8_t quality; ///< GGA: 0 - немає, 1 - GPS, 2 - DGPS, 4/5 - RTK, 6 - оцінка + uint8_t fixType; ///< GSA: 1 - немає, 2 - 2D, 3 - 3D + double latitude; ///< градуси, південь < 0 + double longitude; ///< градуси, захід < 0 + float altitude; ///< метри над рівнем моря + float speedKmh; ///< км/год + float course; ///< градуси від півночі + float hdop, vdop, pdop; + uint8_t satellites; ///< супутники, що використовуються (GGA) + uint16_t year; ///< UTC + uint8_t month, day, hour, minute, second; + uint16_t millis; + uint32_t updates; ///< кількість розібраних GGA/RMC з моменту старту +}; + +/// Супутник у полі зору (GSV). +struct GpsSatellite { + char system; ///< 'P' - GPS, 'L' - ГЛОНАСС, 'A' - Galileo, 'B' - BeiDou, 'N' - інші + uint8_t prn; + uint8_t elevation; ///< градуси + uint16_t azimuth; ///< градуси + int8_t snr; ///< дБГц, -1 якщо не відстежується +}; + +/// Розбирач NMEA 0183 без доступу до заліза. Байти подаються по одному через feed(). +class Nmea { +public: + static constexpr size_t MAX_SENTENCE = 96; + static constexpr size_t MAX_SATELLITES = 48; + + Nmea(); + void reset(); + + /// Подати один байт. Повертає true, коли розібрано повне речення з правильною контрольною сумою. + bool feed(char c); + + const GpsFix& fix() const { + return fixData; + } + size_t satelliteCount() const { + return satCount; + } + const GpsSatellite& satellite(size_t i) const { + return sats[i]; + } + /// Останнє коректне речення (без CR/LF). + const char* lastSentence() const { + return last; + } + uint32_t checksumErrors() const { + return badChecksums; + } + +private: + bool finish(); + void parse(char** f, int n); + void parseGga(char** f, int n); + void parseRmc(char** f, int n); + void parseGsa(char** f, int n); + void parseGsv(char talker, char** f, int n); + void parseTime(const char* s); + + char buf[MAX_SENTENCE + 1]; + size_t len; + bool inSentence; + char last[MAX_SENTENCE + 1]; + uint32_t badChecksums; + + GpsFix fixData; + GpsSatellite sats[MAX_SATELLITES]; + size_t satCount; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/nrf24.cpp b/lib/lilka_modules/src/lilka_modules/nrf24.cpp new file mode 100644 index 0000000..d701d4b --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/nrf24.cpp @@ -0,0 +1,279 @@ +#include "nrf24.h" + +#include +#include +#include +#include +#include + +namespace lilka { +namespace mod { + +enum : uint8_t { + REG_CONFIG = 0x00, + REG_EN_AA = 0x01, + REG_EN_RXADDR = 0x02, + REG_SETUP_AW = 0x03, + REG_SETUP_RETR = 0x04, + REG_RF_CH = 0x05, + REG_RF_SETUP = 0x06, + REG_STATUS = 0x07, + REG_RPD = 0x09, + REG_RX_ADDR_P0 = 0x0A, + REG_TX_ADDR = 0x10, + REG_RX_PW_P0 = 0x11, + REG_FIFO_STATUS = 0x17, + REG_DYNPD = 0x1C, + REG_FEATURE = 0x1D, + + CMD_R_REGISTER = 0x00, + CMD_W_REGISTER = 0x20, + CMD_R_RX_PAYLOAD = 0x61, + CMD_W_TX_PAYLOAD = 0xA0, + CMD_FLUSH_TX = 0xE1, + CMD_FLUSH_RX = 0xE2, + CMD_R_RX_PL_WID = 0x60, + CMD_NOP = 0xFF, + + CONFIG_PRIM_RX = 0x01, + CONFIG_PWR_UP = 0x02, + CONFIG_CRCO = 0x04, + CONFIG_EN_CRC = 0x08, + STATUS_MAX_RT = 0x10, + STATUS_TX_DS = 0x20, + STATUS_RX_DR = 0x40, + FIFO_RX_EMPTY = 0x01, +}; + +static uint32_t nowMs() { + return (uint32_t)(esp_timer_get_time() / 1000); +} + +Nrf24::~Nrf24() { + end(); +} + +uint8_t Nrf24::xfer(uint8_t command, const uint8_t* tx, uint8_t* rx, size_t n) { + cfg.spi->beginTransaction(settings); + digitalWrite(cfg.csn, LOW); + uint8_t st = cfg.spi->transfer(command); + for (size_t i = 0; i < n; i++) { + uint8_t r = cfg.spi->transfer(tx ? tx[i] : 0xFF); + if (rx) rx[i] = r; + } + digitalWrite(cfg.csn, HIGH); + cfg.spi->endTransaction(); + return st; +} + +uint8_t Nrf24::readRegister(uint8_t reg) { + uint8_t v = 0; + xfer(CMD_R_REGISTER | (reg & 0x1F), nullptr, &v, 1); + return v; +} + +void Nrf24::writeRegister(uint8_t reg, uint8_t value) { + xfer(CMD_W_REGISTER | (reg & 0x1F), &value, nullptr, 1); +} + +void Nrf24::writeRegister(uint8_t reg, const uint8_t* data, size_t n) { + xfer(CMD_W_REGISTER | (reg & 0x1F), data, nullptr, n); +} + +uint8_t Nrf24::status() { + return xfer(CMD_NOP, nullptr, nullptr, 0); +} + +bool Nrf24::begin(const Config& config) { + end(); + cfg = config; + if (!cfg.spi) return false; + if (cfg.addressWidth < 3 || cfg.addressWidth > 5) cfg.addressWidth = 5; + if (cfg.payloadSize > MAX_PAYLOAD) cfg.payloadSize = MAX_PAYLOAD; + if (cfg.channel >= CHANNELS) cfg.channel = CHANNELS - 1; + if (cfg.autoAck && cfg.crcBytes == 0) cfg.crcBytes = 1; + settings = SPISettings(cfg.spiFrequency, MSBFIRST, SPI_MODE0); + + pinMode(cfg.csn, OUTPUT); + digitalWrite(cfg.csn, HIGH); + pinMode(cfg.ce, OUTPUT); + digitalWrite(cfg.ce, LOW); + if (cfg.irq >= 0) pinMode(cfg.irq, INPUT); + vTaskDelay(pdMS_TO_TICKS(5)); + + // RF_SETUP is writable only on a real chip; 250 kbps (RF_DR_LOW) exists only on the L01+. + uint8_t rfSetup = (cfg.paLevel & 0x03) << 1; + if (cfg.dataRate == DataRate::Rate250K) rfSetup |= 0x20; + if (cfg.dataRate == DataRate::Rate2M) rfSetup |= 0x08; + writeRegister(REG_RF_SETUP, rfSetup); + if ((readRegister(REG_RF_SETUP) & 0x2E) != rfSetup) return false; + + writeRegister(REG_CONFIG, 0x00); // powered down while configuring + uint8_t ard = (uint8_t)((cfg.retryDelayUs / 250) ? (cfg.retryDelayUs / 250 - 1) : 0); + if (ard > 15) ard = 15; + writeRegister(REG_SETUP_RETR, (uint8_t)((ard << 4) | (cfg.retries & 0x0F))); + writeRegister(REG_SETUP_AW, cfg.addressWidth - 2); + writeRegister(REG_RF_CH, cfg.channel); + writeRegister(REG_EN_AA, cfg.autoAck ? 0x3F : 0x00); + writeRegister(REG_EN_RXADDR, 0x00); + bool dynamic = cfg.payloadSize == 0; + writeRegister(REG_FEATURE, dynamic ? 0x04 : 0x00); + writeRegister(REG_DYNPD, dynamic ? 0x3F : 0x00); + for (uint8_t p = 0; p < 6; p++) + writeRegister(REG_RX_PW_P0 + p, dynamic ? 0 : cfg.payloadSize); + xfer(CMD_FLUSH_TX, nullptr, nullptr, 0); + xfer(CMD_FLUSH_RX, nullptr, nullptr, 0); + writeRegister(REG_STATUS, STATUS_RX_DR | STATUS_TX_DS | STATUS_MAX_RT); + powerUp(false); + running = true; + listening = false; + pipe0Reading = false; + return true; +} + +void Nrf24::end() { + if (!running) return; + digitalWrite(cfg.ce, LOW); + writeRegister(REG_CONFIG, 0x00); // power down + running = false; + listening = false; +} + +void Nrf24::powerUp(bool rx) { + uint8_t c = CONFIG_PWR_UP; + if (cfg.crcBytes) c |= CONFIG_EN_CRC; + if (cfg.crcBytes == 2) c |= CONFIG_CRCO; + if (rx) c |= CONFIG_PRIM_RX; + uint8_t before = readRegister(REG_CONFIG); + writeRegister(REG_CONFIG, c); + if (!(before & CONFIG_PWR_UP)) vTaskDelay(pdMS_TO_TICKS(5)); // Tpd2stby +} + +void Nrf24::setChannel(uint8_t ch) { + if (ch >= CHANNELS) ch = CHANNELS - 1; + cfg.channel = ch; + writeRegister(REG_RF_CH, ch); +} + +void Nrf24::openWritingPipe(const uint8_t* address) { + memcpy(txAddress, address, cfg.addressWidth); + writeRegister(REG_TX_ADDR, address, cfg.addressWidth); + // Auto-ack arrives on pipe 0, so it must listen on the TX address while transmitting. + writeRegister(REG_RX_ADDR_P0, address, cfg.addressWidth); +} + +bool Nrf24::openReadingPipe(uint8_t pipe, const uint8_t* address) { + if (pipe > 5) return false; + if (pipe == 0) { + memcpy(pipe0Address, address, cfg.addressWidth); + pipe0Reading = true; + } + if (pipe < 2) { + writeRegister(REG_RX_ADDR_P0 + pipe, address, cfg.addressWidth); + } else { + writeRegister(REG_RX_ADDR_P0 + pipe, address[0]); + } + writeRegister(REG_EN_RXADDR, readRegister(REG_EN_RXADDR) | (1 << pipe)); + return true; +} + +void Nrf24::closeReadingPipe(uint8_t pipe) { + if (pipe > 5) return; + if (pipe == 0) pipe0Reading = false; + writeRegister(REG_EN_RXADDR, readRegister(REG_EN_RXADDR) & ~(1 << pipe)); +} + +void Nrf24::startListening() { + if (pipe0Reading) writeRegister(REG_RX_ADDR_P0, pipe0Address, cfg.addressWidth); + writeRegister(REG_STATUS, STATUS_RX_DR | STATUS_TX_DS | STATUS_MAX_RT); + powerUp(true); + digitalWrite(cfg.ce, HIGH); + delayMicroseconds(130); + listening = true; +} + +void Nrf24::stopListening() { + digitalWrite(cfg.ce, LOW); + delayMicroseconds(100); + powerUp(false); + // Restore pipe 0 for auto-ack of our own transmissions. + writeRegister(REG_RX_ADDR_P0, txAddress, cfg.addressWidth); + listening = false; +} + +bool Nrf24::send(const uint8_t* data, uint8_t length, uint32_t timeoutMs) { + if (!running) return false; + bool wasListening = listening; + if (wasListening) stopListening(); + if (length > MAX_PAYLOAD) length = MAX_PAYLOAD; + uint8_t buf[MAX_PAYLOAD] = {}; + memcpy(buf, data, length); + uint8_t size = cfg.payloadSize ? cfg.payloadSize : length; + + xfer(CMD_FLUSH_TX, nullptr, nullptr, 0); + writeRegister(REG_STATUS, STATUS_TX_DS | STATUS_MAX_RT); + xfer(CMD_W_TX_PAYLOAD, buf, nullptr, size); + digitalWrite(cfg.ce, HIGH); + delayMicroseconds(15); + digitalWrite(cfg.ce, LOW); + + uint8_t st = 0; + uint32_t t0 = nowMs(); + while (nowMs() - t0 < timeoutMs) { + st = status(); + if (st & (STATUS_TX_DS | STATUS_MAX_RT)) break; + delayMicroseconds(100); + } + writeRegister(REG_STATUS, STATUS_TX_DS | STATUS_MAX_RT); + if (!(st & STATUS_TX_DS)) xfer(CMD_FLUSH_TX, nullptr, nullptr, 0); + if (wasListening) startListening(); + return st & STATUS_TX_DS; +} + +bool Nrf24::available(uint8_t* pipe) { + if (!running) return false; + if (readRegister(REG_FIFO_STATUS) & FIFO_RX_EMPTY) return false; + if (pipe) *pipe = (status() >> 1) & 0x07; + return true; +} + +uint8_t Nrf24::read(uint8_t* buffer, uint8_t max) { + if (!available()) return 0; + uint8_t width = cfg.payloadSize; + if (!width) { + xfer(CMD_R_RX_PL_WID, nullptr, &width, 1); + if (width > MAX_PAYLOAD) { + xfer(CMD_FLUSH_RX, nullptr, nullptr, 0); // corrupted + return 0; + } + } + uint8_t tmp[MAX_PAYLOAD]; + xfer(CMD_R_RX_PAYLOAD, nullptr, tmp, width); + writeRegister(REG_STATUS, STATUS_RX_DR); + uint8_t n = width < max ? width : max; + memcpy(buffer, tmp, n); + return n; +} + +bool Nrf24::carrier() { + return readRegister(REG_RPD) & 0x01; +} + +bool Nrf24::probeChannel(uint8_t ch, uint32_t dwellUs) { + digitalWrite(cfg.ce, LOW); + setChannel(ch); + powerUp(true); + digitalWrite(cfg.ce, HIGH); + delayMicroseconds(dwellUs); + bool hit = carrier(); + if (listening) { + startListening(); // keeps listening, now on the probed channel + } else { + digitalWrite(cfg.ce, LOW); + powerUp(false); + } + return hit; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/nrf24.h b/lib/lilka_modules/src/lilka_modules/nrf24.h new file mode 100644 index 0000000..ec0bf0c --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/nrf24.h @@ -0,0 +1,95 @@ +#pragma once + +#include +#include + +#include "pins.h" + +namespace lilka { +namespace mod { + +/// Радіо 2.4 ГГц Nordic nRF24L01+ (модуль 004 RF). +/// +/// Шина SPI має бути вже запущена - драйвер її не запускає і не зупиняє. +class Nrf24 { +public: + static constexpr uint8_t CHANNELS = 126; + static constexpr uint8_t MAX_PAYLOAD = 32; + + enum class DataRate : uint8_t { + Rate250K, + Rate1M, + Rate2M, + }; + + struct Config { + SPIClass* spi = nullptr; + int csn = pins::SPI_CS; + int ce = pins::RF_CE; + int irq = pins::RF_IRQ; ///< лише читається; NC - не використовується + uint8_t channel = 76; ///< 0-125, частота = 2400 + channel МГц + DataRate dataRate = DataRate::Rate1M; + uint8_t paLevel = 3; ///< 0 (-18 дБм) ... 3 (0 дБм) + uint8_t addressWidth = 5; ///< 3-5 байт + uint8_t payloadSize = 32; ///< 1-32, 0 - динамічна довжина + bool autoAck = true; + uint8_t retries = 15; ///< 0-15 + uint16_t retryDelayUs = 1500; ///< 250-4000, крок 250 + uint8_t crcBytes = 2; ///< 0, 1 або 2 (з autoAck CRC обов'язковий) + uint32_t spiFrequency = 4000000; + }; + + ~Nrf24(); + /// false - чип не відповідає (або це не nRF24L01+). + bool begin(const Config& config); + void end(); + + void setChannel(uint8_t ch); + uint8_t channel() const { + return cfg.channel; + } + + /// Адреса передачі (і RX-канал 0 для автопідтвердження). Довжина - addressWidth. + void openWritingPipe(const uint8_t* address); + /// Канали 0-1 - повна адреса, 2-5 - лише молодший байт (старші як у каналу 1). + bool openReadingPipe(uint8_t pipe, const uint8_t* address); + void closeReadingPipe(uint8_t pipe); + + void startListening(); + void stopListening(); + bool isListening() const { + return listening; + } + + /// Надіслати пакет. З autoAck повертає true лише після підтвердження приймачем. + bool send(const uint8_t* data, uint8_t length, uint32_t timeoutMs = 100); + /// Чи є прийнятий пакет; pipe - номер каналу (може бути nullptr). + bool available(uint8_t* pipe = nullptr); + /// Прочитати пакет. Повертає довжину (0 - нічого немає). + uint8_t read(uint8_t* buffer, uint8_t max); + + /// RPD: на поточному каналі є сигнал сильніший за -64 дБм (у режимі прийому). + bool carrier(); + /// Послухати канал dwellUs мкс і повернути RPD. Режим прийому вмикається і вимикається тут. + bool probeChannel(uint8_t ch, uint32_t dwellUs = 260); + + uint8_t readRegister(uint8_t reg); + void writeRegister(uint8_t reg, uint8_t value); + +private: + uint8_t xfer(uint8_t command, const uint8_t* tx, uint8_t* rx, size_t n); + void writeRegister(uint8_t reg, const uint8_t* data, size_t n); + uint8_t status(); + void powerUp(bool rx); + + Config cfg; + SPISettings settings; + bool running = false; + bool listening = false; + uint8_t txAddress[5] = {}; + uint8_t pipe0Address[5] = {}; + bool pipe0Reading = false; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/pins.h b/lib/lilka_modules/src/lilka_modules/pins.h new file mode 100644 index 0000000..bf13a7f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/pins.h @@ -0,0 +1,62 @@ +#pragma once + +#include + +/// Типові контакти модулів розширення Лілки v2. +/// +/// Нумерація - GPIO ESP32-S3. Контакти 3-10 роз'єму розширення (J2 на схемах модулів): +/// +/// | Контакт | GPIO | Контакт | GPIO | +/// |---|---|---|---| +/// | 3 | 44 (U0RXD) | 7 | 21 | +/// | 4 | 43 (U0TXD) | 8 | 14 | +/// | 5 | 48 | 9 | 13 | +/// | 6 | 47 | 10 | 12 | + +// Older SDK releases don't define the UART pins of the extension header yet. +#ifndef LILKA_EXT_RX +# define LILKA_EXT_RX 44 +#endif +#ifndef LILKA_EXT_TX +# define LILKA_EXT_TX 43 +#endif + +namespace lilka { +namespace mod { +namespace pins { + +/// Контакт роз'єму не під'єднано. +constexpr int NC = -1; + +// UART-модулі (GPS, IR, CAN) +constexpr int UART_RX = LILKA_EXT_RX; ///< Вхід у Лілку (контакт 3) +constexpr int UART_TX = LILKA_EXT_TX; ///< Вихід з Лілки (контакт 4) + +// SPI-модулі (LORA, RF) +constexpr int SPI_SCK = LILKA_EXT_RX; ///< Контакт 3 +constexpr int SPI_MISO = LILKA_EXT_TX; ///< Контакт 4 +constexpr int SPI_MOSI = LILKA_P3; ///< Контакт 5 +constexpr int SPI_CS = LILKA_P4; ///< Контакт 6 + +// 003 LORA +constexpr int LORA_RXEN = LILKA_P5; ///< Контакт 7 +constexpr int LORA_TXEN = LILKA_P6; ///< Контакт 8 +constexpr int LORA_NRST = LILKA_P7; ///< Контакт 9 +constexpr int LORA_BUSY = LILKA_P8; ///< Контакт 10 + +// 004 RF +constexpr int RF_CE = LILKA_P5; ///< nRF24 CE / CC1101 GDO0 (контакт 7) +constexpr int RF_IRQ = LILKA_P6; ///< nRF24 IRQ / CC1101 GDO2 (контакт 8) + +// I2C-модулі (GYRO MAGNET) +constexpr int I2C_SDA = LILKA_EXT_RX; ///< Контакт 3 +constexpr int I2C_SCL = LILKA_EXT_TX; ///< Контакт 4 + +// 006 GYRO MAGNET +constexpr int MAG_INT = LILKA_P3; ///< Контакт 5 +constexpr int GYR_INT1 = LILKA_P4; ///< Контакт 6 +constexpr int GYR_INT2 = LILKA_P5; ///< Контакт 7 + +} // namespace pins +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/resources.cpp b/lib/lilka_modules/src/lilka_modules/resources.cpp new file mode 100644 index 0000000..5c998a4 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/resources.cpp @@ -0,0 +1,109 @@ +#include "resources.h" + +#include + +namespace lilka { +namespace mod { + +Resources resources; + +Resources::Resources() { + memset(pins, 0, sizeof(pins)); + memset(periphs, 0, sizeof(periphs)); + mux = portMUX_INITIALIZER_UNLOCKED; +} + +bool Resources::take(Slot& slot, const void* who) { + if (slot.refs && slot.owner != who) return false; + slot.owner = who; + slot.refs++; + return true; +} + +uint16_t Resources::give(Slot& slot, const void* who) { + if (!slot.refs || slot.owner != who) return 0; + slot.refs--; + if (!slot.refs) slot.owner = nullptr; + return slot.refs; +} + +bool Resources::claimPins(std::initializer_list gpios, const void* who, int* conflict) { + bool ok = true; + portENTER_CRITICAL(&mux); + for (int gpio : gpios) { + if (gpio < 0 || gpio >= SOC_GPIO_PIN_COUNT) continue; + if (pins[gpio].refs && pins[gpio].owner != who) { + if (conflict) *conflict = gpio; + ok = false; + break; + } + } + if (ok) { + for (int gpio : gpios) { + if (gpio < 0 || gpio >= SOC_GPIO_PIN_COUNT) continue; + take(pins[gpio], who); + } + } + portEXIT_CRITICAL(&mux); + return ok; +} + +void Resources::releasePins(std::initializer_list gpios, const void* who) { + portENTER_CRITICAL(&mux); + for (int gpio : gpios) { + if (gpio < 0 || gpio >= SOC_GPIO_PIN_COUNT) continue; + give(pins[gpio], who); + } + portEXIT_CRITICAL(&mux); +} + +bool Resources::claimPin(int gpio, const void* who) { + return claimPins({gpio}, who); +} + +void Resources::releasePin(int gpio, const void* who) { + releasePins({gpio}, who); +} + +bool Resources::claim(Periph periph, const void* who) { + portENTER_CRITICAL(&mux); + bool ok = take(periphs[static_cast(periph)], who); + portEXIT_CRITICAL(&mux); + return ok; +} + +uint16_t Resources::release(Periph periph, const void* who) { + portENTER_CRITICAL(&mux); + uint16_t left = give(periphs[static_cast(periph)], who); + portEXIT_CRITICAL(&mux); + return left; +} + +void Resources::releaseAll(const void* who) { + portENTER_CRITICAL(&mux); + for (Slot& slot : pins) { + if (slot.owner == who) slot = {nullptr, 0}; + } + for (Slot& slot : periphs) { + if (slot.owner == who) slot = {nullptr, 0}; + } + portEXIT_CRITICAL(&mux); +} + +const void* Resources::pinOwner(int gpio) { + if (gpio < 0 || gpio >= SOC_GPIO_PIN_COUNT) return nullptr; + portENTER_CRITICAL(&mux); + const void* o = pins[gpio].owner; + portEXIT_CRITICAL(&mux); + return o; +} + +const void* Resources::owner(Periph periph) { + portENTER_CRITICAL(&mux); + const void* o = periphs[static_cast(periph)].owner; + portEXIT_CRITICAL(&mux); + return o; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/resources.h b/lib/lilka_modules/src/lilka_modules/resources.h new file mode 100644 index 0000000..202ff9f --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/resources.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#include +#include +#include + +namespace lilka { +namespace mod { + +/// Периферія, яку може захопити лише один власник. +enum class Periph : uint8_t { + UART1, + UART2, + SPI2, + I2C0, + TWAI, + RMT_TX, + RMT_RX, + COUNT, +}; + +/// Облік контактів і периферії, які зараз використовуються. +/// +/// Власник - будь-який вказівник, що ідентифікує користувача (наприклад, стан Lua-скрипта). +/// Один власник може захоплювати той самий ресурс кілька разів (лічильник посилань), інші власники - ні. +/// Номери контактів < 0 (``pins::NC``) пропускаються. +class Resources { +public: + Resources(); + + /// Захопити контакти. Якщо хоча б один зайнятий іншим власником, нічого не захоплюється. + /// @param conflict Якщо не nullptr, сюди записується номер зайнятого контакту. + bool claimPins(std::initializer_list gpios, const void* who, int* conflict = nullptr); + /// Звільнити контакти (по одному посиланню на кожен). + void releasePins(std::initializer_list gpios, const void* who); + bool claimPin(int gpio, const void* who); + void releasePin(int gpio, const void* who); + + /// Захопити периферію. + bool claim(Periph periph, const void* who); + /// Звільнити периферію. Повертає кількість посилань, що залишились у цього власника. + uint16_t release(Periph periph, const void* who); + + /// Звільнити все, що захопив власник. + void releaseAll(const void* who); + + /// Власник контакту або nullptr. + const void* pinOwner(int gpio); + /// Власник периферії або nullptr. + const void* owner(Periph periph); + +private: + struct Slot { + const void* owner; + uint16_t refs; + }; + static bool take(Slot& slot, const void* who); + static uint16_t give(Slot& slot, const void* who); + + Slot pins[SOC_GPIO_PIN_COUNT]; + Slot periphs[static_cast(Periph::COUNT)]; + portMUX_TYPE mux; +}; + +/// Спільний облік ресурсів для всіх модулів. +extern Resources resources; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/sx126x.cpp b/lib/lilka_modules/src/lilka_modules/sx126x.cpp new file mode 100644 index 0000000..156acca --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/sx126x.cpp @@ -0,0 +1,437 @@ +#include "sx126x.h" + +#include +#include +#include +#include +#include + +namespace lilka { +namespace mod { + +// Opcodes +enum : uint8_t { + OP_SET_SLEEP = 0x84, + OP_SET_STANDBY = 0x80, + OP_SET_TX = 0x83, + OP_SET_RX = 0x82, + OP_SET_REGULATOR = 0x96, + OP_CALIBRATE = 0x89, + OP_CALIBRATE_IMAGE = 0x98, + OP_SET_PA_CONFIG = 0x95, + OP_SET_DIO_IRQ = 0x08, + OP_GET_IRQ = 0x12, + OP_CLEAR_IRQ = 0x02, + OP_SET_TCXO = 0x97, + OP_SET_RF_FREQ = 0x86, + OP_SET_PACKET_TYPE = 0x8A, + OP_SET_TX_PARAMS = 0x8E, + OP_SET_MOD_PARAMS = 0x8B, + OP_SET_PACKET_PARAMS = 0x8C, + OP_SET_BUFFER_BASE = 0x8F, + OP_GET_STATUS = 0xC0, + OP_GET_RSSI_INST = 0x15, + OP_GET_RX_BUFFER_STATUS = 0x13, + OP_GET_PACKET_STATUS = 0x14, + OP_GET_DEVICE_ERRORS = 0x17, + OP_CLEAR_DEVICE_ERRORS = 0x07, + OP_WRITE_REGISTER = 0x0D, + OP_READ_REGISTER = 0x1D, + OP_WRITE_BUFFER = 0x0E, + OP_READ_BUFFER = 0x1E, +}; + +enum : uint16_t { + REG_SYNC_WORD = 0x0740, + REG_IQ_POLARITY = 0x0736, + REG_TX_CLAMP = 0x08D8, + IRQ_TX_DONE = 0x0001, + IRQ_RX_DONE = 0x0002, + IRQ_HEADER_ERR = 0x0020, + IRQ_CRC_ERR = 0x0040, + IRQ_TIMEOUT = 0x0200, +}; + +static uint32_t nowMs() { + return (uint32_t)(esp_timer_get_time() / 1000); +} + +static bool bandwidthCode(uint32_t hz, uint8_t& code) { + static const struct { + uint32_t hz; + uint8_t code; + } table[] = { + {7800, 0x00}, + {10400, 0x08}, + {15600, 0x01}, + {20800, 0x09}, + {31250, 0x02}, + {41700, 0x0A}, + {62500, 0x03}, + {125000, 0x04}, + {250000, 0x05}, + {500000, 0x06}, + }; + for (auto& e : table) { + if (e.hz == hz) { + code = e.code; + return true; + } + } + return false; +} + +SX126x::~SX126x() { + end(); +} + +bool SX126x::waitBusy(uint32_t timeoutMs) { + uint32_t t0 = nowMs(); + while (digitalRead(cfg.busy)) { + if (nowMs() - t0 > timeoutMs) return false; + delayMicroseconds(10); + } + return true; +} + +bool SX126x::xfer(const uint8_t* tx, uint8_t* rx, size_t n) { + if (asleep) { + // A falling edge on NSS wakes the chip up; it then keeps BUSY high until it is ready. + digitalWrite(cfg.nss, LOW); + delayMicroseconds(100); + digitalWrite(cfg.nss, HIGH); + asleep = false; + waitBusy(10); + } + if (!waitBusy()) return false; + cfg.spi->beginTransaction(settings); + digitalWrite(cfg.nss, LOW); + for (size_t i = 0; i < n; i++) { + uint8_t r = cfg.spi->transfer(tx ? tx[i] : 0); + if (rx) rx[i] = r; + } + digitalWrite(cfg.nss, HIGH); + cfg.spi->endTransaction(); + return true; +} + +bool SX126x::command(const uint8_t* bytes, size_t n) { + return xfer(bytes, nullptr, n); +} + +uint8_t SX126x::readRegister(uint16_t addr) { + const uint8_t tx[5] = {OP_READ_REGISTER, (uint8_t)(addr >> 8), (uint8_t)addr, 0, 0}; + uint8_t rx[5] = {}; + xfer(tx, rx, 5); + return rx[4]; +} + +void SX126x::writeRegister(uint16_t addr, uint8_t value) { + const uint8_t tx[4] = {OP_WRITE_REGISTER, (uint8_t)(addr >> 8), (uint8_t)addr, value}; + command(tx, 4); +} + +uint8_t SX126x::status() { + const uint8_t tx[2] = {OP_GET_STATUS, 0}; + uint8_t rx[2] = {}; + xfer(tx, rx, 2); + return rx[1]; +} + +uint16_t SX126x::irqStatus() { + const uint8_t tx[4] = {OP_GET_IRQ, 0, 0, 0}; + uint8_t rx[4] = {}; + xfer(tx, rx, 4); + return (rx[2] << 8) | rx[3]; +} + +void SX126x::clearIrq() { + const uint8_t c[3] = {OP_CLEAR_IRQ, 0xFF, 0xFF}; + command(c, 3); +} + +uint16_t SX126x::deviceErrors() { + const uint8_t tx[4] = {OP_GET_DEVICE_ERRORS, 0, 0, 0}; + uint8_t rx[4] = {}; + xfer(tx, rx, 4); + return (rx[2] << 8) | rx[3]; +} + +void SX126x::writeBuffer(uint8_t offset, const uint8_t* data, size_t n) { + if (asleep) status(); // wake up + if (!waitBusy()) return; + cfg.spi->beginTransaction(settings); + digitalWrite(cfg.nss, LOW); + cfg.spi->transfer(OP_WRITE_BUFFER); + cfg.spi->transfer(offset); + for (size_t i = 0; i < n; i++) + cfg.spi->transfer(data[i]); + digitalWrite(cfg.nss, HIGH); + cfg.spi->endTransaction(); +} + +void SX126x::readBuffer(uint8_t offset, uint8_t* data, size_t n) { + if (asleep) status(); // wake up + if (!waitBusy()) return; + cfg.spi->beginTransaction(settings); + digitalWrite(cfg.nss, LOW); + cfg.spi->transfer(OP_READ_BUFFER); + cfg.spi->transfer(offset); + cfg.spi->transfer(0); // status + for (size_t i = 0; i < n; i++) + data[i] = cfg.spi->transfer(0); + digitalWrite(cfg.nss, HIGH); + cfg.spi->endTransaction(); +} + +void SX126x::setRfSwitch(bool tx) { + if (cfg.rxen >= 0) digitalWrite(cfg.rxen, tx ? LOW : HIGH); + if (cfg.txen >= 0) digitalWrite(cfg.txen, tx ? HIGH : LOW); +} + +bool SX126x::reset() { + asleep = false; + if (cfg.nrst >= 0) { + digitalWrite(cfg.nrst, LOW); + vTaskDelay(pdMS_TO_TICKS(2)); + digitalWrite(cfg.nrst, HIGH); + } + return waitBusy(200); +} + +void SX126x::setPacketParams(uint8_t length) { + const uint8_t c[7] = { + OP_SET_PACKET_PARAMS, + (uint8_t)(cfg.preambleLength >> 8), + (uint8_t)cfg.preambleLength, + 0x00, // explicit header + length, + (uint8_t)(cfg.crc ? 0x01 : 0x00), + (uint8_t)(cfg.invertIq ? 0x01 : 0x00), + }; + command(c, 7); +} + +SX126x::Result SX126x::setFrequency(uint32_t hz) { + bool ok = cfg.chip == Chip::SX1268 ? (hz >= 410000000 && hz <= 493000000) : (hz >= 850000000 && hz <= 930000000); + if (!ok) return Result::InvalidParam; + cfg.frequencyHz = hz; + if (!running) return Result::OK; + bool wasReceiving = receiving; + standby(); + uint8_t img[3] = {OP_CALIBRATE_IMAGE, 0, 0}; + if (hz < 440000000) { + img[1] = 0x6B, img[2] = 0x6F; // 430-440 MHz + } else if (hz < 510000000) { + img[1] = 0x75, img[2] = 0x81; // 470-510 MHz + } else if (hz < 900000000) { + img[1] = 0xD7, img[2] = 0xDB; // 863-870 MHz + } else { + img[1] = 0xE1, img[2] = 0xE9; // 902-928 MHz + } + command(img, 3); + if (!waitBusy(500)) return Result::BusyTimeout; + uint32_t frf = (uint32_t)(((uint64_t)hz << 25) / 32000000ULL); + const uint8_t f[5] = { + OP_SET_RF_FREQ, (uint8_t)(frf >> 24), (uint8_t)(frf >> 16), (uint8_t)(frf >> 8), (uint8_t)frf + }; + command(f, 5); + return wasReceiving ? startReceive() : Result::OK; +} + +SX126x::Result SX126x::setTxPower(int8_t dbm) { + if (dbm < -9 || dbm > 22) return Result::InvalidParam; + cfg.powerDbm = dbm; + if (!running) return Result::OK; + // SX1262: hpMax 0x07, SX1268: hpMax 0x06 (datasheet 13.1.14, +22 dBm rows) + const uint8_t pa[5] = {OP_SET_PA_CONFIG, 0x04, (uint8_t)(cfg.chip == Chip::SX1262 ? 0x07 : 0x06), 0x00, 0x01}; + command(pa, 5); + const uint8_t tx[3] = {OP_SET_TX_PARAMS, (uint8_t)dbm, 0x04}; // 200 us ramp + command(tx, 3); + return Result::OK; +} + +SX126x::Result SX126x::configure() { + uint8_t bw; + if (cfg.spreadingFactor < 5 || cfg.spreadingFactor > 12 || cfg.codingRate < 5 || cfg.codingRate > 8 || + !bandwidthCode(cfg.bandwidthHz, bw)) { + return Result::InvalidParam; + } + const uint8_t standbyRc[2] = {OP_SET_STANDBY, 0x00}; + command(standbyRc, 2); + const uint8_t dcdc[2] = {OP_SET_REGULATOR, 0x01}; + command(dcdc, 2); + const uint8_t tcxo[5] = {OP_SET_TCXO, 0x02, 0x00, 0x01, 0x40}; // 1.8 V, 5 ms + command(tcxo, 5); + const uint8_t cal[2] = {OP_CALIBRATE, 0x7F}; + command(cal, 2); + vTaskDelay(pdMS_TO_TICKS(10)); + if (!waitBusy(500)) return Result::BusyTimeout; + const uint8_t lora[2] = {OP_SET_PACKET_TYPE, 0x01}; + command(lora, 2); + + running = true; // setFrequency/setTxPower below talk to the chip + Result r = setFrequency(cfg.frequencyHz); + if (r == Result::OK) r = setTxPower(cfg.powerDbm); + if (r != Result::OK) { + running = false; + return r; + } + + // Low data rate optimisation is required when a symbol is longer than 16 ms. + uint32_t symbolUs = (uint32_t)(((uint64_t)1 << cfg.spreadingFactor) * 1000000ULL / cfg.bandwidthHz); + const uint8_t mod[5] = { + OP_SET_MOD_PARAMS, + cfg.spreadingFactor, + bw, + (uint8_t)(cfg.codingRate - 4), + (uint8_t)(symbolUs >= 16000 ? 1 : 0), + }; + command(mod, 5); + const uint8_t base[3] = {OP_SET_BUFFER_BASE, 0x00, 0x00}; + command(base, 3); + const uint8_t irq[9] = {OP_SET_DIO_IRQ, 0x02, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + command(irq, 9); + setPacketParams(0xFF); + + writeRegister(REG_SYNC_WORD, (cfg.syncWord & 0xF0) | 0x04); + writeRegister(REG_SYNC_WORD + 1, ((cfg.syncWord & 0x0F) << 4) | 0x04); + // Errata 15.4: IQ polarity register must match the inverted-IQ setting. + uint8_t iq = readRegister(REG_IQ_POLARITY); + writeRegister(REG_IQ_POLARITY, cfg.invertIq ? (iq & ~0x04) : (iq | 0x04)); + // Errata 15.2: better resistance to antenna mismatch. + writeRegister(REG_TX_CLAMP, readRegister(REG_TX_CLAMP) | 0x1E); + + uint16_t err = deviceErrors(); + if (err & 0x7F) return Result::DeviceError; + return Result::OK; +} + +SX126x::Result SX126x::begin(const Config& config) { + end(); + cfg = config; + if (!cfg.spi) return Result::InvalidParam; + settings = SPISettings(cfg.spiFrequency, MSBFIRST, SPI_MODE0); + pinMode(cfg.nss, OUTPUT); + digitalWrite(cfg.nss, HIGH); + if (cfg.nrst >= 0) pinMode(cfg.nrst, OUTPUT); + if (cfg.rxen >= 0) pinMode(cfg.rxen, OUTPUT); + if (cfg.txen >= 0) pinMode(cfg.txen, OUTPUT); + pinMode(cfg.busy, INPUT); + setRfSwitch(false); + + if (!reset()) return Result::BusyTimeout; + // Default LoRa sync word after reset is 0x1424: proves the SPI link works. + if (readRegister(REG_SYNC_WORD) != 0x14 || readRegister(REG_SYNC_WORD + 1) != 0x24) return Result::NoChip; + const uint8_t clr[3] = {OP_CLEAR_DEVICE_ERRORS, 0, 0}; + command(clr, 3); + + Result r = configure(); + if (r != Result::OK) running = false; + return r; +} + +void SX126x::end() { + if (!running) return; + sleep(); + if (cfg.rxen >= 0) digitalWrite(cfg.rxen, LOW); + if (cfg.txen >= 0) digitalWrite(cfg.txen, LOW); + running = false; +} + +SX126x::Result SX126x::startReceive() { + if (!running) return Result::InvalidParam; + setPacketParams(0xFF); + setRfSwitch(false); + clearIrq(); + const uint8_t rx[4] = {OP_SET_RX, 0xFF, 0xFF, 0xFF}; // continuous + command(rx, 4); + receiving = true; + return Result::OK; +} + +SX126x::Result SX126x::send(const uint8_t* data, uint8_t length, uint32_t timeoutMs, uint32_t* airTimeMs) { + if (!running) return Result::InvalidParam; + bool wasReceiving = receiving; + standby(); + setPacketParams(length); + writeBuffer(0, data, length); + clearIrq(); + setRfSwitch(true); + uint32_t t0 = nowMs(); + const uint8_t tx[4] = {OP_SET_TX, 0x00, 0x00, 0x00}; // no timeout + command(tx, 4); + bool done = false; + while (nowMs() - t0 < timeoutMs) { + if (irqStatus() & IRQ_TX_DONE) { + done = true; + break; + } + vTaskDelay(1); + } + if (airTimeMs) *airTimeMs = nowMs() - t0; + setRfSwitch(false); + if (!done) standby(); + clearIrq(); + if (wasReceiving) startReceive(); + return done ? Result::OK : Result::Timeout; +} + +bool SX126x::receive(Packet& packet) { + if (!running || !receiving) return false; + uint16_t irq = irqStatus(); + if (!(irq & IRQ_RX_DONE)) { + if (irq & IRQ_HEADER_ERR) clearIrq(); + return false; + } + const uint8_t tx[4] = {OP_GET_RX_BUFFER_STATUS, 0, 0, 0}; + uint8_t rx[4] = {}; + xfer(tx, rx, 4); + uint8_t len = rx[2], start = rx[3]; + const uint8_t ps[5] = {OP_GET_PACKET_STATUS, 0, 0, 0, 0}; + uint8_t pr[5] = {}; + xfer(ps, pr, 5); + readBuffer(start, packet.data, len); + packet.length = len; + packet.rssi = -pr[2] / 2.0f; + packet.snr = (int8_t)pr[3] / 4.0f; + packet.crcError = (irq & IRQ_CRC_ERR) != 0; + clearIrq(); + return true; +} + +float SX126x::rssi() { + const uint8_t tx[3] = {OP_GET_RSSI_INST, 0, 0}; + uint8_t rx[3] = {}; + xfer(tx, rx, 3); + return -rx[2] / 2.0f; +} + +void SX126x::standby() { + const uint8_t c[2] = {OP_SET_STANDBY, 0x00}; + command(c, 2); + receiving = false; +} + +void SX126x::sleep() { + standby(); + const uint8_t c[2] = {OP_SET_SLEEP, 0x04}; // warm start, keep configuration + command(c, 2); + asleep = true; + vTaskDelay(pdMS_TO_TICKS(1)); +} + +uint32_t SX126x::timeOnAirMs(uint8_t length) const { + // Semtech AN1200.13 formula, explicit header. + uint32_t sf = cfg.spreadingFactor; + uint32_t symbolUs = (uint32_t)(((uint64_t)1 << sf) * 1000000ULL / cfg.bandwidthHz); + bool ldro = symbolUs >= 16000; + int32_t num = 8 * length - 4 * sf + 28 + (cfg.crc ? 16 : 0); + int32_t den = 4 * (sf - (ldro ? 2 : 0)); + int32_t payloadSymbols = 8 + (num > 0 ? ((num + den - 1) / den) * (cfg.codingRate) : 0); + uint32_t preambleUs = (cfg.preambleLength * 4 + 17) * symbolUs / 4; + return (preambleUs + payloadSymbols * symbolUs) / 1000; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/sx126x.h b/lib/lilka_modules/src/lilka_modules/sx126x.h new file mode 100644 index 0000000..8f0d037 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/sx126x.h @@ -0,0 +1,110 @@ +#pragma once + +#include +#include + +#include "pins.h" + +namespace lilka { +namespace mod { + +/// LoRa-радіо Semtech SX1262 / SX1268 (модуль 003 LORA, Ebyte E22-900M / E22-400M). +/// +/// DIO1 на модулі не під'єднаний, тому стан переривань опитується по SPI. +/// Перемикач антени (RXEN/TXEN) керується з Лілки. TCXO живиться з DIO3 (1.8 В). +/// Шина SPI має бути вже запущена (``spi.begin(sck, miso, mosi)``) - драйвер її не запускає і не зупиняє. +class SX126x { +public: + enum class Chip { + SX1262, ///< 850-930 МГц (E22-900M) + SX1268, ///< 410-493 МГц (E22-400M) + }; + + enum class Result { + OK, + NoChip, ///< немає відповіді по SPI + BusyTimeout, ///< BUSY не відпускається + DeviceError, ///< помилка калібрування / TCXO (див. deviceErrors()) + InvalidParam, ///< частота, SF, BW, CR або потужність поза межами + Timeout, + }; + + struct Config { + SPIClass* spi = nullptr; + int nss = pins::SPI_CS; + int busy = pins::LORA_BUSY; + int nrst = pins::LORA_NRST; + int rxen = pins::LORA_RXEN; + int txen = pins::LORA_TXEN; + Chip chip = Chip::SX1262; + uint32_t frequencyHz = 868100000; + uint8_t spreadingFactor = 7; ///< 5-12 + uint32_t bandwidthHz = 125000; ///< 7800 ... 500000 + uint8_t codingRate = 5; ///< 5-8 (4/5 ... 4/8) + int8_t powerDbm = 0; ///< -9 ... 22 + uint8_t syncWord = 0x12; ///< 0x12 - приватна мережа, 0x34 - LoRaWAN + uint16_t preambleLength = 8; + bool crc = true; + bool invertIq = false; + uint32_t spiFrequency = 2000000; + }; + + struct Packet { + uint8_t data[255]; + uint8_t length; + float rssi; ///< дБм + float snr; ///< дБ + bool crcError; + }; + + ~SX126x(); + Result begin(const Config& config); + void end(); + + /// Надіслати пакет і дочекатись TxDone. Після передачі повертається в прийом, якщо він був увімкнений. + Result send(const uint8_t* data, uint8_t length, uint32_t timeoutMs = 3000, uint32_t* airTimeMs = nullptr); + /// Перейти в безперервний прийом. + Result startReceive(); + /// Перевірити, чи прийшов пакет (без очікування). Повертає true і заповнює packet. + bool receive(Packet& packet); + + /// Миттєвий RSSI каналу, дБм (у режимі прийому). + float rssi(); + void standby(); + void sleep(); + + Result setFrequency(uint32_t hz); + Result setTxPower(int8_t dbm); + + uint16_t deviceErrors(); + bool isReceiving() const { + return receiving; + } + /// Оцінка часу в ефірі для пакета заданої довжини, мс. + uint32_t timeOnAirMs(uint8_t length) const; + +private: + bool waitBusy(uint32_t timeoutMs = 100); + bool xfer(const uint8_t* tx, uint8_t* rx, size_t n); + bool command(const uint8_t* bytes, size_t n); + uint8_t readRegister(uint16_t addr); + void writeRegister(uint16_t addr, uint8_t value); + uint8_t status(); + uint16_t irqStatus(); + void clearIrq(); + void writeBuffer(uint8_t offset, const uint8_t* data, size_t n); + void readBuffer(uint8_t offset, uint8_t* data, size_t n); + void setRfSwitch(bool tx); + void setPacketParams(uint8_t length); + bool reset(); + Result configure(); + + Config cfg; + bool running = false; + bool receiving = false; + bool asleep = false; + SPISettings settings; +}; + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/tmag5273.cpp b/lib/lilka_modules/src/lilka_modules/tmag5273.cpp new file mode 100644 index 0000000..493be20 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/tmag5273.cpp @@ -0,0 +1,77 @@ +#include "tmag5273.h" + +#include +#include + +namespace lilka { +namespace mod { + +enum : uint8_t { + REG_DEVICE_CONFIG_1 = 0x00, + REG_DEVICE_CONFIG_2 = 0x01, + REG_SENSOR_CONFIG_1 = 0x02, + REG_SENSOR_CONFIG_2 = 0x03, + REG_T_CONFIG = 0x07, + REG_DEVICE_ID = 0x0D, + REG_MANUFACTURER_ID_LSB = 0x0E, + REG_T_MSB = 0x10, + REG_X_MSB = 0x12, +}; + +bool Tmag5273::writeRegister(uint8_t reg, uint8_t value) { + cfg.wire->beginTransmission(cfg.address); + cfg.wire->write(reg); + cfg.wire->write(value); + return cfg.wire->endTransmission() == 0; +} + +bool Tmag5273::readRegister(uint8_t reg, uint8_t* data, size_t n) { + cfg.wire->beginTransmission(cfg.address); + cfg.wire->write(reg); + if (cfg.wire->endTransmission(false) != 0) return false; + if (cfg.wire->requestFrom(cfg.address, (uint8_t)n) != n) return false; + for (size_t i = 0; i < n; i++) + data[i] = cfg.wire->read(); + return true; +} + +bool Tmag5273::begin(const Config& config) { + cfg = config; + uint8_t man[2] = {}; + if (!readRegister(REG_MANUFACTURER_ID_LSB, man, 2)) return false; + if (man[0] != 0x49 || man[1] != 0x54) return false; // "TI" + uint8_t dev = 0; + readRegister(REG_DEVICE_ID, &dev, 1); + bool a2 = (dev & 0x03) == 2; + rangeMt = a2 ? (cfg.highRange ? 266.0f : 133.0f) : (cfg.highRange ? 80.0f : 40.0f); + + uint8_t avg = cfg.averaging > 5 ? 5 : cfg.averaging; + writeRegister(REG_DEVICE_CONFIG_1, (uint8_t)(avg << 2)); + writeRegister(REG_SENSOR_CONFIG_1, 0x70); // X, Y, Z + writeRegister(REG_SENSOR_CONFIG_2, cfg.highRange ? 0x03 : 0x00); // XY and Z range + writeRegister(REG_T_CONFIG, 0x01); // temperature on + writeRegister(REG_DEVICE_CONFIG_2, 0x02); // continuous measurement + vTaskDelay(pdMS_TO_TICKS(20)); + return true; +} + +bool Tmag5273::read(Data& d) { + uint8_t b[6]; + if (!readRegister(REG_X_MSB, b, 6)) return false; + auto s16 = [&](int i) { return (int16_t)((b[i] << 8) | b[i + 1]); }; + float k = rangeMt * 1000.0f / 32768.0f; + d.x = s16(0) * k; + d.y = s16(2) * k; + d.z = s16(4) * k; + return true; +} + +float Tmag5273::temperature() { + uint8_t b[2] = {}; + readRegister(REG_T_MSB, b, 2); + int16_t t = (int16_t)((b[0] << 8) | b[1]); + return 25.0f + (t - 17508) / 60.1f; +} + +} // namespace mod +} // namespace lilka diff --git a/lib/lilka_modules/src/lilka_modules/tmag5273.h b/lib/lilka_modules/src/lilka_modules/tmag5273.h new file mode 100644 index 0000000..704d775 --- /dev/null +++ b/lib/lilka_modules/src/lilka_modules/tmag5273.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +namespace lilka { +namespace mod { + +/// 3D-датчик Холла TI TMAG5273 (модуль 006 GYRO MAGNET, TMAG5273A1). +/// +/// Шина I2C має бути вже запущена. +class Tmag5273 { +public: + static constexpr uint8_t DEFAULT_ADDRESS = 0x35; + + struct Config { + TwoWire* wire = &Wire; + uint8_t address = DEFAULT_ADDRESS; + bool highRange = false; ///< A1: ±40 / ±80 мТл, A2: ±133 / ±266 мТл + uint8_t averaging = 5; ///< 0-5: 1x, 2x, 4x, 8x, 16x, 32x + }; + + struct Data { + float x, y, z; ///< мкТл + }; + + bool begin(const Config& config); + bool read(Data& data); + float temperature(); + /// Повний діапазон по осях, мТл. + float rangeMilliTesla() const { + return rangeMt; + } + +private: + bool writeRegister(uint8_t reg, uint8_t value); + bool readRegister(uint8_t reg, uint8_t* data, size_t n); + + Config cfg; + float rangeMt = 40; +}; + +} // namespace mod +} // namespace lilka From e5117fbf11580a937069919911447f1746297598 Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Sun, 8 Nov 2026 22:08:18 +0200 Subject: [PATCH 2/3] ci: use Python 3.11 (3.9 is gone from ubuntu-latest) --- .github/workflows/sdk.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.yml index bcf5ac0..662a058 100644 --- a/.github/workflows/sdk.yml +++ b/.github/workflows/sdk.yml @@ -22,9 +22,10 @@ jobs: ~/.platformio/.cache ./lib/lilka/.pio key: ${{ runner.os }}-lilka - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: - python-version: '3.9' + # 3.9 isn't available for the current ubuntu-latest image + python-version: '3.11' - name: Install PlatformIO Core run: pip install --upgrade platformio From c1bd0e57c4a88f6693d1c63f3148c5c3bfa7248d Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Tue, 10 Nov 2026 15:01:30 +0200 Subject: [PATCH 3/3] feat: add lilka/config INI module, read module pins from it lilka/config: - IniTable: zero-dependency INI parser stored in a hash table (chaining, FNV-1a, case-insensitive sections/keys) with STL-like accessors: begin()/end(), find(), has_key(), size(), empty(), plus typed getters - lilka::config: built-in hardware values for LILKA_VERSION 2 (from config.h macros), then /sd/.lilka/config/*.ini in alphabetical order, later values override earlier ones; loaded in lilka::begin() after the SD card LilkaModules: - driver pin defaults read from lilka::config sections (gps, can, ir, lora, rf, gyro_magnet) via pins::get(); compile-time pin constants removed - example moved to lilka-dev/examples --- lib/lilka/src/lilka.cpp | 1 + lib/lilka/src/lilka.h | 1 + lib/lilka/src/lilka/config/config.cpp | 63 ++++ lib/lilka/src/lilka/config/config.h | 48 +++ lib/lilka/src/lilka/config/defaults.h | 62 ++++ lib/lilka/src/lilka/config/ini.cpp | 322 ++++++++++++++++++ lib/lilka/src/lilka/config/ini.h | 115 +++++++ lib/lilka_modules/README.md | 10 +- .../examples/lora_beacon/lora_beacon.ino | 37 -- lib/lilka_modules/library.json | 1 - .../src/lilka_modules/bmi260.cpp | 4 +- lib/lilka_modules/src/lilka_modules/bmi260.h | 2 +- lib/lilka_modules/src/lilka_modules/can.cpp | 20 +- lib/lilka_modules/src/lilka_modules/can.h | 6 +- .../src/lilka_modules/cc1101.cpp | 4 +- lib/lilka_modules/src/lilka_modules/cc1101.h | 10 +- lib/lilka_modules/src/lilka_modules/gps.cpp | 4 +- lib/lilka_modules/src/lilka_modules/gps.h | 8 +- lib/lilka_modules/src/lilka_modules/ir.cpp | 4 +- lib/lilka_modules/src/lilka_modules/ir.h | 8 +- lib/lilka_modules/src/lilka_modules/nrf24.cpp | 4 +- lib/lilka_modules/src/lilka_modules/nrf24.h | 8 +- lib/lilka_modules/src/lilka_modules/pins.h | 58 +--- .../src/lilka_modules/sx126x.cpp | 4 +- lib/lilka_modules/src/lilka_modules/sx126x.h | 12 +- .../src/lilka_modules/tmag5273.cpp | 4 +- .../src/lilka_modules/tmag5273.h | 2 +- 27 files changed, 681 insertions(+), 141 deletions(-) create mode 100644 lib/lilka/src/lilka/config/config.cpp create mode 100644 lib/lilka/src/lilka/config/config.h create mode 100644 lib/lilka/src/lilka/config/defaults.h create mode 100644 lib/lilka/src/lilka/config/ini.cpp create mode 100644 lib/lilka/src/lilka/config/ini.h delete mode 100644 lib/lilka_modules/examples/lora_beacon/lora_beacon.ino diff --git a/lib/lilka/src/lilka.cpp b/lib/lilka/src/lilka.cpp index 256f658..d201fcc 100644 --- a/lib/lilka/src/lilka.cpp +++ b/lib/lilka/src/lilka.cpp @@ -13,6 +13,7 @@ void begin() { audio.begin(); spi_begin(); fileutils.begin(); + config.reload(); // Must be initialized AFTER SD card: reads /sd/.lilka/config display.begin(); // Must be initialized AFTER SD card controller.begin(); // Must be initialized AFTER SD card (since SD card somehow messes with GPIO) battery.begin(); diff --git a/lib/lilka/src/lilka.h b/lib/lilka/src/lilka.h index 4771507..5e090a8 100644 --- a/lib/lilka/src/lilka.h +++ b/lib/lilka/src/lilka.h @@ -18,6 +18,7 @@ #include "lilka/audio.h" #include "lilka/sdk.h" #include "lilka/dynloader.h" +#include "lilka/config/config.h" namespace lilka { /// Ініціалізація Лілки diff --git a/lib/lilka/src/lilka/config/config.cpp b/lib/lilka/src/lilka/config/config.cpp new file mode 100644 index 0000000..e286402 --- /dev/null +++ b/lib/lilka/src/lilka/config/config.cpp @@ -0,0 +1,63 @@ +#include "config.h" + +#include +#include +#include +#include +#include + +#include "defaults.h" +#include "lilka/serial.h" + +namespace lilka { + +Config config; + +static const int MAX_FILES = 32; + +Config::Config() : files(0) { + // Defaults are available even before begin() (and in programs that never mount the SD card). + parse(LILKA_CONFIG_DEFAULTS); +} + +static int compareNames(const void* a, const void* b) { + return strcmp(*static_cast(a), *static_cast(b)); +} + +void Config::reload() { + clear(); + parse(LILKA_CONFIG_DEFAULTS); + files = 0; + + DIR* dir = opendir(LILKA_CONFIG_DIR); + if (!dir) return; // no SD card or no config directory: defaults only + + // Sorted, so that overrides don't depend on the directory order. + char* names[MAX_FILES] = {}; + int n = 0; + const struct dirent* entry; + while ((entry = readdir(dir)) != nullptr && n < MAX_FILES) { + size_t len = strlen(entry->d_name); + if (len > 4 && !strcasecmp(entry->d_name + len - 4, ".ini")) { + names[n] = strdup(entry->d_name); + if (names[n]) n++; + } + } + closedir(dir); + qsort(names, n, sizeof(char*), compareNames); + + for (int i = 0; i < n; i++) { + char path[300]; + snprintf(path, sizeof(path), "%s/%s", LILKA_CONFIG_DIR, names[i]); + int errors = 0; + if (load(path, &errors)) { + files++; + if (errors) serial.err("config: %s: %d invalid line(s) skipped", path, errors); + } else { + serial.err("config: can't read %s", path); + } + free(names[i]); + } +} + +} // namespace lilka diff --git a/lib/lilka/src/lilka/config/config.h b/lib/lilka/src/lilka/config/config.h new file mode 100644 index 0000000..21a798e --- /dev/null +++ b/lib/lilka/src/lilka/config/config.h @@ -0,0 +1,48 @@ +#pragma once + +#include "ini.h" + +#define LILKA_CONFIG_DIR "/sd/.lilka/config" + +namespace lilka { + +/// Налаштування заліза з INI-файлів. +/// +/// Спершу завантажуються вбудовані значення для поточної плати (для Лілки v2 - контакти роз'єму розширення +/// та модулів: секції ``ext``, ``gps``, ``can``, ``ir``, ``lora``, ``rf``, ``gyro_magnet``), потім усі файли +/// ``*.ini`` з ``/sd/.lilka/config`` в алфавітному порядку. Значення з файлів перекривають вбудовані, +/// тому досить вказати лише те, що відрізняється: +/// +/// .. code-block:: ini +/// +/// ; /sd/.lilka/config/modules.ini +/// [lora] +/// nss = 21 +/// +/// Читання значень: +/// +/// .. code-block:: cpp +/// +/// int nss = lilka::config.getInt("lora", "nss", -1); +/// if (lilka::config.has_key("gps", "baud")) { ... } +class Config : public IniTable { +public: + Config(); + /// (Пере)завантажити вбудовані значення і файли з SD-картки. Викликається з lilka::begin() після + /// монтування SD-картки; можна викликати повторно після зміни файлів. + /// + /// (Не ``begin()``: ``begin()`` / ``end()`` - ітератори таблиці.) + void reload(); + /// Скільки файлів з SD-картки завантажено при останньому reload(). + int fileCount() const { + return files; + } + +private: + int files; +}; + +/// Екземпляр налаштувань. +extern Config config; + +} // namespace lilka diff --git a/lib/lilka/src/lilka/config/defaults.h b/lib/lilka/src/lilka/config/defaults.h new file mode 100644 index 0000000..1357f54 --- /dev/null +++ b/lib/lilka/src/lilka/config/defaults.h @@ -0,0 +1,62 @@ +#pragma once + +#include "lilka/config.h" + +// Built-in hardware configuration, loaded before the files in /sd/.lilka/config. +// Values come from lilka/config.h, so they always match the board the SDK is built for. + +#define LILKA_CONFIG_STR_(x) #x +#define LILKA_CONFIG_STR(x) LILKA_CONFIG_STR_(x) + +#if LILKA_VERSION == 2 + +// Extension header: pins 3-10 (J2 on the module schematics). Sections below are per module board. +// clang-format off +# define LILKA_CONFIG_DEFAULTS \ + "[ext]\n" \ + "rx = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "tx = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "p3 = " LILKA_CONFIG_STR(LILKA_P3) "\n" \ + "p4 = " LILKA_CONFIG_STR(LILKA_P4) "\n" \ + "p5 = " LILKA_CONFIG_STR(LILKA_P5) "\n" \ + "p6 = " LILKA_CONFIG_STR(LILKA_P6) "\n" \ + "p7 = " LILKA_CONFIG_STR(LILKA_P7) "\n" \ + "p8 = " LILKA_CONFIG_STR(LILKA_P8) "\n" \ + "[gps]\n" \ + "rx = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "tx = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "baud = 9600\n" \ + "[can]\n" \ + "rx = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "tx = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "[ir]\n" \ + "rx = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "tx = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "carrier = 38000\n" \ + "[lora]\n" \ + "sck = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "miso = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "mosi = " LILKA_CONFIG_STR(LILKA_P3) "\n" \ + "nss = " LILKA_CONFIG_STR(LILKA_P4) "\n" \ + "rxen = " LILKA_CONFIG_STR(LILKA_P5) "\n" \ + "txen = " LILKA_CONFIG_STR(LILKA_P6) "\n" \ + "nrst = " LILKA_CONFIG_STR(LILKA_P7) "\n" \ + "busy = " LILKA_CONFIG_STR(LILKA_P8) "\n" \ + "[rf]\n" \ + "sck = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "miso = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "mosi = " LILKA_CONFIG_STR(LILKA_P3) "\n" \ + "cs = " LILKA_CONFIG_STR(LILKA_P4) "\n" \ + "ce = " LILKA_CONFIG_STR(LILKA_P5) "\n" \ + "irq = " LILKA_CONFIG_STR(LILKA_P6) "\n" \ + "[gyro_magnet]\n" \ + "sda = " LILKA_CONFIG_STR(LILKA_EXT_RX) "\n" \ + "scl = " LILKA_CONFIG_STR(LILKA_EXT_TX) "\n" \ + "mag_int = " LILKA_CONFIG_STR(LILKA_P3) "\n" \ + "gyr_int1 = " LILKA_CONFIG_STR(LILKA_P4) "\n" \ + "gyr_int2 = " LILKA_CONFIG_STR(LILKA_P5) "\n" +// clang-format on + +#else +# define LILKA_CONFIG_DEFAULTS "" +#endif diff --git a/lib/lilka/src/lilka/config/ini.cpp b/lib/lilka/src/lilka/config/ini.cpp new file mode 100644 index 0000000..097913e --- /dev/null +++ b/lib/lilka/src/lilka/config/ini.cpp @@ -0,0 +1,322 @@ +#include "ini.h" + +#include +#include +#include +#include +#include + +namespace lilka { + +// One allocation per entry: the node header followed by "section\0key\0value\0". +struct IniTable::Node { + Node* next; + uint32_t hash; + const char* key; // points into data + const char* value; // points into data + char section[1]; // data starts here +}; + +static const size_t INITIAL_BUCKETS = 16; +static const size_t MAX_LINE = 256; + +static uint32_t hashPart(uint32_t h, const char* s) { + for (; *s; s++) { + h ^= (uint8_t)tolower((unsigned char)*s); + h *= 16777619u; + } + return h; +} + +static uint32_t hashKey(const char* section, const char* key) { + uint32_t h = hashPart(2166136261u, section); + h ^= 0xFF; // separator: "a" + "bc" != "ab" + "c" + h *= 16777619u; + return hashPart(h, key); +} + +// ---- iterator ---- + +IniTable::iterator::iterator(const IniTable* t, size_t b, const void* n) : table(t), bucket(b), node(n), current() { + load(); +} + +void IniTable::iterator::load() { + if (node) { + const Node* n = static_cast(node); + current = {n->section, n->key, n->value}; + } +} + +IniTable::iterator& IniTable::iterator::operator++() { + const Node* n = static_cast(node); + if (n && n->next) { + node = n->next; + } else { + node = nullptr; + while (++bucket < table->bucketCount) { + if (table->buckets[bucket]) { + node = table->buckets[bucket]; + break; + } + } + } + load(); + return *this; +} + +// ---- table ---- + +IniTable::IniTable() : buckets(nullptr), bucketCount(0), count(0) { +} + +IniTable::~IniTable() { + clear(); + free(buckets); +} + +void IniTable::clear() { + for (size_t i = 0; i < bucketCount; i++) { + Node* n = buckets[i]; + while (n) { + Node* next = n->next; + free(n); + n = next; + } + buckets[i] = nullptr; + } + count = 0; +} + +IniTable::Node* IniTable::findNode(const char* section, const char* key, uint32_t hash) const { + if (!bucketCount) return nullptr; + for (Node* n = buckets[hash % bucketCount]; n; n = n->next) { + if (n->hash == hash && !strcasecmp(n->section, section) && !strcasecmp(n->key, key)) return n; + } + return nullptr; +} + +bool IniTable::grow() { + size_t newCount = bucketCount ? bucketCount * 2 : INITIAL_BUCKETS; + Node** fresh = static_cast(calloc(newCount, sizeof(Node*))); + if (!fresh) return false; + for (size_t i = 0; i < bucketCount; i++) { + Node* n = buckets[i]; + while (n) { + Node* next = n->next; + size_t b = n->hash % newCount; + n->next = fresh[b]; + fresh[b] = n; + n = next; + } + } + free(buckets); + buckets = fresh; + bucketCount = newCount; + return true; +} + +bool IniTable::set(const char* section, const char* key, const char* value) { + if (!section) section = ""; + if (!key || !value) return false; + if ((count + 1) * 4 > bucketCount * 3 && !grow() && !bucketCount) return false; + uint32_t hash = hashKey(section, key); + size_t ls = strlen(section) + 1, lk = strlen(key) + 1, lv = strlen(value) + 1; + Node* n = static_cast(malloc(sizeof(Node) + ls + lk + lv)); + if (!n) return false; + n->next = nullptr; + char* data = n->section; + memcpy(data, section, ls); + memcpy(data + ls, key, lk); + memcpy(data + ls + lk, value, lv); + n->key = data + ls; + n->value = data + ls + lk; + n->hash = hash; + + // Replace an existing entry in place in its chain. + Node** link = &buckets[hash % bucketCount]; + while (*link) { + Node* old = *link; + if (old->hash == hash && !strcasecmp(old->section, section) && !strcasecmp(old->key, key)) { + n->next = old->next; + *link = n; + free(old); + return true; + } + link = &old->next; + } + n->next = buckets[hash % bucketCount]; + buckets[hash % bucketCount] = n; + count++; + return true; +} + +bool IniTable::erase(const char* section, const char* key) { + if (!bucketCount) return false; + if (!section) section = ""; + uint32_t hash = hashKey(section, key); + Node** link = &buckets[hash % bucketCount]; + while (*link) { + Node* n = *link; + if (n->hash == hash && !strcasecmp(n->section, section) && !strcasecmp(n->key, key)) { + *link = n->next; + free(n); + count--; + return true; + } + link = &n->next; + } + return false; +} + +bool IniTable::has_key(const char* section, const char* key) const { + if (!section) section = ""; + return findNode(section, key, hashKey(section, key)) != nullptr; +} + +IniTable::iterator IniTable::find(const char* section, const char* key) const { + if (!section) section = ""; + uint32_t hash = hashKey(section, key); + const Node* n = findNode(section, key, hash); + return n ? iterator(this, hash % bucketCount, n) : end(); +} + +const char* IniTable::get(const char* section, const char* key, const char* fallback) const { + if (!section) section = ""; + const Node* n = findNode(section, key, hashKey(section, key)); + return n ? n->value : fallback; +} + +long IniTable::getInt(const char* section, const char* key, long fallback) const { + const char* v = get(section, key); + if (!v || !*v) return fallback; + char* tail; + long result = strtol(v, &tail, 0); + return *tail ? fallback : result; +} + +float IniTable::getFloat(const char* section, const char* key, float fallback) const { + const char* v = get(section, key); + if (!v || !*v) return fallback; + char* tail; + float result = strtof(v, &tail); + return *tail ? fallback : result; +} + +bool IniTable::getBool(const char* section, const char* key, bool fallback) const { + const char* v = get(section, key); + if (!v) return fallback; + if (!strcasecmp(v, "true") || !strcasecmp(v, "yes") || !strcasecmp(v, "on") || !strcmp(v, "1")) return true; + if (!strcasecmp(v, "false") || !strcasecmp(v, "no") || !strcasecmp(v, "off") || !strcmp(v, "0")) return false; + return fallback; +} + +IniTable::iterator IniTable::begin() const { + for (size_t b = 0; b < bucketCount; b++) { + if (buckets[b]) return iterator(this, b, buckets[b]); + } + return end(); +} + +IniTable::iterator IniTable::end() const { + return iterator(this, bucketCount, nullptr); +} + +// ---- parser ---- + +static char* trim(char* s) { + while (isspace((unsigned char)*s)) + s++; + char* e = s + strlen(s); + while (e > s && isspace((unsigned char)e[-1])) + *--e = 0; + return s; +} + +// Parses one line in place. Returns false on a syntax error. +static bool parseLine(IniTable& table, char* line, char* section, size_t sectionSize) { + char* s = trim(line); + if (!*s || *s == ';' || *s == '#') return true; + if (*s == '[') { + char* close = strchr(s, ']'); + if (!close) return false; + const char* rest = trim(close + 1); + if (*rest && *rest != ';' && *rest != '#') return false; + *close = 0; + const char* name = trim(s + 1); + if (strlen(name) >= sectionSize) return false; + strcpy(section, name); + return true; + } + char* eq = strchr(s, '='); + if (!eq) return false; + *eq = 0; + const char* key = trim(s); + if (!*key) return false; + char* value = trim(eq + 1); + if (*value == '"') { + char* close = strchr(value + 1, '"'); + if (!close) return false; + const char* rest = trim(close + 1); + if (*rest && *rest != ';' && *rest != '#') return false; + *close = 0; + value++; + } else { + // Inline comment: ';' or '#' at the start or after whitespace. + for (char* p = value; *p; p++) { + if ((*p == ';' || *p == '#') && (p == value || isspace((unsigned char)p[-1]))) { + *p = 0; + break; + } + } + value = trim(value); + } + return table.set(section, key, value); +} + +int IniTable::parse(const char* text, size_t length) { + char section[64] = ""; + char line[MAX_LINE]; + int errors = 0; + size_t pos = 0; + while (pos < length) { + size_t n = 0; + bool tooLong = false; + while (pos < length && text[pos] != '\n') { + if (n < MAX_LINE - 1) { + line[n++] = text[pos]; + } else { + tooLong = true; + } + pos++; + } + pos++; // skip '\n' + line[n] = 0; + if (n && line[n - 1] == '\r') line[n - 1] = 0; + if (tooLong || !parseLine(*this, line, section, sizeof(section))) errors++; + } + return errors; +} + +int IniTable::parse(const char* text) { + return parse(text, strlen(text)); +} + +bool IniTable::load(const char* path, int* errors) { + FILE* f = fopen(path, "rb"); + if (!f) return false; + fseek(f, 0, SEEK_END); + long fileSize = ftell(f); + fseek(f, 0, SEEK_SET); + char* text = fileSize > 0 ? static_cast(malloc(fileSize)) : nullptr; + bool ok = fileSize == 0 || (text && fread(text, 1, fileSize, f) == (size_t)fileSize); + fclose(f); + if (ok && fileSize > 0) { + int e = parse(text, fileSize); + if (errors) *errors = e; + } + free(text); + return ok; +} + +} // namespace lilka diff --git a/lib/lilka/src/lilka/config/ini.h b/lib/lilka/src/lilka/config/ini.h new file mode 100644 index 0000000..f4cc810 --- /dev/null +++ b/lib/lilka/src/lilka/config/ini.h @@ -0,0 +1,115 @@ +#pragma once + +#include +#include + +namespace lilka { + +/// Таблиця значень з INI-файлу. +/// +/// Зберігає пари ``[секція] ключ = значення`` у хеш-таблиці (ланцюжки, FNV-1a), тому пошук - O(1). +/// Секції та ключі нечутливі до регістру. Без залежностей: лише libc. +/// +/// Формат: +/// +/// .. code-block:: ini +/// +/// ; коментар (також #) +/// [lora] +/// nss = 47 ; коментар після значення +/// name = "a ; b" ; у лапках ; і # - частина значення +/// +/// Ключі до першої секції потрапляють у секцію ``""``. Повторний ключ перезаписує попереднє значення, +/// тому кілька файлів можна завантажити один за одним: наступний перекриває попередній. +/// +/// Ітерація (порядок не визначений): +/// +/// .. code-block:: cpp +/// +/// for (const lilka::IniTable::Entry& e : table) { +/// printf("[%s] %s = %s\n", e.section, e.key, e.value); +/// } +class IniTable { +public: + struct Entry { + const char* section; + const char* key; + const char* value; + }; + + class iterator { + public: + const Entry& operator*() const { + return current; + } + const Entry* operator->() const { + return ¤t; + } + iterator& operator++(); + bool operator==(const iterator& other) const { + return node == other.node; + } + bool operator!=(const iterator& other) const { + return node != other.node; + } + + private: + friend class IniTable; + iterator(const IniTable* table, size_t bucket, const void* node); + void load(); + + const IniTable* table; + size_t bucket; + const void* node; + Entry current; + }; + using const_iterator = iterator; + + IniTable(); + ~IniTable(); + IniTable(const IniTable&) = delete; + IniTable& operator=(const IniTable&) = delete; + + /// Розібрати INI-текст і додати значення до таблиці. Повертає кількість рядків з помилками + /// (вони пропускаються, решта завантажується). + int parse(const char* text, size_t length); + int parse(const char* text); + /// Завантажити файл (шлях на кшталт ``/sd/.lilka/config/modules.ini``). Повертає false, якщо файл не відкрився. + bool load(const char* path, int* errors = nullptr); + + /// Встановити значення (копіюється). Повертає false, якщо не вистачило пам'яті. + bool set(const char* section, const char* key, const char* value); + /// Видалити значення. Повертає true, якщо ключ був. + bool erase(const char* section, const char* key); + void clear(); + + bool has_key(const char* section, const char* key) const; + iterator find(const char* section, const char* key) const; + /// Значення або ``fallback``, якщо ключа немає. + const char* get(const char* section, const char* key, const char* fallback = nullptr) const; + /// Ціле число (десяткове або ``0x...``); ``fallback``, якщо ключа немає або значення не число. + long getInt(const char* section, const char* key, long fallback) const; + float getFloat(const char* section, const char* key, float fallback) const; + /// ``true/yes/on/1`` або ``false/no/off/0``; інакше ``fallback``. + bool getBool(const char* section, const char* key, bool fallback) const; + + iterator begin() const; + iterator end() const; + size_t size() const { + return count; + } + bool empty() const { + return count == 0; + } + +private: + struct Node; + Node* findNode(const char* section, const char* key, uint32_t hash) const; + bool grow(); + + Node** buckets; + size_t bucketCount; + size_t count; +}; + +} // namespace lilka diff --git a/lib/lilka_modules/README.md b/lib/lilka_modules/README.md index feb653a..7e03149 100644 --- a/lib/lilka_modules/README.md +++ b/lib/lilka_modules/README.md @@ -16,13 +16,19 @@ Rules: - Plain classes, not singletons: create an instance when the module is plugged in, call `begin()`. Nothing is started by `lilka::begin()`. -- Default pins come from `lilka_modules/pins.h`; every pin is a `Config` field. +- Pins come from `lilka::config` (`lilka/config/config.h`): built-in values for Lilka v2, overridable with + INI files in `/sd/.lilka/config/` (sections `gps`, `can`, `ir`, `lora`, `rf`, `gyro_magnet`). + `pins::get(section, key)` reads one; every pin is also a `Config` field. - SPI and I2C drivers take the bus (`SPIClass*`, `TwoWire*`) and never start or stop it: call - `lilka::SPI2.begin(pins::SPI_SCK, pins::SPI_MISO, pins::SPI_MOSI)` / `Wire.begin(pins::I2C_SDA, pins::I2C_SCL)` first. + `lilka::SPI2.begin(pins::get("lora", "sck"), pins::get("lora", "miso"), pins::get("lora", "mosi"))` / + `Wire.begin(pins::get("gyro_magnet", "sda"), pins::get("gyro_magnet", "scl"))` first. - `lilka::mod::resources` tracks which pins/peripherals are in use by whom (used by Keira to keep an app and a service off each other's hardware). Drivers don't use it themselves. - `Nmea` and `IrCodec` have no hardware access and build on a PC. +Examples (C++ and Lua) are in [lilka-dev/examples](https://github.com/lilka-dev/examples): +`C_C++/lilka_modules/` and `LUA/modules/`. + `bmi260_config.h` is Bosch's BMI260 configuration blob (BSD-3-Clause, see `BMI260_CONFIG_LICENSE`). Hardware status: SX126x, nRF24 and CC1101 drivers are ported from code tested on the boards; the GPS, IR diff --git a/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino b/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino deleted file mode 100644 index ef2169d..0000000 --- a/lib/lilka_modules/examples/lora_beacon/lora_beacon.ino +++ /dev/null @@ -1,37 +0,0 @@ -// Sends a LoRa beacon every 10 s and prints received packets (003 LORA module, E22-900M). -#include -#include - -using namespace lilka::mod; - -SX126x radio; - -void setup() { - lilka::begin(); - lilka::SPI2.begin(pins::SPI_SCK, pins::SPI_MISO, pins::SPI_MOSI); - SX126x::Config cfg; - cfg.spi = &lilka::SPI2; - cfg.frequencyHz = 868100000; // check what is allowed where you are - cfg.powerDbm = 0; - if (radio.begin(cfg) != SX126x::Result::OK) { - Serial.println("No SX126x found"); - return; - } - radio.startReceive(); -} - -void loop() { - static uint32_t lastTx = 0; - static uint32_t counter = 0; - SX126x::Packet packet; - if (radio.receive(packet)) { - Serial.printf("RX %.*s rssi=%.1f snr=%.1f\n", packet.length, (const char*)packet.data, packet.rssi, packet.snr); - } - if (millis() - lastTx > 10000) { - char msg[32]; - int n = snprintf(msg, sizeof(msg), "LILKA #%lu", (unsigned long)counter++); - radio.send(reinterpret_cast(msg), n); - lastTx = millis(); - } - vTaskDelay(pdMS_TO_TICKS(5)); -} diff --git a/lib/lilka_modules/library.json b/lib/lilka_modules/library.json index 7d9130c..5fafabd 100644 --- a/lib/lilka_modules/library.json +++ b/lib/lilka_modules/library.json @@ -15,7 +15,6 @@ "platforms": "espressif32", "include": [ "src", - "examples", "README.md" ] } diff --git a/lib/lilka_modules/src/lilka_modules/bmi260.cpp b/lib/lilka_modules/src/lilka_modules/bmi260.cpp index ef66b55..5f4fe64 100644 --- a/lib/lilka_modules/src/lilka_modules/bmi260.cpp +++ b/lib/lilka_modules/src/lilka_modules/bmi260.cpp @@ -94,8 +94,8 @@ bool Bmi260::loadConfig() { return false; } -Bmi260::Result Bmi260::begin(const Config& config) { - cfg = config; +Bmi260::Result Bmi260::begin(const Config& conf) { + cfg = conf; initialized = false; uint8_t accOdr, gyrOdr, accRange, gyrRange; switch (cfg.accelRangeG) { diff --git a/lib/lilka_modules/src/lilka_modules/bmi260.h b/lib/lilka_modules/src/lilka_modules/bmi260.h index ebf78e6..6eddb7b 100644 --- a/lib/lilka_modules/src/lilka_modules/bmi260.h +++ b/lib/lilka_modules/src/lilka_modules/bmi260.h @@ -37,7 +37,7 @@ class Bmi260 { InvalidParam, }; - Result begin(const Config& config); + Result begin(const Config& conf); bool read(Data& data); float temperature(); /// Блоб завантажено і чип повідомив init_ok. diff --git a/lib/lilka_modules/src/lilka_modules/can.cpp b/lib/lilka_modules/src/lilka_modules/can.cpp index 0e83d3d..acde50b 100644 --- a/lib/lilka_modules/src/lilka_modules/can.cpp +++ b/lib/lilka_modules/src/lilka_modules/can.cpp @@ -38,22 +38,22 @@ bool Can::timingFor(uint32_t bitrate, twai_timing_config_t& out) { } } -esp_err_t Can::begin(const Config& config) { +esp_err_t Can::begin(const Config& conf) { end(); twai_timing_config_t timing; - if (!timingFor(config.bitrate, timing)) return ESP_ERR_INVALID_ARG; + if (!timingFor(conf.bitrate, timing)) return ESP_ERR_INVALID_ARG; twai_mode_t mode = TWAI_MODE_NORMAL; - if (config.mode == Mode::ListenOnly) mode = TWAI_MODE_LISTEN_ONLY; - if (config.mode == Mode::NoAck) mode = TWAI_MODE_NO_ACK; - twai_general_config_t general = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)config.tx, (gpio_num_t)config.rx, mode); - general.rx_queue_len = config.rxQueue; - general.tx_queue_len = config.txQueue; + if (conf.mode == Mode::ListenOnly) mode = TWAI_MODE_LISTEN_ONLY; + if (conf.mode == Mode::NoAck) mode = TWAI_MODE_NO_ACK; + twai_general_config_t general = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)conf.tx, (gpio_num_t)conf.rx, mode); + general.rx_queue_len = conf.rxQueue; + general.tx_queue_len = conf.txQueue; twai_filter_config_t filter; - filter.acceptance_code = config.filterCode; - filter.acceptance_mask = config.filterMask; - filter.single_filter = config.singleFilter; + filter.acceptance_code = conf.filterCode; + filter.acceptance_mask = conf.filterMask; + filter.single_filter = conf.singleFilter; esp_err_t err = twai_driver_install(&general, &timing, &filter); if (err != ESP_OK) return err; diff --git a/lib/lilka_modules/src/lilka_modules/can.h b/lib/lilka_modules/src/lilka_modules/can.h index c9b0a08..3478cf7 100644 --- a/lib/lilka_modules/src/lilka_modules/can.h +++ b/lib/lilka_modules/src/lilka_modules/can.h @@ -18,8 +18,8 @@ class Can { }; struct Config { - int tx = pins::UART_TX; - int rx = pins::UART_RX; + int tx = pins::get("can", "tx"); + int rx = pins::get("can", "rx"); uint32_t bitrate = 500000; ///< 25k, 50k, 100k, 125k, 250k, 500k, 800k або 1M Mode mode = Mode::Normal; uint32_t filterCode = 0; @@ -30,7 +30,7 @@ class Can { }; ~Can(); - esp_err_t begin(const Config& config); + esp_err_t begin(const Config& conf); void end(); bool isRunning() const { return running; diff --git a/lib/lilka_modules/src/lilka_modules/cc1101.cpp b/lib/lilka_modules/src/lilka_modules/cc1101.cpp index 207d29f..7210e2a 100644 --- a/lib/lilka_modules/src/lilka_modules/cc1101.cpp +++ b/lib/lilka_modules/src/lilka_modules/cc1101.cpp @@ -264,9 +264,9 @@ bool Cc1101::configure() { return setFrequency(cfg.frequencyMhz); } -bool Cc1101::begin(const Config& config) { +bool Cc1101::begin(const Config& conf) { end(); - cfg = config; + cfg = conf; if (!cfg.spi) return false; settings = SPISettings(cfg.spiFrequency, MSBFIRST, SPI_MODE0); pinMode(cfg.csn, OUTPUT); diff --git a/lib/lilka_modules/src/lilka_modules/cc1101.h b/lib/lilka_modules/src/lilka_modules/cc1101.h index c0bed39..6671738 100644 --- a/lib/lilka_modules/src/lilka_modules/cc1101.h +++ b/lib/lilka_modules/src/lilka_modules/cc1101.h @@ -26,10 +26,10 @@ class Cc1101 { struct Config { SPIClass* spi = nullptr; - int csn = pins::SPI_CS; - int miso = pins::SPI_MISO; ///< для очікування CHIP_RDYn - int gdo0 = pins::RF_CE; - int gdo2 = pins::RF_IRQ; + int csn = pins::get("rf", "cs"); + int miso = pins::get("rf", "miso"); ///< для очікування CHIP_RDYn + int gdo0 = pins::get("rf", "ce"); + int gdo2 = pins::get("rf", "irq"); float frequencyMhz = 433.92f; Modulation modulation = Modulation::GFSK; uint32_t dataRate = 38400; ///< бод, 600 ... 500000 @@ -52,7 +52,7 @@ class Cc1101 { ~Cc1101(); /// false - чип не відповідає або параметри поза межами. - bool begin(const Config& config); + bool begin(const Config& conf); void end(); bool setFrequency(float mhz); diff --git a/lib/lilka_modules/src/lilka_modules/gps.cpp b/lib/lilka_modules/src/lilka_modules/gps.cpp index 1965b2c..4108c42 100644 --- a/lib/lilka_modules/src/lilka_modules/gps.cpp +++ b/lib/lilka_modules/src/lilka_modules/gps.cpp @@ -7,9 +7,9 @@ Gps::~Gps() { end(); } -esp_err_t Gps::begin(const Config& config) { +esp_err_t Gps::begin(const Config& conf) { end(); - cfg = config; + cfg = conf; uart_config_t uc = {}; uc.baud_rate = (int)cfg.baud; uc.data_bits = UART_DATA_8_BITS; diff --git a/lib/lilka_modules/src/lilka_modules/gps.h b/lib/lilka_modules/src/lilka_modules/gps.h index fca84de..8434f3c 100644 --- a/lib/lilka_modules/src/lilka_modules/gps.h +++ b/lib/lilka_modules/src/lilka_modules/gps.h @@ -14,13 +14,13 @@ class Gps { public: struct Config { uart_port_t port = UART_NUM_2; - int rx = pins::UART_RX; ///< Вхід у Лілку (TX модуля) - int tx = pins::UART_TX; ///< Вихід з Лілки (RX модуля), NC - лише прийом - uint32_t baud = 9600; + int rx = pins::get("gps", "rx"); ///< Вхід у Лілку (TX модуля) + int tx = pins::get("gps", "tx"); ///< Вихід з Лілки (RX модуля), NC - лише прийом + uint32_t baud = (uint32_t)lilka::config.getInt("gps", "baud", 9600); }; ~Gps(); - esp_err_t begin(const Config& config); + esp_err_t begin(const Config& conf); void end(); bool isRunning() const { return running; diff --git a/lib/lilka_modules/src/lilka_modules/ir.cpp b/lib/lilka_modules/src/lilka_modules/ir.cpp index bcf61c5..a5778d4 100644 --- a/lib/lilka_modules/src/lilka_modules/ir.cpp +++ b/lib/lilka_modules/src/lilka_modules/ir.cpp @@ -16,9 +16,9 @@ Ir::~Ir() { end(); } -esp_err_t Ir::begin(const Config& config) { +esp_err_t Ir::begin(const Config& conf) { end(); - cfg = config; + cfg = conf; esp_err_t err; if (cfg.tx >= 0) { rmt_config_t tx = RMT_DEFAULT_CONFIG_TX((gpio_num_t)cfg.tx, cfg.txChannel); diff --git a/lib/lilka_modules/src/lilka_modules/ir.h b/lib/lilka_modules/src/lilka_modules/ir.h index 734f53a..538932e 100644 --- a/lib/lilka_modules/src/lilka_modules/ir.h +++ b/lib/lilka_modules/src/lilka_modules/ir.h @@ -24,9 +24,9 @@ class Ir { static constexpr size_t MAX_DURATIONS = 380; struct Config { - int tx = pins::UART_TX; ///< NC - без передавача - int rx = pins::UART_RX; ///< NC - без приймача - uint32_t carrierHz = 38000; + int tx = pins::get("ir", "tx"); ///< NC - без передавача + int rx = pins::get("ir", "rx"); ///< NC - без приймача + uint32_t carrierHz = (uint32_t)lilka::config.getInt("ir", "carrier", 38000); uint8_t dutyPercent = 33; bool rxActiveLow = true; ///< KY-022 / VS1838B тримає 0, поки бачить несучу uint16_t rxIdleUs = 12000; ///< пауза, що завершує кадр @@ -35,7 +35,7 @@ class Ir { }; ~Ir(); - esp_err_t begin(const Config& config); + esp_err_t begin(const Config& conf); void end(); /// Надіслати сирі тривалості (мкс, починаючи з імпульсу). carrierHz = 0 - взяти з конфігурації. diff --git a/lib/lilka_modules/src/lilka_modules/nrf24.cpp b/lib/lilka_modules/src/lilka_modules/nrf24.cpp index d701d4b..1720b89 100644 --- a/lib/lilka_modules/src/lilka_modules/nrf24.cpp +++ b/lib/lilka_modules/src/lilka_modules/nrf24.cpp @@ -84,9 +84,9 @@ uint8_t Nrf24::status() { return xfer(CMD_NOP, nullptr, nullptr, 0); } -bool Nrf24::begin(const Config& config) { +bool Nrf24::begin(const Config& conf) { end(); - cfg = config; + cfg = conf; if (!cfg.spi) return false; if (cfg.addressWidth < 3 || cfg.addressWidth > 5) cfg.addressWidth = 5; if (cfg.payloadSize > MAX_PAYLOAD) cfg.payloadSize = MAX_PAYLOAD; diff --git a/lib/lilka_modules/src/lilka_modules/nrf24.h b/lib/lilka_modules/src/lilka_modules/nrf24.h index ec0bf0c..6b73322 100644 --- a/lib/lilka_modules/src/lilka_modules/nrf24.h +++ b/lib/lilka_modules/src/lilka_modules/nrf24.h @@ -24,9 +24,9 @@ class Nrf24 { struct Config { SPIClass* spi = nullptr; - int csn = pins::SPI_CS; - int ce = pins::RF_CE; - int irq = pins::RF_IRQ; ///< лише читається; NC - не використовується + int csn = pins::get("rf", "cs"); + int ce = pins::get("rf", "ce"); + int irq = pins::get("rf", "irq"); ///< лише читається; NC - не використовується uint8_t channel = 76; ///< 0-125, частота = 2400 + channel МГц DataRate dataRate = DataRate::Rate1M; uint8_t paLevel = 3; ///< 0 (-18 дБм) ... 3 (0 дБм) @@ -41,7 +41,7 @@ class Nrf24 { ~Nrf24(); /// false - чип не відповідає (або це не nRF24L01+). - bool begin(const Config& config); + bool begin(const Config& conf); void end(); void setChannel(uint8_t ch); diff --git a/lib/lilka_modules/src/lilka_modules/pins.h b/lib/lilka_modules/src/lilka_modules/pins.h index bf13a7f..218d4dd 100644 --- a/lib/lilka_modules/src/lilka_modules/pins.h +++ b/lib/lilka_modules/src/lilka_modules/pins.h @@ -1,61 +1,21 @@ #pragma once -#include - -/// Типові контакти модулів розширення Лілки v2. -/// -/// Нумерація - GPIO ESP32-S3. Контакти 3-10 роз'єму розширення (J2 на схемах модулів): -/// -/// | Контакт | GPIO | Контакт | GPIO | -/// |---|---|---|---| -/// | 3 | 44 (U0RXD) | 7 | 21 | -/// | 4 | 43 (U0TXD) | 8 | 14 | -/// | 5 | 48 | 9 | 13 | -/// | 6 | 47 | 10 | 12 | - -// Older SDK releases don't define the UART pins of the extension header yet. -#ifndef LILKA_EXT_RX -# define LILKA_EXT_RX 44 -#endif -#ifndef LILKA_EXT_TX -# define LILKA_EXT_TX 43 -#endif +#include namespace lilka { namespace mod { namespace pins { -/// Контакт роз'єму не під'єднано. +/// Контакт не під'єднано. constexpr int NC = -1; -// UART-модулі (GPS, IR, CAN) -constexpr int UART_RX = LILKA_EXT_RX; ///< Вхід у Лілку (контакт 3) -constexpr int UART_TX = LILKA_EXT_TX; ///< Вихід з Лілки (контакт 4) - -// SPI-модулі (LORA, RF) -constexpr int SPI_SCK = LILKA_EXT_RX; ///< Контакт 3 -constexpr int SPI_MISO = LILKA_EXT_TX; ///< Контакт 4 -constexpr int SPI_MOSI = LILKA_P3; ///< Контакт 5 -constexpr int SPI_CS = LILKA_P4; ///< Контакт 6 - -// 003 LORA -constexpr int LORA_RXEN = LILKA_P5; ///< Контакт 7 -constexpr int LORA_TXEN = LILKA_P6; ///< Контакт 8 -constexpr int LORA_NRST = LILKA_P7; ///< Контакт 9 -constexpr int LORA_BUSY = LILKA_P8; ///< Контакт 10 - -// 004 RF -constexpr int RF_CE = LILKA_P5; ///< nRF24 CE / CC1101 GDO0 (контакт 7) -constexpr int RF_IRQ = LILKA_P6; ///< nRF24 IRQ / CC1101 GDO2 (контакт 8) - -// I2C-модулі (GYRO MAGNET) -constexpr int I2C_SDA = LILKA_EXT_RX; ///< Контакт 3 -constexpr int I2C_SCL = LILKA_EXT_TX; ///< Контакт 4 - -// 006 GYRO MAGNET -constexpr int MAG_INT = LILKA_P3; ///< Контакт 5 -constexpr int GYR_INT1 = LILKA_P4; ///< Контакт 6 -constexpr int GYR_INT2 = LILKA_P5; ///< Контакт 7 +/// Контакт модуля з lilka::config (секція - плата модуля, ключ - сигнал), або NC, якщо його не задано. +/// +/// Вбудовані значення для Лілки v2 описані в lilka/config/defaults.h; їх можна перекрити файлом +/// у ``/sd/.lilka/config``, наприклад ``[lora] nss = 21``. +inline int get(const char* section, const char* key) { + return (int)lilka::config.getInt(section, key, NC); +} } // namespace pins } // namespace mod diff --git a/lib/lilka_modules/src/lilka_modules/sx126x.cpp b/lib/lilka_modules/src/lilka_modules/sx126x.cpp index 156acca..0b252ae 100644 --- a/lib/lilka_modules/src/lilka_modules/sx126x.cpp +++ b/lib/lilka_modules/src/lilka_modules/sx126x.cpp @@ -307,9 +307,9 @@ SX126x::Result SX126x::configure() { return Result::OK; } -SX126x::Result SX126x::begin(const Config& config) { +SX126x::Result SX126x::begin(const Config& conf) { end(); - cfg = config; + cfg = conf; if (!cfg.spi) return Result::InvalidParam; settings = SPISettings(cfg.spiFrequency, MSBFIRST, SPI_MODE0); pinMode(cfg.nss, OUTPUT); diff --git a/lib/lilka_modules/src/lilka_modules/sx126x.h b/lib/lilka_modules/src/lilka_modules/sx126x.h index 8f0d037..bde0195 100644 --- a/lib/lilka_modules/src/lilka_modules/sx126x.h +++ b/lib/lilka_modules/src/lilka_modules/sx126x.h @@ -31,11 +31,11 @@ class SX126x { struct Config { SPIClass* spi = nullptr; - int nss = pins::SPI_CS; - int busy = pins::LORA_BUSY; - int nrst = pins::LORA_NRST; - int rxen = pins::LORA_RXEN; - int txen = pins::LORA_TXEN; + int nss = pins::get("lora", "nss"); + int busy = pins::get("lora", "busy"); + int nrst = pins::get("lora", "nrst"); + int rxen = pins::get("lora", "rxen"); + int txen = pins::get("lora", "txen"); Chip chip = Chip::SX1262; uint32_t frequencyHz = 868100000; uint8_t spreadingFactor = 7; ///< 5-12 @@ -58,7 +58,7 @@ class SX126x { }; ~SX126x(); - Result begin(const Config& config); + Result begin(const Config& conf); void end(); /// Надіслати пакет і дочекатись TxDone. Після передачі повертається в прийом, якщо він був увімкнений. diff --git a/lib/lilka_modules/src/lilka_modules/tmag5273.cpp b/lib/lilka_modules/src/lilka_modules/tmag5273.cpp index 493be20..9f4e311 100644 --- a/lib/lilka_modules/src/lilka_modules/tmag5273.cpp +++ b/lib/lilka_modules/src/lilka_modules/tmag5273.cpp @@ -35,8 +35,8 @@ bool Tmag5273::readRegister(uint8_t reg, uint8_t* data, size_t n) { return true; } -bool Tmag5273::begin(const Config& config) { - cfg = config; +bool Tmag5273::begin(const Config& conf) { + cfg = conf; uint8_t man[2] = {}; if (!readRegister(REG_MANUFACTURER_ID_LSB, man, 2)) return false; if (man[0] != 0x49 || man[1] != 0x54) return false; // "TI" diff --git a/lib/lilka_modules/src/lilka_modules/tmag5273.h b/lib/lilka_modules/src/lilka_modules/tmag5273.h index 704d775..33b44ee 100644 --- a/lib/lilka_modules/src/lilka_modules/tmag5273.h +++ b/lib/lilka_modules/src/lilka_modules/tmag5273.h @@ -24,7 +24,7 @@ class Tmag5273 { float x, y, z; ///< мкТл }; - bool begin(const Config& config); + bool begin(const Config& conf); bool read(Data& data); float temperature(); /// Повний діапазон по осях, мТл.