--Boundary-00=_3IPuC0nLnOSvIuL
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Le Mardi 21 Juin 2005 02:58, Joe Lovick a =E9crit=A0:
> Hi just wondering what was happening about this particular chipset (i have
> a canon LIDE 35) and if their is anything i can do to help? i am a happy c
> coder but am new to SANE.
> if thier is something i can do to help even if it is just testing then
> please give me a shout.
> cheers
>       joe

        Hello,

        I think that the first thing to do, is to have your scanner working 
under=
=20
windows and install usbsniff. So you'll be able to get logs from scanning=20
sessions. Then you have to analyze data to understand what's going on, and=
=20
try to make the backend do the same. At first, it may be hard, but once you=
=20
gained enough momentum, it is much easier.
        The raw logs can be simplified with awk scripts such as the one 
attached.=
=20
Once you identify things in log, you can write another awk script  that tur=
ns=20
data in a readable form. The motor.awk is a sample of what can be done. It=
=20
works on the file produced by parse1.awk. In the end, you have a script tha=
t=20
process logs through a bunch of awk files and produce a high level=20
representation of what is going on. The gl841_r17.pdf documents register us=
e=20
and values, and will help you in the process.
        Next, you have to write code that tries to do the same. When testing 
it, y=
ou=20
compare backend logs with decoded usb log, and fix differences until it=20
works.

Regards,
        Stef

--Boundary-00=_3IPuC0nLnOSvIuL
Content-Type: text/plain;
  charset="iso-8859-1";
  name="parse1.awk"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
        filename="parse1.awk"

# Hi! this script is a awk program script.
# Usage is: time awk -f parse1.awk usbsnoop.log > log1
#
# What does it do ?
# Extract usefull infos from sniffusb logs
#
# It works with sniffusb 1.8
# modified from Franck ZAGO's parse1.awk script which was
# loosely based on a script by Thomas SOUMARMON ([email protected]).
#


BEGIN {

        action = ""; 

        buffer[0] = 0;

        rtype = 0;
        request = 0;
        value = 0;
        rindex = 0;

        ignore_urb = 0;

        last_int_urb = -1;
}

{
        if(NR==1)
                urb = strtonum($5)-1;

        if ($4 == "URB") {

# New URB
                this_urb = strtonum($5);

                if (this_urb == last_int_urb) {
# this interrupt URB is coming back
                        ignore_urb = 1;
                        next;
                }

                if (way == "down" && $7 == "down") {
# This URB is also an interrupt URB
                        printf "URB %5d  skip\n", this_urb;
                        ignore_urb = 1;
                        last_int_urb = this_urb;
                        next;
                }
                
                old_way = way;
                way = $7;

                if (way == "back") {
                        if (urb != this_urb) {
                                printf "got URB back %d instead of %d at line 
%d\n", this_urb, urb, NR;
                                exit;
                        }
                }
                else if (way == "down") {
                        
                        ignore_urb = 0;

                        if (this_urb != urb+1 && this_urb != urb+2) {
                                printf "expected URB down %d instead of %d at 
line %d\n", urb+1, this_urb, NR;
                                exit;
                        }

                        if (last_int_urb != urb) {

                                if (endpoint == "CONTROL") {
                                        printf "URB %5d  control  0x%02x 0x%02x 
0x%02x 0x%02x len %5d", urb, rtype, request, value, rindex, buflen;
                                        if (direction == "OUT") {
                                                printf(" wrote ");
                                        } else {
                                                printf(" read  ");
                                        }

                                        for (i=0; i<buflen; i++)
                                                printf("0x%02x ", buffer[i]);
                                        printf("\n");
                                }
                                else if (endpoint == "BULK_IN") {
                                        printf "URB %5d  bulk_in  len %5d  read 
 ", urb, buflen;

                                        for (i=0; i<buflen; i++)
                                                printf("0x%02x ", buffer[i]);
                                        printf("\n");
                                }
                                else if (endpoint == "BULK_OUT") {
                                        printf "URB %5d  bulk_out len %5d  
wrote ", urb, buflen;
                                
                                        for (i=0; i<buflen; i++)
                                                printf("0x%02x ", buffer[i]);
                                        printf("\n");
                                }
                        }
                }
                else {
                        printf("BAD line %d", NR);
                        exit;
                }


                /* Next urb */
                         urb = strtonum($5);
        }

        if (ignore_urb) {
                next;
        }

        if ($1 == "PipeHandle") {
                if ($5 == "0x00000002]") endpoint = "BULK_OUT";
                else if ($5 == "0x00000081]") endpoint = "BULK_IN";
                else if ($5 == "0x00000083]") {
                        printf "URB %5d  skip\n", urb;
                        ignore_urb = 1;
                        way = "back";           # do as if we got the answer
                        last_int_urb = urb;
                        next;
                }
                else endpoint = "CONTROL";
        }

        if ($1 == "TransferBufferLength") buflen=strtonum("0x"$3);
        if ($1 == "RequestTypeReservedBits") rtype=strtonum("0x"$3);
        if ($1 == "Request") request=strtonum("0x"$3);
        if ($1 == "Value") value=strtonum("0x"$3);
        if ($1 == "Index") {
                rindex=strtonum("0x"$3);
                get_data = 0;
        }

        if ($4 == "(USBD_TRANSFER_DIRECTION_IN,") direction="IN";
        if ($4 == "(USBD_TRANSFER_DIRECTION_OUT,") direction="OUT";

        if ($2 == "URB_FUNCTION_VENDOR_DEVICE:") action="vendor";
        if ($2 == "URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:") action="bulk";
        if ($2 == "URB_FUNCTION_CONTROL_TRANSFER:") action="control";

# Take care of the data
        if ($1 == "UrbLink") {
                get_data = 0;
                if (data_left != 0) {
                        printf("error line %d (data left)\n", NR);
                        exit;
                }
        }

        if (get_data) {
                if (data_left > 16)
                        data_len = 16;
                else
                        data_len = data_left;

                if (NF == (data_len+1)) {
                        data_left = data_left - data_len;

                        for (i=0; i<data_len; i++) {
                                buffer[data_index] = strtonum("0x"$(i+2));
                                data_index ++;
                        }
                } else {
                        printf("error line %d (invalid data)\n", NR);
                        exit;
                }
        }

# We don't want to get data all the time.
        if ($1 == "TransferBufferMDL") {
                if ((direction == "OUT" && way == "down") ||
                        (direction == "IN" && way == "back")) {
                        
                        get_data = 1;
                        data_left = buflen;
                        data_index = 0;
                }
        }
}



--Boundary-00=_3IPuC0nLnOSvIuL
Content-Type: text/plain;
  charset="iso-8859-1";
  name="motor.awk"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
        filename="motor.awk"

#URB   251  bulk_out len     2  wrote 0x0f 0x01 
BEGIN {
        ex=""
}
{
        if(($6=="wrote")&&($7=="0x0f")&&($8=="0x01")&&($5=="2")) 
        {
                print "startMotor()"
                getline
        }
        else
        {
                if(($6=="wrote")&&($7=="0x0f")&&($8=="0x00")&&($5=="2")) 
                {
                        print "stopMotor()"
                        getline
                }
                else
                        print ex
        }
        ex=$0
}
END {
        print ex
}

--Boundary-00=_3IPuC0nLnOSvIuL--

Reply via email to