Skip to content

Commit 33cf554

Browse files
authored
Merge pull request #713 from wooferguy/dev
SubGhz: Magellan Event Code Update
2 parents 200a613 + 9298e56 commit 33cf554

File tree

1 file changed

+75
-21
lines changed

1 file changed

+75
-21
lines changed

lib/subghz/protocols/magellan.c

+75-21
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,38 @@ static void subghz_protocol_magellan_check_remote_controller(SubGhzBlockGeneric*
360360
*
361361
* 0x1275EC => 0x12-event codes, 0x75EC-serial (dec 117236)
362362
*
363-
* event codes
364-
* bit_0: 1-Open/Motion, 0-close/ok
365-
* bit_1: 1-Tamper On (alarm), 0-Tamper Off (ok)
366-
* bit_2: ?
367-
* bit_3: 1-power on
368-
* bit_4: model type - wireless reed
369-
* bit_5: model type - motion sensor
370-
* bit_6: ?
371-
* bit_7: ?
363+
* Event codes consist of two parts:
364+
* - The upper nibble (bits 7-4) represents the event type:
365+
* - 0x00: Nothing
366+
* - 0x01: Door
367+
* - 0x02: Motion
368+
* - 0x03: Smoke Alarm
369+
* - 0x04: REM1
370+
* - 0x05: REM1 with subtype Off1
371+
* - 0x06: REM2
372+
* - 0x07: REM2 with subtype Off1
373+
* - Others: Unknown
374+
* - The lower nibble (bits 3-0) represents the event subtype, which varies based on the model type:
375+
* - If the model type is greater than 0x03 (e.g., REM1 or REM2):
376+
* - 0x00: Arm1
377+
* - 0x01: Btn1
378+
* - 0x02: Btn2
379+
* - 0x03: Btn3
380+
* - 0x08: Reset
381+
* - 0x09: LowBatt
382+
* - 0x0A: BattOk
383+
* - 0x0B: Learn
384+
* - Others: Unknown
385+
* - Otherwise:
386+
* - 0x00: Sealed
387+
* - 0x01: Alarm
388+
* - 0x02: Tamper
389+
* - 0x03: Alarm + Tamper
390+
* - 0x08: Reset
391+
* - 0x09: LowBatt
392+
* - 0x0A: BattOk
393+
* - 0x0B: Learn
394+
* - Others: Unknown
372395
*
373396
*/
374397
uint64_t data_rev = subghz_protocol_blocks_reverse_key(instance->data >> 8, 24);
@@ -377,18 +400,49 @@ static void subghz_protocol_magellan_check_remote_controller(SubGhzBlockGeneric*
377400
}
378401

379402
static void subghz_protocol_magellan_get_event_serialize(uint8_t event, FuriString* output) {
380-
furi_string_cat_printf(
381-
output,
382-
"%s%s%s%s%s%s%s%s",
383-
((event >> 4) & 0x1 ? (event & 0x1 ? " Open" : " Close") :
384-
(event & 0x1 ? " Motion" : " Ok")),
385-
((event >> 1) & 0x1 ? ", Tamper On\n(Alarm)" : ""),
386-
((event >> 2) & 0x1 ? ", ?" : ""),
387-
((event >> 3) & 0x1 ? ", Power On" : ""),
388-
((event >> 4) & 0x1 ? ", MT:Wireless_Reed" : ""),
389-
((event >> 5) & 0x1 ? ", MT:Motion_\nSensor" : ""),
390-
((event >> 6) & 0x1 ? ", ?" : ""),
391-
((event >> 7) & 0x1 ? ", ?" : ""));
403+
const char* event_type;
404+
const char* event_subtype;
405+
406+
switch ((event >> 4) & 0x0F) {
407+
case 0x00: event_type = "Nothing"; break;
408+
case 0x01: event_type = "Door"; break;
409+
case 0x02: event_type = "Motion"; break;
410+
case 0x03: event_type = "Smoke Alarm"; break;
411+
case 0x04: event_type = "REM1"; break;
412+
case 0x05:
413+
event_type = "REM1";
414+
event_subtype = "Off1";
415+
furi_string_cat_printf(output, "%s - %s", event_type, event_subtype);
416+
return;
417+
case 0x06:
418+
event_type = "REM2";
419+
event_subtype = "Off1";
420+
furi_string_cat_printf(output, "%s - %s", event_type, event_subtype);
421+
return;
422+
default: event_type = "Unknown"; break;
423+
}
424+
425+
switch (event & 0x0F) {
426+
case 0x00:
427+
event_subtype = (((event >> 4) & 0x0F) > 0x03) ? "Arm1" : "Sealed";
428+
break;
429+
case 0x01:
430+
event_subtype = (((event >> 4) & 0x0F) > 0x03) ? "Btn1" : "Alarm";
431+
break;
432+
case 0x02:
433+
event_subtype = (((event >> 4) & 0x0F) > 0x03) ? "Btn2" : "Tamper";
434+
break;
435+
case 0x03:
436+
event_subtype = (((event >> 4) & 0x0F) > 0x03) ? "Btn3" : "Alarm + Tamper";
437+
break;
438+
case 0x08: event_subtype = "Reset"; break;
439+
case 0x09: event_subtype = "LowBatt"; break;
440+
case 0x0A: event_subtype = "BattOk"; break;
441+
case 0x0B: event_subtype = "Learn"; break;
442+
default: event_subtype = "Unknown"; break;
443+
}
444+
445+
furi_string_cat_printf(output, "%s - %s", event_type, event_subtype);
392446
}
393447

394448
uint8_t subghz_protocol_decoder_magellan_get_hash_data(void* context) {

0 commit comments

Comments
 (0)