uBlox move some code between files

mtx2
Michal Fratczak 2020-03-29 22:02:01 +02:00
rodzic 2de1b3b8a0
commit 6e84c7d119
3 zmienionych plików z 34 dodań i 31 usunięć

Wyświetl plik

@ -2,12 +2,37 @@
#include "ublox.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <cstring>
#include <memory>
#include <iostream>
int uBLOX_i2c_open(const std::string i_device, const unsigned char addr) //"/dev/i2c-7", 0x42
{
using namespace std;
int file_i2c;
if ((file_i2c = open(i_device.c_str(), O_RDWR)) < 0)
{
cerr << "Failed to open the i2c bus " << i_device << endl;
return 0;
}
if (ioctl(file_i2c, I2C_SLAVE, addr) < 0)
{
cerr << "Failed to acquire bus access and/or talk to slave Address: " << addr << endl;
return 0;
}
return file_i2c;
}
// read char from file descriptor
// and returns a std:string message (anything between 255 or /n characters)
// sometimes returns just \n
@ -143,3 +168,6 @@ std::string vec2str(std::vector<char> v)
delete [] buff;
return res;
}

Wyświetl plik

@ -5,6 +5,10 @@
#include <vector>
#include <string>
#include <unistd.h> // write()
int uBLOX_i2c_open(const std::string i_device, const unsigned char addr); // "/dev/i2c-7", 0x42
// read char from file descriptor
// and returns a std:string message (anything between 255 or /n characters);
// sometimes returns just \n
@ -16,3 +20,4 @@ std::vector<char> uBLOX_read_msg(int fd, int usec_sleep = 3e5);
bool uBLOX_write_msg_ack(int fd, uint8_t* p_msg, size_t msg_sz, const size_t wait = 10);
std::string vec2str(std::vector<char> v);

Wyświetl plik

@ -1,11 +1,4 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <math.h>
#include <cstring>
#include <string>
#include <iostream>
@ -14,34 +7,11 @@
#include "nmea/nmea.h"
int OpenI2C(const std::string i_device = "/dev/i2c-7", const unsigned char addr = 0x42)
{
using namespace std;
int file_i2c;
if ((file_i2c = open(i_device.c_str(), O_RDWR)) < 0)
{
cerr << "Failed to open the i2c bus " << i_device << endl;
return 0;
}
if (ioctl(file_i2c, I2C_SLAVE, addr) < 0)
{
cerr << "Failed to acquire bus access and/or talk to slave Address: " << addr << endl;
return 0;
}
return file_i2c;
}
void ublox_test_i2c(void)
{
using namespace std;
int file_i2c = OpenI2C();
int file_i2c = uBLOX_i2c_open( "/dev/i2c-7", 0x42 );
if (!file_i2c)
{
cerr << "Failed opening I2C" << endl;