Skip to content

Commit

Permalink
merely make code more human readable, functionally identical otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
mightymos committed Nov 27, 2024
1 parent 22732d8 commit 5d17719
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/main_portisch.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
// example for sniffing (0xB1 command) and reply tranmission (0xB0 command) from my door sensor
//{"RfRaw":{"Data":"AA B1 03 0138 03B7 277C 28181909081908190819090908181908181818181908190818 55"}}

// 0xB1 to 0xB0 web convert tool:
// 0xB1 to 0xB0 web convert tool (json format):
// https://bbconv.hrbl.pl/
// got this output from the tool:
// rfraw AA B0 21 03 08 01 38 03 B7 27 7C 28 18 19 09 08 19 08 19 08 19 09 09 08 18 19 08 18 18 18 18 19 08 19 08 18 55
// rfraw AA B0 21 03 08 0138 03B7 277C 28 18 19 09 08 19 08 19 08 19 09 09 08 18 19 08 18 18 18 18 19 08 19 08 18 55

// converter tool for raw byte format
// https://jonajona.nl/convertB1.html

// uart state machine
__xdata uart_state_t uart_state = IDLE;
Expand Down
37 changes: 31 additions & 6 deletions src/portisch.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ void PCA0_StopSniffing(void)
stop_delay_timer();
}

// returns the inverted bit of what was passed in to high_low
bool SendSingleBucket(const bool high_low, uint16_t bucket_time)
{
// FIXME: improve this comment
Expand Down Expand Up @@ -508,15 +509,26 @@ void SendRFBuckets(uint16_t* buckets, uint8_t* rfdata, uint8_t data_len)
bool high_low = true;
bool high_low_mark = false;
uint8_t i;

// help human readability
bool level;
uint16_t bucket_time;

// check first two buckets if high/low marking is included
high_low_mark = (rfdata[0] & 0x88) > 0;

// transmit data
for (i = 0; i < data_len; i++)
{
high_low = SendSingleBucket(high_low_mark ? (bool)(rfdata[i] >> 7) : high_low, buckets[(rfdata[i] >> 4) & 0x07]);
high_low = SendSingleBucket(high_low_mark ? (bool)((rfdata[i] >> 3) & 0x01) : high_low, buckets[rfdata[i] & 0x07]);
//
level = high_low_mark ? (bool)(rfdata[i] >> 7) : high_low;
bucket_time = buckets[(rfdata[i] >> 4) & 0x07];
high_low = SendSingleBucket(level, bucket_time);

//
level = high_low_mark ? (bool)((rfdata[i] >> 3) & 0x01) : high_low;
bucket_time = buckets[rfdata[i] & 0x07];
high_low = SendSingleBucket(level, bucket_time);
}

led_off();
Expand All @@ -528,10 +540,17 @@ void SendBuckets(uint16_t *pulses, uint8_t* start, uint8_t start_size, uint8_t*
uint8_t i, a;
uint8_t actual_byte = 0;
uint8_t actual_bit = 0x80;

bool level;
uint16_t bucket_time;

// transmit sync bucket(s)
for (i = 0; i < start_size; i++)
SendSingleBucket(((start[i] & 0x08) >> 3), pulses[start[i] & 0x07]);
{
level = (start[i] & 0x08) >> 3;
bucket_time = pulses[start[i] & 0x07];
SendSingleBucket(level, bucket_time);
}

// transmit bit bucket(s)
for (i = 0; i < bit_count; i++)
Expand All @@ -541,14 +560,18 @@ void SendBuckets(uint16_t *pulses, uint8_t* start, uint8_t start_size, uint8_t*
{
for (a = 0; a < bit0_size; a++)
{
SendSingleBucket(((bit0[a] & 0x08) >> 3), pulses[bit0[a] & 0x07]);
level = (bit0[a] & 0x08) >> 3;
bucket_time = pulses[bit0[a] & 0x07];
SendSingleBucket(level, bucket_time);
}
}
else
{ // send bit 1
for (a = 0; a < bit1_size; a++)
{
SendSingleBucket(((bit1[a] & 0x08) >> 3), pulses[bit1[a] & 0x07]);
level = (bit1[a] & 0x08) >> 3;
bucket_time = pulses[bit1[a] & 0x07];
SendSingleBucket(level, bucket_time);
}
}

Expand All @@ -564,7 +587,9 @@ void SendBuckets(uint16_t *pulses, uint8_t* start, uint8_t start_size, uint8_t*
// transmit end bucket(s)
for (i = 0; i < end_size; i++)
{
SendSingleBucket(((end[i] & 0x08) >> 3), pulses[end[i] & 0x07]);
level = (end[i] & 0x08) >> 3;
bucket_time = pulses[end[i] & 0x07];
SendSingleBucket(level, bucket_time);
}

led_off();
Expand Down

0 comments on commit 5d17719

Please sign in to comment.