signals.cpp: Make an insensitive string comparison 02/21802/2 7.99.3 8.0.0 8.0.1 8.0.2 halibut/7.99.3 halibut/8.0.0 halibut/8.0.1 halibut/8.0.2 halibut_7.99.3 halibut_8.0.0 halibut_8.0.1 halibut_8.0.2
authorRomain Forlot <romain.forlot@iot.bzh>
Mon, 1 Jul 2019 16:55:23 +0000 (18:55 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Wed, 3 Jul 2019 07:37:05 +0000 (09:37 +0200)
When sending a CAN signal make an case-insensitive comparison as it isn't
necessary to be strict on that, so case insensitive if fine.

Update the documentation accordingly.

Bug-AGL: SPEC-2582

Change-Id: I998b64cdd9a381da3da582aeba42ab726fff1259
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
docs/4-Usage.md
low-can-binding/binding/low-can-hat.hpp
low-can-binding/can/signals.cpp

index 61ca068..cdd8d58 100644 (file)
@@ -216,7 +216,8 @@ low-can subscribe { "event": "doors.driver.open" }
 ON-REPLY 1:low-can/subscribe: {"jtype":"afb-reply","request":{"status":"success","uuid":"a18fd375-b6fa-4c0e-a1d4-9d3955975ae8"}}
 ```
 
-Subscription and unsubscription can take wildcard in their _event_ value.
+Subscription and unsubscription can take wildcard in their _event_ value and are
+**case-insensitive**.
 
 To receive all doors events :
 
@@ -317,9 +318,9 @@ ON-REPLY 2:low-can/list: {"response":["messages.hvac.fan.speed","messages.hvac.t
 
 ## Write on CAN buses
 
-A new capability as been introcuded to be able to write on handled CAN buses.
 Two modes could be used for that which is either specifying the CAN bus and a
-*RAW* CAN message either by specifying a defined signal and its value.
+*RAW* CAN message either by specifying a defined signal, **case-insensitively**,
+and its value.
 
 Examples:
 
index e21b9cd..1662ce0 100644 (file)
@@ -23,6 +23,7 @@
 #include <string>
 #include <memory>
 #include <systemd/sd-event.h>
+#include <cctype>
 
 #include <afb/afb-binding>
 
@@ -31,3 +32,12 @@ class low_can_subscription_t;
 void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s);
 void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uint32_t pid, std::map<int, std::shared_ptr<low_can_subscription_t> >& s);
 int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata);
+
+inline bool caseInsCharCompareN(char a, char b) {
+       return(toupper(a) == toupper(b));
+}
+
+inline bool caseInsCompare(const std::string& s1, const std::string& s2) {
+       return((s1.size() == s2.size()) &&
+       equal(s1.begin(), s1.end(), s2.begin(), caseInsCharCompareN));
+}
index b47001b..3d26343 100644 (file)
@@ -161,7 +161,7 @@ uint64_t signal_t::get_states(const std::string& value) const
        uint64_t ret = -1;
        for( const auto& state: states_)
        {
-               if(state.second == value)
+               if(caseInsCompare(state.second, value))
                {
                        ret = (uint64_t)state.first;
                        break;