test fix lora configuration and transmission

This commit is contained in:
Alessandro Mauri 2026-09-20 12:53:37 +02:00
parent 43dffd6884
commit cdbee17f94

48
main.py
View File

@ -378,12 +378,40 @@ class LoRaGSStateMachine:
# --- Hardware Interface Stubs ---
# You will need to implement these using LoRaRF or your chosen SPI library
def lora_transmit_timeout(self, data: bytes, timeout_ms: int, force: bool) -> bool:
"""Transmit packet over SPI to SX1262 and update self.last_tx_time."""
# TODO: Implement via LoRaRF
# def lora_transmit_timeout(self, data: bytes, timeout_ms: int, force: bool) -> bool:
# """Transmit packet over SPI to SX1262 and update self.last_tx_time."""
# # TODO: Implement via LoRaRF
# LoRa.beginPacket()
# LoRa.write(list(data), len(data))
# LoRa.endPacket(timeout_ms * 64)
# self.last_tx_time = self.now_ms()
# return True
def lora_transmit_timeout(
self,
data: bytes,
timeout_ms: int,
force: bool
) -> bool:
LoRa.beginPacket()
LoRa.write(list(data), len(data))
LoRa.endPacket(timeout_ms * 64)
# timeout is already in milliseconds.
if not LoRa.endPacket(timeout_ms):
print("Failed to start LoRa TX")
return False
# endPacket() is asynchronous. DO NOT enter RX until TX is done.
if not LoRa.wait(timeout_ms / 1000.0):
print("LoRa TX host timeout")
return False
status = LoRa.status()
if status != LoRa.STATUS_TX_DONE:
print(f"LoRa TX failed, status={status}")
return False
self.last_tx_time = self.now_ms()
return True
@ -435,7 +463,17 @@ def main():
LoRa.setLoRaModulation(spreading_factor,EU868_BANDS[band].ch_bw_khz*1000, coding_rate, False)
LoRa.setTxPower(10, LoRa.TX_POWER_SX1262)
LoRa.setRxGain(LoRa.RX_GAIN_BOOSTED)
LoRa.setHeaderType(LoRa.HEADER_EXPLICIT)
#LoRa.setHeaderType(LoRa.HEADER_EXPLICIT)
LoRa.setLoRaPacket(
LoRa.HEADER_EXPLICIT,
8, # preamble symbols: match RadioLib
15, # sync/connect/accept packet length
True, # CRC enabled
False # normal IQ
)
# Explicitly make the sync word identical on both radios.
LoRa.setSyncWord(0x12)
print("LoRa parameters set")
state_machine = LoRaGSStateMachine(LORA_GS_ID, LORA_FC_ID)