From 4767945f7f170aecbc5ee9684649e219212674c0 Mon Sep 17 00:00:00 2001 From: "Daniel A. Maierhofer" Date: Mon, 12 Jan 2015 11:00:43 +0100 Subject: [PATCH] Unify hexadecimal notation and whitespace --- RFM69.cpp | 64 +++++++++++++++++++++++++++---------------------------- RFM69.h | 18 ++++++++-------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/RFM69.cpp b/RFM69.cpp index f000fe7..9a8cadb 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -49,9 +49,9 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) { /* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY }, /* 0x02 */ { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 }, // no shaping - /* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, // default:4.8 KBPS + /* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, // default: 4.8 KBPS /* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_55555}, - /* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, // default:5khz, (FDEV + BitRate/2 <= 500Khz) + /* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, // default: 5KHz, (FDEV + BitRate / 2 <= 500KHz) /* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_50000}, /* 0x07 */ { REG_FRFMSB, (freqBand==RF69_315MHZ ? RF_FRFMSB_315 : (freqBand==RF69_433MHZ ? RF_FRFMSB_433 : (freqBand==RF69_868MHZ ? RF_FRFMSB_868 : RF_FRFMSB_915))) }, @@ -60,27 +60,27 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) // looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm // +17dBm and +20dBm are possible on RFM69HW - // +13dBm formula: Pout=-18+OutputPower (with PA0 or PA1**) - // +17dBm formula: Pout=-14+OutputPower (with PA1 and PA2)** - // +20dBm formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet) + // +13dBm formula: Pout = -18 + OutputPower (with PA0 or PA1**) + // +17dBm formula: Pout = -14 + OutputPower (with PA1 and PA2)** + // +20dBm formula: Pout = -11 + OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet) ///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111}, ///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, // over current protection (default is 95mA) - // RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz) + // RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4KHz) /* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, // (BitRate < 2 * RxBw) //for BR-19200: /* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_3 }, /* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, // DIO0 is the only IRQ we're using - /* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm - ///* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA - /* 0x2e */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 }, - /* 0x2f */ { REG_SYNCVALUE1, 0x2D }, // attempt to make this compatible with sync1 byte of RFM12B lib + /* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2), default is 0xE4 = 228 so -114dBm + ///* 0x2D */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA + /* 0x2E */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 }, + /* 0x2F */ { REG_SYNCVALUE1, 0x2D }, // attempt to make this compatible with sync1 byte of RFM12B lib /* 0x30 */ { REG_SYNCVALUE2, networkID }, // NETWORK ID /* 0x37 */ { REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF }, /* 0x38 */ { REG_PAYLOADLENGTH, 66 }, // in variable length mode: the max frame size, not used in TX ///* 0x39 */ { REG_NODEADRS, nodeID }, // turned off because we're not using address filtering /* 0x3C */ { REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE }, // TX on FIFO not empty - /* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) - //for BR-19200: /* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) + /* 0x3D */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) + //for BR-19200: /* 0x3D */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) ///* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode /* 0x6F */ { REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0 }, // run DAGC continuously in RX mode, recommended default for AfcLowBetaOn=0 {255, 0} @@ -89,7 +89,7 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) pinMode(_slaveSelectPin, OUTPUT); SPI.begin(); - do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa); + do writeReg(REG_SYNCVALUE1, 0xAA); while (readReg(REG_SYNCVALUE1) != 0xAA); do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55); for (byte i = 0; CONFIG[i][0] != 255; i++) @@ -112,13 +112,13 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) // return the frequency (in Hz) uint32_t RFM69::getFrequency() { - return RF69_FSTEP * (((uint32_t)readReg(REG_FRFMSB)<<16) + ((uint16_t)readReg(REG_FRFMID)<<8) + readReg(REG_FRFLSB)); + return RF69_FSTEP * (((uint32_t) readReg(REG_FRFMSB) << 16) + ((uint16_t) readReg(REG_FRFMID) << 8) + readReg(REG_FRFLSB)); } // set the frequency (in Hz) void RFM69::setFrequency(uint32_t freqHz) { - // TODO: p38 hopping sequence may need to be followed in some cases + // TODO: datasheet p38 hopping sequence may need to be followed in some cases freqHz /= RF69_FSTEP; // divide down by FSTEP to get FRF writeReg(REG_FRFMSB, freqHz >> 16); writeReg(REG_FRFMID, freqHz >> 8); @@ -172,7 +172,7 @@ void RFM69::setNetwork(byte networkID) writeReg(REG_SYNCVALUE2, networkID); } -// set output power: 0=min, 31=max +// set output power: 0 = min, 31 = max // this results in a "weaker" transmitted signal, and directly results in a lower RSSI at the receiver void RFM69::setPowerLevel(byte powerLevel) { @@ -194,7 +194,7 @@ void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool reque { writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks unsigned long now = millis(); - while (!canSend() && millis()-now < RF69_CSMA_LIMIT_MS) receiveDone(); + while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone(); sendFrame(toAddress, buffer, bufferSize, requestACK, false); } @@ -203,22 +203,22 @@ void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool reque // The only twist is that you have to manually listen to ACK requests on the other side and send back the ACKs // The reason for the semi-automaton is that the lib is interrupt driven and // requires user action to read the received data and decide what to do with it -// replies usually take only 5-8ms at 50kbps@915Mhz +// replies usually take only 5..8ms at 50kbps@915MHz bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) { unsigned long sentTime; for (byte i = 0; i <= retries; i++) { send(toAddress, buffer, bufferSize, true); sentTime = millis(); - while (millis()-sentTime 66 ? 66 : PAYLOADLEN; // precaution TARGETID = SPI.transfer(0); @@ -312,7 +312,7 @@ void RFM69::interruptHandler() { { DATA[i] = SPI.transfer(0); } - if (DATALEN0) + if (_mode == RF69_MODE_RX && PAYLOADLEN > 0) { setMode(RF69_MODE_STANDBY); // enables interrupts return true; } - else if (_mode == RF69_MODE_RX) // already in RX no payload yet + else if (_mode == RF69_MODE_RX) // already in RX no payload yet { interrupts(); // explicitly re-enable interrupts return false; @@ -424,7 +424,7 @@ void RFM69::unselect() { } // ON = disable filtering to capture all frames on network -// OFF = enable node+broadcast filtering to capture only frames sent to this/broadcast address +// OFF = enable node/broadcast filtering to capture only frames sent to this/broadcast address void RFM69::promiscuous(bool onOff) { _promiscuousMode = onOff; //writeReg(REG_PACKETCONFIG1, (readReg(REG_PACKETCONFIG1) & 0xF9) | (onOff ? RF_PACKET1_ADRSFILTERING_OFF : RF_PACKET1_ADRSFILTERING_NODEBROADCAST)); @@ -457,7 +457,7 @@ void RFM69::readAllRegs() for (byte regAddr = 1; regAddr <= 0x4F; regAddr++) { select(); - SPI.transfer(regAddr & 0x7f); // send address + r/w bit + SPI.transfer(regAddr & 0x7F); // send address + r/w bit regVal = SPI.transfer(0); unselect(); @@ -475,7 +475,7 @@ byte RFM69::readTemperature(byte calFactor) // returns centigrade setMode(RF69_MODE_STANDBY); writeReg(REG_TEMP1, RF_TEMP1_MEAS_START); while ((readReg(REG_TEMP1) & RF_TEMP1_MEAS_RUNNING)); - return ~readReg(REG_TEMP2) + COURSE_TEMP_COEF + calFactor; // 'complement'corrects the slope, rising temp = rising val + return ~readReg(REG_TEMP2) + COURSE_TEMP_COEF + calFactor; // 'complement' corrects the slope, rising temp = rising val } // COURSE_TEMP_COEF puts reading in the ballpark, user can add additional correction void RFM69::rcCalibration() diff --git a/RFM69.h b/RFM69.h index b5957a9..6489f9f 100644 --- a/RFM69.h +++ b/RFM69.h @@ -32,10 +32,10 @@ #define RFM69_h #include // assumes Arduino IDE v1.0 or greater -#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead) -#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on atmega328 +#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc) +#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on ATmega328 -// INT0 on AVRs should be connected to RFM69's DIO0 (ex on Atmega328 it's D2, on Atmega644/1284 it's D2) +// INT0 on AVRs should be connected to RFM69's DIO0 (ex on ATmega328 it's D2, on ATmega644/1284 it's D2) #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) #define RF69_IRQ_PIN 2 #define RF69_IRQ_NUM 0 @@ -50,7 +50,7 @@ #define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access #define RF69_MODE_SLEEP 0 // XTAL OFF -#define RF69_MODE_STANDBY 1 // XTAL ON +#define RF69_MODE_STANDBY 1 // XTAL ON #define RF69_MODE_SYNTH 2 // PLL ON #define RF69_MODE_RX 3 // RX MODE #define RF69_MODE_TX 4 // TX MODE @@ -66,17 +66,17 @@ #define RF69_BROADCAST_ADDR 255 #define RF69_CSMA_LIMIT_MS 1000 #define RF69_TX_LIMIT_MS 1000 -#define RF69_FSTEP 61.03515625 // == FXOSC/2^19 = 32mhz/2^19 (p13 in DS) +#define RF69_FSTEP 61.03515625 // == FXOSC / 2^19 = 32MHz / 2^19 (p13 in datasheet) class RFM69 { public: - static volatile byte DATA[RF69_MAX_DATA_LEN]; // recv/xmit buf, including hdr & crc bytes + static volatile byte DATA[RF69_MAX_DATA_LEN]; // recv/xmit buf, including header & crc bytes static volatile byte DATALEN; static volatile byte SENDERID; static volatile byte TARGETID; // should match _address static volatile byte PAYLOADLEN; static volatile byte ACK_REQUESTED; - static volatile byte ACK_RECEIVED; // Should be polled immediately after sending a packet with ACK request + static volatile byte ACK_RECEIVED; // should be polled immediately after sending a packet with ACK request static volatile int RSSI; // most accurate RSSI during reception (closest to the reception) static volatile byte _mode; // should be protected? @@ -95,7 +95,7 @@ class RFM69 { void setNetwork(byte networkID); bool canSend(); void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false); - bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=40); // 40ms roundtrip req for 61byte packets + bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=40); // 40ms roundtrip req for 61byte packets bool receiveDone(); bool ACKReceived(byte fromNodeID); bool ACKRequested(); @@ -106,7 +106,7 @@ class RFM69 { void setCS(byte newSPISlaveSelect); int readRSSI(bool forceTrigger=false); void promiscuous(bool onOff=true); - void setHighPower(bool onOFF=true); // have to call it after initialize for RFM69HW + void setHighPower(bool onOFF=true); // has to be called after initialize() for RFM69HW void setPowerLevel(byte level); // reduce/increase transmit power level void sleep(); byte readTemperature(byte calFactor=0); // get CMOS temperature (8bit)