#include #include #include #include #include "modulecomm.h" #include "xmlparam.h" #include "ivexit.h" #include "ivfault.h" #include "ivlog.h" #include "ivversion.h" #include "ivbacktrace.h" #include "canmsg.pb.h" #include "gpsimu.pb.h" #include "gps.pb.h" #include #include #include iv::gps::gpsimu hcp2_obj; int gntemp = 0; void * gpa , * gpb; QTime gTime; bool gbRun = true; std::thread * gstatethread; iv::Ivfault *gfault = nullptr; iv::Ivlog *givlog = nullptr; int gnOldRtkState = 0; int gnogpsdata = 0; static inline void bigtolittle(char * strbig, char * strlittle, int n) { int i; for(i = 0; i < n; i++) { strlittle[i] = strbig[n-1-i]; } } void ShareResult() { gnogpsdata = 0; char * str = new char[hcp2_obj.ByteSize()]; int nsize = hcp2_obj.ByteSize(); if(hcp2_obj.SerializeToArray(str,nsize)) { iv::modulecomm::ModuleSendMsg(gpa,str,nsize); } // qDebug("share time is %d ",gTime.elapsed()); qDebug("time is %s", qPrintable( QDateTime::fromMSecsSinceEpoch(QDateTime::currentMSecsSinceEpoch()).toString("yyyy--MM-dd hh:mm:ss:zzz") )); delete str; } void Decode_hcp2(iv::can::canmsg xmsg) { static bool x1ok = false; static bool x2ok = false; static bool x3ok = false; static bool x4ok = false; static bool x5ok = false; double acc_x = 0.0, acc_y = 0.0, acc_z = 0.0, ins_pitch = 0.0, ins_roll = 0.0, ins_heading = 0.0, ins_northspd = 0.0, ins_eastspd = 0.0, ins_skyspd = 0.0, ins_carspd = 0.0, gyro_x = 0.0, gyro_y = 0.0, gyro_z = 0.0, ins_long = 0.0, ins_lat = 0.0, ins_localheight = 0.0, ins_time = 0.0; if(xmsg.rawmsg_size() < 1) return; int i; for(i=0;i= 360)ins_heading = ins_heading - 360; hcp2_obj.set_heading(ins_heading); hcp2_obj.set_pitch(ins_pitch); hcp2_obj.set_roll(ins_roll); } if(x1ok && x2ok && x3ok && x4ok && x5ok) { x1ok = false; x2ok = false; x3ok = false; x4ok = false; x5ok = false; hcp2_obj.set_msgtime(QDateTime::currentMSecsSinceEpoch()); hcp2_obj.set_time(QDateTime::currentMSecsSinceEpoch()); std::cout<<"time is "<verbose("gps lat:%11.7f lon:%11.7f heading:%11.3f rtk:%d",hcp2_obj.lat(),hcp2_obj.lon(),hcp2_obj.heading(),hcp2_obj.rtk_state()); if(hcp2_obj.rtk_state() != gnOldRtkState) { gnOldRtkState = hcp2_obj.rtk_state(); if(hcp2_obj.rtk_state() == 6) { givlog->info("GPS Fix."); gfault->SetFaultState(0,0,"GPS Fix"); } else { givlog->info("GPS Not Fix, RTK State is %d",hcp2_obj.rtk_state()); gfault->SetFaultState(1,2,"GPS Not Fix."); } } ShareResult(); } } } void Listencan0(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { if(nSize<1)return; iv::can::canmsg xmsg; if(false == xmsg.ParseFromArray(strdata,nSize)) { std::cout<<"hcp2 Listencan0 fail."<join(); iv::modulecomm::Unregister(gpa); iv::modulecomm::Unregister(gpb); std::cout<<"Complete exitfunc."< 100)nstate = 1; if(gnogpsdata > 6000)nstate = 2; if(nstate != noldstate) { noldstate = nstate; switch (nstate) { case 0: gfault->SetFaultState(0,0,"OK."); givlog->info("GPS OK."); break; case 1: gfault->SetFaultState(1,1,"More than 1 second not have data."); givlog->warn("More than 1 second not have data."); break; case 2: gfault->SetFaultState(2,3,"More than 60 seconds not have data."); givlog->error("More than 60 seconds not have data."); break; default: break; } } } } int main(int argc, char *argv[]) { RegisterIVBackTrace(); showversion("detection_gps_hcp2"); QCoreApplication a(argc, argv); gTime.start(); gfault = new iv::Ivfault("detection_gps_hcp2"); givlog = new iv::Ivlog("detection_gps_hcp2"); gfault->SetFaultState(0,0,"Initialize."); QString strpath = QCoreApplication::applicationDirPath(); if(argc < 2) strpath = strpath + "/detection_gps_hcp2.xml"; else strpath = argv[1]; std::cout<