Пример #1
0
void Modem::abortXModem()
{
    timer->stop();
    writeChar(CCAN);
    xreset();
    emit xmodemDone(false);
}
Пример #2
0
Modem::Modem(KandyPrefs *kprefs, QObject *parent, const char *name) :
    QObject(parent, name)
{
    mOpen = false;

    prefs = kprefs;

    timer = new QTimer(this, "modemtimer");
    Q_CHECK_PTR(timer);
    connect(timer, SIGNAL(timeout()), SLOT(timerDone()));

    init();
    xreset();
}
Пример #3
0
void Modem::timerDone()
{
#ifdef MODEM_DEBUG
    fprintf(stderr, "Modem: timeout, xstate = %d.\n", xstate);
#endif

    switch(xstate)
    {
        case  0:			/* non-XModem mode	*/
            emit timeout();
            break;

        case  1:			/* 1st 'C' sent		*/
        case  2:			/* 2nd 'C' sent		*/
        case  3:			/* 3rd 'C' sent		*/
            writeChar('C');
            xstate++;
            timerStart(1000);	/* Should be 3000 in original XModem	*/
            break;

        case  4:			/* 4th 'C' sent		*/
            xcrc = false;

        case  5:			/* 1st <NAK> sent	*/
        case  6:			/* 2nd <NAK> sent	*/
        case  7:			/* 3rd <NAK> sent	*/
        case  8:			/* 4th <NAK> sent	*/
        case  9:			/* 5th <NAK> sent	*/
            writeChar(CNAK);
            xstate++;
            timerStart(1000);	/* Should be 10000 in original XModem	*/
            break;

        case 10:			/* 6th <NAK> sent	*/
            xreset();
            emit xmodemDone(false);
            break;

        default:			/* pending XModem block	*/
            writeChar(CNAK);
            xstate = 5;
            timerStart(1000);	/* Should be 10000 in original XModem	*/
    }
}
Пример #4
0
void Modem::close()
{
  timer->stop();

  delete sn;
  sn = 0;

  if ( fd ) {
    tcflush( fd, TCIOFLUSH );
    tcsetattr( fd, TCSANOW, &init_tty );
    ::close( fd );
    fd = 0;
  }

  xreset();

  unlockDevice();

  mOpen = false;
}
Пример #5
0
void Modem::readXChar(int)
{
    uchar c;
    static uchar crc_hi, block, cblock;


    while(read(fd, (void *) &c, 1) == 1)
    {
        switch(xstate)
        {
            case  1:	/* 1st 'C' sent 	*/
            case  2:	/* 2nd 'C' sent		*/
            case  3:	/* 3rd 'C' sent		*/
            case  4:	/* 4th 'C' sent		*/
            case  5:	/* 1st <NAK> sent	*/
            case  6:	/* 2nd <NAK> sent	*/
            case  7:	/* 3rd <NAK> sent	*/
            case  8:	/* 4th <NAK> sent	*/
            case  9:	/* 5th <NAK> sent	*/
            case 10:	/* 6th <NAK> sent	*/
                if(c == CSOH)
                {
                    timerStart(1000);
                    xsize = 128;
                    xstate = 11;
                }
                else if(c == CSTX)
                {
                    timerStart(1000);
                    xsize = 1024;
                    xstate = 11;
                }
                else if(c == CEOT)
                {
                    timer->stop();
                    writeChar(CACK);
                    xreset();
                    emit xmodemDone(true);
                }
                else
                    timerStart(1000);
                break;

            case 11:	/* <SOH> or <STX> received	 */
                timerStart(1000);
                block = c;
                xstate++;
                break;

            case 12:	/* block number received	*/
                timerStart(1000);
                cblock = c;
                xstate++;
                bufpos = 0;
                break;

            case 13:	/* complement block number received	*/
                timerStart(1000);
                buffer[ bufpos++ ] = c;
                if(bufpos == xsize)
                {
                    bufpos = 0;
                    xstate++;
                    if(!xcrc)
                        xstate++;
                }
                break;

            case 14:	/* data block received	*/
                timerStart(1000);
                crc_hi = c;
                xstate++;
                break;

            case 15:	/* crc high-byte received	*/
                timerStart(10000);
                xstate = 4;
                if((uchar)(block ^ cblock) != 0xff)
                {
                    writeChar(CNAK);
                    break;
                }
                if(block + 1 == xblock)
                {
                    writeChar(CACK);
                    break;
                }
                if(block != xblock)
                {
                    timer->stop();
                    writeChar(CCAN);
                    xreset();
                    emit xmodemDone(false);
                    break;
                }
                if(xcrc)
                {
                    if(((ushort) crc_hi << 8 | (ushort) c) != calcCRC())
                    {
                        writeChar(CNAK);
                        break;
                    }
                }
                else
                {
                    if(c != calcChecksum())
                    {
                        writeChar(CNAK);
                        break;
                    }
                }
                writeChar(CACK);
                xblock++;
                emit gotXBlock(buffer, xsize);
                break;

            default:
                break;
        }
    }
}