paraSql=$paraSql";
$paraResult=mysqli_query($pubConn,$paraSql);
$paraRows=@mysqli_fetch_array($paraResult);
$setValue=$paraRows[initValue];
$readValue=$paraRows[readValue];
if($DEBUG)
echo "
setValue=$setValue";
function omcStrFill($string,$defLen,$fillWay='high',$fillChar='0'){
if(strlen($string) <= $defLen){
$fillLen=$defLen - strlen($string);
for($i=0;$i<$fillLen;$i++){
if($fillWay == 'low'){
$string = $string.$fillChar;
}else{
$string = $fillChar.$string;
}
}
return($string);
}else{
echo "
Error in omcStrFill:the defLen < lengh of string!!";
echo "
defLen=$defLen and string=$string!!";
exit();
}
}
//----------------------
//选择语言版本
if($language == 'eng'){
$objNameField=name_2;
$objSetField=setTemplate_2 ; //语种2
}else{
$objNameField=name_1;
$objSetField=setTemplate_1 ; //语种1(默认语种)
}
//-----------------------
//=======================Get value From submit===================
if($set == 'Set'){
//sort by offset
for($i=1;$i<=$unitNum;$i++){
$tmpDef = ${'unitDef_'.$i};
$tmpValue = ${'unit_'.$i};
if($DEBUG) echo "
tmpDef = $tmpDef";
$defArr[$i] = $tmpDef;
$tmpDefArr=explode('-',$tmpDef);
$sortArr[$i] = $tmpDefArr[0];
$valueArr[$i] = $tmpValue;
}
$lastValue = '';
$k = 0;
asort($sortArr);
for(reset($sortArr); $key = key($sortArr); next($sortArr)){
if($DEBUG) echo "
sortArr[$key] = {$sortArr[$key]}";
if($DEBUG) echo "
unitValue = {$valueArr[$key]}";
$unitValue = $valueArr[$key];
if($DEBUG) echo "
defArr[$key] = {$defArr[$key]}";
$unitDefArr = explode('-',$defArr[$key]); //例:0.0-0.7-input -toDec-high-0
if(sizeof($unitDefArr) <= 1){
if($DEBUG) echo "
nothing,just a name";
continue;
}
$bgnOffset = $unitDefArr[0];
$endOffset = $unitDefArr[1];
$operType = $unitDefArr[2];
$valueType = $unitDefArr[3];
$fillWay = $unitDefArr[4];
$fillChar = $unitDefArr[5];
$bgnOffsetArr = explode('.',$bgnOffset);
$bgnByte = $bgnOffsetArr[0];
$bgnBit = $bgnOffsetArr[1];
$endOffsetArr = explode('.',$endOffset);
$endByte = $endOffsetArr[0];
$endBit = $endOffsetArr[1];
$byteLen = $endByte - $bgnByte + 1;
$byteValue = '';
if($DEBUG) echo "
valueType = $valueType";
switch($valueType){
case 'toDec':
if($bgnBit > 0 ||$endBit < 7){
$bitLen = $byteLen*8 - $bgnBit - (7 - $endBit) ; //1 BYTE = 8 bit
$bitValue = DecBin($unitValue);
if($DEBUG)echo "
bitValue = $bitValue ";
$bitValue = omcStrFill($bitValue,$bitLen,$fillWay,$fillChar);
if($DEBUG) echo "
omcStrFill($bitValue,$bitLen,$fillWay,$fillChar)";
$bitValueArr[$k] = $bitValue;
if($DEBUG) echo "
bitValueArr[$k] = {$bitValueArr[$k]}";
if($endBit == 7){//发现这个单元结束,并没有跨byte,这时需要组成一个byte值
$bitValue = '';
for($bitNo=0; $bitNo<=$k; $bitNo++){
if($DEBUG) echo "
bitValueArr[$bitNo] = {$bitValueArr[$bitNo]}";
$bitValue = $bitValueArr[$bitNo].$bitValue;
}
$k=0;
if($DEBUG) echo "
bitValue = $bitValue";
$byteLen = strlen($bitValue) / 8;
if($DEBUG) echo "
byteLen = $byteLen";
$byteValue = BinDec($bitValue);
$byteValue = DecHex($byteValue);
$strLen = $byteLen*2;
if($DEBUG) echo "
omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
}else{//否则,继续组合下一个bit组
$byteValue = '';
$k++;
}
}else{
$byteValue = DecHex($unitValue);
$strLen = $byteLen*2;
$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
if($DEBUG) echo "
omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
}
if($DEBUG) echo "
byteValue = $byteValue";
break;
case 'keepDec':
//echo "
Error:keepDec";
$byteValue = $unitValue - 0;
break;
case 'toHex':
echo "
Error:toHex";
break;
case 'keepHex':
if($bgnBit > 0 || $endBit < 7){//这里的处理不够全面,没有对=7的进行收尾
$byteValue = $unitValue;
$strLen = $byteLen;
$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
$bitValue = DecBin(HexDec($byteValue));
$byteValue='';
$bitLen = $byteLen*8 - $bgnBit - (7 - $endBit) ; //1 BYTE = 8 bit
$bitValue = omcStrFill($bitValue,$bitLen,'high','0');
if($DEBUG) echo "
bitValue = $bitValue";
$bitValueArr[$k] = $bitValue;
$k++;
}else{
$k=0;
$byteValue = $unitValue;
$strLen = $byteLen*2;
$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
if($DEBUG) echo "
omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
}
break;
case 'toAscii':
if($bgnBit > 0 ||$endBit < 7){
echo "
Error:toAscii";
exit(1);
}else{
$tmpLen=strlen($unitValue);
for($i=0;$i<$tmpLen;$i++){
$unitChar = substr($unitValue,$i,1);
$decValue = ord($unitChar); //ascii -> dec
$byteValue .= DecHex($decValue);
if(strlen($byteValue) < 2){
$byteValue = '0'.$byteValue;
}
}
$strLen = $byteLen*2;
$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
}
break;
case 'toLatitude':
//feake show 4byte
if($unitValue>90)
{
$unitValue=90;
/**************************************************/
echo "\n\n";
/***************************************************/
}
if($unitValue<-90)
{
$unitValue=-90;
/**************************************************/
echo "\n\n";
/***************************************************/
}
$byteValue=$unitValue*pow(2,23)/90;
$byteValue=ceil($byteValue);
$byteValue=dechex($byteValue);
$byteValue=omcStrFill($byteValue,8,'high','0');
break;
case 'toLongitude':
if($unitValue>180)
{
$unitValue=180;
/**************************************************/
echo "\n\n";
/***************************************************/
}
if($unitValue<-180)
{
$unitValue=-180;
/**************************************************/
echo "\n\n";
/***************************************************/
}
$byteValue=$unitValue*pow(2,24)/360;
$byteValue=ceil($byteValue);
$byteValue=dechex($byteValue);
$byteValue=omcStrFill($byteValue,8,'high','0');
break;
default:
echo "Error:Unknown valueType";
break;
}
if($DEBUG) echo "
byteValue = $byteValue ";
//--><-//$lastValue = $byteValue.$lastValue;
$lastValue = $lastValue.$byteValue;
}
$lastValue=strtoupper($lastValue);
if($DEBUG) echo "
lastValue = $lastValue ";
$updateSql="UPDATE $paraTable SET initValue='$lastValue' WHERE $levelWhere AND instanceNo=$instanceNo";
if($DEBUG)echo "
updateSql=$updateSql";
mysqli_query($pubConn,$updateSql);
if($lastValue==$readValue)
{
$returnColor= $settedColor;
}
else
{
$returnColor= $notSettedColor;
$oidwhere=getLevelWhere(substr($oidStr,0,strlen($oidStr)-2));
$tableName=getNameByOID_handle($sysTypeNo,$oidwhere);
$tableName=str_replace("Entry","",$tableName);
$sysName=getSystemNameBySysTypeNo($sysTypeNo);
$fieldName=getNameByOID_handle($sysTypeNo,$levelWhere);
$log="Change $sysName $tableName's $fieldName, ".$readValue." -> ".$lastValue;
insertLog($log);
//$handle=fopen("/tmp/test.txt","a");
//fwrite($handle,$log);
//fwrite($handle,"\n");
//fclose($handle);
}
if(!$DEBUG){
//discard the postfix E
if(strstr($tmpDef,"keepHex-low"))
{
$oidwhere=getLevelWhere($oidStr);
$sql="select setTemplate_2 from OBJ_$sysTypeNo.paramConf where $oidwhere ";
$res=@mysqli_query($pubConn,$sql);
$row=@mysqli_fetch_array($res);
$split=explode("[unit]",$row[0]);
$tmplen=sizeof($split);
//only one unit
//if($tmplen == 2)
{
$split2=explode("keepHex-low-",$row[0]);
$repl=substr($split2[1],0,1);
$lastValue=str_replace($repl," ",$lastValue);
}
}
if(strlen(trim($lastValue))<=0)
$lastValue="--";
echo "";
exit();
}else{
echo "
lastValue = $lastValue ";
}
}//end of if($set == 1)
//=======================Show GUI ========================
?>