64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
class W433DataReciver
|
|
{
|
|
public:
|
|
static constexpr int ERROR_CRC = 1;
|
|
|
|
static constexpr int SAMPLES_PER_BIT = 8;
|
|
static constexpr int PLL_RAMP_LEN = 160;
|
|
static constexpr int PLL_RAMP_INC_STEP = PLL_RAMP_LEN/SAMPLES_PER_BIT;
|
|
static constexpr int PLL_RAMP_TRANSITION = PLL_RAMP_LEN/2;
|
|
static constexpr int PLL_RAMP_INC_RETARD = PLL_RAMP_INC_STEP-9;
|
|
static constexpr int PLL_RAMP_INC_ADVANCE = PLL_RAMP_INC_STEP+9;
|
|
static constexpr int PLL_HEADER_LEN_BITS = 8;
|
|
static constexpr int PACKET_LENGTH = sizeof(uint32_t)+2;
|
|
|
|
private:
|
|
|
|
static constexpr int MODE_SEARCHING = 0;
|
|
static constexpr int MODE_RECEIVING = 1;
|
|
|
|
static W433DataReciver* instance;
|
|
|
|
volatile unsigned char *port;
|
|
unsigned char pin;
|
|
|
|
bool prevSample = 0;
|
|
uint8_t pllRamp = 0;
|
|
uint8_t rxIntegrator = 0;
|
|
|
|
uint16_t rxBits = 0;
|
|
|
|
uint8_t mode = MODE_SEARCHING;
|
|
|
|
uint8_t rxBuf[PACKET_LENGTH];
|
|
uint8_t rxCount = 0;
|
|
volatile uint8_t rxLen = 0;
|
|
|
|
void (* const packetCallback)(uint32_t, void*);
|
|
void (* const errorCodeHandler)(uint8_t, void*);
|
|
void* const userData;
|
|
|
|
private:
|
|
|
|
static uint16_t calcCrc(uint32_t data);
|
|
static uint8_t symbolDecode(uint8_t symbol);
|
|
void pll(bool sample);
|
|
|
|
public:
|
|
|
|
W433DataReciver(volatile unsigned char* const portIn, const unsigned char pinIn, void (*packetCallbackIn)(uint32_t,
|
|
void*),
|
|
void* userDataIn = nullptr, void (*errorCodeHandlerIn)(uint8_t, void*) = nullptr );
|
|
~W433DataReciver();
|
|
|
|
static void staticInterrupt();
|
|
void interrupt();
|
|
|
|
static uint16_t calculateOverflowRegister(uint16_t bitRate, uint16_t devisor);
|
|
};
|