Commit 7d29d1f8 authored by gophi's avatar gophi

initial commit

git-svn-id: 8cc89244-2450-4880-90d3-191243f3a0b0
/* $Id$ */
- fixed silly bug in endianness handling code
- changed endianness-related code to compile on MacOSX (thx Tod Fitch)
- changed maximum non-bogus UHF frequency from 500 to 600 MHz (thx Tod Fitch)
- added UVD3 welcome message editing (thx SQ5LWN)
- removed references in some places in export code
- exported FromHexOne() in Util namespace
- added encoding and decoding of frequency ranges (thx K7DB)
- added Apache 2.0 license to README
- added support for DCS and TEAM 2 to TODO
- fixed bug when importing channels (were imported 127, not 128)
- fixed bug in makefile (added -f to ln)
- changed tcdrain and program_invocation_short_name for cygwin compatibility
- added FM radio import/export
- added support for .tw files to TODO
- minor changes in the code and README
- added cstdio include to some files (thanks ur6lad)
- minor changes in README file
- RSS feed for changelog
- complete rewrite
- initial release as a little utility
# $Id$
.PHONY: all
cd src && $(MAKE) all
.PHONY: install
cd src && $(MAKE) install
.PHONY: clean
cd src && $(MAKE) clean
Apache License
Version 2.0, January 2004
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
implied, including, without limitation, any warranties or conditions
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
/* $Id$ */
Wouxun protocol information.
File written by SP5GOF using information reverse-engineered by SQ5LWN.
Communication parameters are 9600 8n1, with flow control disabled.
After you connect, you must send: "HiWOUXUN" (without quotes and null)
and 0x02. Radio will acknowledge by sending back: 0x06. After that you
send 0x02, radio acknowledges with 0x06 and sends back it's ID string
(6 bytes, "KG669V") and 0xF8. We're not sure what 0xF8 means - maybe
some kind of software revision or similar?
After this handshake you can download (read) and upload (write) memory
pages by sending 4-byte commands:
1 byte: command
2 bytes: address (little endian)
1 byte: size
For reading, use command 'R' and size 0x40. For writing, use command 'W'
and size 0x10. After write command send 16 (0x10) bytes in raw binary.
After you send write command, radio will acknowledge it with ACK byte
After you send read command, radio will acknowledge it by re-sending your
command string back to you with command reversed, so 'R' becomes 'W'.
After this 64 (0x40) bytes of raw binary data will follow. After receiving
you must send ACK (0x06) byte and radio will reply with 0x06 byte.
Wouxun memory map can be found on SQ5LWN page:
/* $Id$ */
1. About this program
2. Authors, webpage, credits, license
3. Interface
4. Compilation and installation
5. Usage
5.1. owx-check
5.2. owx-get
5.3. owx-put
5.4. owx-export
5.5. owx-import
6. Spreadsheet format
6.1. Channel table
6.1.1. CH
6.1.2. Name
6.1.3. RX & TX Frequency
6.1.4. RX & TX CTCSS
6.1.5. Deviation
6.1.6. TX Power
6.1.7. Scan
6.1.8. BCL
6.2. Frequency ranges
6.3. FM radio
6.4. UVD3 welcome message
1. About this program
OWX (Open Wouxun) is an open-source program designed to program Wouxun
transceivers. It was developed on Wouxun KG-UV2D and tested on KG-UVD1P
(both identify as KG669V). Possibly other Wouxuns are supported too, but
this is not guaranteed - use at your own risk and ALWAYS make backups!
This software is highly experimental. Using it can result in rendering
your radio unusable and your dog killed. You have been warned.
Utility was developed on GNU/Linux with gcc 4.3.2, but ports to other
systems can (and should!) be made. It was tested only on i386, but is
written with endianness in mind and should run on BE machines as well
(but it was never tested and some bugs are possible).
It communicates only in english, but is prepared to handle i18n if someone
wants to. Please see intl.h file for details.
Utility has five functions. They are used to:
- check radio connection
- download binary data from radio
- upload binary data to radio
- export human-readable spreadsheet from binary data file
- import edited spreadsheet into existing binary data file
Binary data contains everything that can be changed in the radio - all
settings, channels, current modes of operation etc.
Please also see the TODO file to see what this software can NOT do!
2. Authors, webpage, credits, license
Program was written by SP5GOF (Adam Wysocki, gof (at)
Newest version can be downloaded from
Reverse-engineering, protocol information and initial testing were done
by SQ5LWN (Lukasz Mozer, baseciq (at)
You can also try to reach us on SR5WW repeater and 145.525 MHz near KO02mf
(Warsaw, Poland).
Program is licensed under beer-ware license. We're HAMs and not lawyers,
so no law hell applies here (nobody really reads licenses anyways), just
pure HAM spirit. You are free to do with this program whatever you like,
just be nice and don't remove the original authorship - that would be a
bit shitty. If you feel that this code is worth this, you can just shout
us some beer.
If you don't like the beer-ware license, like, if you prefer fruity
drinks or something, you can use the Apache 2.0 license instead.
Regardless of this, one thing must be said: we cannot be made responsible
for breaking your radio with this program. Everything you do, you do at
your own risk and by using this program you agree not to fill any lawsuit
against us if your rig explodes right in front of your face.
3. Interface
To connect your rig to the PC, you will need any standard RS232/TTL
converter with MAX232 or similar. Schematics etc. can be found on
Google. You can also adapt some old cellular phone cable or buy a
dedicated cable on your favourite bidding service.
2.5mm (speaker):
- shield: gnd
- ring: radio tx (out)
- tip: not connected
3.5mm (microphone):
- shield: radio rx (in)
- ring: not connected
- tip: not connected
4. Compilation and installation
Standard GNU make command will do the stuff. Program was written in C++
with heavy usage of STL, so you will need g++ with standard libraries,
and of course GNU make. After compilation use "make install" to install
the program in /usr/local/.
5. Usage
Before you begin, it may be convenient to set OWX_PORT environmental
variable in ~/.bashrc or similar shell rc file. With this variable
you can specify default port instead of using -p. You can also set
OWX_TIMEOUT to use alternate default when -t is not specified.
After installation you will find five programs in /usr/local/bin:
They are all symlinks to one executable - /usr/local/libexec/owx.
All programs return 0 when everything goes okay and 1 when error occurs.
Programs accept these common options:
-c <cmd>: override command (check, get, put, export, import)
-h: fast help
-v: version string
You will almost never use -c command - if it's used, you can use one
command (owx-get) to perform another task. It is mandatory only when
you run main binary and not the symlinks.
Programs that communicate with the radio (owx-check, owx-get and owx-put)
accept these options:
-f: force even if radio is not recognized
-p <port>: specify port
-t <timeout>: receive timeout in seconds
-f can force the operation if your radio identifies different from KG669V.
Use this option with extreme caution - it is very possible that your radio
will be rendered unusable after you use this. It was NEVER tested with any
radio different from mentoined above.
-p specifies path to the tty device, i.e. /dev/ttyS0 or /dev/ttyUSB0. Of
course you must have appropriate read and write permissions for this device.
-t specifies receive timeout for communication with radio. If you disable
it (by setting to 0) and the communication fails, the program will hang
forever. You probably don't need to change the default value (5 seconds).
5.1. owx-check
This program just checks for the connection and identification string. It
can be used to check that your cable and port works.
5.2. owx-get
This program downloads memory map from radio to binary file.
-o <path>: binary file to write to
5.3. owx-put
This program uploads memory map from binary file to radio.
-i <path>: binary file to read from
-r <path>: reference file
Option -r is not mandatory, but recommended. You can specify original,
unchanged file (exactly as downloaded using owx-get) and this will speed
up memory uploading, as owx will compare input file to this reference
file and upload only changed memory pages. When using this option, be
sure that nothing has changed in the radio (even the currently selected
memory channel) between downloading reference file and using it for
upload. This is important as some variables that cross the page
boundaries (if there are any in the memory map) could be corrupted
by this.
owx-get -o file.bin
cp file.bin backup.bin
owx-export -i file.bin -o wouxun.csv
oocalc wouxun.csv
owx-import -i wouxun.csv -o file.bin
owx-put -i file.bin -r backup.bin
Please do yourself a favour and double-check that you upload the correct
file. If you try to upload incorrect or corrupted file, your radio will
power down and fail to power up. owx will refuse to upload any file with
incorrect size, but this is the only safety check.
5.4. owx-export
This program exports channel data from binary file to CSV file. This file
can be later edited using your favourite spreadsheet editor or even text
-i <path>: binary file to read from
-o <path>: csv file to write to
5.5. owx-import
This program reads the specified, possibly edited by you CSV file, and
patches existing binary file with this updated data. The file is now
prepared to be uploaded with owx-put.
-i <path>: csv file to read from
-o <path>: binary file to write to (must already exist)
6. Spreadsheet format
When importing to a spreadsheet editor, import all fields as text (to
make sure that your editor will not try to interpret anything). Then
you will see the channel table and below it, frequency ranges.
6.1. Channel table
Channel table fields are as follows:
6.1.1. CH
This is the channel number. Do not change.
6.1.2. Name
Channel name. Max 6 characters, only letters and digits. Lowercase letters
will be converted to uppercase.
6.1.3. RX & TX Frequency
Frequencies in format XXX.YYYYY (for example "145.52500"). They must strictly
follow this format (another reason to import fields as text).
6.1.4. RX & TX CTCSS
PL subtone. Format is XX.Y or XXX.Y (for example: "127.3").
6.1.5. Deviation
Can be "narrow" or "wide", for narrow-band FM and wide-band FM.
6.1.6. TX Power
Can be "low" for 1W and "high" for 5W (on VHF) or 4W (on UHF).
6.1.7. Scan
Can be "yes" to include this channel in scanning and "no" to skip.
6.1.8. BCL
Can be "yes" to enable BCL (Busy Channel Lockout) on this channel and "no"
otherwise. BCL prevents you from TX-ing when the channel is busy (squelch
6.2. Frequency ranges
There are eight values below the channel table. They correspond to the RX
and TX ranges on both bands. By editing them, you can unlock your radio
(change it's transmit and receive range), but it's easy to kill your radio
by setting invalid values. If the ranges are invalid, the rig will refuse
to turn on, probably due to busy-waiting for the PLL loop to lock. YOU WILL
this way and in order to bring it back to life I had to open it, disable the
MCU (I just disabled it's clock), connect to the memory I2C bus and manually
reprogram it. If you lack appropriate equipment or skills you definitely
don't want to do this.
OWX performs some basic checks on the ranges when importing and warns you
if any value seems to be bogus, but it doesn't check the ranges (if you mess
with their order). Also, bugs in the importing routine are possible. If you
see any warning during importing, consider contacting me before putting the
resulting file to the radio, as it is easy to brick the radio and not so
easy to bring it back to life.
If instead of frequencies you see some hexadecimal values (0xABCD or so)
then the decoder (used when exporting) found unexpected pattern and refused
to decode the value. Please contact me and provide these raw values. It
should be safe to program them back to the radio, but don't change them
(they're encoded).
6.3. FM radio
Below frequency ranges there are nine FM broadcast radio channels. You can
use syntax XX.Y or XXX.Y (example: "101.5") to program broadcast FM radio.
6.4. UVD3 welcome message
KG-UVD3 allows you to edit welcome message - max 6 ascii characters. In UVD1
and UVD2 this memory area is ignored.
/* $Id$ */
- use some version control system (possibly SVN; files already have rcsid tags)
- discover how frequency ranges are coded
- add support to Windows .tw files
- add support to DCS
- add support to TEAM 2 broadcast bank
- port autodetection (probably as a shell script)
- make installation more flexible (instead of hard-coded /usr/local/)
- install documentation as well as binaries
- write manual page/pages
- some autoconf/automake machinery (is it really needed?)
- i18n (see intl.h)
- grep for xxx in sources - these are places to return to
# $Id$
NAME = owx
CXX = /usr/bin/g++
RM = rm -f
INSTALL = install
LN = ln
LIBXDIR = /usr/local/libexec/
BINDIR = /usr/local/bin/
CXXFLAGS= -pipe -Wall -Wextra -O2 -g
OBJS = owx.o cli.o throw.o cmds.o wouxun.o comm.o file.o csv.o export.o import.o util.o
SRCS = $(
.PHONY: all
all: dep $(NAME)
$(NAME): $(OBJS)
.PHONY: dep
dep: .depend
.depend: $(SRCS)
$(CXX) -MM $(CXXFLAGS) $(SRCS) 1> .depend
.PHONY: install
install: all
$(INSTALL) -m 755 $(NAME) $(LIBXDIR)
$(LN) -f -s $(LIBXDIR)$(NAME) $(BINDIR)$(NAME)-check
$(LN) -f -s $(LIBXDIR)$(NAME) $(BINDIR)$(NAME)-get
$(LN) -f -s $(LIBXDIR)$(NAME) $(BINDIR)$(NAME)-put
$(LN) -f -s $(LIBXDIR)$(NAME) $(BINDIR)$(NAME)-export
$(LN) -f -s $(LIBXDIR)$(NAME) $(BINDIR)$(NAME)-import
.PHONY: clean
$(RM) $(OBJS) $(NAME) .depend
.PHONY: install
ifneq ($(wildcard .depend),)
include .depend
/* $Id$ */
#include <unistd.h>
#include "throw.h"
#include "intl.h"
#include "cli.h"
CCli::CCli(int ac, char * const av[], const char *optstring)
opterr = 0;
for (;;)
int rs(getopt(ac, av, optstring));
if (rs == -1)
if (rs == '?')
Throw(_("CLI: -%c: Invalid option"), optopt);
if (rs == ':')
Throw(_("CLI: -%c: Missing argument"), optopt);
m_data[rs] = (optarg && *optarg) ? optarg : "";
for (int i(optind); i < ac; ++i)
bool CCli::Avail(const char &key) const
return m_data.find(key) != m_data.end();
const std::string &CCli::Param(const char &key) const
return m_data.find(key)->second;
size_t CCli::RestSize() const
return m_rest.size();
const std::string &CCli::Rest(size_t i) const
return m_rest[i];
/* $Id$ */
#pragma once
#include <string>
#include <vector>
#include <map>
class CCli
std::map<char, std::string> m_data;
std::vector<std::string> m_rest;
CCli(int ac, char * const av[], const char *optstring);
bool Avail(const char &key) const;
const std::string &Param(const char &key) const;
size_t RestSize() const;
const std::string &Rest(size_t i) const;
/* $Id$ */
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include "wouxun.h"
#include "impexp.h"
#include "throw.h"
#include "intl.h"
#include "file.h"
#include "cmds.h"
#include "csv.h"
#define MEMORY_SIZE 0x2000
static void RejectOptions(const CCli &cli, const std::string forbidden)
for (std::string::const_iterator i(forbidden.begin()); i != forbidden.end(); ++i)
if (cli.Avail(*i))
Throw(_("Option \"-%c\" not available with this command. See help"), *i);
static std::string GetEnv(const std::string &name)
const char *env(getenv(name.c_str()));
return env ? env : "";
static void PrepareWouxun(const CCli &cli, CWouxun &wx) </