Skip to content

Instantly share code, notes, and snippets.

@antokne
Last active October 30, 2023 01:25
Show Gist options
  • Save antokne/1c4ce6e487c6dfab63de703bd9d3df1a to your computer and use it in GitHub Desktop.
Save antokne/1c4ce6e487c6dfab63de703bd9d3df1a to your computer and use it in GitHub Desktop.
Magene Radar Data
Command to enable radar data over BTLE send to char 0xE5CC02
0x57,0x09,0x01
Disable
0x57,0x09,0x00
Then set notify on 0xE5CC02
Data as follows from Radar demo mode
No cars
570900 30 00 00 00 00 00 00 00
1 car
570900 30 01 00 29 00 00 04 00
2 cars
570900 30 05 00 AC 0B 00 44 00
3 cars
570900 30 15 00 2A DB 02 44 04
4 cars
570900 30 55 00 E9 CA BA 44 44
5 cars
570900 30 55 00 68 BA B2 44 44
570900 31 01 00 2E 00 00 04 00
6 cars
570900 30 55 00 26 9A AE 44 44
570900 31 05 00 AC 0B 00 44 00
7 cars
570900 30 55 00 A4 89 A6 44 44
570900 31 15 00 2B EB 02 44 04
8 cars
570900 30 55 00 23 69 A2 44 44
570900 31 55 00 E9 CA BA 44 44
570900 is always the same
byte 4: - 30 - Radar Targets A
31 - Radar Targets B, if more than 4 cars
byte 5 - 2 bits per target target 1 bits 0:1, target 2 2:3 etc. values are:
0 - no threat,
1 - vehicle approaches,
2 - Vehicle Fast Approach
byte 6 - Threat side not appeared to be used
bytes 7-9 - Target ranges possibly 6 bits per target?
// Bit odd this...
// Range target 1 is right 6 bits of first byte.
let rangeTarget1 = Double(firstByte & 0x3F) * 3.125
// Range Target 2 is first byte right shifted 6 (left 2 bits) + 4 right bits of second byte left shifted twice
let rangeTarget2 = Double((firstByte >> 6) + ((secondByte & 0xF) << 2)) * 3.125
// Range Target 3 second byte right shifted 4 (left 4 bits) + right 2 bits of third byte left shifted 4
let rangeTarget3 = Double(secondByte >> 4 + (thirdByte & 0x3) << 4 ) * 3.125
// Range Target 4 left 6 bits of third byte right shifted 2.
let rangeTarget4 = Double(thirdByte >> 2) * 3.125
bytes 10-11 - Speed in units of 3.04 m/s 4 bits per target.
speed target 1 is right 4 bits of byte 10
speed target 2 is left 4 bits of byte 10
speed target 1 is right 4 bits of byte 11
speed target 2 is left 4 bits of byte 11
@antokne
Copy link
Author

antokne commented Sep 11, 2023

I created a graph to make it easier to visualise.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment