mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 22:20:37 +00:00
trunk roundhouse kick
This commit is contained in:
@@ -55,7 +55,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine
|
||||
static uint8_t scratch[MAX_BLOCKSIZE];
|
||||
memcpy(scratch, bytes, numBytes);
|
||||
memset(scratch + numBytes, 0,
|
||||
sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it)
|
||||
sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it)
|
||||
|
||||
ctr->setIV(nonce, sizeof(nonce));
|
||||
ctr->setCounterSize(4);
|
||||
|
||||
@@ -23,7 +23,6 @@ void cpuDeepSleep(uint64_t msecs)
|
||||
|
||||
void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel");
|
||||
|
||||
|
||||
/** a simulated pin for busted IRQ hardware
|
||||
* Porduino helper class to do this i2c based polling:
|
||||
*/
|
||||
@@ -51,27 +50,29 @@ class PolledIrqPin : public GPIOPin
|
||||
|
||||
static GPIOPin *loraIrq;
|
||||
|
||||
int TCPPort = 4403;
|
||||
int TCPPort = 4403;
|
||||
|
||||
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
switch (key) {
|
||||
case 'p':
|
||||
if (sscanf(arg, "%d", &TCPPort) < 1)
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
else
|
||||
printf("Using TCP port %d\n", TCPPort);
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
switch (key) {
|
||||
case 'p':
|
||||
if (sscanf(arg, "%d", &TCPPort) < 1)
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
else
|
||||
printf("Using TCP port %d\n", TCPPort);
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
return 0;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void portduinoCustomInit() {
|
||||
void portduinoCustomInit()
|
||||
{
|
||||
static struct argp_option options[] = {{"port", 'p', "PORT", 0, "The TCP port to use."}, {0}};
|
||||
static void *childArguments;
|
||||
static void *childArguments;
|
||||
static char doc[] = "Meshtastic native build.";
|
||||
static char args_doc[] = "...";
|
||||
static struct argp argp = {options, parse_opt, args_doc, doc, 0, 0, 0};
|
||||
@@ -79,7 +80,6 @@ void portduinoCustomInit() {
|
||||
portduinoAddArguments(child, childArguments);
|
||||
}
|
||||
|
||||
|
||||
/** apps run under portduino can optionally define a portduinoSetup() to
|
||||
* use portduino specific init code (such as gpioBind) to setup portduino on their host machine,
|
||||
* before running 'arduino' code.
|
||||
@@ -89,9 +89,9 @@ void portduinoSetup()
|
||||
printf("Setting up Meshtastic on Portduino...\n");
|
||||
|
||||
#ifdef PORTDUINO_LINUX_HARDWARE
|
||||
SPI.begin(); // We need to create SPI
|
||||
SPI.begin(); // We need to create SPI
|
||||
bool usePineLora = !spiChip->isSimulated();
|
||||
if(usePineLora) {
|
||||
if (usePineLora) {
|
||||
printf("Connecting to PineLora board...\n");
|
||||
|
||||
// FIXME: remove this hack once interrupts are confirmed to work on new pine64 board
|
||||
@@ -110,8 +110,7 @@ void portduinoSetup()
|
||||
auto loraCs = new LinuxGPIOPin(SX126X_CS, "ch341", "cs0", "loraCs");
|
||||
loraCs->setSilent();
|
||||
gpioBind(loraCs);
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
@@ -35,9 +35,9 @@ void SimRadio::setTransmitDelay()
|
||||
// So we want to make sure the other side has had a chance to reconfigure its radio.
|
||||
|
||||
/* We assume if rx_snr = 0 and rx_rssi = 0, the packet was generated locally.
|
||||
* This assumption is valid because of the offset generated by the radio to account for the noise
|
||||
* floor.
|
||||
*/
|
||||
* This assumption is valid because of the offset generated by the radio to account for the noise
|
||||
* floor.
|
||||
*/
|
||||
if (p->rx_snr == 0 && p->rx_rssi == 0) {
|
||||
startTransmitTimer(true);
|
||||
} else {
|
||||
@@ -96,7 +96,6 @@ void SimRadio::completeSending()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Could we send right now (i.e. either not actively receving or transmitting)? */
|
||||
bool SimRadio::canSendImmediately()
|
||||
{
|
||||
@@ -116,14 +115,14 @@ bool SimRadio::canSendImmediately()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimRadio::isActivelyReceiving()
|
||||
bool SimRadio::isActivelyReceiving()
|
||||
{
|
||||
return false; // TODO check how this should be simulated
|
||||
return false; // TODO check how this should be simulated
|
||||
}
|
||||
|
||||
bool SimRadio::isChannelActive()
|
||||
{
|
||||
return false; // TODO ask simulator
|
||||
return false; // TODO ask simulator
|
||||
}
|
||||
|
||||
/** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
|
||||
@@ -138,14 +137,13 @@ bool SimRadio::cancelSending(NodeNum from, PacketId id)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void SimRadio::onNotify(uint32_t notification)
|
||||
{
|
||||
switch (notification) {
|
||||
case ISR_TX:
|
||||
handleTransmitInterrupt();
|
||||
LOG_DEBUG("tx complete - starting timer\n");
|
||||
startTransmitTimer();
|
||||
startTransmitTimer();
|
||||
break;
|
||||
case ISR_RX:
|
||||
LOG_DEBUG("rx complete - starting timer\n");
|
||||
@@ -179,25 +177,25 @@ void SimRadio::onNotify(uint32_t notification)
|
||||
} else {
|
||||
// LOG_DEBUG("done with txqueue\n");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
assert(0); // We expected to receive a valid notification from the ISR
|
||||
}
|
||||
}
|
||||
|
||||
/** start an immediate transmit */
|
||||
void SimRadio::startSend(MeshPacket * txp)
|
||||
void SimRadio::startSend(MeshPacket *txp)
|
||||
{
|
||||
printPacket("Starting low level send", txp);
|
||||
size_t numbytes = beginSending(txp);
|
||||
MeshPacket* p = packetPool.allocCopy(*txp);
|
||||
MeshPacket *p = packetPool.allocCopy(*txp);
|
||||
perhapsDecode(p);
|
||||
Compressed c = Compressed_init_default;
|
||||
c.portnum = p->decoded.portnum;
|
||||
// LOG_DEBUG("Sending back to simulator with portNum %d\n", p->decoded.portnum);
|
||||
c.portnum = p->decoded.portnum;
|
||||
// LOG_DEBUG("Sending back to simulator with portNum %d\n", p->decoded.portnum);
|
||||
if (p->decoded.payload.size <= sizeof(c.data.bytes)) {
|
||||
memcpy(&c.data.bytes, p->decoded.payload.bytes, p->decoded.payload.size);
|
||||
c.data.size = p->decoded.payload.size;
|
||||
c.data.size = p->decoded.payload.size;
|
||||
} else {
|
||||
LOG_WARN("Payload size is larger than compressed message allows! Sending empty payload.\n");
|
||||
}
|
||||
@@ -206,8 +204,8 @@ void SimRadio::startSend(MeshPacket * txp)
|
||||
service.sendToPhone(p); // Sending back to simulator
|
||||
}
|
||||
|
||||
|
||||
void SimRadio::startReceive(MeshPacket *p) {
|
||||
void SimRadio::startReceive(MeshPacket *p)
|
||||
{
|
||||
isReceiving = true;
|
||||
size_t length = getPacketLength(p);
|
||||
uint32_t xmitMsec = getPacketTime(length);
|
||||
@@ -243,8 +241,8 @@ void SimRadio::handleReceiveInterrupt(MeshPacket *p)
|
||||
xmitMsec = getPacketTime(length);
|
||||
// LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length);
|
||||
|
||||
MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packtPool
|
||||
mp->which_payload_variant = MeshPacket_decoded_tag; // Mark that the payload is already decoded
|
||||
MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packtPool
|
||||
mp->which_payload_variant = MeshPacket_decoded_tag; // Mark that the payload is already decoded
|
||||
|
||||
printPacket("Lora RX", mp);
|
||||
|
||||
@@ -253,15 +251,17 @@ void SimRadio::handleReceiveInterrupt(MeshPacket *p)
|
||||
deliverToReceiver(mp);
|
||||
}
|
||||
|
||||
size_t SimRadio::getPacketLength(MeshPacket *mp) {
|
||||
size_t SimRadio::getPacketLength(MeshPacket *mp)
|
||||
{
|
||||
auto &p = mp->decoded;
|
||||
return (size_t)p.payload.size+sizeof(PacketHeader);
|
||||
return (size_t)p.payload.size + sizeof(PacketHeader);
|
||||
}
|
||||
|
||||
int16_t SimRadio::readData(uint8_t* data, size_t len) {
|
||||
int16_t SimRadio::readData(uint8_t *data, size_t len)
|
||||
{
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
// add null terminator
|
||||
data[len] = 0;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "RadioInterface.h"
|
||||
#include "MeshPacketQueue.h"
|
||||
#include "RadioInterface.h"
|
||||
#include "api/WiFiServerAPI.h"
|
||||
|
||||
#include <RadioLib.h>
|
||||
|
||||
class SimRadio : public RadioInterface
|
||||
{
|
||||
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };
|
||||
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };
|
||||
|
||||
/**
|
||||
* Debugging counts
|
||||
*/
|
||||
uint32_t rxBad = 0, rxGood = 0, txGood = 0;
|
||||
/**
|
||||
* Debugging counts
|
||||
*/
|
||||
uint32_t rxBad = 0, rxGood = 0, txGood = 0;
|
||||
|
||||
MeshPacketQueue txQueue = MeshPacketQueue(MAX_TX_QUEUE);
|
||||
|
||||
MeshPacketQueue txQueue = MeshPacketQueue(MAX_TX_QUEUE);
|
||||
|
||||
public:
|
||||
SimRadio();
|
||||
|
||||
@@ -24,7 +24,6 @@ class SimRadio : public RadioInterface
|
||||
*/
|
||||
static SimRadio *instance;
|
||||
|
||||
|
||||
virtual ErrorCode send(MeshPacket *p) override;
|
||||
|
||||
/** can we detect a LoRa preamble on the current channel? */
|
||||
@@ -38,7 +37,7 @@ class SimRadio : public RadioInterface
|
||||
/** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
|
||||
virtual bool cancelSending(NodeNum from, PacketId id) override;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Start waiting to receive a message
|
||||
*
|
||||
* External functions can call this method to wake the device from sleep.
|
||||
@@ -47,13 +46,11 @@ class SimRadio : public RadioInterface
|
||||
|
||||
QueueStatus getQueueStatus() override;
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/// are _trying_ to receive a packet currently (note - we might just be waiting for one)
|
||||
bool isReceiving = false;
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
void setTransmitDelay();
|
||||
|
||||
/** random timer with certain min. and max. settings */
|
||||
@@ -71,19 +68,17 @@ class SimRadio : public RadioInterface
|
||||
virtual void startSend(MeshPacket *txp);
|
||||
|
||||
// derive packet length
|
||||
size_t getPacketLength(MeshPacket *p);
|
||||
size_t getPacketLength(MeshPacket *p);
|
||||
|
||||
int16_t readData(uint8_t* str, size_t len);
|
||||
int16_t readData(uint8_t *str, size_t len);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/** Could we send right now (i.e. either not actively receiving or transmitting)? */
|
||||
virtual bool canSendImmediately();
|
||||
|
||||
|
||||
/**
|
||||
* If a send was in progress finish it and return the buffer to the pool */
|
||||
void completeSending();
|
||||
|
||||
};
|
||||
|
||||
extern SimRadio *simRadio;
|
||||
Reference in New Issue
Block a user