Esempio n. 1
0
/**
 * Write into a buffer to send via TCP.
 * @param devptr TCP device table entry
 * @param buf buffer to read octets into
 * @param len size of the buffer
 * @return count of octets written
 */
devcall tcpWrite(device *devptr, void *buf, uint len)
{
    uint count = 0;
    uchar ch;
    struct tcb *tcbptr;
    uchar *buffer = buf;
    int check;

    tcbptr = &tcptab[devptr->minor];

    /* Handle states for which data can never be sent */
    wait(tcbptr->mutex);
    check = stateCheck(tcbptr);
    if (check != OK)
    {
        signal(tcbptr->mutex);
        return check;
    }
    signal(tcbptr->mutex);

    /* Put each octet from the buffer into output buffer */
    while (count < len)
    {
        /* Wait for space and write as much as possible into the output
         * buffer; Preserve the circular buffer */
        wait(tcbptr->writers);
        wait(tcbptr->mutex);

        /* Returned if changed to a state where no data can be sent */
        check = stateCheck(tcbptr);
        if (check != OK)
        {
            signal(tcbptr->writers);
            return check;
        }

        while ((tcbptr->ocount < TCP_OBLEN) && (count < len))
        {
            ch = *buffer++;
            tcbptr->out[((tcbptr->ostart + tcbptr->ocount) % TCP_OBLEN)] =
                ch;
            tcbptr->ocount++;
            count++;
        }
        /* If space remains, another writer can write */
        if (tcbptr->ocount < TCP_OBLEN)
        {
            signal(tcbptr->writers);
        }
        if ((TCP_ESTAB == tcbptr->state)
            || (TCP_CLOSEWT == tcbptr->state))
        {
            tcpSendData(tcbptr);
        }
        signal(tcbptr->mutex);
    }

    return count;
}
Esempio n. 2
0
ThreadNet::ThreadNet(QObject *parent) : QThread(parent)
{
	tcp_server = new QTcpServer();
	connect(tcp_server, SIGNAL(newConnection()), this, SLOT(tcpSendData()));
	tcpInitServer();

	udp_socket = new QUdpSocket();
	udp_socket->bind(udp_port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
	connect(udp_socket, SIGNAL(readyRead()), this, SLOT(udpProcessPendingDatagrams()));

	checkUpdate();
	setTimer();



}
Esempio n. 3
0
void update_device(data_t *data)
{
    int i;
	

    /* Abbreviations for the electrodes */
    const char source[] = { 'S', 'W', 'N', 'E', 'C' };


    while(gestic_data_stream_update(data->gestic, NULL) == 0)
    {
        /* Print update of the position */
        gotoxy(0, 4);
        if(data->gestic_pos != NULL)
        {    printf("Position:         X %5d   Y %5d   Z %5d   \n",
                   data->gestic_pos->x, data->gestic_pos->y,
                   data->gestic_pos->z);
		/*
		counts++;
		if (counts == 10)
		{
			if((lastz != data->gestic_pos->z))
			{
			tcpData[0]='Z';
			sprintf(&tcpData[1],"%d",data->gestic_pos->z);
			tcpSendData(tcpData);
			lastz = data->gestic_pos->z;
			counts = 0;
			}
		}*/
		}
        else
            printf("Position:         Not available\n");

        /* Print update of gestures */
        gotoxy(0, 5);
        if(data->gestic_gesture != NULL) {
            /* Remember last gesture and reset it after 1s = 200 updates */
            if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6)
                data->last_gesture = data->gestic_gesture->gesture;
            else if(data->gestic_gesture->last_event > 1)	//Shrenik
                data->last_gesture = 0;

            printf("Gesture:          %s \n", gestures[data->last_gesture]);
			//*tcpData = (char *)gestures[data->last_gesture];
			if(strcmp(gestures[data->last_gesture],"DNULL"))
			{
				tcpSendData(gestures[data->last_gesture]);

			}
			else if((lastz != data->gestic_pos->z))
			{
				if(((lastz-data->gestic_pos->z) > 1000) | ((data->gestic_pos->z - lastz) > 1000))
				{
				tcpData[0]='Z';
				sprintf(&tcpData[1],"%d",data->gestic_pos->z);
				// tcpSendData(tcpData);
				lastz = data->gestic_pos->z;
				//counts = 0;
				//Sleep(10);
				}
			}

        } else {
            printf("Gesture:          Not available\n");
        }

        /* Print update of touch */
        gotoxy(0, 6);
        printf("Touch:            ");
        for(i = 0; i < 5; ++i) {
            if(data->gestic_touch->flags & (1<<i))
                printf("%c ", source[i]);
        }
        printf("           \n");

        /* Print update of AirWheel */
        gotoxy(0, 7);
        if(data->gestic_air_wheel != NULL) {
            printf("Air Wheel:        %d   \n", data->gestic_air_wheel->counter);
        } else {
            printf("Air Wheel:        Not available\n");
        }

        /* Print update of Signal Deviation */
        gotoxy(0, 8);
        if(data->gestic_sd != NULL) {
            printf("Signal Deviation:");
            for(i = 0; i < 5; ++i)
                printf(" %c %5.0f  ", source[i], data->gestic_sd->channel[i]);

            if(data->gestic_calib != NULL)
                printf("\nLast Calibration: %7d",
                       data->gestic_calib->last_event);
        } else {
            printf("Signal Deviation: Not available\n");
        }
    }
}