Exemplo n.º 1
0
function formatGPSData($type, $tag, $intel, $data)
{
    if ($type == "ASCII") {
        if ($tag == "0001" || $tag == "0003") {
            // Latitude Reference, Longitude Reference
            $data = $data[1] == $data[2] && $data[1] == $data[3] ? $data[0] : $data;
        }
    } else {
        if ($type == "URATIONAL" || $type == "SRATIONAL") {
            $data = bin2hex($data);
            if ($intel == 1) {
                $data = intel2Moto($data);
            }
            if ($intel == 1) {
                $top = hexdec(substr($data, 8, 8));
            } else {
                $top = hexdec(substr($data, 0, 8));
            }
            //motorola stores them top-bottom
            if ($intel == 1) {
                $bottom = hexdec(substr($data, 0, 8));
            } else {
                $bottom = hexdec(substr($data, 8, 8));
            }
            //motorola stores them top-bottom
            if ($type == "SRATIONAL" && $top > 2147483647) {
                $top = $top - 4294967296.0;
            }
            //this makes the number signed instead of unsigned
            if ($tag == "0002" || $tag == "0004") {
                //Latitude, Longitude
                if ($intel == 1) {
                    $seconds = GPSRational(substr($data, 0, 16), $intel);
                    $hour = GPSRational(substr($data, 32, 16), $intel);
                } else {
                    $hour = GPSRational(substr($data, 0, 16), $intel);
                    $seconds = GPSRational(substr($data, 32, 16), $intel);
                }
                $minutes = GPSRational(substr($data, 16, 16), $intel);
                $data = $hour + $minutes / 60 + $seconds / 3600;
            } else {
                if ($tag == "0007") {
                    //Time
                    $seconds = GPSRational(substr($data, 0, 16), $intel);
                    $minutes = GPSRational(substr($data, 16, 16), $intel);
                    $hour = GPSRational(substr($data, 32, 16), $intel);
                    $data = $hour . ":" . $minutes . ":" . $seconds;
                } else {
                    if ($bottom != 0) {
                        $data = $top / $bottom;
                    } else {
                        if ($top == 0) {
                            $data = 0;
                        } else {
                            $data = $top . "/" . $bottom;
                        }
                    }
                    if ($tag == "0006") {
                        $data .= 'm';
                    }
                }
            }
        } else {
            if ($type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") {
                $data = bin2hex($data);
                if ($intel == 1) {
                    $data = intel2Moto($data);
                }
                $data = hexdec($data);
            } else {
                if ($type == "UNDEFINED") {
                } else {
                    if ($type == "UBYTE") {
                        $data = bin2hex($data);
                        if ($intel == 1) {
                            $num = intel2Moto($data);
                        }
                        if ($tag == "0000") {
                            // VersionID
                            $data = hexdec(substr($data, 0, 2)) . "." . hexdec(substr($data, 2, 2)) . "." . hexdec(substr($data, 4, 2)) . "." . hexdec(substr($data, 6, 2));
                        } else {
                            if ($tag == "0005") {
                                // Altitude Reference
                                if ($data == "00000000") {
                                    $data = 'Above Sea Level';
                                } else {
                                    if ($data == "01000000") {
                                        $data = 'Below Sea Level';
                                    }
                                }
                            }
                        }
                    } else {
                        $data = bin2hex($data);
                        if ($intel == 1) {
                            $data = intel2Moto($data);
                        }
                    }
                }
            }
        }
    }
    return $data;
}
Exemplo n.º 2
0
function formatGPSData($type,$tag,$intel,$data) {

	if($type=="ASCII") {
		
		
	} else if($type=="URATIONAL" || $type=="SRATIONAL") {
		$data = bin2hex($data);
		if($intel==1) $data = intel2Moto($data);
		
		if($intel==1) $top = hexdec(substr($data,8,8)); 	//intel stores them bottom-top
		else  $top = hexdec(substr($data,0,8));				//motorola stores them top-bottom
		
		if($intel==1) $bottom = hexdec(substr($data,0,8));	//intel stores them bottom-top
		else  $bottom = hexdec(substr($data,8,8));			//motorola stores them top-bottom
		
		if($type=="SRATIONAL" && $top>2147483647) $top = $top - 4294967296;		//this makes the number signed instead of unsigned
		
		if($tag=="0002" || $tag=="0004") { //Latitude
		
			$seconds = GPSRational(substr($data,0,16),$intel);
			$minutes = GPSRational(substr($data,16,16),$intel);
			$hour = GPSRational(substr($data,32,16),$intel);
			
			$data = $hour+$minutes/60+$seconds/3600;
		} else if($tag=="0007") { //Time
			$seconds = GPSRational(substr($data,0,16),$intel);
			$minutes = GPSRational(substr($data,16,16),$intel);
			$hour = GPSRational(substr($data,32,16),$intel);
			
			$data = $hour.":".$minutes.":".$seconds;
		} else {
			if($bottom!=0) $data=$top/$bottom;
			else if($top==0) $data = 0;
			else $data=$top."/".$bottom;
		}
	} else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
		$data = bin2hex($data);
		if($intel==1) $data = intel2Moto($data);
		$data=hexdec($data);
		
		
	} else if($type=="UNDEFINED") {
		
		
		
	} else if($type=="UBYTE") {
		$data = bin2hex($data);
		if($intel==1) $num = intel2Moto($data);
			
		if($tag=="0000") { //Latitude
			$data =  hexdec(substr($data,0,2)).".". hexdec(substr($data,2,2)).".". hexdec(substr($data,4,2)).".". hexdec(substr($data,6,2));
		} 
		
	} else {
		$data = bin2hex($data);
		if($intel==1) $data = intel2Moto($data);
	}
	
	return $data;
}