Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-UTF-8 characters raise exception #10

Open
esev opened this issue Sep 20, 2024 · 0 comments · May be fixed by #11
Open

Non-UTF-8 characters raise exception #10

esev opened this issue Sep 20, 2024 · 0 comments · May be fixed by #11

Comments

@esev
Copy link

esev commented Sep 20, 2024

A mail message containing 8-bit ASCII graphics caused an unhandled exception.

Traceback (most recent call last):                                                                             
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/esev/paracon_1.1.0.pyz/__main__.py", line 3, in <module>
  File "/home/esev/paracon_1.1.0.pyz/paracon.py", line 1473, in run
  File "/home/esev/paracon_1.1.0.pyz/paracon.py", line 1015, in run
  File "/home/esev/paracon_1.1.0.pyz/urwid/event_loop/main_loop.py", line 337, in run
  File "/home/esev/paracon_1.1.0.pyz/urwid/event_loop/main_loop.py", line 439, in _run
  File "/home/esev/paracon_1.1.0.pyz/urwid/event_loop/select_loop.py", line 182, in run
  File "/home/esev/paracon_1.1.0.pyz/urwid/event_loop/select_loop.py", line 224, in _loop
  File "/home/esev/paracon_1.1.0.pyz/urwid/event_loop/main_loop.py", line 218, in cb
  File "/home/esev/paracon_1.1.0.pyz/paracon.py", line 952, in cb
  File "/home/esev/paracon_1.1.0.pyz/paracon.py", line 587, in _update_from_queue
  File "/home/esev/paracon_1.1.0.pyz/paracon.py", line 594, in _gather_lines
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 46: invalid start byte

The direwolf logs capture the offending line:

<0x0d>To get the right RF level into the 75<0xea> VCR input, an MF amplifier will be<0x0d>

The message itself gave a hint about the cause: (8 Bit ASCII graphics use code page 437 or 850, Terminal Font)

Decoding the line with cp437 produces the expected result:

>>> b'\x0dTo get the right RF level into the 75\xea VCR input, an MF amplifier will be\x0d'.decode('cp437')
'\rTo get the right RF level into the 75Ω VCR input, an MF amplifier will be\r'

I'm not sure this is the best fix, but this worked for me. I was able to view the message including the ASCII graphics.

diff --git a/paracon/paracon.py b/paracon/paracon.py
index 2ec1a1a..9eaafd2 100644
--- a/paracon/paracon.py
+++ b/paracon/paracon.py
@@ -591,7 +591,10 @@ class ConnectionPanel(urwid.WidgetWrap):
 
     def _gather_lines(self, data):
         if not isinstance(data, str):
-            data = data.decode('utf-8')
+            try:
+                data = data.decode('utf-8')
+            except UnicodeDecodeError:
+                data = data.decode('cp437')
         parts = data.split('\r')
         if len(self._line_remains):
             parts[0] = self._line_remains + parts[0]
3) K3SEV de N0ARY [0]>
r 28789
=============================================================
      Date: 19 Sep 2024 08:30
 Message #: 28789
       BID: <16351_GB7CIP>
      From: G8MNY@GB7CIP
        To: TECH@WW
   Subject: Recording whole LF + MF bands

N6RME!I0OJJ!LU4ECL!UA6ADV!CX2SA!GB7CIP
-------------------------------------------------------------


From: G8MNY@GB7CIP.#32.GBR.EURO
To  : TECH@WW

By G8MNY                                  (Updated Feb 10)
(8 Bit ASCII graphics use code page 437 or 850, Terminal Font)

Here is a system for recording 100kHz - 3MHz on an old VCR. A VCR can record
40dB Signal to Noise over that whole DC - 3MHz bandwidth, or 70dB S/N in each
==== More ... [CR] next page, [Q]uit, [S]croll, [!cmd] ====>3kHz, & that equates to about 60dB S/N in each 9kHz AM channel!

Old VCRs (not HiFi) are best for this, provided the tape speed & head drum are
still good, as they do less cleaver video processing than later ones, so there
is less to corrupt the RF signal.

To get the right RF level into the 75Ω VCR input, an MF amplifier will be
needed. Here a simple NPN follower to do that using any MF transistor. If you
look at the VCR signal on a monitor you should see noise & patterning as bright
as a normal picture, the VCR will have a few dB of AGC as well to keep the
levels approximately right.

CIRCUIT
              ┌────┬───────────────┬─100R──<+12V
Wire  \│/    68K   │               │
Aerial │      │  │/            u1 ===
       └───┤├─┴──┤BC108            │
        100pF    │\e               │ 
                   │        10n    │
                 470R<────┤├────┐  │
q
b
Disconnected (00:02:21)
@esev esev linked a pull request Sep 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant