Michal Fratczak 2020-04-09 18:42:43 +02:00
rodzic 7b0579e6d1
commit 8aab69ecaf
8 zmienionych plików z 252 dodań i 38 usunięć

Wyświetl plik

@ -1,7 +1,14 @@
set ( Boost_USE_STATIC_LIBS ON )
find_package(Boost REQUIRED COMPONENTS program_options )
include_directories( ${Boost_INCLUDE_DIRS} )
set (tracker_src
main.cpp
GLOB.h GLOB.cpp
cli.h cli.cpp
ssdv_t.cpp
main.cpp
../mtx2/mtx2.cpp
../nmea/nmea.cpp
../ublox/ublox_cmds.cpp
@ -13,4 +20,4 @@ include_directories( ${CMAKE_SOURCE_DIR} )
add_executable( tracker ${tracker_src})
target_link_libraries( tracker "pigpio" )
target_link_libraries( tracker "pigpio" ${Boost_LIBRARIES} )

Wyświetl plik

@ -0,0 +1,17 @@
#include "GLOB.h"
#include <sstream>
std::string GLOB::str() const
{
std::stringstream s;
s<<"callsign="<<cli.callsign<<"\n";
s<<"freqMHz="<<cli.freqMHz<<"\n";
s<<"baud="<<baud_t_to_int(cli.baud)<<"\n";
s<<"hw_pin_radio_on="<<cli.hw_pin_radio_on<<"\n";
s<<"hw_radio_serial="<<cli.hw_radio_serial<<"\n";
s<<"hw_ublox_device="<<cli.hw_ublox_device<<"\n";
return s.str();
}

Wyświetl plik

@ -0,0 +1,38 @@
#pragma once
#include <string>
#include "../mtx2/mtx2.h"
// global options - singleton
class GLOB
{
private:
GLOB() {};
GLOB( const GLOB& ) = delete; // non construction-copyable
GLOB& operator=( const GLOB& ) = delete; // non copyable
public:
static GLOB& get()
{
static GLOB g;
return g;
}
struct cli_t // command line interface options
{
std::string callsign;
float freqMHz = 0; //MegaHertz
baud_t baud = baud_t::kInvalid;
// hardware config
int hw_pin_radio_on = 0; // gpio numbered pin for radio enable. current board: 22
std::string hw_radio_serial; // serial device for MTX2 radio. for rPI4: /dev/serial0
std::string hw_ublox_device; // I2C device for uBLOX. for rPI4: /dev/i2c-7
};
cli_t cli;
std::string str() const;
};

Wyświetl plik

@ -0,0 +1,95 @@
#include "cli.h"
#include <string>
#include <iostream>
#include <fstream>
#include "glob.h"
#include <boost/program_options.hpp>
void CLI(int ac, char* av[])
{
namespace po = boost::program_options;
using namespace std;
try
{
po::options_description generic("Command Line Interface options");
generic.add_options()
("help", "Display help message")
("callsign",po::value<string>(), "callsign")
("freq", po::value<float>(), "frequency in MHz")
("baud", po::value<int>(), "baud: 50, 150, 200, 300, 600, 1200")
("ssdv", po::value<string>(), "SSDV encoded image")
("hw_pin_radio_on", po::value<int>(), "gpio numbered pin for radio enable. current board: 22")
("hw_radio_serial", po::value<string>(), "serial device for MTX2 radio. for rPI4: /dev/serial0")
("hw_ublox_device", po::value<string>(), "I2C device for uBLOX. for rPI4: /dev/i2c-7")
;
po::options_description cli_options("Command Line Interface options");
cli_options.add(generic);
string config_file;
cli_options.add_options()
("config", po::value<string>(&config_file), "config file");
po::options_description file_options;
file_options.add(generic);
po::variables_map vm;
store( po::command_line_parser(ac, av).options(cli_options).allow_unregistered().run(), vm );
notify(vm);
if(vm.count("config"))
{
const string config_file = vm["config"].as<string>();
ifstream ifs(config_file.c_str());
if (!ifs)
{
cout << "Can not open config file: " << config_file << endl;
}
else
{
cout<<"Reading config from file "<<config_file<<endl;
store(parse_config_file(ifs, file_options, 1), vm);
notify(vm);
}
}
if(vm.count("help"))
{
cout<<cli_options<<endl;
exit(0);
}
if (vm.count("callsign"))
{
GLOB::get().cli.callsign = vm["callsign"].as<string>();
}
if (vm.count("freq"))
{
GLOB::get().cli.freqMHz = vm["freq"].as<float>();
}
if (vm.count("hw_pin_radio_on"))
{
GLOB::get().cli.hw_pin_radio_on = vm["hw_pin_radio_on"].as<int>();
}
if (vm.count("hw_radio_serial"))
{
GLOB::get().cli.hw_radio_serial = vm["hw_radio_serial"].as<string>();
}
if (vm.count("hw_ublox_device"))
{
GLOB::get().cli.hw_ublox_device = vm["hw_ublox_device"].as<string>();
}
if (vm.count("baud"))
{
GLOB::get().cli.baud = baud_t_from_int(vm["baud"].as<int>());
}
}
catch(exception& e)
{
cerr<<"CLI ERROR:\n\t";
cerr<<e.what()<<endl;
exit(1);
}
}

Wyświetl plik

@ -0,0 +1,5 @@
#pragma once
// command line interface options
void CLI(int ac, char* av[]);

Wyświetl plik

@ -15,9 +15,10 @@
#include "ds18b20/ds18b20.h"
#include "ssdv_t.h"
#include "cli.h"
#include "GLOB.h"
const unsigned int GPIOPIN_MTX2_EN_gpio = 22;
int radio_fd = 0;
@ -58,7 +59,7 @@ std::string CRC(std::string i_str)
void CTRL_C(int sig)
{
gpioWrite(GPIOPIN_MTX2_EN_gpio, 0);
gpioWrite(GLOB::get().cli.hw_pin_radio_on, 0);
close(radio_fd);
gpioTerminate();
exit(0);
@ -69,6 +70,41 @@ int main1(int argc, char** argv)
{
using namespace std;
CLI(argc, argv); // command line interface
auto& G = GLOB::get();
if( !G.cli.callsign.size() ) {
cerr<<"ERROR:\n\tNo Callsign."<<endl;
return 1;
}
if( !G.cli.freqMHz ) {
cerr<<"ERROR:\n\tNo frequency."<<endl;
return 1;
}
if(G.cli.baud == baud_t::kInvalid) {
cerr<<"ERROR:\n\tNo baud."<<endl;
return 1;
}
if( !G.cli.hw_pin_radio_on ) {
cerr<<"ERROR:\n\tNo hw_pin_radio_on."<<endl;
return 1;
}
if( !G.cli.hw_radio_serial.size() ) {
cerr<<"ERROR:\n\tNo hw_radio_serial."<<endl;
return 1;
}
if( !G.cli.hw_ublox_device.size() ) {
cerr<<"ERROR:\n\tNo hw_ublox_device."<<endl;
return 1;
}
cout<<G.str()<<endl;
signal(SIGINT, CTRL_C);
signal(SIGTERM, CTRL_C);
@ -82,27 +118,25 @@ int main1(int argc, char** argv)
// RADIO
//
gpioSetPullUpDown(GPIOPIN_MTX2_EN_gpio, PI_PUD_DOWN);
gpioSetMode(GPIOPIN_MTX2_EN_gpio, PI_OUTPUT);
gpioWrite (GPIOPIN_MTX2_EN_gpio, 1);
mtx2_set_frequency(GPIOPIN_MTX2_EN_gpio, 434.50f);
radio_fd = mtx2_open("/dev/serial0", baud_t::k300);
if (!radio_fd)
gpioSetPullUpDown( G.cli.hw_pin_radio_on, PI_PUD_DOWN );
gpioSetMode( G.cli.hw_pin_radio_on, PI_OUTPUT );
gpioWrite ( G.cli.hw_pin_radio_on, 1 );
mtx2_set_frequency( G.cli.hw_pin_radio_on, G.cli.freqMHz );
radio_fd = mtx2_open( G.cli.hw_radio_serial, G.cli.baud );
if (radio_fd < 1)
{
cerr<<"Failed opening radio UART /dev/serial0"<<endl;
cerr<<"Failed opening radio UART "<<G.cli.hw_radio_serial<<endl;
return 1;
}
cout<<"Radio FD "<<radio_fd<<endl;
// uBLOX I2C
//
int uBlox_i2c_fd = uBLOX_i2c_open( "/dev/i2c-7", 0x42 );
int uBlox_i2c_fd = uBLOX_i2c_open( G.cli.hw_ublox_device, 0x42 );
if (!uBlox_i2c_fd)
{
cerr<<"Failed opening I2C /dev/i2c-7 0x42"<<endl;
cerr<<"Failed opening I2C "<<G.cli.hw_ublox_device<<" 0x42"<<endl;
return 1;
}
cout<<"uBLOX I2C FD "<<uBlox_i2c_fd<<endl;
write(uBlox_i2c_fd, UBX_CMD_EnableOutput_ACK_ACK, sizeof(UBX_CMD_EnableOutput_ACK_ACK));
write(uBlox_i2c_fd, UBX_CMD_EnableOutput_ACK_NAK, sizeof(UBX_CMD_EnableOutput_ACK_NAK));
sleep(3);
@ -154,7 +188,7 @@ int main1(int argc, char** argv)
//
stringstream msg_stream;
// msg_stream<<nmea;
msg_stream<<"not-a-real-flight";
msg_stream<<G.cli.callsign;
msg_stream<<","<<msg_num;
msg_stream<<","<<nmea.utc;
msg_stream<<","<<nmea.lat<<","<<nmea.lon<<","<<nmea.alt;
@ -182,35 +216,14 @@ int main1(int argc, char** argv)
close(uBlox_i2c_fd);
close(radio_fd);
gpioWrite (GPIOPIN_MTX2_EN_gpio, 0);
gpioWrite (G.cli.hw_pin_radio_on, 0);
gpioTerminate();
return 0;
}
int test_ssdv(int argc, char** argv)
{
using namespace std;
string fname(argv[1]);
ssdv_t ssdv_data;
const size_t num_tiles = ssdv_data.load_file(fname);
cout<<"num_tiles: "<<num_tiles<<endl;
while( ssdv_data.size() )
{
const ssdv_t::tile_t tile = ssdv_data.next_tile();
string data(tile.data(), sizeof(tile));
cout<<data<<endl;
}
return 0;
}
int main(int argc, char** argv)
{
// return test_ssdv(argc, argv);
return main1(argc, argv);
}

Wyświetl plik

@ -135,3 +135,39 @@ void mtx2_set_frequency(const int mtx2_enable_pin_gpio, const float freq_Mhz) //
}
}
int baud_t_to_int(const baud_t& baud)
{
switch (baud)
{
case baud_t::k50: return 50;
case baud_t::k75: return 75;
case baud_t::k150: return 150;
case baud_t::k200: return 200;
case baud_t::k300: return 300;
case baud_t::k600: return 600;
case baud_t::k1200: return 1200;
case baud_t::k4800: return 4800;
case baud_t::k9600: return 9600;
}
return 0;
}
baud_t baud_t_from_int(const int baud)
{
switch (baud)
{
case 50: return baud_t::k50;
case 75: return baud_t::k75;
case 150: return baud_t::k150;
case 200: return baud_t::k200;
case 300: return baud_t::k300;
case 600: return baud_t::k600;
case 1200: return baud_t::k1200;
case 4800: return baud_t::k4800;
case 9600: return baud_t::k9600;
}
return baud_t::kInvalid;
}

Wyświetl plik

@ -24,3 +24,6 @@ int mtx2_write(const int serial_file_descriptor, const std::string& msg);
// will open and close i_device
// void mtx2_set_frequency(const std::string i_device, const float freq_Mhz); // 434.250
void mtx2_set_frequency(const int mtx2_enable_pin, const float freq_Mhz); // 434.250
int baud_t_to_int(const baud_t&);
baud_t baud_t_from_int(const int);