#!/usr/bin/env python3 """SMS step 3: show a received message on the screen and beep.""" W = "/home/viktor/ogd77rel/uv_src/OpenGD77_MDUV380_DM1701_20260130/MDUV380_firmware/application" p = W + "/source/applicationMain.c" s = open(p).read() if "smsGetLatest" in s: print("already showing messages") raise SystemExit(0) old = "\t\tsmsTick();// turn received data bursts into messages\n" assert old in s, "smsTick call not found" new = """\t\tsmsTick();// turn received data bursts into messages \t\tif (smsHasUnread()) \t\t{ \t\t\tconst smsMessage_t *msg = smsGetLatest(); \t\t\tif (msg != NULL) \t\t\t{ \t\t\t\tchar smsLine[SMS_MAX_TEXT_LENGTH + 16]; \t\t\t\tsnprintf(smsLine, sizeof(smsLine), "%u: %s", (unsigned int)msg->srcId, msg->text); \t\t\t\tuiNotificationShow(NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_ID_MESSAGE, 10000, smsLine, true); \t\t\t\tsoundSetMelody(MELODY_ACK_BEEP); \t\t\t\tsmsMarkRead(); \t\t\t} \t\t} """ s = s.replace(old, new, 1) open(p, "w").write(s) print("applicationMain.c: incoming SMS is shown and beeps")