Browse Source

读取txt文件,在每次请求发起时读取

limengqi 6 tháng trước cách đây
mục cha
commit
81dc574cbe
1 tập tin đã thay đổi với 35 bổ sung35 xóa
  1. 35 35
      src/canbus/canbus.cpp

+ 35 - 35
src/canbus/canbus.cpp

@@ -179,41 +179,6 @@ int Canbus::Start() {
 
   ros::ServiceServer SftTxtService = node_handle_->advertiseService(robot::common::SftTxtService,
                                                                     &Canbus::SftTxtReq,this);
-
-  string str = "/home/madesheng/angle.txt";
-  int flag = Canbus::read_txt(str,1);
-  if(flag != ROBOT_SUCCESS)
-  {
-    return ROBOT_FAILTURE;
-  }
-   str = "/home/madesheng/psng.txt";
-   flag = Canbus::read_txt(str,2);
-   if(flag != ROBOT_SUCCESS)
-   {
-     return ROBOT_FAILTURE;
-   }
-
-   str = "/home/madesheng/acc.txt";
-   flag = Canbus::read_txt(str,3);
-   if(flag != ROBOT_SUCCESS)
-   {
-     return ROBOT_FAILTURE;
-   }
-
-   str = "/home/madesheng/angleLine.txt";
-   flag = Canbus::read_txt(str,4);
-   if(flag != ROBOT_SUCCESS)
-   {
-     return ROBOT_FAILTURE;
-   }
-
-   str = "/home/madesheng/sft.txt";
-   flag = Canbus::read_txt(str,5);
-   if(flag != ROBOT_SUCCESS)
-   {
-     return ROBOT_FAILTURE;
-   }
-
   //data receive
   while(ros::ok())
   {
@@ -1146,6 +1111,13 @@ bool Canbus::StrTxtReq(canbus::StrTxtReq::Request &req,canbus::StrTxtReq::Respon
         res.uiReturn = 1;
         return true;
       }
+      string str = "/home/madesheng/angle.txt";
+            int flag = Canbus::read_txt(str,1);
+            if(flag != ROBOT_SUCCESS)
+            {
+              res.uiReturn = 0;
+              return false;
+            }
       if(strTxtTimerState)
       {
         str_txt_timer_.stop();
@@ -1222,6 +1194,13 @@ bool Canbus::BrkTxtReq(canbus::BrkTxtReq::Request &req,canbus::BrkTxtReq::Respon
       res.uiReturn = 1;
       return true;
     }
+    string str = "/home/madesheng/psng.txt";
+    int flag = Canbus::read_txt(str,2);
+    if(flag != ROBOT_SUCCESS)
+    {
+      res.uiReturn = 0;
+      return false;
+    }
     if(brkTxtTimerState)
     {
       brk_txt_timer_.stop();
@@ -1293,6 +1272,13 @@ bool Canbus::AccTxtReq(canbus::AccTxtReq::Request &req,canbus::AccTxtReq::Respon
       res.uiReturn = 1;
       return true;
     }
+    string str = "/home/madesheng/acc.txt";
+    int flag = Canbus::read_txt(str,3);
+    if(flag != ROBOT_SUCCESS)
+    {
+      res.uiReturn = 0;
+      return false;
+    }
     if(accTxtTimerState)
     {
       acc_txt_timer_.stop();
@@ -1362,6 +1348,13 @@ bool Canbus::StrTxtLineReq(canbus::StrTxtLineReq::Request &req,canbus::StrTxtLin
         res.uiReturn = 1;
         return true;
       }
+      string str = "/home/madesheng/angleLine.txt";
+      int flag = Canbus::read_txt(str,4);
+      if(flag != ROBOT_SUCCESS)
+      {
+        res.uiReturn = 0;
+        return false;
+      }
       if(strTxtLineTimerState)
       {
         str_txt_line_timer_.stop();
@@ -1430,6 +1423,13 @@ bool Canbus::SftTxtReq(canbus::SftTxtReq::Request &req,canbus::SftTxtReq::Respon
       res.uiReturn = 1;
       return true;
     }
+    string str = "/home/madesheng/sft.txt";
+    int flag = Canbus::read_txt(str,5);
+    if(flag != ROBOT_SUCCESS)
+    {
+      res.uiReturn = 0;
+      return false;
+    }
     if(sftTxtTimerState)
     {
       sft_txt_timer_.stop();