-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Aston Martin Smartire TPMS sensor, Vantage DB9 protocol #3072
Open
ProfBoc75
wants to merge
3
commits into
master
Choose a base branch
from
feat-aston_martin_smartire
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/** @file | ||
Aston Martin Smartire TPMS sensor. | ||
|
||
Copyright (C) 2024 Bruno OCTAU (ProfBoc75) | ||
|
||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
*/ | ||
|
||
#include "decoder.h" | ||
|
||
/** | ||
Aston Martin Smartire TPMS sensor. | ||
- Vantage Smartire / Aston Martin DB9 protocol, from 1/2005 till 12/2011 | ||
|
||
S.a. issue #3067 | ||
|
||
Data Layout: | ||
- Total of 10 messages at a time, OOK PCM and Differential MC coded. | ||
- 2 types of message have been identified. | ||
- 1 Message with Pressure information follow by | ||
- 1 Message with Temperature information | ||
- Both messages are repeated 5 times | ||
- In case of fast pressure increasing, the pressure message is sent with Fast increased flag, then the 10 messages each 2 seconds with the flag. | ||
|
||
Flex decoder: | ||
|
||
rtl_433 -X 'n=Aston-Martin-Smartire,m=OOK_PCM,s=167,l=167,r=600,preamble=32b4,decode_dm' | ||
|
||
Preamble/Syncword .... : 0x32b4 | ||
|
||
6 bytes message | ||
Byte Position 0 1 2 3 4 5 | ||
Sample 28 3f ff ff 00 fa | ||
VV |I II II || CC | ||
| || | ||
+----+-+ +----------+ | ||
| 1234 | | 12345678 | | ||
| MMII | | FFFFFFXX | | ||
+------+ +----------+ | ||
|
||
- VV: {8} Pressure value, offset 40, scale 2.5 if Message Type = 0x00 | ||
Temperature Value, offset 40, if Message Type = 0x01 | ||
- MM: {2} Message Type, 0x00 or 0x01 | ||
- II:{22} Sensor ID, | ||
- F : {8} Flags, F1 = quick inflate detected, | ||
F2 to F6 are unknown, | ||
X78:{2} Looks like XOR/checksum/Parity from previous bits, not decoded. | ||
- C : {7} CRC-7, poly 0x45, init 0x6f, final XOR 0x00 | ||
|
||
Bitbench: | ||
|
||
TEMP/PRESSURE 8d MESSAGE_TYPE 2b ID 22d FAST_INCREASE 1b FLAGS ? 5b PARITY_XOR ? 2b CRC_SEVEN 7b 1x | ||
|
||
*/ | ||
|
||
static int tpms_aston_martin_decode(r_device *decoder, bitbuffer_t *bitbuffer) | ||
{ | ||
bitbuffer_t decoded = { 0 }; | ||
uint8_t *b; | ||
uint8_t const preamble_pattern[] = {0x32, 0xb4}; | ||
uint8_t len_msg = 6; | ||
float pressure_kPa = 0; | ||
int temperature_C = 0; | ||
|
||
if (bitbuffer->num_rows != 1) { | ||
return DECODE_ABORT_EARLY; | ||
} | ||
|
||
int pos = bitbuffer_search(bitbuffer, 0, 0, preamble_pattern, sizeof(preamble_pattern) * 8); | ||
if (pos >= bitbuffer->bits_per_row[0]) { | ||
decoder_logf(decoder, 1, __func__, "Preamble not found"); | ||
return DECODE_ABORT_EARLY; | ||
} | ||
|
||
decoder_log_bitrow(decoder, 1, __func__, bitbuffer->bb[0], bitbuffer->bits_per_row[0], "MSG"); | ||
bitbuffer_differential_manchester_decode(bitbuffer, 0, pos + sizeof(preamble_pattern) * 8, &decoded, len_msg * 8); | ||
decoder_log_bitrow(decoder, 1, __func__, decoded.bb[0], decoded.bits_per_row[0], "DMC"); | ||
|
||
// check msg length | ||
if (decoded.bits_per_row[0] < (len_msg * 8) - 1 ) { // always missing last bit | ||
decoder_logf(decoder, 1, __func__, "Too short"); | ||
return DECODE_ABORT_LENGTH; | ||
} | ||
|
||
b = decoded.bb[0]; | ||
|
||
// verify checksum | ||
if (crc7(b, len_msg, 0x45, 0x6f)) { | ||
decoder_logf(decoder, 1, __func__, "crc error"); | ||
return DECODE_FAIL_MIC; // crc mismatch | ||
} | ||
|
||
int id = ((b[1] & 0x3f) << 16) | (b [2] << 8) | b[3]; | ||
int msg_type = (b[1] & 0xc0) >> 6; | ||
int value = b[0] - 40; | ||
|
||
if (msg_type == 0) { // pressure | ||
pressure_kPa = value * 2.5; | ||
} | ||
else if (msg_type == 1) { // temperature | ||
temperature_C = value; | ||
} | ||
else { | ||
decoder_logf(decoder, 1, __func__, "Unknown message type %x", msg_type); | ||
return DECODE_ABORT_EARLY; | ||
} | ||
|
||
int inflate = (b[4] & 0x80) >> 7; | ||
int flags = b[4] & 0x7f; | ||
|
||
/* clang-format off */ | ||
data_t *data = data_make( | ||
"model", "", DATA_STRING, "Aston-Martin-Smartire", | ||
"type", "", DATA_STRING, "TPMS", | ||
"id", "", DATA_INT, id, | ||
"pressure_kPa", "Pressure", DATA_COND, msg_type == 0, DATA_FORMAT, "%.1f kPa", DATA_DOUBLE, (double)pressure_kPa, | ||
"temperature_C", "Temperature", DATA_COND, msg_type == 1, DATA_FORMAT, "%.1f C", DATA_DOUBLE, (double)temperature_C, | ||
"inflate", "Inflate", DATA_COND, inflate == 1, DATA_INT, 1, | ||
"flags", "Flags", DATA_FORMAT, "%07b", DATA_INT, flags, | ||
"mic", "Integrity", DATA_STRING, "CRC", | ||
NULL); | ||
/* clang-format on */ | ||
|
||
decoder_output_data(decoder, data); | ||
return 1; | ||
} | ||
|
||
static char const *const output_fields[] = { | ||
"model", | ||
"type", | ||
"id", | ||
"pressure_kPa", | ||
"temperature_C", | ||
"inflate", | ||
"flags", | ||
"mic", | ||
NULL, | ||
}; | ||
|
||
r_device const tpms_aston_martin = { | ||
.name = "Aston Martin Smartire TPMS sensor, Vantage DB9 protocol", | ||
.modulation = OOK_PULSE_PCM, | ||
.short_width = 167, | ||
.long_width = 167, | ||
.reset_limit = 1000, | ||
.decode_fn = &tpms_aston_martin_decode, | ||
.fields = output_fields, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a single dash, and should be shorter. Since SmarTire is the manufacturer maybe
SmarTire-AM
?And decoder file could be tpms_smartire.c perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, renamed everywhere.