Example #1
0
int AJ_Main()
{
    AJ_Status status;
    memset(&txBuffer, 'T', sizeof(txBuffer));
    memset(&rxBuffer, 'R', sizeof(rxBuffer));

    int blocks;
    int blocksize = LOCAL_DATA_PACKET_SIZE;
    for (blocks = 0; blocks < 16; blocks++) {
        memset(txBuffer + (blocks * blocksize), 0x41 + (uint8_t)blocks, blocksize);
    }

#ifdef READTEST
    status = AJ_SerialInit("/dev/ttyUSB0", BITRATE, AJ_SERIAL_WINDOW_SIZE, AJ_SERIAL_PACKET_SIZE);
#else
    status = AJ_SerialInit("/dev/ttyUSB1", BITRATE, AJ_SERIAL_WINDOW_SIZE, AJ_SERIAL_PACKET_SIZE);
#endif

    AJ_AlwaysPrintf(("serial init was %u\n", status));




#ifdef READTEST
    AJ_Sleep(2000); // wait for the writing side to be running, this should test the queuing of data.
    // try to read everything at once
    int i = 0;

    //for ( ; i < 10000; ++i) {
    while (1) {
        AJ_SerialRecv(rxBuffer, sizeof(rxBuffer), 50000, NULL);
    }


/*
    //Read small chunks of a packet at one time.
    for (blocks = 0 ; blocks < 16*4; blocks++) {
        AJ_SerialRecv(rxBuffer+(blocks*blocksize/4), blocksize/4, 2000, NULL);
   //        AJ_Sleep(200);
    }
 */
    AJ_DumpBytes("Post serial recv", rxBuffer, sizeof(rxBuffer));
    AJ_Sleep(500);
#else
    AJ_Sleep(5000);
    int i = 0;


    while (1) {
        AJ_SerialSend(txBuffer, sizeof(txBuffer));
        ++i;
        if (i % 500 == 0) {
            AJ_AlwaysPrintf(("Hit iteration %d\n", i));
        }
    }

    AJ_AlwaysPrintf(("post serial send\n"));
#endif


    while (1) {
        AJ_StateMachine();
    }


    return(0);
}
Example #2
0
int AJ_Main()
{
    AJ_Status status;

    while (1) {
        int windows = 1 << (rand() % 3); // randomize window width 1,2,4
        int blocksize = 50 + (rand() % 1000); // randomize packet size 50 - 1050
        AJ_AlwaysPrintf(("Windows:%i Blocksize:%i\n", windows, blocksize));
        txBuffer = (uint8_t*) AJ_Malloc(blocksize);
        rxBuffer = (uint8_t*) AJ_Malloc(blocksize);
        memset(txBuffer, 0x41,  blocksize);
        memset(rxBuffer, 'r', blocksize);

#ifdef READTEST
        status = AJ_SerialInit("/dev/ttyUSB0", BITRATE, windows, blocksize);
#else
        status = AJ_SerialInit("/dev/ttyUSB1", BITRATE, windows, blocksize);
#endif

        AJ_AlwaysPrintf(("serial init was %u\n", status));
        if (status != AJ_OK) {
            continue; // init failed perhaps from bad parameters, start the loop again
        }

        // Change the buffer transmission function to one that fuzzes the output.
        AJ_SetTxSerialTransmit(&FuzzBuffer);

#ifdef READTEST
        AJ_Sleep(2000); // wait for the writing side to be running, this should test the queuing of data.
        // try to read everything at once
        int i = 0;

        while (1) {
            AJ_SerialRecv(rxBuffer, blocksize, 50000, NULL);
        }


        AJ_DumpBytes("Post serial recv", rxBuffer, blocksize);
        AJ_Sleep(500);
#else
        AJ_Sleep(5000);
        int i = 0;


        while (1) {
            // change the packet to be sent every time through the loop.
            memset(txBuffer, 0x41 + (i % 26), blocksize);
            memset(rxBuffer, 0x41 + (i % 26), blocksize);
            AJ_SerialSend(txBuffer, blocksize);
            ++i;
            if (i % 20 == 0) {
                AJ_AlwaysPrintf(("Hit iteration %d\n", i));
                break;
            }
            AJ_SerialRecv(rxBuffer, blocksize, 5000, NULL);
        }

        AJ_AlwaysPrintf(("post serial send\n"));
#endif

        // clean up and start again
        AJ_SerialShutdown();
        AJ_Free(txBuffer);
        AJ_Free(rxBuffer);
    }
    return(0);
}
Example #3
0
int main()
{
    AJ_Status status;
    memset(&txBuffer, 'T', sizeof(txBuffer));
    memset(&rxBuffer, 'R', sizeof(rxBuffer));

    int blocks;
    int blocksize = LOCAL_DATA_PACKET_SIZE;
    for (blocks = 0; blocks < 16; blocks++) {
        memset(txBuffer + (blocks * blocksize), 0x41 + (uint8_t)blocks, blocksize);
    }

#ifdef READTEST
    status = AJ_SerialInit("/tmp/COM0", BITRATE, AJ_SERIAL_WINDOW_SIZE, AJ_SERIAL_ENABLE_CRC, AJ_SERIAL_PACKET_SIZE);
#else
    status = AJ_SerialInit("/tmp/COM1", BITRATE, AJ_SERIAL_WINDOW_SIZE, AJ_SERIAL_ENABLE_CRC, AJ_SERIAL_PACKET_SIZE);
#endif

    AJ_Printf("serial init was %u\n", status);

    uint32_t timerEndProc = 9999;
    status = AJ_TimerRegister(100000, &TimerCallbackEndProc, NULL, &timerEndProc);
    AJ_Printf("Added id %u\n", timerEndProc);


    int iter;
    int i;
#ifdef READTEST
    AJ_Sleep(2000); // wait for the writing side to be running, this should test the queuing of data.
    for (iter = 0; iter < 10; iter++) {
        AJ_Printf("iteration %d\n########################################################################\n", iter);
        AJ_SerialRecv(rxBuffer, sizeof(rxBuffer), 10000, NULL);
        if (0 == memcmp(txBuffer, rxBuffer, sizeof(rxBuffer))) {
            AJ_Printf("Passed#: buffers match.\n");
        } else {
            AJ_Printf("FAILED#: buffers mismatch.\n");
            AJ_DumpBytes("RXBUFFER:", rxBuffer, sizeof(rxBuffer));
            AJ_DumpBytes("TXBUFFER:", txBuffer, sizeof(txBuffer));

            exit(-1);
        }
        //AJ_SerialSend(txBuffer, sizeof(txBuffer));

    }
    AJ_Printf("post serial recv\n");

    AJ_Sleep(4000);
#else

    AJ_Sleep(500);
    for (iter = 0; iter < 10; iter++) {
        printf("iteration %d\n########################################################################\n", iter);
        AJ_SerialSend(txBuffer, sizeof(txBuffer));
        /*AJ_SerialRecv(rxBuffer, sizeof(rxBuffer), 10000, NULL);
           if (0 == memcmp(txBuffer, rxBuffer, sizeof(rxBuffer))) {
            AJ_Printf("Passed##: buffers match.\n");
           } else {
            AJ_Printf("FAILED##: buffers mismatch.\n");
            AJ_DumpBytes("RXBUFFER:", rxBuffer, sizeof(rxBuffer));
            AJ_DumpBytes("TXBUFFER:", txBuffer, sizeof(txBuffer));
            exit(-1);
           }*/

    }

    AJ_Printf("post serial send\n");
    AJ_Sleep(4000);
#endif


    /*while (1) {
        usleep(4000);
       }*/


    return(0);
}
int AJ_Main()
{
    AJ_Status status;

    status = AJ_SerialInit("/dev/ttyUSB1", BITRATE, AJ_SERIAL_WINDOW_SIZE, AJ_SERIAL_PACKET_SIZE);
    AJ_AlwaysPrintf(("serial init was %u\n", status));
    uint16_t txlen;
    uint16_t rxlen;
    int i = 0;

#ifdef ECHO
    while (1) {
        AJ_AlwaysPrintf(("Iteration %d\n", i++));
        status = AJ_SerialRecv(rxBuffer, RANDOM_BYTES_MAX, 5000, &rxlen);
        if (status == AJ_ERR_TIMEOUT) {
            continue;
        }
        if (status != AJ_OK) {
            AJ_AlwaysPrintf(("AJ_SerialRecv returned %d\n", status));
            exit(1);
        }
        AJ_Sleep(rand() % 5000);

        status = AJ_SerialSend(rxBuffer, rxlen);
        if (status != AJ_OK) {
            AJ_AlwaysPrintf(("AJ_SerialSend returned %d\n", status));
            exit(1);
        }

        AJ_Sleep(rand() % 5000);
    }
#else
    txlen = 0;
    while (1) {
        AJ_AlwaysPrintf(("Iteration %d\n", i++));
        txlen = rand() % 5000;
        for (int i = 0; i < txlen; i++) {
            txBuffer[i] = rand() % 256;
            rxBuffer[i] = 1;
        }
        status = AJ_SerialSend(txBuffer, txlen);
        if (status != AJ_OK) {
            AJ_AlwaysPrintf(("AJ_SerialSend returned %d\n", status));
            exit(1);
        }
        AJ_Sleep(rand() % 5000);
        status = AJ_SerialRecv(rxBuffer, txlen, 50000, &rxlen);
        if (status != AJ_OK) {
            AJ_AlwaysPrintf(("AJ_SerialRecv returned %d\n", status));
            exit(1);
        }
        if (rxlen != txlen) {
            AJ_AlwaysPrintf(("Failed: length match rxlen=%d txlen=%d.\n", rxlen, txlen));
            exit(-1);
        }
        if (0 != memcmp(txBuffer, rxBuffer, rxlen)) {
            AJ_AlwaysPrintf(("Failed: buffers match.\n"));
            exit(-1);
        }

    }
#endif
    return(0);
}