|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
patch: delbin, don't rely on navigation messages for timeoutsPer the report from Jed Frechette, navigation messages can't be relied
on to occur once a second, so don't use them for timeouts. I added some debugging code to print the time when packets are sent and received, and added another level to show the messages as text, (I found it distracting). This also reverts your change to the hidsdi.h include, with DDK 6001.18001 that header is in inc/api/, not ddk/, so I don't think it's right to use a directory prefix in the include directive. Index: delbin.c =================================================================== --- delbin.c (revision 9) +++ delbin.c (working copy) @@ -73,11 +73,15 @@ // number of times to attempt a transfer before giving up #define ATTEMPT_MAX 2 +// seconds to wait for expected message, this value is 1 greater than +// minimum, i.e. READ_TIMEOUT - 1 <= actual_timeout <= READ_TIMEOUT +#define READ_TIMEOUT 6 -// debug output: low, medium, high +// debug output: low, medium, high, higher #define DBGLVL_L 1 #define DBGLVL_M 2 #define DBGLVL_H 3 +#define DBGLVL_H2 4 // Multiple unit support. #define DELBIN_MAX_UNITS 32 @@ -373,6 +377,34 @@ //----------------------------------------------------------------------------- +#if __APPLE__ || __linux + #include <sys/time.h> +#endif + +static void +debug_out(const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fputs(MYNAME ": ", stderr); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + +static void +debug_out_time(const char* s) +{ +#if __APPLE__ || __linux + struct timeval tv; + gettimeofday(&tv, NULL); + debug_out("%u.%03u %s", (unsigned)tv.tv_sec & 0xf, (unsigned)tv.tv_usec / 1000, s); +#else + debug_out("%u %s", (unsigned)time(NULL) & 0xf, s); +#endif +} + +//----------------------------------------------------------------------------- + static gbuint16 checksum(const gbuint8* p, unsigned n) { @@ -400,14 +432,18 @@ } if (global_opts.debug_level >= DBGLVL_H) { unsigned j; - warning(MYNAME ": pcktrd "); + const gbuint8* p = buf; + + debug_out_time("pcktrd"); for (j = 0; j < n; j++) { - warning("%02x ", ((gbuint8*)buf)[j]); + warning(" %02x", p[j]); } - warning(" "); - for (j = 0; j < n; j++) { - gbuint8 c = ((gbuint8*)buf)[j]; - warning("%c", isprint(c) ? c : '.'); + if (global_opts.debug_level >= DBGLVL_H2) { + warning(" "); + for (j = 0; j < n; j++) { + int c = p[j]; + warning("%c", isprint(c) ? c : '.'); + } } warning("\n"); } @@ -415,23 +451,27 @@ } static void -packet_write(const void* p, unsigned size) +packet_write(const void* buf, unsigned size) { unsigned n; if (global_opts.debug_level >= DBGLVL_H) { unsigned j; - warning(MYNAME ": pcktwr "); + const gbuint8* p = buf; + + debug_out_time("pcktwr"); for (j = 0; j < size; j++) { - warning("%02x ", ((gbuint8*)p)[j]); + warning(" %02x", p[j]); } - warning(" "); - for (j = 0; j < size; j++) { - gbuint8 c = ((gbuint8*)p)[j]; - warning("%c", isprint(c) ? c : '.'); + if (global_opts.debug_level >= DBGLVL_H2) { + warning(" "); + for (j = 0; j < size; j++) { + int c = p[j]; + warning("%c", isprint(c) ? c : '.'); + } } warning("\n"); } - n = delbin_os_ops.packet_write(p, size); + n = delbin_os_ops.packet_write(buf, size); if (n != size) { fatal(MYNAME ": short write %u %u\n", size, n); } @@ -547,9 +587,11 @@ { static gbuint8 buf[256]; static unsigned buf_i, buf_n; - while (buf_n == 0 || new_packet) { + if (new_packet) { + buf_n = 0; + } + while (buf_n == 0) { packet_read(buf); - new_packet = FALSE; if (buf[1] <= delbin_os_packet_size - 2) { buf_n = buf[1]; buf_i = 2; @@ -647,13 +689,12 @@ } // Get specific message, ignoring others. Sends ACK for non-interval messages. -// Gives up if 6 navigation messages are received, which means we waited at least -// 5 seconds. +// Gives up after at least READ_TIMEOUT-1 seconds have passed. static int message_read(unsigned msg_id, message_t* m) { unsigned id; - int interval_message_count = 0; + time_t time_start = time(NULL); if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": looking for %x\n", msg_id); @@ -663,15 +704,9 @@ break; } message_ack(id, m); - if (id == msg_id) { + if (id == msg_id || time(NULL) - time_start >= READ_TIMEOUT) { break; } - if (id == MSG_NAVIGATION) { - interval_message_count++; - if (interval_message_count == 6) { - break; - } - } } return id == msg_id; } @@ -688,7 +723,7 @@ if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": begin get_batch\n"); do { - unsigned timeout_count = 0; + time_t time_start = time(NULL); if (i == array_max) { message_t* old_a = a; array_max += array_max; @@ -701,13 +736,11 @@ id = message_read_1(0, &a[i]); switch (id) { case MSG_NAVIGATION: - timeout_count++; - if (timeout_count == 6) { + if (time(NULL) - time_start >= READ_TIMEOUT) { success = 0; break; } // fall through - case 0: case MSG_ACK: case MSG_NACK: case MSG_SATELLITE_INFO: @@ -779,6 +812,8 @@ warning(MYNAME ": begin send_batch, %u messages\n", n); for (i = 0; i < n; i++) { unsigned timeout_count = 0; + time_t time_start = time(NULL); + message_write(batch_array[i].msg_id, &batch_array[i].msg); for (;;) { unsigned id = message_read_1(0, &m); @@ -786,17 +821,17 @@ case MSG_ACK: break; case MSG_NAVIGATION: - timeout_count++; - if (timeout_count > 2) { - fatal(MYNAME ": send_batch timed out\n"); - } - if (timeout_count == 2) { + if (time(NULL) - time_start >= 2) { + if (timeout_count) { + fatal(MYNAME ": send_batch timed out\n"); + } + timeout_count++; if (global_opts.debug_level >= DBGLVL_M) warning(MYNAME ": re-sending %x\n", batch_array[i].msg_id); message_write(batch_array[i].msg_id, &batch_array[i].msg); + time_start = time(NULL); } // fall through - case 0: case MSG_NACK: case MSG_SATELLITE_INFO: continue; @@ -1010,6 +1045,7 @@ case gt_benchmark: gc_sym = 172; break; case gt_cito: gc_sym = 167; break; case gt_mega: gc_sym = 166; break; + case gt_wherigo: gc_sym = 164; break; case gt_unknown: case gt_locationless: case gt_ape: @@ -1988,7 +2024,7 @@ { int i; for (i = 0; i < n_delbin_units; i++) { - printf("%d %s %s\n", + printf("%u %s %s\n", delbin_unit_info[i].unit_number, delbin_unit_info[i].unit_serial_number, delbin_unit_info[i].unit_name ); @@ -2021,7 +2057,7 @@ } else if (strstr(p->product, "PN-20")) { use_extended_notes = p->firmware[0] > '1' || (p->firmware[0] == '1' && p->firmware[2] >= '6'); - } else if (strstr(p->product, "PN-40")) { + } else if (strstr(p->product, "PN-30") || strstr(p->product, "PN-40")) { use_extended_notes = p->firmware[0] > '2' || (p->firmware[0] == '2' && p->firmware[2] >= '5'); } @@ -2114,7 +2150,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <setupapi.h> -#include <ddk/hidsdi.h> +#include <hidsdi.h> static HANDLE hid_handle; ------------------------------------------------------------------------------ _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsOn Thu, Jul 23, 2009 at 1:00 AM, Paul Cornett <pc-gpsb@...> wrote: Per the report from Jed Frechette, navigation messages can't be relied Applied. I added some debugging code to print the time when packets are sent I've done similar things in several of my modules. Low numbers give an overiew of the packets, middle numbers display packet types and as much stuff as'll fit in one 80 columnt line. Bigger numbers hex dump every byte. Bigger still dumps every byte as hex and as printable ascii. It's one of the reasons I"m weasely about documenting the debug levels; they vary from module to module and do move around as we need to 'see' hardware/OS combinations that we may not have ourselves. This also reverts your change to the hidsdi.h OK, I'll work around this in the mingw cross build some other way. Thanx, RJL
------------------------------------------------------------------------------ _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsRobert Lipe wrote:
> On Thu, Jul 23, 2009 at 1:00 AM, Paul Cornett > wrote: > > > Per the report from Jed Frechette, navigation messages can't be > > relied on to occur once a second, so don't use them for timeouts. > > > > Applied. Uhh, it looks like you applied the patch I sent to Jed for more info, and not the one attached in this thread... ------------------------------------------------------------------------------ _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsI've also attached a tweak to a wrong comment in the aformentioned patch
--- delbin.c~ 2009-07-22 22:35:53.240012620 -0700 +++ delbin.c 2009-07-24 00:00:32.958153512 -0700 @@ -73,8 +73,8 @@ // number of times to attempt a transfer before giving up #define ATTEMPT_MAX 2 -// seconds to wait for expected message, this value is 1 greater than -// minimum, i.e. READ_TIMEOUT - 1 <= actual_timeout <= READ_TIMEOUT +// seconds to wait for expected message (actual time will be somewhat +// indeterminate, but at least READ_TIMEOUT - 1) #define READ_TIMEOUT 6 // debug output: low, medium, high, higher ------------------------------------------------------------------------------ _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsOoops. Fixed. Comment tweak applied, too.
On Fri, Jul 24, 2009 at 1:50 AM, Paul Cornett <pc-gpsb@...> wrote:
------------------------------------------------------------------------------ _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsI'm seeing an intermittent problem on both Mac and Windows with bulk input on the PN-40. Writes seem to be pretty solid. At best, it leads us into the slow retry/timeout path and at worst we actually give up and abort. Is anyone else seeing this? It catches my eye that we are detecting packet coruption, but I'm not certain that's related. Subjectively, the problem seems worse on Windows, but I see it on Mac, too. Here's an example where we detect corruption and recover:
delbin: received a010 delbin: 12.256 pcktrd 00 3d db fe 13 b0 35 00 dd 50 58 02 00 00 02 00 00 00 67 05 03 00 00 00 9d d0 ab 03 7b ff 0f f7 00 24 f4 c9 03 a0 11 43 6f 75 6e 74 79 20 4c 69 6e 65 20 4d 69 6e 69 00 ff ff 00 61 c7 ad bc 00 .=....5..PX.......g.........{....$.....County Line Mini....a.... delbin: received b013 delbin: 12.257 pcktwr 20 10 db fe 00 aa 08 00 1d 57 13 b0 61 c7 8c 88 ad bc ........W..a... .. delbin: sent aa00 delbin: 12.297 pcktrd 00 3e db fe 15 b0 3c 03 d4 4d 01 00 03 00 11 43 6f 75 6e 74 79 20 4c 69 6e 65 20 4d 69 6e 69 00 20 03 43 6f 75 6e 74 79 20 4c 69 6e 65 20 4d 69 6e 69 20 62 79 20 4a 61 6d 65 73 20 6f 6e 20 74 .>....<..M.....County Line Mini. .County Line Mini by James on t delbin: 12.297 pcktrd 00 3e 68 65 20 45 6c 6b 20 52 69 76 65 72 0a 43 61 63 68 65 20 49 44 3a 20 47 43 47 32 31 35 0a 54 72 61 64 69 74 69 6f 6e 61 6c 20 43 61 63 68 65 0a 53 49 5a 45 3a 20 53 6d 61 6c 6c 0a 44 31 .>he Elk River.Cache ID: GCG215.Traditional Cache.SIZE: Small.D1 delbin: 12.298 pcktrd 00 3e 6c 6f 63 61 74 65 64 20 6e 65 61 72 20 61 20 73 6d 6f 6f 74 68 20 26 20 71 75 69 65 74 20 66 69 73 68 69 6e 67 20 68 6f 6c 65 20 6f 6e 20 74 68 65 20 75 70 70 65 72 20 65 6e 64 20 6f 66 .>located near a smooth & quiet fishing hole on the upper end of delbin: 12.301 pcktrd 00 3e 20 74 68 65 20 45 6c 6b 20 52 69 76 65 72 21 0a 54 68 69 73 20 63 61 63 68 65 20 72 65 61 6c 6c 79 20 69 73 20 61 20 6d 69 6e 69 2e 2e 2e 20 62 69 67 67 65 72 20 74 68 61 6e 20 61 20 66 .> the Elk River!.This cache really is a mini... bigger than a f delbin: 12.302 pcktrd 00 3e 69 6c 6d 20 63 61 6e 69 73 74 65 72 2c 20 73 6d 61 6c 6c 65 72 20 74 68 61 6e 20 61 6e 20 61 6d 6d 6f 20 62 6f 78 2e 2e 2e 20 62 75 74 20 73 68 6f 75 6c 64 20 62 65 20 65 61 73 79 20 74 .>ilm canister, smaller than an ammo box... but should be easy t delbin: 12.304 pcktrd 00 3e 6f 20 66 69 6e 64 2e 20 20 4f 66 66 2d 72 6f 61 64 20 70 61 72 6b 69 6e 67 20 69 73 20 61 76 61 69 6c 61 62 6c 65 20 77 69 74 68 69 6e 20 73 69 67 68 74 20 6f 66 20 74 68 65 20 63 61 63 .>o find. Off-road parking is available within sight of the cac delbin: 12.313 pcktrd 00 3e 68 65 20 6c 6f 63 61 74 69 6f 6e 2e 20 20 42 75 67 20 73 70 72 61 79 20 69 73 20 72 65 63 6f 6d 6d 65 6e 64 65 64 2e 20 46 69 73 68 69 6e 67 20 70 6f 6c 65 20 26 20 70 69 63 6e 69 63 20 .>he location. Bug spray is recommended. Fishing pole & picnic delbin: 12.313 pcktrd 00 3e 6c 75 6e 63 68 20 61 72 65 20 6f 70 74 69 6f 6e 61 6c 2e 20 20 5b 3a 29 5d 20 0a 0a 54 68 65 20 63 61 63 68 65 20 63 6f 6e 74 61 69 6e 65 72 20 69 73 20 61 20 72 65 63 74 61 6e 67 75 6c .>lunch are optional. [:)] ..The cache container is a rectangul delbin: 12.313 pcktrd 00 3e 61 72 20 31 32 6f 7a 20 52 75 62 62 65 72 6d 61 69 64 20 74 75 62 20 70 61 69 6e 74 65 64 20 74 6f 20 6d 61 74 63 68 20 74 68 65 20 68 69 64 69 6e 67 20 70 6c 61 63 65 2e 20 20 41 74 20 .>ar 12oz Rubbermaid tub painted to match the hiding place. At delbin: 12.314 pcktrd 00 3e 6f 6e 6c 79 20 33 20 69 6e 63 68 65 73 20 62 79 20 35 2d 31 2f 32 20 69 6e 63 68 65 73 20 62 79 20 31 20 69 6e 63 68 2c 20 69 74 20 68 61 73 20 72 6f 6f 6d 20 6f 6e 6c 79 20 66 6f 72 20 .>only 3 inches by 5-1/2 inches by 1 inch, it has room only for delbin: 12.327 pcktrd 00 3e 6d 69 6e 69 20 69 74 65 6d 73 21 20 20 50 6c 65 61 73 65 20 74 72 61 64 65 20 73 6f 6d 65 74 68 69 6e 67 20 6e 69 63 65 20 28 61 6e 64 20 6d 69 6e 69 21 29 20 66 6f 72 20 79 6f 75 72 20 .>mini items! Please trade something nice (and mini!) for your delbin: 12.329 pcktrd 00 3e 66 65 6c 6c 6f 77 20 63 61 63 68 65 72 73 2e 20 0a 0a 4f 72 69 67 69 6e 61 6c 20 6d 69 6e 69 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20 74 68 65 20 6d 69 6e 69 20 63 61 63 68 65 2e 2e 2e 20 .>fellow cachers. ..Original mini contents of the mini cache... delbin: 12.329 pcktrd 00 3e 20 6c 6f 67 20 62 6f 6f 6b 20 26 20 70 65 6e 20 26 20 70 65 6e 63 69 6c 2c 00 6f 17 ad bc db fe 20 a0 75 00 90 60 07 06 55 12 43 ff 2b af 1b 41 74 00 db 00 f8 00 0c 02 6c 20 48 0d d8 0e .> log book & pen & pencil,.o..... .u..`..U.C.+..At.......l H... delbin: 12.333 pcktrd 00 3e 07 04 b8 24 90 01 00 00 00 0a ac 0d 9c 18 54 0b 07 0c a4 51 78 05 a4 06 07 0f 48 3f ac 0d 10 0e 07 15 48 71 dc 05 b8 0b 07 18 44 7a ec 13 34 08 07 1d b4 78 b4 14 28 0a 07 1e 94 5c 34 08 .>...$..........T....Qx.....H?......Hq......Dz..4....x..(....\4. delbin: corrupted message b015 Is anyone else working with the delbin support? Also, Paul, can you offer tips on how you're building on Windows? I wasn't able to get MSVC Express 2008 and the Windows SDK for Windows 7 to find the hid library. Thanx, RJL On Fri, Jul 24, 2009 at 10:28 AM, Robert Lipe <robertlipe@...> wrote: Ooops. Fixed. Comment tweak applied, too. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsRobert Lipe wrote:
> I'm seeing an intermittent problem on both Mac and Windows with bulk > input on the PN-40. I'm not seeing it, but you are probably transferring alot more long waypoints than I have. From your log, it looks like the 3rd packet of the b015 message is just plain missing. I don't see what we can do about that. I did find a problem where the version message wasn't getting read properly, which I fixed by not allowing a message head to span packets, and discarding the first packet read which always seems to be stale (patch attached). > Also, Paul, can you offer tips on how you're building on Windows? I > wasn't able to get MSVC Express 2008 and the Windows SDK for Windows > 7 to find the hid library. I added the directory containing hid.lib (.../WinDDK/6001.18001/lib/wxp/i386 for me) to the list in the Tools->Options dialog for Projects and Solutions/VC++ Directories, Library Files. HTH. Index: delbin.c =================================================================== --- delbin.c (revision 18) +++ delbin.c (working copy) @@ -627,15 +627,18 @@ unsigned id; for (;;) { unsigned total; + unsigned n; gbuint8 buf[8]; gbuint8* p; - read_depacketize(buf, 8); + n = read_depacketize_1(&p, 8, FALSE); + memset(buf, 0, 8); + memcpy(buf, p, n); while (buf[0] != 0xdb || buf[1] != 0xfe || checksum(buf, 6) != le_readu16(buf + 6)) { - gbuint8* pp; // try for a message start at the beginning of next packet - read_depacketize_1(&pp, 8, TRUE); - memcpy(buf, pp, 8); + n = read_depacketize_1(&p, 8, TRUE); + memset(buf, 0, 8); + memcpy(buf, p, n); } id = le_readu16(buf + 2); total = le_readu16(buf + 4); @@ -2037,9 +2040,13 @@ delbin_rw_init(const char *fname) { message_t m; + char buf[256]; delbin_os_ops.init(fname); + // Often the first packet is part of an old message, sometimes it can + // confuse the first message read if we don't get rid of it + packet_read(buf); // Send a break to clear any state from a previous failure message_init(&m); m.size = MSG_BREAK_SIZE; ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsOn Fri, Aug 7, 2009 at 1:06 PM, Paul Cornett <pc-gpsb@...> wrote:
The problem is indeed easiest to see if you're doing reads of really massive waypoint piles; a couple of pocket queries and including logs tends to tickle it. I did find a problem where the version message wasn't getting read Good catch. It really is unfortunate to transfer a framed protocol over a framed interface and then throw that away by stuffing the data into the frames without respecting frame boundaries, forcing this whole "look for the start of the packet and latch on" game. Thanx. I've committed this. RJL ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: patch: delbin, don't rely on navigation messages for timeoutsRobert Lipe wrote:
> The problem is indeed easiest to see if you're doing reads of really > massive waypoint piles; a couple of pocket queries and including logs > tends to tickle it. I notice you are doing transfers with the GPS enabled (I can tell because the a020 satellite messages don't appear if it is disabled). It's not a fix, but it may be more reliable to do transfers with the GPS disabled. I measured a speed gain of 5-10% reading waypoints when it is disabled. I get the impression it doesn't really have enough horsepower to do everything at once. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
| Free embeddable forum powered by Nabble | Forum Help |