uint64_t get_uptime_msec() { return get_time_msec() - startup_timestamp; }
void startup_note() { startup_timestamp = get_time_msec(); }
int32_t parse_mile_message(struct mile_packet *packet, void **bl_reader, int16_t exceed_cpu_used, MEM_POOL_PTR session_mem) { int32_t result_code = MILE_RETURN_SUCCESS; //读buffer和写buffer struct data_buffer* rbuf = packet->rbuf; struct data_buffer* sbuf = packet->sbuf; //读取消息头 struct mile_message_header msg_head; //当前时间与超时时间 uint64_t now_time; uint64_t deadline_time; if (rbuf == NULL) { log_error("严重错误, 读buffer为空!"); return ERROR_PACKET_FORMAT; } msg_head.version_major = read_int8(rbuf); msg_head.version_minor = read_int8(rbuf); msg_head.message_type = read_int16(rbuf); msg_head.message_id = read_int32(rbuf); packet->timeout = read_int32(rbuf); log_debug( "数据包包头信息 -- 主版本号: %d, 小版本号: %d, 消息类型: 0x%x, 消息id: %d, 超时: %d", msg_head.version_major, msg_head.version_minor, msg_head.message_type, msg_head.message_id, packet->timeout); now_time = get_time_msec(); if (packet->timeout != 0 && now_time - packet->launch_time / 1000 > packet->timeout) { log_warn( "执行sql超时, 收到sql命令时的时间 %llu, 当前时间 %llu, 超时时间 %u", packet->launch_time / 1000, now_time, packet->timeout); return ERROR_TIMEOUT; } else { deadline_time = now_time + packet->timeout; } uint16_t msg_head_type = (msg_head.message_type & 0xFF00); if (msg_head_type == MT_VG_MD) { result_code = process_mergeserver_message(&msg_head, rbuf, sbuf, exceed_cpu_used, deadline_time); } else if (msg_head_type == MT_VG_SC) { result_code = StorageEngine::storage->Command(&msg_head, rbuf, sbuf); if (MILE_RETURN_SUCCESS != result_code) gen_docserver_client_error_packet(result_code, &msg_head, sbuf); } else if (msg_head_type == MT_VG_CD) { result_code = process_client_message(&msg_head, rbuf, sbuf); } else if (msg_head_type == MT_VG_SM) { result_code = process_master_message(&msg_head, rbuf, sbuf, bl_reader, session_mem); } else if (msg_head_type == MT_VG_TEST_REQ) { result_code = process_test_message(&msg_head, rbuf, sbuf); } else { result_code = -1; } if (result_code != MILE_RETURN_SUCCESS) { log_error( "执行过程中出错, 错误码 %d, 错误原因 %s", result_code, error_msg(result_code)); } return result_code; }
//periodic adc process. this gets called from the main loop. void adc_process(void) { if(ADC10IFG & ADC10IFG0) //result ready { uint8_t present_state; uint16_t v_threshold; uint32_t adc_present_time; static uint8_t adc_input0_last_state = 0; static uint8_t adc_input1_last_state = 0; static uint8_t adc_input2_last_state = 0; static uint8_t adc_input3_last_state = 0; //this will matchup with the below switch case switch(adc_vref[adc_conversions]) { case INPUT_5V: v_threshold = ADC_TH_5V; break; case INPUT_12V: v_threshold = ADC_TH_12V; break; case INPUT_24V: v_threshold = ADC_TH_24V; break; default: break; } switch (adc_conversions) { case 0: adc_input0_prescale = ADC10MEM0; //get raw adc value adc_input0_scaled = adc_get_scaled(adc_input0_prescale); //convert raw value to scaled voltage ADC10CTL0 &= ~ADC10ENC; //toggle ADC10ENC ADC10MCTL0 = ADC10INCH_1; // ADC10CTL0 |= ADC10ENC + ADC10SC; //enable conversion and start sample-and-conversion if(adc_input0_scaled >= v_threshold) present_state = true; else present_state = false; if(present_state ^ adc_input0_last_state) //if states have changed adc_past_time[0] = get_time_msec(); adc_present_time = get_time_msec(); if((adc_present_time - adc_past_time[0]) >= ADC_STABLE_TIME) adc_state[0] = present_state; adc_input0_last_state = present_state; break; case 1: adc_input1_prescale = ADC10MEM0; adc_input1_scaled = adc_get_scaled(adc_input1_prescale); ADC10CTL0 &= ~ADC10ENC; ADC10MCTL0 = ADC10INCH_2; ADC10CTL0 |= ADC10ENC + ADC10SC; if(adc_input1_scaled >= v_threshold) present_state = true; else present_state = false; if(present_state ^ adc_input1_last_state) adc_past_time[1] = get_time_msec(); adc_present_time = get_time_msec(); if((adc_present_time - adc_past_time[1]) >= ADC_STABLE_TIME) adc_state[1] = present_state; adc_input1_last_state = present_state; break; case 2: adc_input2_prescale = ADC10MEM0; adc_input2_scaled = adc_get_scaled(adc_input2_prescale); ADC10CTL0 &= ~ADC10ENC; ADC10MCTL0 = ADC10INCH_12; ADC10CTL0 |= ADC10ENC + ADC10SC; if(adc_input2_scaled >= v_threshold) present_state = true; else present_state = false; if(present_state ^ adc_input2_last_state) adc_past_time[2] = get_time_msec(); adc_present_time = get_time_msec(); if((adc_present_time - adc_past_time[2]) >= ADC_STABLE_TIME) adc_state[2] = present_state; adc_input2_last_state = present_state; break; case 3: adc_input3_prescale = ADC10MEM0; adc_input3_scaled = adc_get_scaled(adc_input3_prescale); ADC10CTL0 &= ~ADC10ENC; ADC10MCTL0 = ADC10INCH_0; ADC10CTL0 |= ADC10ENC + ADC10SC; if(adc_input3_scaled >= v_threshold) present_state = true; else present_state = false; if(present_state ^ adc_input3_last_state) adc_past_time[3] = get_time_msec(); adc_present_time = get_time_msec(); if((adc_present_time - adc_past_time[3]) >= ADC_STABLE_TIME) adc_state[3] = present_state; adc_input3_last_state = present_state; break; default: break; } //all four inputs have been sampled once, start back at first input if(adc_conversions == 0) { adc_conversions = 4; } --adc_conversions; } }
int init() { struct image *imgfile = 0; glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); /*glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);*/ glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); glStencilFunc(GL_ALWAYS, 0, 0xffffffff); if(tex_fname) { if(!(imgfile = load_image(tex_fname))) { fprintf(stderr, "failed to load image file: %s\n", tex_fname); } } glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(imgfile) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgfile->width, imgfile->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgfile->pixels); free_image(imgfile); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img_refmap.width, img_refmap.height, 0, GL_RGB, GL_UNSIGNED_BYTE, img_refmap.pixels); } glEnable(GL_TEXTURE_2D); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glMatrixMode(GL_TEXTURE); glScalef(1, -1, 1); glMatrixMode(GL_MODELVIEW); if(!(msurf = msurf_create())) { return -1; } msurf_set_threshold(msurf, 8); msurf_set_inside(msurf, MSURF_GREATER); msurf_set_bounds(msurf, -3.5, 3.5, -3.5, 3.5, -3.5, 3.5); msurf_eval_func(msurf, eval); msurf_vertex_func(msurf, vertex); #ifdef RANDOM_BLOB_PARAMS { int i, j; srand(time(0)); for(i=0; i<NUM_MBALLS; i++) { mballs[i].energy = frand() * 2.0 + 0.5; for(j=0; j<2; j++) { mballs[i].path_scale[j] = frand() * 1.5 + 0.5; mballs[i].path_offset[j] = (frand() * 2.0 - 1.0) * 1.1; } mballs[i].path_scale[2] = 1; mballs[i].path_offset[2] = 0; mballs[i].phase_offset = frand() * M_PI * 2.0; mballs[i].speed = frand() + 0.5; } } #endif start_time = get_time_msec(); return 0; }