27 #ifndef TL_RECEIVE_TIME
28 #define TL_RECEIVE_TIME 0
37 uint32_t back_off(uint8_t attempts)
39 uint32_t result = attempts;
40 for(uint8_t d = 0; d < TL_BACK_OFF_DEGREE; d++) {
41 result *= (uint32_t)(attempts);
48 return LoRa.packetRssi();
53 return LoRa.packetSnr();
56 bool setFrequency(uint32_t frequency)
58 return LoRa.begin(frequency);
61 void setSignalBandwidth(uint32_t bandwidth)
63 LoRa.setSignalBandwidth(bandwidth);
66 void setPins(uint8_t cs_pin, uint8_t reset_pin, uint8_t dio0_pin)
68 LoRa.setPins(cs_pin, reset_pin, dio0_pin);
71 void setSpreadingFactor(uint8_t spreadingFactor)
73 LoRa.setSpreadingFactor(spreadingFactor);
76 void setCodingRate4(uint8_t codingRate)
78 LoRa.setCodingRate4(codingRate);
81 void setPreambleLength(uint16_t preambleLength)
83 LoRa.setPreambleLength(preambleLength);
86 void setSyncWord(uint8_t syncWord)
88 LoRa.setSyncWord(syncWord);
91 void setCRC(
bool enableCRC)
100 void setTxPower(uint8_t txPower)
102 LoRa.setTxPower(txPower);
105 void setTxPower(uint8_t txPower, uint8_t boostPin)
107 LoRa.setTxPower(txPower, boostPin);
122 return LoRa.random();
128 bool begin(uint8_t did = 0)
130 PJON_DELAY_MICROSECONDS(PJON_RANDOM(TL_INITIAL_DELAY) + did);
138 if(LoRa.parsePacket() > 0) {
146 static uint8_t get_max_attempts()
148 return TL_MAX_ATTEMPTS;
153 static uint16_t get_receive_time()
155 return TL_RECEIVE_TIME;
160 void handle_collision()
162 PJON_DELAY_MICROSECONDS(PJON_RANDOM(TL_COLLISION_DELAY));
171 void prepare_response(
const uint8_t *buffer, uint16_t position)
173 for(int8_t i = 0; i < TL_RESPONSE_LENGTH; i++)
175 buffer[(position - ((TL_RESPONSE_LENGTH - 1) - i)) - 1];
180 uint16_t receive_response()
182 uint32_t time = PJON_MICROS();
183 while((uint32_t)(PJON_MICROS() - time) < TL_RESPONSE_TIME_OUT) {
184 uint8_t frame_size = LoRa.parsePacket();
185 if(frame_size == TL_RESPONSE_LENGTH) {
186 for(uint8_t i = 0; i < TL_RESPONSE_LENGTH; i++)
187 if(LoRa.read() != _response[i]) {
198 uint16_t receive_frame(uint8_t *
data, uint16_t max_length)
200 uint8_t frameSize = LoRa.parsePacket();
203 if((frameSize > 5) && (frameSize <= max_length)) {
204 while(LoRa.available()) {
208 prepare_response(
data, frameSize);
217 void send_byte(uint8_t b)
224 void send_response(uint8_t response)
226 if(response == PJON_ACK) {
228 for(uint8_t i = 0; i < TL_RESPONSE_LENGTH; i++) {
229 send_byte(_response[i]);
237 void send_frame(uint8_t *
data, uint8_t length)
240 for(uint8_t b = 0; b < length; b++) {
243 prepare_response(
data, length);
258 uint32_t _last_reception_time;
259 uint8_t _response[TL_RESPONSE_LENGTH];