void dcf2time(void) { if (signal_iter == 60) { time.seconds = 0; // Assume time signal is good only if all parities are correct if (check_parity(21, 27, 28) && check_parity(29, 34, 35) && check_parity(36, 57, 58)) { time.minutes = decode_value(21, 27); time.hours = decode_value(29, 34); time.date = decode_value(36, 41); time.dow = decode_value(42, 44); time.month = decode_value(45, 49); time.year = decode_value(50, 57); time_valid = true; } } }
bool CRC_Code::decode(bvec &coded_bits) const { //coded_bits = coded_bits(0, coded_bits.size()-no_parity-1); <-- OLD CODE if (check_parity(coded_bits)) { return true; } else return false; }
bool CRC_Code::decode(const bvec &coded_bits, bvec &out) const { out = coded_bits(0, coded_bits.size() - no_parity - 1); if (check_parity(coded_bits)) { return true; } else return false; }
static bool data_frame_check_multiblock(data_frame_t *data_fr) { if (data_fr->nerrs) { fix_by_parity(data_fr); } else { if (!check_parity(data_fr)) { LOG(ERR, "MB parity error %d", data_fr->nblks); data_frame_reset(data_fr); return false; } } return true; }
/****************************************************************** * change parity ******************************************************************/ static int writeParity( int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len ) { unsigned long value = *(unsigned long *)var_val; DEBUGMSGTL(("aj_serial", "%s()\n", __FUNCTION__)); switch(action) { case RESERVE1: if(var_val_type != ASN_INTEGER) { DEBUGMSGTL(("aj_serial", "%x net inter type", var_val_type)); return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long)) { DEBUGMSGTL(("aj_serial", "wrong length %x", var_val_len)); return SNMP_ERR_WRONGLENGTH; } if(!check_parity(value)) { return SNMP_ERR_WRONGVALUE; } break; case ACTION: if(g_serial_setting.parity != value) { g_serial_setting.parity = value; g_save_flag = 1; } break; case COMMIT: if(g_save_flag) { save_serial_config(); g_save_flag = 0; } break; default: break; } return SNMP_ERR_NOERROR; }
int command_well_formated(char *buff) { if (!check_parity(buff, '\'', '\'') || !check_parity(buff, '"', '"') || !check_parity(buff, '`', '`') || !check_parity(buff, '(', ')') || !check_parity(buff, '[', ']') || !check_parity(buff, '{', '}')) return (0); return (1); }
INT32 Evaluation(UINT8 *board, UINT64 bk, UINT64 wh, UINT32 color, UINT32 stage) { float eval; /* 現在の色とステージでポインタを指定 */ hori_ver1 = hori_ver1_data[color][stage]; hori_ver2 = hori_ver2_data[color][stage]; hori_ver3 = hori_ver3_data[color][stage]; dia_ver1 = dia_ver1_data[color][stage]; dia_ver2 = dia_ver2_data[color][stage]; dia_ver3 = dia_ver3_data[color][stage]; dia_ver4 = dia_ver4_data[color][stage]; edge = edge_data[color][stage]; corner5_2 = corner5_2_data[color][stage]; corner3_3 = corner3_3_data[color][stage]; triangle = triangle_data[color][stage]; parity = parity_data[color][stage]; eval = check_h_ver1(board); eval += check_h_ver2(board); eval += check_h_ver3(board); eval += check_dia_ver1(board); eval += check_dia_ver2(board); eval += check_dia_ver3(board); eval += check_dia_ver4(board); eval += check_edge(board); eval += check_corner5_2(board); eval += check_corner3_3(board); eval += check_triangle(board); eval += check_parity(~(bk | wh), color); eval_sum = eval; eval *= EVAL_ONE_STONE; #ifdef LOSSGAME return -(INT32)eval; #else return (INT32)eval; #endif }
/* decode gps message --------------------------------------------------------*/ static int decode_gw10gps(raw_t *raw) { eph_t eph={0}; double tow,ion[8]={0},utc[4]={0}; unsigned int buff=0; int i,prn,sat,id,leaps; unsigned char *p=raw->buff+2,subfrm[30]; trace(4,"decode_gw10gps: len=%d\n",raw->len); tow=U4(p)/1000.0; p+=4; prn=U1(p); p+=1; if (!(sat=satno(SYS_GPS,prn))) { trace(2,"gw10 gps satellite number error: tow=%.1f prn=%d\n",tow,prn); return -1; } for (i=0;i<10;i++) { buff=(buff<<30)|U4(p); p+=4; /* check parity of word */ if (!check_parity(buff,subfrm+i*3)) { trace(2,"gw10 gps frame parity error: tow=%.1f prn=%2d word=%2d\n", tow,prn,i+1); return -1; } } id=getbitu(subfrm,43,3); /* subframe id */ if (id<1||5<id) { trace(2,"gw10 gps frame id error: tow=%.1f prn=%2d id=%d\n",tow,prn,id); return -1; } for (i=0;i<30;i++) raw->subfrm[sat-1][i+(id-1)*30]=subfrm[i]; if (id==3) { /* decode ephemeris */ if (decode_frame(raw->subfrm[sat-1] ,&eph,NULL,NULL,NULL,NULL)!=1|| decode_frame(raw->subfrm[sat-1]+30,&eph,NULL,NULL,NULL,NULL)!=2|| decode_frame(raw->subfrm[sat-1]+60,&eph,NULL,NULL,NULL,NULL)!=3) { return 0; } if (!strstr(raw->opt,"-EPHALL")) { if (eph.iode==raw->nav.eph[sat-1].iode) return 0; /* unchanged */ } eph.sat=sat; raw->nav.eph[sat-1]=eph; raw->ephsat=sat; return 2; } else if (id==4) { /* decode ion-utc parameters */ if (decode_frame(subfrm,NULL,NULL,ion,utc,&leaps)!=4) { return 0; } if (norm(ion,8)>0.0&&norm(utc,4)>0.0&&leaps!=0) { for (i=0;i<8;i++) raw->nav.ion_gps[i]=ion[i]; for (i=0;i<4;i++) raw->nav.utc_gps[i]=utc[i]; raw->nav.leaps=leaps; return 9; } } return 0; }
int main(int argc,char *argv[]) { int ch; int num_options; unsigned long action; char config_filename[PATH_MAX]; char dev_name[PATH_MAX]; char name[PATH_MAX]; char component[PATH_MAX]; char autoconf[10]; int do_output; int do_recon; int do_rewrite; int is_clean; int raidID; int serial_number; struct stat st; int fd; int force; int openmode; num_options = 0; action = 0; do_output = 0; do_recon = 0; do_rewrite = 0; is_clean = 0; serial_number = 0; force = 0; openmode = O_RDWR; /* default to read/write */ while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:r:R:sSpPuv")) != -1) switch(ch) { case 'a': action = RAIDFRAME_ADD_HOT_SPARE; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'A': action = RAIDFRAME_SET_AUTOCONFIG; strlcpy(autoconf, optarg, sizeof(autoconf)); num_options++; break; case 'B': action = RAIDFRAME_COPYBACK; num_options++; break; case 'c': action = RAIDFRAME_CONFIGURE; strlcpy(config_filename, optarg, sizeof(config_filename)); force = 0; num_options++; break; case 'C': strlcpy(config_filename, optarg, sizeof(config_filename)); action = RAIDFRAME_CONFIGURE; force = 1; num_options++; break; case 'f': action = RAIDFRAME_FAIL_DISK; strlcpy(component, optarg, sizeof(component)); do_recon = 0; num_options++; break; case 'F': action = RAIDFRAME_FAIL_DISK; strlcpy(component, optarg, sizeof(component)); do_recon = 1; num_options++; break; case 'g': action = RAIDFRAME_GET_COMPONENT_LABEL; strlcpy(component, optarg, sizeof(component)); openmode = O_RDONLY; num_options++; break; case 'G': action = RAIDFRAME_GET_INFO; openmode = O_RDONLY; do_output = 1; num_options++; break; case 'i': action = RAIDFRAME_REWRITEPARITY; num_options++; break; case 'I': action = RAIDFRAME_INIT_LABELS; serial_number = atoi(optarg); num_options++; break; case 'l': action = RAIDFRAME_SET_COMPONENT_LABEL; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'r': action = RAIDFRAME_REMOVE_HOT_SPARE; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'R': strlcpy(component, optarg, sizeof(component)); action = RAIDFRAME_REBUILD_IN_PLACE; num_options++; break; case 's': action = RAIDFRAME_GET_INFO; openmode = O_RDONLY; num_options++; break; case 'S': action = RAIDFRAME_CHECK_RECON_STATUS_EXT; openmode = O_RDONLY; num_options++; break; case 'p': action = RAIDFRAME_CHECK_PARITY; openmode = O_RDONLY; num_options++; break; case 'P': action = RAIDFRAME_CHECK_PARITY; do_rewrite = 1; num_options++; break; case 'u': action = RAIDFRAME_SHUTDOWN; num_options++; break; case 'v': verbose = 1; /* Don't bump num_options, as '-v' is not an option like the others */ /* num_options++; */ break; default: usage(); } argc -= optind; argv += optind; if ((num_options > 1) || (argc == 0)) usage(); strlcpy(name, argv[0], sizeof(name)); fd = opendisk(name, openmode, dev_name, sizeof(dev_name), 0); if (fd == -1) { fprintf(stderr, "%s: unable to open device file: %s\n", getprogname(), name); exit(1); } if (fstat(fd, &st) != 0) { fprintf(stderr,"%s: stat failure on: %s\n", getprogname(), dev_name); exit(1); } if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) { fprintf(stderr,"%s: invalid device: %s\n", getprogname(), dev_name); exit(1); } raidID = DISKUNIT(st.st_rdev); switch(action) { case RAIDFRAME_ADD_HOT_SPARE: add_hot_spare(fd, component); break; case RAIDFRAME_REMOVE_HOT_SPARE: remove_hot_spare(fd, component); break; case RAIDFRAME_CONFIGURE: rf_configure(fd, config_filename, force); break; case RAIDFRAME_SET_AUTOCONFIG: set_autoconfig(fd, raidID, autoconf); break; case RAIDFRAME_COPYBACK: printf("Copyback.\n"); do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK"); if (verbose) { sleep(3); /* XXX give the copyback a chance to start */ printf("Copyback status:\n"); do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT); } break; case RAIDFRAME_FAIL_DISK: rf_fail_disk(fd, component, do_recon); break; case RAIDFRAME_SET_COMPONENT_LABEL: set_component_label(fd, component); break; case RAIDFRAME_GET_COMPONENT_LABEL: get_component_label(fd, component); break; case RAIDFRAME_INIT_LABELS: init_component_labels(fd, serial_number); break; case RAIDFRAME_REWRITEPARITY: printf("Initiating re-write of parity\n"); do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL, "RAIDFRAME_REWRITEPARITY"); if (verbose) { sleep(3); /* XXX give it time to get started */ printf("Parity Re-write status:\n"); do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT); } break; case RAIDFRAME_CHECK_RECON_STATUS_EXT: check_status(fd,1); break; case RAIDFRAME_GET_INFO: if (do_output) rf_output_configuration(fd, dev_name); else rf_get_device_status(fd); break; case RAIDFRAME_REBUILD_IN_PLACE: rebuild_in_place(fd, component); break; case RAIDFRAME_CHECK_PARITY: check_parity(fd, do_rewrite, dev_name); break; case RAIDFRAME_SHUTDOWN: do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN"); break; default: break; } close(fd); exit(0); }
int main(int argc,char *argv[]) { int ch, i; int num_options; unsigned long action; char config_filename[PATH_MAX]; char dev_name[PATH_MAX]; char name[PATH_MAX]; char component[PATH_MAX]; char autoconf[10]; char *parityconf = NULL; int parityparams[3]; int do_output; int do_recon; int do_rewrite; int raidID; int serial_number; struct stat st; int fd; int force; int openmode; int last_unit; num_options = 0; action = 0; do_output = 0; do_recon = 0; do_rewrite = 0; serial_number = 0; force = 0; last_unit = 0; openmode = O_RDWR; /* default to read/write */ while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:mM:r:R:sSpPuU:v")) != -1) switch(ch) { case 'a': action = RAIDFRAME_ADD_HOT_SPARE; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'A': action = RAIDFRAME_SET_AUTOCONFIG; strlcpy(autoconf, optarg, sizeof(autoconf)); num_options++; break; case 'B': action = RAIDFRAME_COPYBACK; num_options++; break; case 'c': action = RAIDFRAME_CONFIGURE; strlcpy(config_filename, optarg, sizeof(config_filename)); force = 0; num_options++; break; case 'C': strlcpy(config_filename, optarg, sizeof(config_filename)); action = RAIDFRAME_CONFIGURE; force = 1; num_options++; break; case 'f': action = RAIDFRAME_FAIL_DISK; strlcpy(component, optarg, sizeof(component)); do_recon = 0; num_options++; break; case 'F': action = RAIDFRAME_FAIL_DISK; strlcpy(component, optarg, sizeof(component)); do_recon = 1; num_options++; break; case 'g': action = RAIDFRAME_GET_COMPONENT_LABEL; strlcpy(component, optarg, sizeof(component)); openmode = O_RDONLY; num_options++; break; case 'G': action = RAIDFRAME_GET_INFO; openmode = O_RDONLY; do_output = 1; num_options++; break; case 'i': action = RAIDFRAME_REWRITEPARITY; num_options++; break; case 'I': action = RAIDFRAME_INIT_LABELS; serial_number = xstrtouint(optarg); num_options++; break; case 'm': action = RAIDFRAME_PARITYMAP_STATUS; openmode = O_RDONLY; num_options++; break; case 'M': action = RAIDFRAME_PARITYMAP_SET_DISABLE; parityconf = strdup(optarg); num_options++; /* XXXjld: should rf_pm_configure do the strtol()s? */ i = 0; while (i < 3 && optind < argc && isdigit((int)argv[optind][0])) parityparams[i++] = xstrtouint(argv[optind++]); while (i < 3) parityparams[i++] = 0; break; case 'l': action = RAIDFRAME_SET_COMPONENT_LABEL; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'r': action = RAIDFRAME_REMOVE_HOT_SPARE; strlcpy(component, optarg, sizeof(component)); num_options++; break; case 'R': strlcpy(component, optarg, sizeof(component)); action = RAIDFRAME_REBUILD_IN_PLACE; num_options++; break; case 's': action = RAIDFRAME_GET_INFO; openmode = O_RDONLY; num_options++; break; case 'S': action = RAIDFRAME_CHECK_RECON_STATUS_EXT; openmode = O_RDONLY; num_options++; break; case 'p': action = RAIDFRAME_CHECK_PARITY; openmode = O_RDONLY; num_options++; break; case 'P': action = RAIDFRAME_CHECK_PARITY; do_rewrite = 1; num_options++; break; case 'u': action = RAIDFRAME_SHUTDOWN; num_options++; break; case 'U': action = RAIDFRAME_SET_LAST_UNIT; num_options++; last_unit = atoi(optarg); if (last_unit < 0) errx(1, "Bad last unit %s", optarg); break; case 'v': verbose = 1; /* Don't bump num_options, as '-v' is not an option like the others */ /* num_options++; */ break; default: usage(); } argc -= optind; argv += optind; if ((num_options > 1) || (argc == 0)) usage(); if (prog_init && prog_init() == -1) err(1, "init failed"); strlcpy(name, argv[0], sizeof(name)); fd = opendisk1(name, openmode, dev_name, sizeof(dev_name), 0, prog_open); if (fd == -1) err(1, "Unable to open device file: %s", name); if (prog_fstat(fd, &st) == -1) err(1, "stat failure on: %s", dev_name); if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) err(1, "invalid device: %s", dev_name); raidID = DISKUNIT(st.st_rdev); switch(action) { case RAIDFRAME_ADD_HOT_SPARE: add_hot_spare(fd, component); break; case RAIDFRAME_REMOVE_HOT_SPARE: remove_hot_spare(fd, component); break; case RAIDFRAME_CONFIGURE: rf_configure(fd, config_filename, force); break; case RAIDFRAME_SET_AUTOCONFIG: set_autoconfig(fd, raidID, autoconf); break; case RAIDFRAME_COPYBACK: printf("Copyback.\n"); do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK"); if (verbose) { sleep(3); /* XXX give the copyback a chance to start */ printf("Copyback status:\n"); do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT); } break; case RAIDFRAME_FAIL_DISK: rf_fail_disk(fd, component, do_recon); break; case RAIDFRAME_SET_COMPONENT_LABEL: set_component_label(fd, component); break; case RAIDFRAME_GET_COMPONENT_LABEL: get_component_label(fd, component); break; case RAIDFRAME_INIT_LABELS: init_component_labels(fd, serial_number); break; case RAIDFRAME_REWRITEPARITY: printf("Initiating re-write of parity\n"); do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL, "RAIDFRAME_REWRITEPARITY"); if (verbose) { sleep(3); /* XXX give it time to get started */ printf("Parity Re-write status:\n"); do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT); } break; case RAIDFRAME_CHECK_RECON_STATUS_EXT: check_status(fd,1); break; case RAIDFRAME_GET_INFO: if (do_output) rf_output_configuration(fd, dev_name); else rf_get_device_status(fd); break; case RAIDFRAME_PARITYMAP_STATUS: rf_output_pmstat(fd, raidID); break; case RAIDFRAME_PARITYMAP_SET_DISABLE: rf_pm_configure(fd, raidID, parityconf, parityparams); break; case RAIDFRAME_REBUILD_IN_PLACE: rebuild_in_place(fd, component); break; case RAIDFRAME_CHECK_PARITY: check_parity(fd, do_rewrite, dev_name); break; case RAIDFRAME_SHUTDOWN: do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN"); break; case RAIDFRAME_SET_LAST_UNIT: do_ioctl(fd, RAIDFRAME_SET_LAST_UNIT, &last_unit, "RAIDFRAME_SET_LAST_UNIT"); break; default: break; } prog_close(fd); exit(0); }
/****************************************************************** * load serial setting *****************************************************************/ static void load_serial_setting(void) { char buff[256]; FILE* fp = fopen(SERIAL_CONFIG_FILE, "r"); if(!fp) { DEBUGMSGTL(("aj_serial", "init_serial_seting()\n")); return; } /* get value from config file */ while(fgets(buff, sizeof(buff), fp)) { const char* fmt = "%s %u"; char key[64]; unsigned long value; if(sscanf(buff, fmt, key, &value) != 2) { DEBUGMSGTL(("aj_serial", "format invalid %s\n", buff)); continue; } if(!strcmp(key, SOCK_PROTO_KEY_STR)) { if(check_sock_proto(value)) { g_sock_proto = value; } } else if(!strcmp(key, CONNECT_ADDR_KEY_STR)) { g_connect_addr = value; } else if(!strcmp(key, PORTNO_KEY_STR)) { if(check_portno(value)) { g_port_no = value; } else { g_port_no = DEFAULT_PORT_NO; } } else if(!strcmp(key, BAUDRATE_KEY_STR)) { if(check_baudrate(value)) { g_serial_setting.baudrate = value; } } else if(!strcmp(key, STOPBIT_KEY_STR)) { if(check_stop_bit(value)) { g_serial_setting.stop_bit = (stop_bit_e)value; } } else if(!strcmp(key, PARITY_KEY_STR)) { if(check_parity(value)) { g_serial_setting.parity = (parity_e)value; } } else if(!strcmp(key, FLOWCTRL_KEY_STR)) { if(check_flow_ctrl(value)) { g_serial_setting.flow_ctrl = (flow_ctrl_e)value; } } else { DEBUGMSGTL(("aj_serial", "invalid key %s\n", key)); } } fclose(fp); return; }