Only in serproxy-0.1.3.src.hexbin/: .cvsignore diff -cr serproxy-0.1.3.src.orig/ChangeLog serproxy-0.1.3.src.hexbin/ChangeLog *** serproxy-0.1.3.src.orig/ChangeLog Fri Jun 17 21:04:46 2005 --- serproxy-0.1.3.src.hexbin/ChangeLog Wed Dec 10 02:37:21 2008 *************** *** 1,3 **** --- 1,6 ---- + v0.1.3a - modified by fenrir + - usehex option is added, see README.txt. + v0.1.3 - 17/05/2005 - DAM - Can now specify config file location on command line. diff -cr serproxy-0.1.3.src.orig/README serproxy-0.1.3.src.hexbin/README *** serproxy-0.1.3.src.orig/README Fri Jun 17 21:05:55 2005 --- serproxy-0.1.3.src.hexbin/README Wed Dec 10 02:49:23 2008 *************** *** 114,119 **** --- 114,136 ---- newlines_to_nils=true --------------------------------------------------------------------- + usehex= + + This option enables to convert two hexagonal characters + into one binary, and vice versa, which resolves the problem of + XMLSocket which can not handle a 0x00(Null) character correctly. + For example, when you send a "00" command from Flash, + the serproxy with "usehex" option send 0x00 command to your Arduino. + Conversely, when your Arduino says 0x00, the serproxy + with "usehex" option relay "00" string to Flash. + This option works well with the combination of XMLSocket class + in Flash and Arduino Firmata, because Firmata command uses + many 0x00 binary in its packets. + + Example: + usehex=true + + --------------------------------------------------------------------- net_port= Used to map tcp port numbers to serial port numbers. These define diff -cr serproxy-0.1.3.src.orig/config.c serproxy-0.1.3.src.hexbin/config.c *** serproxy-0.1.3.src.orig/config.c Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/config.c Wed Dec 10 02:37:21 2008 *************** *** 27,32 **** --- 27,33 ---- {"net_allow", "all"}, {"net_deny", "none"}, {"newlines_to_nils", "false"}, + {"usehex", "false"}, {"serial_device", ""} }; diff -cr serproxy-0.1.3.src.orig/config.h serproxy-0.1.3.src.hexbin/config.h *** serproxy-0.1.3.src.orig/config.h Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/config.h Wed Dec 10 02:37:21 2008 *************** *** 17,22 **** --- 17,23 ---- CFG_SALLOW, CFG_SDENY, CFG_SNEWLINES, + CFG_USEHEX, CFG_SDEVICE, CFG_SEND } cfg_str_t; diff -cr serproxy-0.1.3.src.orig/macosx/README-wiring.txt serproxy-0.1.3.src.hexbin/macosx/README-wiring.txt *** serproxy-0.1.3.src.orig/macosx/README-wiring.txt Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/macosx/README-wiring.txt Wed Dec 10 02:37:21 2008 *************** *** 49,54 **** --- 49,60 ---- newlines_to_nils=true + Also, if you use this serproxy with the combination of XMLSocket class in Flash and Arduino Firmata, you are strongly recommended to use "usehex" option like: + + usehex=true + + This option enables to convert two hexagonal characters into one binary, and vice versa, which resolves the problem of Flash XMLSocket which can not handle a 0x00(Null) character correctly. For example, when you send a "00" command from Flash, the serproxy with "usehex" option send 0x00 command to your Arduino. Conversely, when your Arduino says 0x00, the serproxy with "usehex" option relay "00" string to Flash. + To launch serproxy, simply double-click it. (This version does not require a .command file.) -- David A. Mellis diff -cr serproxy-0.1.3.src.orig/main.c serproxy-0.1.3.src.hexbin/main.c *** serproxy-0.1.3.src.orig/main.c Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/main.c Wed Dec 10 02:37:21 2008 *************** *** 92,98 **** pipe_s *pipe; cfg_s local; serialinfo_s sinfo; ! char *parity, *newlines; /* Read the global config settings */ cfg_fromfile(&cfg, cfgfile); --- 92,98 ---- pipe_s *pipe; cfg_s local; serialinfo_s sinfo; ! char *parity, *newlines, *hex; /* Read the global config settings */ cfg_fromfile(&cfg, cfgfile); *************** *** 171,176 **** --- 171,191 ---- { errend("Unknown value '%s' for newlines to nils (must be 'true' or 'false')", newlines); } + + hex = local.strs[CFG_USEHEX].val; + + if (strcmp(hex, "true") == 0) + { + pipe->hex = 1; + } + else if (strcmp(hex, "false") == 0) + { + pipe->hex = 0; + } + else + { + errend("Unknown value '%s' for hex converter (must be 'true' or 'false')", hex); + } if (sio_setinfo(&pipe->sio, &sinfo)) errend("Unable to configure comm port %d", port); *************** *** 269,274 **** --- 284,290 ---- free(newsock); newpipe->newlines = pit->newlines; + newpipe->hex = pit->hex; newpipe->timeout = pit->timeout; newpipe->mutex = pit->mutex; *************** *** 294,299 **** --- 310,333 ---- return 0; } + char itoa_hex(char i){ + if(i >= 10){ + return (i - 10) + 'A'; + }else{ + return i + '0'; + } + } + + char atoi_hex(char c){ + if(c >= 'a'){ + return c - 'a' + 10; + }else if(c >= 'A'){ + return c - 'A' + 10; + }else{ + return c - '0'; + } + } + /* Main routine for the server threads */ thr_startfunc_t serve_pipe(void *data) { *************** *** 386,392 **** /* Only read input if buffer is empty */ if (sio_count == 0) { ! sio_count = sio_read(&pipe->sio, sio_buf, sizeof(sio_buf)); if (sio_count <= 0) { if (sio_count == 0) --- 420,426 ---- /* Only read input if buffer is empty */ if (sio_count == 0) { ! sio_count = sio_read(&pipe->sio, sio_buf, (sizeof(sio_buf) / 2) - 1); if (sio_count <= 0) { if (sio_count == 0) *************** *** 406,415 **** { DBG_MSG3("server(%d) - read %d bytes from sio", port, sio_count); } } } ! if (pipe->newlines) { /* Replace incoming newlines with nils. */ for (i = 0; i < sio_count; i++) --- 440,462 ---- { DBG_MSG3("server(%d) - read %d bytes from sio", port, sio_count); } + + // Binary -> Hex + if(pipe->hex){ + int j = sio_count * 2; + sio_buf[j] = 0; + for(i = sio_count - 1; i >= 0; --i){ + sio_buf[--j] = itoa_hex(sio_buf[i] & 0x0F); + sio_buf[--j] = itoa_hex(sio_buf[i] >> 4); + } + sio_count = sio_count * 2 + 1; + DBG_MSG3("server(%d) - convert into %d hex characters", port, sio_count); + DBG_MSG3("server(%d) - %s", port, sio_buf); + } } } ! if (!(pipe->hex) && pipe->newlines) { /* Replace incoming newlines with nils. */ for (i = 0; i < sio_count; i++) *************** *** 456,461 **** --- 503,531 ---- } } DBG_MSG3("server(%d) - read %d bytes from sock", port, sock_count); + + // Hex -> Binary + if(pipe->hex){ + char c1, c2; + int j = 0; + c1 = atoi_hex(sock_buf[0]); + for(i = 1; i < sock_count; ++i){ + c2 = atoi_hex(sock_buf[i]); + if((c1 >= 0) && (c1 < 16)){ + if((c2 >= 0) && (c2 < 16)){ + sock_buf[j++] = (c1 << 4) | c2; + } + c1 = atoi_hex(sock_buf[++i]); + }else{ + c1 = c2; + } + } + sock_count = j; + DBG_MSG3("server(%d) - convert into %d binary bytes", port, sock_count); + for(j = 0; j < sock_count; j++){ + DBG_MSG3("server(%d) - %02x", port, sock_buf[j]); + } + } } } diff -cr serproxy-0.1.3.src.orig/pipe.h serproxy-0.1.3.src.hexbin/pipe.h *** serproxy-0.1.3.src.orig/pipe.h Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/pipe.h Wed Dec 10 02:37:21 2008 *************** *** 21,26 **** --- 21,29 ---- /* Convert newlines from the serial port to nils? */ int newlines; + + /* Convert Hexgonal string from/to binary? */ + int hex; } pipe_s; int pipe_init(pipe_s *pipe, int sock_port); diff -cr serproxy-0.1.3.src.orig/serproxy.cfg serproxy-0.1.3.src.hexbin/serproxy.cfg *** serproxy-0.1.3.src.orig/serproxy.cfg Fri Jun 17 20:36:03 2005 --- serproxy-0.1.3.src.hexbin/serproxy.cfg Wed Dec 10 02:38:57 2008 *************** *** 5,10 **** --- 5,13 ---- # true (e.g. if using Flash) or false newlines_to_nils=true + # Convert hex string <=> binary + usehex=true + # Comm ports used comm_ports=1,2,3,4