works with phone

This commit is contained in:
geeksville
2020-02-02 19:08:04 -08:00
parent b799004f0d
commit d34bbffb2d
5 changed files with 40 additions and 8 deletions

View File

@@ -28,10 +28,13 @@ class BluetoothMeshCallbacks : public BLECharacteristicCallbacks
// or make empty if the queue is empty
if (!mp)
{
Serial.println("toPhone queue is empty");
c->setValue((uint8_t *)"", 0);
}
else
{
Serial.println("delivering toPhone packet to phone");
static FromRadio fradio;
// Encapsulate as a ToRadio packet

View File

@@ -87,7 +87,7 @@ ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len)
// FIXME - for now we do all packets as broadcast
dest = NODENUM_BROADCAST;
assert(len <= 255); // Make sure we don't overflow the tiny max packet size
assert(len <= 255); // Make sure we don't overflow the tiny max packet size
// Note: we don't use sendToWait here because we don't want to wait and for the time being don't require
// reliable delivery
@@ -95,6 +95,13 @@ ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len)
return manager.sendto((uint8_t *)buf, len, dest) ? ERRNO_OK : ERRNO_UNKNOWN;
}
/// enqueue a received packet in rxDest
void MeshRadio::handleReceive(MeshPacket *mp)
{
int res = rxDest.enqueue(mp, 0); // NOWAIT - fixme, if queue is full, delete older messages
assert(res == pdTRUE);
}
void MeshRadio::loop()
{
// FIXME read from radio with recvfromAckTimeout
@@ -136,8 +143,7 @@ static int16_t packetnum = 0; // packet counter, we increment per xmission
{
// parsing was successful, queue for our recipient
mp->has_payload = true;
int res = rxDest.enqueue(mp, 0); // NOWAIT - fixme, if queue is full, delete older messages
assert(res == pdTRUE);
handleReceive(mp);
}
}
@@ -159,6 +165,10 @@ static int16_t packetnum = 0; // packet counter, we increment per xmission
assert(res == ERRNO_OK);
}
pool.release(txp);
bool loopbackTest = false; // if true we will pretend to receive any packets we just sent
if (loopbackTest)
handleReceive(txp);
else
pool.release(txp);
}
}

View File

@@ -51,5 +51,8 @@ private:
/// low level send, might block for mutiple seconds
ErrorCode sendTo(NodeNum dest, const uint8_t *buf, size_t len);
/// enqueue a received packet in rxDest
void handleReceive(MeshPacket *p);
};

View File

@@ -85,6 +85,18 @@ void MeshService::handleToRadio(std::string s)
sendToMesh(r.variant.packet);
break;
case ToRadio_want_nodes_tag:
Serial.println("FIXME: ignoring want nodes");
break;
case ToRadio_set_radio_tag:
Serial.println("FIXME: ignoring set radio");
break;
case ToRadio_set_owner_tag:
Serial.println("FIXME: ignoring set owner");
break;
default:
Serial.println("Error: unexpected ToRadio variant");
break;