MISB 0903 Converter Library  Version 2.02
Sample Code - MISB 0903 Converter Demo Application (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Diagnostics;
namespace STD0903WrDemoApp
{
static class Constants
{
public const uint NumberOfTargets = 10;
}
class Program
{
static void Main(string[] args)
{
try
{
// Create Converter
STD0903ConverterWr conv = new STD0903ConverterWr();
// Set Tag to 74 and do not generate a checksum
conv.ConfigureEncoder(74, false);
#region Sample 1. Read data from file and decode it to (fill VMTI_PacketWr)
// Read data
byte[] buf = System.IO.File.ReadAllBytes(@"data0903.bin");
// Decode packet
var pckt = conv.DecodeVmtiPacket(buf);
// Get Json
var json = conv.VmtiPacketToJson(pckt, true);
// Print
PrintVmtiString("Decoded file", conv, pckt);
#endregion
#region Sample 2. Fill VMTI_Packet parameters and encode it ( get a data buffer )
//Create VMTI Packet
VMTI_PacketWr pcktEnc = new VMTI_PacketWr();
// Fill Local Data Set
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.UNIX_Time_Stamp, DateTime.Now);
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.System_Name, "VMTI Test");
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.Source_Sensor, "EO Nose");
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.LDS_Version_Number, (ushort)3);
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.TotalNumberOfTargets, (uint)Constants.NumberOfTargets);
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.VideoFrameNumber, (uint)44);
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.FrameWidth, (uint)720);
pcktEnc.AddLocalDataItem(VTargetLocalDataTagWr.FrameHeight, (uint)480);
// Create a Target Packets
for (uint i = 0; i < Constants.NumberOfTargets; i++)
{
VMTI_TargetPackItemWr tTargetPack = new VMTI_TargetPackItemWr((uint)(27 + i));
tTargetPack.AddTargetPackItem(VTargetPackTagWr.TargetCentroidPixel, (UInt64)74985);
tTargetPack.AddTargetPackItem(VTargetPackTagWr.BoundingBoxTopLeftPixel, (UInt64)71380);
tTargetPack.AddTargetPackItem(VTargetPackTagWr.BoundingBoxBottomRightPixel, (UInt64)78590);
tTargetPack.AddTargetPackItem(VTargetPackTagWr.NewDetectionFlag, (ushort)i);
var color = Color.Red.ToArgb() & 0x00FFFFFF;
tTargetPack.AddTargetPackItem(VTargetPackTagWr.TargetColor, (uint)color);
// Add tracker
VTrackerLDSWr tTracker = new VTrackerLDSWr(i);
List<LocationTypeWr> locusList = new List<LocationTypeWr>();
locusList.Add(new LocationTypeWr(40.83715820003851, -104.97543811798096, 0));
locusList.Add(new LocationTypeWr(40.837645225907835, -104.97410774230957, 0.5));
locusList.Add(new LocationTypeWr(40.838262120205684, -104.97307777404785, 100));
locusList.Add(new LocationTypeWr(40.839171217127976, -104.97307777404785, 100));
locusList.Add(new LocationTypeWr(40.84014523570922, -104.97406482696533, 100));
locusList.Add(new LocationTypeWr(40.840534839134165, -104.97445106506348, 100));
tTracker.AddLDS(VTrackerLDSTagWr.NumberOfPoints, (ushort)locusList.Count);
tTracker.AddLDS(VTrackerLDSTagWr.Locus, locusList);
tTargetPack.AddTargetPackItem(VTargetPackTagWr.VTracker_LDS, tTracker);
// Add Target Pack to TargetPackSeries container
pcktEnc.AddToTargetPackSeries(tTargetPack);
}
// Get Json
json = conv.VmtiPacketToJson(pcktEnc, false);
// Print
PrintVmtiString("Created packet", conv, pcktEnc);
// Encode packet into data buffer.
var encDataBuff = conv.EncodeVmtiPacket(pcktEnc);
System.IO.File.WriteAllBytes(@"vmti1.bin", encDataBuff);
// Decode packet
var pcktDec = conv.DecodeVmtiPacket(encDataBuff);
// Get Json
json = conv.VmtiPacketToJson(pcktDec, true);
// Print
PrintVmtiString("Decoded packet", conv, pcktEnc);
#endregion
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}
static void PrintVmtiString(string title, STD0903ConverterWr conv, VMTI_PacketWr pckt)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(title);
Console.ResetColor();
StringBuilder sb = new StringBuilder();
// Add Local data items
foreach (var ldItem in pckt.LocalDataItems)
{
sb.Append(String.Format("{0,-32} {1, -32}", conv.TargetLocalDataTagToString(ldItem.Key), conv.TargetLocalDataToHRString(ldItem.Key, ldItem.Value)));
sb.Append(Environment.NewLine);
}
// Add Target Series data items
foreach (var tpItemSeria in pckt.TargetPackSeries)
{
sb.Append(string.Format("--------Target Pack ( {0} )--------", tpItemSeria.TargetID));
sb.Append(Environment.NewLine);
foreach (var tpSeriesItem in tpItemSeria.TargetPackItems)
{
if (tpSeriesItem.Key < VTargetPackTagWr.VMask_LDS)
{
sb.Append(String.Format("{0,-38} {1, -38}", conv.TargetPackTagToString(tpSeriesItem.Key), conv.TargetPackValueToHRString(tpSeriesItem.Key, tpSeriesItem.Value)));
sb.Append(Environment.NewLine);
}
else
{
switch (tpSeriesItem.Key)
{
case VTargetPackTagWr.VMask_LDS:
sb.Append(String.Format("{0,-38} {1, -38}", conv.TargetPackTagToString(tpSeriesItem.Key), "VMask_LDS"));
break;
case VTargetPackTagWr.VObject:
sb.Append(String.Format("{0,-38} {1, -38}", conv.TargetPackTagToString(tpSeriesItem.Key), "VObject"));
break;
case VTargetPackTagWr.VFeature_LDS:
sb.Append(String.Format("{0,-38} {1, -38}", conv.TargetPackTagToString(tpSeriesItem.Key), "VFeature_LDS"));
break;
case VTargetPackTagWr.VTracker_LDS:
var vtlds = tpSeriesItem.Value as VTrackerLDSWr;
sb.Append(String.Format("{0,-38} {1, -38}", conv.TargetPackTagToString(tpSeriesItem.Key), "TargetID - " + vtlds.TargetID + " (" + vtlds.LDSItems.Count + " items)"));
sb.Append(Environment.NewLine);
foreach (var vTrackerItem in vtlds.LDSItems)
{
if (vTrackerItem.Key == VTrackerLDSTagWr.NumberOfPoints)
sb.Append(String.Format("{0,-36} {1, -36}\n", conv.TrackerLocalDataTagToString(vTrackerItem.Key), vTrackerItem.Value.ToString()));
else
if (vTrackerItem.Key == VTrackerLDSTagWr.Locus)
{
sb.Append(String.Format(" {0}", "Locus:\n"));
var locus = (List<LocationTypeWr>) vTrackerItem.Value;
locus.ForEach(delegate(LocationTypeWr locItem)
{
sb.Append(String.Format("\t{0}, \t {1}, \t {2}\n", Math.Round(locItem.Latitude, 8).ToString(), Math.Round(locItem.Longitude, 8).ToString(), Math.Round(locItem.Height, 1).ToString()));
});
}
else
sb.Append(String.Format(" {0,-36}\n", conv.TrackerLocalDataTagToString(vTrackerItem.Key)));
}
break;
case VTargetPackTagWr.VChip_LDS:
sb.Append(String.Format(" {0,-38} {1, -36}", conv.TargetPackTagToString(tpSeriesItem.Key), "VChip_LDS"));
break;
}
sb.Append(Environment.NewLine);
}
}
}
Console.WriteLine(sb.ToString());
}
}
}
Untitled 1




 Copyright 2017,    IMPLEOTV SYSTEMS LTD