Files
meshcore-bot/modules/enums.py
Stacy Olivas ce884cee87 fix: auth, db migrations, retry, chunking, socket race, trace, timezone, repeater, and ruff/mypy cleanup
BUG-001: web viewer login/session auth (in web viewer commit)
BUG-002: db_manager ALTER TABLE for missing channel_operations and
  feed_message_queue columns on startup
BUG-015: scheduler thread blocked on future.result(); replaced all
  blocking waits with add_done_callback (fire-and-forget)
BUG-016: reboot_radio sends meshcore.commands.reboot() before disconnect
BUG-017: radio disconnect uses asyncio.wait_for(timeout=10)
BUG-022: custom asyncio loop exception handler suppresses IndexError
  from meshcore parser at DEBUG level
BUG-024: last_db_backup_run updated after each run; 2-min startup
  window; last-run seeded from DB on restart
BUG-025: send_channel_message retries up to 2 times (2s delay) on
  no_event_received via _is_no_event_received() helper
BUG-026: split_text_into_chunks() and get_max_message_length() added
  to CommandManager; keyword dispatch uses send_response_chunked()
BUG-028: byte_data = b"" initialised before try block in
  decode_meshcore_packet to prevent UnboundLocalError in except handler
TraceCommand: path nodes reversed and return path truncated; fixed
format_elapsed_display: UTC normalisation before elapsed computation (#75)
RepeaterManager: auto_manage_contacts guard before any purge logic (#50)
Command aliases: [Aliases] config section injects shorthands at startup
JSON logging: _JsonFormatter; json_logging = true in [Logging]
Structured JSON logging compatible with Loki, Elasticsearch, Splunk
Discord bridge, Telegram bridge, and all service plugins updated
MeshGraph edge promotion logic corrected
Shutdown: scheduler and meshcore disconnect joined cleanly; log spam fixed
All modules: ruff and mypy cleanup applied (type annotations, imports)
2026-03-17 18:07:18 -07:00

71 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
Enums for MeshCore packet parsing
Based on the meshcore protocol specifications
"""
from enum import Enum, Flag
class AdvertFlags(Flag):
"""Advertisement flags for MeshCore packets - matches C++ AdvertDataHelpers.h"""
# Type flags (bits 0-3)
ADV_TYPE_NONE = 0x00
ADV_TYPE_CHAT = 0x01
ADV_TYPE_REPEATER = 0x02
ADV_TYPE_ROOM = 0x03
ADV_TYPE_SENSOR = 0x04
# Feature flags (bits 4-7)
ADV_LATLON_MASK = 0x10 # Bit 4 - Has location data
ADV_FEAT1_MASK = 0x20 # Bit 5 - Future feature 1
ADV_FEAT2_MASK = 0x40 # Bit 6 - Future feature 2
ADV_NAME_MASK = 0x80 # Bit 7 - Has name data
# Legacy aliases for backward compatibility
IsCompanion = ADV_TYPE_CHAT
IsRepeater = ADV_TYPE_REPEATER
IsRoomServer = ADV_TYPE_ROOM
HasLocation = ADV_LATLON_MASK
HasName = ADV_NAME_MASK
HasNameBit7 = ADV_NAME_MASK
class PayloadType(Enum):
"""Payload types for MeshCore packets - matches C++ definitions"""
REQ = 0x00 # PAYLOAD_TYPE_REQ
RESPONSE = 0x01 # PAYLOAD_TYPE_RESPONSE
TXT_MSG = 0x02 # PAYLOAD_TYPE_TXT_MSG
ACK = 0x03 # PAYLOAD_TYPE_ACK
ADVERT = 0x04 # PAYLOAD_TYPE_ADVERT
GRP_TXT = 0x05 # PAYLOAD_TYPE_GRP_TXT
GRP_DATA = 0x06 # PAYLOAD_TYPE_GRP_DATA
ANON_REQ = 0x07 # PAYLOAD_TYPE_ANON_REQ
PATH = 0x08 # PAYLOAD_TYPE_PATH
TRACE = 0x09 # PAYLOAD_TYPE_TRACE
MULTIPART = 0x0A # PAYLOAD_TYPE_MULTIPART
Type11 = 0x0B # Reserved
Type12 = 0x0C # Reserved
Type13 = 0x0D # Reserved
Type14 = 0x0E # Reserved
RAW_CUSTOM = 0x0F # PAYLOAD_TYPE_RAW_CUSTOM
class PayloadVersion(Enum):
"""Payload versions for MeshCore packets - matches original mctomqtt.py"""
VER_1 = 0x00 # Version 1
VER_2 = 0x01 # Reserved for future protocol extensions
VER_3 = 0x02 # Reserved for future protocol extensions
VER_4 = 0x03 # Reserved for future protocol extensions
class RouteType(Enum):
"""Route types for MeshCore packets - matches C++ definitions"""
TRANSPORT_FLOOD = 0x00 # ROUTE_TYPE_TRANSPORT_FLOOD
FLOOD = 0x01 # ROUTE_TYPE_FLOOD
DIRECT = 0x02 # ROUTE_TYPE_DIRECT
TRANSPORT_DIRECT = 0x03 # ROUTE_TYPE_TRANSPORT_DIRECT
class DeviceRole(Enum):
"""Device roles in MeshCore network"""
Companion = "Companion"
Repeater = "Repeater"
RoomServer = "RoomServer"