コード例 #1
0
void SEND_UART (uint16_t time)
{
	static uint16_t ticker = 0;
	
	if ((uint16_t)(ticker+time)== GetTicker()) 
	{
		ticker = GetTicker();
		
		SENDDATA(PID_VELO_HOLD.set_point,txbuffer,0);
		SENDDATA(PID_VELO_HOLD.feedback,txbuffer,1);
		SENDDATA(PID_TILT.set_point,txbuffer,2);
		SENDDATA(PID_TILT.feedback,txbuffer,3);
		SENDDATA(Left_motor.U0_100,txbuffer,4);
	}
}
コード例 #2
0
ファイル: service.c プロジェクト: trailofbits/cb-multios
/**
 * Main request handling loop
 *
 * @return 0 on success, err code on failure
 */
int go(void) {
    int i;
    int res;
    uint32_t tmp = 0;
    uint32_t *seed;
    char *resend;
    size_t tosend;
    size_t offset;
    uint32_t *f;

    init_fs();
    debug("fs init complete\n");

    if (!READDATATIMEOUT(conf)) {
        debug("failed to recv conf\n");
        res = 0;
        SENDDATA(res);
        return 3;
    }

    if (conf.min_ver > VERSION || conf.max_ver < VERSION) {
        debug("version mismatch\n");
        res = 0;
        SENDDATA(res);
        return 5;
    }
    //send success ack
    res = 1;
    SENDDATA(res);

    //seed our PRNG
    //because of how it works, seeding with 0's == no encryption
    seed = (uint32_t*)(FLAG_PAGE + (8*sizeof(uint32_t)));

    f = malloc(8*sizeof(uint32_t));

    if (!f)
        return 1;

    cgc_memcpy(f, seed, 8*sizeof(uint32_t));

    if (!conf.encrypt)
        seed = calloc(8*sizeof(uint32_t));

    srand(seed);

    //inform client of seed
    for (i = 0; i < 8; i+=2) {
        if (conf.encrypt)
            tmp = f[i]^f[i+1];
        SENDDATA(tmp);
    }

#ifdef PATCHED_1
    cgc_memset(f, '\0', 8*sizeof(uint32_t));
#endif
    debug("flag data: @h\n",f);

    free(f);


    while (1) {
        res = process_req();
        if (res == ERR || res == EXIT) {
            break;
        } else if (res == DISCON && conf.allow_reconnect && last) {
            debug("disconnected, retrying\n");
            if (!READDATATIMEOUT(conf)) {
                debug("failed to recv conf\n");
                return 3;
            }

            if (!last)
                continue;

            debug("Allocating resend buffer of @h bytes.\n",conf.buf_size+sizeof(resp_t));
#ifdef PATCHED_1
            resend = calloc(conf.buf_size+sizeof(resp_t));
#else
            resend = malloc(conf.buf_size+sizeof(resp_t));
#endif
            debug("resend data: @h\n",resend);

            if (!READDATA(offset)) {
                debug("failed to recv offset\n");
                return 4;
            }

            tosend = sizeof(resp_t)-offset;
            tosend = tosend > sizeof(resp_t) ? sizeof(resp_t) : tosend;

            if (offset > conf.buf_size || offset > sizeof(resp_t)
#ifdef PATCHED_1
                    || tosend > (conf.buf_size+sizeof(resp_t))
#endif
               ) {
                debug("failed to validate offset.\n");
                return 1;
            } else {
                debug("copying last out\n");
                cgc_memcpy(resend, last+offset, sizeof(resp_t)-offset);
            }

#ifdef PATCHED_1
            if (tosend != esendall(stdout, resend, tosend))
#else
            if (tosend != esendall(stdout, resend, sizeof(resp_t)))
#endif
                return 4;
            debug("Resent all, should be back!\n");

            free(resend);
            free(last);
            last = NULL;
        }
    }
    return 0;
}