xmodem crc

This is a discussion on xmodem crc within the C++ Programming forums, part of the General Programming Boards category; hello, I want to send a file with xmodem crc. After the first "C" from the reciever, I prepare the ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    xmodem crc

    hello,

    I want to send a file with xmodem crc.
    After the first "C" from the reciever, I prepare the first packet and send it to the reciever. But then I get another "C" instead a "NAK" or an "ACK".

    Has anybody an idea, or a working example for windows/dos with the source code.

    Thanks a lot.

    cu hick.hack

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    8
    yes, I know already what the xmodem protocol is for use.
    But it dosn't work in my code.
    Want I want is to send a file is the same way like hyperterminal.

    Here is my code for preparing the xmodem block.

    Code:
    switch (szBuffer[0]) 
    {
      case 'C':  // 'C' means the reciever want data in XModem CRC
      packetno = 1;
      filepointer = fopen("start.sre", "rb"); // open the file for binary read
    
      while (!feof(filepointer)) 
      {
        // xbuff[0] = SOH; bufsz = 128;  // 128 Byte block size
        xbuff[0] = STX; bufsz = 1024;  // 1024 Byte block size
        xbuff[1] = packetno;
        xbuff[2] = ~packetno;
                            
        memset (&xbuff[3], 0, bufsz);
        numread = fread( &xbuff[3], sizeof( char ), bufsz, filepointer);
        if (numread < bufsz) xbuff[3+numread] = CTRLZ;
        
        // calculate the crc checksum                    
        unsigned short ccrc = calcrc((char *) &xbuff[3], bufsz);
        xbuff[bufsz+3] = (ccrc>>8) & 0xFF;
        xbuff[bufsz+4] = ccrc & 0xFF;
    
        do
        {
          // the serial class is from this homepage
          // http://home.ict.nl/~ramklein/Projects/Serial.html
          serial.Write(&xbuff[0], bufsz + 5);  
          serial.Read(szBuffer, sizeof(szBuffer)-1, &dwBytesRead);
          if (dwBytesRead > 0) 
          {
            switch (szBuffer[0]) 
            {
            case NAK:   printf ("%d NAK recieved \n", szBuffer[0]);
                               break;
            case ACK:   printf ("%d ACK recieved \n", szBuffer[0]);
                               break;
            case CTRLZ: printf ("%d Cancel by remote \n", szBuffer[0]);
                               break;
            default:    printf ("%d Unknown \n", szBuffer[0]);
                             break;
            }
          }
        } while ((szBuffer[0] != ACK));
    
        // If sending was succesfully
        packetno++;
        if (packetno >= 256) packetno = 0;
     }
    
      // the whole file was send
     fclose (filepointer);
    }
    and here is the code for the calccrc function

    Code:
    int calcrc(char *ptr, int count)
    {
        int crc, i;
    
        crc = 0;
    
        while (--count >= 0) {
           crc = crc ^ (int)*ptr++ << 8;
    
           for (i = 0; i < 8; ++i)
               if (crc & 0x8000)
                   crc = crc << 1 ^ 0x8408;
               else
                   crc = crc << 1;
           }
       return (crc & 0xFFFF);
    }
    
    thanks for your help
    Last edited by hick.hack; 02-20-2003 at 08:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CRC Check
    By silentkarma in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2008, 04:20 AM
  2. CRC problem
    By NewGuy100 in forum C Programming
    Replies: 6
    Last Post: 09-11-2005, 09:57 AM
  3. Crc error
    By Oluf in forum Tech Board
    Replies: 21
    Last Post: 04-30-2004, 10:57 AM
  4. xmodem question
    By hick.hack in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2003, 04:09 AM
  5. CRC / checksum
    By Zoltarc in forum C++ Programming
    Replies: 0
    Last Post: 11-30-2002, 11:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21