Browse Source

Replaced all instances of kiss with kiss2

Stephen Downward 1 year ago
parent
commit
cdcf091541
1 changed files with 34 additions and 30 deletions
  1. 34 30
      kiss2/classes.py

+ 34 - 30
kiss2/classes.py

@ -8,7 +8,7 @@ import socket
8 8
9 9
import serial
10 10
11
import kiss
11
import kiss2
12 12
13 13
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
14 14
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
@ -21,10 +21,10 @@ class KISS(object):
21 21
22 22
    _logger = logging.getLogger(__name__)  # pylint: disable=R0801
23 23
    if not _logger.handlers:  # pylint: disable=R0801
24
        _logger.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
24
        _logger.setLevel(kiss2.LOG_LEVEL)  # pylint: disable=R0801
25 25
        _console_handler = logging.StreamHandler()  # pylint: disable=R0801
26
        _console_handler.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
27
        _console_handler.setFormatter(kiss.LOG_FORMAT)  # pylint: disable=R0801
26
        _console_handler.setLevel(kiss2.LOG_LEVEL)  # pylint: disable=R0801
27
        _console_handler.setFormatter(kiss2.LOG_FORMAT)  # pylint: disable=R0801
28 28
        _logger.addHandler(_console_handler)  # pylint: disable=R0801
29 29
        _logger.propagate = False  # pylint: disable=R0801
30 30
@ -45,7 +45,7 @@ class KISS(object):
45 45
        """
46 46
        Helper method to call when reading from KISS interface.
47 47
        """
48
        read_bytes = read_bytes or kiss.READ_BYTES
48
        read_bytes = read_bytes or kiss2.READ_BYTES
49 49
50 50
    def _write_handler(self, frame=None):  # pylint: disable=R0201
51 51
        """
@ -82,14 +82,14 @@ class KISS(object):
82 82
83 83
        return self.interface.write(
84 84
            b''.join([
85
                kiss.FEND,
86
                bytes(getattr(kiss, name.upper())),
87
                kiss.escape_special_codes(value),
88
                kiss.FEND
85
                kiss2.FEND,
86
                bytes(getattr(kiss2, name.upper())),
87
                kiss2.escape_special_codes(value),
88
                kiss2.FEND
89 89
            ])
90 90
        )
91 91
92
    def read(self, read_bytes=None, callback=None, readmode=True, blocking=True):  # NOQA pylint: disable=R0912
92
    def read(self, read_bytes=None, callback=None, readmode=True):  # NOQA pylint: disable=R0912
93 93
        """
94 94
        Reads data from KISS device.
95 95
@ -106,7 +106,8 @@ class KISS(object):
106 106
107 107
        read_buffer = bytes()
108 108
109
        while blocking:
109
        while True:
110
110 111
            read_data = self._read_handler(read_bytes)
111 112
112 113
            if read_data is not None and len(read_data):
@ -115,7 +116,7 @@ class KISS(object):
115 116
116 117
                frames = []
117 118
118
                split_data = read_data.split(kiss.FEND)
119
                split_data = read_data.split(kiss2.FEND)
119 120
                fends = len(split_data)
120 121
121 122
                self._logger.debug(
@ -123,7 +124,7 @@ class KISS(object):
123 124
124 125
                # Handle NMEAPASS on T3-Micro
125 126
                if len(read_data) >= 900:
126
                    if kiss.NMEA_HEADER in read_data and '\r\n' in read_data:
127
                    if kiss2.NMEA_HEADER in read_data and '\r\n' in read_data:
127 128
                        if callback:
128 129
                            callback(read_data)
129 130
                        elif not readmode:
@ -162,15 +163,15 @@ class KISS(object):
162 163
                        read_buffer = bytearray(split_data[fends - 1])
163 164
164 165
                # Fixup T3-Micro NMEA Sentences
165
                frames = list(map(kiss.strip_nmea, frames))
166
                frames = list(map(kiss2.strip_nmea, frames))
166 167
                # Remove None frames.
167 168
                frames = [_f for _f in frames if _f]
168 169
169 170
                # Maybe.
170
                frames = list(map(kiss.recover_special_codes, frames))
171
                frames = list(map(kiss2.recover_special_codes, frames))
171 172
172 173
                if self.strip_df_start:
173
                    frames = list(map(kiss.strip_df_start, frames))
174
                    frames = list(map(kiss2.strip_df_start, frames))
174 175
175 176
                if readmode:
176 177
                    for frame in frames:
@ -186,15 +187,15 @@ class KISS(object):
186 187
        """
187 188
        self._logger.debug('frame(%s)="%s"', len(frame), frame)
188 189
189
        frame_escaped = kiss.escape_special_codes(frame)
190
        frame_escaped = kiss2.escape_special_codes(frame)
190 191
        self._logger.debug(
191 192
            'frame_escaped(%s)="%s"', len(frame_escaped), frame_escaped)
192 193
193 194
        frame_kiss = b''.join([
194
            kiss.FEND,
195
            kiss.DATA_FRAME,
195
            kiss2.FEND,
196
            kiss2.DATA_FRAME,
196 197
            frame_escaped,
197
            kiss.FEND
198
            kiss2.FEND
198 199
        ])
199 200
        self._logger.debug(
200 201
            'frame_kiss(%s)="%s"', len(frame_kiss), frame_kiss)
@ -212,10 +213,13 @@ class TCPKISS(KISS):
212 213
        super(TCPKISS, self).__init__(strip_df_start)
213 214
214 215
    def _read_handler(self, read_bytes=None):
215
        read_bytes = read_bytes or kiss.READ_BYTES
216
        read_data = self.interface.recv(read_bytes)
217
        self._logger.debug('len(read_data)=%s', len(read_data))
218
        return read_data
216
        read_bytes = read_bytes or kiss2.READ_BYTES
217
        try:
218
            read_data = self.interface.recv(read_bytes)
219
            self._logger.debug('len(read_data)=%s', len(read_data))
220
            return read_data
221
        except socket.timeout:
222
            return None
219 223
220 224
    def stop(self):
221 225
        if self.interface:
@ -244,7 +248,7 @@ class SerialKISS(KISS):
244 248
        super(SerialKISS, self).__init__(strip_df_start)
245 249
246 250
    def _read_handler(self, read_bytes=None):
247
        read_bytes = read_bytes or kiss.READ_BYTES
251
        read_bytes = read_bytes or kiss2.READ_BYTES
248 252
        read_data = self.interface.read(read_bytes)
249 253
        if len(read_data) > 0:
250 254
            self._logger.debug('len(read_data)=%s', len(read_data))
@ -274,15 +278,15 @@ class SerialKISS(KISS):
274 278
        Xastir.
275 279
        """
276 280
        return self._write_defaults(
277
            **kiss.DEFAULT_KISS_CONFIG_VALUES)
281
            **kiss2.DEFAULT_KISS_CONFIG_VALUES)
278 282
279 283
    def kiss_on(self):
280 284
        """Turns KISS ON."""
281
        self.interface.write(kiss.KISS_ON)
285
        self.interface.write(kiss2.KISS_ON)
282 286
283 287
    def kiss_off(self):
284 288
        """Turns KISS OFF."""
285
        self.interface.write(kiss.KISS_OFF)
289
        self.interface.write(kiss2.KISS_OFF)
286 290
287 291
    def stop(self):
288 292
        try:
@ -303,7 +307,7 @@ class SerialKISS(KISS):
303 307
        """
304 308
        self._logger.debug('kwargs=%s', kwargs)
305 309
        self.interface = serial.Serial(self.port, self.speed)
306
        self.interface.timeout = kiss.SERIAL_TIMEOUT
310
        self.interface.timeout = kiss2.SERIAL_TIMEOUT
307 311
        self._write_handler = self.interface.write
308 312
        self._write_defaults(**kwargs)
309 313
@ -312,5 +316,5 @@ class SerialKISS(KISS):
312 316
        Initializes the KISS device without writing configuration.
313 317
        """
314 318
        self.interface = serial.Serial(self.port, self.speed)
315
        self.interface.timeout = kiss.SERIAL_TIMEOUT
319
        self.interface.timeout = kiss2.SERIAL_TIMEOUT
316 320
        self._write_handler = self.interface.write