This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Editing mmWave.js inside guicomposer not working

Hello,

I have tried to add a simple node.js code inside <var processRangeDopplerHeatMap = function (bytevec, byteVecIdx, Params)> of the mmWave.js file within <mmWave_Demo_Visualizer> in order to write to a simple string to a file (presumably in the same directory), but no file is created. I have tried it manually and using GUI composer. My final goal is to try to get rangeDoppler matrix without having to write a TLV parser.
Is there a reason why it wouldn't work?

Here is the sample of the modified code

var processRangeDopplerHeatMap = function (bytevec, byteVecIdx, Params) {
    var elapsed_time = {}; // for profile this code only
    var subFrameNum = Params.currentSubFrameNumber;

    if (subFrameNum != Params.subFrameToPlot) return;

    if (Params.guiMonitor[subFrameNum].rangeDopplerHeatMap == 1) {
        var start_time = new Date().getTime();
        // %Get the whole log magnitude range dopppler matrix
        var numBytes = Params.dataPath[subFrameNum].numDopplerBins * Params.dataPath[subFrameNum].numRangeBins * 2;
        var rangeDoppler = bytevec.slice(byteVecIdx, byteVecIdx + numBytes);
        // rangeDoppler = rangeDoppler(1:2:end) + rangeDoppler(2:2:end)*256;
        rangeDoppler = math.add(
            math.subset(rangeDoppler, math.index(math.range(0, numBytes, 2))),
            math.multiply(math.subset(rangeDoppler, math.index(math.range(1, numBytes, 2))), 256)
        );
        rangeDoppler = MyUtil.reshape(rangeDoppler, Params.dataPath[subFrameNum].numDopplerBins, Params.dataPath[subFrameNum].numRangeBins);
        // rangeDoppler = fftshift(rangeDoppler,1);
		
////////////////////////////////////////////////////////////////////////////////////////////////////

		var fs = require("fs");

		var data = "New File Contents";

		fs.writeFile("temp.txt", data, function(err, data) {
		  if (err) console.log(err);
		  console.log("Successfully Written to File.");
		});

////////////////////////////////////////////////////////////////////////////////////////////////////

        rangeDoppler = rangeDoppler.slice((rangeDoppler.length + 1) / 2).concat(rangeDoppler.slice(0, (rangeDoppler.length + 1) / 2));
        var range = math.dotMultiply(math.range(0, Params.dataPath[subFrameNum].numRangeBins - 1, true), Params.dataPath[subFrameNum].rangeIdxToMeters);
        range = math.subtract(range, Params.compRxChanCfg.rangeBias); //correct regardless of state (measurement or compensation)
        math.forEach(range, function (value, idx, ary) {
            ary[idx] = math.max(ary[idx], 0);
        });

        var dopplermps = math.dotMultiply(math.range(-Params.dataPath[subFrameNum].numDopplerBins / 2,
            Params.dataPath[subFrameNum].numDopplerBins / 2 - 1, true),
            Params.dataPath[subFrameNum].dopplerResolutionMps);
            
        templateObj.$.ti_widget_plot3.data[0].x = range.valueOf();
        templateObj.$.ti_widget_plot3.data[0].y = dopplermps.valueOf();
        templateObj.$.ti_widget_plot3.data[0].z = rangeDoppler;
        templateObj.$.ti_widget_plot3.redrawdata();
        
        elapsed_time.rangeDopplerHeatMap = new Date().getTime() - start_time;
    }
    return elapsed_time;
};

  • Hi,
    Try to import this visualizer to your dev.ti.com workspace and find the code snippet which does the writing to a file.
    dev.ti.com/.../

    Regards,
    Jitendra
  • I solved it using sockets. I tried to write to a file from mmWave.js but it did not work. After researching Node.js processes and experimenting with them, i discovered that spawned processes can't print to console or write to a file for reasons I don't know or I am unaware of.

    My solution was to create  a TCP client in nodejs within processRangeDopplerHeatMap  . Here is the new code:

    var processRangeDopplerHeatMap = function (bytevec, byteVecIdx, Params) {
        var elapsed_time = {}; // for profile this code only
        var subFrameNum = Params.currentSubFrameNumber;
    
        if (subFrameNum != Params.subFrameToPlot) return;
    
        if (Params.guiMonitor[subFrameNum].rangeDopplerHeatMap == 1) {
            var start_time = new Date().getTime();
            // %Get the whole log magnitude range dopppler matrix
            var numBytes = Params.dataPath[subFrameNum].numDopplerBins * Params.dataPath[subFrameNum].numRangeBins * 2;
            var rangeDoppler = bytevec.slice(byteVecIdx, byteVecIdx + numBytes);
            // rangeDoppler = rangeDoppler(1:2:end) + rangeDoppler(2:2:end)*256;
            rangeDoppler = math.add(
                math.subset(rangeDoppler, math.index(math.range(0, numBytes, 2))),
                math.multiply(math.subset(rangeDoppler, math.index(math.range(1, numBytes, 2))), 256)
            );
            rangeDoppler = MyUtil.reshape(rangeDoppler, Params.dataPath[subFrameNum].numDopplerBins, Params.dataPath[subFrameNum].numRangeBins);
            // rangeDoppler = fftshift(rangeDoppler,1);
    		
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    
    		var net = require('net');
    
    		var client = new net.Socket();
    		client.connect(65432, '127.0.0.1', function() {
    			client.write(JSON.stringify(rangeDoppler));
    		});
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    
            rangeDoppler = rangeDoppler.slice((rangeDoppler.length + 1) / 2).concat(rangeDoppler.slice(0, (rangeDoppler.length + 1) / 2));
            var range = math.dotMultiply(math.range(0, Params.dataPath[subFrameNum].numRangeBins - 1, true), Params.dataPath[subFrameNum].rangeIdxToMeters);
            range = math.subtract(range, Params.compRxChanCfg.rangeBias); //correct regardless of state (measurement or compensation)
            math.forEach(range, function (value, idx, ary) {
                ary[idx] = math.max(ary[idx], 0);
            });
    
            var dopplermps = math.dotMultiply(math.range(-Params.dataPath[subFrameNum].numDopplerBins / 2,
                Params.dataPath[subFrameNum].numDopplerBins / 2 - 1, true),
                Params.dataPath[subFrameNum].dopplerResolutionMps);
                
            templateObj.$.ti_widget_plot3.data[0].x = range.valueOf();
            templateObj.$.ti_widget_plot3.data[0].y = dopplermps.valueOf();
            templateObj.$.ti_widget_plot3.data[0].z = rangeDoppler;
            templateObj.$.ti_widget_plot3.redrawdata();
            
            elapsed_time.rangeDopplerHeatMap = new Date().getTime() - start_time;
        }
        return elapsed_time;
    };

    And I made a python server that receives the data. Here is an example:


    import socket, json
    
    # Server.py
    HOST = '127.0.0.1'	# Standard loopback interface address (localhost)
    PORT = 65432		# Port to listen on (non-privileged ports are > 1023)
    
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    	s.bind((HOST, PORT))
    	s.listen()
    	conn, addr = s.accept()
    	with conn:
    		print('Connected by', addr)
    		while True:
    			data = conn.recv(1024)
    			print(data)
    			if not data:
    				break
    			conn.sendall(data)