private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { BitStream con = new BitStream(new byte[12]); byte[] bs = con.getValueArray(4097); string value = HexAscii.ConvertToHexAsciiFromBytes(bs); //con.parseBitString("100000000001"); //value = con.ToString(); int val = 0; //control word val = 0; con.insertIntoArray(val, 0, 4); //messagetype val = 3; con.insertIntoArray(val, 4, 3); //signo val = 1; con.insertIntoArray(val, 7, 1); //grados val = 24; con.insertIntoArray(val, 8, 11); //minutos val = 6; con.insertIntoArray(val, 16, 6); //segundos val = 31; con.insertIntoArray(val, 22, 6); //centesimas segundos val = 27; con.insertIntoArray(val, 28, 7); }
public static byte[] FromGSM7BitPacked(byte[] bytes) { BitStream stream = new BitStream(new byte[0]); byte[] bytesa = new byte[bytes.Length]; for (int i = 0, j = bytes.Length - 1; i < bytes.Length; i++, j--) bytesa[j] = bytes[i]; string stra = stream.ToBitString(bytesa); string strb = ""; for (int i = stra.Length-1; (i/7) > 0; i -= 7) strb = string.Format("{0}0{1}", strb, stra.Substring(i - 6, 7)); stream.parseBitString(strb); byte[] bytese = stream.ToBytes(); return bytese; }
public static byte[] ToGSM7BitPacked(byte[] bytes) { BitStream stream = new BitStream(new byte[0]); string strb = stream.ToBitString(bytes); string strc = ""; for (int i = 1; i < strb.Length; i += 8) { strc = string.Format("{0}{1}", strb.Substring(i, 7), strc); } while (strc.Length % 8 > 0) strc = string.Format("{0}{1}", 0, strc); stream.parseBitString(strc); byte[] bytesd = stream.ToBytes(); byte[] bytese = new byte[bytesd.Length]; for (int i = 0, j = bytesd.Length - 1; i < bytesd.Length; i++, j--) bytese[j] = bytesd[i]; return bytese; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_CannedMessagesHash cannedMessageHash) { bool reslt = false; cannedMessageHash = new DataBlock_CannedMessagesHash(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); cannedMessageHash.blockType = stream.GetUint(offset, BlockTypeLen); cannedMessageHash.BlockType = (ICDBlockType)cannedMessageHash.blockType; offset += BlockTypeLen; cannedMessageHash.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; cannedMessageHash.BlockLengthBytes = stream.GetUint(offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; // uint tempUint = 0; byte[] tempBytes = new byte[0]; for (int j = 0; j < 4; j++) { tempUint = stream.GetUint(offset, 4 * 8); //un uint son 4 bytes o sea 32 bits offset += 4 * 8; tempBytes = DataBlock_CannedMessagesHash.GetBytes(tempUint); for (int i = 0; i < tempBytes.Length; i++) cannedMessageHash.Hash[(j * 4) + i] = tempBytes[i]; } reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_SynchronisationEmergencyDestination emergencyDestination) { bool reslt = false; emergencyDestination = new DataBlock_SynchronisationEmergencyDestination(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); emergencyDestination.blockType = stream.GetUint(offset, BlockTypeLen); emergencyDestination.BlockType = (ICDBlockType)emergencyDestination.blockType; offset += BlockTypeLen; emergencyDestination.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (emergencyDestination.BlockLengthIndicator == 0) { emergencyDestination.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { emergencyDestination.BlockLengthBytes = stream.GetUint(offset, DataBlock_Synchronisation.BlockLengthExtendedBytesLen); offset += DataBlock_Synchronisation.BlockLengthExtendedBytesLen; } emergencyDestination.dataType = stream.GetUint(offset, DataTypeLen); emergencyDestination.DataType = (SynchronisationDataType)emergencyDestination.dataType; offset += DataTypeLen; reslt = DataBlock_EmergencyDestination.TryParse(buff, offset, out emergencyDestination.data); } catch (Exception ex) { reslt = false; } return reslt; }
public override byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[DiagnosticsLenBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (BlockLengthIndicator == 0) { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } stream.insertIntoArray((int)BatteryVoltage, offset, BatteryVoltageLen); offset += BatteryVoltageLen; stream.insertIntoArray((int)ChargerStatus, offset, ChargerStatusLen); offset += ChargerStatusLen; stream.insertIntoArray((int)AccumulatorRange, offset, AccumulatorRangeLen); offset += AccumulatorRangeLen; stream.insertIntoArray((int)VisibleGPSSatellites, offset, VisisbleGPSSatellitesLen); offset += VisisbleGPSSatellitesLen; byte[] tempBytes = stream.ToBytes(); byte[] FreeTextBytes = FreeText.ToBytes(); offset /= 8; for (int i = 0; i < FreeTextBytes.Length; i++) { if ((i + offset) >= tempBytes.Length) break; tempBytes[i + offset] = FreeTextBytes[i]; } return tempBytes; }
public override byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[DeviceIdentifierLenBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (BlockLengthIndicator == 0) { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } offset /= 8; byte[] tempBytes = stream.ToBytes(); byte[] FreeTextBytes = FreeText.ToBytes(); for (int i = 0; i < FreeTextBytes.Length; i++) { if ((i + offset) >= tempBytes.Length) break; tempBytes[i + offset] = FreeTextBytes[i]; } return tempBytes; }
public override byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[DataBlockCircleLenBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; stream.insertIntoArray((int)AlertWhenCrossed, offset, AlertWhenCrossedLen); offset += AlertWhenCrossedLen; stream.insertIntoArray((int)FenceHysteresisUnits, offset, FenceHysteresisUnitsLen); offset += FenceHysteresisUnitsLen; stream.insertIntoArray((int)FenceHysteresis, offset, FenceHysteresisLen); offset += FenceHysteresisLen; stream.insertIntoArray((int)FenceProximityUnits, offset, FenceProximityUnitsLen); offset += FenceProximityUnitsLen; stream.insertIntoArray((int)FenceProximity, offset, FenceProximityLen); offset += FenceProximityLen; stream.insertIntoArray((int)RefreshRateInMinutes, offset, RefreshRateInMinutesLen); offset += RefreshRateInMinutesLen; stream.insertIntoArray((int)LatitudeMinutes, offset, LatitudeMinutesLen); offset += LatitudeMinutesLen; stream.insertIntoArray((int)LatitudeMinutesDecimal, offset, LatitudeMinutesDecimalLen); offset += LatitudeMinutesDecimalLen; stream.insertIntoArray((int)LongitudeHemisphere, offset, LongitudeHemisphereLen); offset += LongitudeHemisphereLen; stream.insertIntoArray((int)LongitudeDegrees, offset, LongitudeDegreesLen); offset += LongitudeDegreesLen; stream.insertIntoArray((int)LongitudeMinutes, offset, LongitudeMinutesLen); offset += LongitudeMinutesLen; stream.insertIntoArray((int)LongitudeMinutesDecimal, offset, LongitudeMinutesDecimalLen); offset += LongitudeMinutesDecimalLen; stream.insertIntoArray((int)RadiusMeasurement, offset, RadiusMeasurementLen); offset += RadiusMeasurementLen; stream.insertIntoArray((int)RadiusLength, offset, RadiusLengthLen); offset += RadiusLengthLen; stream.insertIntoArray((int)Spare, offset, SpareLen); offset += SpareLen; return stream.ToBytes(); }
//hacete este public override byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[CannedMessagesHashLenBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; byte[] tempBytes = stream.ToBytes(); offset /= 8; for (int i = 0; i < Hash.Length; i++) { if ((i + offset) >= tempBytes.Length) break; tempBytes[i + offset] = Hash[i]; } return tempBytes; }
public static bool TryParse(byte[] buff, int baseoffset, out _FreeText freeText) { freeText = new _FreeText(); bool resp = false; try { int offset = baseoffset; BitStream stream = new BitStream(buff); freeText.FreeTextLengthIndicator = stream.GetUint(offset, freeText.FreeTextLengthIndicatorLen); offset += freeText.FreeTextLengthIndicatorLen; //la longitud es 7 bits if (freeText.FreeTextLengthIndicator == 0) freeText.FreeTextLengthLen = 7; else freeText.FreeTextLengthLen = 15; freeText.FreeTextLength = stream.GetUint(offset, freeText.FreeTextLengthLen); offset += freeText.FreeTextLengthLen; //repetir freeText.DecodeTextIndicator = stream.GetUint(offset, freeText.FreeTextLengthIndicatorLen); offset += freeText.FreeTextLengthIndicatorLen; int rest = 1; if (freeText.DecodeTextIndicator == 0) freeText.DecodeTextLengthLen = 7; else { freeText.DecodeTextLengthLen = 15; rest = 2; } freeText.DecodeTextLength = stream.GetUint(offset, (int)freeText.DecodeTextLengthLen); offset += freeText.FreeTextLengthLen; // offset = ((int)offset / 8); freeText.BytesText = new byte[freeText.FreeTextLength - rest]; for (int i = 0; i < freeText.FreeTextLength; i++, offset++) { if (offset < buff.Length) { freeText.BytesText[i] = buff[offset]; } } resp = true; } catch (Exception ex) { resp = false; } return resp; }
public byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[HeaderLenBytes]); stream.insertIntoArray((int)ProtocolType, offset, ProtocolTypeLen); offset += ProtocolTypeLen; stream.insertIntoArray((int)ProtocolVersionNumber, offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; stream.insertIntoArray((int)MOMessageType, offset, MOMessageTypeLen); offset += MOMessageTypeLen; stream.insertIntoArray((int)Timestamp, offset, TimestampLen); offset += TimestampLen; stream.insertIntoArray((int)EmergencyFlag, offset, EmergencyFlagLen); offset += EmergencyFlagLen; return stream.ToBytes(); }
public static bool TryParse(byte[] buff, int baseoffset, out ICDMOMessageReduceHeader rheader) { rheader = new ICDMOMessageReduceHeader(); bool reslt = false; try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); rheader.protocolType = stream.GetUint(offset, ProtocolTypeLen); if (rheader.protocolType == 102) rheader.ProtocolType = ICDProtocolType.p102; offset += ProtocolTypeLen; rheader.ProtocolVersionNumber = stream.GetUint(offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; rheader.MOMessageType = stream.GetUint(offset, MOMessageTypeLen); rheader.MessageType = (ICDMOMessageType)rheader.MOMessageType; // continuar ... offset += MOMessageTypeLen; rheader.Timestamp = stream.GetUint(offset, TimestampLen); offset += TimestampLen; rheader.EmergencyFlag = stream.GetUint(offset, EmergencyFlagLen); reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
//The message body for a Mobile Originated message consists of zero or more Data Blocks. Some message types have mandatory Data Blocks. Optionally, additional data blocks may be included for any message type. public static bool TryParse(byte[] buff, int offset, ICDMOPacket packet1, out ICDMOPacket packet) { bool flag = false; bool reslt = false; packet = packet1; packet.body = new ICDMOMessageBody(); ICDMOMessageType type = ICDMOMessageType.Unknown; if (packet.header != null) type = packet.header.MessageType; else if (packet.rheader != null) type = packet.rheader.MessageType; int boffset = offset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); uint blockType = 0; if (packet.header != null) { // blockType = stream.GetUint(ICDMessageStandardHeader.HeaderLen, DataBlock_Location.BlockTypeLen); boffset = ICDMOMessageStandardHeader.HeaderLen; } else if (packet.rheader != null) { // blockType = stream.GetUint(ICDMessageReduceHeader.HeaderLen, DataBlock_ReducedLocation.BlockTypeLen); boffset = ICDMOMessageReduceHeader.HeaderLen; } while (boffset < buff.Length * 8 && flag == false) { blockType = stream.GetUint(boffset, ICDDataBlock.BlockTypeLen); switch (blockType) { case 0: DataBlock_Location location; if (DataBlock_Location.TryParse(buff, boffset, out location)) { packet.body.datablocks.Add(location); boffset += DataBlock_Location.LocationLenBytes * 8; } break; case 0x01: DataBlock_FreeText freetext; if (DataBlock_FreeText.TryParse(buff, boffset, out freetext)) { packet.body.datablocks.Add(freetext); boffset += DataBlock_FreeText.BlockTypeLen * 8; } break; case 0x0E: int isReduced = 0; DataBlock_ReducedLocation rlocation; if (DataBlock_ReducedLocation.TryParse(buff, boffset, out rlocation, isReduced)) { //DataBlock_ReducedLocation.ToBytes(isReduced, rlocation); packet.body.datablocks.Add(rlocation); boffset += DataBlock_ReducedLocation.ReducedLocationLenBytes * 8; } break; case 0x34: isReduced = 1; DataBlock_ReducedLocation rminlocation; if (DataBlock_ReducedLocation.TryParse(buff, ICDMOMessageReduceHeader.HeaderLen, out rminlocation, isReduced)) { packet.body.datablocks.Add(rminlocation); boffset += DataBlock_ReducedLocation.ReducedLocationLenBytes * 8; } break; case 0x0a: //int isReduced = 0; DataBlock_PhoneSettings phonesettings; if (DataBlock_PhoneSettings.TryParse(buff, boffset, out phonesettings)) { //DataBlock_ReducedLocation.ToBytes(isReduced, rlocation); packet.body.datablocks.Add(phonesettings); boffset += phonesettings.PhoneSettingsLenBytes * 8; } break; case 0x0c: //int isReduced = 0; DataBlock_CannedMessagesHash cannedMessageHash; if (DataBlock_CannedMessagesHash.TryParse(buff, boffset, out cannedMessageHash)) { //DataBlock_ReducedLocation.ToBytes(isReduced, rlocation); packet.body.datablocks.Add(cannedMessageHash); boffset += DataBlock_CannedMessagesHash.CannedMessagesHashLenBytes * 8; } break; case 0x10: //int isReduced = 0; DataBlock_DistributionListHash distributionListHash; if (DataBlock_DistributionListHash.TryParse(buff, boffset, out distributionListHash)) { //DataBlock_ReducedLocation.ToBytes(isReduced, rlocation); packet.body.datablocks.Add(distributionListHash); boffset += DataBlock_DistributionListHash.DistributionListHashLenBytes * 8; } break; case 0x12: //int isReduced = 0; DataBlock_HandsetFwHwVersion handsetFirmwareHardwareVersion; if (DataBlock_HandsetFwHwVersion.TryParse(buff, boffset, out handsetFirmwareHardwareVersion)) { //DataBlock_ReducedLocation.ToBytes(isReduced, rlocation); packet.body.datablocks.Add(handsetFirmwareHardwareVersion); boffset += handsetFirmwareHardwareVersion.HandsetFwHwVersionLenBytes * 8; } break; case 0x03: while (boffset < buff.Length * 8) { DataBlock_Synchronisation synchronisation; if (DataBlock_Synchronisation.TryParse(buff, boffset, out synchronisation)) { packet.body.datablocks.Add(synchronisation); boffset += synchronisation.SynchronisationLenBytes * 8; } } break; case 0x09: DataBlock_PortalStatus portalStatus; if (DataBlock_PortalStatus.TryParse(buff, boffset, out portalStatus)) { packet.body.datablocks.Add(portalStatus); boffset += portalStatus.PortalStatusLenBytes * 8; } break; case 0x0d: DataBlock_PortalProviderInformation portalProviderInformation; if (DataBlock_PortalProviderInformation.TryParse(buff, boffset, out portalProviderInformation)) { packet.body.datablocks.Add(portalProviderInformation); boffset += portalProviderInformation.PortalProviderInformationLenBytes * 8; } break; case 0x02: DataBlock_Recipient recipient; if (DataBlock_Recipient.TryParse(buff, boffset, out recipient)) { packet.body.datablocks.Add(recipient); boffset += recipient.RecipientLenBytes * 8; } break; case 0x04: DataBlock_DeviceIdentifier deviceIdentifier; if (DataBlock_DeviceIdentifier.TryParse(buff, boffset, out deviceIdentifier)) { packet.body.datablocks.Add(deviceIdentifier); boffset += deviceIdentifier.DeviceIdentifierLenBytes * 8; } break; case 0x05: DataBlock_Diagnostics diagnostics; if (DataBlock_Diagnostics.TryParse(buff, boffset, out diagnostics)) { packet.body.datablocks.Add(diagnostics); boffset += diagnostics.DiagnosticsLenBytes * 8; } break; case 0x06: DataBlock_Sender sender; if (DataBlock_Sender.TryParse(buff, boffset, out sender)) { packet.body.datablocks.Add(sender); boffset += sender.SenderLenBytes * 8; } break; case 0x07: DataBlock_Circle circle; if (DataBlock_Circle.TryParse(buff, boffset, out circle)) { packet.body.datablocks.Add(circle); boffset += (int)circle.BlockLengthBytes * 8; } break; //POLYGON// case 0x08: DataBlock_Polygon polygon; if (DataBlock_Polygon.TryParse(buff, boffset, out polygon)) { packet.body.datablocks.Add(polygon); boffset += (int)polygon.BlockLengthBytes * 8; } break; case 0x11: DataBlock_GeofenceStatus geofenceStatus; if (DataBlock_GeofenceStatus.TryParse(buff, boffset, out geofenceStatus)) { packet.body.datablocks.Add(geofenceStatus); boffset += (int)geofenceStatus.BlockLengthBytes * 8; } break; case 0x0F: DataBlock_CannedMessageIdentifier cannedmessage; if (DataBlock_CannedMessageIdentifier.TryParse(buff, boffset, out cannedmessage)) { packet.body.datablocks.Add(cannedmessage); boffset += (int)cannedmessage.BlockLengthBytes * 8; } break; case 0x17: DataBlock_MessageIdentifier messageIdentifier; if (DataBlock_MessageIdentifier.TryParse(buff, boffset, out messageIdentifier)) { packet.body.datablocks.Add(messageIdentifier); boffset += (int)messageIdentifier.BlockLengthBytes * 8; } break; default: flag = true; break; } } /* case ICDMOMessageType.UserExtensions: break; case ICDMOMessageType.Reserved: break; */ //} reslt = true; return reslt; }
public override byte[] ToBytes() { int offset = 0; byte[] array = new byte[0]; array = data.ToBytes(SynchronisationLenBytes); BitStream stream = new BitStream(new byte[SynchronisationLenBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (BlockLengthIndicator == 0) { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } stream.insertIntoArray((int)dataType, offset, DataTypeLen); offset += DataTypeLen; byte[] resp = stream.ToBytes(); int boffset = offset / 8; resp = stream.ToBytes(); byte[] tempBytes = array; resp[boffset] = (byte)array.Length; boffset++; for (int i = 0; i < tempBytes.Length; i++) { if ((i + boffset) >= resp.Length) break; resp[i + boffset] = tempBytes[i]; } return resp; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_SynchronisationReportingFrequencyRate reportingFrequency) { bool reslt = false; reportingFrequency = new DataBlock_SynchronisationReportingFrequencyRate(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); reportingFrequency.blockType = stream.GetUint(offset, BlockTypeLen); reportingFrequency.BlockType = (ICDBlockType)reportingFrequency.blockType; offset += BlockTypeLen; reportingFrequency.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (reportingFrequency.BlockLengthIndicator == 0) { reportingFrequency.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { reportingFrequency.BlockLengthBytes = stream.GetUint(offset, DataBlock_Synchronisation.BlockLengthExtendedBytesLen); offset += DataBlock_Synchronisation.BlockLengthExtendedBytesLen; } reportingFrequency.dataType = stream.GetUint(offset, DataTypeLen); reportingFrequency.DataType = (SynchronisationDataType)reportingFrequency.dataType; offset += DataTypeLen; reslt = DataBlock_ReportingFrequencyRate.TryParse(buff, offset, out reportingFrequency.data); } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_SynchronisationProtocolType protocolType) { bool reslt = false; protocolType = new DataBlock_SynchronisationProtocolType(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); protocolType.blockType = stream.GetUint(offset, BlockTypeLen); protocolType.BlockType = (ICDBlockType)protocolType.blockType; offset += BlockTypeLen; protocolType.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (protocolType.BlockLengthIndicator == 0) { protocolType.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { protocolType.BlockLengthBytes = stream.GetUint(offset, DataBlock_Synchronisation.BlockLengthExtendedBytesLen); offset += DataBlock_Synchronisation.BlockLengthExtendedBytesLen; } protocolType.dataType = stream.GetUint(offset, DataTypeLen); protocolType.DataType = (SynchronisationDataType)protocolType.dataType; offset += DataTypeLen; reslt = DataBlock_ProtocolType.TryParse(buff, offset, out protocolType.data); } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_CannedMessageIdentifier cannedMessageIdentifier) { bool reslt = false; cannedMessageIdentifier = new DataBlock_CannedMessageIdentifier(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); cannedMessageIdentifier.blockType = stream.GetUint(offset, BlockTypeLen); cannedMessageIdentifier.BlockType = (ICDBlockType)cannedMessageIdentifier.blockType; offset += BlockTypeLen; cannedMessageIdentifier.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (cannedMessageIdentifier.BlockLengthIndicator == 0) { cannedMessageIdentifier.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { cannedMessageIdentifier.BlockLengthBytes = stream.GetUint(offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } cannedMessageIdentifier.CannedMessageNumber = stream.GetUint(offset, CannedMessageNumberLen); offset += CannedMessageNumberLen; cannedMessageIdentifier.cannedMessageCRC = stream.GetUint(offset, CannedMessageCRCLen); offset += CannedMessageCRCLen; try { Encoding unicode = Encoding.Unicode; Encoding utf8 = Encoding.UTF8; string s = "I have achieved my objective"; //string s = "123456789"; //var barray = GsmUtils.ToGSM7BitPacked(s); // byte[] array = HexAscii.ConvertToBytes(barray); byte[] array = HexAscii.ConvertToBytes("1C49103A6C2F83C26374BA6C2F9341ED3CE82D5697C7F4B4BD0C"); //byte[] barray = GetBytes(s); //1C49103A6C2F83C26374BA6C2F9341ED3CE82D5697C7F4B4BD0C crc_32c crc32 = new crc_32c(); uint crcVar = 0; /*ASCII*/ //array = Encoding.Convert(unicode, utf8, array); crcVar = crc32.crc_32c_init(); crcVar = crc32.crc_32c_update(array, array.Length, crcVar); crcVar = crc32.crc_32c_finalize(crcVar); /*UTF-16*/ //array = Encoding.Convert(unicode, utf8, array); //crcVar = crc32.crc_32c_init(); //crcVar = crc32.crc_32c_update_UTF_16(array, array.Length, crcVar); //crcVar = crc32.crc_32c_finalize(crcVar); //CRC (ASCII): 0xe3069283 //CRC (UTF-16): 0x9d7b210c string imei = "300015010444890"; byte[] imeib = GetBytes(imei); imeib = Encoding.Convert(unicode, utf8, imeib); crc_32c hash = new crc_32c(); uint hashvar = hash.toHash2(imeib, imeib.Length); } catch (Exception e) { } reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, uint BlockLengthBytes, out List<Point> listPoints) { bool reslt = false; listPoints = new List<Point>(); int points = 0; try { int offset = baseoffset; int tempOffset = 0; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); switch ((int)BlockLengthBytes) { case 24: points = 3; break; case 30: points = 4; break; case 36: points = 5; break; case 42: points = 6; break; case 48: points = 7; break; case 54: points = 8; break; } for (int i = 0; i < points; i++) { Point point = new Point(); if (tempOffset != 0) { offset = tempOffset; } point.LatitudeHemisphere = stream.GetUint(offset, LatitudeHemisphereLen); offset += LatitudeHemisphereLen; point.LatitudeDegrees = stream.GetUint(offset, LatitudeDegreesLen); offset += LatitudeDegreesLen; point.LatitudeMinutes = stream.GetUint(offset, LatitudeMinutesLen); offset += LatitudeMinutesLen; point.LatitudeMinutesDecimal = stream.GetUint(offset, LatitudeMinutesDecimalLen); offset += LatitudeMinutesDecimalLen; if (point.LatitudeHemisphere == 0) point.position.Latitude.setValue((int)point.LatitudeDegrees, (point.LatitudeMinutes + (double)point.LatitudeMinutesDecimal / 1000), "N"); else point.position.Latitude.setValue((int)point.LatitudeDegrees, (point.LatitudeMinutes + (double)point.LatitudeMinutesDecimal / 1000), "N"); point.LongitudeHemisphere = stream.GetUint(offset, LongitudeHemisphereLen); offset += LongitudeHemisphereLen; point.LongitudeDegrees = stream.GetUint(offset, LongitudeDegreesLen); offset += LongitudeDegreesLen; point.LongitudeMinutesDecimal = stream.GetUint(offset, LongitudeMinutesDecimalLen); offset += LongitudeMinutesDecimalLen; if (point.LongitudeHemisphere == 0) point.position.Longitude.setValue((int)point.LongitudeDegrees, (point.LongitudeMinutes + (double)point.LongitudeMinutesDecimal / 1000), "E"); else point.position.Longitude.setValue((int)point.LongitudeDegrees, (point.LongitudeMinutes + (double)point.LongitudeMinutesDecimal / 1000), "W"); tempOffset = offset; listPoints.Add(point); } reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public byte[] ToBytes(int lenPolygon, List<Point> listPoints) { int offset = 0; int tempOffset = 0; BitStream stream = new BitStream(new byte[lenPolygon]); foreach(Point p in listPoints) { if (tempOffset != 0) { offset = tempOffset; } stream.insertIntoArray((int)p.LatitudeHemisphere, offset, LatitudeHemisphereLen); offset += LatitudeHemisphereLen; stream.insertIntoArray((int)p.LatitudeDegrees, offset, LatitudeDegreesLen); offset += LatitudeDegreesLen; stream.insertIntoArray((int)p.LatitudeMinutes, offset, LatitudeMinutesLen); offset += LatitudeMinutesLen; stream.insertIntoArray((int)p.LatitudeMinutesDecimal, offset, LatitudeMinutesDecimalLen); offset += LatitudeMinutesDecimalLen; stream.insertIntoArray((int)p.LongitudeHemisphere, offset, LongitudeHemisphereLen); offset += LongitudeHemisphereLen; stream.insertIntoArray((int)p.LongitudeDegrees, offset, LongitudeDegreesLen); offset += LongitudeDegreesLen; stream.insertIntoArray((int)p.LongitudeMinutesDecimal, offset, LongitudeMinutesDecimalLen); offset += LongitudeMinutesDecimalLen; tempOffset = offset; } return stream.ToBytes(); }
public static bool TryParse(byte[] buff, int baseoffset, out ICDMOMessageStandardHeader header) { header = new ICDMOMessageStandardHeader(); bool reslt = false; try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); header.protocolType = stream.GetUint(offset, ProtocolTypeLen); if (header.protocolType == 102) header.ProtocolType = ICDProtocolType.p102; offset += ProtocolTypeLen; header.ProtocolVersionNumber = stream.GetUint(offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; header.LanguageIdentifierFirstLetter = stream.GetUint(offset, LanguageIdentifierFirstLetterLen); offset += LanguageIdentifierFirstLetterLen; header.LanguageIdentifierSecondLetter = stream.GetUint(offset, LanguageIdentifierSecondLetterLen); byte[] bytes = Encoding.ASCII.GetBytes("a"); bytes[0] += (byte)(header.LanguageIdentifierFirstLetter - 1); header.LanguageIdentifier = new string(Encoding.ASCII.GetChars(bytes)); bytes = Encoding.ASCII.GetBytes("a"); bytes[0] += (byte)(header.LanguageIdentifierSecondLetter - 1); header.LanguageIdentifier = string.Format("{0}{1}", header.LanguageIdentifier, new string(Encoding.ASCII.GetChars(bytes))); offset += LanguageIdentifierSecondLetterLen; header.MOMessageType = stream.GetUint(offset, MOMessageTypeLen); header.MessageType = (ICDMOMessageType)header.MOMessageType; offset += MOMessageTypeLen; header.SequenceNumber = stream.GetUint(offset, SequenceNumberLen); offset += SequenceNumberLen; header.TimestampUTCYear = stream.GetUint(offset, TimestampUTCYearLen); offset += TimestampUTCYearLen; header.TimestampUTCMonth = stream.GetUint(offset, TimestampUTCMonthLen); offset += TimestampUTCMonthLen; header.TimestampUTCDay = stream.GetUint(offset, TimestampUTCDayLen); offset += TimestampUTCDayLen; header.TimestampUTCHours = stream.GetUint(offset, TimestampUTCHoursLen); offset += TimestampUTCHoursLen; header.TimestampUTCMinutes = stream.GetUint(offset, TimestampUTCMinutesLen); offset += TimestampUTCMinutesLen; header.TimestampUTCSeconds = stream.GetUint(offset, TimestampUTCSecondsLen); offset += TimestampUTCSecondsLen; header.EmergencyFlag = stream.GetUint(offset, EmergencyFlagLen); offset += EmergencyFlagLen; header.Spare = stream.GetUint(offset, SpareLen); reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public byte[] ToBytes() { int offset = 0; byte[] buff = new byte[0]; BitStream stream = new BitStream(new byte[FreeTextLenBytes]); stream.insertIntoArray((int)FreeTextLengthIndicator, offset, FreeTextLengthIndicatorLen); offset += FreeTextLengthIndicatorLen; if (FreeTextLengthIndicator == 0) FreeTextLengthLen = 7; else FreeTextLengthLen = 15; stream.insertIntoArray((int)FreeTextLength, offset, FreeTextLengthLen); offset += FreeTextLengthLen; if (BytesText.Length >= 128) { stream.insertIntoArray((int)DecodeTextIndicator, offset, DecodeTextIndicatorLen); offset += DecodeTextIndicatorLen; //int rest = 1; if (DecodeTextIndicator == 0) DecodeTextLengthLen = 7; else { DecodeTextLengthLen = 15; //rest = 2; } stream.insertIntoArray((int)DecodeTextLength, offset, DecodeTextLengthLen); offset += DecodeTextLengthLen; } int boffset = offset / 8; byte[] tempBytes = BytesText;//GsmUtils.ToGSM7BitPacked(FreeText); byte[] resp = new byte[boffset + tempBytes.Length]; stream.ToBytes().CopyTo(resp, 0); for (int i = 0; i < tempBytes.Length; i++) { if ((i + boffset) >= resp.Length) break; resp[i + boffset] = tempBytes[i]; } //byte[] len = new byte[1]; //len[0] = (byte)BytesText.Length; //len = HexAscii.ConvertToBytes(HexAscii.ConvertToHexAsciiFromBytes(len)); //byte[] array = new byte[tempBytes.Length + 1]; //len.CopyTo(array, 0); //tempBytes.CopyTo(array, len.Length); //byte[] resp = new byte[boffset + array.Length + 1]; //stream.ToBytes().CopyTo(resp, 0); //for (int i = 0; i < array.Length; i++) //{ // if ((i + boffset) >= resp.Length) // break; // resp[i + boffset] = array[i]; //} return resp; }
public override byte[] ToBytes() { int offset = 0; byte[] buff = new byte[0]; BitStream stream = new BitStream(new byte[BlockLengthBytes]); stream.insertIntoArray((int)blockType, offset, BlockTypeLen); offset += BlockTypeLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; stream.insertIntoArray((int)BlockLengthIndicator, offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; stream.insertIntoArray((int)BlockLengthBytes, offset, BlockLengthBytesLen); offset += BlockLengthBytesLen; stream.insertIntoArray((int)CannedMessageNumber, offset, CannedMessageNumberLen); offset += CannedMessageNumberLen; stream.insertIntoArray((int)CannedMessageNumber, offset, CannedMessageNumberLen); offset += CannedMessageNumberLen; buff = stream.ToBytes(); return buff; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_Circle dataBlockCircle) { bool reslt = false; dataBlockCircle = new DataBlock_Circle(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); dataBlockCircle.blockType = stream.GetUint(offset, BlockTypeLen); dataBlockCircle.BlockType = (ICDBlockType)dataBlockCircle.blockType; offset += BlockTypeLen; dataBlockCircle.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; dataBlockCircle.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; dataBlockCircle.AlertWhenCrossed = stream.GetUint(offset, AlertWhenCrossedLen); offset += AlertWhenCrossedLen; dataBlockCircle.FenceHysteresisUnits = stream.GetUint(offset, FenceHysteresisUnitsLen); offset += FenceHysteresisUnitsLen; dataBlockCircle.FenceHysteresis = stream.GetUint(offset, FenceHysteresisLen); offset += FenceHysteresisLen; dataBlockCircle.FenceProximityUnits = stream.GetUint(offset, FenceProximityUnitsLen); offset += FenceProximityUnitsLen; dataBlockCircle.FenceProximity = stream.GetUint(offset, FenceProximityLen); offset += FenceProximityLen; dataBlockCircle.RefreshRateInMinutes = stream.GetUint(offset, RefreshRateInMinutesLen); offset += RefreshRateInMinutesLen; dataBlockCircle.LatitudeHemisphere = stream.GetUint(offset, LatitudeHemisphereLen); offset += LatitudeHemisphereLen; dataBlockCircle.LatitudeDegrees = stream.GetUint(offset, LatitudeDegreesLen); offset += LatitudeDegreesLen; dataBlockCircle.LatitudeMinutes = stream.GetUint(offset, LatitudeMinutesLen); offset += LatitudeMinutesLen; dataBlockCircle.LatitudeMinutesDecimal = stream.GetUint(offset, LatitudeMinutesDecimalLen); offset += LatitudeMinutesDecimalLen; if (dataBlockCircle.LatitudeHemisphere == 0) dataBlockCircle.position.Latitude.setValue((int)dataBlockCircle.LatitudeDegrees, (dataBlockCircle.LatitudeMinutes + (double)dataBlockCircle.LatitudeMinutesDecimal / 1000), "N"); else dataBlockCircle.position.Latitude.setValue((int)dataBlockCircle.LatitudeDegrees, (dataBlockCircle.LatitudeMinutes + (double)dataBlockCircle.LatitudeMinutesDecimal / 1000), "N"); dataBlockCircle.LongitudeHemisphere = stream.GetUint(offset, LongitudeHemisphereLen); offset += LongitudeHemisphereLen; dataBlockCircle.LongitudeDegrees = stream.GetUint(offset, LongitudeDegreesLen); offset += LongitudeDegreesLen; dataBlockCircle.RefreshRateInMinutes = stream.GetUint(offset, RefreshRateInMinutesLen); offset += RefreshRateInMinutesLen; dataBlockCircle.LongitudeMinutesDecimal = stream.GetUint(offset, LongitudeMinutesDecimalLen); offset += LongitudeMinutesDecimalLen; if (dataBlockCircle.LongitudeHemisphere == 0) dataBlockCircle.position.Longitude.setValue((int)dataBlockCircle.LongitudeDegrees, (dataBlockCircle.LongitudeMinutes + (double)dataBlockCircle.LongitudeMinutesDecimal / 1000), "E"); else dataBlockCircle.position.Longitude.setValue((int)dataBlockCircle.LongitudeDegrees, (dataBlockCircle.LongitudeMinutes + (double)dataBlockCircle.LongitudeMinutesDecimal / 1000), "W"); dataBlockCircle.RadiusMeasurement = stream.GetUint(offset, RadiusMeasurementLen); offset += RadiusMeasurementLen; dataBlockCircle.RadiusLength = stream.GetUint(offset, RadiusLengthLen); offset += RadiusLengthLen; dataBlockCircle.Spare = stream.GetUint(offset, SpareLen); offset += SpareLen; reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[HeaderLenBytes]); stream.insertIntoArray((int)ProtocolType, offset, ProtocolTypeLen); offset += ProtocolTypeLen; stream.insertIntoArray((int)ProtocolVersionNumber, offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; stream.insertIntoArray((int)LanguageIdentifierFirstLetter, offset, LanguageIdentifierFirstLetterLen); offset += LanguageIdentifierFirstLetterLen; stream.insertIntoArray((int)LanguageIdentifierSecondLetter, offset, LanguageIdentifierSecondLetterLen); offset += LanguageIdentifierSecondLetterLen; stream.insertIntoArray((int)MOMessageType, offset, MOMessageTypeLen); offset += MOMessageTypeLen; stream.insertIntoArray((int)SequenceNumber, offset, SequenceNumberLen); offset += SequenceNumberLen; stream.insertIntoArray((int)TimeStamp.Year, offset, TimestampUTCYearLen); offset += TimestampUTCYearLen; stream.insertIntoArray((int)TimeStamp.Month, offset, TimestampUTCMonthLen); offset += TimestampUTCMonthLen; stream.insertIntoArray((int)TimeStamp.Day, offset, TimestampUTCDayLen); offset += TimestampUTCDayLen; stream.insertIntoArray((int)TimeStamp.Hour, offset, TimestampUTCHoursLen); offset += TimestampUTCHoursLen; stream.insertIntoArray((int)TimeStamp.Minute, offset, TimestampUTCMinutesLen); offset += TimestampUTCMinutesLen; stream.insertIntoArray((int)TimeStamp.Second, offset, TimestampUTCSecondsLen); offset += TimestampUTCSecondsLen; stream.insertIntoArray((int)EmergencyFlag, offset, EmergencyFlagLen); offset += EmergencyFlagLen; stream.insertIntoArray((int)Spare, offset, SpareLen); offset += SpareLen; return stream.ToBytes(); }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_DeviceIdentifier deviceIdentifier) { bool reslt = false; deviceIdentifier = new DataBlock_DeviceIdentifier(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); deviceIdentifier.blockType = stream.GetUint(offset, BlockTypeLen); deviceIdentifier.BlockType = (ICDBlockType)deviceIdentifier.blockType; offset += BlockTypeLen; deviceIdentifier.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (deviceIdentifier.BlockLengthIndicator == 0) { deviceIdentifier.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { deviceIdentifier.BlockLengthBytes = stream.GetUint(offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } reslt = _FreeText.TryParse(buff, offset, out deviceIdentifier.FreeText); reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int offset, ICDMTPacket packet1, out ICDMTPacket packet) { bool reslt = false; packet = packet1; packet.body = new ICDMTMessageBody(); ICDMTMessageType type = ICDMTMessageType.Unknown; type = packet.header.MessageType; int boffset = offset; BitStream stream = new BitStream(buff); uint blockType = 0; if (boffset == 0) { boffset = ICDMTMessageStandardHeader.HeaderLen; } blockType = stream.GetUint(boffset, ICDDataBlock.BlockTypeLen); switch (type) { case ICDMTMessageType.EmergencyAcknowledge: case ICDMTMessageType.EmergencyCancelRequest: case ICDMTMessageType.LocationPingRequest: case ICDMTMessageType.SystemTestResponseEndToEnd: case ICDMTMessageType.DiagnosticRequest: case ICDMTMessageType.ConfirmedCheckIn: case ICDMTMessageType.GeofenceCancel: case ICDMTMessageType.RequestDeviceIdentifier: break; case ICDMTMessageType.FreeText: while (boffset < buff.Length * 8) { blockType = stream.GetUint(boffset, ICDDataBlock.BlockTypeLen); switch (blockType) { case 0x01: DataBlock_FreeText freeText; if (DataBlock_FreeText.TryParse(buff, boffset, out freeText)) { packet.body.datablocks.Add(freeText); boffset += (int)freeText.FreeTextLenBytes * 8; } break; case 0x06: { DataBlock_Sender sender; if (DataBlock_Sender.TryParse(buff, boffset, out sender)) { packet.body.datablocks.Add(sender); boffset += (int)sender.SenderLenBytes * 8; } } break; } } break; case ICDMTMessageType.GeofenceActivate: while (boffset < buff.Length * 8) { blockType = stream.GetUint(boffset, ICDDataBlock.BlockTypeLen); switch (blockType) { case 0x08: DataBlock_Polygon polygon; if (DataBlock_Polygon.TryParse(buff, boffset, out polygon)) { packet.body.datablocks.Add(polygon); boffset += (int)polygon.BlockLengthBytes * 8; } break; case 0x07: DataBlock_Circle circle; if (DataBlock_Circle.TryParse(buff, boffset, out circle)) { packet.body.datablocks.Add(circle); boffset += (int)circle.BlockLengthBytes * 8; } break; } } break; case ICDMTMessageType.SynchroniseDataToDevice: while (boffset < buff.Length * 8) { DataBlock_Synchronisation synchronisation; if (DataBlock_Synchronisation.TryParse(buff, boffset, out synchronisation)) { packet.body.datablocks.Add(synchronisation); boffset += synchronisation.SynchronisationLenBytes * 8; } } break; case ICDMTMessageType.PortalStatusMessage: while (boffset < buff.Length * 8) { blockType = stream.GetUint(boffset, ICDDataBlock.BlockTypeLen); switch (blockType) { case 0x09: DataBlock_PortalStatus portalStatus; if (DataBlock_PortalStatus.TryParse(buff, boffset, out portalStatus)) { packet.body.datablocks.Add(portalStatus); boffset += portalStatus.PortalStatusLenBytes * 8; } break; case 0x0d: DataBlock_PortalProviderInformation portalProviderInformation; if (DataBlock_PortalProviderInformation.TryParse(buff, boffset, out portalProviderInformation)) { packet.body.datablocks.Add(portalProviderInformation); boffset += portalProviderInformation.PortalProviderInformationLenBytes * 8; } break; } } break; case ICDMTMessageType.Reserved://borrar? break; case ICDMTMessageType.UserExtensions: // borrar? break; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_Diagnostics diagnostics) { bool reslt = false; diagnostics = new DataBlock_Diagnostics(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); diagnostics.blockType = stream.GetUint(offset, BlockTypeLen); diagnostics.BlockType = (ICDBlockType)diagnostics.blockType; offset += BlockTypeLen; diagnostics.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (diagnostics.BlockLengthIndicator == 0) { diagnostics.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { diagnostics.BlockLengthBytes = stream.GetUint(offset, BlockLengthExtendedBytesLen); offset += BlockLengthExtendedBytesLen; } diagnostics.BatteryVoltage = stream.GetUint(offset, BatteryVoltageLen); offset += BatteryVoltageLen; diagnostics.ChargerStatus = stream.GetUint(offset, ChargerStatusLen); offset += ChargerStatusLen; diagnostics.AccumulatorRange = stream.GetUint(offset, AccumulatorRangeLen); offset += AccumulatorRangeLen; diagnostics.VisibleGPSSatellites = stream.GetUint(offset, VisisbleGPSSatellitesLen); offset += AccumulatorRangeLen; reslt = _FreeText.TryParse(buff, offset, out diagnostics.FreeText); reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public byte[] ToBytes() { int offset = 0; BitStream stream = new BitStream(new byte[HeaderLenBytes]); stream.insertIntoArray((int)ProtocolType, offset, ProtocolTypeLen); offset += ProtocolTypeLen; stream.insertIntoArray((int)ProtocolVersionNumber, offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; stream.insertIntoArray((int)messageType, offset, MTMessageTypeLen); offset += MTMessageTypeLen; stream.insertIntoArray((int)MessageIdentifier, offset, MessageIdentifierLen); offset += MessageIdentifierLen; return stream.ToBytes(); }
public static bool TryParse(byte[] buff, int baseoffset, out ICDMTMessageStandardHeader header) { header = new ICDMTMessageStandardHeader(); bool reslt = false; try { int offset = baseoffset; BitStream stream = new BitStream(buff); header.protocolType = stream.GetUint(offset, ProtocolTypeLen); offset += ProtocolTypeLen; header.ProtocolVersionNumber = stream.GetUint(offset, ProtocolVersionNumberLen); offset += ProtocolVersionNumberLen; header.messageType = stream.GetUint(offset, MTMessageTypeLen); header.MessageType = (ICDMTMessageType)header.messageType; offset += MTMessageTypeLen; header.MessageIdentifier = stream.GetUint(offset, MessageIdentifierLen); offset = MessageIdentifierLen; reslt = true; } catch (Exception ex) { reslt = false; } return reslt; }
public static bool TryParse(byte[] buff, int baseoffset, out DataBlock_SynchronisationDistributionList distributionList) { bool reslt = false; distributionList = new DataBlock_SynchronisationDistributionList(); try { int offset = baseoffset; net.Tesacom.GeneralUtilities.BitStream stream = new net.Tesacom.GeneralUtilities.BitStream(buff); distributionList.blockType = stream.GetUint(offset, BlockTypeLen); distributionList.BlockType = (ICDBlockType)distributionList.blockType; offset += BlockTypeLen; distributionList.BlockLengthIndicator = stream.GetUint(offset, BlockLengthIndicatorLen); offset += BlockLengthIndicatorLen; if (distributionList.BlockLengthIndicator == 0) { distributionList.BlockLengthBytes = stream.GetUint(offset, ICDDataBlock.BlockLengthBytesLen); offset += BlockLengthBytesLen; } else { distributionList.BlockLengthBytes = stream.GetUint(offset, DataBlock_Synchronisation.BlockLengthExtendedBytesLen); offset += DataBlock_Synchronisation.BlockLengthExtendedBytesLen; } distributionList.dataType = stream.GetUint(offset, DataTypeLen); distributionList.DataType = (SynchronisationDataType)distributionList.dataType; offset += DataTypeLen; if ((SynchronisationDataType)distributionList.dataType == SynchronisationDataType.DistributionlistClearAll) { reslt = true; } else { reslt = DataBlock_DistributionList.TryParse(buff, offset, out distributionList.data); } } catch (Exception ex) { reslt = false; } return reslt; }