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.

CCS: UART Custom Codec streaming data continuously

Tool/software: Code Composer Studio

My javascript knowledge is limited so I don't know how to do what I am trying to achieve. When I used the USB UART Monitor protocol, it was very easy to bind the GUI parameters to my target Global variables. And anything that changed on either side, GUI or target, updated on the other side. Now I would like to do the same but using the USB UART Custom Codec streaming protocol. I would like to continuously send a packet of binary data to my target, and the target will respond on receiving a packet. For instance, the packet of data that I want to send is parameters from my gui (StartTest, SystemType, TestType) that is bind to the ti_model_streaming. I added a new Custom codec JS file and here is my custom codec encode and decode functions:

document.addEventListener('gc-databind-ready', function() {
    

    CustomCodec = function() {};
    CustomCodec.prototype = new gc.databind.IPollingPacketCodec();
    CustomCodec.prototype.rxPktCtr = 0;
    CustomCodec.prototype.rxMsgCtr = 0;
    CustomCodec.prototype.txPktCtr = 0;
    CustomCodec.prototype.txMsgCtr = 0;
    CustomCodec.prototype.strRxBuffer = "";
    CustomCodec.prototype.strTxBuffer = "";
    CustomCodec.prototype.isConnected = false;
    CustomCodec.prototype.initComplete = false;
    CustomCodec.prototype.templateObj = undefined;
    

    CustomCodec.prototype.encode = function(target, jsonObj) {
        this.txPktCtr++;
    

       try{
            this.txMsgCtr++;
            if (this.txMsgCtr % 256){
                gc.console.log("CustomCodec","Number of tx messages to target: "+this.txMsgCtr);
            }
            
            var dataToSend = []; //JSON.stringify(jsonObj) +"\n";
            dataToSend.push(0x55); //startbyte
            dataToSend.push(jsonObj.StartTest);
            dataToSend.push(jsonObj.SystemType);
            dataToSend.push(jsonObj.TestType);
           
    
            // send the string to the target
            target(dataToSend);
            } catch (ex) {
                console.log("CustomCodec.encode (to target): exception=" + ex);
            }
    
    };

    CustomCodec.prototype.decode = function(target, data) {
        this.isConnected = true;
        this.rxPktCtr++;
    

        var StartByte = data[0];
        var jsonObj = {
        CycleCounter: data[1],
        StartTest: data[2],
        DataRecieved: data[3]
        }
                
        target(jsonObj);
    
        // Return true to set the 'Hardware Connected' status in the status bar
        return this.isConnected;
    
    };

I am able to send the packet to my target, but I have tow problems.

Firstly, the packet only gets send when I click on something on the gui. I guess this is because the encode function is inside an eventlistener, document.addEventListener('gc-databind-ready', function() that reacts on some GUI event. But how can I send the packet of data independent of the GUI events, continuously at an interval of 1ms for instance?

Secondly, when the packet is sent, only the value of the parameter that was changed (clicked on) is sent to my target, the other parameters shows "undefined" in my debug watch window and at the target.

In other words, I would like to synchronously send all the binded parameters from my GUI to the target and the target will respond. The data received I want to again bind to the Gui and display. How can I do this?

  • Hello Albert,

    UART Monitor is a polling model, the GC framework runs on a loop to read target variables from host to target. On the other hand, UART Streaming is a pushing model and data need to be pushed from the target to the host.

    Albert Smit23 said:

    Firstly, the packet only gets send when I click on something on the gui. I guess this is because the encode function is inside an eventlistener, document.addEventListener('gc-databind-ready', function() that reacts on some GUI event. But how can I send the packet of data independent of the GUI events, continuously at an interval of 1ms for instance?

    You can use the setInterval API to continuously push data from host to target. See www.w3schools.com/.../met_win_setinterval.asp

    Albert Smit23 said:

    Secondly, when the packet is sent, only the value of the parameter that was changed (clicked on) is sent to my target, the other parameters shows "undefined" in my debug watch window and at the target.

    In other words, I would like to synchronously send all the binded parameters from my GUI to the target and the target will respond. The data received I want to again bind to the Gui and display. How can I do this?

    GC call the encode function if it detects a change in any on of the bounded variable. To do a batch operation, cache the variables' last know value in the decode function. In the encode function, overwrite the cached value with the new value. And send all the cached values to the target.
    Regards,
    Patrick