To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 663
662  |  664
Subject: 
firmdl3 on Winnt - no more problems!
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 16 Jan 2000 23:58:48 GMT
Viewed: 
1636 times
  
Finally I got a firmdl3 version that FULLY works on Winnt, both in slow and
fast mode! No more "write: permission denied" or "read: permission denied"
problems... No more interrupted downloads at all on my system (NTWS 4 SP6a).

Note: I've not tested it on Win95 system.

I had to patch original files from Kekoa Proudfoot to handle the
infamous "permission denied" error on NT. I've also introduced some more
progress indicators during the download.

I think that the patch should work also on *nix systems: it uses few
modification to the sources. I hope that the patch will become part of the
normal distribution of this very good tool for Winnt users too.

Here is the patch. It's for the "multifile" version of firmdl3
(firmdl3.tar.gz). You can untar the file in legos/util to get the sources in
legos/util/firmdl3 dir.

From legos/util you can apply the patch as usual and compile it with make.

Ex.:

$ cd /legos/util
$ tar xvfz firmdl3.tar.gz
$ patch -u -b < firmdl3.3.0-win.diff
$ cd firmdl3
$ make

Here is the diff file (firmdl3.3.0-win.diff):

-------- snipsnip
--- firmdl3\Makefile Thu Oct 14 04:12:02 1999
+++ firmdl3\Makefile Tue Jan 11 01:12:14 2000
@@ -17,23 +17,23 @@
# Kekoa Proudfoot. All Rights Reserved.

# Linux, IRIX
-CC = cc
+#CC = cc

# Cygwin
-#CC = gcc
+CC = gcc

all: fastdl.h firmdl

mkimg: mkimg.o srec.o
- $(CC) $^ -o mkimg
+ $(CC) $^ -o mkimg.exe

firmdl: firmdl.o srec.o rcx_comm.o
- $(CC) $^ -o firmdl
+ $(CC) $^ -o firmdl3.exe

fastdl.h: mkimg fastdl.srec
./mkimg fastdl.srec > fastdl.h

clean:
- rm -f *.o fastdl.h mkimg firmdl
+ rm -f *.o fastdl.h mkimg.exe firmdl3.exe


--- firmdl3\firmdl.c Mon Oct 04 11:39:56 1999
+++ firmdl3\firmdl.c Sun Jan 16 23:07:19 2000
@@ -81,6 +81,7 @@
/* Global variables */

char *progname;
+extern int  fd;

#include "fastdl.h"

@@ -198,7 +199,7 @@

