Skip to content

Commit

Permalink
updated MTconnector to produce a file output of
Browse files Browse the repository at this point in the history
 coordinates time difference and sequence #
  • Loading branch information
salam committed Jan 14, 2016
1 parent 04d63ee commit 538572a
Show file tree
Hide file tree
Showing 14 changed files with 76,040 additions and 140 deletions.
54,614 changes: 54,614 additions & 0 deletions DATA.txt

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ using namespace System::Net;
using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Text;
#pragma once
#ifndef __EXEC__
#define __EXEC__
public ref class Exec

ref class Exec
{
private:
String^ name;
String ^ name;
__int64 id;
__int64 index;
WP^ parent;
Exec^ parent;
bool typeWP;
public:

bool isWP(){return typeWP;}
bool isWP(){return typeWP;};
//get name of Executable
String^ getName(){return name;}
String^ getName(){return name;};
// get stpnc id of Executable
__int64 getId(){return id;}
__int64 getId(){return id;};
// index in list of enabled executalbes for an enabled parent WorkPlan
__int64 getIndex(){return index;}
__int64 getIndex(){return index;};

WP^ getParent(){return parent;};
Exec(String^ n,__int64 ID,__int64 in,WP^p,bool iswp){
Exec^ getParent(){return parent;};
Exec(String^ n,__int64 ID,__int64 in,Exec^p,bool iswp){
name=n;
id=ID;
index=in;
Expand Down
81 changes: 73 additions & 8 deletions MtConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ void MtConnector::EventHandler(Object^ sender, OpenReadCompletedEventArgs^ e){


}
void MtConnector::getRequest(String^ str){
void MtConnector::getRequest(String^ requestStr,String^ dataLocation){

UriBuilder^ build=gcnew UriBuilder(str);
UriBuilder^ build=gcnew UriBuilder(requestStr);
WebRequest^ request = WebRequest::Create(build->Uri);
WebResponse ^ response=request->GetResponse();
WebResponse ^ response;
try{
response=request->GetResponse();
}catch(Exception ^e){
Console::WriteLine(e);
}
Console::WriteLine("requested data");
//response->Headers->Add("Content-Type","multipart/x-mixed-replace;boundary=--");
//response->Headers->Add("Content-Type","text/xml");
//response->Headers->Add("Transfer-Encoding","chunked");
Expand All @@ -69,21 +75,80 @@ void MtConnector::getRequest(String^ str){
array<wchar_t>^ buff;
int size=0;
Console::WriteLine(bound);
//////////////////////////////////


//////////////////////////
bool firstTime=true;
DateTime ^ tempTime=gcnew DateTime();


StreamWriter ^write=gcnew StreamWriter(dataLocation);
while(!(reader->EndOfStream)){

size=getMessageSize(bound,reader);

Console::WriteLine(size);
//Console::WriteLine(line);
buff=getMessage(size,reader);
printXMLData(buff);

printXMLData(buff,tempTime,firstTime,write);
write->Flush();
firstTime=false;
}
Console::WriteLine("end of stream");
}
void MtConnector::printXMLData(array<wchar_t>^ buff){
Console::WriteLine(buff);

void MtConnector::printXMLData(array<wchar_t>^ buff,DateTime ^% time1,bool firstTime,StreamWriter ^ write){
String^ timeStr1,^timeStr2,^coor,^seq;
double diff=0;
DateTime^ time2=gcnew DateTime();
String ^ data=gcnew String(buff);
bool gotData=false;
//Console::WriteLine(data);
XmlReader^ reader = XmlReader::Create(gcnew StringReader(data));
try{

while(reader->Read()){
//Console::WriteLine(reader->MoveToAttribute("timestamp"));
//Console::WriteLine(reader->ReadAttributeValue());
if(reader->Name=="PathPosition"){

//Console::WriteLine(reader->GetAttribute("timestamp"));
//Console::WriteLine(reader->ReadInnerXml());
//DateTime^ time2=gcnew DateTime();
if (firstTime){
time1=time1->Parse(reader->GetAttribute("timestamp"));
seq=reader->GetAttribute("sequence");
coor=reader->ReadInnerXml();
coor=String::Format("{0} {1} {2}",coor,0,seq);

firstTime=false;

}
else{
time2=time2->Parse(reader->GetAttribute("timestamp"));
seq=reader->GetAttribute("sequence");
diff=(time2->Subtract(*time1).TotalSeconds);
coor=reader->ReadInnerXml();
coor=String::Format("{0} {1} {2}",coor,diff,seq);
//Console::WriteLine(time1);
//Console::WriteLine(time2);

(*time1)=(*time2);

}
write->WriteLine(coor);
Console::WriteLine(coor);

}


/*
if(reader->HasValue)
{Console::WriteLine(reader->Value);}
*/
}
}catch(Exception ^e){Console::WriteLine(e);}

}
int MtConnector::getMessageSize(String^bound,StreamReader^ reader){
int size=0;
Expand Down
4 changes: 2 additions & 2 deletions MtConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ ref class MtConnector
WebClient ^wc;
int getMessageSize(String^bound,StreamReader^ reader);
array<wchar_t>^ getMessage(int size,StreamReader ^ reader);
void printXMLData(array<wchar_t>^ buff);
void printXMLData(array<wchar_t>^ buff,DateTime ^%,bool firstTime,StreamWriter^ writer);
public:
MtConnector();
array<double>^ getPos();
void printData();
Boolean startPush(String ^ str);
void getRequest(String^ str);
void getRequest(String^ str,String^ dataLocation);


void EventHandler(Object^ sender, OpenReadCompletedEventArgs^ e);
Expand Down
89 changes: 87 additions & 2 deletions Patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ void DeleteBefore(__int64 wpid,STEPNCLib::Finder ^find,STEPNCLib::AptStepMaker^a

}

void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String coor,bool toInches){
void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor,bool toInches){
STEPNCLib::AptStepMaker^ apt;
STEPNCLib::Finder^find;
__int64 oldWPID;
Expand All @@ -635,4 +635,89 @@ void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileNa



}
}



/*
ToolPath^ nextPath(bool % newWP, bool% newWS){
ToolPath^temp=nextPath();
Exec^ tempExec;
if (temp!=nullptr){
newWP=false;
newWS=false;
return temp;
}
else{
WS^ tempWS=dynamic_cast<WS^>(parent);
ToolPath^ nextToolPath=nullptr;
List<WP^>^path=pathtoRoot(tempWS);
for (int i=0;i<path->Count;i++){
nextToolPath=recurseToNextToolPath(path[i],tempWS->getIndex());
}
}
}
List<WP^>^pathtoRoot(WS^temp){
List<WP^> ^path=gcnew List<WP^>();
WP^ temp1=dynamic_cast<WP^>(temp->getParent());
if(temp!=nullptr){
while (temp1!=nullptr){
path->Add(temp1);
temp1=dynamic_cast<WP^>(temp1->getParent());
}
}
return path;
}
ToolPath^ recurseToNextToolPath(WP^ current , __int64 startIndexAfter){
ToolPath^ result=nullptr;
for(int i=startIndexAfter+1;i<current->getExecutableCount();i++){
result =recurseToolPath(current->getExecutable(i));
if(result!=nullptr){
return result;
}
}
}
ToolPath^ recurseToolPath(Exec^ current){
WS^ tempWS=nullptr;
WP^ tempWP=nullptr;
WP^ tempWP2;
if (current->isWP()){
tempWP=dynamic_cast<WP^>(current);
}
else{
tempWS=dynamic_cast<WS^>(current);
}
if(tempWS!=nullptr){
if(tempWS->getPathCount()>0){
return tempWS->getPath(0);
}
}
if(tempWP!=nullptr){
for (int i=0;i<tempWP->getExecutableCount();i++){
return recurseToolPath(tempWP->getExecutable(i));
}
}
return nullptr;
}
*/



6 changes: 3 additions & 3 deletions Patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ref class Patcher{

void OpenFile(String^file,String^ desiredWorkPlanPath,String^newWorkPlanName,STEPNCLib::Finder ^%find,STEPNCLib::AptStepMaker^%apt, __int64% wpID);
//Delete all workplans and executables in the same root as wpid and before wpid
void DeleteBefore(__int64 wpid);
//void DeleteBefore(__int64 wpid);

//returns coordinates in inches
List<array<double>^> ^ coordinates(String ^fileName,bool convert_to_inches);
Expand All @@ -48,7 +48,7 @@ ref class Patcher{
List<double> ^getAllPoints(List<long long>^ paths,STEPNCLib::Finder ^find);
void patchRapid(List<long long>^ pathList,STEPNCLib::AptStepMaker ^ apt, STEPNCLib::Finder ^find,double max_feed);
void appendPatchWorkPlan(String^partFile,String^coorFile,String^outName,String^ path,bool toInches );
void createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String coor,bool toInches);
ToolPath^ firstPath(__int64 root);
void createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor,bool toInches);
//ToolPath^ firstPath(__int64 root);
};
#endif
81 changes: 3 additions & 78 deletions ToolPath.cpp
Original file line number Diff line number Diff line change
@@ -1,89 +1,14 @@
#include "ToolPath.h";


/*
ToolPath^ ToolPath::nextPath(){
if(parent!=nullptr){
return parent->getPath(getIndex()+1);
return dynamic_cast<ToolPath^>(dynamic_cast<WS^>(parent)->getPath(getIndex()+1));
}else{
Console::WriteLine("Error path is not nested in a WS");
return nullptr;}
return nullptr;
}

ToolPath^ ToolPath::nextPath(bool % newWP, bool% newWS){
ToolPath^temp=nextPath();
Exec^ tempExec;
if (temp!=nullptr){
newWP=false;
newWS=false;
return temp;
}
else{
WS^ tempWS=parent;
ToolPath^ nextToolPath=nullptr;
List<WP^>^path=pathtoRoot(tempWS);
for (int i=0;i<path->Count;i++){
nextToolPath=recurseToNextToolPath(path[i],tempWS->getIndex());


}
}
}
List<WP^>^pathtoRoot(WS^temp){
List<WP^> ^path=gcnew List<WP^>();
WP^ temp1=temp->getParent();

if(temp!=nullptr){
while (temp1!=nullptr){
path->Add(temp1);
temp1=temp1->getParent();


}

}

return path;

}
ToolPath^ recurseToNextToolPath(WP^ current , __int64 startIndexAfter){
ToolPath^ result=nullptr;
for(int i=startIndexAfter+1;i<current->getExecutableCount();i++){
recurseToolPath(current->getExecutable(i),result);
if(result!=nullptr){
return result;
}
}


}
ToolPath^ recurseToolPath(Exec^ current){
WS^ tempWS=nullptr;
WP^ tempWP=nullptr;
WP^ tempWP2;
if (current->isWP()){
tempWP=dynamic_cast<WP^>(current);
}
else{
tempWS=dynamic_cast<WS^>(current);
}
if(tempWS!=nullptr){
if(tempWS->getPathCount()>0){
return tempWS->getPath(0);

}
}
if(tempWP!=nullptr){
for (int i=0;i<tempWP->getExecutableCount();i++){

return recurseToolPath(tempWP->getExecutable(i));


}


}
return nullptr;
}
*/
Loading

0 comments on commit 538572a

Please sign in to comment.