diff --git a/src/main.cpp b/src/main.cpp index 634ddeb25..f36c7d132 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,8 +67,11 @@ NRF52Bluetooth *nrf52Bluetooth; #include "platform/portduino/SimRadio.h" #endif -#if defined(HAS_RADIO) && defined(ARCH_PORTDUINO) +#ifdef ARCH_RASPBERRY_PI #include "platform/portduino/PiHal.h" +#include +#include +#include #endif #if HAS_BUTTON @@ -132,12 +135,28 @@ std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySenso Router *router = NULL; // Users of router don't care what sort of subclass implements that API +#ifdef ARCH_RASPBERRY_PI +void getPiMacAddr(uint8_t *dmac) +{ + std::fstream macIdentity; + macIdentity.open("/sys/kernel/debug/bluetooth/hci0/identity", std::ios::in); + std::string macLine; + getline(macIdentity, macLine); + macIdentity.close(); + + dmac[0] = strtol(macLine.substr(0, 2).c_str(), NULL, 16); + dmac[1] = strtol(macLine.substr(3, 2).c_str(), NULL, 16); + dmac[2] = strtol(macLine.substr(6, 2).c_str(), NULL, 16); + dmac[3] = strtol(macLine.substr(9, 2).c_str(), NULL, 16); + dmac[4] = strtol(macLine.substr(12, 2).c_str(), NULL, 16); + dmac[5] = strtol(macLine.substr(15, 2).c_str(), NULL, 16); +} +#endif + const char *getDeviceName() { uint8_t dmac[6]; - getMacAddr(dmac); - // Meshtastic_ab3c or Shortname_abcd static char name[20]; snprintf(name, sizeof(name), "%02x%02x", dmac[4], dmac[5]); @@ -679,7 +698,7 @@ void setup() } } -#elif HW_SPI1_DEVICE +#elif defined(HW_SPI1_DEVICE) LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI1, spiSettings); #else // HW_SPI1_DEVICE LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); diff --git a/src/main.h b/src/main.h index 3f0120406..5c9de1b81 100644 --- a/src/main.h +++ b/src/main.h @@ -56,6 +56,7 @@ extern graphics::Screen *screen; // Return a human readable string of the form "Meshtastic_ab13" const char *getDeviceName(); +void getPiMacAddr(uint8_t *dmac); extern uint32_t timeLastPowered; diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 2046c2cea..6d9fc2dea 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -421,7 +421,11 @@ void NodeDB::init() */ void NodeDB::pickNewNodeNum() { +#ifdef ARCH_RASPBERRY_PI + getPiMacAddr(ourMacAddr); // Make sure ourMacAddr is set +#else getMacAddr(ourMacAddr); // Make sure ourMacAddr is set +#endif // Pick an initial nodenum based on the macaddr NodeNum nodeNum = (ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]; @@ -433,6 +437,7 @@ void NodeDB::pickNewNodeNum() LOG_WARN("NOTE! Our desired nodenum 0x%x is invalid or in use, so trying for 0x%x\n", nodeNum, candidate); nodeNum = candidate; } + LOG_WARN("Using nodenum 0x%x \n", nodeNum); myNodeInfo.my_node_num = nodeNum; } diff --git a/src/platform/portduino/PiHal.h b/src/platform/portduino/PiHal.h index 9ffaa7fa0..f10040583 100644 --- a/src/platform/portduino/PiHal.h +++ b/src/platform/portduino/PiHal.h @@ -78,7 +78,6 @@ class PiHal : public RadioLibHal void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override { - LOG_DEBUG("Here to enable pin %d!\n", interruptNum); if (interruptNum == RADIOLIB_NC) { return; } @@ -87,18 +86,15 @@ class PiHal : public RadioLibHal } else { gpioSetAlertFunc(interruptNum, (gpioISRFunc_t)interruptCb); } - LOG_DEBUG("Pin enabled %d!\n", interruptNum); } void detachInterrupt(uint32_t interruptNum) override { - LOG_DEBUG("Here for pin %d!\n", interruptNum); if (interruptNum == RADIOLIB_NC) { return; } gpioSetAlertFunc(interruptNum, NULL); - LOG_DEBUG("Finished\n"); } void delay(unsigned long ms) override { gpioDelay(ms * 1000); } diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 3af65be38..fb71a429b 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -7,13 +7,15 @@ #include #include + #ifdef ARCH_RASPBERRY_PI #include "pigpio.h" + #else #include #endif -// FIXME - move setBluetoothEnable into a HALPlatform class +// FIXME - move setBluetoothEnable into a HALPlatform class void setBluetoothEnable(bool on) { // not needed @@ -93,30 +95,9 @@ void portduinoSetup() #ifdef ARCH_RASPBERRY_PI return; -/* - //printf("using GPIOD Version: %s\n", gpiod_version_string()); - gpioInitialise(); - // We need to create SPI - SPI.begin(); - if (!spiChip->isSimulated()) { - printf("Connecting to RFM95 board...\n"); - loraIrq = new LinuxGPIOPin(LORA_DIO0, "gpiochip0", LORA_DIO0_LABEL, "loraIrq"); - loraIrq->setSilent(); - gpioBind(loraIrq); - -#if (RF95_NSS != RADIOLIB_NC) - auto loraCs = new LinuxGPIOPin(RF95_NSS, GPIOD_CHIP_LABEL, RF95_NSS_LABEL, "loraCs"); - loraCs->setSilent(); - gpioBind(loraCs); #endif - auto loraReset = new LinuxGPIOPin(LORA_RESET, GPIOD_CHIP_LABEL, LORA_RESET_LABEL, "loraReset"); - loraReset->setSilent(); - gpioBind(loraReset); - - } else - -#elif defined(PORTDUINO_LINUX_HARDWARE) +#ifdef defined(PORTDUINO_LINUX_HARDWARE) SPI.begin(); // We need to create SPI bool usePineLora = !spiChip->isSimulated(); if (usePineLora) { @@ -157,8 +138,6 @@ void portduinoSetup() gpioBind(new SimGPIOPin(SX126X_RESET, "fakeLoraReset")); gpioBind(new SimGPIOPin(LORA_DIO1, "fakeLoraIrq")); } -*/ -#endif // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); // gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent()); } \ No newline at end of file diff --git a/src/shutdown.h b/src/shutdown.h index 90fb19d0c..f36a7f8dd 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -14,6 +14,8 @@ void powerCommandsCheck() NVIC_SystemReset(); #elif defined(ARCH_RP2040) rp2040.reboot(); +#elif defined(ARCH_RASPBERRY_PI) + exit(EXIT_SUCCESS); #else rebootAtMsec = -1; LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied.\n");