void
image_dl (int fd, unsigned char *image, int len, unsigned short start,
-   int use_comp)
+   int use_comp, char *filename)
{
     unsigned short cksum = 0;
     unsigned char send[BUFFERSIZE];
@@ -217,7 +218,8 @@
     send[4] = 7;
     send[5] = 11;

-    if (rcx_sendrecv(fd, send, 6, recv, 1, 50, RETRIES, use_comp) != 1) {
+    /* PM - Increased Timeout from 50 to 150 to get fewer syncronization
error */
+    if (rcx_sendrecv(fd, send, 6, recv, 1, 150, RETRIES, use_comp) != 1) {
fprintf(stderr, "%s: delete firmware failed\n", progname);
exit(1);
     }
@@ -230,15 +232,18 @@
     send[4] = (cksum >> 8) & 0xff;
     send[5] = 0;

-    if (rcx_sendrecv(fd, send, 6, recv, 2, 50, RETRIES, use_comp) != 2) {
+    /* PM - Increased Timeout from 50 to 150 to get fewer syncronization
error */
+    if (rcx_sendrecv(fd, send, 6, recv, 2, 150, RETRIES, use_comp) != 2) {
fprintf(stderr, "%s: start firmware download failed\n", progname);
exit(1);
     }

     /* Transfer data */
+    fprintf(stderr, "\rTransferring \"%s\" to RCX...\n", filename);
     addr = 0;
     index = 1;
     for (addr = 0, index = 1; addr < len; addr += size, index++) {
+      fprintf(stderr,"\r%3d%%        \r",(100*addr)/len);
size = len - addr;
send[0] = 0x45;
if (index & 1)
@@ -263,6 +268,7 @@
    exit(1);
}
     }
+    fputs("100%\n",stderr);

     /* Unlock firmware */
     send[0] = 0xa5;
@@ -288,7 +294,7 @@
     char *tty = NULL;
     int use_fast = 1;
     int usage = 0;
-    int fd;
+//    int fd;
     int status;

     progname = argv[0];
@@ -404,7 +410,7 @@
exit(1);
    }

-     image_dl(fd, fastdl_image, fastdl_len, fastdl_start, 1);
+     image_dl(fd, fastdl_image, fastdl_len, fastdl_start, 1, "Fast
Download Image");

    /* Go back to fast mode */
    close(fd);
@@ -413,14 +419,14 @@

/* Download image in fast mode */

- image_dl(fd, image, image_len, image_start, 0);
+ image_dl(fd, image, image_len, image_start, 0, argv[0]);
close(fd);
     }
     else {
/* Try to wake up the tower in slow mode */

fd = rcx_init(tty, 0);
-
+
if ((status = rcx_wakeup_tower(fd, WAKEUP_TIMEOUT)) < 0) {
    fprintf(stderr, "%s: %s\n", progname, rcx_strerror(status));
    exit(1);
@@ -442,9 +448,9 @@
    fprintf(stderr, "%s: no response from rcx\n", progname);
    exit(1);
}
-
+
/* Download image */
- image_dl(fd, image, image_len, image_start, 1);
+ image_dl(fd, image, image_len, image_start, 1, argv[0]);

close(fd);
     }
--- firmdl3\rcx_comm.c Mon Oct 04 11:40:02 1999
+++ firmdl3\rcx_comm.c Sun Jan 16 23:17:22 2000
@@ -42,6 +42,7 @@
/* Globals */

int __comm_debug = 0;
+int fd = 0;

/* Timer routines */

@@ -85,7 +86,7 @@
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;

- if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 0) {
+ if (select(fd+1, &fds, NULL, NULL, &tv) < 0) {
    perror("select");
    exit(1);
}
@@ -94,8 +95,8 @@
    break;

if ((count = read(fd, &bufp[len], maxlen - len)) < 0) {
-     perror("read");
-     exit(1);
+     fputs("R", stderr);
+     continue;
}

len += count;
@@ -107,11 +108,22 @@
/* RCX routines */

int
-rcx_init(char *tty, int is_fast)
+rcx_init(char *stty, int is_fast)
{
     int fd;
+    char *tty;
+    static int old_isfast;
+    static char old_device[100];
     struct termios ios;

+    if (stty == NULL) {
+ is_fast=old_isfast;
+    } else {
+ old_isfast=is_fast;
+ strcpy(old_device, stty);
+    }
+    tty=old_device;
+
     if (__comm_debug) printf("mode = %s\n", is_fast ? "fast" : "slow");

     if ((fd = open(tty, O_RDWR)) < 0) {
@@ -153,7 +165,7 @@
}

int
-rcx_wakeup_tower (int fd, int timeout)
+rcx_wakeup_tower (int myfd, int timeout)
{
     char msg[] = { 0x10, 0xfe, 0x10, 0xfe };
     char buf[BUFFERSIZE];
@@ -164,11 +176,16 @@
     timer_reset(&timer);

     do {
- if (write(fd, msg, sizeof(msg)) != sizeof(msg)) {
-     perror("write");
-     exit(1);
+ if (write(myfd, msg, sizeof(msg)) != sizeof(msg)) {
+     fputs("W", stderr);
+     /* reset connection if echo is bad */
+     close(myfd);
+     fd = rcx_init(NULL, -1);
+     myfd = fd;
+     /* Retry until timeout */
+     continue;
}
- count += len = nbread(fd, buf, BUFFERSIZE, 50);
+ count += len = nbread(myfd, buf, BUFFERSIZE, 50);
if (len == sizeof(msg) && !memcmp(buf, msg, sizeof(msg)))
    return RCX_OK; /* success */
     } while (timer_read(&timer) < (float)timeout / 1000.0f);
@@ -209,7 +226,7 @@


int
-rcx_send (int fd, void *buf, int len, int use_comp)
+rcx_send (int myfd, void *buf, int len, int use_comp)
{
     char *bufp = (char *)buf;
     char buflen = len;
@@ -245,15 +262,17 @@
     }

     /* Send message */
-
-    if (write(fd, msg, msglen) != msglen) {
- perror("write");
- exit(1);
+    if (write(myfd, msg, msglen) != msglen) {
+ fputs("Resync\r", stderr);
+ /* reset connection if echo is bad */
+ close(myfd);
+ fd = rcx_init(NULL, -1);
+ return RCX_BAD_LINK;
     }

     /* Receive echo */

-    echolen = nbread(fd, echo, msglen, 100);
+    echolen = nbread(myfd, echo, msglen, 100);

     if (__comm_debug) {
printf("msglen = %d, echolen = %d\n", msglen, echolen);
@@ -266,8 +285,7 @@
     if (echolen != msglen /* || memcmp(echo, msg, msglen) */ ) {

/* Flush connection if echo is bad */
-
- echolen = nbread(fd, echo, BUFFERSIZE, 200);
+ echolen = nbread(myfd, echo, BUFFERSIZE, 200);

return RCX_BAD_ECHO;
     }
-------- snipsnip

That's all.

Hope it helps... :-)

Bye,
      Paolo.



Message has 1 Reply:
  Re: firmdl3 on Winnt - no more problems!
 
Hello Paolo, Would you mind sharing that binary executable of firmdl3 ??? Maybe Kekoa should make executables available on his site? I tried using NQC -firmware but got "RCX not responding" after what appeared to be a successful download. Thanks, (...) (25 years ago, 18-Jan-00, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR