Merge branch 'RF_settings'

This commit is contained in:
Telekatz 2017-07-23 09:21:20 +02:00
commit ad40b1dbe6
9 changed files with 2021 additions and 66 deletions

1738
FHEM/00_CUL.pm Normal file

File diff suppressed because it is too large Load diff

176
FHEM/10_Betty.pm Normal file
View file

@ -0,0 +1,176 @@
##############################################
# $Id: $
package main;
use strict;
use warnings;
use SetExtensions;
my %sets = (
"clear:noArg" => "",
"time:noArg" => "",
"raw" => "",
);
sub
Betty_Initialize($)
{
my ($hash) = @_;
$hash->{Match} = "^y.*";
$hash->{SetFn} = "Betty_Set";
$hash->{DefFn} = "Betty_Define";
$hash->{ParseFn} = "Betty_Parse";
$hash->{AttrList} = "IODev ". $readingFnAttributes;
}
###################################
sub
Betty_Set($@) {
my ($hash, @a) = @_;
return "set $hash->{NAME} needs at least one parameter" if(@a < 2);
my $me = shift @a;
my $cmd = shift @a;
my $arg = shift @a;
my $arg2 = shift @a;
return join(" ", sort keys %sets) if ($cmd eq "?");
if ($cmd eq "clear") {
my @cH = ($hash);
delete $_->{READINGS} foreach (@cH);
return undef;
} elsif ($cmd eq "raw") {
my $msg = $arg;
#IOWrite( $hash, $msg );
IOWrite( $hash, "y", $msg );
return undef;
} elsif ($cmd eq "time") {
my $address = $hash->{ADDRESS};
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime;
my $m = sprintf("%02d%02d%02d%02d",$mday,$wday,$month+1, $year-100);
my $n = sprintf("%02d%02d%02d",$sec, $min, $hour );
my $msg = "w".$address;
IOWrite( $hash, "y", $msg );
$msg = "s0a".$address."0003".$m.$n;
IOWrite( $hash, "y", $msg );
return undef;
}
return "Unknown argument $cmd, choose one of ". join(" ", sort keys %sets);
}
#############################
sub
Betty_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
return "wrong syntax: define <name> Betty <address>"
if(int(@a) < 2 || int(@a) > 4);
my $address = uc($a[2]);
$hash->{ADDRESS} = $address;
$modules{Betty}{defptr}{$address} = $hash;
AssignIoPort($hash);
readingsSingleUpdate($hash, "state", "Initialized", 1);
return undef;
}
sub
Betty_Parse($$)
{
my ($hash,$msg) = @_;
my ($len,$dest,$src,$service,$data) = unpack 'x1A2A2A2A2A*',$msg;
my $def = $modules{Betty}{defptr}{$src};
if(!$def) {
DoTrigger("global","UNDEFINED Betty_$src Betty $src");
$def = $modules{Betty}{defptr}{$src};
if(!$def) {
Log3 $hash, 1, "Betty UNDEFINED, address $src";
return "UNDEFINED Betty_$src Betty $src";
}
}
$hash = $def;
my $name = $hash->{NAME};
# packet_RFenc
if ($service eq '04') {
my ($addr,$key) = unpack 'A2A2',$data;
if($hash->{helper}{lastkey } ne $key) {
$hash->{helper}{lastkey } = $key;
$key = sprintf "%02x", hex($key) & 0x7F;
readingsSingleUpdate($hash, "key", $addr."_".$key , 1);
}
# packet_test
} elsif ($service eq '01') {
$data = latin1ToUtf8(pack("H*",$data));
readingsSingleUpdate($hash, "test", $data , 1);
# packet_time
} elsif ($service eq '03') {
my ($request) = unpack 'A2',$data;
if($request eq "FF") {
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime;
my $m = sprintf("%02d%02d%02d%02d",$mday,$wday,$month+1, $year-100);
my $n = sprintf("%02d%02d%02d",$sec, $min, $hour );
$msg = "s0a".$src."0003".$m.$n;
IOWrite( $hash, "y", $msg );
}
} else {
Log3 $hash, 4, "Betty UNKNOWN MESSAGE $service: $data";
}
return $name;
}
1;
=pod
=item summary devices communicating with the Betty remote control
=item summary_DE Anbindung der Betty Fernbedienung
=begin html
<a name="Betty"></a>
<h3>Betty</h3>
<ul>
Todo
</ul>
=end html
=cut

View file

@ -55,7 +55,7 @@ ifeq ($(MAKECMDGOALS),debug)
COMPILE += -D DEBUGMODE
OPTFLAGS = -O0
else
OPTFLAGS = -Os
OPTFLAGS = -Og
endif
ifeq ($(MAKECMDGOALS),release)

Binary file not shown.

View file

