#!/usr/bin/env python3 """Patch 1 of RX support: new RX event type + Slot Type encoder.""" W = "/home/viktor/ogd77rel/uv_src/OpenGD77_MDUV380_DM1701_20260130/MDUV380_firmware/application" # --- 1. new RX event type ------------------------------------------------- p = W + "/include/functions/hotspot.h" s = open(p).read() if "HOTSPOT_RX_DATA_FRAME" not in s: a = "\tHOTSPOT_RX_STOP,\n" assert a in s, "RX enum anchor missing" s = s.replace(a, a + "\tHOTSPOT_RX_DATA_FRAME,// a packet data burst (SMS etc) was received off air\n", 1) open(p, "w").write(s) print("hotspot.h: RX event added") else: print("hotspot.h: already has RX event") # --- 2. bring the Slot Type encoder over from the older MK22 branch ------- src = open("/home/viktor/OpenGD77/firmware/source/hotspot/DMRSlotType.c").read() start = src.index("static const uint16_t ENCODING_TABLE_2087[] =") table = src[start:src.index("};", start) + 2] p = W + "/source/functions/hotspot.c" s = open(p).read() if "ENCODING_TABLE_2087" in s: print("hotspot.c: encoder already present") raise SystemExit(0) anchor = "static void BPTCencode(const uint8_t *inputData, uint8_t *outputData)\n{" assert anchor in s, "BPTCencode definition not found" header = ( "// Slot Type encoder, needed to build received data bursts for the host.\n" "// Golay(20,8) table and logic come from the project's own DMRSlotType implementation\n" "// (present in the MK22 branch, absent here because stock firmware never sent data).\n" ) func = """ // Writes colour code + data type (FEC protected) into the Slot Type half-bursts of a frame. static void DMRSlotTypeEncode(uint32_t colorCode, uint32_t dataType, uint8_t *frame) { \tuint8_t slotType[3]; \tslotType[0] = (colorCode << 4) & 0xF0U; \tslotType[0] |= (dataType << 0) & 0x0FU; \tuint16_t cksum = ENCODING_TABLE_2087[slotType[0]]; \tslotType[1] = (cksum >> 0) & 0xFFU; \tslotType[2] = (cksum >> 8) & 0xFFU; \tframe[12] = (frame[12] & 0xC0U) | ((slotType[0] >> 2) & 0x3FU); \tframe[13] = (frame[13] & 0x0FU) | ((slotType[0] << 6) & 0xC0U) | ((slotType[1] >> 2) & 0x30U); \tframe[19] = (frame[19] & 0xF0U) | ((slotType[1] >> 2) & 0x0FU); \tframe[20] = (frame[20] & 0x03U) | ((slotType[1] << 6) & 0xC0U) | ((slotType[2] >> 2) & 0x3CU); } """ s = s.replace(anchor, header + table + func + anchor, 1) open(p, "w").write(s) print("hotspot.c: slot type encoder added (table %d bytes)" % len(table))