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 6, 2023

It turns out that this is essentially wrapping the ANT+ data page 48 - Radar Targets A (0x30) and Data Page 49 – Radar Targets B (0x31).
byte 4 matches the first byte of the ANT+ page exactly. see screen shot

image

However, the target ranges is a bit messed up. maybe to obfuscate the data? not sure.

@antokne
Copy link
Author

antokne commented Sep 6, 2023

Results from test with radar in demo mode:

ranges: 128 134 138 144
ranges: 128 131 138 141
ranges: 125 131 134 141
ranges: 125 128 134 138
ranges: 122 128 131 138
ranges: 122 125 131 138
ranges: 119 125 128 134
ranges: 119 122 128 134
ranges: 116 122 125 131
ranges: 116 119 125 131
ranges: 112 119 125 128
ranges: 112 116 122 128
ranges: 109 116 122 125
ranges: 109 112 119 125
ranges: 106 112 119 122
ranges: 106 112 116 122
ranges: 103 109 116 119
ranges: 103 109 112 119
ranges: 100 106 112 116
ranges: 100 103 109 112
ranges:  97 103 106 112
ranges:  97 100 106 109
ranges:  94 100 103 109
ranges:  94  97 103 106
ranges:  91  97 100 106
ranges:  91  94 100 103
ranges:  88  94  97 103
ranges:  88  91  97 100
ranges:  84  91  94 100
ranges:  84  88  94 100
ranges:  81  88  91  97
ranges:  81  84  91  97
ranges:  78  84  88  94
ranges:  78  81  88  94
ranges:  75  81  88  91
ranges:  75  78  84  91
ranges:  72  78  84  88
ranges:  72  75  81  88
ranges:  69  75  81  84
ranges:  69  75  78  84
ranges:  66  72  78  81
ranges:  66  72  75  81
ranges:  62  69  75  78
ranges:  62  69  72  78
ranges:  62  66  72  75
ranges:  59  66  69  75
ranges:  59  62  69  72
ranges:  56  62  66  72
ranges:  53  59  62  69
ranges:  53  56  62  66
ranges:  50  56  59  66
ranges:  50  53  59  62
ranges:  47  53  56  62
ranges:  47  50  56  62
ranges:  44  50  53  59
ranges:  44  47  53  59
ranges:  41  47  50  56
ranges:  41  44  50  56
ranges:  38  44  50  53
ranges:  38  41  47  53
ranges:  34  41  47  50
ranges:  34  38  44  50
ranges:  31  38  44  47
ranges:  31  38  41  47
ranges:  28  34  41  44
ranges:  28  34  38  44
ranges:  25  31  38  41
ranges:  25  31  34  41
ranges:  25  28  34  38
ranges:  22  28  31  38
ranges:  22  25  31  34
ranges:  19  22  28  31
ranges:  16  22  25  31
ranges:  16  19  25  28
ranges:  12  19  22  28
ranges:  12  16  22  25
ranges:   9  16  19  25
ranges:   9  12  19  25
ranges:   6  12  16  22
ranges:   6   9  16  22
ranges:   3   9  12  19
ranges:   3   6  12  19
ranges:   0   6  12  16
ranges:   3   9  16   0
ranges:   3   9  12   0
ranges:   0   6  12   0
ranges:   0   6   9   0
ranges:   3   9   0   0
ranges:   3   6   0   0
ranges:   0   6   0   0
ranges:   3   0   0   0
ranges:   0   0   0   0

Note at the bottom when a target is zero it is removed and the list shifts one to the left.

@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