Exemple #1
0
int cwiid_beep(cwiid_wiimote_t *wiimote)
{
    /* unsigned char buf[SOUND_BUF_LEN] = { 0xA0, 0xCC, 0x33, 0xCC, 0x33,
        0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33,
        0xCC, 0x33, 0xCC, 0x33}; */
    unsigned char buf[SOUND_BUF_LEN] = { 0xA0, 0xC3, 0xC3, 0xC3, 0xC3,
                                         0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3,
                                         0xC3, 0xC3, 0xC3, 0xC3
                                       };
    int i;
    int ret = 0;
    pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t timer_cond = PTHREAD_COND_INITIALIZER;
    struct timespec t;

    if (exec_write_seq(wiimote, SEQ_LEN(speaker_enable_seq),
                       speaker_enable_seq)) {
        cwiid_err(wiimote, "Speaker enable error");
        ret = -1;
    }

    pthread_mutex_lock(&timer_mutex);

    for (i=0; i<100; i++) {
        clock_gettime(CLOCK_REALTIME, &t);
        t.tv_nsec += 10204081;
        /* t.tv_nsec += 7000000; */
        if (cwiid_send_rpt(wiimote, 0, RPT_SPEAKER_DATA, SOUND_BUF_LEN, buf)) {
            printf("%d\n", i);
            cwiid_err(wiimote, "Report send error (speaker data)");
            ret = -1;
            break;
        }
        /* TODO: I should be shot for this, but hey, it works.
         * longterm - find a better wait */
        pthread_cond_timedwait(&timer_cond, &timer_mutex, &t);
    }

    pthread_mutex_unlock(&timer_mutex);

    if (exec_write_seq(wiimote, SEQ_LEN(speaker_disable_seq),
                       speaker_disable_seq)) {
        cwiid_err(wiimote, "Speaker disable error");
        ret = -1;
    }

    return ret;
}
Exemple #2
0
/* Define a Nemesis-style Main() function which will serve as the
 * entry point of the user program if they haven't defined one.  This
 * allows the user to have a posix-style main() function, and have it
 * called in the traditional manner by this piece of code.  Since this
 * is in an ar-archive, it will only be used if Main() is undefined -
 * precisely the semantics we want. */
void Main(Closure_clp cl)
{
    NOCLOBBER uint32_t            argc;
    char ** NOCLOBBER             argv;
    char                          *null_arg = NULL;
    int                           ret;
    struct __atexit_stack_element __atexit_stack[__MAX_ATEXIT_FUNCS];
    int                           __atexit_stack_length;
#ifdef SPEC
    Time_T NOCLOBBER              start_time;
#endif

#ifdef SPEC
    start_time = NOW();
#endif

    __atexit_stack_length = 0;

    /*
     * Argument handling
     */
    TRY {
      uint32_t       i;
      Context_clp    ctx;
      uint32_t       num;
      
      ctx = NAME_LOOKUP ("arguments", Pvs(root), Context_clp);
      num = SEQ_LEN( Context$List( ctx ) );
      argv = Heap$Malloc (Pvs(heap), (num + 1) * sizeof (char *));
      for (i = 0, argc=0; i < num; i++) {
	uchar_t name[32];
	sprintf (name, "a%d", i);
	TRY {
	  argv[argc] = NAME_LOOKUP (name, ctx, string_t);
	  argc++;
	} CATCH_ALL {
	  /* one argument didn't have the right form, ignore it */
	} ENDTRY;
      }
      argv[argc] = (char *)NULL;
    } CATCH_ALL {
      argc = 0;
      argv = &null_arg;
    } ENDTRY;
    
    /* Run the program with a correctly setup exit. */
    CX_ADD("__atexit_stack", __atexit_stack, addr_t);
    CX_ADD("__atexit_stack_length", &__atexit_stack_length, addr_t);


#ifdef SPEC
    /* For timing stuff */
    CX_ADD("__spec_start_time", start_time, Time_T);
    (void)posixmain_atexit(__print_time);
#endif
    ret = main(argc, argv);
    if (ret)
	printf("main() exited with non-zero return code %d\n", ret);
}
Exemple #3
0
static SEQ *seq_mask_inplace(SEQ *seq)
{
        int a, b;  
        FILE *fp = fopen(seq->maskname, "r");

        if (fp == 0) {
                Fatalfr("cannot open '%s'", seq->maskname);
                return 0;
        } else {
                while (getpair(fp, &a, &b))
                        byte_fill_range(SEQ_CHARS(seq),SEQ_LEN(seq),'X',a,b);
                fclose(fp);
                seq->flags |= SEQ_HAS_MASK;
                return seq;
        }
}
Exemple #4
0
static IO_clp bindIO(IOOffer_cl *io_offer, HeapMod_cl *hmod, Heap_clp *heap) 
{
    IO_clp res; 
    IOData_Shm *shm;
    
    if(io_offer != NULL) {

	if(*heap) {   /* We have some memory => bind using it */
	    Type_Any    any;
	    IDCClientBinding_clp cb;

	    shm = SEQ_NEW(IOData_Shm, 1, Pvs(heap));
	    
	    SEQ_ELEM(shm, 0).buf.base = 
		HeapMod$Where(hmod, *heap, &(SEQ_ELEM(shm, 0).buf.len));
	    SEQ_ELEM(shm, 0).param.attrs  = 0;
	    SEQ_ELEM(shm, 0).param.awidth = PAGE_WIDTH;
	    SEQ_ELEM(shm, 0).param.pwidth = PAGE_WIDTH;
	    
	    cb = IOOffer$ExtBind(io_offer, shm, Pvs(gkpr), &any);
	    if(!ISTYPE(&any, IO_clp)) {
		eprintf("udp_socket.c [bindIO]: IOOffer$ExtBind failed.\n");
		if(cb) IDCClientBinding$Destroy(cb);
		RAISE_TypeSystem$Incompatible();
	    }
	    res = NARROW (&any, IO_clp);
	} else { 
	    /* Just bind to offer and create a heap afterwards. */
	    res = IO_BIND(io_offer);
	    shm = IO$QueryShm(res); 
	    if(SEQ_LEN(shm) != 1) 
		eprintf("udp_socket.c [bindIO]: "
			"got > 1 data areas in channel!\n");

	    /* Ignore extra areas for now */
	    *heap = HeapMod$NewRaw(hmod, SEQ_ELEM(shm, 0).buf.base, 
				   SEQ_ELEM(shm, 0).buf.len);
	}

	return res; 
    } 
    
    return (IO_cl *)NULL;
}
Exemple #5
0
static void FB_UpdateWindows_m(FB_clp self,
			       const FB_WinUpdatePkt *updates)
{

    FB_st *st = (FB_st *)self->st;
    int i;

    for(i = 0; i < SEQ_LEN(updates); i++) {
	
	FB_MgrWinData *data = &SEQ_ELEM(updates, i);
    
	FB_MoveWindow_m(self, data->wid, data->x, data->y);

	FB_ResizeWindow_m(self, data->wid, data->width, data->height);

	if(data->exposemask) 
	    FB_ExposeWindow_m(self, data->wid, data->exposemask);

    }

}
Exemple #6
0
SEQ *seq_revcomp_inplace(SEQ *seq) 
{
	do_revcomp(SEQ_CHARS(seq), SEQ_LEN(seq));
	seq->flags ^= SEQ_IS_REVCOMP;
	return seq;
}
Exemple #7
0
int seq_read_fasta(SEQ *seq)
{
	int b, c;
	charvec_t shdr = charvec_INIT(ckrealloc,ckfree);
	charvec_t sseq = charvec_INIT(ckrealloc,ckfree);

	if (feof(seq->fp) || ferror(seq->fp))
		return 0;

	if (seq->count > 0) { 
		if (seq->flags & SEQ_IS_SUBRANGE) {
			return 0;
		} else {
			seq->from = 1;
			seq->slen = -1; /* will be computed below */
		}
	}

	if (seq->header) ZFREE(seq->header);
	if (seq->seq) ZFREE(seq->seq);

	seq->offset = ftell(seq->fp);

	/* --- header --- */
	c = getnwc(seq->fp);
	if (c == '>') {
		while (c != '\n' && c != EOF) {
			char_append(&shdr, c);
			c = getc(seq->fp);
		}
	} else {
		un_getc(c, seq->fp);
	}
	if (ferror(seq->fp))
		Fatalfr("seq_read(%s)", seq->fname);
	char_append(&shdr, 0);
	seq->header = shdr.a;
	seq->hlen = shdr.len;

	/* --- seq --- */
	b = '\n';
	c = getnwc(seq->fp);
	while ((c != EOF) && !(b == '\n' && c == '>')) {
		switch (nfasta_ctype[c]) {
		case Nfasta_nt:
			char_append(&sseq, c);
			break;
		case Nfasta_ws:
			/* skip space */
			break;
		case Nfasta_amb:
			if (seq->flags & SEQ_ALLOW_AMB) {
				char_append(&sseq, c);
				break;
			}
			/* FALLTHRU */
		default:
			fatalf("non-DNA character '%c' in sequence '%s'",
			  c, seq->fname);
			break;
		}
		b = c;
		c = getc(seq->fp);
	}
	un_getc(c, seq->fp);
	if (ferror(seq->fp))
		Fatalfr("seq_read(%s)", seq->fname);

	/* check conformance */
	if (SEQ_LEN(seq) == -1) {
		char_append(&sseq, 0);
		charvec_fit(&sseq);
		seq->seq = (uchar*)sseq.a;
		seq->slen = sseq.len;
		if (seq->slen > 0) --seq->slen;  /* don't include '\0' */
	} else {
		charvec_t ssub = charvec_INIT(ckrealloc,ckfree);
		int i;

		if (SEQ_FROM(seq) < 1 ||
		    (int)sseq.len < SEQ_FROM(seq) ||
		    SEQ_TO(seq) < 1 ||
		    (int)sseq.len < SEQ_TO(seq) ||
		    SEQ_TO(seq) < SEQ_FROM(seq))
		    fatalf("range [%d,%d] incommensurate with sequence [%d,%d]",
				SEQ_FROM(seq), SEQ_TO(seq), 1, sseq.len);
		
		for (i = SEQ_FROM(seq); i <= SEQ_TO(seq); ++i)
			char_append(&ssub, sseq.a[i-1]);
		char_append(&ssub, 0);
		charvec_fini(&sseq);
		seq->seq = (uchar*)ssub.a;
	}

	seq->flags = seq->flags &~ SEQ_IS_REVCOMP;
        if (seq->flags & SEQ_DO_REVCOMP) {
	    (void)seq_revcomp_inplace(seq);
	}
	if (seq->flags & SEQ_HAS_MASK) {
	    (void)seq_mask_inplace(seq);
	}

	seq->count++;
	return 1;
}
Exemple #8
0
	RANK(7),
	RANK(8),
	RANK(9),
	RANK(10),
	RANK(11),
	RANK(12),
	RANK(13),
	RANK(14),
	RANK(15),
	RANK(16),
};

