Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <Arduino.h>
- #include <SPI.h>
- // Ramses II / Orcon bypass command bytes (sent in 22F7 payload)
- #define BYPASS_AUTO 0xFF
- #define BYPASS_OPEN 0xC8
- #define BYPASS_CLOSE 0x00
- // Out-of-range sentinel for "current bypass state unknown" — never equals a real value (0x00/0xC8/0xFF)
- #define BYPASS_UNKNOWN 0xEE
- #define CC1101_GDO2 11
- #define chipSelectPin 4
- #define PAIR_TIME_OUT 5000 // ms
- #define RX_TIME_OUT 300 // ms
- #define TX_REQUEST_COUNT 12 // Warm-up polls before requestFanState() drops unresponsive opcodes
- #define WRITE_BURST 0x40
- #define READ_BURST 0xC0
- #define CC1101_STATUS_REGISTER READ_BURST
- #define CC1101_UNKNOWNFIFO 0x7E // ? FIFO address
- // Command strobes
- #define CC1101_SRES 0x30 // Reset CC1101 chip
- #define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1
- #define CC1101_STX 0x35 // Enable TX from IDLE (or from RX if CCA enabled and channel clear)
- #define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer
- #define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high
- // Configuration registers
- #define CC1101_IOCFG2 0x00 // GDO2 Output Pin Configuration
- #define CC1101_IOCFG0 0x02 // GDO0 Output Pin Configuration
- #define CC1101_PKTCTRL1 0x07 // Packet Automation Control
- #define CC1101_PKTCTRL0 0x08 // Packet Automation Control
- #define CC1101_CHANNR 0x0A // Channel Number
- #define CC1101_FSCTRL1 0x0B // Frequency Synthesizer Control
- #define CC1101_FSCTRL0 0x0C // Frequency Synthesizer Control
- #define CC1101_FREQ2 0x0D // Frequency Control Word, High Byte
- #define CC1101_FREQ1 0x0E // Frequency Control Word, Middle Byte
- #define CC1101_FREQ0 0x0F // Frequency Control Word, Low Byte
- #define CC1101_MDMCFG4 0x10 // Modem Configuration
- #define CC1101_MDMCFG3 0x11 // Modem Configuration
- #define CC1101_MDMCFG2 0x12 // Modem Configuration
- #define CC1101_MDMCFG1 0x13 // Modem Configuration
- #define CC1101_MDMCFG0 0x14 // Modem Configuration
- #define CC1101_DEVIATN 0x15 // Modem Deviation Setting
- #define CC1101_MCSM0 0x18 // Main Radio Control State Machine Configuration
- #define CC1101_FOCCFG 0x19 // Frequency Offset Compensation Configuration
- #define CC1101_BSCFG 0x1A // Bit Synchronization Configuration
- #define CC1101_AGCCTRL2 0x1B // AGC Control
- #define CC1101_AGCCTRL1 0x1C // AGC Control
- #define CC1101_AGCCTRL0 0x1D // AGC Control
- #define CC1101_WORCTRL 0x20 // Wake On Radio Control
- #define CC1101_FREND1 0x21 // Front End RX Configuration
- #define CC1101_FREND0 0x22 // Front End TX Configuration
- #define CC1101_FSCAL3 0x23 // Frequency Synthesizer Calibration
- #define CC1101_FSCAL2 0x24 // Frequency Synthesizer Calibration
- #define CC1101_FSCAL1 0x25 // Frequency Synthesizer Calibration
- #define CC1101_FSCAL0 0x26 // Frequency Synthesizer Calibration
- #define CC1101_TEST0 0x2E // Various Test Settings
- // Status registers
- #define CC1101_MARCSTATE 0x35 // Main Radio Control State Machine State
- #define CC1101_DEFVAL_IOCFG2 0x0A
- #define CC1101_DEFVAL_IOCFG0 0x2E // High impedance / 3-state
- #define CC1101_SERIAL_OUT_IOCFG0 0x0D // Async serial data out
- #define CC1101_DEFVAL_PKTCTRL1 0x04 // Packet Automation Control
- #define CC1101_DEFVAL_PKTCTRL0 0x32 // Packet Automation Control
- #define CC1101_DEFVAL_CHANNR 0x00 // Channel Number
- #define CC1101_DEFVAL_FSCTRL1 0x08 // Frequency Synthesizer Control
- #define CC1101_DEFVAL_FSCTRL0 0x00 // Frequency Synthesizer Control
- // Carrier frequency = 868 MHz
- #define CC1101_DEFVAL_FREQ2_868 0x21 // Frequency Control Word, High Byte
- #define CC1101_DEFVAL_FREQ1_868 0x65 // Frequency Control Word, Middle Byte [modified!]
- #define CC1101_DEFVAL_FREQ0_868 0x8A // Frequency Control Word, Low Byte [modified!]
- #define CC1101_DEFVAL_MDMCFG4 0x5A
- #define CC1101_DEFVAL_MDMCFG3 0x83 // Modem Configuration
- #define CC1101_DEFVAL_MDMCFG2 0x00 // Modem Configuration
- #define CC1101_DEFVAL_MDMCFG1 0x22 // Modem Configuration
- #define CC1101_DEFVAL_MDMCFG0 0xF8 // Modem Configuration
- #define CC1101_DEFVAL_DEVIATN 0x50 // Modem Deviation Setting
- #define CC1101_DEFVAL_MCSM0 0x18 // Main Radio Control State Machine Configuration
- #define CC1101_DEFVAL_FOCCFG 0x1D // Frequency Offset Compensation Configuration
- #define CC1101_DEFVAL_BSCFG 0x1C // Bit Synchronization Configuration
- #define CC1101_DEFVAL_AGCCTRL2 0xC7 // AGC Control
- #define CC1101_DEFVAL_AGCCTRL1 0x00 // AGC Control
- #define CC1101_DEFVAL_AGCCTRL0 0xB2 // AGC Control
- #define CC1101_DEFVAL_WORCTRL 0xFB // Wake On Radio Control
- #define CC1101_DEFVAL_FREND1 0xB6 // Front End RX Configuration
- #define CC1101_DEFVAL_FREND0 0x17 // Front End TX Configuration
- #define CC1101_DEFVAL_FSCAL3 0xE9 // Frequency Synthesizer Calibration
- #define CC1101_DEFVAL_FSCAL2 0x2A // Frequency Synthesizer Calibration
- #define CC1101_DEFVAL_FSCAL1 0x00 // Frequency Synthesizer Calibration
- #define CC1101_DEFVAL_FSCAL0 0x1F // Frequency Synthesizer Calibration
- #define CC1101_DEFVAL_TEST0 0x09 // Various Test Settings
- class CC1101
- {
- private:
- void writeBurstReg(uint8_t registerAddress, uint8_t* buffer, uint8_t length);
- void manchesterDecode(uint8_t rxBuffer[], uint8_t length, uint8_t *rxPayload);
- void manchesterEncode(uint8_t txBuffer[], uint8_t length, uint8_t *payloadEncoded);
- bool transmitData(uint8_t payload[], uint8_t length);
- uint8_t calcCrc(uint8_t dataframe[], uint8_t length);
- void parseRamsesPayload(uint8_t dataframe[], uint8_t length);
- bool waitForBof(uint16_t timeoutMs);
- void buildRamsesFrame(uint8_t header, uint16_t opcode, const uint8_t *payload, uint8_t payloadLength, uint8_t *out);
- void setRxState(void);
- void setTxState(void);
- void cmdStrobe(uint8_t cmd);
- void writeReg(uint8_t registerAddress, uint8_t value);
- void configRegisters(void);
- void reset(void);
- void setCarrierFreq();
- void setPowerDownState();
- enum CodeSlot
- {
- fanSpeed,
- indoorHum,
- fanInfo,
- NUM_CODES
- };
- struct CodeEntry
- {
- uint16_t codeId;
- bool rxFlag;
- };
- CodeEntry msgId[NUM_CODES];
- public:
- struct Datapoints
- {
- uint8_t fanSpeed;
- uint8_t indoorHumidity;
- uint8_t outdoorHumidity;
- uint16_t exhaustTemperature;
- uint16_t supplyTemperature;
- uint16_t indoorTemperature;
- uint16_t outdoorTemperature;
- uint16_t comfortTemperature; // 2411 param 0x75, centi-°C (Orcon bypass target)
- uint8_t bypassPosition;
- uint8_t bypassMode;
- uint8_t exhaustFanspeed;
- uint8_t supplyFanspeed;
- uint16_t exhaustFlow;
- uint16_t supplyFlow;
- uint8_t address[6];
- };
- Datapoints newFanState;
- Datapoints currentFanState;
- CC1101(void);
- bool txFanspeed(uint8_t fanSpeed);
- bool txDemand(uint8_t demandByte);
- bool setBypass(uint8_t bypassMode);
- bool requestFanState(void);
- bool requestComfortTemperature(void);
- bool setComfortTemperature(uint16_t centiCelsius);
- uint8_t readReg(uint8_t registerAddress, uint8_t registerType);
- void init(void);
- void setRxMode(void);
- bool cloneMode(void);
- };
Advertisement
Add Comment
Please, Sign In to add comment