
* Use unsigned long when dealing with millis() and micros(). Although sizeof(uint32_t) == sizeof(unsigned long) on Arduino, this is not the case on 64-bit Linux, where sizeof(unsigned long) == sizeof(uint64_t). Most timestamp arithmetic and comparisons have been left alone, to reduce code churn. This is fine, as uint32_t is perfectly wide to store most timestamp deltas this library will deal with, and C will promote the integer rather than do a narrowing conversion. The real problem arises with narrowing conversions being done by assuming timestamps are 32-bit. No functional changes intended for platforms where sizeof(uint32_t) == sizeof(unsigned long) (so most 8/16/32-bit platforms). Signed-off-by: Elizabeth Myers <elizabeth.jennifer.myers@gmail.com> * Change most timestamps to use RadioLibTime_t. This makes it obvious what is and isn't a timestamp. Not everything has been converted; anything dealing with protocol and chip-level timestamps has been left alone on purpose, to make it clear that these functions do require 32-bit timestamps. No functional changes intended on platforms where sizeof(uint32_t) == sizeof(unsigned long). Signed-off-by: Elizabeth Myers <elizabeth.jennifer.myers@gmail.com> * Use uint32_t internally in getTimeOnAir. We need to not overflow the integers with the shifts and multiplications, so this is correct behaviour. Signed-off-by: Elizabeth Myers <elizabeth.jennifer.myers@gmail.com> --------- Signed-off-by: Elizabeth Myers <elizabeth.jennifer.myers@gmail.com>
98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
#include "BellModem.h"
|
|
#if !RADIOLIB_EXCLUDE_BELL
|
|
|
|
const BellModem_t Bell101 = {
|
|
.freqMark = 1270,
|
|
.freqSpace = 1070,
|
|
.baudRate = 110,
|
|
.freqMarkReply = 2225,
|
|
.freqSpaceReply = 2025,
|
|
};
|
|
|
|
const BellModem_t Bell103 = {
|
|
.freqMark = 1270,
|
|
.freqSpace = 1070,
|
|
.baudRate = 300,
|
|
.freqMarkReply = 2225,
|
|
.freqSpaceReply = 2025,
|
|
};
|
|
|
|
const BellModem_t Bell202 = {
|
|
.freqMark = 1200,
|
|
.freqSpace = 2200,
|
|
.baudRate = 1200,
|
|
.freqMarkReply = 1200,
|
|
.freqSpaceReply = 2200,
|
|
};
|
|
|
|
BellClient::BellClient(PhysicalLayer* phy, uint32_t pin) : AFSKClient(phy, pin) {
|
|
this->reply = false;
|
|
}
|
|
|
|
BellClient::BellClient(AFSKClient* aud) : AFSKClient(aud) {
|
|
this->reply = false;
|
|
}
|
|
|
|
int16_t BellClient::begin(const BellModem_t& modem) {
|
|
int16_t state = setModem(modem);
|
|
RADIOLIB_ASSERT(state);
|
|
|
|
state = phyLayer->startDirect();
|
|
return(state);
|
|
}
|
|
|
|
int16_t BellClient::setModem(const BellModem_t& modem) {
|
|
this->modemType = modem;
|
|
this->toneLen = (1000000.0/(float)this->modemType.baudRate)*this->correction;
|
|
return(RADIOLIB_ERR_NONE);
|
|
}
|
|
|
|
int16_t BellClient::setCorrection(float corr) {
|
|
this->correction = corr;
|
|
return(RADIOLIB_ERR_NONE);
|
|
}
|
|
|
|
size_t BellClient::write(uint8_t b) {
|
|
// first get the frequencies
|
|
uint16_t toneMark = this->modemType.freqMark;
|
|
uint16_t toneSpace = this->modemType.freqSpace;
|
|
if(this->reply) {
|
|
toneMark = this->modemType.freqMarkReply;
|
|
toneMark = this->modemType.freqSpaceReply;
|
|
}
|
|
|
|
// get the Module pointer to access HAL
|
|
Module* mod = this->phyLayer->getMod();
|
|
|
|
if(this->autoStart) {
|
|
phyLayer->transmitDirect();
|
|
}
|
|
|
|
// iterate over the bits and set correct frequencies
|
|
for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) {
|
|
RadioLibTime_t start = mod->hal->micros();
|
|
if(b & mask) {
|
|
this->tone(toneMark, false);
|
|
} else {
|
|
this->tone(toneSpace, false);
|
|
}
|
|
mod->waitForMicroseconds(start, this->toneLen);
|
|
}
|
|
|
|
if(this->autoStart) {
|
|
phyLayer->standby();
|
|
}
|
|
return(1);
|
|
}
|
|
|
|
int16_t BellClient::idle() {
|
|
this->autoStart = false;
|
|
return(phyLayer->transmitDirect());
|
|
}
|
|
|
|
int16_t BellClient::standby() {
|
|
this->autoStart = true;
|
|
return(phyLayer->standby());
|
|
}
|
|
|
|
#endif
|