[wireless-regdb] [PATCH] Correctly parse power with gain and eirp

Rusty Howell <[email protected]>
Newsgroups org.infradead.lists.wireless-regdb
Message-ID <CAE+BM3kzS-xYjLWyBqTaYpEAmR1p=8UuxR957QZW1soKwakmZQ@mail.gmail.com>
From 082a38a3de11701ea1edf40a2f3268ec5115c691 Mon Sep 17 00:00:00 2001
From: Rusty Howell <[email protected]>
Date: Wed, 13 Sep 2023 11:13:19 -0600
Subject: [PATCH] Correctly parse power with gain and eirp

Parse a power entry like "(6, 20)" or "(20", or "(N/A, 20)".
Previously, the example ASCII file format show in this page would not parse.
https://wireless.wiki.kernel.org/en/developers/regulatory/wireless-regdb#mailing_list_for_regulatory_updates
---
 dbparse.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/dbparse.py b/dbparse.py
index 1e87813..b36ff9c 100755
--- a/dbparse.py
+++ b/dbparse.py
@@ -264,16 +264,25 @@ class DBParser(object):

     def _parse_power_def(self, pname, line, dupwarn=True):
         try:
-            max_eirp = line
-            if max_eirp == 'N/A':
-                max_eirp = '0'
-            max_ant_gain = float(0)
+            max_eirp = ''
+            max_ant_gain = ''
+            if ',' in line:
+                max_ant_gain, max_eirp = line.split(',')
+                if max_ant_gain == 'N/A':
+                    max_ant_gain = '0'
+            else:
+                max_ant_gain = '0'
+                max_eirp = line
+                if max_eirp == 'N/A':
+                    max_eirp = 0.0
+
             def conv_pwr(pwr):
                 if pwr.endswith('mW'):
                     pwr = float(pwr[:-2])
                     return 10.0 * math.log10(pwr)
                 else:
                     return float(pwr)
+            max_ant_gain = float(max_ant_gain)
             max_eirp = conv_pwr(max_eirp)
         except ValueError:
             self._syntax_error("invalid power data")
-- 
2.25.1

_______________________________________________
wireless-regdb mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/wireless-regdb
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.