Physical computing ︰《四》 Serial Port ︰ 3. 攔截竄訊‧中

在《知識是什麼?》一文中,我們談過柏拉圖的『洞穴寓言』,據聞『需要為發明之母』與 Plato 理想國有關︰ Proverb / 諺語 Necessity is the mother of invention, means

Difficult situations inspire ingenious solutions.

也許看過『羅倫佐的油』的人,自能體會;然而今天令人很懷疑『★★才是○○』的吧!!

此處我們將簡單扼要介紹 Freddy Spierenburg 先生,在二零零四年夏天所寫的『 jpnevulator 』  Jackpot Navigator emulator

假使你讀《 README 》── Why this program ?

如果你看《 INSTALL 》 ── How to build the program ?

要是你查《 jpnevulator 》── If you have a question, please first read the FAQ.

你將知道『使用』的第一步︰

FAQ
===

This is actually a quiet lousy FAQ with only one question answered. But the truth is that only one question is asked frequently.

Q: Your serial tool seems to block my application. What am I doing wrong?

A: First the bad news: It’s impossible for two GNU/Linux processes to open the same serial port at the same time. Doing so results in undefined behaviour like you just experienced.

Jpnevulator was never built to sit in between the kernel and your
application. I’m sorry.

The way I have used Jpnevulator over and over again, was with a special self (not entirely myself, but a colleague of mine) made device that sort of sits in between a serial cable. Out of the device comes another serial cable that mirrors everything that is sent over the original serial cable. A sort of man in the middle.

Now with a little bit of luck some good news: A little while ago Eric Shattow suggested to use pseudo-terminal devices to sit in between the kernel and your application. Unfortunately it’s still impossible to work with speed changes that way and hence Eric never replied when I asked him what he did think of the solution I provided to him. So this pseudo-terminal device support is not tested very well, only in a limited way by me. It works and I think it’s even relatively easy to use stty to detect speed changes and act upon it. I leave that as an exercise to the reader, but I would love to hear from anyone having done it.

你會了解

# raspbian 的目前版本
apt-cache show jpnevulator
Package: jpnevulator
Version: 1.3.1-1
Architecture: armhf
Maintainer: Freddy Spierenburg <freddy@snarl.nl>
Installed-Size: 67
Depends: libc6 (>= 2.4)
Homepage: http://jpnevulator.snarl.nl/
Priority: optional
Section: comm
Filename: pool/main/j/jpnevulator/jpnevulator_1.3.1-1_armhf.deb
Size: 19266
SHA256: eb6fe746049fe2993a4049d7422bd66ac19e2703f4fe43e9f0349b8259259d7e
SHA1: fd30874b6789fd26cdd30c1781fb6e4803d8c754
MD5sum: 61fb064effdf71877c92854ae51c39e5
Description: Serial sniffer
 jpnevulator is a handy serial sniffer. You can use it to send data on a
 serial device too. You can read or write from/to one or more serial
 devices at the same time.
 .
 In write mode data to be sent on the serial device(s) is read from a
 file or stdin in hexadecimal notation. Data is sent on the serial
 device(s) line by line.
 .
 In read mode data to be read from the serial device(s) is written to a
 file or stdout in hexadecimal notation. It's even possible to pass the
 data in between the serial device(s). Several options enhance the
 way the data is displayed.

# 自己編譯
wget http://jpnevulator.snarl.nl/download/jpnevulator-2.1.3.tgz
tar -zxvf jpnevulator-2.1.3.tgz
cd jpnevulator-2.1.3/
make
sudo make install

# 檢查
jpnevulator -v
jpnevulator version 2.1.3
Copyright (C) 2006-2014 Freddy Spierenburg <freddy@snarl.nl>
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

# 使用手冊
man jpnevulator

 

── 也許,吉人之辭寡,躁人之辭多的吧 ──