C++ (Cpp) fflush Examples

C++ (Cpp) fflush - 30 examples found. These are the top rated real world C++ (Cpp) examples of fflush extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void update(int axisc, int * axis, int buttonc, char * button)
{
    static char * b = NULL;
    if (b == NULL) {
        b = calloc(buttonc, sizeof(char));
    }

    if (button[0] && !b[0]) {
        b[0] = 1;
        fprintf(can, "asserv speed 0 0\n");
        fflush(can);
    } else if (button[1] && !b[1]) {
        b[1] = 1;
        fprintf(can, "asserv rot 18000\n");
        fflush(can);
    } else if (button[2] && !b[2]) {
        b[2] = 1;
        fprintf(can, "asserv rot -9000\n");
        fflush(can);
    } else if (button[3] && !b[3]) {
        b[3] = 1;
        fprintf(can, "asserv rot 9000\n");
        fflush(can);
    } else {
        int i;
        for (i = 0; i < 4 ; i++) {
            b[i] = 0;
        }
        update_pos(axis[0]*sensi, axis[1]*sensi, axis[2]*sensi);
    }
}
void *recv_cmd_func(void *args)
{
    ros::NodeHandle n;
    ros::Publisher motor_pub = n.advertise<std_msgs::Char>("motor_chatter", 1000);
    ros::Publisher servox_pub = n.advertise<std_msgs::Char>("servox_chatter", 1000);
    ros::Publisher servoy_pub = n.advertise<std_msgs::Char>("servoy_chatter", 1000);
    int client_sockfd = *(int *)args;
    //printf("%d ", client_sockfd);
    //fflush(stdout);
    char speech_cmd;
    while(1)
    {
        int recvlen = 0;
        if((recvlen = recv(client_sockfd, &speech_cmd, 1, 0)) == 1)
        {
            printf("recv cmd is %c\n", speech_cmd);
            fflush(stdout);
            //motor.data = speech_cmd;
            //motor_pub.publish(motor);
            convert(speech_cmd, motor_pub, servox_pub, servoy_pub);
            printf("servox cmd is %c\n", servox.data);
            fflush(stdout);
            printf("servoy cmd is %c\n", servoy.data);
            fflush(stdout);
            printf("motor cmd is %c\n", motor.data);
            fflush(stdout);
            //speech_cmd = 'q';
        }
    }
}
Example #3
0
uint8_t Sket::sendData(uint32_t cmd,uint32_t frame, uint32_t payload_size,uint8_t *payload)
{
    SktHeader header;
    memset(&header,0,sizeof(header));

    header.cmd=cmd;
    header.payloadLen=payload_size;
    header.frame=frame;
    header.magic=(uint32_t)MAGGIC;

    if(sizeof(header)!= send(workSocket,(char *)&header,sizeof(header),0))
    {
        printf("Error in senddata: header\n");
        fflush(stdout);
        exit(-1);
    }
    int togo=payload_size;
    int chunk;
    while(togo)
    {
        chunk=send(workSocket,(char *)payload,togo,0);
        if(chunk<0)
        {
            printf("Error in senddata: body\n");
            fflush(stdout);
            exit(-1);
        }
        togo-=chunk;
        payload+=chunk;
    }
    return 1;


    return 0;
}
Example #4
0
File: log.cpp Project: nixz/covise
int __dprintf(int dlevel, char *fmt, ...)
{
    va_list ap;

    if (dlevel <= _debuglevel)
    {
        if (_debugstderr || dlevel == 0)
        {
            va_start(ap, fmt);
            vfprintf(stderr, fmt, ap);
            va_end(ap);
            fflush(stderr);
        }
        if (_D)
        {
#ifdef DEBUG
            if (*__src)
                fprintf(_D, "%-25.25s(%4d): ", __src, __srcline);
#endif
            va_start(ap, fmt);
            vfprintf(_D, fmt, ap);
            va_end(ap);
            fflush(_D);
        }
    }
    return 1; // wegen Makro !!!!
}
Example #5
0
void * sender(void * arg)
{
    int l = INT_MIN;
    int r = INT_MIN;
    int a = INT_MIN;
    int u = 0;
    int v = 0;
    int todo;

    while (1) {

        todo = 0;

        if (pthread_mutex_lock(&mtx) < 0) {
            perror("pthread_mutex_lock");
            exit(1);
        }

        if (l == left && r == right) {
            u++;
        } else {
            u = 0;
            l = left;
            r = right;
        }
        if (a == angle) {
            v++;
        } else {
            v = 0;
            a = angle;
        }

        if (pthread_mutex_unlock(&mtx) < 0) {
            perror("pthread_mutex_unlock");
            exit(1);
        }

        if (u < NB_CONSIGNE) {
            fprintf(can, "asserv speed %d %d\n", r, l);
            fflush(can);
            todo = 1;
        }
        if (v < NB_CONSIGNE) {
            fprintf(can, "ax 1 angle set %d\n", a);
            fflush(can);
            usleep(100*1000);
            fprintf(can, "ax 2 angle set %d\n", a);
            fflush(can);
            todo = 1;
        }
        if (todo) {
            usleep(DELAY * 1000);
        } else {
            pthread_mutex_lock(&cnd_mtx);
            pthread_cond_wait(&cnd, &cnd_mtx);
            pthread_mutex_unlock(&cnd_mtx);
        }

    }
}
Example #6
0
void getpassword(const char *prompt, char *pbuf)
{
    struct sgttyb ttyb;
    int flags;
    register char *p;
    register int c;
    FILE *fi;
    void (*sig)(int);

    if ((fi = fdopen(open("/dev/tty", 2, 0), "r")) == NULL)
        fi = stdin;
    else
        setbuf(fi, (char *)NULL);
    sig = signal(SIGINT, SIG_IGN);
    ioctl(fileno(fi), TIOCGETP, &ttyb);
    flags = ttyb.sg_flags;
    ttyb.sg_flags &= ~ECHO;
    ioctl(fileno(fi), TIOCSETP, &ttyb);
    fprintf(stderr, "%s", prompt);
    fflush(stderr);
    for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
        if (p < &pbuf[PHRASELEN-1])
            *p++ = c;
    }
    *p = '\0';
    fprintf(stderr, "\n");
    fflush(stderr);
    ttyb.sg_flags = flags;
    ioctl(fileno(fi), TIOCSETP, &ttyb);
    (void)signal(SIGINT, sig);
    if (fi != stdin)
        fclose(fi);
}