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

[VN100] Fixed self test failing for reading wrong data

parent 8e5cb22a
Branches vn100-upd
No related tags found
No related merge requests found
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
namespace Boardcore namespace Boardcore
{ {
VN100::VN100(USART &usart, int baudRate, CRCOptions crc, VN100::VN100(USART &usart, int baudRate, CRCOptions crc, uint16_t samplePeriod)
uint16_t samplePeriod)
: usart(usart), baudRate(baudRate), samplePeriod(samplePeriod), crc(crc) : usart(usart), baudRate(baudRate), samplePeriod(samplePeriod), crc(crc)
{ {
} }
...@@ -108,12 +107,6 @@ bool VN100::init() ...@@ -108,12 +107,6 @@ bool VN100::init()
return false; return false;
} }
if (!this->start())
{
LOG_ERR(logger, "Unable to start the sampling thread");
return false;
}
// Set the isInit flag true // Set the isInit flag true
isInit = true; isInit = true;
...@@ -128,11 +121,11 @@ void VN100::run() ...@@ -128,11 +121,11 @@ void VN100::run()
while (!shouldStop()) while (!shouldStop())
{ {
long long initialTime = miosix::getTick(); long long initialTime = miosix::getTick();
{
// Sample the data locking the mutex // Sample the data locking the mutex
miosix::Lock<FastMutex> l(mutex); miosix::Lock<FastMutex> l(mutex);
threadSample = sampleData(); threadSample = sampleData();
}
// Sleep for the sampling period // Sleep for the sampling period
miosix::Thread::sleepUntil(initialTime + samplePeriod); miosix::Thread::sleepUntil(initialTime + samplePeriod);
} }
...@@ -418,20 +411,18 @@ bool VN100::selfTestImpl() ...@@ -418,20 +411,18 @@ bool VN100::selfTestImpl()
return false; return false;
} }
// I check the model number (I perform the procedure twice to delete junk // removing junk
// problems) usart.clearQueue();
sendStringCommand("VNRRG,01");
miosix::Thread::sleep(
100); // These sleep are important at very high baud rates
recvStringCommand(recvString, recvStringMaxDimension);
miosix::Thread::sleep(100);
// I check the model number
if (!sendStringCommand("VNRRG,01")) if (!sendStringCommand("VNRRG,01"))
{ {
LOG_WARN(logger, "Unable to send string command"); LOG_WARN(logger, "Unable to send string command");
return false; return false;
} }
miosix::Thread::sleep(100);
if (!recvStringCommand(recvString, recvStringMaxDimension)) if (!recvStringCommand(recvString, recvStringMaxDimension))
{ {
LOG_WARN(logger, "Unable to receive string command"); LOG_WARN(logger, "Unable to receive string command");
......
...@@ -86,8 +86,7 @@ public: ...@@ -86,8 +86,7 @@ public:
* @param Redundancy check option. * @param Redundancy check option.
* @param samplePeriod Sampling period in ms * @param samplePeriod Sampling period in ms
*/ */
VN100(USART &usart, int baudrate, VN100(USART &usart, int baudrate, CRCOptions crc = CRCOptions::CRC_ENABLE_8,
CRCOptions crc = CRCOptions::CRC_ENABLE_8,
uint16_t samplePeriod = 20); uint16_t samplePeriod = 20);
bool init() override; bool init() override;
......
...@@ -31,28 +31,42 @@ int main() ...@@ -31,28 +31,42 @@ int main()
{ {
VN100Data sample; VN100Data sample;
string sampleRaw; string sampleRaw;
GpioPin u2tx1(GPIOA_BASE, 2);
GpioPin u2rx1(GPIOA_BASE, 3);
u2rx1.alternateFunction(7);
u2rx1.mode(Mode::ALTERNATE);
u2tx1.alternateFunction(7);
u2tx1.mode(Mode::ALTERNATE);
USART usart(USART1, 921600); USART usart(USART1, 921600);
VN100 sensor{usart, 921600, VN100 sensor{usart, 921600, VN100::CRCOptions::CRC_ENABLE_16};
VN100::CRCOptions::CRC_ENABLE_16};
// Let the sensor start up // Let the sensor start up
Thread::sleep(1000); Thread::sleep(1000);
printf("Initializing sensor\n");
if (!sensor.init()) if (!sensor.init())
{ {
printf("Error initializing the sensor!\n"); printf("Error initializing the sensor!\n");
return 0; return 0;
} }
printf("Sensor init successful!\n"); printf("Running self-test\n");
if (!sensor.selfTest()) if (!sensor.selfTest())
{ {
printf("Error self test check!\n"); printf("Unable to execute self-test\n");
return 0;
}
if (!sensor.start())
{
printf("Unable to start the sampling thread\n");
return 0; return 0;
} }
printf("Sensor self test successful!\n"); printf("Sensor sampling thread started!\n");
// Sample and print 100 samples // Sample and print 100 samples
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment