Exemplo n.º 1
0
void serial_simple_step(void)
{

#define MAX_PACKET_SIZE 50

    unsigned char data[MAX_PACKET_SIZE];
	//unsigned short data[MAX_PACKET_SIZE];

    static unsigned int packetSize=1;
    unsigned int i;

    if (packetSize <= MAX_PACKET_SIZE) {
        size_t sizeRecvd;
        unsigned int packetIdx=0;
        rtIOStreamRecv(0, data, (size_t) packetSize, &sizeRecvd);
        packetIdx=(unsigned int) sizeRecvd;
        while (packetIdx < packetSize) {
            rtIOStreamRecv(0, &data[packetIdx], (size_t) (packetSize-packetIdx), &sizeRecvd);
            packetIdx=packetIdx+(unsigned int) sizeRecvd;
        }
        for (i=0; i<packetSize; i++) {
            /* Expected return packet is received data + 1 */
            data[i]=data[i]+1;
        }
        {
            size_t tmp;
            rtIOStreamSend( 0, data, packetSize, &tmp);
        }
        packetSize++;
    }
}
Exemplo n.º 2
0
/* Function: ExtGetHostPkt =====================================================
 * Abstract:
 *  Attempts to get the specified number of bytes from the comm line.  The
 *  number of bytes read is returned via the 'nBytesGot' parameter.
 *  EXT_NO_ERROR is returned on success, EXT_ERROR is returned on failure.
 *
 * NOTES:
 *  o it is not an error for 'nBytesGot' to be returned as 0
 *  o not guaranteed to read total requested number of bytes
 */
PUBLIC boolean_T ExtGetHostPkt(
    const ExtUserData *UD,
    const int         nBytesToGet,
    int               *nBytesGot, /* out */
    char              *dst)       /* out */
{
    boolean_T error = EXT_NO_ERROR;
    int_T result;
    size_t stNBytesGot;

    result = rtIOStreamRecv(UD->streamID, dst, (size_t) nBytesToGet, &stNBytesGot);

    if (result == RTIOSTREAM_ERROR) {
        error = EXT_ERROR;
    } else {
        *nBytesGot = (int) stNBytesGot;
    }

    return(error);
} /* end ExtGetHostPkt */