Эх сурвалжийг харах

change controller_chery_sterra_es_fcm for use net set.

yuchuli 1 сар өмнө
parent
commit
3568e38222

+ 45 - 2
src/controller/controller_chery_sterra_es_fcm/dbcsigpacker.cpp

@@ -2,10 +2,39 @@
 
 #include <iostream>
 
-dbcsigpacker::dbcsigpacker() {}
 
+dbcsigpacker::dbcsigpacker(std::string strdbcname){
+    mpPacker =  new CANPacker(strdbcname);
+    mpdbc = mpPacker->GetDBC();
+    InitSig();
+}
+
+dbcsigpacker::dbcsigpacker(std::string strdbcname,std::istringstream & strsteam){
+    mpPacker = new CANPacker(strdbcname,strsteam);
+    mpdbc = mpPacker->GetDBC();
+    InitSig();
+}
+
+void dbcsigpacker::SetMsgSignal(std::string  strmsgname,std::string  strsigname,const double fvalue){
+
+    if(mmapMsgSig.count(strmsgname)<=0)
+    {
+        std::cout<<" SetMsgSignal no message "<<strmsgname<<std::endl;
+        return;
+    }
+
+    iv::MsgSig & xMsgSig = mmapMsgSig[strmsgname];
 
-void dbcsigpacker::SetMsgSignal(std::string & strmsgname,std::string & strsigname,const double fvalue){
+    int i;
+    int nsize = static_cast<int>(xMsgSig.mvectorSPV.size());
+    for(i=0;i<nsize;i++){
+        if(xMsgSig.mvectorSPV[i].name == strsigname){
+            xMsgSig.mvectorSPV[i].value = fvalue;
+            break;
+        }
+    }
+
+    std::cout<<" Msg "<<strmsgname<<" no signal "<<strsigname<<std::endl;
 
 }
 
@@ -35,3 +64,17 @@ void dbcsigpacker::InitSig()
 
 
 }
+
+std::vector<uint8_t> dbcsigpacker::GetPack(std::string  strmsgname){
+    std::vector<uint8_t> xPack;
+    if(mmapMsgSig.count(strmsgname)<=0)
+    {
+        std::cout<<" GetPack no message "<<strmsgname<<std::endl;
+        return xPack;
+    }
+
+    iv::MsgSig & xMsgSig = mmapMsgSig[strmsgname];
+    xPack = mpPacker->pack(xMsgSig.mid,xMsgSig.mvectorSPV);
+    return xPack;
+
+}

+ 6 - 3
src/controller/controller_chery_sterra_es_fcm/dbcsigpacker.h

@@ -18,17 +18,20 @@ struct MsgSig
 class dbcsigpacker
 {
 public:
-    dbcsigpacker();
+    dbcsigpacker(std::string strdbcname);
+    dbcsigpacker(std::string strdbcname,std::istringstream & strsteam);
 
 private:
-    DBC * mpdbc;
+    CANPacker * mpPacker;
+    const DBC * mpdbc;
     std::map<std::string,iv::MsgSig> mmapMsgSig;
 
 private:
     void InitSig();
 
 public:
-    void SetMsgSignal(std::string & strmsgname,std::string & strsigname,const double fvalue);
+    void SetMsgSignal(std::string  strmsgname,std::string  strsigname,const double fvalue);
+    std::vector<uint8_t> GetPack(std::string  strmsgname);
 };
 
 #endif // DBCSIGPACKER_H

+ 4 - 0
src/controller/controller_chery_sterra_es_fcm/main.cpp

@@ -24,6 +24,7 @@
 
 #include "candbc.h"
 #include "sterraes.h"
+#include "dbcsigpacker.h"
 
 std::string gstrdbcpath;
 bool gbUseOutDBC;
@@ -1050,6 +1051,9 @@ int main(int argc, char *argv[])
 
             std::istringstream iss(content.toStdString());
             gpsterraes = new sterraes(std::string(":/ADCC_CH.dbc"),iss);
+
+            dbcsigpacker * ppac = new dbcsigpacker(std::string(":/ADCC_CH.dbc"),iss);
+            ppac->SetMsgSignal("ADS_EPS_1","hi",1);
         }
         else
             std::cout<<" open qrc dbc file fail. "<<std::endl;

+ 85 - 15
src/controller/controller_chery_sterra_es_fcm/sterraes.cpp

@@ -7,16 +7,25 @@
 
 sterraes::sterraes(std::string strdbcname) {
 
-    mpPacker =  new CANPacker(strdbcname);
-    initsig();
+    mpdbcsigpacker = new dbcsigpacker(strdbcname);
+    // mpPacker =  new CANPacker(strdbcname);
+    // initsig();
 }
 
 sterraes::sterraes(std::string strdbcname,std::istringstream & strsteam)
 {
-    mpPacker = new CANPacker(strdbcname,strsteam);
-    initsig();
+    mpdbcsigpacker = new dbcsigpacker(strdbcname,strsteam);
+
+    // mpPacker = new CANPacker(strdbcname,strsteam);=
+    // initsig();
 }
 