@ -26,58 +26,74 @@
#include "cc1100.h"
#include "irq.h"
//setting 6_WOR
const unsigned char conf[0x2F] = {
0x29, // IOCFG2
0x2E, // IOCFG1
0x06, // IOCFG0
0x47, // FIFOTHR
0xD3, // SYNC1
0x91, // SYNC0
0x3E, // PKTLEN
0x1A, // PKTCTRL1
0x45, // PKTCTRL0
0x01, // ADDR
0x01, // CHANNR
0x06, // FSCTRL1
0x00, // FSCTRL0
0x10, // FREQ2 #
0x0B, // FREQ1 #
0xDA, // FREQ0 # -> 433,249969 MHz
0x8A, // MDMCFG4
0x75, // MDMCFG3
0x13, // MDMCFG2
0x22, // MDMCFG1
0xC1, // MDMCFG0 CHANSPC_M
0x35, // DEVIATN
0x04, // MCSM2
0x0C, // MCSM1 0c
0x38, // MCSM0
0x16, // FOCCFG
0x6C, // BSCFG
0x43, // AGCCTRL2
0x40, // AGCCTRL1
0x91, // AGCCTRL0
0x46, // WOREVT1
0x50, // WOREVT0
0x78, // WORCTRL
0x56, // FREND1
0x10, // FREND0
0xA9, // FSCAL3
0x0A, // FSCAL2
0x00, // FSCAL1
0x11, // FSCAL0
0x41, // RCCTRL1
0x00, // RCCTRL0
0x57, // FSTEST
0x7F, // PTEST
0x3F, // AGCTEST
0x98, // TEST2
0x31, // TEST1
0x0B // TEST0
// Deviation = 21.423340
// Base frequency = 433.254913
// Carrier frequency = 433.254913
// Channel number = 0
// Carrier frequency = 433.254913
// Modulated = true
// Modulation format = GFSK
// Manchester enable = false
// Sync word qualifier mode = 30/32 sync word bits detected
// Preamble count = 4
// Channel spacing = 184.982300
// Carrier frequency = 433.254913
// Data rate = 37.4908
// RX filter BW = 210.937500
// Data format = Normal mode
// CRC enable = true
// Whitening = false
// Device address = 1
// Address config = Address check and 0 (0x00) broadcast
// CRC autoflush = true
// PA ramping = false
// TX power = 0
// Rf settings for CC1101
const unsigned char conf[] = {
0x29, // IOCFG2 GDO2 Output Pin Configuration
0x2E, // IOCFG1 GDO1 Output Pin Configuration
0x06, // IOCFG0 GDO0 Output Pin Configuration
0x47, // FIFOTHR RX FIFO and TX FIFO Thresholds
0xD3, // SYNC1 Sync Word, High Byte
0x91, // SYNC0 Sync Word, Low Byte
0x3E, // PKTLEN Packet Length
0x1A, // PKTCTRL1 Packet Automation Control
0x05, // PKTCTRL0 Packet Automation Control
0x01, // ADDR Device Address
0x00, // CHANNR Channel Number
0x06, // FSCTRL1 Frequency Synthesizer Control
0x00, // FSCTRL0 Frequency Synthesizer Control
0x10, // FREQ2 Frequency Control Word, High Byte
0x0B, // FREQ1 Frequency Control Word, Middle Byte
0xE6, // FREQ0 Frequency Control Word, Low Byte
0x8A, // MDMCFG4 Modem Configuration
0x6C, // MDMCFG3 Modem Configuration
0x13, // MDMCFG2 Modem Configuration
0x22, // MDMCFG1 Modem Configuration
0xC1, // MDMCFG0 Modem Configuration
0x35, // DEVIATN Modem Deviation Setting
0x04, // MCSM2 Main Radio Control State Machine Configuration
0x0C, // MCSM1 Main Radio Control State Machine Configuration
0x38, // MCSM0 Main Radio Control State Machine Configuration
0x16, // FOCCFG Frequency Offset Compensation Configuration
0x6C, // BSCFG Bit Synchronization Configuration
0x43, // AGCCTRL2 AGC Control
0x40, // AGCCTRL1 AGC Control
0x91, // AGCCTRL0 AGC Control
0x46, // WOREVT1 High Byte Event0 Timeout
0x50, // WOREVT0 Low Byte Event0 Timeout
0x78, // WORCTRL Wake On Radio Control
0x56, // FREND1 Front End RX Configuration
0x10, // FREND0 Front End TX Configuration
0xE9, // FSCAL3 Frequency Synthesizer Calibration
0x2A, // FSCAL2 Frequency Synthesizer Calibration
0x00, // FSCAL1 Frequency Synthesizer Calibration
0x1F, // FSCAL0 Frequency Synthesizer Calibration
0x41, // RCCTRL1 RC Oscillator Configuration
0x00, // RCCTRL0 RC Oscillator Configuration
};
const unsigned char confasync[0x2F] = {
const unsigned char confasync[] = {
0x0D, // IOCFG2
0x0D, // IOCFG1
0x2E, // IOCFG0
@ -120,12 +136,6 @@ const unsigned char confasync[0x2F] = {
0x1F, // FSCAL0
0x41, // RCCTRL1
0x00, // RCCTRL0
0x59, // FSTEST
0x7F, // PTEST
0x3F, // AGCTEST
0x81, // TEST2
0x35, // TEST1
0x09 // TEST0
};
void cc1100_init(void) {
@ -164,7 +174,7 @@ void cc1100_init(void) {
while (SSPSR & (1<<4));
xx = SSPDR;
cc1100_write((0x00 | BURST ),(unsigned char*)conf,0x2f);
cc1100_write((0x00 | BURST ),(unsigned char*)conf,sizeof(conf));
cc1100_write1(PATABLE,0xC0);
cc1100_strobe(SIDLE);
cc1100_strobe(SPWD);

View file

@ -118,8 +118,8 @@
#define MARCSTATE_IDLE 0x01
#define MARCSTATE_RX 0x0d
const unsigned char conf[0x2F] __attribute__((aligned(0x4)));
const unsigned char confasync[0x2F] __attribute__((aligned(0x4)));
extern const unsigned char conf[]; //__attribute__((aligned(0x4)));
extern const unsigned char confasync[];// __attribute__((aligned(0x4)));
void cc1100_init(void);
unsigned char cc1100_write(unsigned char addr, unsigned char* data, unsigned char length);

View file

@ -485,14 +485,14 @@ void RFasyncmode(unsigned char on) {
RF_changestate(RFidle);
while(RF.state != RFidle);
stopRFIRQ();
cc1100_write((0x00 | BURST ),(unsigned char*)confasync,0x2f);
cc1100_write((0x00 | BURST ),(unsigned char*)confasync,sizeof((unsigned char*)confasync));
cc1100_write1(PATABLE,0xf0);
PINSEL1 &= 0xfffffffc; // GDO0 as GPIO
FIODIR0 |= GDO0; // output
}
else {
PINSEL1 |= 1; // GDO0 as EINT0
cc1100_write((0x00 | BURST ),(unsigned char*)conf,0x2f);
cc1100_write((0x00 | BURST ),(unsigned char*)conf,sizeof((unsigned char*)conf));
cc1100_write1(PATABLE,0xC0);
cc1100_strobe(SIDLE);
load_RF_setting();

View file

@ -862,6 +862,35 @@ void test_RF(void) {
cur_ep->bufferlen = 3;
cur_ep->flags |= EPenabled | EPoutput | EPnewdata | EPonce | EPsendwor;
RF_changestate(RFtx);
} else if(KEY_1)
{
struct RFendpoint_* cur_ep;
cur_ep = openEP(0,0, packet_test);
if(cur_ep) {
cur_ep->dest = destAddr;
cur_ep->data[0] = 'X';
cur_ep->data[1] = '1';
cur_ep->data[2] = 0x00;
cur_ep->bufferlen = 3;
cur_ep->flags |= EPenabled | EPoutput | EPnewdata | EPonce;
RF_changestate(RFtx);
}
}
else if(KEY_2)
{
struct RFendpoint_* cur_ep;
cur_ep = openEP(0,0, packet_test);
cur_ep->dest = destAddr;
cur_ep->data[0] = 'X';
cur_ep->data[1] = '2';
cur_ep->data[2] = 0x00;
cur_ep->bufferlen = 3;
cur_ep->flags |= EPenabled | EPoutput | EPnewdata | EPonce ;
RF_changestate(RFtx);
}
}

View file

@ -42,7 +42,7 @@ extern volatile unsigned long keyMap[42];
#define IRRF_WAIT 0x01
#define IRRF_BITTIME 40
#define IRRF_WAITTIME 125
#define IRRF_WAITTIME 100
void __attribute__ ((section(".text.fastcode"))) IRRF_Encode (void)
{
@ -63,6 +63,7 @@ void __attribute__ ((section(".text.fastcode"))) IRRF_Encode (void)
}
break;
}
T1MR0 = 15*1000;
}
void IRRF_Init(unsigned char map)
@ -100,9 +101,10 @@ void IRRF_Repeat(void)
struct RFendpoint_* cur_ep;
cur_ep = (struct RFendpoint_*)ir.general.trail;
if((cur_ep) && !(cur_ep->flags & EPnewdata)) {
cur_ep->dest = (ir.actcmd & 0xff00) >> 8;
cur_ep->data[0] = (ir.actcmd & 0x00ff);
cur_ep->bufferlen = 1;
cur_ep->dest = 0;
cur_ep->data[1] = (ir.actcmd & 0x00ff);
cur_ep->data[0] = (ir.actcmd & 0xff00) >> 8;
cur_ep->bufferlen = 2;
cur_ep->flags |= EPenabled | EPoutput | EPnewdata;
RF_changestate(RFtx);