Пример #1
0
		/// <summary>
		/// Returns the byte size of a POI if it was serialised
		/// </summary>
		/// <param name="poi">The POI</param>
		/// <returns>The byte size of the POI if serialised</returns>
		private Int32 GetPOISize(POI poi) {
			Int32 iReturn = 0;
			if(String.IsNullOrEmpty(poi.ExtendedData)) {
				iReturn += SimplePOIStructSize + poi.Name.Length;
			}
			else {
				iReturn += ExendedPOIStructSize + poi.Name.Length + poi.ExtendedData.Length;
			}
			
			if(!String.IsNullOrEmpty(poi.Telephone)) {
				iReturn += poi.Telephone.Length + 1;
			}
			return iReturn;
		}
Пример #2
0
		/// <summary>
		/// Serailises a TomTom simple POI into a byte stream
		/// </summary>
		/// <param name="Rec">The TomTom POI record to serialise</param>
		/// <returns>The serialised byte stream</returns>
		private byte[] SerialiseSimplePOI(POI Rec) {
			int Pos = 0;
			int Size = SimplePOIStructSize + Rec.Name.Length;
			
			if(!String.IsNullOrEmpty(Rec.Telephone)) {
				Size += Rec.Telephone.Length + 1;
			}
			
			byte[] bReturn = new byte[Size];
			bReturn[Pos] = 0x02;
			Pos++;
			ConvertToLEBytes(Size).CopyTo(bReturn, Pos);
			Pos += 4;
			ConvertToLEBytes((Int32)(Rec.Long * 100000)).CopyTo(bReturn, Pos);
			Pos += 4;
			ConvertToLEBytes((Int32)(Rec.Lat * 100000)).CopyTo(bReturn, Pos);
			Pos += 4;
			Encoding.ASCII.GetBytes(Rec.Name).CopyTo(bReturn, Pos);
			Pos += Rec.Name.Length;
			
			if(!String.IsNullOrEmpty(Rec.Telephone)) {
				bReturn[Pos] = 0x3E;
				Pos += 1;
				Encoding.ASCII.GetBytes(Rec.Telephone).CopyTo(bReturn, Pos);
				Pos += Rec.Telephone.Length;
			}
			bReturn[Pos] = 0x00;
			return bReturn;
		}
Пример #3
0
		private POI ConvertToPOI(byte[] POIData) {
			POI ReturnPOI = new POI();
			int Pos = 0;
			byte[] BinInt32 = new byte[4];
			byte ReadByte = 0x01;
			
			//Get longitude
			BinInt32[Pos] = POIData[Pos + 5];
			BinInt32[Pos + 1] = POIData[Pos + 6];
			BinInt32[Pos + 2] = POIData[Pos + 7];
			BinInt32[Pos + 3] = POIData[Pos + 8];
			ReturnPOI.Long = (double)BitConverter.ToInt32(BinInt32, 0) / (double)100000;

			//Get latitude
			BinInt32[Pos] = POIData[Pos + 9];
			BinInt32[Pos + 1] = POIData[Pos + 10];
			BinInt32[Pos + 2] = POIData[Pos + 11];
			BinInt32[Pos + 3] = POIData[Pos + 12];
			ReturnPOI.Lat = (double)BitConverter.ToInt32(BinInt32, 0) / (double)100000;
			
			//Get Name
			Pos = Pos + 13;
			ReadByte = POIData[Pos];
			while(ReadByte != 0x00) {
				ReturnPOI.Name += (char)ReadByte;
				Pos++;
				ReadByte = POIData[Pos];
			}
			
			//DOes the name contain a phone number?
			if(ReturnPOI.Name.Contains('>')) {
				int GTPos = ReturnPOI.Name.LastIndexOf('>');
				ReturnPOI.Telephone = ReturnPOI.Name.Substring(GTPos + 1);
				ReturnPOI.Name = ReturnPOI.Name.Substring(0, GTPos);
			}
			
			//If this is an extended POI, then read the extended data
			if(POIData[0] == (byte)POIRecordTypes.ExtendedPOI) {
				Pos++;
				ReadByte = POIData[Pos];
				while (ReadByte != 0x00) {
					ReturnPOI.ExtendedData += (char)ReadByte;
					Pos++;
					ReadByte = POIData[Pos];
				}
			}
			
			return ReturnPOI;
		}