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> |
d6f0ba
|
13 |
#include <sstream> |
JS |
14 |
|
e9b870
|
15 |
using namespace clipp; using std::cout; using std::string; |
929277
|
16 |
|
e43149
|
17 |
#define OUTPUT_BUFFER_SIZE 512 |
929277
|
18 |
|
JS |
19 |
int RunCollect=0; |
e43149
|
20 |
std::unique_ptr<UdpTransmitSocket> transmitSocket; |
d6f0ba
|
21 |
bool use_text = false; |
929277
|
22 |
|
JS |
23 |
|
|
24 |
void* Collect(REND_STRUCT* prs){ |
|
25 |
int i = 0; |
|
26 |
CG4Trk* pTrk = prs->pTrk; |
|
27 |
while (RunCollect){ |
|
28 |
// periodically check for new hubs coming on line |
|
29 |
if(i % 1000 == 0) { |
|
30 |
int numHubs; |
|
31 |
if (prs->tot_hubs_on_system!=prs->numHub){ |
|
32 |
prs->numHub=numHubs=prs->tot_hubs_on_system=pTrk->UpdateHubs(); |
|
33 |
int colorInd=0; |
|
34 |
if (prs->hubList) { |
|
35 |
delete[] prs->hubList; |
|
36 |
} |
|
37 |
prs->hubList=new CG4Hub[numHubs]; |
|
38 |
int* hubIds=new int[numHubs]; |
|
39 |
pTrk->GetHubList(hubIds,numHubs); |
|
40 |
for (int i=0;i<numHubs;i++){ |
|
41 |
prs->hubList[i].SetId(hubIds[i]); |
|
42 |
} |
|
43 |
delete[] hubIds; |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
i++; |
|
48 |
prs->hubreadmap=0; |
|
49 |
prs->tot_hubs_on_system=prs->pTrk->GetHubsPno(prs); |
e43149
|
50 |
char buffer[OUTPUT_BUFFER_SIZE]; |
JS |
51 |
osc::OutboundPacketStream p( buffer, OUTPUT_BUFFER_SIZE ); |
|
52 |
|
d6f0ba
|
53 |
if(!use_text) { |
JS |
54 |
p << osc::BeginBundleImmediate; |
|
55 |
} |
929277
|
56 |
for (int i=0;i<prs->numHub;i++){ |
d05d79
|
57 |
for(int j=0;j<G4_SENSORS_PER_HUB;j++) { |
JS |
58 |
if(!prs->hubList[i].IsSenActive(j)){ |
|
59 |
continue; |
|
60 |
} |
|
61 |
auto dat = prs->hubList[i].GetPnoData()[j]; |
|
62 |
//printf("sns: %i: [%f;%f;%f],[%f,%f,%f]\n",i, dat[0],dat[1],dat[2], dat[3],dat[4],dat[5]); |
|
63 |
p << osc::BeginMessage( (string("/g4/hub/") + std::to_string(i) + string("/") + std::to_string(j)).c_str()); |
|
64 |
std::ostringstream ss; |
|
65 |
if(use_text) { |
|
66 |
ss << "[" << dat[0] << "," << dat[1] << "," << dat[2] << "," << dat[3] << "," << dat[4] << "," << dat[5] << "]"; |
|
67 |
auto res = ss.str(); |
|
68 |
p << res.c_str(); |
|
69 |
} else { |
|
70 |
p << dat[0] << dat[1] << dat[2] << dat[3] << dat[4] << dat[5]; |
|
71 |
} |
|
72 |
p << osc::EndMessage; |
d6f0ba
|
73 |
} |
d05d79
|
74 |
if(!use_text) { |
JS |
75 |
p << osc::EndBundle; |
|
76 |
} |
|
77 |
transmitSocket->Send( p.Data(), p.Size() ); |
929277
|
78 |
} |
JS |
79 |
usleep(15000); |
|
80 |
// usleep(8000); |
|
81 |
} |
|
82 |
|
|
83 |
return NULL; |
|
84 |
} |
|
85 |
|
|
86 |
int main(int argc,char* argv[]){ |
|
87 |
|
|
88 |
CG4Trk trk; |
|
89 |
REND_STRUCT rs; |
e9b870
|
90 |
string cfgFile; |
e43149
|
91 |
string oscSinkAddr; |
JS |
92 |
int oscSinkPort; |
929277
|
93 |
|
e9b870
|
94 |
auto cli = ( |
d6f0ba
|
95 |
option("-t", "--text").set(use_text).doc("send strings in osc messages instead of a float bundle"), |
e9b870
|
96 |
value("c4g configuration file", cfgFile), |
e43149
|
97 |
value("osc sink address", oscSinkAddr), |
JS |
98 |
integer("osc sink port", oscSinkPort) |
e9b870
|
99 |
); |
929277
|
100 |
|
e9b870
|
101 |
if(!parse(argc, argv, cli)) { |
JS |
102 |
cout << make_man_page(cli, argv[0]); |
|
103 |
return 1; |
|
104 |
} |
e43149
|
105 |
transmitSocket = std::make_unique<UdpTransmitSocket>( IpEndpointName( oscSinkAddr.c_str(), oscSinkPort ) ); |
929277
|
106 |
memset(rs.viewTrans,0,sizeof(float)*3); |
JS |
107 |
rs.srcScale=rs.senScale=0.5; |
|
108 |
rs.counter=0; |
|
109 |
|
|
110 |
cfgFile="config.g4c"; |
e9b870
|
111 |
int resp=trk.Connect(const_cast<char*>(cfgFile.c_str())); // whaaaaa |
929277
|
112 |
if (!resp){ |
JS |
113 |
printf("Error Connecting to G4\n"); |
|
114 |
return -1; |
|
115 |
} |
|
116 |
|
|
117 |
usleep(500000); |
|
118 |
rs.numSrc=trk.GetNumSrc(); |
|
119 |
rs.srcList=new float[rs.numSrc][6]; |
|
120 |
trk.GetSrcLoc(rs.srcList); |
|
121 |
|
|
122 |
rs.numHub=trk.UpdateHubs(); |
|
123 |
rs.hubList=new CG4Hub[rs.numHub]; |
|
124 |
int* hubIds=new int[rs.numHub]; |
|
125 |
trk.GetHubList(hubIds,rs.numHub); |
|
126 |
for (int i=0;i<rs.numHub;i++){ |
|
127 |
rs.hubList[i].SetId(hubIds[i]); |
|
128 |
} |
|
129 |
delete[] hubIds; |
|
130 |
|
|
131 |
rs.pTrk=&trk; |
|
132 |
|
|
133 |
RunCollect=1; |
|
134 |
|
|
135 |
Collect(&rs); |
|
136 |
|
|
137 |
delete[] rs.srcList; |
|
138 |
delete[] rs.hubList; |
|
139 |
|
|
140 |
return 0; |
|
141 |
} |
|
142 |
|