-
Notifications
You must be signed in to change notification settings - Fork 123
Define new protocol in RF_Protocols.h
Let's take the example from decode 0xB1 sniffed data.
These are the Parameters needed to be defined:
typedef struct PROTOCOL_DATA_UINT8_T
{
// pointer to array of uint8_t elements
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_CODE);
// size of the array
uint8_t size;
} PROTOCOL_DATA_UINT8_T;
typedef struct PROTOCOL_DATA_UINT16_T
{
// pointer to array of uint16_t elements
SI_VARIABLE_SEGMENT_POINTER(dat, uint16_t, SI_SEG_CODE);
// size of the array
uint8_t size;
} PROTOCOL_DATA_UINT16_T;
typedef struct BUCKET_PROTOCOL_DATA
{
// array and array size of buckets
PROTOCOL_DATA_UINT16_T buckets;
// array and array size of start buckets
PROTOCOL_DATA_UINT8_T start;
// array and array size of bit 0 buckets
PROTOCOL_DATA_UINT8_T bit0;
// array and array size of bit 1 buckets
PROTOCOL_DATA_UINT8_T bit1;
// array and array size of end buckets
PROTOCOL_DATA_UINT8_T end;
// bit count for this protocol
uint8_t bit_count;
} BUCKET_PROTOCOL_DATA;
/*
* New protocol description
*/
#if EFM8BB1_SUPPORT_new_protocol_PROTOCOL == 1
#define new_protocol
SI_SEGMENT_VARIABLE(PROTOCOL_BUCKETS(new_protocol)[], static uint16_t, SI_SEG_CODE) = { };
SI_SEGMENT_VARIABLE(PROTOCOL_START(new_protocol)[], static uint8_t, SI_SEG_CODE) = { };
SI_SEGMENT_VARIABLE(PROTOCOL_BIT0(new_protocol)[], static uint8_t, SI_SEG_CODE) = { };
SI_SEGMENT_VARIABLE(PROTOCOL_BIT1(new_protocol)[], static uint8_t, SI_SEG_CODE) = { };
SI_SEGMENT_VARIABLE(PROTOCOL_END(new_protocol)[], static uint8_t, SI_SEG_CODE) = { };
#endif
First the pulse time needs to be found.
We do have these 4 buckets from this sniffed data:
Hex: AA B1 04 017C 046A 0BCC 2378 3818190908181908190909090908190819081818190909091A 55
Bucket 0 length: 380µs
Bucket 1 length: 1130µs
Bucket 2 length: 3020µs
Bucket 3 length: 9080µs
So you are able to insert these values in the PROTOCOL_BUCKETS
array:
SI_SEGMENT_VARIABLE(PROTOCOL_BUCKETS(new_protocol)[], static uint16_t, SI_SEG_CODE) = { 380, 1130, 3020, 9080 };`
Use the defined macro HIGH(x) or LOW(x) to define a bucket number as high or low bucket.
Implement in RF_Config.h and RF_Protocols.h a new compiler flag for this protocol.
#define EFM8BB1_SUPPORT_new_protocol_PROTOCOL 1 // new_protocol
Find the sync bucket like this example:
A3
[A] & 0x07 == 2
: So first sync bucket is number 2 (high)
[3] & 0x07 == 3
: So second sync bucket is number 3 (low)
So you are able to insert these values in the PROTOCOL_START
array:
SI_SEGMENT_VARIABLE(PROTOCOL_START(new_protocol)[], static uint8_t, SI_SEG_CODE) = { HIGH(2), LOW(3) };`
As a bit 0 is high Bucket 0 length: 380µs
followed by low Bucket 1 length: 1130µs
the result will be:
SI_SEGMENT_VARIABLE(PROTOCOL_BIT0(new_protocol)[], static uint8_t, SI_SEG_CODE) = { HIGH(0), LOW(1) };
As a bit 1 is high Bucket 1 length: 1130µs
followed by low Bucket 0 length: 380µs
the result will be:
SI_SEGMENT_VARIABLE(PROTOCOL_BIT1(new_protocol)[], static uint8_t, SI_SEG_CODE) = { HIGH(1), LOW(0) };
This can be use if the protocol does include like a pause between the transmit repeats:
SI_SEGMENT_VARIABLE(PROTOCOL_END(new_protocol)[], static uint8_t, SI_SEG_CODE) = { LOW(0) };
If this is not used just do not define an PROTOCOL_END.
By the decoded data the bit count would be 24 bits.
This may vary by the used protocol.
Below the single protocols there is a array where you have to add the new protocol data.
SI_SEGMENT_VARIABLE(PROTOCOL_DATA[], static struct BUCKET_PROTOCOL_DATA, SI_SEG_CODE)
Just add at the end of the array the new data and complete it with the bit count and "inverse" parameter.
When no PROTOCOL_END is used:
#if EFM8BB1_SUPPORT_new_protocol_PROTOCOL == 1
/*
* New protocol description
*/
{
{ &PROTOCOL_BUCKETS(new_protocol), ARRAY_LENGTH(PROTOCOL_BUCKETS(new_protocol)) },
{ &PROTOCOL_START(new_protocol), ARRAY_LENGTH(PROTOCOL_START(new_protocol)) },
{ &PROTOCOL_BIT0(new_protocol), ARRAY_LENGTH(PROTOCOL_BIT0(new_protocol)) },
{ &PROTOCOL_BIT1(new_protocol), ARRAY_LENGTH(PROTOCOL_BIT1(new_protocol)) },
{ NULL, 0 },
24
}
#endif
When PROTOCOL_END is used:
#if EFM8BB1_SUPPORT_new_protocol_PROTOCOL == 1
/*
* New protocol description
*/
{
{ &PROTOCOL_BUCKETS(new_protocol), ARRAY_LENGTH(PROTOCOL_BUCKETS(new_protocol)) },
{ &PROTOCOL_START(new_protocol), ARRAY_LENGTH(PROTOCOL_START(new_protocol)) },
{ &PROTOCOL_BIT0(new_protocol), ARRAY_LENGTH(PROTOCOL_BIT0(new_protocol)) },
{ &PROTOCOL_BIT1(new_protocol), ARRAY_LENGTH(PROTOCOL_BIT1(new_protocol)) },
{ &PROTOCOL_END(new_protocol), ARRAY_LENGTH(PROTOCOL_END(new_protocol)) },
24
}
#endif