Patch: osmocon: excape non-printable, add -c option
Christian Vogel
vogelchr at vogel.cx
Sat Mar 27 20:21:34 CET 2010
Hi,
I started to play around with osmocon, but unfortunately my serial
cable (a FTDI232RL module from Sparkfun connected to the 2.5mm plug,
this one is set to 3v3 and worked flawlessly for several projects!)
seems to be quite unreliable in the host -> handset direction.
But to not procrastinate, I did some cleanup in osmocon to escape
non-printable output and added new "-c" option to start straight into
HDLC-mode without uploading any firmware to the mobile.
Are those kinds of mostly cosmetic patches appreciated or considered
unnecessary?
Chris
-------------- next part --------------
commit afb6794ee0bc6a971b70d65a551851592f19ca5b
Author: Christian Vogel <chris at distress.dillberg.com>
Date: Sat Mar 27 19:58:01 2010 +0100
Misc "cleanup" of osmocon:
- \x escapes for binary stuff sent to console
- usage() prettyfied
- defaults for sockets, serial port to defines
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index f934dd7..0af8c14 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -26,6 +26,11 @@
#define MAX_DNLOAD_SIZE 0xFFFF
#define MAX_HDR_SIZE 128
+
+#define DEF_SERIAL_DEV "/dev/ttyUSB1"
+#define DEF_LAYER2_UN_PATH "/tmp/osmocom_l2"
+#define DEF_LOADER_UN_PATH "/tmp/osmocom_loader"
+
struct tool_server *tool_server_for_dlci[256];
/**
@@ -366,7 +371,19 @@ static void hdlc_send_to_phone(uint8_t dlci, uint8_t *data, int len)
static void hdlc_console_cb(uint8_t dlci, struct msgb *msg)
{
- write(1, msg->data, msg->len);
+ int i;
+ unsigned char *c=msg->data;
+
+ for(i=0;i<msg->len;i++){
+ if(isprint(*c) || *c == '\n')
+ putchar(*c);
+ else
+ printf("\\x%02x",(unsigned char)*c);
+ c++;
+ }
+ fflush(stdout);
+
+// write(1, msg->data, msg->len);
msgb_free(msg);
}
@@ -501,7 +518,20 @@ static int parse_mode(const char *arg)
static int usage(const char *name)
{
- printf("\nUsage: %s [ -v | -h ] [ -p /dev/ttyXXXX ] [ -s /tmp/osmocom_l2 ] [ -l /tmp/osmocom_loader ] [ -m {c123,c123xor,c155} ] file.bin\n", name);
+ printf("\nUsage: %s [ -v | -h ] [-c] [ -p tty ] [ -s path ] [ -l path ]\n"
+ "\t[ -m {c123,c123xor,c155} ] file.bin\n",name);
+ printf("\nOptions:\n");
+ printf(" -v Print version, then exit.\n");
+ printf(" -h Print usage, then exit.\n");
+ printf(" -s path unix domain socket for layer2 client (default: %s)\n",
+ DEF_LAYER2_UN_PATH);
+ printf(" -l path unix domain socket for loader client (default: %s)\n",
+ DEF_LOADER_UN_PATH);
+ printf(" -c don't start to download, go straight to HDLC\n");
+ printf(" -m checksum mode? (default: c123)\n");
+ printf(" -p path serial port to use (default: %s)\n",DEF_SERIAL_DEV);
+ printf("\n");
+ printf("Purpose of this program:\n");
printf("\t* Open serial port /dev/ttyXXXX (connected to your phone)\n"
"\t* Perform handshaking with the ramloader in the phone\n"
"\t* Download file.bin to the attached phone (base address 0x00800100)\n");
@@ -665,13 +695,13 @@ extern void hdlc_tpudbg_cb(uint8_t dlci, struct msgb *msg);
int main(int argc, char **argv)
{
int opt, flags;
- const char *serial_dev = "/dev/ttyUSB1";
- const char *layer2_un_path = "/tmp/osmocom_l2";
- const char *loader_un_path = "/tmp/osmocom_loader";
+ const char *serial_dev = DEF_SERIAL_DEV;
+ const char *layer2_un_path = DEF_LAYER2_UN_PATH;
+ const char *loader_un_path = DEF_LOADER_UN_PATH;
dnload.mode = MODE_C123;
- while ((opt = getopt(argc, argv, "hl:p:m:s:v")) != -1) {
+ while ((opt = getopt(argc, argv, "hl:p:m:s:vc")) != -1) {
switch (opt) {
case 'p':
serial_dev = optarg;
@@ -690,6 +720,9 @@ int main(int argc, char **argv)
case 'v':
version(argv[0]);
break;
+ case 'c':
+ dnload.print_hdlc=1;
+ break;
case 'h':
default:
usage(argv[0]);
More information about the baseband-devel
mailing list