46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
|
|||
|
|
#include <vector>
|
||
|
|
#include "raymath.h"
|
||
|
|
#include <cstdint>
|
||
|
|
#ifdef _WIN32
|
||
|
|
#include <windows.h>
|
||
|
|
#endif
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
// struct Quaternion{
|
||
|
|
// float w, x, y, z;
|
||
|
|
// };
|
||
|
|
|
||
|
|
#pragma pack(push, 1)
|
||
|
|
typedef struct {
|
||
|
|
uint8_t StartByte;
|
||
|
|
uint8_t SensorAddress;
|
||
|
|
float qw;
|
||
|
|
float qx;
|
||
|
|
float qy;
|
||
|
|
float qz;
|
||
|
|
uint8_t EndByte;
|
||
|
|
} QuaternionData;
|
||
|
|
#pragma pack(pop)
|
||
|
|
|
||
|
|
// serial communication functions
|
||
|
|
#ifdef _WIN32
|
||
|
|
HANDLE initSerialPort (const char* portName, DWORD baudRate);
|
||
|
|
bool readSerialData (HANDLE hSerial, uint8_t* buffer, DWORD bufferSize, DWORD& bytesRead);
|
||
|
|
#elif defined(__APPLE__)
|
||
|
|
#elif defined(__linux__)
|
||
|
|
int linux_initSerialPort();
|
||
|
|
bool linux_close_serial_port(int serial_port);
|
||
|
|
bool linux_readSerialData(int serialPort, std::vector<uint8_t> &buffer, size_t& bytes_read);
|
||
|
|
void print_vector_content(std::vector<uint8_t> &vec, std::string vector_name);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
// extract packet data from serial datastream
|
||
|
|
std::vector<uint8_t> extractPacket(std::vector<uint8_t> &buffer);
|
||
|
|
bool parseBinaryPacket(std::vector<uint8_t> &packetData, Quaternion &quat);
|
||
|
|
|
||
|
|
|
||
|
|
bool parseQuaternion(const std::string& data, Quaternion& quat);
|
||
|
|
|
||
|
|
|