+void sterraes::SetMsgSignal(std::string  strmsgname,std::string  strsigname,const double fvalue){
+
+    mpdbcsigpacker->SetMsgSignal(strmsgname,strsigname,fvalue);
+}
+
+
 void sterraes::initsig()
 {
     SignalPackValue sv;
@@ -205,7 +214,14 @@ void sterraes::fillcrc(unsigned short dataid,unsigned char * pdata){
 }
 
 void sterraes::GetEPS1Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x195,mvectorADSEPS1);
+ //   std::vector<uint8_t> xpack =  mpPacker->pack(0x195,mvectorADSEPS1);
+
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_EPS_1");
+
+    if(xpack.size()<24){
+        std::cout<<"GetEPS1Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -214,16 +230,33 @@ void sterraes::GetEPS1Data(unsigned char * pdata){
 }
 
 void sterraes::GetEPS3Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x1BC,mvectorADSEPS3);
+ //   std::vector<uint8_t> xpack =  mpPacker->pack(0x1BC,mvectorADSEPS3);
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_EPS_3");
+
+    if(xpack.size()<24){
+        std::cout<<"GetEPS3Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
+
     fillcrc(0x0006,pdata);
     fillcrc(0x0007,pdata+8);
 }
 
 void sterraes::GetONEBOX1Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x159,mvectorADSONEBOX1);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x159,mvectorADSONEBOX1);
+
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_ONEBOX_1");
+
+    if(xpack.size()<24){
+        std::cout<<"GetONEBOX1Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -231,7 +264,15 @@ void sterraes::GetONEBOX1Data(unsigned char * pdata){
 }
 
 void sterraes::GetVCU1Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x167,mvectorADSVCU1);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x167,mvectorADSVCU1);
+
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_VCU_1");
+
+    if(xpack.size()<24){
+        std::cout<<"GetVCU1Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -240,7 +281,16 @@ void sterraes::GetVCU1Data(unsigned char * pdata){
 }
 
 void sterraes::GetONEBOX2Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x145,mvectorADSONEBOX2);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x145,mvectorADSONEBOX2);
+
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_ONEBOX_2");
+
+    if(xpack.size()<24){
+        std::cout<<"GetONEBOX2Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -248,7 +298,14 @@ void sterraes::GetONEBOX2Data(unsigned char * pdata){
 }
 
 void sterraes::GetONEBOX3Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x14A,mvectorADSONEBOX3);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x14A,mvectorADSONEBOX3);
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_ONEBOX_3");
+
+    if(xpack.size()<24){
+        std::cout<<"GetONEBOX3Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -256,7 +313,16 @@ void sterraes::GetONEBOX3Data(unsigned char * pdata){
 }
 
 void sterraes::GetADSCOM3Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x31A,mvectorADSCOM3);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x31A,mvectorADSCOM3);
+
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_COM_2");
+
+    if(xpack.size()<24){
+        std::cout<<"GetADSCOM3Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
+
     int i;
     for(i=0;i<24;i++)pdata[i] = xpack[i];
 
@@ -264,13 +330,17 @@ void sterraes::GetADSCOM3Data(unsigned char * pdata){
 }
 
 void sterraes::GetADSCOM2Data(unsigned char * pdata){
-    std::vector<uint8_t> xpack =  mpPacker->pack(0x314,mvectorADSCOM2);
+//    std::vector<uint8_t> xpack =  mpPacker->pack(0x314,mvectorADSCOM2);
+    std::vector<uint8_t> xpack = mpdbcsigpacker->GetPack("ADS_COM_3");
+
+    if(xpack.size()<8){
+        std::cout<<"GetADSCOM2Data Fail. pack size: "<<xpack.size()<<std::endl;
+        return;
+    }
+
     int i;
     for(i=0;i<8;i++)pdata[i] = xpack[i];
 
     fillcrc(0x0010,pdata);
 }
 
-void SetMsgSignal(std::string & strmsgname,std::string & strsigname,const double fvalue){
-
-}

+ 9 - 1
src/controller/controller_chery_sterra_es_fcm/sterraes.h

@@ -3,6 +3,7 @@
 
 #include <vector>
 #include "candbc.h"
+#include "dbcsigpacker.h"
 
 
 class sterraes
@@ -11,6 +12,14 @@ public:
     sterraes(std::string strdbcname);
     sterraes(std::string strdbcname,std::istringstream & strsteam);
 
+
+private:
+    dbcsigpacker * mpdbcsigpacker;
+
+
+public:
+    void SetMsgSignal(std::string  strmsgname,std::string  strsigname,const double fvalue);
+
 private:
     std::vector<SignalPackValue> mvectorADSEPS1;
     std::vector<SignalPackValue> mvectorADSEPS3;
@@ -49,7 +58,6 @@ public:
     void GetADSCOM3Data(unsigned char * pdata);
     void GetADSCOM2Data(unsigned char * pdata);
 
-    void SetMsgSignal(std::string & strmsgname,std::string & strsigname,const double fvalue);
 
 
 };