-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZeusRfDecode.h
106 lines (100 loc) · 3.97 KB
/
ZeusRfDecode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Class to receive and decode signals from wireless sensors of an old
* security system.
*
* See the README.md for more details.
*
* Copyright 2017 David M Kent.
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef ARDUINO
#include <Arduino.h>
typedef unsigned long INTPOS;
typedef unsigned long INTWID;
typedef byte BYTE;
typedef void (*AdvanceHighFuncType)();
typedef void (*PairTransFuncType)(INTPOS*, INTPOS*, INTWID*, INTWID*);
typedef void (*MarkByteFuncType)(INTPOS, INTPOS, BYTE);
typedef void (*MarkSyncBitFuncType)(INTPOS);
#else
#include <functional>
#include <Analyzer.h>
typedef U64 INTPOS;
typedef U32 INTWID;
typedef U8 BYTE;
typedef std::function<void()> AdvanceHighFuncType;
typedef std::function<void(INTPOS*, INTPOS*, INTWID*, INTWID*)> PairTransFuncType;
typedef std::function<void(INTPOS, INTPOS, BYTE)> MarkByteFuncType;
typedef std::function<void(INTPOS)> MarkSyncBitFuncType;
#endif
/* Used to flag end of data (in micro seconds) */
#define SAMPLES_PREAMBLE_MIN 13700
/* Used to flag end of sync/start of data */
#define SAMPLES_PAUSE_MIN 3550
#define SAMPLES_PAUSE_MAX 3900
/* Max sync pairs expected */
#define MAX_PREAMBLE 12
/**
* Progressivly work through the stream of data until we detect initial sync signal.
*
* This works by looking for pairs of transitions (one high pulse, one low) and comparing
* their width to the previous pairs. If we get a series of pairs with same widths then
* we know we have a signal. When we then get a long low pulse we know data is about to
* start.
*
* Callbacks:
* AdvanceUntilHigh - should skip read pulses until current one is HIGH.
* GetPairTransitions - should get/wait for next pair of pulses. The values of
* the four pointers should be set to:
* 1. Position of pair start (as position count)
* 2. Position of pair end (as position count)
* 3. Width of high pulse (in micro seconds)
* 4. Width of low pulse (in micro seconds)
* MarkSyncBit - called when a complete sync pair is detected giving the
* end position count.
*
* Returns:
* The current position index for start of data.
*/
INTPOS block_until_data(
AdvanceHighFuncType AdvanceUntilHigh,
PairTransFuncType GetPairTransitions,
MarkSyncBitFuncType MarkSyncBit
);
/**
* Progressivly work through the stream of data returning decoded byte data.
*
* This applies on-off-keying (OOK) to decode data from pulses.
*
* Takes the initial position index as an argument.
*
* Callbacks:
* GetPairTransitions - should get/wait for next pair of pulses. The values of
* the four pointers should be set to:
* 1. Position of pair start (as position count)
* 2. Position of pair end (as position count)
* 3. Width of high pulse (in micro seconds)
* 4. Width of low pulse (in micro seconds)
* MarkByte - called when a complete byte has been decoded. Arguments will be:
* 1. Starting position index of byte
* 2. Ending position index of byte
* 3. Byte value
*/
void receive_and_process_data(
INTPOS data_start,
PairTransFuncType GetPairTransitions,
MarkByteFuncType MarkByte
);