msg_num CLI. baud_t : int.

master
Michal Fratczak 2020-04-11 13:53:04 +02:00
rodzic 6ac52b3605
commit a5e62ece6a
4 zmienionych plików z 57 dodań i 41 usunięć

Wyświetl plik

@ -28,10 +28,10 @@ public:
struct cli_t // command line interface options
{
std::string callsign;
float freqMHz = 0; //MegaHertz
baud_t baud = baud_t::kInvalid;
std::string ssdv_image; // ssdv encoded image path
float freqMHz = 0; //MegaHertz
baud_t baud = baud_t::kInvalid;
std::string ssdv_image; // ssdv encoded image path
int msg_num = 1; // number of telemetry sentences emitted between SSDV packets
// hardware config
int hw_pin_radio_on = 0; // gpio numbered pin for radio enable. current board: 22

Wyświetl plik

@ -22,6 +22,7 @@ void CLI(int ac, char* av[])
("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 path")
("msg_num", po::value<int>(), "number of telemetry sentences emitted between SSDV packets")
("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")
@ -69,6 +70,10 @@ void CLI(int ac, char* av[])
{
GLOB::get().cli.freqMHz = vm["freq"].as<float>();
}
if (vm.count("msg_num"))
{
GLOB::get().cli.msg_num = vm["msg_num"].as<int>();
}
if (vm.count("hw_pin_radio_on"))
{
GLOB::get().cli.hw_pin_radio_on = vm["hw_pin_radio_on"].as<int>();

Wyświetl plik

@ -63,8 +63,7 @@ std::string CRC(std::string i_str)
zmq::message_t make_zmq_reply(const std::string& i_msg_str)
{
if(i_msg_str == "nmea") {
nmea_t nmea = GLOB::get().nmea_get();
std::string reply_str( nmea.str() );
const std::string reply_str( GLOB::get().nmea_get().str() );
zmq::message_t reply( reply_str.size() );
memcpy( (void*) reply.data(), reply_str.c_str(), reply_str.size() );
return reply;
@ -216,71 +215,82 @@ int main1(int argc, char** argv)
std::thread zmq_thread( [&zmq_socket]() {
while(G_RUN) {
zmq::message_t msg;
zmq_socket.recv(msg);
auto res = zmq_socket.recv(msg); // using recv_result_t = std::optional<size_t>;
if(!res.has_value())
continue;
string msg_str( (char*)msg.data(), msg.size() );
std::cout<<"ZMQ msg: "<<msg_str<<std::endl;
zmq_socket.send( make_zmq_reply(msg_str) );
zmq_socket.send( make_zmq_reply(msg_str), zmq::send_flags::none );
}
});
// READ SENSORS, CONSTRUCT TELEMETRY MESSAGE, RF SEND TEMEMETRY AND IMAGE
//
nmea_t valid_nmea;
ssdv_t ssdv_data;
int msg_num = 0;
int msg_id = 0;
while(G_RUN)
{
++msg_num;
for(int i=0; i<G.cli.msg_num; ++i)
{
++msg_id;
// ds18b20
//
GLOB::get().temperature = read_temp_from_ds18b20(ds18b20_device);
// ds18b20
//
GLOB::get().temperature = read_temp_from_ds18b20(ds18b20_device);
nmea_t current_nmea = G.nmea_get();
const bool gps_fix_valid =
current_nmea.fix_status == nmea_t::fix_status_t::kValid
&& current_nmea.fix_quality != nmea_t::fix_quality_t::kNoFix;
if(gps_fix_valid)
valid_nmea = current_nmea;
nmea_t current_nmea = G.nmea_get();
const bool gps_fix_valid =
current_nmea.fix_status == nmea_t::fix_status_t::kValid
&& current_nmea.fix_quality != nmea_t::fix_quality_t::kNoFix;
if(gps_fix_valid)
valid_nmea = current_nmea;
// telemetry message
//
stringstream msg_stream;
msg_stream<<G.cli.callsign;
msg_stream<<","<<msg_num;
msg_stream<<","<<valid_nmea.utc;
msg_stream<<","<<valid_nmea.lat<<","<<valid_nmea.lon<<","<<valid_nmea.alt;
msg_stream<<","<<valid_nmea.sats<<","<<gps_fix_valid;
// msg_stream<<","<<"05231.4567"<<","<<"2117.8412"<<","<<valid_nmea.alt; // example NMEA format
msg_stream<<","<<setprecision(1)<<fixed<<GLOB::get().temperature;
// telemetry message
//
stringstream msg_stream;
msg_stream<<G.cli.callsign;
msg_stream<<","<<msg_id;
msg_stream<<","<<valid_nmea.utc;
msg_stream<<","<<valid_nmea.lat<<","<<valid_nmea.lon<<","<<valid_nmea.alt;
msg_stream<<","<<valid_nmea.sats<<","<<gps_fix_valid;
// msg_stream<<","<<"05231.4567"<<","<<"2117.8412"<<","<<valid_nmea.alt; // example NMEA format
msg_stream<<","<<setprecision(1)<<fixed<<GLOB::get().temperature;
const string msg_and_crc = string("\0",1) + "$$$" + msg_stream.str() + '*' + CRC(msg_stream.str());
cout<<msg_and_crc<<endl;
const string msg_and_crc = string("\0",1) + "$$$" + msg_stream.str() + '*' + CRC(msg_stream.str());
cout<<msg_and_crc<<endl;
// emit telemetry msg RF
//
mtx2_write(radio_fd, msg_and_crc + '\n');
// emit telemetry msg RF
//
mtx2_write(radio_fd, msg_and_crc + '\n');
}
// SSDV image
// send SSDV image next packet
//
if( G.cli.ssdv_image.size() && !ssdv_data.size() )
cout<<"SSDV loaded "<<ssdv_data.load_file( G.cli.ssdv_image )<<" tiles"<<endl;
if( ssdv_data.size() )
{
const ssdv_t::tile_t tile = ssdv_data.next_tile();
// delete image after send
if(!ssdv_data.size()) {
cout<<(string("rm -f ") + G.cli.ssdv_image)<<endl;
auto tile = ssdv_data.next_tile();
if(!ssdv_data.size()) // delete image after send
system( (string("rm -f ") + G.cli.ssdv_image).c_str() );
}
mtx2_write( radio_fd, tile.data(), sizeof(tile) );
}
}
// RELEASE RESOURCES
//
cout<<"Closing uBlox"<<endl;
ublox_thread.join();
close(uBlox_i2c_fd);
cout<<"Closing UART"<<endl;
close(radio_fd);
gpioWrite (G.cli.hw_pin_radio_on, 0);
cout<<"Closing gpio"<<endl;
gpioTerminate();
cout<<"Closing zmq"<<endl;
zmq_thread.join(); // will return after next received message, or stuck forever if no messages come in
return 0;
}

Wyświetl plik

@ -2,7 +2,8 @@
#include <string>
enum class baud_t {
enum class baud_t : int
{
kInvalid = 0,
k50 = 50,
k75 = 75,