ILD file to Json

I am designing an RGB LASER system controlled with an RPI 3B + and Node-Red.
On the internet I found 'https://github.com/possan/ilda.js/tree/master'

Can someone help me further?

This is in the function node:

var file = msg.payload;
var back = {};
var ArrayReader = function(bytes) {
	this.bytes = bytes || [];
	this.position = 0;
	this.length = this.bytes.length;
}

ArrayReader.prototype.seek = function(p) {
	this.position = p;
}

ArrayReader.prototype.eof = function() {
	return this.position >= this.length;
}

ArrayReader.prototype.readString = function(length) {
	var s = '';
	for(var i=0; i<length; i++) {	
		var b0 = this.readByte();
		if (b0 > 0 && b0 < 0x7F)
			s += String.fromCharCode(b0);
	}
	return s.trim();
}

ArrayReader.prototype.readByte = function() {
	var b = this.bytes[this.position];
	this.position ++;
	return b;
}

ArrayReader.prototype.readShort = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	return (b0 << 8) + b1;
}

ArrayReader.prototype.readSignedShort = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	var s = (b0 << 8) + b1;
	if (s > 32768)
		s = -(65535-s);
	return s;
}

ArrayReader.prototype.readLong = function() {
	var b0 = this.readByte();
	var b1 = this.readByte();
	var b2 = this.readByte();
	var b3 = this.readByte();
	return b3 + (b2<<8) + (b1<<16) + (b0<<24);
}

var Reader = {};

Reader.fromByteArray = function(arr, callback) {
	var i;
	var f = msg.payload;//new File();
	var p = new ArrayReader(arr);
	while (!p.eof()) {
		// read frame.
		var head = p.readString(4);
		if (head != 'ILDA')
		 	break;
		var section = new Section();
		section.type = p.readLong();
		switch(section.type) {
			case SectionTypes.THREE_DIMENSIONAL:
				// 3D frame
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				section.total = p.readShort();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var point = new Point();
					point.x = p.readSignedShort();
					point.y = p.readSignedShort();
					point.z = p.readSignedShort();
					var st = p.readShort();
					point.color = (st >> 0) & 0x7F; 
					point.blanking = (st & BlankingBit) == BlankingBit;
					point.last = (st & LastBit) == LastBit;
					section.points.push(point);
				}
				break;
			case SectionTypes.TWO_DIMENSIONAL:
				// 2D frame
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				section.total = p.readShort();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var point = new Point();
					point.x = p.readSignedShort();
					point.y = p.readSignedShort();
					var st = p.readShort();
					point.color = (st >> 0) & 0x7F; 
					point.blanking = (st & BlankingBit) == BlankingBit;
					point.last = (st & LastBit) == LastBit;
					section.points.push(point);
				}
				break;
			case SectionTypes.COLOR_TABLE:
				// color table
				section.name = p.readString(8);
				section.company = p.readString(8);
				var np = p.readShort();
				section.index = p.readShort();
				p.readByte();
				p.readByte();
				section.head = p.readByte();
				p.readByte();
				for (var i=0; i<np; i++) {
					var color = new Color();
					color.r = p.readByte();
					color.g = p.readByte();
					color.b = p.readByte();
					section.colors.push(color);
				}
				break;
			case SectionTypes.TRUECOLOR_TABLE:
				// truecolor points
				var _len = p.readLong();
				var np = p.readLong();
				for(var i=0; i<np; i++) {
					var color = new Color();
					color.r = p.readByte();
					color.g = p.readByte();
					color.b = p.readByte();
					section.colors.push(color);
				}
					break;
		}
		f.sections.push(section);
	}
	callback(f);
};

msg.payload = reader(file);
return msg;

Hint: Case will always get you -now go look at the error message and your code

Stupid of me.
I modified that line, but now I get the following error: 'TypeError: Reader is not a function'

what are you trying to return? using
msg.payload = Reader(file);
is saying 'set msg.payload to the value returned by the function Reader that is being sent what is in the variable file

The intention is to convert from the ILD file to JSON file, classified point by point with data x, y, r, g, b

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.