#define SEQ_LEN(n)	LL_ADC_REG_SEQ_SCAN_ENABLE_##n##RANKS
static const u32_t table_seq_len[] = {
	LL_ADC_REG_SEQ_SCAN_DISABLE,
	SEQ_LEN(2),
	SEQ_LEN(3),
	SEQ_LEN(4),
	SEQ_LEN(5),
	SEQ_LEN(6),
	SEQ_LEN(7),
	SEQ_LEN(8),
	SEQ_LEN(9),
	SEQ_LEN(10),
	SEQ_LEN(11),
	SEQ_LEN(12),
	SEQ_LEN(13),
	SEQ_LEN(14),
	SEQ_LEN(15),
	SEQ_LEN(16),
};
Exemple #9
0
int update_rpt_mode(struct wiimote *wiimote, int8_t rpt_mode)
{
	unsigned char buf[RPT_MODE_BUF_LEN];
	uint8_t rpt_type;
	struct write_seq *ir_enable_seq;
	int seq_len;

	/* rpt_mode = bitmask of requested report types */
	/* rpt_type = report id sent to the wiimote */
	if (pthread_mutex_lock(&wiimote->rpt_mutex)) {
		cwiid_err(wiimote, "Mutex lock error (rpt mutex)");
		return -1;
	}

	/* -1 updates the reporting mode using old rpt_mode
	 * (reporting type may change if extensions are
	 * plugged in/unplugged */
	if (rpt_mode == -1) {
		rpt_mode = wiimote->state.rpt_mode;
	}

	/* Pick a report mode based on report flags */
	if ((rpt_mode & CWIID_RPT_EXT) &&
	  ((wiimote->state.ext_type == CWIID_EXT_NUNCHUK) ||
	   (wiimote->state.ext_type == CWIID_EXT_CLASSIC))) {
		if ((rpt_mode & CWIID_RPT_IR) && (rpt_mode & CWIID_RPT_ACC)) {
			rpt_type = RPT_BTN_ACC_IR10_EXT6;
			ir_enable_seq = ir_enable10_seq;
			seq_len = SEQ_LEN(ir_enable10_seq);
		}
		else if (rpt_mode & CWIID_RPT_IR) {
			rpt_type = RPT_BTN_IR10_EXT9;
			ir_enable_seq = ir_enable10_seq;
			seq_len = SEQ_LEN(ir_enable10_seq);
		}
		else if (rpt_mode & CWIID_RPT_ACC) {
			rpt_type = RPT_BTN_ACC_EXT16;
		}
		else if (rpt_mode & CWIID_RPT_BTN) {
			rpt_type = RPT_BTN_EXT8;
		}
		else {
			rpt_type = RPT_EXT21;
		}	
	}
	else if ((rpt_mode & CWIID_RPT_EXT) &&
	  wiimote->state.ext_type == CWIID_EXT_BALANCE) {
		rpt_type = RPT_BTN_EXT8;
	}
	else {
		if (rpt_mode & CWIID_RPT_IR) {
			rpt_type = RPT_BTN_ACC_IR12;
			ir_enable_seq = ir_enable12_seq;
			seq_len = SEQ_LEN(ir_enable12_seq);
		}
		else if (rpt_mode & CWIID_RPT_ACC) {
			rpt_type = RPT_BTN_ACC;
		}
		else {
			rpt_type = RPT_BTN;
		}
	}

	/* Enable IR */
	/* TODO: only do this when necessary (record old IR mode) */
	if ((rpt_mode & CWIID_RPT_IR)) {
		if (exec_write_seq(wiimote, seq_len, ir_enable_seq)) {
			cwiid_err(wiimote, "IR enable error");
			return -1;
		}
	}
	/* Disable IR */
	else if ((wiimote->state.rpt_mode & CWIID_RPT_IR) &&
	         !(rpt_mode & CWIID_RPT_IR)) {
		if (exec_write_seq(wiimote, SEQ_LEN(ir_disable_seq), ir_disable_seq)) {
			cwiid_err(wiimote, "IR disable error");
			return -1;
		}
	}

	/* Send SET_REPORT */
	buf[0] = (wiimote->flags & CWIID_FLAG_CONTINUOUS) ? 0x04 : 0;
	buf[1] = rpt_type;
	if (send_report(wiimote, 0, RPT_RPT_MODE, RPT_MODE_BUF_LEN, buf)) {
		cwiid_err(wiimote, "Send report error (report mode)");
		return -1;
	}

	/* clear state for unreported data */
	if (CWIID_RPT_BTN & ~rpt_mode & wiimote->state.rpt_mode) {
		wiimote->state.buttons = 0;
	}
	if (CWIID_RPT_ACC & ~rpt_mode & wiimote->state.rpt_mode) {
		memset(wiimote->state.acc, 0, sizeof wiimote->state.acc);
	}
	if (CWIID_RPT_IR & ~rpt_mode & wiimote->state.rpt_mode) {
		memset(wiimote->state.ir_src, 0, sizeof wiimote->state.ir_src);
	}
	if ((wiimote->state.ext_type == CWIID_EXT_NUNCHUK) &&
	  (CWIID_RPT_NUNCHUK & ~rpt_mode & wiimote->state.rpt_mode)) {
		memset(&wiimote->state.ext, 0, sizeof wiimote->state.ext);
	}
	else if ((wiimote->state.ext_type == CWIID_EXT_CLASSIC) &&
	  (CWIID_RPT_CLASSIC & ~rpt_mode & wiimote->state.rpt_mode)) {
		memset(&wiimote->state.ext, 0, sizeof wiimote->state.ext);
	}
	else if ((wiimote->state.ext_type == CWIID_EXT_BALANCE) &&
	  (CWIID_RPT_BALANCE & ~rpt_mode & wiimote->state.rpt_mode)) {
		memset(&wiimote->state.ext, 0, sizeof wiimote->state.ext);
	}

	wiimote->state.rpt_mode = rpt_mode;

	if (pthread_mutex_unlock(&wiimote->rpt_mutex)) {
		cwiid_err(wiimote, "Mutex unlock error (rpt mutex) - "
		          "deadlock warning");
		return -1;
	}

	return 0;
}
Exemple #10
0
int main(int argc, char **argv) {
	SEQ *sf;
	uchar *s;
	FILE *f;
	char chr_name[100], info[1000], dir;
	int i = 0, j = 0, k = 0, B = 0, E = 0;
	int max_len = 0;
	char *cur_seq;
	int seq_len = 0;
	bool is_correct_splicing = false;
	int num_genes = 0;
	int num_exons = 0;
	int num = 0;
	struct g_list *genes;
	struct exons_list *exons;
	bool no_branchpoint = false;

	if( argc == 5 ) {
		
	}	
	else if( argc == 4 ) {
		if( strcmp( argv[3], "NO_BRANCHPOINT") == 0 ) {
			no_branchpoint = true;
		}
		else {
			fatalf("args: fasta gff (NO_BRANCHPOINT)");
		}
	}
	else if (argc != 3)
		fatalf("args: fasta gff (NO_BRANCHPOINT)");

	if((f = ckopen(argv[2], "r")) == NULL )
	{
		fatalf("Cannot open file %s\n", argv[1]);
	}
	else {
		num_genes = count_genes_in_gff(f, &num_exons);
		if( num_genes > 0 ) {
			genes = (struct g_list *) ckalloc(num_genes * sizeof(struct g_list));	
			if( num_exons < num_genes ) num_exons = num_genes;
			exons = (struct exons_list *) ckalloc(num_exons * sizeof(struct exons_list));	
			initialize_genes(genes, num_genes);
			initialize_exons(exons, num_exons);
		}
	}
	fseek(f, 0, SEEK_SET);
	
	branchpoints = (char **) ckalloc(sizeof(char *) * NUM_BP_SEQ);
	for( i = 0; i < NUM_BP_SEQ; i++ ) {
		branchpoints[i] = (char *) ckalloc(sizeof(char) * 8);	
	}
	
	strcpy(branchpoints[0], "AACTAAC");
	strcpy(branchpoints[1], "AATTAAC");
	strcpy(branchpoints[2], "CACTAAC");
	strcpy(branchpoints[3], "GACTAAC");
	strcpy(branchpoints[4], "TACTAAC");
	strcpy(branchpoints[5], "TACTAAT");
	strcpy(branchpoints[6], "TATTAAC");
	strcpy(branchpoints[7], "TGCTAAC");
	strcpy(branchpoints[8], "GATTAAC");

	num = input_genes_in_gff(f, genes, exons);	
	if( num != num_genes ) {
		fatalf("gene counter error in %s\n", argv[1]);
	}

	if( num_genes > 0 ) {
		quick_sort_inc_genes(genes, 0, num_genes-1, POS_BASE);
	}

	i = 0;
	while( i < num_genes ) {
		j = 0;
    while( ((i+j) < num_genes) && (genes[i].txStart == genes[i+j].txStart )) j++;
    quick_sort_dec_genes(genes, i, i+j-1, LEN_BASE);
    i = i+j;
	}
	fclose(f);

	compl['a'] = compl['A'] = 'T';
	compl['c'] = compl['C'] = 'G';
	compl['g'] = compl['G'] = 'C';
	compl['t'] = compl['T'] = 'A';
	sf = seq_get(argv[1]);
	s = SEQ_CHARS(sf) - 1;
	seq_len = SEQ_LEN(sf);

	for( i = 0; i < num_genes; i++ ) {
		B = genes[i].txStart;
		E = genes[i].txEnd;
		if( E > seq_len ) {
			fatalf("gene boundary [%d,%d] over the sequence length %d\n", B, E, seq_len);
		}

		if( (E - B + 1) > max_len ) {
			max_len = E - B + 1;
		}
	}

	cur_seq = (char *) ckalloc(sizeof(char) * (max_len+1));
	for( i = 0; i < num_genes; i++ ) {
		if( genes[i].exonCount >= 2 ) {
			strcpy(chr_name, genes[i].sname);
			B = genes[i].txStart;
			E = genes[i].txEnd;
			dir = genes[i].strand;
			strcpy(info, genes[i].gname);	

			k = 0;
			if( dir == '+' ) {
				for (j = B; j <= E; j++) {
					cur_seq[k] = s[j];
					k++;
				}
				cur_seq[k] = '\0';
			}
			else {
				k = 0;
				for (j = E; j >= B; j--) {
					cur_seq[k] = compl[s[j]];
					k++;
				}
				cur_seq[k] = '\0';
			}

			is_correct_splicing = true;
			is_correct_splicing = check_introns(genes, i, exons, cur_seq, k);
			if( is_correct_splicing == false ) {
				if( no_branchpoint == false ) {
					genes[i].type = REDUN;
				}
			}
			else {
				if( no_branchpoint == true ) {
					genes[i].type = REDUN;
				}
			}
		}
	}

  num_genes = rm_redun_genes(genes, 0, num_genes-1);
  write_in_gff(genes, num_genes, exons, num_exons);
	
	free(cur_seq);
	for( i = 0; i < NUM_BP_SEQ; i++ ) free(branchpoints[i]);
	free(branchpoints);
	seq_close(sf);
	return EXIT_SUCCESS;
}