Upgrade RadioLib to 5.50

This commit is contained in:
lewishe 2022-12-09 16:12:04 +08:00
commit 6301fa4734
208 changed files with 15925 additions and 10099 deletions

View file

@ -0,0 +1,111 @@
import re, sys, argparse
from pathlib import Path
from argparse import RawTextHelpFormatter
'''
TODO list:
1. Parse macro values (the names of bits in all registers in header file)
2. Failed SPI write handling
3. SX126x/SX128x handling
'''
def get_macro_name(value, macros):
for macro in macros:
if macro[1] == value:
return macro[0]
return 'UNKNOWN_VALUE'
def get_macro_value(value):
return ' 0x{0:02X}\n'.format(int(value, 16))
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description='''
RadioLib debug output decoder script. Turns RadioLib Serial dumps into readable text.
Step-by-step guid on how to use the decoder:
1. Uncomment lines 312 (#define RADIOLIB_DEBUG) and 313 (#define RADIOLIB_VERBOSE) in RadioLib/src/BuildOpt.h
2. Recompile and upload the failing Arduino sketch
3. Open Arduino IDE Serial Monitor and enable timestamps
4. Copy the Serial output and save it into a .txt file
5. Run this script
Output will be saved in the file specified by --out and printed to the terminal
''')
parser.add_argument('file', metavar='file', type=str, help='Text file of the debug output')
parser.add_argument('--out', metavar='out', default='./out.txt', type=str, help='Where to save the decoded file (defaults to ./out.txt)')
args = parser.parse_args()
# open the log file
log = open(args.file, 'r').readlines()
# find modules that are in use
used_modules = []
pattern_module = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?M\t')
for entry in log:
m = pattern_module.search(entry)
if m != None:
used_modules.append(entry[m.end():].rstrip())
# get paths to all relevant header files
header_files = []
for path in Path('../../src').rglob('*.h'):
for module in used_modules:
if module in path.name:
header_files.append(path)
# extract names of address macros from the header files
macro_addresses = []
pattern_define = re.compile('#define \w* +\w*(\n| +\/\/){1}')
for path in header_files:
file = open(path, 'r').readlines()
for line in file:
m = pattern_define.search(line)
if m != None:
s = re.split(' +', m.group().rstrip())
if (s.__len__() > 1) and ('_REG' in s[1]):
macro_addresses.append([s[1], int(s[2], 0)])
'''
# extract names of value macros for each adddress macro
macro_values = []
for path in header_files:
file = open(path, 'r').readlines()
for line in file:
for module in used_modules:
pattern_addr_macro = re.compile('\/\/ SI443X_REG_\w+'.format(module.capitalize()))
'''
# parse every line in the log file
out = []
pattern_debug = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?[RWM]\t.+')
for entry in log:
m = pattern_debug.search(entry)
if m != None:
s = re.split('( |\t)+', entry.rstrip())
cmd_len = int((s.__len__() - 7)/2)
new_entry = s[0] + s[1] + s[2] + s[3]
if s[4] == 'W':
macro_address = int(s[6], 16)
new_entry += 'write {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
for i in range(cmd_len):
new_entry += get_macro_value(s[8 + 2*i]);
elif s[4] == 'R':
macro_address = int(s[6], 16)
new_entry += 'read {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
for i in range(cmd_len):
new_entry += get_macro_value(s[8 + 2*i]);
elif s[4] == 'M':
new_entry += 'module {}\n'.format(s[6])
out.append(new_entry)
else:
out.append(entry)
# write the output file
out_file = open(args.out, 'w')
for line in out:
print(line, end='')
out_file.write(line)
out_file.close()

View file

@ -0,0 +1,22 @@
#include "<module_name>.h"
#if !defined(RADIOLIB_EXCLUDE_<module_name>)
<module_name>::<module_name>(Module* mod) {
/*
Constructor implementation MUST assign the provided "mod" pointer to the private "_mod" pointer.
*/
_mod = mod;
}
int16_t <module_name>::begin() {
/*
"begin" method implementation MUST call the "init" method with appropriate settings.
*/
_mod->init();
/*
"begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module.
For example, reading a version register
*/
}

View file

@ -0,0 +1,99 @@
/*
RadioLib Module Template header file
Before opening pull request, please make sure that:
1. All files MUST be compiled without errors using default Arduino IDE settings.
2. All files SHOULD be compiled without warnings with compiler warnings set to "All".
3. Example sketches MUST be working correctly and MUST be stable enough to run for prolonged periods of time.
4. Writing style SHOULD be consistent.
5. Comments SHOULD be in place for the most important chunks of code and SHOULD be free of typos.
6. To indent, 2 spaces MUST be used.
If at any point you are unsure about the required style, please refer to the rest of the modules.
*/
#if !defined(_RADIOLIB_<module_name>_H) && !defined(RADIOLIB_EXCLUDE_<module_name>)
#if !defined(_RADIOLIB_<module_name>_H)
#define _RADIOLIB_<module_name>_H
/*
Header file for each module MUST include Module.h and TypeDef.h in the src folder.
The header file MAY include additional header files.
*/
#include "../../Module.h"
#include "../../TypeDef.h"
/*
Only use the following include if the module implements methods for OSI physical layer control.
This concerns only modules similar to SX127x/RF69/CC1101 etc.
In this case, your class MUST implement all virtual methods of PhysicalLayer class.
*/
//#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
/*
Register map
Definition of SPI register map SHOULD be placed here. The register map SHOULD have two parts:
1 - Address map: only defines register names and addresses. Register names MUST match names in
official documentation (datasheets etc.).
2 - Variable map: defines variables inside register. This functions as a bit range map for a specific register.
Bit range (MSB and LSB) as well as short description for each variable MUST be provided in a comment.
See RF69 and SX127x header files for examples of register maps.
*/
// <module_name> register map | spaces up to this point
#define RADIOLIB_<module_name>_REG_<register_name> 0x00
// <module_name>_REG_<register_name> MSB LSB DESCRIPTION
#define RADIOLIB_<module_name>_<register_variable> 0b00000000 // 7 0 <description>
/*
Module class definition
The module class MAY inherit from the following classes:
1 - PhysicalLayer: In case the module implements methods for OSI physical layer control (e.g. SX127x).
2 - Common class: In case the module further specifies some more generic class (e.g. SX127x/SX1278)
*/
class <module_name> {
public:
/*
Constructor MUST have only one parameter "Module* mod".
The class MAY implement additional overloaded constructors.
*/
// constructor
<module_name>(Module* mod);
/*
The class MUST implement at least one basic method called "begin".
The "begin" method MUST initialize the module and return the status as int16_t type.
*/
// basic methods
int16_t begin();
/*
The class MAY implement additional methods.
All implemented methods SHOULD return the status as int16_t type.
*/
#if !defined(RADIOLIB_GODMODE)
private:
#endif
/*
The class MUST contain private member "Module* _mod"
*/
Module* _mod;
/*
The class MAY contain additional private variables and/or methods.
Private member variables MUST have a name prefixed with "_" (underscore, ASCII 0x5F)
Usually, these are variables for saving module configuration, or methods that do not have to be exposed to the end user.
*/
};
#endif
#endif