kopia lustrzana https://github.com/ogre/pizero_tracker
Initial ZeroMQ. Private GLOB::nmea
rodzic
2be53f1198
commit
2518d8b96e
|
@ -14,3 +14,8 @@ dtparam=i2c=off
|
|||
#dtoverlay=i2c-gpio,bus=1,i2c_gpio_sda=2,i2c_gpio_scl=3
|
||||
dtoverlay=i2c-gpio,i2c_gpio_sda=2,i2c_gpio_scl=3
|
||||
```
|
||||
|
||||
|
||||
dependencies
|
||||
boost program_options
|
||||
https://github.com/zeromq/cppzmq/
|
|
@ -1,9 +1,12 @@
|
|||
|
||||
|
||||
set ( Boost_USE_STATIC_LIBS ON )
|
||||
find_package(Boost REQUIRED COMPONENTS program_options )
|
||||
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||
|
||||
# https://github.com/zeromq/cppzmq/
|
||||
#find cppzmq wrapper, installed by make of cppzmq
|
||||
find_package(cppzmq)
|
||||
|
||||
set (tracker_src
|
||||
GLOB.h GLOB.cpp
|
||||
cli.h cli.cpp
|
||||
|
@ -20,4 +23,4 @@ include_directories( ${CMAKE_SOURCE_DIR} )
|
|||
|
||||
add_executable( tracker ${tracker_src})
|
||||
|
||||
target_link_libraries( tracker pthread atomic pigpio ${Boost_LIBRARIES} )
|
||||
target_link_libraries( tracker pthread atomic pigpio cppzmq ${Boost_LIBRARIES} )
|
||||
|
|
|
@ -15,6 +15,9 @@ private:
|
|||
GLOB( const GLOB& ) = delete; // non construction-copyable
|
||||
GLOB& operator=( const GLOB& ) = delete; // non copyable
|
||||
|
||||
std::atomic<nmea_t> nmea; // GPS data
|
||||
|
||||
|
||||
public:
|
||||
static GLOB& get()
|
||||
{
|
||||
|
@ -37,8 +40,9 @@ public:
|
|||
};
|
||||
|
||||
cli_t cli;
|
||||
std::atomic<nmea_t> nmea; // GPS data
|
||||
|
||||
nmea_t nmea_get() { nmea_t ret = get().nmea; return ret; }
|
||||
void nmea_set(const nmea_t& in_nmea) { get().nmea = in_nmea; }
|
||||
std::string str() const;
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -96,4 +96,4 @@ void CLI(int ac, char* av[])
|
|||
cerr<<e.what()<<endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
// command line interface options
|
||||
|
||||
void CLI(int ac, char* av[]);
|
||||
void CLI(int ac, char* av[]);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <thread>
|
||||
|
||||
#include "pigpio.h"
|
||||
#include <zmq.hpp>
|
||||
|
||||
#include "mtx2/mtx2.h"
|
||||
#include "nmea/nmea.h"
|
||||
|
@ -168,7 +169,7 @@ int main1(int argc, char** argv)
|
|||
continue;
|
||||
}
|
||||
NMEA_parse( nmea_str.c_str(), nmea );
|
||||
GLOB::get().nmea = nmea; //update nmea with this message info
|
||||
GLOB::get().nmea_set(nmea); //update nmea with this message info
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -184,6 +185,32 @@ int main1(int argc, char** argv)
|
|||
cout<<"ds18b20_device "<<ds18b20_device<<endl;
|
||||
|
||||
|
||||
// ZeroMQ server
|
||||
zmq::context_t zmq_context(1);
|
||||
zmq::socket_t zmq_socket(zmq_context, ZMQ_REP);
|
||||
zmq_socket.bind ( string("tcp://*:6666").c_str() );
|
||||
std::thread zmq_thread( [&zmq_socket]() {
|
||||
while(G_RUN) {
|
||||
zmq::message_t msg;
|
||||
zmq_socket.recv(msg);
|
||||
string msg_str( (char*)msg.data(), msg.size() );
|
||||
std::cout<<"ZMQ msg: "<<msg_str<<std::endl;
|
||||
if(msg_str == "nmea") {
|
||||
nmea_t nmea = GLOB::get().nmea_get();
|
||||
string nmea_str( nmea.str() );
|
||||
zmq::message_t reply( nmea_str.size() );
|
||||
memcpy( (void*) reply.data(), nmea_str.c_str(), nmea_str.size() );
|
||||
zmq_socket.send(reply);
|
||||
}
|
||||
else {
|
||||
zmq::message_t reply( 7 );
|
||||
memcpy( (void*) reply.data(), "UNKNOWN", 7 );
|
||||
zmq_socket.send(reply);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
nmea_t valid_nmea;
|
||||
ssdv_t ssdv_data;
|
||||
int msg_num = 0;
|
||||
|
@ -195,7 +222,7 @@ int main1(int argc, char** argv)
|
|||
//
|
||||
const float temperature_cels = read_temp_from_ds18b20(ds18b20_device);
|
||||
|
||||
nmea_t current_nmea = G.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;
|
||||
|
|
|
@ -17,4 +17,4 @@ public:
|
|||
private:
|
||||
std::deque<tile_t> tiles_que_;
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import time
|
||||
import zmq
|
||||
|
||||
def main():
|
||||
|
||||
context = zmq.Context(1)
|
||||
socket = context.socket(zmq.REQ)
|
||||
socket.connect( 'tcp://192.168.1.22:6666' )
|
||||
|
||||
while True:
|
||||
socket.send('nmea')
|
||||
msg = socket.recv()
|
||||
print msg
|
||||
time.sleep(1)
|
||||
|
||||
socket.send('nmeaX')
|
||||
msg = socket.recv()
|
||||
print msg
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
while(1):
|
||||
pass
|
|
@ -170,4 +170,4 @@ baud_t baud_t_from_int(const int baud)
|
|||
case 9600: return baud_t::k9600;
|
||||
}
|
||||
return baud_t::kInvalid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,4 +26,4 @@ int mtx2_write(const int serial_file_descriptor, const std::string& msg);
|
|||
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);
|
||||
baud_t baud_t_from_int(const int);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <math.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace
|
||||
|
@ -236,37 +237,39 @@ bool NMEA_parse(const char* Buffer, nmea_t& o_nmea)
|
|||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const nmea_t& nmea)
|
||||
std::string nmea_t::str() const
|
||||
{
|
||||
std::string ws(" ");
|
||||
s<<"utc:"<<nmea.utc<<ws;
|
||||
std::stringstream s;
|
||||
std::string ws(",");
|
||||
|
||||
s<<"lat:"<<nmea.lat<<ws;
|
||||
s<<"lon:"<<nmea.lon<<ws;
|
||||
s<<"alt:"<<nmea.alt<<ws;
|
||||
s<<"utc:"<<utc<<ws;
|
||||
|
||||
s<<"speed_over_ground_mps:"<<nmea.speed_over_ground_mps<<ws;
|
||||
s<<"course_over_ground_deg:"<<nmea.course_over_ground_deg<<ws;
|
||||
s<<"lat:"<<lat<<ws;
|
||||
s<<"lon:"<<lon<<ws;
|
||||
s<<"alt:"<<alt<<ws;
|
||||
|
||||
s<<"sats:"<<nmea.sats<<ws;
|
||||
s<<"speed_over_ground_mps:"<<speed_over_ground_mps<<ws;
|
||||
s<<"course_over_ground_deg:"<<course_over_ground_deg<<ws;
|
||||
|
||||
if(nmea.fix_status == nmea_t::fix_status_t::kValid)
|
||||
s<<"sats:"<<sats<<ws;
|
||||
|
||||
if(fix_status == nmea_t::fix_status_t::kValid)
|
||||
s<<"VALID"<<ws;
|
||||
else if(nmea.fix_status == nmea_t::fix_status_t::kInvalid)
|
||||
else if(fix_status == nmea_t::fix_status_t::kInvalid)
|
||||
s<<"INVALID"<<ws;
|
||||
|
||||
if( nmea.fix_quality == nmea_t::fix_quality_t::kNoFix )
|
||||
s<<"Q:kNoFix"<<ws;
|
||||
else if( nmea.fix_quality == nmea_t::fix_quality_t::kAutonomous )
|
||||
s<<"Q:kAutonomous"<<ws;
|
||||
else if( nmea.fix_quality == nmea_t::fix_quality_t::kDifferential )
|
||||
s<<"Q:kDifferential"<<ws;
|
||||
else if( nmea.fix_quality == nmea_t::fix_quality_t::kRtkFixed )
|
||||
s<<"Q:kRtkFixed"<<ws;
|
||||
else if( nmea.fix_quality == nmea_t::fix_quality_t::kRtkFloat )
|
||||
s<<"Q:kRtkFloat"<<ws;
|
||||
else if( nmea.fix_quality == nmea_t::fix_quality_t::kEstimated )
|
||||
s<<"Q:kEstimated"<<ws;
|
||||
if( fix_quality == nmea_t::fix_quality_t::kNoFix )
|
||||
s<<"Q:kNoFix";
|
||||
else if( fix_quality == nmea_t::fix_quality_t::kAutonomous )
|
||||
s<<"Q:kAutonomous";
|
||||
else if( fix_quality == nmea_t::fix_quality_t::kDifferential )
|
||||
s<<"Q:kDifferential";
|
||||
else if( fix_quality == nmea_t::fix_quality_t::kRtkFixed )
|
||||
s<<"Q:kRtkFixed";
|
||||
else if( fix_quality == nmea_t::fix_quality_t::kRtkFloat )
|
||||
s<<"Q:kRtkFloat";
|
||||
else if( fix_quality == nmea_t::fix_quality_t::kEstimated )
|
||||
s<<"Q:kEstimated";
|
||||
|
||||
return s;
|
||||
return s.str();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
kEstimated = 6
|
||||
};
|
||||
fix_quality_t fix_quality = fix_quality_t::kNoFix;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -56,5 +59,3 @@ std::string NMEA_get_last_msg(const char *buff, const size_t buff_sz);
|
|||
std::string NMEA_get_last_msg(const std::string& msg);
|
||||
|
||||
bool NMEA_parse(const char *Buffer, nmea_t& o_nmea);
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const nmea_t& nmea);
|
||||
|
|
|
@ -36,5 +36,4 @@ int main()
|
|||
else
|
||||
cout<<"nmea msg not found"<<endl;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ set (ublox_test_i2c_src
|
|||
|
||||
include_directories( ${CMAKE_SOURCE_DIR} )
|
||||
|
||||
add_executable( ublox_test_i2c ${ublox_test_i2c_src})
|
||||
add_executable( ublox_test_i2c ${ublox_test_i2c_src})
|
||||
|
|
|
@ -153,4 +153,3 @@ std::string vec2str(std::vector<char> v)
|
|||
delete [] buff;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,4 +20,3 @@ 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);
|
||||
|
||||
|
|
|
@ -151,4 +151,3 @@ bool UBX_PACKET_EQ(const std::vector<char>& i_data, const uint8_t* p_ref, const
|
|||
return false;
|
||||
return UBX_PACKET_EQ( (uint8_t*) i_data.data(), p_ref, ref_sz );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,4 +31,3 @@ void UBX_MAKE_PACKET_NAK(const uint8_t i_class, const uint8_t i_id, uint8_t* o_c
|
|||
bool UBX_PACKET_EQ(uint8_t* i_data, const uint8_t* p_ref, const size_t ref_sz);
|
||||
|
||||
bool UBX_PACKET_EQ(const std::vector<char>& i_data, const uint8_t* p_ref, const size_t ref_sz);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue