#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
#include <comutil.h>
#include <iostream>
#include <fstream>
#include "ISTD0903Conv.h"
#include "Windows.h"
#include <Oleauto.h>
#include <OaIdl.h>
#include <iostream>
#include <iomanip>
#ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
#else
# pragma comment(lib, "comsuppw.lib")
#endif
# pragma comment(lib, "wbemuuid.lib")
#define TARGET_PACKS 1
#define NUMBER_OF_POINTS 10
#pragma warning(push)
#pragma warning(disable : 4482)
bool exists(const char* path);
unsigned char* ReadBinData(const char* path, size_t& l);
void PrintData(VARIANT& vt);
int main(int argc, char* argv[])
{
size_t length;
unsigned char* pBuf;
if (argc < 2)
{
cout << "No bin file argument provided";
}
else
{
string path = argv[1];
if (exists(path.c_str()))
ReadVmtiFileAndShowContent(pVmtiConv, path.c_str());
else
cout << "File " << path << " not found";
}
pBuf = FillAndEncodeVMTIBuffer(pVmtiConv, pEncPckt, length);
PrintVmtiPacket(pVmtiConv, pEncPckt);
delete pEncPckt;
cout << "Decode Packet";
VMTI_Packet* pDecPckt = DecodeVMTIBuffer(pVmtiConv, pBuf, length);
cout << "Examine the content";
PrintVmtiPacket(pVmtiConv, pDecPckt);
delete pDecPckt;
delete pVmtiConv;
return 0;
}
{
size_t l;
unsigned char* sampleBuf = ReadBinData(filePath, l);
pVmtiConv->
Decode(sampleBuf, l, pPcktDec);
PrintVmtiPacket(pVmtiConv, pPcktDec);
delete pPcktDec;
delete sampleBuf;
}
{
for (int i = 0; i < TARGET_PACKS; i++)
{
delete vTLds;
}
return pVmtiConv->
Encode(pPckt, length);
}
{
pVmtiConv->
Decode(pBuf, length, pPckt);
return pPckt;
}
{
for (int i = 0; i < NUMBER_OF_POINTS; i++)
{
}
return vLds;
}
{
VARIANT vt;
TargetLocalDataIterator ld_it;
{
VariantInit(&vt);
VTargetLocalDataTag tag = (*ld_it).first;
PrintData(vt);
if (tag == VTargetLocalDataTag::UNIX_Time_Stamp)
cout << endl;
VariantClear(&vt);
}
TargetSeriesIterator ts_it;
{
TargetPackIterator tp_it;
cout <<
"\tTarget Id - " << pTargetPack->
TargetID << endl;
for (tp_it = pTargetPack->GetVTargetPackItems().begin(); tp_it != pTargetPack->GetVTargetPackItems().end(); tp_it++)
{
VariantInit(&vt);
VTargetPackTag tag = (*tp_it).first;
if (tag < Target_Location)
PrintData(vt);
else
{
PrintHierarchyData(pVmtiConv, tag, vt);
}
cout << endl;
VariantClear(&vt);
}
}
cout << endl;
}
void PrintData(VARIANT& vt)
{
switch (vt.vt)
{
case VT_BSTR:
cout << (char*)(_bstr_t)vt;
break;
case VT_UI1:
case VT_UI2:
case VT_UI4:
cout << vt.uintVal;
break;
case VT_UI8:
cout << vt.ullVal;
break;
case VT_R4:
cout << vt.fltVal;
break;
case VT_R8:
cout << vt.dblVal;
break;
}
}
{
switch (tag)
{
case Target_Location:
{
SafeArrayLock(vt.parray);
void* pArrayData = NULL;
SafeArrayAccessData(vt.parray, &pArrayData);
long uBound;
HRESULT hresult;
hresult = SafeArrayGetUBound(vt.parray, 1, &uBound);
if (!FAILED(hresult))
{
LocationType locus((
unsigned char*)pArrayData, (
size_t)uBound + 1);
if (locus.GetMode() == LocationMode::GeospatialOnly)
cout << "\tLat: " << locus.Latitude << " Lon: " << locus.Longitude << " Alt: " << std::fixed << std::setprecision(2) << locus.Height << std::setprecision(4);
else
if (locus.GetMode() == LocationMode::GeospatialAndDeviations)
cout << " Sigma Lat: " << locus.SigmaLatitude << " Sigma Lon: " << locus.SigmaLongitude << " Sigma Alt: " << locus.SigmaHeight;
else
cout << " RhoLatLon: " << locus.RhoLatLon << " RhoLatHt: " << locus.RhoLatHt << " RhoLonH: " << locus.RhoLonHt;
cout << endl;
SafeArrayUnaccessData(vt.parray);
}
}
break;
case VObject:
break;
case VFeature_LDS:
break;
case VTracker_LDS:
{
SafeArrayLock(vt.parray);
void* pArrayData = NULL;
SafeArrayAccessData(vt.parray, &pArrayData);
long uBound;
HRESULT hresult;
hresult = SafeArrayGetUBound(vt.parray, 1, &uBound);
if (!FAILED(hresult))
{
cout << "(TargetId - " << vtLds.TargetID << ")" << endl;
map<VTrackerLDSTag, VTargetItem*>::iterator it;
for (it = vtLds.m_LDSItems.begin(); it != vtLds.m_LDSItems.end(); it++)
{
VTrackerLDSTag tag = (*it).first;
if (tag != VTrackerLDSTag::Locus && tag != VTrackerLDSTag::Velocity && tag != VTrackerLDSTag::Acceleration)
{
cout << endl;
}
}
if (!vtLds.m_Locus.empty())
{
vector<LocationType>::iterator itLocus;
cout << "\t\t\t\tLocus:" << endl;
cout << std::fixed << std::setprecision(4);
for (itLocus = vtLds.m_Locus.begin(); itLocus != vtLds.m_Locus.end(); itLocus++)
{
if (itLocus->GetMode() == LocationMode::GeospatialOnly)
cout << "\t\t\t\tLat: " << itLocus->Latitude << " Lon: " << itLocus->Longitude << " Alt: " << std::fixed << std::setprecision(2) << itLocus->Height << std::setprecision(4);
else
if (itLocus->GetMode() == LocationMode::GeospatialAndDeviations)
cout << " Sigma Lat: " << itLocus->SigmaLatitude << " Sigma Lon: " << itLocus->SigmaLongitude << " Sigma Alt: " << itLocus->SigmaHeight;
else
cout << " RhoLatLon: " << itLocus->RhoLatLon << " RhoLatHt: " << itLocus->RhoLatHt << " RhoLonH: " << itLocus->RhoLonHt;
cout << endl;
}
}
if (vtLds.m_pVelocity){
cout << "\t\t\t\tVelocity:" << endl;
cout << std::fixed << std::setprecision(4);
if (vtLds.m_pVelocity->GetMode() == VAMode::ComponentOnly)
cout << "\t\t\t\tX: " << vtLds.m_pVelocity->X_Component << " Y: " << vtLds.m_pVelocity->Y_Component << " Z: " << vtLds.m_pVelocity->Z_Component;
else
if (vtLds.m_pVelocity->GetMode() == VAMode::ComponentAndDeviations)
cout << " Sigma X: " << vtLds.m_pVelocity->SigmaX << " Sigma Y: " << vtLds.m_pVelocity->SigmaY << " Sigma Z: " << vtLds.m_pVelocity->SigmaZ;
else
cout << " Rho_X_Y: " << vtLds.m_pVelocity->Rho_X_Y << " Rho_X_Z: " << vtLds.m_pVelocity->Rho_X_Z << " Rho_Y_Z: " << vtLds.m_pVelocity->Rho_Y_Z;
cout << endl;
}
if (vtLds.m_pAcceleration){
cout << "\t\t\t\tAcceleration:" << endl;
cout << std::fixed << std::setprecision(4);
if (vtLds.m_pAcceleration->GetMode() == VAMode::ComponentOnly)
cout << "\t\t\t\tX: " << vtLds.m_pAcceleration->X_Component << " Y: " << vtLds.m_pAcceleration->Y_Component << " Z: " << vtLds.m_pAcceleration->Z_Component;
else
if (vtLds.m_pAcceleration->GetMode() == VAMode::ComponentAndDeviations)
cout << " Sigma X: " << vtLds.m_pAcceleration->SigmaX << " Sigma Y: " << vtLds.m_pAcceleration->SigmaY << " Sigma Z: " << vtLds.m_pAcceleration->SigmaZ;
else
cout << " Rho_X_Y: " << vtLds.m_pAcceleration->Rho_X_Y << " Rho_X_Z: " << vtLds.m_pAcceleration->Rho_X_Z << " Rho_Y_Z: " << vtLds.m_pAcceleration->Rho_Y_Z;
cout << endl;
}
SafeArrayUnaccessData(vt.parray);
}
}
break;
case VChip_LDS:
break;
}
}
bool exists(const char* path) {
ifstream f(path);
return f.good();
}
unsigned char* ReadBinData(const char* path, size_t& l)
{
unsigned char * buffer;
ifstream is;
is.open(path, ios::in | ios::out | ios::binary | ios::ate);
if (!is.is_open())
{
printf("File %s not found.", path);
throw "open failed";
}
is.seekg(0, ios::end);
l = is.tellg();
is.seekg(0, ios::beg);
buffer = new unsigned char[l];
is.read((char*)buffer, l);
is.close();
return buffer;
}
#pragma warning(pop)