public void Process(GLPBinaryPictureData picturePackage, NmeaConnection conn) { if (picturePackage == null) { throw new ArgumentNullException("Picture package is null."); } if (conn == null) { throw new ArgumentNullException("Connection is null."); } ISavePicture savePicture = new SavePicture(); string strPictureName = picturePackage.RTC.ToString("s", CultureInfo.InvariantCulture); int iD = conn.Device.ID; if (picturePackage.PackageIndex == 1) { long? lTrackDataID = null; TrackPoint trackPoint = this.m_ResolvePosition(conn.Device.DeviceOwnerID, picturePackage.RTC); if (trackPoint != null) { lTrackDataID = new long?(trackPoint.ID); } savePicture.NewPicture(picturePackage.RTC.ToString("s", CultureInfo.InvariantCulture), iD, picturePackage.RTC, lTrackDataID, (int)picturePackage.TotalPackages, 0, null); } savePicture.SavePictureData(strPictureName, iD, (int)picturePackage.PackageIndex, picturePackage.PictureData); }
/// <summary> /// Next report. Or null if there is none. /// </summary> /// <returns></returns> public GLPBase NextReport() { GLPBase iBase = null; bool sendAck = false; if (m_bHeaderFound == false && m_cirBuf.UsedLength >= 14) { // Looking for header. byte[] arrPackets = m_cirBuf.Peek(0, 14); m_arrDeviceID = new byte[8]; // Device ID Array.Copy(arrPackets, m_arrDeviceID, 8); // Packet type m_iPacketType = arrPackets[8]; // Packet count m_iPacketCount = arrPackets[9]; // Firmware version BitParser bp = new BitParser(2, true, false); bp.WriteData(arrPackets, 10, 2); int build = bp.ReadIntX(6); int major = bp.ReadIntX(7); int minor = bp.ReadIntX(3); m_FirmwareVersion = minor + "." + major + "." + build; ushort ackAndLength = BitConverter.ToUInt16(arrPackets, 12); if ((ackAndLength & 0x8000) > 0) { sendAck = true; } else { sendAck = false; } m_iPacketLength = ackAndLength & (ushort)0x7FFF; if (m_cirBuf.UsedLength >= m_iPacketLength) { byte[] CRC = new byte[2]; byte[] packet = m_cirBuf.Peek(0, m_iPacketLength); GetCRC(packet, ref CRC); if (CRC[0] == packet[packet.Length - 2] && CRC[1] == packet[packet.Length - 1]) { m_bHeaderFound = true; m_iPacketsProcessed = 0; m_cirBuf.Seek(14); } else { m_bHeaderFound = false; m_cirBuf.Clear(); } } } if (m_bHeaderFound) { byte[] arrPackets = m_cirBuf.Peek(0, m_cirBuf.UsedLength); if (m_iPacketType == 0) { iBase = new GLPLogin(m_arrDeviceID, arrPackets); //iBase.AddStatus("FirmwareVersion", m_FirmwareVersion); iBase.loginPacket = true; iBase.sendAck = sendAck; } if (m_iPacketType == 1) { iBase = new GLPReport(m_arrDeviceID, arrPackets); iBase.AddStatus("FirmwareVersion", m_FirmwareVersion); m_iPacketsProcessed++; // Forward to next packet start. m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType == 0x20) { iBase = new GLPTerminal(m_arrDeviceID, arrPackets); m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType == 0x30) { iBase = new GLPBinaryPictureData(m_arrDeviceID, arrPackets); m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType >= 0xF0 && m_iPacketType <= 0xFF) { iBase = new GLPLogin(m_arrDeviceID, arrPackets); m_cirBuf.Seek(m_iPacketLength - 14); //bo nie wiemy jaka jest dlugosc m_bHeaderFound = false; iBase.loginPacket = true; iBase.sendAck = sendAck; return(iBase); } if (m_iPacketsProcessed >= m_iPacketCount || iBase.parseError) { // Forward to next packet start (jump CRC). if (iBase.parseError) { m_cirBuf.Clear(); } else { m_cirBuf.Seek(2); } m_bHeaderFound = false; } } return(iBase); }