Add function get_data_vector with index 95/23095/1
authorRomain Forlot <romain.forlot@iot.bzh>
Tue, 26 Nov 2019 15:19:08 +0000 (16:19 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 28 Nov 2019 15:11:47 +0000 (16:11 +0100)
This commit adds the function get_data_vector to get
another vector between the index indicates.

Bug-AGL : SPEC-2779
Bug-AGL: SPEC-2976

Change-Id: I704d78467839ee7f9a2fec397e9b0db8da43d79d
Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh>
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
low-can-binding/can/message/message.cpp
low-can-binding/can/message/message.hpp

index 5384c02..b0a33f7 100644 (file)
@@ -76,6 +76,40 @@ const uint8_t* message_t::get_data() const
        return data_.data();
 }
 
+
+///
+/// @brief Retrieve data_ member value.
+///
+/// @return pointer to the first element
+///  of class member data_
+///
+const std::vector<uint8_t> message_t::get_data_vector(int start,int end) const
+{
+       std::vector<uint8_t> ret;
+       if(start >= 0)
+       {
+               if(end<length_)
+               {
+                       for(int i=start;i<=end;i++)
+                       {
+                               ret.push_back(data_[i]);
+                       }
+               }
+               else
+               {
+                       for(int i=start;i<length_;i++)
+                       {
+                               ret.push_back(data_[i]);
+                       }
+               }
+       }
+       else
+       {
+               AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d",start,end,length_);
+       }
+       return ret;
+}
+
 ///
 /// @brief Retrieve data_ member whole vector
 ///
index 48f4d98..f0e1bf0 100644 (file)
@@ -66,6 +66,7 @@ public:
        int get_sub_id() const;
        const uint8_t* get_data() const;
        const std::vector<uint8_t> get_data_vector() const;
+       const std::vector<uint8_t> get_data_vector(int start,int end) const;
        uint32_t get_length() const;
        uint64_t get_timestamp() const;