commit | author | age
|
929277
|
1 |
#include <stdio.h> |
e9b870
|
2 |
#include <iostream> |
929277
|
3 |
#include "Quaternion.h" |
JS |
4 |
#include "struct.h" |
|
5 |
#include "G4Trk.h" |
|
6 |
#include "G4Hub.h" |
|
7 |
#include <string.h> |
|
8 |
#include <unistd.h> |
e43149
|
9 |
#include <memory> |
e9b870
|
10 |
#include "clipp.h" |
e43149
|
11 |
#include <ip/UdpSocket.h> |
JS |
12 |
#include <osc/OscOutboundPacketStream.h> |
e9b870
|
13 |
using namespace clipp; using std::cout; using std::string; |
929277
|
14 |
|
e43149
|
15 |
#define OUTPUT_BUFFER_SIZE 512 |
929277
|
16 |
|
JS |
17 |
int RunCollect=0; |
e43149
|
18 |
std::unique_ptr<UdpTransmitSocket> transmitSocket; |
929277
|
19 |
|
JS |
20 |
|
|
21 |
void* Collect(REND_STRUCT* prs){ |
|
22 |
int i = 0; |
|
23 |
CG4Trk* pTrk = prs->pTrk; |
|
24 |
while (RunCollect){ |
|
25 |
// periodically check for new hubs coming on line |
|
26 |
if(i % 1000 == 0) { |
|
27 |
int numHubs; |
|
28 |
if (prs->tot_hubs_on_system!=prs->numHub){ |
|
29 |
prs->numHub=numHubs=prs->tot_hubs_on_system=pTrk->UpdateHubs(); |
|
30 |
int colorInd=0; |
|
31 |
if (prs->hubList) { |
|
32 |
delete[] prs->hubList; |
|
33 |
} |
|
34 |
prs->hubList=new CG4Hub[numHubs]; |
|
35 |
int* hubIds=new int[numHubs]; |
|
36 |
pTrk->GetHubList(hubIds,numHubs); |
|
37 |
for (int i=0;i<numHubs;i++){ |
|
38 |
prs->hubList[i].SetId(hubIds[i]); |
|
39 |
} |
|
40 |
delete[] hubIds; |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
44 |
i++; |
|
45 |
prs->hubreadmap=0; |
|
46 |
prs->tot_hubs_on_system=prs->pTrk->GetHubsPno(prs); |
e43149
|
47 |
char buffer[OUTPUT_BUFFER_SIZE]; |
JS |
48 |
osc::OutboundPacketStream p( buffer, OUTPUT_BUFFER_SIZE ); |
|
49 |
|
|
50 |
p << osc::BeginBundleImmediate; |
929277
|
51 |
for (int i=0;i<prs->numHub;i++){ |
JS |
52 |
auto dat = prs->hubList[i].GetPnoData()[0]; |
e43149
|
53 |
//printf("sns: %i: [%f;%f;%f],[%f,%f,%f]\n",i, dat[0],dat[1],dat[2], dat[3],dat[4],dat[5]); |
JS |
54 |
p << osc::BeginMessage( (string("/hub/") + std::to_string(i)).c_str() ) |
|
55 |
<< dat[0] << dat[1] << dat[2] << dat[3] << dat[4] << dat[5] << osc::EndMessage; |
929277
|
56 |
} |
e43149
|
57 |
p << osc::EndBundle; |
JS |
58 |
transmitSocket->Send( p.Data(), p.Size() ); |
929277
|
59 |
usleep(15000); |
JS |
60 |
// usleep(8000); |
|
61 |
} |
|
62 |
|
|
63 |
return NULL; |
|
64 |
} |
|
65 |
|
|
66 |
int main(int argc,char* argv[]){ |
|
67 |
|
|
68 |
CG4Trk trk; |
|
69 |
REND_STRUCT rs; |
e9b870
|
70 |
string cfgFile; |
e43149
|
71 |
string oscSinkAddr; |
JS |
72 |
int oscSinkPort; |
929277
|
73 |
|
e9b870
|
74 |
auto cli = ( |
JS |
75 |
value("c4g configuration file", cfgFile), |
e43149
|
76 |
value("osc sink address", oscSinkAddr), |
JS |
77 |
integer("osc sink port", oscSinkPort) |
e9b870
|
78 |
); |
929277
|
79 |
|
e9b870
|
80 |
if(!parse(argc, argv, cli)) { |
JS |
81 |
cout << make_man_page(cli, argv[0]); |
|
82 |
return 1; |
|
83 |
} |
e43149
|
84 |
transmitSocket = std::make_unique<UdpTransmitSocket>( IpEndpointName( oscSinkAddr.c_str(), oscSinkPort ) ); |
929277
|
85 |
memset(rs.viewTrans,0,sizeof(float)*3); |
JS |
86 |
rs.srcScale=rs.senScale=0.5; |
|
87 |
rs.counter=0; |
|
88 |
|
|
89 |
cfgFile="config.g4c"; |
e9b870
|
90 |
int resp=trk.Connect(const_cast<char*>(cfgFile.c_str())); // whaaaaa |
929277
|
91 |
if (!resp){ |
JS |
92 |
printf("Error Connecting to G4\n"); |
|
93 |
return -1; |
|
94 |
} |
|
95 |
|
|
96 |
usleep(500000); |
|
97 |
rs.numSrc=trk.GetNumSrc(); |
|
98 |
rs.srcList=new float[rs.numSrc][6]; |
|
99 |
trk.GetSrcLoc(rs.srcList); |
|
100 |
|
|
101 |
rs.numHub=trk.UpdateHubs(); |
|
102 |
rs.hubList=new CG4Hub[rs.numHub]; |
|
103 |
int* hubIds=new int[rs.numHub]; |
|
104 |
trk.GetHubList(hubIds,rs.numHub); |
|
105 |
for (int i=0;i<rs.numHub;i++){ |
|
106 |
rs.hubList[i].SetId(hubIds[i]); |
|
107 |
} |
|
108 |
delete[] hubIds; |
|
109 |
|
|
110 |
rs.pTrk=&trk; |
|
111 |
|
|
112 |
RunCollect=1; |
|
113 |
|
|
114 |
Collect(&rs); |
|
115 |
|
|
116 |
delete[] rs.srcList; |
|
117 |
delete[] rs.hubList; |
|
118 |
|
|
119 |
return 0; |
|
120 |
} |
|
121 |
|