#include // write() #include #include #include #include #include #include #include #include "pigpio.h" #include #include "mtx2/mtx2.h" #include "nmea/nmea.h" #include "ublox/ublox_cmds.h" #include "ublox/ublox.h" #include "ds18b20/ds18b20.h" #include "ssdv_t.h" #include "cli.h" #include "GLOB.h" const char* C_RED = "\033[1;31m"; const char* C_GREEN = "\033[1;32m"; const char* C_MAGENTA = "\033[1;35m"; const char* C_OFF = "\033[0m"; bool G_RUN = true; // keep threads running char _hex(char Character) { char _hexTable[] = "0123456789ABCDEF"; return _hexTable[int(Character)]; } // UKHAS Sentence CRC std::string CRC(std::string i_str) { using std::string; unsigned int CRC = 0xffff; // unsigned int xPolynomial = 0x1021; for (size_t i = 0; i < i_str.length(); i++) { CRC ^= (((unsigned int)i_str[i]) << 8); for (int j=0; j<8; j++) { if (CRC & 0x8000) CRC = (CRC << 1) ^ 0x1021; else CRC <<= 1; } } string result; result += _hex((CRC >> 12) & 15); result += _hex((CRC >> 8) & 15); result += _hex((CRC >> 4) & 15); result += _hex(CRC & 15); return result; } zmq::message_t make_zmq_reply(const std::string& i_msg_str) { auto& G = GLOB::get(); if(i_msg_str == "nmea") { std::string reply_str = G.nmea_get().json(); reply_str.pop_back(); reply_str += ",'fixAge':" + std::to_string(G.gps_fix_age()) + "}"; zmq::message_t reply( reply_str.size() ); memcpy( (void*) reply.data(), reply_str.c_str(), reply_str.size() ); return reply; } else if(i_msg_str == "dynamics") { std::string reply_str("{"); for(auto& dyn_name : G.dynamics_keys()) reply_str += "'" + dyn_name + "':" + G.dynamics_get(dyn_name).json() + ","; reply_str.pop_back(); // last comma reply_str += "}"; zmq::message_t reply( reply_str.size() ); memcpy( (void*) reply.data(), reply_str.c_str(), reply_str.size() ); return reply; } else { zmq::message_t reply( 7 ); memcpy( (void*) reply.data(), "UNKNOWN", 7 ); return reply; } } void CTRL_C(int sig) { std::cout<<"CTRL+C"< ublox_data = uBLOX_read_msg(uBlox_i2c_fd); // typical blocking time: 0/1/1.2 seconds const string nmea_str = NMEA_get_last_msg(ublox_data.data(), ublox_data.size()); // cout<; if(!res.has_value()) continue; string msg_str( (char*)msg.data(), msg.size() ); zmq_socket.send( make_zmq_reply(msg_str), zmq::send_flags::none ); } }); // READ SENSORS, CONSTRUCT TELEMETRY MESSAGE, RF SEND TELEMETRY AND IMAGE // ssdv_t ssdv_tiles; int msg_id = 0; while(G_RUN) { // telemetry. G.cli.msg_num sentences before SSDV // for(int __mi=0; __mi -5 // not falling ) { if( !ssdv_tiles.size() && G.cli.ssdv_image.size() ) cout<<"SSDV loaded "<< ssdv_tiles.load_file( G.cli.ssdv_image ) <<" packets from disk."<