1+ <!DOCTYPE html>
2+ < html >
3+ < title > Aditof JS Client</ title >
4+ < link rel ="shortcut icon " href ="# ">
5+ < script type ="text/javascript " src ="../bundle.js "> </ script >
6+
7+ < script type ="text/javascript ">
8+ async function main ( ) {
9+ let status ;
10+ const ip_address = '192.168.0.106' ;
11+
12+ let net = new Network ( ip_address ) ;
13+ status = await net . ServerConnect ( ) ;
14+
15+ var nse = new NetworkSensorEnumerator ( net ) ;
16+ status = await nse . searchSensors ( ) ;
17+
18+ console . log ( nse ) ;
19+
20+ let depth_sensor = nse . getDepthSensors ( ) [ 1 ] [ 0 ] ;
21+ let storage = nse . getStorages ( ) [ 1 ] [ 0 ] ;
22+ let temp_sensor = nse . getTemperatureSensors ( ) [ 1 ] [ 0 ] ;
23+
24+ console . log ( depth_sensor ) ;
25+ console . log ( storage ) ;
26+ console . log ( temp_sensor ) ;
27+
28+ let address , data , length , bytesCount ;
29+
30+ //depth sensor
31+ console . log ( '' ) ;
32+ console . log ( 'depth sensor testing' ) ;
33+ console . log ( '' ) ;
34+
35+ console . log ( 'opened: ' , depth_sensor . m_opened ) ;
36+ status = await depth_sensor . open ( ) ;
37+ console . log ( 'status open: ' , status , depth_sensor . m_opened ) ;
38+
39+ let firmware , size ;
40+ firmware = 'asd' ;
41+ size = 3 ;
42+ status = await depth_sensor . program ( firmware , size ) ;
43+ console . log ( 'status program: ' , status ) ;
44+
45+ // doesn 't work
46+ // status = await depth_sensor.start();
47+ // console.log('status start: ', status);
48+
49+ [ status , details ] = await depth_sensor . getAvailableFrameTypes ( ) ;
50+ console . log ( 'status getAvailableFrameTypes: ' , status ) ;
51+
52+ status = await depth_sensor . setFrameType ( new Object ( ) ) ;
53+ console . log ( 'status setFrameType: ' , status ) ;
54+
55+ // doesn 't work
56+ // status = await depth_sensor.getFrame();
57+ // console.log('status getFrame: ', status);
58+
59+ address = "asd" ;
60+ data = "qwe" ;
61+ length = 3 ;
62+ status = await depth_sensor . writeAfeRegisters ( address , data , length ) ;
63+ console . log ( 'status writeAfeRegisters: ' , status ) ;
64+
65+ status = await depth_sensor . readAfeRegisters ( address , data , length ) ;
66+ console . log ( 'status readAfeRegisters: ' , status ) ;
67+
68+ status = await depth_sensor . stop ( ) ;
69+ console . log ( 'status stop: ' , status ) ;
70+
71+ //storage
72+ console . log ( "" ) ;
73+ console . log ( 'storage testing' ) ;
74+ console . log ( "" ) ;
75+
76+ status = await storage . open ( ) ;
77+ console . log ( 'status open: ' , status ) ;
78+
79+ address = 1 ;
80+ data = new Uint8Array ( ) ;
81+ bytesCount = 3 ;
82+ status = await storage . write ( address , data , bytesCount ) ;
83+ console . log ( 'status write: ' , status ) ;
84+
85+ [ status , data ] = await storage . read ( address , bytesCount ) ;
86+ console . log ( 'status read: ' , status ) ;
87+
88+ status = await storage . close ( ) ;
89+ console . log ( 'status close: ' , status ) ;
90+
91+
92+ //temperature sensor
93+ console . log ( '' ) ;
94+ console . log ( 'temp sensor testing' ) ;
95+ console . log ( '' ) ;
96+
97+ status = await temp_sensor . open ( ) ;
98+ console . log ( 'status open: ' , status ) ;
99+
100+ [ status , temp ] = await temp_sensor . read ( ) ;
101+ console . log ( 'status read: ' , status ) ;
102+
103+ status = await temp_sensor . close ( ) ;
104+ console . log ( 'status close: ' , status ) ;
105+
106+ }
107+
108+ // main();
109+
110+ async function first_frame_network ( ip_address ) {
111+ let status ;
112+
113+ console . clear ( ) ;
114+ console . log ( '\n\n\n\n' ) ;
115+ console . log ( 'Hello World! ... First frame network running ... ' ) ;
116+
117+ // const ip_address = '10.42.0.65';
118+
119+
120+ // let net = new Network(ip_address);
121+ // status = await net.ServerConnect();
122+
123+ // var nse = new NetworkSensorEnumerator(net);
124+ // status = await nse.searchSensors();
125+
126+ // console.log(nse);
127+
128+ // let depth_sensor = nse.getDepthSensors()[1][0];
129+ // let storage = nse.getStorages()[1][0];
130+ // let temp_sensor = nse.getTemperatureSensors()[1][0];
131+
132+ // console.log(depth_sensor);
133+ // console.log(storage);
134+ // console.log(temp_sensor);
135+
136+ // let address, data, length, bytesCount;
137+
138+ // //depth sensor
139+ // console.log('');
140+ // console.log('depth sensor testing');
141+ // console.log('');
142+
143+ // console.log('opened: ', depth_sensor.m_opened);
144+ // status = await depth_sensor.open();
145+ // console.log('status open: ', status, depth_sensor.m_opened);
146+
147+ // let firmware, size;
148+ // firmware = 'asd';
149+ // size = 3;
150+ // status = await depth_sensor.program(firmware, size);
151+ // console.log('status program: ', status);
152+
153+ // // doesn 't work
154+ // // status = await depth_sensor.start();
155+ // // console.log('status start: ', status);
156+
157+ // [status, details] = await depth_sensor.getAvailableFrameTypes();
158+ // console.log('status getAvailableFrameTypes: ', status);
159+
160+ // status = await depth_sensor.setFrameType(new Object());
161+ // console.log('status setFrameType: ', status);
162+
163+ // // doesn 't work
164+ // // status = await depth_sensor.getFrame();
165+ // // console.log('status getFrame: ', status);
166+
167+ // address = "asd";
168+ // data = "qwe";
169+ // length = 3;
170+ // status = await depth_sensor.writeAfeRegisters(address, data, length);
171+ // console.log('status writeAfeRegisters: ', status);
172+
173+ // status = await depth_sensor.readAfeRegisters(address, data, length);
174+ // console.log('status readAfeRegisters: ', status);
175+
176+ // status = await depth_sensor.stop();
177+ // console.log('status stop: ', status);
178+
179+ // //storage
180+ // console.log("");
181+ // console.log('storage testing');
182+ // console.log("");
183+
184+ // status = await storage.open();
185+ // console.log('status open: ', status);
186+
187+ // address = 1;
188+ // data = new Uint8Array();
189+ // bytesCount = 3;
190+ // status = await storage.write(address, data, bytesCount);
191+ // console.log('status write: ', status);
192+
193+ // [status, data] = await storage.read(address, bytesCount);
194+ // console.log('status read: ', status);
195+
196+ // status = await storage.close();
197+ // console.log('status close: ', status);
198+
199+
200+ // //temperature sensor
201+ // console.log('');
202+ // console.log('temp sensor testing');
203+ // console.log('');
204+
205+ // status = await temp_sensor.open();
206+ // console.log('status open: ', status);
207+
208+ // [status, temp] = await temp_sensor.read();
209+ // console.log('status read: ', status);
210+
211+ // status = await temp_sensor.close();
212+ // console.log('status close: ', status);
213+
214+
215+ let system = new System ( ) ;
216+ let cameras = [ ] ;
217+
218+ [ status , cameras ] = await system . getCameraListAtIp ( ip_address ) ;
219+ if ( ! cameras . length ) {
220+ console . log ( 'WARNING: No cameras found' ) ;
221+ return 0 ;
222+ }
223+
224+ let camera = cameras [ 0 ] ;
225+ status = camera . initialize ( ) ;
226+ if ( status !== Status . OK ) {
227+ console . log ( 'ERROR: Could not initialize camera!' ) ;
228+ return 0 ;
229+ }
230+
231+ let frameTypes = [ ] ;
232+ [ status , frameTypes ] = camera . getAvailableFrameTypes ( ) ;
233+ if ( ! frameTypes . length ) {
234+ console . log ( 'ERROR: no frame type available!' ) ;
235+ return 0 ;
236+ }
237+
238+ status = camera . setFrameType ( frameTypes [ 0 ] ) ;
239+ if ( status !== Status . OK ) {
240+ console . log ( 'ERROR: Could not set camera frame type!' ) ;
241+ return 0 ;
242+ }
243+
244+ let modes = [ ] ;
245+ [ status , modes ] = camera . getAvailableModes ( ) ;
246+ if ( ! modes . length ) {
247+ console . log ( 'ERROR: no camera modes available!' ) ;
248+ return 0 ;
249+ }
250+
251+ status = camera . setMode ( modes [ 0 ] ) ;
252+ if ( status !== Status . OK ) {
253+ console . log ( 'ERROR: Could not set camera mode!' ) ;
254+ return 0 ;
255+ }
256+
257+ let frame = new Frame ( ) ;
258+ [ status , frame ] = camera . requestFrame ( ) ;
259+ if ( status !== Status . OK ) {
260+ console . log ( 'ERROR: Could not request frame!' ) ;
261+ return 0 ;
262+ } else {
263+ console . log ( 'INFO: succesfully requested frame!' ) ;
264+ }
265+
266+ // uint16_t *
267+ let frameData ;
268+ [ status , frameData ] = frame . getData ( FrameDataType . FULL_DATA ) ;
269+
270+ if ( status !== Status . OK ) {
271+ console . log ( 'ERROR: Could not get frame data!' ) ;
272+ return 0 ;
273+ }
274+
275+ if ( ! frameData ) {
276+ console . log ( 'ERROR: no memory allocated in frame' ) ;
277+ return 0 ;
278+ }
279+
280+ let fDetails = new FrameDetails ( ) ;
281+ [ status , fDetails ] = frame . getDetails ( ) ;
282+ for ( let i = 0 ; i < fDetails . height ; i ++ ) {
283+ for ( let j = 0 ; j < fDetails . width ; j ++ ) {
284+ console . log ( frameData [ i * fDetails . width + j ] ) ;
285+ }
286+ }
287+
288+ }
289+
290+ // first_frame_network();
291+ </ script >
292+
293+
294+ < body >
295+ < div >
296+ < h1 > AdiTof JS Client </ h1 >
297+ < input id ="ip_input ">
298+ < button onclick ='first_frame_network(document.getElementById("ip_input").value) '> Connect to the camera </ button >
299+ < br >
300+ < br >
301+ <!-- <input id="fun_name_input"> -->
302+ <!-- <button onclick='net.SendCommand();'> Send </button> -->
303+ </ div >
304+ </ body >
305+
306+ </ html >
307+
308+ </ html>
0 commit comments