Feature/v0.2.2 (#10)
* init v.0.2.2 * v0.2.2 added support for rs485 to tcp adapter
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -173,3 +173,4 @@ cython_debug/
|
|||||||
prot.csv
|
prot.csv
|
||||||
helpertils/serial.py
|
helpertils/serial.py
|
||||||
helpertils/test.py
|
helpertils/test.py
|
||||||
|
helpertils/socker.py
|
||||||
|
|||||||
33
EHSConfig.py
33
EHSConfig.py
@@ -25,6 +25,7 @@ class EHSConfig():
|
|||||||
MQTT = None
|
MQTT = None
|
||||||
GENERAL = None
|
GENERAL = None
|
||||||
SERIAL = None
|
SERIAL = None
|
||||||
|
TCP = None
|
||||||
NASA_REPO = None
|
NASA_REPO = None
|
||||||
LOGGING = {}
|
LOGGING = {}
|
||||||
|
|
||||||
@@ -77,7 +78,13 @@ class EHSConfig():
|
|||||||
config = yaml.safe_load(file)
|
config = yaml.safe_load(file)
|
||||||
self.MQTT = config.get('mqtt')
|
self.MQTT = config.get('mqtt')
|
||||||
self.GENERAL = config.get('general')
|
self.GENERAL = config.get('general')
|
||||||
self.SERIAL = config.get('serial')
|
|
||||||
|
if 'tcp' in config:
|
||||||
|
self.TCP = config.get('tcp')
|
||||||
|
|
||||||
|
if 'serial' in config:
|
||||||
|
self.SERIAL = config.get('serial')
|
||||||
|
|
||||||
if 'logging' in config:
|
if 'logging' in config:
|
||||||
self.LOGGING = config.get('logging')
|
self.LOGGING = config.get('logging')
|
||||||
else:
|
else:
|
||||||
@@ -106,11 +113,25 @@ class EHSConfig():
|
|||||||
if 'protocolFile' not in self.GENERAL:
|
if 'protocolFile' not in self.GENERAL:
|
||||||
self.GENERAL['protocolFile'] = None
|
self.GENERAL['protocolFile'] = None
|
||||||
|
|
||||||
if 'device' not in self.SERIAL:
|
if self.SERIAL is None and self.TCP is None:
|
||||||
raise ConfigException(argument=self.SERIAL['device'], message="serial device config parameter is missing")
|
raise ConfigException(argument="", message="define tcp or serial config parms")
|
||||||
|
|
||||||
if 'baudrate' not in self.SERIAL:
|
if self.SERIAL is not None and self.TCP is not None:
|
||||||
raise ConfigException(argument=self.SERIAL['baudrate'], message="serial baudrate config parameter is missing")
|
raise ConfigException(argument="", message="you cannot define tcp and serial please define only one")
|
||||||
|
|
||||||
|
if self.SERIAL is not None:
|
||||||
|
if 'device' not in self.SERIAL:
|
||||||
|
raise ConfigException(argument=self.SERIAL['device'], message="serial device config parameter is missing")
|
||||||
|
|
||||||
|
if 'baudrate' not in self.SERIAL:
|
||||||
|
raise ConfigException(argument=self.SERIAL['baudrate'], message="serial baudrate config parameter is missing")
|
||||||
|
|
||||||
|
if self.TCP is not None:
|
||||||
|
if 'ip' not in self.TCP:
|
||||||
|
raise ConfigException(argument=self.TCP['ip'], message="tcp ip config parameter is missing")
|
||||||
|
|
||||||
|
if 'port' not in self.TCP:
|
||||||
|
raise ConfigException(argument=self.TCP['port'], message="tcp port config parameter is missing")
|
||||||
|
|
||||||
if 'broker-url' not in self.MQTT:
|
if 'broker-url' not in self.MQTT:
|
||||||
raise ConfigException(argument=self.MQTT['broker-url'], message="mqtt broker-url config parameter is missing")
|
raise ConfigException(argument=self.MQTT['broker-url'], message="mqtt broker-url config parameter is missing")
|
||||||
|
|||||||
23
README.md
23
README.md
@@ -184,12 +184,21 @@ The `config.yml` file contains configuration settings for the EHS-Sentinel proje
|
|||||||
- Default: `False`
|
- Default: `False`
|
||||||
|
|
||||||
### Serial Connection Settings
|
### Serial Connection Settings
|
||||||
|
cannot be defined with TCP parm...
|
||||||
|
|
||||||
- **device**: The serial device URL.
|
- **device**: The serial device URL.
|
||||||
- Example: `/dev/ttyUSB0`
|
- Example: `/dev/ttyUSB0`
|
||||||
- **baudrate**: The baud rate for the serial connection.
|
- **baudrate**: The baud rate for the serial connection.
|
||||||
- Example: `9600`
|
- Example: `9600`
|
||||||
|
|
||||||
|
### TCP Settings
|
||||||
|
cannot be defined with SERIAL parm...
|
||||||
|
|
||||||
|
- **ip**: The ip of rs485 to ETH Adapter.
|
||||||
|
- Example: `168.192.2.200`
|
||||||
|
- **port**: The port of rs485 to ETH Adapter.
|
||||||
|
- Example: `4196`
|
||||||
|
|
||||||
### MQTT Broker Settings
|
### MQTT Broker Settings
|
||||||
|
|
||||||
- **broker-url**: The URL of the MQTT broker.
|
- **broker-url**: The URL of the MQTT broker.
|
||||||
@@ -214,15 +223,18 @@ The `config.yml` file contains configuration settings for the EHS-Sentinel proje
|
|||||||
```yaml
|
```yaml
|
||||||
general:
|
general:
|
||||||
nasaRepositoryFile: data/NasaRepository.yml
|
nasaRepositoryFile: data/NasaRepository.yml
|
||||||
protocolFile: prot.csv
|
# protocolFile: prot.csv
|
||||||
logging:
|
logging:
|
||||||
deviceAdded: True
|
deviceAdded: True
|
||||||
messageNotFound: False
|
messageNotFound: False
|
||||||
packetNotFromIndoorOutdoor: False
|
packetNotFromIndoorOutdoor: False
|
||||||
proccessedMessage: False
|
proccessedMessage: False
|
||||||
serial:
|
#serial:
|
||||||
device: /dev/ttyUSB0
|
# device: /dev/ttyUSB0
|
||||||
baudrate: 9600
|
# baudrate: 9600
|
||||||
|
tcp:
|
||||||
|
ip: 168.192.2.200
|
||||||
|
port: 4196
|
||||||
mqtt:
|
mqtt:
|
||||||
broker-url: 123.45.6.69
|
broker-url: 123.45.6.69
|
||||||
broker-port: 1883
|
broker-port: 1883
|
||||||
@@ -267,6 +279,9 @@ if you want to see how many uniquie Messages have been collected in the Dumpfile
|
|||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### v0.2.2 - 2025-02-24
|
||||||
|
- Support for rs485 to ETH Adapter, tcp options instead of serial port are possible now
|
||||||
|
|
||||||
### v0.2.1 - 2025-02-22
|
### v0.2.1 - 2025-02-22
|
||||||
- limit NASA_EHSSENTINEL_COP and NASA_EHSSENTINEL_TOTAL_COP to values between 0 and 20
|
- limit NASA_EHSSENTINEL_COP and NASA_EHSSENTINEL_TOTAL_COP to values between 0 and 20
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ logging:
|
|||||||
serial:
|
serial:
|
||||||
device: /dev/ttyUSB0
|
device: /dev/ttyUSB0
|
||||||
baudrate: 9600
|
baudrate: 9600
|
||||||
|
tcp:
|
||||||
|
ip: 168.192.2.200
|
||||||
|
port: 4196
|
||||||
mqtt:
|
mqtt:
|
||||||
broker-url: 111.111.11.1
|
broker-url: 111.111.11.1
|
||||||
broker-port: 1883
|
broker-port: 1883
|
||||||
|
|||||||
@@ -115,36 +115,31 @@ async def serial_connection(config, args):
|
|||||||
"""
|
"""
|
||||||
Asynchronously reads data from a serial connection and processes it.
|
Asynchronously reads data from a serial connection and processes it.
|
||||||
Args:
|
Args:
|
||||||
config (object): Configuration object containing serial connection parameters.
|
config (object): Configuration object containing serial or tcp connection parameters.
|
||||||
args (object): Additional arguments for buffer processing.
|
args (object): Additional arguments for buffer processing.
|
||||||
This function establishes a serial connection using parameters from the config object,
|
This function establishes a serial or tcp connection using parameters from the config object,
|
||||||
reads data from the serial port until a specified delimiter (0x34) is encountered,
|
reads data from the serial port or tcp port until a specified delimiter (0x34) is encountered,
|
||||||
and appends the received data to a buffer. It also starts an asynchronous task to
|
and appends the received data to a buffer. It also starts an asynchronous task to
|
||||||
process the buffer.
|
process the buffer.
|
||||||
The serial connection is configured with the following parameters:
|
The function runs an infinite loop to continuously read data from the serial port/tcp port.
|
||||||
- Device URL: config.SERIAL['device']
|
|
||||||
- Baudrate: config.SERIAL['baudrate']
|
|
||||||
- Parity: Even
|
|
||||||
- Stopbits: One
|
|
||||||
- Bytesize: Eight
|
|
||||||
- RTS/CTS flow control: Enabled
|
|
||||||
- Timeout: 0
|
|
||||||
The function runs an infinite loop to continuously read data from the serial port.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
buffer = []
|
buffer = []
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
reader, writer = await serial_asyncio.open_serial_connection(
|
if config.TCP is not None:
|
||||||
loop=loop,
|
reader, writer = await asyncio.open_connection(config.TCP['ip'], config.TCP['port'])
|
||||||
url=config.SERIAL['device'],
|
else:
|
||||||
baudrate=config.SERIAL['baudrate'],
|
reader, writer = await serial_asyncio.open_serial_connection(
|
||||||
parity=serial.PARITY_EVEN,
|
loop=loop,
|
||||||
stopbits=serial.STOPBITS_ONE,
|
url=config.SERIAL['device'],
|
||||||
bytesize=serial.EIGHTBITS,
|
baudrate=config.SERIAL['baudrate'],
|
||||||
rtscts=True,
|
parity=serial.PARITY_EVEN,
|
||||||
timeout=1
|
stopbits=serial.STOPBITS_ONE,
|
||||||
)
|
bytesize=serial.EIGHTBITS,
|
||||||
|
rtscts=True,
|
||||||
|
timeout=1
|
||||||
|
)
|
||||||
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
serial_read(reader, args, config),
|
serial_read(reader, args, config),
|
||||||
|
|||||||
Reference in New Issue
Block a user