int PrintPhoNode(PhoNode *node) { PRINTF(("PrintPhoNode begin\n")); if (BIT_TEST(node->sflags, ISSET_REGID)) { PRINTF(("Registration ID %s\n", node->regid)); } if (BIT_TEST(node->sflags, ISSET_UPORT)) { PRINTF (("Uport %lu\n", node->uport)); } if (BIT_TEST(node->sflags, ISSET_IPADDRESS)) { PRINTF (("IPADDRESS %s\n", (char*) ULIPtostring((node->ipaddress.l)))); } if (BIT_TEST(node->sflags, ISSET_PHONE)) { PRINTF( ("Phone %s\n", node->phone)); } if (BIT_TEST(node->sflags, ISSET_VPNPHONE)) { PRINTF( ("Vpn Phone %s %lu\n", node->vpnPhone, node->vpnExtLen)); } PRINTF( ("PrintPhoNode end\n")); return(0); }
static void minimap_draw(minimap_t *minimap, frame_t *frame) { if (BIT_TEST(minimap->flags, 1)) { sdl_fill_rect(0, 0, 128, 128, 1, frame); draw_minimap_ownership(minimap, 2, frame); } else { draw_minimap_map(minimap, frame); if (BIT_TEST(minimap->flags, 0)) { draw_minimap_ownership(minimap, 1, frame); } } if (BIT_TEST(minimap->flags, 2)) { draw_minimap_roads(minimap, frame); } if (BIT_TEST(minimap->flags, 3)) { draw_minimap_buildings(minimap, frame); } if (BIT_TEST(minimap->flags, 4)) { draw_minimap_grid(minimap, frame); } if (minimap->advanced > 0) { draw_minimap_traffic(minimap, frame); } draw_minimap_rect(minimap, frame); }
static void cmdClosing(void *base) { node_t *node = (node_t *) base; assert(node); assert(node->sysdata); logger(node->sysdata->logging, 3, "node:%d CLOSING (flags:%x, mask:%x)", node->handle, node->data.flags, node->data.mask); // if the node is a regular consumer then we cancel all the queues that do // not have pending requests for this node. queue_cancel_node(node); // if we have messages still in the list, we need to go through them, to see // if there are any for this node that we need to set timeouts on. if (node->sysdata->msg_used > 0) { assert(0); } // mark the node as closing so that as soon as all the messages have // completed, the node can be shutdown. assert(BIT_TEST(node->flags, FLAG_NODE_CLOSING) == 0); BIT_SET(node->flags, FLAG_NODE_CLOSING); // if this node is a controller, then we may need to do something to handle // it. Although it is likely that nothign would be done until the // connection is actually lost. if (BIT_TEST(node->flags, FLAG_NODE_CONTROLLER)) { // what do we need to do special to handle the closing of a controller node? // nothing really... that would be done when the connection is actually closed. } }
unsigned int BitVector::getBit(int i) { int wordIndex = i / WORD_SIZE; int bitIndex = i % WORD_SIZE; if ( wordIndex < f_words - 1 ) return BIT_TEST(f_array[wordIndex], (0x1 << bitIndex)) ? 1 : 0; else return BIT_TEST(f_array[wordIndex], (0x1 << (WORD_SIZE - f_bits % WORD_SIZE + bitIndex)) ) ? 1 : 0; }
int PhoNodeCmp(PhoNode *n1, PhoNode *n2) { if (BIT_TEST(n1->sflags, ISSET_REGID) && BIT_TEST(n2->sflags, ISSET_REGID)) { if (memcmp(n1->regid, n2->regid, REG_ID_LEN) != 0) { return 1; } } if (BIT_TEST(n1->sflags, ISSET_UPORT) && BIT_TEST(n2->sflags, ISSET_UPORT)) { if (n1->uport != n2->uport) { return 1; } } if (BIT_TEST(n1->sflags, ISSET_IPADDRESS) && BIT_TEST(n2->sflags, ISSET_IPADDRESS)) { if ((n1->ipaddress.l != n2->ipaddress.l) || (n1->realmId != n2->realmId) ) { return 1; } } if (BIT_TEST(n1->sflags, ISSET_PHONE) && BIT_TEST(n2->sflags, ISSET_PHONE)) { if (strcmp(n1->phone, n2->phone) != 0) { return 1; } } if (BIT_TEST(n1->sflags, ISSET_VPNPHONE) && BIT_TEST(n2->sflags, ISSET_VPNPHONE)) { if (strcmp(n1->vpnPhone, n2->vpnPhone) != 0) { return 1; } } return 0; }
void __recalc_multiline(t_CEditor *pme, gu16 width) { if(BIT_TEST(pme->flags, IDF_TEXT_AUTO_WRAP)){ ucs2_t *ptr = pme->buffer; t_CTextLine line; int start; int len; len = pme->nchars; start = 0; g_array_reset(pme->lines, NULL); pme->cursor_r = 0; pme->cursor_c = pme->cursor; while(len > 0 && *ptr){ line.num = font_measure_ustring(ptr, len, width, NULL, NULL); if(line.num == 0) break; line.start = start; start += line.num; if(pme->cursor >= line.start && pme->cursor <= start){ pme->cursor_r = g_array_size(pme->lines); pme->cursor_c = pme->cursor-line.start; } g_array_append(pme->lines, &line); len -= line.num; ptr += line.num; } }else{ //2 单行显示,需要使光标可见 } }
int ios::bad() { if ( BIT_TEST(f_state, BAD) ) return 1; else return 0; }
void *muestrear(void *arg) { char select[16]; int i; //printf("Soy el HILO\n"); while(1) { //printf("Thread: Valor anterior %s\n", select); recibir(fd,select,15); select[1]='\0'; //printf("Thread: Valor leido %u\n", (unsigned char)select[0]); sensoresPIC=(unsigned int) select[0]; for(i=0;i<8;i++) { if( BIT_TEST(sensoresPIC,i) ) printf("X"); else printf("_"); } if( borde == DCHO ) printf("\tDCHO\t%lf",error); else printf("\tIZQDO\t%lf",error); printf("\n"); //printf("KK %u\n", sensoresPIC); } return NULL; }
void scheduler_callback() { unsigned int max = last_alarm_frequency(); unsigned int i; ScheduledTask *curr, *last; for (i=0; i<= max; ++i) { curr = state.tasks[i]; while (curr) { if (BIT_TEST(curr->flags, kScheduleForeverBit) == 0) { --curr->remaining_calls; } taskloop_add(curr->callback); last = curr; curr = curr->next; if (last->remaining_calls == 0) scheduler_list_remove(&state.tasks[i], last); } } }
//----------------------------------------------------------------------------- // Payload data is handled slightly differently. Because we need the actual // data to be handled by different parts of the system, and we dont want to do // memory copies all the time. So the payload buffer itself will be moved. // Therefore, each time we handle a payload, we will get a new buffer from the // bufpool. When all the commands are being executed, the payload buffer will // be transferred to the message object that is created for it. When // everything has completed processing, then the buffer will be returned to the // buffpool to be re-used. static void cmdPayload(void *base, const risp_length_t length, const risp_data_t *data) { node_t *node = (node_t *) base; assert(node != NULL); assert(length > 0); assert(data != NULL); assert(node->sysdata); assert(node->sysdata->bufpool); assert(node->data.payload == NULL); assert(BIT_TEST(node->data.mask, DATA_MASK_PAYLOAD) == 0); node->data.payload = expbuf_pool_new(node->sysdata->bufpool, length); assert(node->data.payload); expbuf_set(node->data.payload, data, length); BIT_SET(node->data.mask, DATA_MASK_PAYLOAD); assert(node->sysdata != NULL); logger(node->sysdata->logging, 3, "node:%d PAYLOAD (len:%d, flags:%x, mask:%x)", node->handle, length, node->data.flags, node->data.mask); }
static void cmdConsuming(void *base) { node_t *node = (node_t *) base; assert(node); assert(node->sysdata); logger(node->sysdata->logging, 3, "node:%d CONSUMING (flags:%x, mask:%x)", node->handle, node->data.flags, node->data.mask); assert(BIT_TEST(node->data.mask, DATA_MASK_QUEUEID)); assert(BIT_TEST(node->data.mask, DATA_MASK_QUEUE)); assert(node->sysdata); assert(node->sysdata->queues); queue_set_id(node->sysdata->queues, expbuf_string(&node->data.queue), node->data.qid); }
int ios::fail() { if ( bad() ) return 1; if ( BIT_TEST(f_state, FAIL) ) return 1; else return 0; }
int hasData() { if(BIT_TEST(RF_24G_DR1_PORT, RF_24G_DR1_BIT)){ return 1; }else{ return 0; } }
int schedule_wait_for_event (schedule_t *schedule) { event_t *event; pthread_mutex_lock (&schedule->mutex_cond_lock); while (schedule->new_event_flag == 0) { #ifdef MRT_DEBUG trace (TR_THREAD, schedule->trace, "pthread_cond_wait for a new event\n"); #endif /* MRT_DEBUG */ pthread_cond_wait (&schedule->cond_new_event, &schedule->mutex_cond_lock); } #ifdef MRT_DEBUG trace (TR_THREAD, schedule->trace, "Processing event queue\n"); #endif /* MRT_DEBUG */ event = LL_GetHead (schedule->ll_events); if (event != NULL) { LL_RemoveFn (schedule->ll_events, event, NULL); schedule->new_event_flag --; schedule->lastrun = time (NULL); } else { trace (TR_ERROR, schedule->trace, "THREAD NULL event for %s -- strange...", schedule->description); } /* unlock -- we removed the event from the schedule quere */ pthread_mutex_unlock (&schedule->mutex_cond_lock); if (event == NULL) {return (-1);} #ifdef MRT_DEBUG if (event->description) trace (TR_THREAD, schedule->trace, "THREAD Event %s now run (%d events left) for %s\n", event->description, LL_GetCount (schedule->ll_events), schedule->description); else trace (TR_THREAD, schedule->trace, "THREAD Event %x now run (%d events left) for %s\n", event->call_fn, LL_GetCount (schedule->ll_events), schedule->description); #endif /* MRT_DEBUG */ schedule->is_running++; schedule_event_dispatch (event); schedule->is_running--; if (BIT_TEST (schedule->flags, MRT_SCHEDULE_DELETED)) destroy_schedule (schedule); return (1); }
static void cmdBroadcast(void *base) { node_t *node = (node_t *) base; queue_t *q = NULL; message_t *msg; assert(node); assert(node->handle >= 0); assert(node->sysdata); logger(node->sysdata->logging, 3, "node:%d BROADCAST (flags:%x, mask:%x)", node->handle, node->data.flags, node->data.mask); // do we have a queue name, or a qid? if (BIT_TEST(node->data.mask, DATA_MASK_QUEUE) || BIT_TEST(node->data.mask, DATA_MASK_QUEUEID)) { if (BIT_TEST(node->data.mask, DATA_MASK_QUEUE)) { q = queue_get_name(node->sysdata->queues, expbuf_string(&node->data.queue)); } else if (BIT_TEST(node->data.mask, DATA_MASK_QUEUEID)) { q = queue_get_id(node->sysdata->queues, node->data.qid); } if (q == NULL) { q = queue_create(node->sysdata, expbuf_string(&node->data.queue)); } // by this point, we should have 'q'. assert(q); // create message object. msg = next_message(node); assert(msg); // now that we have a message structure completely filled out with the // data from the node, then we need to do something with it. assert(0); } else { // we didn't have a queue name, or a queue id. We need to handle this gracefully. assert(0); } }
void list_print(struct list_t *list, FILE *file) { long j, sum = 1; int k; io_buffer[io_pos++] = '2'; io_buffer[io_pos++] = '\n'; for (j = 0; j < list->len; ++j) { for (k = 0; k < LISTENT_BIT; ++k) { if (BIT_TEST(list->data[j], k)) { long number = sum + k * 2; char buffer[32]; int pos = 0; do { buffer[pos++] = '0' + (number % 10); number /= 10; } while (number != 0); if (io_pos + pos + 1 > IO_BUFSIZE) { if (write(1, io_buffer, io_pos) == -1) { perror("write"); exit(EXIT_FAILURE); } io_pos = 0; } for (pos = pos - 1; pos + 1 > 0; --pos) { io_buffer[io_pos++] = buffer[pos]; } io_buffer[io_pos++] = '\n'; } } sum += LISTENT_BIT * 2; } if (io_pos) { if (write(1, io_buffer, io_pos) == -1) { perror("write"); exit(EXIT_FAILURE); } io_pos = 0; } }
int detect2(int data, int ini, int end, int *dist) { int i; int est=0; int cont=1; //printf("asd"); for( i=ini; i<=end; i++ ) { switch(est) { case 0: if ( BIT_TEST(data,i) ) est=1; break; case 1: if( !(BIT_TEST(data,i)) ) est=2; break; case 2: if( BIT_TEST(data,i) ) est=3; else cont++; break; case 3: break; } } if( est == 3 ) { //printf("distancia = %d\n",cont); *dist=cont; //ojo con los puteros en el pic return 1; } return 0; }
void taskloop_loop() { while(1) { while(taskloop_process_one()) ; if (BIT_TEST(taskqueue.flags, kTaskLoopSleepBit)) asm_sleep(); } }
/* * Given the length of a key in bytes (not to exceed 256), return the * length in patricia bit format. */ static inline u_int16_t pat_plen_to_bit (u_int16_t plen) { u_int16_t result; result = (plen & PAT_PLEN_BYTE_MASK) << 5; if (BIT_TEST(plen, PAT_PLEN_BIT_MASK)) { result |= patricia_bit_masks[plen & PAT_PLEN_BIT_MASK]; } else { result--; /* subtract 0x100, or in 0xff */ } return (result); }
void *isPrime(void *arg) { pthread_mutex_lock(&mutex_bitmap); unsigned long val; while (factor * factor <= max) { factor += 2; if (!BIT_TEST(bitmap, factor)) for (val = 3 * factor; val < max; val += factor << 1) BIT_SET(bitmap, val); } pthread_mutex_unlock(&mutex_bitmap); pthread_exit(NULL); }
static inline uint32_t led_mask_to_gpio(uint8_t led_mask) { uint32_t result = 0; for(uint32_t i=0; i<BOARD_LED_NUM; i++) { if ( BIT_TEST(led_mask,i) ) { result = BIT_SET(result, led_gpio[i]); } } return result; }
int detect(int data, int ini, int end) { int i; int est=0; int cont=1; for( i=ini; i<=end; i++ ) { switch(est) { case 0: if ( BIT_TEST(data,i) ) est=1; break; case 1: if( !(BIT_TEST(data,i)) ) est=2; break; case 2: if( BIT_TEST(data,i) ) est=3; else cont++; break; case 3: break; } } if( est == 3 ) { return 1; } return 0; }
void rd_opt_usage (const rd_opt_t *ros, FILE *fp, const char *argv0, const char *extra_args) { const rd_opt_t *ro; int confnamecnt = 0; int mutcnt[RD_OPT_MUT_NUM+1] = {}; int mg; if (!ros || BIT_TEST(ros->ro_type, RD_OPT_END)) { /* No options */ fprintf(fp, "Usage: %s%s%s\n\n", argv0, extra_args ? " " : "", extra_args ? : ""); return; }
void Decrypt() { unsigned char i, j, key; // 8 bit unsigned signed char p; // 8 bit signed p = 1; for (j=66; j>0; j--) { key = DKEY[p--]; if ( p < 0) p += 8; for (i=8; i>0; i--) { // NLF if ( BIT_TEST( Buffer[3],6)) { if ( !BIT_TEST( Buffer[3],1)) aux = 0b00111010; // 10 else aux = 0b01011100; // 11 } else { if ( !BIT_TEST( Buffer[3],1)) aux = 0b01110100; // 00 else aux = 0b00101110; // 01 } // move bit in position 7 if ( BIT_TEST( Buffer[2],3)) asm("swapf _aux,f"); if ( BIT_TEST( Buffer[1],0)) aux<<=2; if (BIT_TEST( Buffer[0],0)) aux<<=1; // xor with Buffer and Dkey aux ^= Buffer[1] ^ Buffer[3] ^ key; // shift in buffer #asm rlf _aux,w rlf _Buffer,f rlf _Buffer+1,f rlf _Buffer+2,f rlf _Buffer+3,F #endasm // rotate Dkey key<<=1; } // for i } // for j } // decrypt
BitVector& BitVector::shiftLeftOneBit() { unsigned int msb = 0; unsigned int lsb = 0; for ( int i=f_words-1; i>=0; i++ ) { msb = ( BIT_TEST(f_array[i], wordWithMSBSet) ) ? wordWithMSBSet : 0x0; f_array[i] = f_array[i] << 1; f_array[i] |= lsb; lsb = msb; } return *this; }
BitVector& BitVector::shiftRightOneBit() { unsigned int msb = 0; unsigned int lsb = 0; for ( int i=0; i<f_words; i++ ) { lsb = ( BIT_TEST(f_array[i], 0x1) ) ? 0x1 : 0x0; f_array[i] = f_array[i] >> 1; f_array[i] |= msb; msb = lsb; } SET_BIT(f_array[0], wordWithMSBSet); return *this; }
uint8_t getByte() { //MSB first int8_t i, b = 0; for(i=0 ; i < 8 ; i++) { BIT_CLEAR(RF_24G_CLK1_PORT, RF_24G_CLK1_BIT); CLKDELAY(); BIT_SET(RF_24G_CLK1_PORT, RF_24G_CLK1_BIT); CLKDELAY(); // Read before falling edge if( BIT_TEST(RF_24G_DATA_IN_PORT, RF_24G_DATA_BIT) ) { b|=1; } if(i!=7) b<<=1; } return b; }
void putByte( uint8_t b ) { //MSB first int8_t i; for(i=0 ; i < 8 ; i++) { BIT_CLEAR(RF_24G_CLK1_PORT, RF_24G_CLK1_BIT); if( BIT_TEST(b,BIT7) ) { BIT_SET(RF_24G_DATA_OUT_PORT, RF_24G_DATA_BIT); }else{ BIT_CLEAR(RF_24G_DATA_OUT_PORT, RF_24G_DATA_BIT); } b<<=1; CLKDELAY(); BIT_SET(RF_24G_CLK1_PORT, RF_24G_CLK1_BIT); // Clock out on rising edge CLKDELAY(); } }
//----------------------------------------------------------------------------- // When the controller could not connect, it is paused for a certain time, and // then a connect attempt needs to be made again. static void controller_wait_handler(int fd, short int flags, void *arg) { controller_t *ct; assert(fd < 0); assert((flags & EV_TIMEOUT) == EV_TIMEOUT); assert(arg); ct = (controller_t *) arg; assert(ct->connect_event); event_free(ct->connect_event); ct->connect_event = NULL; // only retry the connect if the controller is not marked as FAILED. if (BIT_TEST(ct->flags, FLAG_CONTROLLER_FAILED) == 0) { controller_connect(ct); } }
//----------------------------------------------------------------------------- // When a PONG is received, it is assumed that we sent a ping. It can also be // used as a keep-alive. static void cmdPong(void *base) { node_t *node = (node_t *) base; assert(node != NULL); assert(node->handle >= 0); assert(node->idle >= 0); node->idle = 0; if (BIT_TEST(node->flags, FLAG_NODE_BUSY)) { BIT_CLEAR(node->flags, FLAG_NODE_BUSY); // since the node is no longer marked as busy, then we need to alert the // queues so that they can begin sending messages to this node again. assert(0); } }