Add Hideki TS04 sensors

This commit is contained in:
Emmanuel N 2015-12-06 23:54:02 +01:00
parent c29463f5de
commit 6f8348532f
6 changed files with 107 additions and 3 deletions

View file

@ -105,6 +105,8 @@ Supported devices:
[37] Inovalley kw9015b rain and Temperature weather station
[38] Generic temperature sensor 1
[39] Acurite 592TXR Temperature/Humidity Sensor and 5n1 Weather Station
[40] Acurite 986 Refrigerator / Freezer Thermometer
[41] HIDEKI TS04 Temperature and Humidity sensor
```

View file

@ -31,7 +31,7 @@
#define DEFAULT_LEVEL_LIMIT 8000 // Theoretical high level at I/Q saturation is 128x128 = 16384 (above is ripple)
#define MINIMAL_BUF_LENGTH 512
#define MAXIMAL_BUF_LENGTH (256 * 16384)
#define MAX_PROTOCOLS 40
#define MAX_PROTOCOLS 41
#define SIGNAL_GRABBER_BUFFER (12 * DEFAULT_BUF_LENGTH)
/* Supported modulation types */

View file

@ -43,7 +43,8 @@
DECL(kw9015b) \
DECL(generic_temperature_sensor) \
DECL(acurite_txr) \
DECL(acurite_986)
DECL(acurite_986) \
DECL(hideki_ts04)
typedef struct {
char name[256];

View file

@ -59,6 +59,7 @@ add_executable(rtl_433
devices/efergy_e2_classic.c
devices/inovalley-kw9015b.c
devices/generic_temperature_sensor.c
devices/hideki.c
)
add_library(data data.c)

View file

@ -44,6 +44,7 @@ rtl_433_SOURCES = baseband.c \
devices/x10_rf.c \
devices/xc0348.c \
devices/inovalley-kw9015b.c \
devices/generic_temperature_sensor.c
devices/generic_temperature_sensor.c\
devices/hideki.c
rtl_433_LDADD = $(LIBRTLSDR) $(LIBM)

99
src/devices/hideki.c Normal file
View file

@ -0,0 +1,99 @@
#include "rtl_433.h"
#include "pulse_demod.h"
#include "util.h"
#include "data.h"
#define HIDEKI_BYTES_PER_ROW 10
// 11111001 0 11110101 0 01110011 1 01111010 1 11001100 0 01000011 1 01000110 1 00111111 0 00001001 0 00010111 0
// SYNC+HEAD P RC cha P P Nr.? P .1° 1° P 10° BV P 1% 10% P ????SYNC -------Check?------- P
// 00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999
// SYNC+HEAD cha RC Nr.? 1° .1° BV 10° 10% 1% SYNC???? -----Check?------
static int hideki_ts04_callback(bitbuffer_t *bitbuffer) {
bitrow_t *bb = bitbuffer->bb;
uint8_t *b = bb[0];//TODO: handle the 3 row, need change in PULSE_CLOCK decoding
time_t time_now;
char time_str[LOCAL_TIME_BUFLEN];
data_t *data;
time(&time_now);
local_time_str(time_now, time_str);
uint8_t packet[HIDEKI_BYTES_PER_ROW];
// Transform the incoming data:
// * change endianness
// * toggle each bits
// * Remove (and check) parity bit
for(int i=0; i<HIDEKI_BYTES_PER_ROW; i++){
unsigned int offset = i/8;
packet[i] = b[i+offset] << (i%8);
packet[i] |= b[i+offset+1] >> (8 - i%8);
// reverse as it is litle endian...
packet[i] = reverse8(packet[i]);
// toggle each bit
packet[i] ^= 0xFF;
// check parity
uint8_t parity = ((b[i+offset+1] >> (7 - i%8)) ^ 0xFF) & 0x01;
if(parity != byteParity(packet[i])){
fprintf(stderr, "Invalid parity\n");
return 0;
}
}
// Read data
if(packet[0] == 0x9f){ //Note: it may exist other valid id
uint8_t channel = (packet[1] >> 5) & 0x0F;
if(channel >= 5) channel -= 1;
uint8_t rc = packet[1] & 0x0F;
int temp = (packet[5] & 0x0F) * 100 + ((packet[4] & 0xF0) >> 4) * 10 + (packet[4] & 0x0F);
if((packet[5]>>4) & 0x01){
temp = -temp;
}
uint8_t humidity = ((packet[6] & 0xF0) >> 4) * 10 + (packet[6] & 0x0F);
uint8_t battery_low = (packet[5]>>5) & 0x01;
data = data_make("time", "", DATA_STRING, time_str,
"model", "", DATA_STRING, "HIDEKI TS04 sensor",
"rc", "Rolling Code", DATA_INT, rc,
"channel", "Channel", DATA_INT, channel,
"battery", "Battery", DATA_STRING, battery_low ? "LOW" : "OK",
"temperature_C", "Temperature", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp/10.f,
"humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, humidity,
NULL);
data_acquired_handler(data);
return 1;
}
return 0;
}
PWM_Precise_Parameters hideki_ts04_clock_bits_parameters = {
.pulse_tolerance = 60,
.pulse_sync_width = 0, // No sync bit used
};
static char *output_fields[] = {
"time",
"model",
"rc",
"channel",
"battery",
"temperature_C",
"humidity",
NULL
};
r_device hideki_ts04 = {
.name = "HIDEKI TS04 Temperature and Humidity Sensor",
.modulation = OOK_PULSE_CLOCK_BITS,
.short_limit = 130,
.long_limit = 260, // not used
.reset_limit = 1000,
.json_callback = &hideki_ts04_callback,
.disabled = 0,
.demod_arg = (unsigned long)&hideki_ts04_clock_bits_parameters,
.fields = output_fields,
};