From f95463a8f2d7d9d9974476feb6df39535197e730 Mon Sep 17 00:00:00 2001
From: daniel-k <github@daniel-krebs.net>
Date: Fri, 5 Jan 2018 13:16:50 +0100
Subject: [PATCH] tests/sx127x: deduce size of netopts from variable

This adapts automatically when a variable type changes, which is easy
to forget to change the correspondig netdev->set/get call.
---
 tests/driver_sx127x/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tests/driver_sx127x/main.c b/tests/driver_sx127x/main.c
index 0818f142d9..13dcbad0e8 100644
--- a/tests/driver_sx127x/main.c
+++ b/tests/driver_sx127x/main.c
@@ -104,11 +104,11 @@ int lora_setup_cmd(int argc, char **argv) {
     /* Configure radio device */
     netdev_t *netdev = (netdev_t*) &sx127x;
     netdev->driver->set(netdev, NETOPT_BANDWIDTH,
-                        &lora_bw, sizeof(uint8_t));
+                        &lora_bw, sizeof(lora_bw));
     netdev->driver->set(netdev, NETOPT_SPREADING_FACTOR,
-                        &lora_sf, 1);
+                        &lora_sf, lora_sf);
     netdev->driver->set(netdev, NETOPT_CODING_RATE,
-                        &lora_cr, sizeof(uint8_t));
+                        &lora_cr, sizeof(lora_cr));
 
     puts("[Info] setup: configuration set with success");
 
@@ -247,7 +247,7 @@ int listen_cmd(int argc, char **argv)
 
     /* Switch to RX state */
     uint8_t state = NETOPT_STATE_RX;
-    netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(uint8_t));
+    netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(state));
 
     printf("Listen mode set\n");
 
@@ -263,7 +263,7 @@ int channel_cmd(int argc, char **argv)
 
     uint32_t chan;
     if (strstr(argv[1], "get") != NULL) {
-        netdev->driver->get(netdev, NETOPT_CHANNEL_FREQUENCY, &chan, sizeof(uint32_t));
+        netdev->driver->get(netdev, NETOPT_CHANNEL_FREQUENCY, &chan, sizeof(chan));
         printf("Channel: %i\n", (int) chan);
         return 0;
     }
@@ -274,7 +274,7 @@ int channel_cmd(int argc, char **argv)
             return -1;
         }
         chan = atoi(argv[2]);
-        netdev->driver->set(netdev, NETOPT_CHANNEL_FREQUENCY, &chan, sizeof(uint32_t));
+        netdev->driver->set(netdev, NETOPT_CHANNEL_FREQUENCY, &chan, sizeof(chan));
         printf("New channel set\n");
     }
     else {
-- 
GitLab