kopia lustrzana https://github.com/ogre/pizero_tracker
example SSDV send
rodzic
66095febb5
commit
7e32808d8b
|
@ -1,6 +1,7 @@
|
|||
|
||||
set (tracker_src
|
||||
main.cpp
|
||||
ssdv_t.cpp
|
||||
../mtx2/mtx2.cpp
|
||||
../nmea/nmea.cpp
|
||||
../ublox/ublox_cmds.cpp
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "ublox/ublox.h"
|
||||
#include "ds18b20/ds18b20.h"
|
||||
|
||||
#include "ssdv_t.h"
|
||||
|
||||
|
||||
const unsigned int GPIOPIN_MTX2_EN_gpio = 22;
|
||||
int radio_fd = 0;
|
||||
|
@ -63,7 +65,7 @@ void CTRL_C(int sig)
|
|||
}
|
||||
|
||||
|
||||
int main1()
|
||||
int main1(int argc, char** argv)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
@ -122,7 +124,9 @@ int main1()
|
|||
}
|
||||
cout<<"ds18b20_device "<<ds18b20_device<<endl;
|
||||
|
||||
|
||||
nmea_t nmea; // parsed GPS data
|
||||
ssdv_t ssdv_data;
|
||||
int msg_num = 0;
|
||||
while(true)
|
||||
{
|
||||
|
@ -146,6 +150,8 @@ int main1()
|
|||
//
|
||||
const float temperature_cels = read_temp_from_ds18b20(ds18b20_device);
|
||||
|
||||
// telemetry message
|
||||
//
|
||||
stringstream msg_stream;
|
||||
// msg_stream<<nmea;
|
||||
msg_stream<<"not-a-real-flight";
|
||||
|
@ -159,9 +165,19 @@ int main1()
|
|||
const string msg_and_crc = string("\0",1) + "$$$" + msg_stream.str() + '*' + CRC(msg_stream.str());
|
||||
cout<<msg_and_crc<<endl;
|
||||
|
||||
// emit RF
|
||||
// emit telemetry msg RF
|
||||
//
|
||||
mtx2_write(radio_fd, msg_and_crc + '\n');
|
||||
|
||||
// SSDV image
|
||||
//
|
||||
if( argc > 1 && !ssdv_data.size() )
|
||||
ssdv_data.load_file(argv[1]);
|
||||
if( ssdv_data.size() )
|
||||
{
|
||||
const ssdv_t::tile_t tile = ssdv_data.next_tile();
|
||||
mtx2_write( radio_fd, tile.data(), sizeof(tile) );
|
||||
}
|
||||
}
|
||||
|
||||
close(uBlox_i2c_fd);
|
||||
|
@ -172,8 +188,29 @@ int main1()
|
|||
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 main1();
|
||||
// return test_ssdv(argc, argv);
|
||||
return main1(argc, argv);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include "ssdv_t.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
size_t ssdv_t::load_file(const std::string file_path)
|
||||
{
|
||||
FILE* p_file = fopen(file_path.c_str(), "rb");
|
||||
if(!p_file)
|
||||
return 0;
|
||||
|
||||
tile_t tile;
|
||||
size_t total_tiles = 0;
|
||||
while(1)
|
||||
{
|
||||
const size_t read_bytes = fread( tile.data(), sizeof(char), 256, p_file );
|
||||
if(!read_bytes)
|
||||
return total_tiles;
|
||||
tiles_que_.push_back(tile);
|
||||
++total_tiles;
|
||||
}
|
||||
}
|
||||
|
||||
ssdv_t::tile_t ssdv_t::next_tile()
|
||||
{
|
||||
tile_t tile = tiles_que_.front();
|
||||
tiles_que_.pop_front();
|
||||
return tile;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <deque>
|
||||
|
||||
// load SSDV encoded files and keep as stack of 256 bytes tiles
|
||||
class ssdv_t
|
||||
{
|
||||
|
||||
public:
|
||||
using tile_t = std::array<char, 256>;
|
||||
bool size() const { return tiles_que_.size(); }
|
||||
size_t load_file(const std::string file_path);
|
||||
tile_t next_tile();
|
||||
|
||||
private:
|
||||
std::deque<tile_t> tiles_que_;
|
||||
|
||||
};
|
Ładowanie…
Reference in New Issue