From c19179434eb458a7525d8429b6b1381b4bf6c37c Mon Sep 17 00:00:00 2001
From: "Christian W. Zuckschwerdt" <christian@zuckschwerdt.org>
Date: Mon, 7 Jun 2021 11:49:04 +0200
Subject: [PATCH] Remove oldmodel option

---
 README.md                 |  3 +--
 conf/rtl_433.example.conf |  3 +--
 docs/DATA_FORMAT.md       |  1 -
 docs/OPERATION.md         |  2 +-
 include/decoder.h         |  2 +-
 include/r_device.h        |  1 -
 include/rtl_433.h         |  1 -
 man/man1/rtl_433.1        |  5 +----
 src/r_api.c               | 32 +++++++++++++-------------------
 src/rtl_433.c             | 15 ++++-----------
 10 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md
index 3ab03618..c6429e21 100644
--- a/README.md
+++ b/README.md
@@ -369,7 +369,7 @@ E.g. -X "n=doorbell,m=OOK_PWM,s=400,l=800,r=7000,g=1000,match={24}0xa9878c,repea
 
 
 		= Meta information option =
-  [-M time[:<options>]|protocol|level|stats|bits|oldmodel] Add various metadata to every output line.
+  [-M time[:<options>]|protocol|level|stats|bits] Add various metadata to every output line.
 	Use "time" to add current date and time meta data (preset for live inputs).
 	Use "time:rel" to add sample position meta data (preset for read-file and stdin).
 	Use "time:unix" to show the seconds since unix epoch as time meta data.
@@ -385,7 +385,6 @@ E.g. -X "n=doorbell,m=OOK_PWM,s=400,l=800,r=7000,g=1000,match={24}0xa9878c,repea
 	Use "stats[:[<level>][:<interval>]]" to report statistics (default: 600 seconds).
 	  level 0: no report, 1: report successful devices, 2: report active devices, 3: report all
 	Use "bits" to add bit representation to code outputs (for debug).
-	Note: You can use "oldmodel" to get the old model keys. This will be removed shortly.
 
 
 		= Read file option =
diff --git a/conf/rtl_433.example.conf b/conf/rtl_433.example.conf
index 90a5615f..2df10b54 100644
--- a/conf/rtl_433.example.conf
+++ b/conf/rtl_433.example.conf
@@ -111,7 +111,7 @@ analyze_pulses false
 #out_block_size
 
 # as command line option:
-#   [-M time[:<options>]|protocol|level|stats|bits|oldmodel] Add various metadata to every output line.
+#   [-M time[:<options>]|protocol|level|stats|bits] Add various metadata to every output line.
 # Use "time" to add current date and time meta data (preset for live inputs).
 # Use "time:rel" to add sample position meta data (preset for read-file and stdin).
 # Use "time:unix" to show the seconds since unix epoch as time meta data.
@@ -125,7 +125,6 @@ analyze_pulses false
 # Use "level" to add Modulation, Frequency, RSSI, SNR, and Noise meta data.
 # Use "stats[:[<level>][:<interval>]]" to report statistics (default: 600 seconds).
 #   level 0: no report, 1: report successful devices, 2: report active devices, 3: report all
-# Use "oldmodel" to use to old model keys. This will be removed shortly.
 report_meta level
 report_meta stats
 report_meta time:usec
diff --git a/docs/DATA_FORMAT.md b/docs/DATA_FORMAT.md
index 6161a8ca..73af3f56 100644
--- a/docs/DATA_FORMAT.md
+++ b/docs/DATA_FORMAT.md
@@ -1,7 +1,6 @@
 # JSON Data fields
 
 See also the discussion and rationale in https://github.com/merbanan/rtl_433/pull/827
-Note that you can use `-M oldmodel` to still get the legacy names for a short while.
 
 ## Message Data
 These fields are the primary data fields containing the most basic message data and used to identify the specific device.
