Ardupilot2/libraries/AP_Scripting/AP_Scripting_SerialAccess.cpp
Thomas Watson e18449b1b8 AP_Scripting: use generic access userdata for serial ports
Adding another layer instead of just exposing UARTDriver bindings allows
substitution of the different functions for device simulation later.

Also take the opportunity to rework the docs a little.
2024-06-27 12:00:18 +10:00

50 lines
953 B
C++

/*
generic object to allow a script to use a serial stream
*/
#include "AP_Scripting_config.h"
#include "AP_Scripting_SerialAccess.h"
#if AP_SCRIPTING_ENABLED
void AP_Scripting_SerialAccess::begin(uint32_t baud)
{
stream->begin(baud);
}
size_t AP_Scripting_SerialAccess::write(uint8_t c)
{
return write(&c, 1);
}
size_t AP_Scripting_SerialAccess::write(const uint8_t *buffer, size_t size)
{
return stream->write(buffer, size);
}
int16_t AP_Scripting_SerialAccess::read(void)
{
uint8_t c;
if (read(&c, 1) != 1) {
return -1;
}
return c;
}
ssize_t AP_Scripting_SerialAccess::read(uint8_t* buffer, uint16_t count)
{
return stream->read(buffer, count);
}
uint32_t AP_Scripting_SerialAccess::available(void)
{
return stream->available();
}
void AP_Scripting_SerialAccess::set_flow_control(enum AP_HAL::UARTDriver::flow_control fcs)
{
stream->set_flow_control(fcs);
}
#endif // AP_SCRIPTING_ENABLED