Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
Signed-off-by: Timotei Molcut <timotei.molcut@analog.com>
  • Loading branch information
tmanalog committed Jul 12, 2022
1 parent af02f8e commit 20fba1b
Show file tree
Hide file tree
Showing 6 changed files with 1,243 additions and 1,178 deletions.
172 changes: 90 additions & 82 deletions sdk/src/connections/network_javascript/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,107 +107,111 @@

// main();

async function first_frame_network() {
async function first_frame_network(ip_address) {
let status;

console.clear();
console.log('\n\n\n\n');
console.log('Hello World! ... First frame network running ... ');

const ip_address = '192.168.0.106';
// const ip_address = '10.42.0.65';

let net = new Network(ip_address);
status = await net.ServerConnect();

var nse = new NetworkSensorEnumerator(net);
status = await nse.searchSensors();
// let net = new Network(ip_address);
// status = await net.ServerConnect();

console.log(nse);
// var nse = new NetworkSensorEnumerator(net);
// status = await nse.searchSensors();

let depth_sensor = nse.getDepthSensors()[1][0];
let storage = nse.getStorages()[1][0];
let temp_sensor = nse.getTemperatureSensors()[1][0];
// console.log(nse);

console.log(depth_sensor);
console.log(storage);
console.log(temp_sensor);
// let depth_sensor = nse.getDepthSensors()[1][0];
// let storage = nse.getStorages()[1][0];
// let temp_sensor = nse.getTemperatureSensors()[1][0];

let address, data, length, bytesCount;
// console.log(depth_sensor);
// console.log(storage);
// console.log(temp_sensor);

//depth sensor
console.log('');
console.log('depth sensor testing');
console.log('');
// let address, data, length, bytesCount;

console.log('opened: ', depth_sensor.m_opened);
status = await depth_sensor.open();
console.log('status open: ', status, depth_sensor.m_opened);
// //depth sensor
// console.log('');
// console.log('depth sensor testing');
// console.log('');

let firmware, size;
firmware = 'asd';
size = 3;
status = await depth_sensor.program(firmware, size);
console.log('status program: ', status);
// console.log('opened: ', depth_sensor.m_opened);
// status = await depth_sensor.open();
// console.log('status open: ', status, depth_sensor.m_opened);

// doesn 't work
// status = await depth_sensor.start();
// console.log('status start: ', status);
// let firmware, size;
// firmware = 'asd';
// size = 3;
// status = await depth_sensor.program(firmware, size);
// console.log('status program: ', status);

[status, details] = await depth_sensor.getAvailableFrameTypes();
console.log('status getAvailableFrameTypes: ', status);
// // doesn 't work
// // status = await depth_sensor.start();
// // console.log('status start: ', status);

status = await depth_sensor.setFrameType(new Object());
console.log('status setFrameType: ', status);
// [status, details] = await depth_sensor.getAvailableFrameTypes();
// console.log('status getAvailableFrameTypes: ', status);

// doesn 't work
// status = await depth_sensor.getFrame();
// console.log('status getFrame: ', status);
// status = await depth_sensor.setFrameType(new Object());
// console.log('status setFrameType: ', status);

address = "asd";
data = "qwe";
length = 3;
status = await depth_sensor.writeAfeRegisters(address, data, length);
console.log('status writeAfeRegisters: ', status);
// // doesn 't work
// // status = await depth_sensor.getFrame();
// // console.log('status getFrame: ', status);

status = await depth_sensor.readAfeRegisters(address, data, length);
console.log('status readAfeRegisters: ', status);
// address = "asd";
// data = "qwe";
// length = 3;
// status = await depth_sensor.writeAfeRegisters(address, data, length);
// console.log('status writeAfeRegisters: ', status);

status = await depth_sensor.stop();
console.log('status stop: ', status);
// status = await depth_sensor.readAfeRegisters(address, data, length);
// console.log('status readAfeRegisters: ', status);

//storage
console.log("");
console.log('storage testing');
console.log("");
// status = await depth_sensor.stop();
// console.log('status stop: ', status);

status = await storage.open();
console.log('status open: ', status);
// //storage
// console.log("");
// console.log('storage testing');
// console.log("");

address = 1;
data = new Uint8Array();
bytesCount = 3;
status = await storage.write(address, data, bytesCount);
console.log('status write: ', status);
// status = await storage.open();
// console.log('status open: ', status);

[status, data] = await storage.read(address, bytesCount);
console.log('status read: ', status);
// address = 1;
// data = new Uint8Array();
// bytesCount = 3;
// status = await storage.write(address, data, bytesCount);
// console.log('status write: ', status);

status = await storage.close();
console.log('status close: ', status);
// [status, data] = await storage.read(address, bytesCount);
// console.log('status read: ', status);

// status = await storage.close();
// console.log('status close: ', status);

//temperature sensor
console.log('');
console.log('temp sensor testing');
console.log('');

status = await temp_sensor.open();
console.log('status open: ', status);
// //temperature sensor
// console.log('');
// console.log('temp sensor testing');
// console.log('');

// status = await temp_sensor.open();
// console.log('status open: ', status);

// [status, temp] = await temp_sensor.read();
// console.log('status read: ', status);

// status = await temp_sensor.close();
// console.log('status close: ', status);

[status, temp] = await temp_sensor.read();
console.log('status read: ', status);

status = await temp_sensor.close();
console.log('status close: ', status);

let system = new System();
let cameras = [];

Expand Down Expand Up @@ -260,35 +264,38 @@
}

// uint16_t *
let data1;
[status, data1] = frame.getData(FrameDataType.FULL_DATA);
let frameData;
[status, frameData] = frame.getData(FrameDataType.FULL_DATA);

if (status !== Status.OK) {
console.log('ERROR: Could not get frame data!');
return 0;
}

// if (!data1) {
// LOG(ERROR) << "no memory allocated in frame";
// return 0;
// }
if (!frameData) {
console.log('ERROR: no memory allocated in frame');
return 0;
}

let fDetails = new FrameDetails();
[status, fDetails] = frame.getDetails();
for (let i = 0; i < fDetails.width * fDetails.height; ++i) {
console.log(data1[i], end=' ');
for (let i = 0; i < fDetails.height; i++) {
for (let j = 0; j < fDetails.width; j++) {
console.log(frameData[i * fDetails.width + j]);
}
}

}

first_frame_network();
// first_frame_network();
</script>


<body>
<div>
<h1> AdiTof JS Client </h1>
<!-- <input id="ip_input"> -->
<!-- <button onclick='net.ServerConnect(document.getElementById("ip_input").value || ip_address)'> Connect to camera </button> -->
<input id="ip_input">
<button onclick='first_frame_network(document.getElementById("ip_input").value || ip_address)'> Connect to camera </button>
<br>
<br>
<!-- <input id="fun_name_input"> -->
Expand All @@ -298,3 +305,4 @@ <h1> AdiTof JS Client </h1>

</html>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {

console.log("status: " + status + "\ncameraType: " + cameraType);

this.m_cameraType = cameraType;
return [status, cameraType];
}

Expand All @@ -88,6 +89,10 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
console.log(`ERROR: invalid connection string: ${connectionString}`);
return Status.GENERIC_ERROR;
}