diff --git a/docs/OPERATION.md b/docs/OPERATION.md
index b88db1d1..86f8f052 100644
--- a/docs/OPERATION.md
+++ b/docs/OPERATION.md
@@ -496,7 +496,7 @@ Without any `-F` option the default is KV output. Use `-F null` to remove that d
 ### Meta information
 
 ```
-  [-M time[:<options>]|protocol|level|stats|bits|oldmodel]
+  [-M time[:<options>]|protocol|level|stats|bits]
     Add various metadata to every output line.
 ```
 - Use `time` to add current date and time meta data (preset for live inputs).
diff --git a/include/decoder.h b/include/decoder.h
index 432f8f29..cc99424a 100644
--- a/include/decoder.h
+++ b/include/decoder.h
@@ -13,6 +13,6 @@
 #include "decoder_util.h"
 
 /* TODO: temporary allow to change to new style model keys */
-#define _X(n, o) (decoder->old_model_keys ? (o) : (n))
+#define _X(n, o) ((0) ? (o) : (n))
 
 #endif /* INCLUDE_DECODER_H_ */
diff --git a/include/r_device.h b/include/r_device.h
index 5613d2e1..7051736e 100644
--- a/include/r_device.h
+++ b/include/r_device.h
@@ -57,7 +57,6 @@ typedef struct r_device {
     char **fields; ///< List of fields this decoder produces; required for CSV output. NULL-terminated.
 
     /* public for each decoder */
-    int old_model_keys; ///< TODO: temporary allow to change to old style model keys
     int verbose;
     int verbose_bits;
     void (*output_fn)(struct r_device *decoder, struct data *data);
diff --git a/include/rtl_433.h b/include/rtl_433.h
index bfed2740..e69b333f 100644
--- a/include/rtl_433.h
+++ b/include/rtl_433.h
@@ -95,7 +95,6 @@ typedef struct r_cfg {
     struct dm_state *demod;
     char const *sr_filename;
     int sr_execopen;
-    int old_model_keys;
     /* stats*/
     time_t frames_since; ///< stats start time
     unsigned frames_count; ///< stats counter for interval
diff --git a/man/man1/rtl_433.1 b/man/man1/rtl_433.1
index b913a6ef..7b26dd6a 100644
--- a/man/man1/rtl_433.1
+++ b/man/man1/rtl_433.1
@@ -352,7 +352,7 @@ Specify host/port for syslog with e.g. \-F syslog:127.0.0.1:1514
 .RE
 .SS "Meta information option"
 .TP
-[ \fB\-M\fI time[:<options>]|protocol|level|stats|bits|oldmodel\fP ]
+[ \fB\-M\fI time[:<options>]|protocol|level|stats|bits\fP ]
 Add various metadata to every output line.
 .RS
 Use "time" to add current date and time meta data (preset for live inputs).
@@ -399,9 +399,6 @@ Use "stats[:[<level>][:<interval>]]" to report statistics (default: 600 seconds)
 .RS
 Use "bits" to add bit representation to code outputs (for debug).
 .RE
-.RS
-Note: You can use "oldmodel" to get the old model keys. This will be removed shortly.
-.RE
 .SS "Read file option"
 .TP
 [ \fB\-r\fI <filename>\fP ]
diff --git a/src/r_api.c b/src/r_api.c
index 66bc2d4c..2ef688ef 100644
--- a/src/r_api.c
+++ b/src/r_api.c
@@ -227,8 +227,6 @@ void register_protocol(r_cfg_t *cfg, r_device *r_dev, char *arg)
     p->verbose      = cfg->verbosity > 0 ? cfg->verbosity - 1 : 0;
     p->verbose_bits = cfg->verbose_bits;
 
-    p->old_model_keys = cfg->old_model_keys; // TODO: temporary allow to change to new style model keys
-
     p->output_fn  = data_acquired_handler;
     p->output_ctx = cfg;
 
@@ -374,10 +372,8 @@ char const **well_known_output_fields(r_cfg_t *cfg)
 /** Convert CSV keys according to selected conversion mode. Replacement is static but in-place. */
 static char const **convert_csv_fields(r_cfg_t *cfg, char const **fields)
 {
-    if (!cfg->old_model_keys) {
-        for (char const **p = fields; *p; ++p) {
-            if (!strcmp(*p, "battery")) *p = "battery_ok";
-        }
+    for (char const **p = fields; *p; ++p) {
+        if (!strcmp(*p, "battery")) *p = "battery_ok";
     }
 
     if (cfg->conversion_mode == CONVERT_SI) {
@@ -557,19 +553,17 @@ void data_acquired_handler(r_device *r_dev, data_t *data)
 #endif
 
     // replace textual battery key with numerical battery key
-    if (!cfg->old_model_keys) {
-        for (data_t *d = data; d; d = d->next) {
-            if ((d->type == DATA_STRING) && !strcmp(d->key, "battery")) {
-                free(d->key);
-                d->key = strdup("battery_ok");
-                if (!d->key)
-                    FATAL_STRDUP("data_acquired_handler()");
-                int ok = d->value.v_ptr && !strcmp(d->value.v_ptr, "OK");
-                free(d->value.v_ptr);
-                d->type = DATA_INT;
-                d->value.v_int = ok;
-                break;
-            }
+    for (data_t *d = data; d; d = d->next) {
+        if ((d->type == DATA_STRING) && !strcmp(d->key, "battery")) {
+            free(d->key);
+            d->key = strdup("battery_ok");
+            if (!d->key)
+                FATAL_STRDUP("data_acquired_handler()");
+            int ok = d->value.v_ptr && !strcmp(d->value.v_ptr, "OK");
+            free(d->value.v_ptr);
+            d->type = DATA_INT;
+            d->value.v_int = ok;
+            break;
         }
     }
 
diff --git a/src/rtl_433.c b/src/rtl_433.c
index edf35bf6..a651fe9a 100644
--- a/src/rtl_433.c
+++ b/src/rtl_433.c
@@ -253,7 +253,7 @@ static void help_meta(void)
 {
     term_help_printf(
             "\t\t= Meta information option =\n"
-            "  [-M time[:<options>]|protocol|level|stats|bits|oldmodel] Add various metadata to every output line.\n"
+            "  [-M time[:<options>]|protocol|level|stats|bits] Add various metadata to every output line.\n"
             "\tUse \"time\" to add current date and time meta data (preset for live inputs).\n"
             "\tUse \"time:rel\" to add sample position meta data (preset for read-file and stdin).\n"
             "\tUse \"time:unix\" to show the seconds since unix epoch as time meta data.\n"
@@ -268,8 +268,7 @@ static void help_meta(void)
             "\tUse \"level\" to add Modulation, Frequency, RSSI, SNR, and Noise meta data.\n"
             "\tUse \"stats[:[<level>][:<interval>]]\" to report statistics (default: 600 seconds).\n"
             "\t  level 0: no report, 1: report successful devices, 2: report active devices, 3: report all\n"
-            "\tUse \"bits\" to add bit representation to code outputs (for debug).\n"
-            "\tNote: You can use \"oldmodel\" to get the old model keys. This will be removed shortly.\n");
+            "\tUse \"bits\" to add bit representation to code outputs (for debug).\n");
     exit(0);
 }
 
@@ -966,9 +965,9 @@ static void parse_conf_option(r_cfg_t *cfg, int opt, char *arg)
         else if (!strcasecmp(arg, "description"))
             cfg->report_description = 1;
         else if (!strcasecmp(arg, "newmodel"))
-            cfg->old_model_keys = 0;
+            fprintf(stderr, "newmodel option (-M) is deprecated.\n");
         else if (!strcasecmp(arg, "oldmodel"))
-            cfg->old_model_keys = 1;
+            fprintf(stderr, "oldmodel option (-M) is deprecated.\n");
         else if (!strncasecmp(arg, "stats", 5)) {
             // there also should be options to set wether to flush on report
             char *p = arg_param(arg);
@@ -1302,12 +1301,6 @@ int main(int argc, char **argv) {
 
     parse_conf_args(cfg, argc, argv);
 
-    // warn if still using old model keys
-    if (cfg->old_model_keys) {
-        fprintf(stderr,
-                "\n\tWarning: Using deprecated old model keys (\"-M oldmodel\"). This will be removed shortly.\n\n");
-    }
-
     // add all remaining positional arguments as input files
     while (argc > optind) {
         add_infile(cfg, argv[optind++]);