Added KISS flow control
This commit is contained in:
		
							parent
							
								
									8a35afbebe
								
							
						
					
					
						commit
						978800aaf9
					
				
							
								
								
									
										7
									
								
								Config.h
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								Config.h
									
									
									
									
									
								
							@ -26,6 +26,9 @@
 | 
				
			|||||||
		const int pin_dio = 2;
 | 
							const int pin_dio = 2;
 | 
				
			||||||
		const int pin_led_rx = 5;
 | 
							const int pin_led_rx = 5;
 | 
				
			||||||
		const int pin_led_tx = 4;
 | 
							const int pin_led_tx = 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							#define FLOW_CONTROL_ENABLED true
 | 
				
			||||||
 | 
							#define QUEUE_SIZE 0
 | 
				
			||||||
	#endif
 | 
						#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#if MCU_VARIANT == MCU_1284P
 | 
						#if MCU_VARIANT == MCU_1284P
 | 
				
			||||||
@ -34,6 +37,9 @@
 | 
				
			|||||||
		const int pin_dio = 2;
 | 
							const int pin_dio = 2;
 | 
				
			||||||
		const int pin_led_rx = 12;
 | 
							const int pin_led_rx = 12;
 | 
				
			||||||
		const int pin_led_tx = 13;
 | 
							const int pin_led_tx = 13;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							#define FLOW_CONTROL_ENABLED true
 | 
				
			||||||
 | 
							#define QUEUE_SIZE 24
 | 
				
			||||||
	#endif
 | 
						#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// MCU independent configuration parameters
 | 
						// MCU independent configuration parameters
 | 
				
			||||||
@ -42,6 +48,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Default LoRa settings
 | 
						// Default LoRa settings
 | 
				
			||||||
	int  lora_sf   = 0;
 | 
						int  lora_sf   = 0;
 | 
				
			||||||
 | 
						int  lora_cr   = 5;
 | 
				
			||||||
	int  lora_txp  = 0xFF;
 | 
						int  lora_txp  = 0xFF;
 | 
				
			||||||
	uint32_t lora_bw   = 0;
 | 
						uint32_t lora_bw   = 0;
 | 
				
			||||||
	uint32_t lora_freq = 0;
 | 
						uint32_t lora_freq = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@
 | 
				
			|||||||
	#define CMD_SF			0x04
 | 
						#define CMD_SF			0x04
 | 
				
			||||||
	#define CMD_RADIO_STATE 0x05
 | 
						#define CMD_RADIO_STATE 0x05
 | 
				
			||||||
	#define CMD_RADIO_LOCK	0x06
 | 
						#define CMD_RADIO_LOCK	0x06
 | 
				
			||||||
 | 
						#define CMD_READY		0x0F
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#define CMD_STAT_RX		0x21
 | 
						#define CMD_STAT_RX		0x21
 | 
				
			||||||
	#define CMD_STAT_TX		0x22
 | 
						#define CMD_STAT_TX		0x22
 | 
				
			||||||
 | 
				
			|||||||
@ -42,6 +42,7 @@ bool startRadio() {
 | 
				
			|||||||
        setTXPower();
 | 
					        setTXPower();
 | 
				
			||||||
        setBandwidth();
 | 
					        setBandwidth();
 | 
				
			||||||
        setSpreadingFactor();
 | 
					        setSpreadingFactor();
 | 
				
			||||||
 | 
					        setCodingRate();
 | 
				
			||||||
        getFrequency();
 | 
					        getFrequency();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        LoRa.enableCrc();
 | 
					        LoRa.enableCrc();
 | 
				
			||||||
@ -178,6 +179,10 @@ void transmit(size_t size) {
 | 
				
			|||||||
    LoRa.endPacket();
 | 
					    LoRa.endPacket();
 | 
				
			||||||
    led_tx_off();
 | 
					    led_tx_off();
 | 
				
			||||||
    LoRa.receive();
 | 
					    LoRa.receive();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (FLOW_CONTROL_ENABLED)
 | 
				
			||||||
 | 
					      kiss_indicate_ready();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    kiss_indicate_error(ERROR_TXFAILED);
 | 
					    kiss_indicate_error(ERROR_TXFAILED);
 | 
				
			||||||
    led_indicate_error(5);
 | 
					    led_indicate_error(5);
 | 
				
			||||||
 | 
				
			|||||||
@ -146,6 +146,13 @@ void kiss_indicate_random(uint8_t byte) {
 | 
				
			|||||||
	Serial.write(FEND);
 | 
						Serial.write(FEND);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void kiss_indicate_ready() {
 | 
				
			||||||
 | 
						Serial.write(FEND);
 | 
				
			||||||
 | 
						Serial.write(CMD_READY);
 | 
				
			||||||
 | 
						Serial.write(0x01);
 | 
				
			||||||
 | 
						Serial.write(FEND);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool isSplitPacket(uint8_t header) {
 | 
					bool isSplitPacket(uint8_t header) {
 | 
				
			||||||
	return (header & FLAG_SPLIT);
 | 
						return (header & FLAG_SPLIT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -165,6 +172,10 @@ void setSpreadingFactor() {
 | 
				
			|||||||
	if (radio_online) LoRa.setSpreadingFactor(lora_sf);
 | 
						if (radio_online) LoRa.setSpreadingFactor(lora_sf);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void setCodingRate() {
 | 
				
			||||||
 | 
						if (radio_online) LoRa.setCodingRate4(lora_cr);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setTXPower() {
 | 
					void setTXPower() {
 | 
				
			||||||
	if (radio_online) LoRa.setTxPower(lora_txp);
 | 
						if (radio_online) LoRa.setTxPower(lora_txp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user