📄 defs.php
字号:
if (key_in_array($name, $array)) $ai = array_search($array[$name], $vals, FALSE); else { if (key_in_array($i, $defs)) $ai = $defs[$i]; else $ai = 0; } for ($j = 0; $j < $nval; $j++) { $val = $vals[$j]; if ($val == '') $pval = " "; else $pval = "$val"; printf("\t\t\t<option " . "value=\"%s\"%s>%s</option>\n", $val, $j == $ai ? " selected" : "", $pval); } echo "\t\t</select>\n"; } end_field(); } // functions to handle the form input // fetch all the parts of an "enum_multi" into a string suitable // for a MySQL query function gather_enum_multi_query($base, $cnt) { $retval = ''; for ($i = 0; $i < $cnt; $i++) { $name = sprintf("%s%x", $base, $i); if (isset($GLOBALS[$name])) { $retval .= sprintf(", %s='%s'", $name, $GLOBALS[$name]); } } return $retval; } // fetch all the parts of an "enum_multi" into a string suitable // for a display e.g. in an html table cell function gather_enum_multi_print($base, $cnt, $array) { $retval = ''; for ($i = 0; $i < $cnt; $i++) { $name = sprintf("%s%x", $base, $i); if ($array[$name] != '') { if ($retval != '') $retval .= ','; $retval .= $array[$name]; } } return $retval; } // fetch all the parts of an "enum_multi" into a string suitable // for writing to the eeprom data file function gather_enum_multi_write($base, $cnt, $vals, $xfrm = array()) { $retval = ''; for ($i = 0; $i < $cnt; $i++) { $name = sprintf("%s%x", $base, $i); if ($GLOBALS[$name] != '') { if ($retval != '') $retval .= ','; $index = enum_to_index($name, $vals); if ($xfrm != array()) $retval .= $xfrm[$index]; else $retval .= $index; } } return $retval; } // count how many parts of an "enum_multi" are actually set function count_enum_multi($base, $cnt) { $retval = 0; for ($i = 0; $i < $cnt; $i++) { $name = sprintf("%s%x", $base, $i); if (isset($GLOBALS[$name])) $retval++; } return $retval; } // ethernet address functions // generate a (possibly not unique) random vendor ethernet address // (setting bit 6 in the ethernet address - motorola wise i.e. bit 0 // is the most significant bit - means it is not an assigned ethernet // address - it is a "locally administered" address). Also, make sure // it is NOT a multicast ethernet address (by setting bit 7 to 0). // e.g. the first byte of all ethernet addresses generated here will // have 2 in the bottom two bits (incidentally, these are the first // two bits transmitted on the wire, since the octets in ethernet // addresses are transmitted LSB first). function gen_eth_addr($serno) { $ethaddr_high = (mt_rand(0, 65535) & 0xfeff) | 0x0200; $ethaddr_low = mt_rand(0, 4294967295); return sprintf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx", $ethaddr_high >> 8, $ethaddr_high & 0xff, $ethaddr_low >> 24, ($ethaddr_low >> 16) & 0xff, ($ethaddr_low >> 8) & 0xff, $ethaddr_low & 0xff); } // check that an ethernet address is valid function eth_addr_is_valid($ethaddr) { $ethbytes = split(':', $ethaddr); if (count($ethbytes) != 6) return FALSE; for ($i = 0; $i < 6; $i++) { $ethbyte = $ethbytes[$i]; if (!ereg('^[0-9a-f][0-9a-f]$', $ethbyte)) return FALSE; } return TRUE; } // write a simple eeprom configuration file function write_eeprom_cfg_file() { global $sernos, $nsernos, $bddb_cfgdir, $numerrs, $cfgerrs; global $date, $batch, $type_vals, $rev; global $sdram_vals, $sdram_nbits; global $flash_vals, $flash_nbits; global $zbt_vals, $zbt_nbits; global $xlxtyp_vals, $xlxspd_vals, $xlxtmp_vals, $xlxgrd_vals; global $cputyp, $cputyp_vals, $clk_vals; global $hstype, $hstype_vals, $hschin, $hschout; $numerrs = 0; $cfgerrs = array(); for ($i = 0; $i < $nsernos; $i++) { $serno = sprintf("%010d", $sernos[$i]); $wfp = @fopen($bddb_cfgdir . "/$serno.cfg", "w"); if (!$wfp) { $cfgerrs[$i] = 'file create fail'; $numerrs++; continue; } set_file_buffer($wfp, 0); if (!fprintf($wfp, "serno=%d\n", $sernos[$i])) { $cfgerrs[$i] = 'cfg wr fail (serno)'; fclose($wfp); $numerrs++; continue; } if (!fprintf($wfp, "date=%s\n", $date)) { $cfgerrs[$i] = 'cfg wr fail (date)'; fclose($wfp); $numerrs++; continue; } if ($batch != '') { if (!fprintf($wfp, "batch=%s\n", $batch)) { $cfgerrs[$i] = 'cfg wr fail (batch)'; fclose($wfp); $numerrs++; continue; } } $typei = enum_to_index("type", $type_vals); if (!fprintf($wfp, "type=%d\n", $typei)) { $cfgerrs[$i] = 'cfg wr fail (type)'; fclose($wfp); $numerrs++; continue; } if (!fprintf($wfp, "rev=%d\n", $rev)) { $cfgerrs[$i] = 'cfg wr fail (rev)'; fclose($wfp); $numerrs++; continue; } $s = gather_enum_multi_write("sdram", 4, $sdram_vals, $sdram_nbits); if ($s != '') { $b = fprintf($wfp, "sdram=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (sdram)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("flash", 4, $flash_vals, $flash_nbits); if ($s != '') { $b = fprintf($wfp, "flash=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (flash)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("zbt", 16, $zbt_vals, $zbt_nbits); if ($s != '') { $b = fprintf($wfp, "zbt=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (zbt)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxtyp", 4, $xlxtyp_vals); if ($s != '') { $b = fprintf($wfp, "xlxtyp=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxtyp)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxspd", 4, $xlxspd_vals); if ($s != '') { $b = fprintf($wfp, "xlxspd=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxspd)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxtmp", 4, $xlxtmp_vals); if ($s != '') { $b = fprintf($wfp, "xlxtmp=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxtmp)'; fclose($wfp); $numerrs++; continue; } } $s = gather_enum_multi_write("xlxgrd", 4, $xlxgrd_vals); if ($s != '') { $b = fprintf($wfp, "xlxgrd=%s\n", $s); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (xlxgrd)'; fclose($wfp); $numerrs++; continue; } } if ($cputyp != '') { $cputypi = enum_to_index("cputyp",$cputyp_vals); $cpuspdi = enum_to_index("cpuspd", $clk_vals); $busspdi = enum_to_index("busspd", $clk_vals); $cpmspdi = enum_to_index("cpmspd", $clk_vals); $b = fprintf($wfp, "cputyp=%d\ncpuspd=%d\n" . "busspd=%d\ncpmspd=%d\n", $cputypi, $cpuspdi, $busspdi, $cpmspdi); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (cputyp)'; fclose($wfp); $numerrs++; continue; } } if ($hstype != '') { $hstypei = enum_to_index("hstype",$hstype_vals); $b = fprintf($wfp, "hstype=%d\n" . "hschin=%s\nhschout=%s\n", $hstypei, $hschin, $hschout); if (!$b) { $cfgerrs[$i] = 'cfg wr fail (hstype)'; fclose($wfp); $numerrs++; continue; } } if (!fclose($wfp)) { $cfgerrs[$i] = 'file cls fail'; $numerrs++; } } return $numerrs; }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -