Simulator
Download
Pre-compiled binaries for some platforms are available here:
The source code is available as a patch (against the libdivecomputer source) or a complete tarball. (Note this is based on a fairly old version of the libdivecomputer source code.)
Serial setup
To use the simulator, you need two serial ports connected with a nullmodem cable. If you do not have the necessary hardware, you can also use a software solution to emulate a virtual nullmodem cable.
Windows
On Windows, I have used these applications with success:
- com0com (open source)
- Eltima Virtual Serial Port Driver (commercial)
From my personal experience, com0com does work well most of the time. For some unknown reason, certain applications (e.g. Suunto Dive Manager) fail to detect the com0com virtual ports, and you'll have to use another solution. Performance of the Eltima VSPD appears to be better sometimes.
Linux
On linux systems you can use a pair of pseudo terminals as a virtual nullmodem cable. You can use one of the ttypatch or socat applications.
socat PTY,link=/tmp/ttyS0 PTY,link=/tmp/ttyS1
The major disadvantage is that these pseudo terminals do not support all
functionallity of real serial hardware, such as the DTR and RTS lines. However,
for local testing, you can build libdivecomputer with the --enable-pty
option to change these functions into no-ops. For socat, there appears to
be a patch to
support this too, but I haven't tested it.
Virtualization software
If you are testing your code inside a virtual machine, you can let the virtualization software emulate the serial ports and the nullmodem cable.
Virtualbox
Add two serial ports (COM1 and COM2) to your virtual machine, and choose the
"Host Pipe" mode for both. Make sure the "Create pipe" checkbox is enabled for
the first port, but not for the second one. For the paths, choose two
non-existing files like /tmp/ttyS0
and /tmp/ttyS1
. Now, create
the second file as a symlink to the first one: ln -s /tmp/ttyS0
/tmp/ttyS1
. The symlink is required because virtualbox does not allow to
use the same filename for both serial ports. The symlink is a workaround for
this limitation.
Vmware
In VMware you can add 2 serial ports and using the same named pipe as source
and destination. To do this: Edit your virtual machine, go to the hardware tab,
add 2 serial ports with the serial port type set to "Output to named pipe",
give both serial ports the same location (for windows named pipes must begin
with '\\.\pipe\'
(e.g. '\\.\pipe\com_1'
) with one serial port
set to "this end is the server" and the other "this end is the client" and for
the last option leave it to the default: "the other end is a virtual
machine"
IrDA setup
For IrDA support you'll have to do an addititonal step to attach the IrDA subsystem to the (virtual) serial ports. The Uwatec Smart/Galileo (which is currently the only backend requiring IrDA support), also needs to have a specific name. I discovered that everything works fine if the name contains the string "Uwatec", so that's what I use.
Windows
On windows, go to the "Add new hardware" wizard and install the "IrDA over serial cable" driver. When the installation asks for a serial port, use one of the nullmodem ports, and repeat the procedure for the second port. Windows should now be able to recognize an IrDA device. Because of the nullmodem cable setup, it does detect itself as an IrDA device!
You'll also need to change the hostname to "Uwatec" and reboot.
Linux
On linux, you should run the commands irattach /tmp/ttyS0
and
irattach /tmp/ttyS1
(as root).
To set the IrDA device name to "Uwatec", you should run the command:
echo Uwatec > /proc/sys/net/irda/devname
(as root).