void delay_us (WORD delay) { int timeout = read_time () + delay; if ((delay < 0) || (delay >= (1 << 30))) return; while (read_time () < timeout) continue; }
int main(void) { time_t t = time(NULL); int pipes[2]; pipe(pipes); pid_t child1 = fork(); if (child1 == 0) { close(pipes[1]); struct tm* tm; pid_t child2 = fork(); if (child2 == 0) { pid_t child3 = fork(); if (child3 == 0) { /* in child3 */ tm = read_time(pipes[0]); printf("S:%02d\n", tm->tm_sec); } else { /* in child2 */ while (wait(NULL) != child3); tm = read_time(pipes[0]); printf("M:%02d\n", tm->tm_min); } } else { /* in child1 */ while (wait(NULL) != child2); tm = read_time(pipes[0]); printf("H:%02d\n", tm->tm_hour); } close(pipes[0]); } else { /* in parent */ close(pipes[0]); for (int i = 0; i < 3; ++i) { write(pipes[1], &t, sizeof(time_t)); } while (wait(NULL) != child1); close(pipes[1]); } return 0; }
void macan_ev_timer_start(macan_ev_loop *loop, macan_ev_timer *w) { w->expire_us = read_time() + w->after_us; w->next = loop->timers; loop->timers = w; }
int main () { TOrderedList_char cList; char cItem; TOrderedList_time tList; Ttime tItem; int i; initialize_list_char(&cList); initialize_list_time(&tList); printf("\n Enter items in any order\n"); for (i = 0 ; i < 3 ; i++) { read_char(&cItem, "Give character: "); read_time(&tItem, "Give time (hh mm): "); if (!insert_item_char(&cList, cItem)) printf("\nChar list is full"); if (!insert_item_time(&tList, tItem)) printf("\nTime list is full"); } printf("\nChar list ouputted using for loop and retrieve_ith function:\n"); for (i=0; i<number_of_items_char(&cList); i++) { retrieve_ith_char(&cList, i, &cItem); print_char(cItem); } printf("\nTime list ouputted using for loop and retrieve_ith function:\n"); for (i=0; i<number_of_items_time(&tList); i++) { retrieve_ith_time(&tList, i, &tItem); print_time(tItem); } fflush(stdin); getchar(); return 0; }
int main(void) { // Read input file and get number of particles read_input(); read_nparts(); // Read list of files in ./output/part-*.*.cgns read_time(); // strrep part- and .cgns, save remainder to tName array // pare down tName array to ts < tName < te // pare down tName array to multiples of dt, or thereabouts // read first file, find nparts // construct part_struct[nparts].vec[length(tName)] // read part-*.** to part_struct array // loop over all r0 TODO: list r0, tol in input file // loop over all particles and find tetrad apirs // create *T struct with first tetrad pair // double n[0], n[1], n[2], n[3] // *prev = NULL // *next = // create a *T, loop over *prev, check if unique or not // if unique, change *T.next = *currT // *T = *currT // fill out V, R^2, etc. to *T // continue loops return EXIT_SUCCESS; }
/** * @brief Description 系统初始化 * @param None * @retval None */ void SysInit(void) { FirstScanSysData(); // set_time(); read_time(); while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET); displayTIME(Rtc.Hour,Rtc.Minute); showTIME; LCD_UpdateDisplayRequest(); Started_Channel = GetStartChanel(Channel_count); StartedChannelForDisplay = Started_Channel; Sensor1.sensor_infor[0] = 4; Sensor1.sensor_infor[1] = 2; Bat.Voltage_TestTime=11; Sensor1.sensor1_str.sensor_type = 1; Flag.MucReset = 1; Flag.IsDisplayRightNow = 1; JlyParam.WorkStatueIsStop = 1; Queue.FlashSectorPoint = 0; }
int main(void) { Ttime j; Ttime time[M]; Ttime dur; Ttime smal; int i = 0; printf("How many times you have? "); scanf("%d", &j); for(i = 0; i<j; i++) { printf("Give the time %d (hh mm)? ", i+1); read_time(&time[i]); } smal = smallest(time, j); //printf("%d" , smal); //display_time(&smal); printf("Result list:\n"); for(i = 0; i<j; i++) { time_diff(&smal, &time[i], &dur); display_time(&time[i]); printf(" "); display_time(&dur); printf("\n"); } return 0; }
struct cue_file *mp_parse_cue(struct bstr data) { struct cue_file *f = talloc_zero(NULL, struct cue_file); f->tags = talloc_zero(f, struct mp_tags); data = skip_utf8_bom(data); char *filename = NULL; // Global metadata, and copied into new tracks. struct cue_track proto_track = {0}; struct cue_track *cur_track = NULL; while (data.len) { struct bstr param; int cmd = read_cmd(&data, ¶m); switch (cmd) { case CUE_ERROR: talloc_free(f); return NULL; case CUE_TRACK: { MP_TARRAY_GROW(f, f->tracks, f->num_tracks); f->num_tracks += 1; cur_track = &f->tracks[f->num_tracks - 1]; *cur_track = proto_track; cur_track->tags = talloc_zero(f, struct mp_tags); break; } case CUE_TITLE: case CUE_PERFORMER: { static const char *metanames[] = { [CUE_TITLE] = "title", [CUE_PERFORMER] = "performer", }; struct mp_tags *tags = cur_track ? cur_track->tags : f->tags; mp_tags_set_bstr(tags, bstr0(metanames[cmd]), param); break; } case CUE_INDEX: { int type = read_int_2(¶m); double time = read_time(¶m); if (cur_track) { if (type == 1) { cur_track->start = time; cur_track->filename = filename; } else if (type == 0) { cur_track->pregap_start = time; } } break; } case CUE_FILE: // NOTE: FILE comes before TRACK, so don't use cur_track->filename filename = read_quoted(f, ¶m); break; } } return f; }
void sleep_until (WORD timeout) { unsigned int sleep_for = (unsigned int) (timeout - read_time ()); if (sleep_for >= min_sleep) { go_to_sleep (sleep_for > max_sleep ? max_sleep : sleep_for); } }
static off_t search_by_time(int fd, const char *fmt, time_t t, off_t off_m, off_t off_n) { int rval; time_t val_p; off_t off_p; #ifdef LOGCUT_DEBUG char buf0[256], buf1[256]; #endif while (off_m < off_n) { off_p = line_head(fd, (off_m + off_n) / 2); do { rval = read_time(fd, fmt, &val_p); if (off_p > 1 && rval == 0) { off_p = line_head(fd, off_p - 1); continue; } break; } while (1); if (t <= val_p) { LOGCUT_DBG((stderr, "n %10lld => %10lld %s <= %s\n", off_n, off_p, my_ctime(&t, buf0, sizeof(buf0)), my_ctime(&val_p, buf1, sizeof(buf1)))); off_n = off_p; } else { off_p = line_next(fd, (off_m + off_n) / 2); do { rval = read_time(fd, fmt, &val_p); if (rval == 0) { off_p = line_next(fd, off_p); continue; } break; } while (off_p < off_n); LOGCUT_DBG((stderr, "m %10lld => %10lld %s > %s\n", off_n, off_p, my_ctime(&t, buf0, sizeof(buf0)), my_ctime(&val_p, buf1, sizeof(buf1)))); off_m = off_p; } } return (off_m); }
TEST_F(tempdir, save_time) { char buf[PATH_MAX]; time_t now = time(NULL); time_t tm; snprintf(buf, sizeof(buf), "%s/save", self->path); save_disk_timestamp(buf, now); ASSERT_EQ(0, read_time(buf, &tm)); EXPECT_EQ(now, tm); }
/* *@功能:2字节用户编号+4字节RFID+6字节时间+1字节开锁结果,存入记录区 * * 每条长度为13字节 */ void save_rfid_result(void) //操作钥匙 { uint32_t record_addr; uint32_t Lock_number_addr; uint32_t total_row; uint8_t temp_Lock_number[4]; IWDG_Feed(); record_addr= SPI_FLASH_ReadWord(RECORD_POINT); //已存储的组数 SPI_FLASH_Write(User_Num,record_addr,2); //写查找到的授权的用户编号到记录中,如果没有找到则编号为零 SPI_FLASH_Write(Lock_number,record_addr+2,4); //写读到的RFID到记录中 read_time(); //读取实时时间,放到time_buff中 SPI_FLASH_Write(time_buff,record_addr+6,6); //写实时时间到time记录中 SPI_FLASH_Write(&unlock_result,record_addr+12,1); //写开锁结果到记录中 //for debug SPI_FLASH_Read(item,record_addr,13); UART1nSendChar(1,item,13); delay_ms(1000); record_addr=record_addr+RECORD_LEN; //每条授权RECORD_LEN=13字节 //更改授权用户信息指针的位置 SPI_FLASH_WriteWord(RECORD_POINT,record_addr); //for debug point=SPI_FLASH_ReadWord(RECORD_POINT); //RECORD_POINT=RECORD_START UART1SendwordHex(1, point); delay_ms(1000); //要区分宏地址里存放的内容到底是表示地址还是数据 total_row= SPI_FLASH_ReadWord(RECORD_ROW); total_row=total_row+1; //授权信息条数加一 SPI_FLASH_WriteWord(RECORD_ROW,total_row); //for debug row=SPI_FLASH_ReadWord(RECORD_ROW); UART1SendwordHex(1, row); delay_ms(1000); }
bool config::read_time(const key_t& key, int& hour, int& minute, int& second) const { if (int time = read_time(key)) { hour = time / 3600; minute = time % 3600 / 60; second = time % 3600 % 60; return true; } return false; }
static void print_bench(void) { uint16_t nops[10000] = {0}; int i, j, k, nfuncs, nop_time=0; for( i=0; i<10000; i++ ) { int t = read_time(); nops[i] = read_time() - t; } qsort( nops, 10000, sizeof(uint16_t), cmp_nop ); for( i=500; i<9500; i++ ) nop_time += nops[i]; nop_time /= 900; printf( "nop: %d\n", nop_time ); for( i=0; i<MAX_FUNCS && benchs[i].name; i++ ); nfuncs=i; qsort( benchs, nfuncs, sizeof(bench_func_t), cmp_bench ); for( i=0; i<nfuncs; i++ ) for( j=0; j<MAX_CPUS && (!j || benchs[i].vers[j].cpu); j++ ) { bench_t *b = &benchs[i].vers[j]; if( !b->den ) continue; for( k=0; k<j && benchs[i].vers[k].pointer != b->pointer; k++ ); if( k<j ) continue; printf( "%s_%s%s: %"PRId64"\n", benchs[i].name, b->cpu&X264_CPU_PHADD_IS_FAST ? "phadd" : b->cpu&X264_CPU_SSSE3 ? "ssse3" : b->cpu&X264_CPU_SSE3 ? "sse3" : /* print sse2slow only if there's also a sse2fast version of the same func */ b->cpu&X264_CPU_SSE2_IS_SLOW && j<MAX_CPUS && b[1].cpu&X264_CPU_SSE2_IS_FAST && !(b[1].cpu&X264_CPU_SSE3) ? "sse2slow" : b->cpu&X264_CPU_SSE2 ? "sse2" : b->cpu&X264_CPU_MMX ? "mmx" : "c", b->cpu&X264_CPU_CACHELINE_32 ? "_c32" : b->cpu&X264_CPU_CACHELINE_64 ? "_c64" : "", ((int64_t)10*b->cycles/b->den - nop_time)/4 ); } }
/* If force is true then ignore the timestamps */ void mount_update(gboolean force) { #ifdef DO_MOUNT_POINTS time_t time; time = read_time(THE_FSTAB); if (force || time != fstab_time) { fstab_time = time; read_table(); } #endif /* DO_MOUNT_POINTS */ }
int main(void) { Ttime start[6],diff; char buff[80]; int i; for(i=0;i<3;i++) { sprintf(buff, "Enter starting time for the leg %d", i+1); read_time(&start[2*i], buff); sprintf(buff, "Enter end time for the leg %d", i+1); read_time(&start[2*i+1], buff); } for(i=0;i<3;i++) { diff=time_diff(start[2*i], start[2*i+1]); printf("\nThe length of leg%d is\n", i+1); print_time(diff); } system("PAUSE"); }
/*---------------------------------------------------------------------------*/ static void isotime(char *str) { uint8_t timestore_read[7]; uint8_t iso_timestore[16]; read_time(timestore_read); iso_time(timestore_read, iso_timestore); /* iso_timestore[0] = 'a' + timestore_read[0]; iso_timestore[1] = 'a' + timestore_read[1]; iso_timestore[2] = 'a' + timestore_read[2]; iso_timestore[3] = 'a' + timestore_read[3]; iso_timestore[4] = '\0'; */ shell_output(iso_timestore, ""); }
/*Func: read_from_stat() * This fucnction create stat type struct * Read the information from stat() * Check to see if there is error * Calling functions to read info of the file: * timestamp * user_id, group_id * mode, size, numintro */ void read_from_stat(file *info){ int t=0; struct stat fileinfo; t = fstat(info->desc,&fileinfo); //perror("File Stat"); if(t==-1){ printf(CY"Error: File stat cannot be read. \nProgram is now exiting!\n"NC); exit(EXIT_FAILURE); } read_time(info, fileinfo); read_ids(info, fileinfo); read_mode(info, fileinfo); read_size(info, fileinfo); }
void read_station(struct station *s) { if (s == NULL) { printf("\n\n!!!В функцию был передан нулевой указатель!!!\n\n"); return; } printf("Введите название станции (не более 20 символов): "); char str[300] = ""; gets(str); s->station_name[0] = '\0'; strncat(s->station_name, str, 20); printf("\t"); read_time(&s->arrival_time); printf("\n"); }
bool macan_ev_run(macan_ev_loop *loop) { while (1) { uint64_t now = read_time(); poll_can_fifo(macan_ev_recv_cb, loop); for (macan_ev_timer *t = loop->timers; t; t = t->next) { //if (t->expire_us >= now) { if (now >= t->expire_us) { t->cb(loop, t, MACAN_EV_TIMER); t->expire_us = now + t->repeat_us; // TODO: one shot timers } } } return true; }
void mount_init(void) { fstab_mounts = g_hash_table_new(g_str_hash, g_str_equal); user_mounts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); #ifdef DO_MOUNT_POINTS if(file_exists(THE_FSTAB)) { fstab_time = read_time(THE_FSTAB); } else { fstab_time = 0; #if defined(HAVE_MNTENT_H) || defined(HAVE_SYS_MNTENT_H) /* We need THE_FSTAB for these implementations, but * it is missing */ g_warning(_("File system table \"%s\" not found, cannot monitor system mounts"), THE_FSTAB); #endif } read_table(); #endif }
void macan_ev_timer_again(macan_ev_loop *loop, macan_ev_timer *w) { w->expire_us = read_time() + w->repeat_us; }
int read_item(Titem *item) { fseek(stdin, 0, SEEK_END); // flush (emtpy) the input keyboard buffer read_time(item); return 1; }
void read_leg(Tleg *leg,char *prompt) { printf("%s\n",prompt); read_time(&leg->t1,"Start"); read_time(&leg->t2,"End"); }
void readTime(Trunner *runner, const char *prompt) { read_time(&runner->record, (char*)prompt); }
int read_config(const char *path, int type) { char line[1024]; FILE *fp; char *s, *key, *val, *end_of_key; const char *error; char *cp, *cp2; int i; int lineno = 0; int got_transport = 0; int min_timeout = 0; struct ticket_config defaults = { { 0 } }; struct ticket_config *current_tk = NULL; fp = fopen(path, "r"); if (!fp) { log_error("failed to open %s: %s", path, strerror(errno)); return -1; } booth_conf = malloc(sizeof(struct booth_config) + TICKET_ALLOC * sizeof(struct ticket_config)); if (!booth_conf) { fclose(fp); log_error("failed to alloc memory for booth config"); return -ENOMEM; } memset(booth_conf, 0, sizeof(struct booth_config) + TICKET_ALLOC * sizeof(struct ticket_config)); ticket_size = TICKET_ALLOC; booth_conf->proto = UDP; booth_conf->port = BOOTH_DEFAULT_PORT; booth_conf->maxtimeskew = BOOTH_DEFAULT_MAX_TIME_SKEW; booth_conf->authkey[0] = '\0'; /* Provide safe defaults. -1 is reserved, though. */ booth_conf->uid = -2; booth_conf->gid = -2; strcpy(booth_conf->site_user, "hacluster"); strcpy(booth_conf->site_group, "haclient"); strcpy(booth_conf->arb_user, "nobody"); strcpy(booth_conf->arb_group, "nobody"); parse_weights("", defaults.weight); defaults.clu_test.path = NULL; defaults.clu_test.pid = 0; defaults.clu_test.status = 0; defaults.clu_test.progstate = EXTPROG_IDLE; defaults.term_duration = DEFAULT_TICKET_EXPIRY; defaults.timeout = DEFAULT_TICKET_TIMEOUT; defaults.retries = DEFAULT_RETRIES; defaults.acquire_after = 0; defaults.mode = TICKET_MODE_AUTO; error = ""; log_debug("reading config file %s", path); while (fgets(line, sizeof(line), fp)) { lineno++; s = skip_while(line, isspace); if (is_end_of_line(s) || *s == '#') continue; key = s; /* Key */ end_of_key = skip_while_in(key, isalnum, "-_"); if (end_of_key == key) { error = "No key"; goto err; } if (!*end_of_key) goto exp_equal; /* whitespace, and something else but nothing more? */ s = skip_while(end_of_key, isspace); if (*s != '=') { exp_equal: error = "Expected '=' after key"; goto err; } s++; /* It's my buffer, and I terminate if I want to. */ /* But not earlier than that, because we had to check for = */ *end_of_key = 0; /* Value tokenizing */ s = skip_while(s, isspace); switch (*s) { case '"': case '\'': val = s+1; s = skip_until(val, *s); /* Terminate value */ if (!*s) { error = "Unterminated quoted string"; goto err; } /* Remove and skip quote */ *s = 0; s++; if (*(s = skip_while(s, isspace)) && *s != '#') { error = "Surplus data after value"; goto err; } *s = 0; break; case 0: no_value: error = "No value"; goto err; break; default: val = s; /* Rest of line. */ i = strlen(s); /* i > 0 because of "case 0" above. */ while (i > 0 && isspace(s[i-1])) i--; s += i; *s = 0; } if (val == s) goto no_value; if (strlen(key) > BOOTH_NAME_LEN || strlen(val) > BOOTH_NAME_LEN) { error = "key/value too long"; goto err; } if (strcmp(key, "transport") == 0) { if (got_transport) { error = "config file has multiple transport lines"; goto err; } if (strcasecmp(val, "UDP") == 0) booth_conf->proto = UDP; else if (strcasecmp(val, "SCTP") == 0) booth_conf->proto = SCTP; else { error = "invalid transport protocol"; goto err; } got_transport = 1; continue; } if (strcmp(key, "port") == 0) { booth_conf->port = atoi(val); continue; } if (strcmp(key, "name") == 0) { safe_copy(booth_conf->name, val, BOOTH_NAME_LEN, "name"); continue; } #if HAVE_LIBGCRYPT || HAVE_LIBMHASH if (strcmp(key, "authfile") == 0) { safe_copy(booth_conf->authfile, val, BOOTH_PATH_LEN, "authfile"); continue; } if (strcmp(key, "maxtimeskew") == 0) { booth_conf->maxtimeskew = atoi(val); continue; } #endif if (strcmp(key, "site") == 0) { if (add_site(val, SITE)) goto err; continue; } if (strcmp(key, "arbitrator") == 0) { if (add_site(val, ARBITRATOR)) goto err; continue; } if (strcmp(key, "site-user") == 0) { safe_copy(booth_conf->site_user, optarg, BOOTH_NAME_LEN, "site-user"); continue; } if (strcmp(key, "site-group") == 0) { safe_copy(booth_conf->site_group, optarg, BOOTH_NAME_LEN, "site-group"); continue; } if (strcmp(key, "arbitrator-user") == 0) { safe_copy(booth_conf->arb_user, optarg, BOOTH_NAME_LEN, "arbitrator-user"); continue; } if (strcmp(key, "arbitrator-group") == 0) { safe_copy(booth_conf->arb_group, optarg, BOOTH_NAME_LEN, "arbitrator-group"); continue; } if (strcmp(key, "debug") == 0) { if (type != CLIENT && type != GEOSTORE) debug_level = max(debug_level, atoi(val)); continue; } if (strcmp(key, "ticket") == 0) { if (current_tk && strcmp(current_tk->name, "__defaults__")) { if (!postproc_ticket(current_tk)) { goto err; } } if (!strcmp(val, "__defaults__")) { current_tk = &defaults; } else if (add_ticket(val, ¤t_tk, &defaults)) { goto err; } continue; } /* current_tk must be allocated at this point, otherwise * we don't know to which ticket the key refers */ if (!current_tk) { error = "Unexpected keyword"; goto err; } if (strcmp(key, "expire") == 0) { current_tk->term_duration = read_time(val); if (current_tk->term_duration <= 0) { error = "Expected time >0 for expire"; goto err; } continue; } if (strcmp(key, "timeout") == 0) { current_tk->timeout = read_time(val); if (current_tk->timeout <= 0) { error = "Expected time >0 for timeout"; goto err; } if (!min_timeout) { min_timeout = current_tk->timeout; } else { min_timeout = min(min_timeout, current_tk->timeout); } continue; } if (strcmp(key, "retries") == 0) { current_tk->retries = strtol(val, &s, 0); if (*s || s == val || current_tk->retries<3 || current_tk->retries > 100) { error = "Expected plain integer value in the range [3, 100] for retries"; goto err; } continue; } if (strcmp(key, "renewal-freq") == 0) { current_tk->renewal_freq = read_time(val); if (current_tk->renewal_freq <= 0) { error = "Expected time >0 for renewal-freq"; goto err; } continue; } if (strcmp(key, "acquire-after") == 0) { current_tk->acquire_after = read_time(val); if (current_tk->acquire_after < 0) { error = "Expected time >=0 for acquire-after"; goto err; } continue; } if (strcmp(key, "before-acquire-handler") == 0) { if (parse_extprog(val, current_tk)) { goto err; } continue; } if (strcmp(key, "attr-prereq") == 0) { if (parse_attr_prereq(val, current_tk)) { goto err; } continue; } if (strcmp(key, "mode") == 0) { current_tk->mode = retrieve_ticket_mode(val); continue; } if (strcmp(key, "weights") == 0) { if (parse_weights(val, current_tk->weight) < 0) goto err; continue; } error = "Unknown keyword"; goto err; } fclose(fp); if ((booth_conf->site_count % 2) == 0) { log_warn("Odd number of nodes is strongly recommended!"); } /* Default: make config name match config filename. */ if (!booth_conf->name[0]) { cp = strrchr(path, '/'); cp = cp ? cp+1 : (char *)path; cp2 = strrchr(cp, '.'); if (!cp2) cp2 = cp + strlen(cp); if (cp2-cp >= BOOTH_NAME_LEN) { log_error("booth config file name too long"); goto out; } strncpy(booth_conf->name, cp, cp2-cp); *(booth_conf->name+(cp2-cp)) = '\0'; } if (!postproc_ticket(current_tk)) { goto out; } poll_timeout = min(POLL_TIMEOUT, min_timeout/10); if (!poll_timeout) poll_timeout = POLL_TIMEOUT; return 0; err: fclose(fp); out: log_error("%s in config file line %d", error, lineno); free(booth_conf); booth_conf = NULL; return -1; }
void process_end_time(){ if(!matches(value, STR_DATE_FORMAT, valuelen)) return; tm_elems tm; read_time(&tm); Scheduling_SetEndTimeUnix(Time_UnixFromTime(&tm)); }
main() { uint8 option=0; uint8 key; SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); Uart0Init(19200); Uart1Init(9600); Uart2Init(19200); IntMasterEnable(); SysLinearTimer =0; IoPortInit(); //IO口初始化 I2C1Init() ;//Fm31256 TimerInit(); xs6963_init(); PIN_TDA7367stand_Write(ETDA7367work_no); FlashUsecSet(49); //T1Init_LM331(); DPRINTF(("Bat=%d ,cha=%d ,Temp=%d \n",1,2,3)); Usb_Host_Init(); mainHandleinit(); signPWM_init(50.0); PWM_sign_stop(); /*LCD初始化*/ start_mune(); /* fm31256 eeprom 8 */ readbyte_much(setsto_addr,settype_nub,set.byte ); /*修正系数*/ modify_read(); /**/ Oiltempset.oilTwork=EOiltemp_Workon; /*lm331初始化 温度测量使用*/ T1Init_LM331(); /*系统节拍*/ SysLinearTimer=0; while(SysLinearTimer<3*TIMER_FREQ)//后台参数设置 { key=Keyset.keyEfficiency; if(key==key_modify) { while(Keyset.keyEfficiency==key_modify); option++; if(option>=4) { modify_read();//读取修正参数 TgC_read(); modify();//修正 } } } modifyK_js(); SysLinearTimer=0; rx_flag=0; option=0; mainset_go: key=Keyset.keyEfficiency; mainset_mune(); Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4); while(1) { while(key==Keyset.keyEfficiency) { if(SysLinearTimer>(3*TIMER_FREQ/4)) { // Temp_account(); if(TRUE_z==Gandispose())//地线检测 { mainset_mune(); Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4); } read_time(); { uint8 byte[12]; Clock_viewxs(byte) ; } SysLinearTimer=0; } } key=Keyset.keyEfficiency; /*按键处理*/ switch(key) { case key_no: case key_back: continue; case key_down: case key_up: Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4); option=keyoption_js(option, key,4,Emune_key);// Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4); /* if(key==key_up) { PWM_sign_acc(0.0, 0.0); delay(0x80000); PIN_DCAC_pwm(EDC_power); PWM_sign_acc(0.0, 0.7); } else { PWM_sign_acc(0.0, 0.0); delay(0x80000); PIN_DCAC_pwm(EAC_power); PWM_sign_acc(50.0, 0.8); } */ break; case key_ok: switch(option) { case ELan_main://语言 set.mune.Langue++; set.mune.Langue&=0x01; //ShowtextLine(mainset_lin+option*mainset_high, mainset_column+0x10,Lanset_p[set.mune.Langue]); break; case EOilset_main://油样设置 oidset(); break; case EView_main://历史数据 Viewdata_Hander(); break; case EClock_main://时钟设置 clockset_mune(); break; } goto mainset_go ; case key_oil: Oilclear();//排油 break; } } }
int main(int argc, char **cargv) { int dbdata_type; uschar **argv = USS cargv; uschar buffer[256]; uschar name[256]; void *reset_point = store_get(0); name[0] = 0; /* No name set */ /* Sort out the database type, verify what we are working on and then process user requests */ dbdata_type = check_args(argc, argv, US"fixdb", US""); printf("Modifying Exim hints database %s/db/%s\n", argv[1], argv[2]); for(;;) { open_db dbblock; open_db *dbm; void *record; dbdata_retry *retry; dbdata_wait *wait; dbdata_callout_cache *callout; dbdata_ratelimit *ratelimit; int i, oldlength; uschar *t; uschar field[256], value[256]; store_reset(reset_point); printf("> "); if (Ufgets(buffer, 256, stdin) == NULL) break; buffer[Ustrlen(buffer)-1] = 0; field[0] = value[0] = 0; /* If the buffer contains just one digit, or just consists of "d", use the previous name for an update. */ if ((isdigit((uschar)buffer[0]) && (buffer[1] == ' ' || buffer[1] == '\0')) || Ustrcmp(buffer, "d") == 0) { if (name[0] == 0) { printf("No previous record name is set\n"); continue; } (void)sscanf(CS buffer, "%s %s", field, value); } else { name[0] = 0; (void)sscanf(CS buffer, "%s %s %s", name, field, value); } /* Handle an update request */ if (field[0] != 0) { int verify = 1; dbm = dbfn_open(argv[1], argv[2], O_RDWR, &dbblock); if (dbm == NULL) continue; if (Ustrcmp(field, "d") == 0) { if (value[0] != 0) printf("unexpected value after \"d\"\n"); else printf("%s\n", (dbfn_delete(dbm, name) < 0)? "not found" : "deleted"); dbfn_close(dbm); continue; } else if (isdigit((uschar)field[0])) { int fieldno = Uatoi(field); if (value[0] == 0) { printf("value missing\n"); dbfn_close(dbm); continue; } else { record = dbfn_read_with_length(dbm, name, &oldlength); if (record == NULL) printf("not found\n"); else { time_t tt; int length = 0; /* Stops compiler warning */ switch(dbdata_type) { case type_retry: retry = (dbdata_retry *)record; length = sizeof(dbdata_retry) + Ustrlen(retry->text); switch(fieldno) { case 0: retry->basic_errno = Uatoi(value); break; case 1: retry->more_errno = Uatoi(value); break; case 2: if ((tt = read_time(value)) > 0) retry->first_failed = tt; else printf("bad time value\n"); break; case 3: if ((tt = read_time(value)) > 0) retry->last_try = tt; else printf("bad time value\n"); break; case 4: if ((tt = read_time(value)) > 0) retry->next_try = tt; else printf("bad time value\n"); break; case 5: if (Ustrcmp(value, "yes") == 0) retry->expired = TRUE; else if (Ustrcmp(value, "no") == 0) retry->expired = FALSE; else printf("\"yes\" or \"no\" expected=n"); break; default: printf("unknown field number\n"); verify = 0; break; } break; case type_wait: printf("Can't change contents of wait database record\n"); break; case type_misc: printf("Can't change contents of misc database record\n"); break; case type_callout: callout = (dbdata_callout_cache *)record; length = sizeof(dbdata_callout_cache); switch(fieldno) { case 0: callout->result = Uatoi(value); break; case 1: callout->postmaster_result = Uatoi(value); break; case 2: callout->random_result = Uatoi(value); break; default: printf("unknown field number\n"); verify = 0; break; } break; case type_ratelimit: ratelimit = (dbdata_ratelimit *)record; length = sizeof(dbdata_ratelimit); switch(fieldno) { case 0: if ((tt = read_time(value)) > 0) ratelimit->time_stamp = tt; else printf("bad time value\n"); break; case 1: ratelimit->time_usec = Uatoi(value); break; case 2: ratelimit->rate = Ustrtod(value, NULL); break; default: printf("unknown field number\n"); verify = 0; break; } break; } dbfn_write(dbm, name, record, length); } } } else { printf("field number or d expected\n"); verify = 0; } dbfn_close(dbm); if (!verify) continue; } /* The "name" q causes an exit */ else if (Ustrcmp(name, "q") == 0) return 0; /* Handle a read request, or verify after an update. */ dbm = dbfn_open(argv[1], argv[2], O_RDONLY, &dbblock); if (dbm == NULL) continue; record = dbfn_read_with_length(dbm, name, &oldlength); if (record == NULL) { printf("record %s not found\n", name); name[0] = 0; } else { int count_bad = 0; printf("%s\n", CS print_time(((dbdata_generic *)record)->time_stamp)); switch(dbdata_type) { case type_retry: retry = (dbdata_retry *)record; printf("0 error number: %d %s\n", retry->basic_errno, retry->text); printf("1 extra data: %d\n", retry->more_errno); printf("2 first failed: %s\n", print_time(retry->first_failed)); printf("3 last try: %s\n", print_time(retry->last_try)); printf("4 next try: %s\n", print_time(retry->next_try)); printf("5 expired: %s\n", (retry->expired)? "yes" : "no"); break; case type_wait: wait = (dbdata_wait *)record; t = wait->text; printf("Sequence: %d\n", wait->sequence); if (wait->count > WAIT_NAME_MAX) { printf("**** Data corrupted: count=%d=0x%x max=%d ****\n", wait->count, wait->count, WAIT_NAME_MAX); wait->count = WAIT_NAME_MAX; count_bad = 1; } for (i = 1; i <= wait->count; i++) { Ustrncpy(value, t, MESSAGE_ID_LENGTH); value[MESSAGE_ID_LENGTH] = 0; if (count_bad && value[0] == 0) break; if (Ustrlen(value) != MESSAGE_ID_LENGTH || Ustrspn(value, "0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ-") != MESSAGE_ID_LENGTH) { int j; printf("\n**** Data corrupted: bad character in message id ****\n"); for (j = 0; j < MESSAGE_ID_LENGTH; j++) printf("%02x ", value[j]); printf("\n"); break; } printf("%s ", value); t += MESSAGE_ID_LENGTH; } printf("\n"); break; case type_misc: break; case type_callout: callout = (dbdata_callout_cache *)record; printf("0 callout: %s (%d)\n", print_cache(callout->result), callout->result); if (oldlength > sizeof(dbdata_callout_cache_address)) { printf("1 postmaster: %s (%d)\n", print_cache(callout->postmaster_result), callout->postmaster_result); printf("2 random: %s (%d)\n", print_cache(callout->random_result), callout->random_result); } break; case type_ratelimit: ratelimit = (dbdata_ratelimit *)record; printf("0 time stamp: %s\n", print_time(ratelimit->time_stamp)); printf("1 fract. time: .%06d\n", ratelimit->time_usec); printf("2 sender rate: % .3f\n", ratelimit->rate); break; } } /* The database is closed after each request */ dbfn_close(dbm); } printf("\n"); return 0; }
// Main function void main(void) { reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin(); initGPIO(); initADC(); initConsole(); int i = 0; //init_password(); send_data(); initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data); int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0; int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0; float distance = 0; bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time; int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0; IntMasterEnable(); while(1){ //reading data read_data = split_data(UART_char_data_old, read_data); // decode data speed = read_speed(); //read data into variables adc = run_adc()/7; //calculations aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed); if (speed_set_data.enable == 1){ step_motor_control(encoder_1/40, aim_pos); } //sending fake data fake_speed = (int)adc;//= random_at_most(100/1.852); send_info(fake_speed);//knots //storing data store_speed(speed); buffed_speed = analysis_speed(); acc = read_acceleration(buffed_speed); max_acc = max_acc_func(acc, max_acc); time = read_time(); satillite = read_satillite(); fix = read_fix(); quality = read_quality(); debounce_button(); // debounce buttons screen = read_button_screen(screen, fix); distance = read_distance(); select_read(); //need a mosfet for turning power off // select adds a an on and off switch yo if (screen == 1){ if(screen_prev != 1 && screen == 1){ speed_set_data.speed = buffed_speed; } speed_set_data.speed = set_speed(speed_set_data.speed); // set the speed to cruise at } if (screen == 2){ //0 to 100 acceleration_test(speed); } // refresh chainging if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){ UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0); refresh_rate += 1; } if (i >= 50){ display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite, encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times); i = 0; } screen_prev = screen; i++; } }