Skip to content
Snippets Groups Projects
Commit 8e5cb22a authored by EmilioCorigliano's avatar EmilioCorigliano Committed by Emilio Corigliano
Browse files

[VN100] Correctly using the usart bus instead of creating it in the driver

parent 6370560d
Branches
No related tags found
No related merge requests found
......@@ -27,11 +27,10 @@
namespace Boardcore
{
VN100::VN100(USARTType *portNumber, int baudRate, CRCOptions crc,
VN100::VN100(USART &usart, int baudRate, CRCOptions crc,
uint16_t samplePeriod)
: portNumber(portNumber), baudRate(baudRate), crc(crc)
: usart(usart), baudRate(baudRate), samplePeriod(samplePeriod), crc(crc)
{
this->samplePeriod = samplePeriod;
}
bool VN100::init()
......@@ -151,7 +150,7 @@ bool VN100::sampleRaw()
}
// Send the IMU sampling command
serialInterface->writeString(preSampleImuString->c_str());
usart.writeString(preSampleImuString->c_str());
// Wait some time
// TODO dimension the time
......@@ -200,9 +199,6 @@ bool VN100::closeAndReset()
// Free the recvString memory
delete recvString;
// Free the serialInterface memory
delete serialInterface;
return true;
}
......@@ -241,7 +237,7 @@ VN100Data VN100::sampleData()
}
// Returns Quaternion, Magnetometer, Accelerometer and Gyro
serialInterface->writeString(preSampleImuString->c_str());
usart.writeString(preSampleImuString->c_str());
// Wait some time
// TODO dimension the time
......@@ -269,7 +265,7 @@ VN100Data VN100::sampleData()
// Returns Magnetometer, Accelerometer, Gyroscope, Temperature and Pressure
// (UNCOMPENSATED) DO NOT USE THESE MAGNETOMETER, ACCELEROMETER AND
// GYROSCOPE VALUES
serialInterface->writeString(preSampleTempPressString->c_str());
usart.writeString(preSampleTempPressString->c_str());
// Wait some time
// TODO dimension the time
......@@ -319,7 +315,7 @@ bool VN100::disableAsyncMessages(bool waitResponse)
bool VN100::configDefaultSerialPort()
{
// Initial default settings
serialInterface = new USART(portNumber, 115200);
usart.setBaudrate(115200);
// Check correct serial init
return true;
......@@ -342,11 +338,8 @@ bool VN100::configUserSerialPort()
return false;
}
// Destroy the serial object
delete serialInterface;
// I can open the serial with user's baud rate
serialInterface = new USART(portNumber, baudRate);
usart.setBaudrate(baudRate);
// Check correct serial init
return true;
......@@ -654,7 +647,7 @@ bool VN100::sendStringCommand(std::string command)
}
// I send the final command
serialInterface->writeString(command.c_str());
usart.writeString(command.c_str());
// Wait some time
// TODO dimension the time
......@@ -667,7 +660,7 @@ bool VN100::recvStringCommand(char *command, int maxLength)
{
int i = 0;
// Read the buffer
if (!(serialInterface->readBlocking(command, maxLength)))
if (!usart.readBlocking(command, maxLength))
{
return false;
}
......
......@@ -80,13 +80,13 @@ public:
/**
* @brief Constructor.
*
* @param USART port number.
* @param usart Serial bus used for the sensor.
* @param BaudRate different from the sensor's default [9600, 19200, 38400,
* 57600, 115200, 128000, 230400, 460800, 921600].
* @param Redundancy check option.
* @param samplePeriod Sampling period in ms
*/
VN100(USARTType *portNumber = USART2, int baudRate = 921600,
VN100(USART &usart, int baudrate,
CRCOptions crc = CRCOptions::CRC_ENABLE_8,
uint16_t samplePeriod = 20);
......@@ -238,8 +238,13 @@ private:
*/
uint16_t calculateChecksum16(uint8_t *message, int length);
USARTType *portNumber;
/**
* @brief Serial interface that is needed to communicate
* with the sensor via ASCII codes.
*/
USART &usart;
int baudRate;
uint16_t samplePeriod;
CRCOptions crc;
bool isInit = false;
......@@ -266,12 +271,6 @@ private:
*/
unsigned int recvStringLength = 0;
/**
* @brief Serial interface that is needed to communicate
* with the sensor via ASCII codes.
*/
USARTInterface *serialInterface = nullptr;
/**
* @brief Mutex to synchronize the reading and writing of the threadSample
*/
......
......@@ -31,7 +31,9 @@ int main()
{
VN100Data sample;
string sampleRaw;
VN100 sensor{USART1, 921600, VN100::CRCOptions::CRC_ENABLE_16};
USART usart(USART1, 921600);
VN100 sensor{usart, 921600,
VN100::CRCOptions::CRC_ENABLE_16};
// Let the sensor start up
Thread::sleep(1000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment