Skip to content

Commit

Permalink
build-time address customization
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed May 8, 2018
1 parent 94c795a commit e387f12
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
15 changes: 5 additions & 10 deletions software/firmware/source/SoftRF/BluetoothHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,28 @@ class MyCallbacks: public BLECharacteristicCallbacks {
std::string rxValue = pCharacteristic->getValue();

if (rxValue.length() > 0) {
#if 0
Serial.println("*********");
Serial.print("Received Value: ");
for (int i = 0; i < rxValue.length(); i++)
Serial.print(rxValue[i]);

Serial.println();
Serial.println("*********");
#else
BLE_FIFO_RX->write(rxValue.c_str(),
(BLE_FIFO_RX->room() > rxValue.length() ?
rxValue.length() : BLE_FIFO_RX->room()));
#endif
}
}
};

static void ESP32_Bluetooth_setup()
{
#if !defined(SOFTRF_ADDRESS)
union {
uint8_t efuse_mac[6];
uint64_t chipmacid;
};

chipmacid = ESP.getEfuseMac();

BT_name += String((uint32_t) efuse_mac[5] | (efuse_mac[4] << 8) | \
(efuse_mac[3] << 16), HEX);
#else
BT_name += String(SOFTRF_ADDRESS & 0x00FFFFFFU, HEX);
#endif

switch(settings->bluetooth)
{
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SoftRF/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static void ESP32_setup()

static uint32_t ESP32_getChipId()
{
#if !defined(SOFTRF_ADDRESS)
union {
uint8_t efuse_mac[6];
uint64_t chipmacid;
Expand All @@ -112,6 +113,9 @@ static uint32_t ESP32_getChipId()

return (uint32_t) efuse_mac[5] | (efuse_mac[4] << 8) | \
(efuse_mac[3] << 16) | (efuse_mac[2] << 24);
#else
return (SOFTRF_ADDRESS & 0xFFFFFFFFU );
#endif
}

static uint32_t ESP32_getFlashChipId()
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SoftRF/Platform_ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ static void ESP8266_setup()

static uint32_t ESP8266_getChipId()
{
#if !defined(SOFTRF_ADDRESS)
return ESP.getChipId();
#else
return (SOFTRF_ADDRESS & 0xFFFFFFFFU );
#endif
}

static uint32_t ESP8266_getFlashChipId()
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/Protocol_FANET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ size_t fanet_encode(void *fanet_pkt, ufo_t *this_aircraft) {

pkt->heading = constrain((int)roundf(heading * 256.0f)/360.0f, 0, 255);

int turnr4 = constrain((int)roundf(turnrate * 4.0f), 0, 255);
int turnr4 = constrain((int)roundf(turnrate * 4.0f), -255, 255);
if(abs(turnr4) > 63) {
pkt->turn_scale = 1;
pkt->turn_rate = ((turnr4 + (turnr4 >= 0 ? 2 : -2)) / 4);
Expand Down
7 changes: 7 additions & 0 deletions software/firmware/source/SoftRF/Protocol_Legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {
unsigned int aircraft_type = this_aircraft->aircraft_type;

pkt->addr = id & 0x00FFFFFF;

#if !defined(SOFTRF_ADDRESS)
pkt->addr_type = ADDR_TYPE_FLARM;
#else
pkt->addr_type = (pkt->addr == SOFTRF_ADDRESS ?
ADDR_TYPE_ICAO : ADDR_TYPE_FLARM);
#endif

pkt->parity = 0;
pkt->vs = 0;
pkt->vsmult = 0;
Expand Down
6 changes: 5 additions & 1 deletion software/firmware/source/SoftRF/WebHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ void handleRoot() {
</table>\
</body>\
</html>"),
ThisAircraft.addr, SOFTRF_FIRMWARE_VERSION,
ThisAircraft.addr, SOFTRF_FIRMWARE_VERSION
#if defined(SOFTRF_ADDRESS)
"I"
#endif
,
(SoC == NULL ? "NONE" : SoC->name),
(rf_chip == NULL ? "NONE" : rf_chip->name),
(baro_chip == NULL ? "NONE" : baro_chip->name),
Expand Down

0 comments on commit e387f12

Please sign in to comment.