50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
m2m.nbiot package initialization.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Dict, Type, Optional
|
|
|
|
from m2m.nbiot.module import ModuleBase
|
|
from m2m.nbiot.module_bg96 import ModuleBG96
|
|
from m2m.nbiot.module_bg95 import ModuleBG95
|
|
from m2m.nbiot.module_bc66 import ModuleBC66
|
|
from m2m.nbiot.module_hisi import ModuleHiSi
|
|
|
|
# Establish parent logger
|
|
logging.getLogger('m2m').addHandler(logging.NullHandler())
|
|
|
|
# Chipset Registry
|
|
_MODULE_REGISTRY: Dict[str, Type[ModuleBase]] = {
|
|
'HiSi': ModuleHiSi,
|
|
'BG96': ModuleBG96,
|
|
'BG95': ModuleBG95,
|
|
'BC66': ModuleBC66,
|
|
}
|
|
|
|
def factory(chipset: str, serial_port: str, **kwargs) -> ModuleBase:
|
|
"""
|
|
Factory for creating module instances based on chipset name.
|
|
|
|
Args:
|
|
chipset: Name of the chipset (e.g., 'BG96', 'BG95', 'HiSi').
|
|
serial_port: Device path (e.g., '/dev/ttyUSB0').
|
|
**kwargs: Passed to the module constructor.
|
|
|
|
Returns:
|
|
An instance of a ModuleBase subclass.
|
|
|
|
Raises:
|
|
ValueError: If the chipset is not supported.
|
|
"""
|
|
module_class = _MODULE_REGISTRY.get(chipset)
|
|
if not module_class:
|
|
supported = ", ".join(_MODULE_REGISTRY.keys())
|
|
raise ValueError(f"Unsupported chipset '{chipset}'. Supported: {supported}")
|
|
|
|
return module_class(serial_port, **kwargs)
|
|
|
|
__all__ = ['factory', 'ModuleBase', 'ModuleBG96', 'ModuleBG95', 'ModuleBC66', 'ModuleHiSi']
|