console.log('before getCameraType()');

[status, this.m_cameraType] = await this.getCameraType();
if (status !== Status.OK) {
console.log("WARNING: Failed to find out the camera type on target. Assumming it's camera: AD-96TOF1-EBZ");
Expand All @@ -98,6 +103,8 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
this.m_network.send_buff.setFuncName("FindSensors");
this.m_network.send_buff.setExpectReply(true);

console.log('before findSensor call');

if ((await this.m_network.SendCommand()) !== 0) {
console.log("WARNING: Send Command Failed");
return Status.INVALID_ARGUMENT;
Expand All @@ -108,6 +115,8 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
return Status.GENERIC_ERROR;
}

console.log('after findSensors');

const sensorsInfo = this.m_network.recv_buff.getSensorsInfo();
let name, id;
for (let i = 0; i < sensorsInfo.getImageSensorsList().length; i++) {
Expand All @@ -128,7 +137,9 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
this.m_temperatureSensorsInfo.push({ name, id });
}

return this.m_network.recv_buff.getStatus();
let val = this.m_network.recv_buff.getStatus();
console.log('val: ', val);
return val;
}

getDepthSensors() {
Expand Down Expand Up @@ -166,10 +177,18 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
let storages = [];
let storage;
let status = Status.OK;
let i = 0;
console.log('the storages are: ');
for (const nameAndId of this.m_storagesInfo) {
// if (i == 0)
// continue;
let { name, id } = nameAndId;
console.log('name: ', name, 'id: ', id);

storage = new NetworkStorage(name, id, this.m_network);
storages.push(storage);
console.log(i + ' --- ' + storages[i].getName());
i++;
}

return [status, storages];
Expand All @@ -192,5 +211,4 @@ class NetworkSensorEnumerator extends SensorEnumeratorInterface {
return [Status.OK, this.m_cameraType];
}
}
window.NetworkSensorEnumerator = NetworkSensorEnumerator;

window.NetworkSensorEnumerator = NetworkSensorEnumerator;
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ class NetworkStorage extends StorageInterface {
return status;
}
getName() {
return [Status.OK, this.m_name];
return this.m_name;
}

}

window.NetworkStorage = NetworkStorage;

window.NetworkStorage = NetworkStorage;
Loading

0 comments on commit 20fba1b

Please sign in to comment.