mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-30 06:31:01 +00:00
get sensor and NMEA data from indicator. Will test tomorrow, don't merge yet.
This commit is contained in:
90
src/gps/FakeUART.cpp
Normal file
90
src/gps/FakeUART.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "FakeUART.h"
|
||||
|
||||
FakeUART::FakeUART() {}
|
||||
|
||||
void FakeUART::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms,
|
||||
uint8_t rxfifo_full_thrhd)
|
||||
{
|
||||
baudrate = baud;
|
||||
FakeBuf.clear();
|
||||
}
|
||||
|
||||
void FakeUART::end()
|
||||
{
|
||||
FakeBuf.clear();
|
||||
}
|
||||
|
||||
int FakeUART::available()
|
||||
{
|
||||
return FakeBuf.size();
|
||||
}
|
||||
|
||||
int FakeUART::peek()
|
||||
{
|
||||
unsigned char ret;
|
||||
if (FakeBuf.peek(ret))
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int FakeUART::read()
|
||||
{
|
||||
unsigned char ret;
|
||||
if (FakeBuf.pop(ret))
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FakeUART::flush()
|
||||
{
|
||||
FakeBuf.clear();
|
||||
}
|
||||
|
||||
uint32_t FakeUART::baudRate()
|
||||
{
|
||||
return baudrate;
|
||||
}
|
||||
|
||||
void FakeUART::updateBaudRate(unsigned long speed)
|
||||
{
|
||||
baudrate = speed;
|
||||
}
|
||||
|
||||
size_t FakeUART::setRxBufferSize(size_t size)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t FakeUART::write(const char *buffer)
|
||||
{
|
||||
return write((char *)buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
size_t FakeUART::write(uint8_t *buffer, size_t size)
|
||||
{
|
||||
return write((char *)buffer, size);
|
||||
}
|
||||
|
||||
size_t FakeUART::write(char *buffer, size_t size)
|
||||
{
|
||||
meshtastic_InterdeviceMessage message = meshtastic_InterdeviceMessage_init_zero;
|
||||
if (size > sizeof(message.data.nmea)) {
|
||||
size = sizeof(message.data.nmea); // Truncate if buffer is too large
|
||||
}
|
||||
memcpy(message.data.nmea, buffer, size);
|
||||
sensecapIndicator.send_uplink(message);
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t FakeUART::stuff_buffer(const char *buffer, size_t size)
|
||||
{
|
||||
// push buffer in a loop to FakeBuf
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (!FakeBuf.push(buffer[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
FakeUART *FakeSerial;
|
||||
Reference in New Issue
Block a user