cortex-debug icon indicating copy to clipboard operation
cortex-debug copied to clipboard

Example of advanced decoder

Open diggit opened this issue 7 years ago • 15 comments

Hi, could you provide some small example of "advanced" decoder? Can such decoder send output only to plots or even to console?

diggit avatar Nov 02 '18 23:11 diggit

I do have one on my side, will try to package it up and document it on the wiki soon.

Marus avatar Jan 20 '19 15:01 Marus

Could you please provide any example? I am not javascript pro and reverse engineering what should decoder class look like is quite difficult for me...

diggit avatar Oct 04 '19 21:10 diggit

Hi @Marus @haneefdm, do you have some working advanced decoder or Docs for it? I'd really love to decode some traces.

diggit avatar Apr 06 '20 09:04 diggit

I'll try to write up one of my examples that I have later this week. It uses data transferred in a protocol buffer format.

On Mon, Apr 6, 2020 at 6:50 AM Patrik Bachan [email protected] wrote:

Hi @Marus @haneefdm, do you have some working advanced decoder or Docs for it? I'd really love to decode some traces.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

-- Marcel Ball [email protected]


The purpose of writing is to inflate weak ideas, obscure pure reasoning, and inhibit clarity. With a little practice, writing can be an intimidating and impenetrable fog! - Calvin

Marus avatar Apr 06 '20 14:04 Marus

@Marus any chance to get some example? :blush:

diggit avatar Jun 16 '20 08:06 diggit

Hi @Marus, that sounds really useful, I'd be very interested in this as well. Anything we can do to help?

mcejp avatar Oct 06 '20 18:10 mcejp

Hope to be answered

abc528 avatar Apr 16 '21 09:04 abc528

This is what I see...

https://github.com/Marus/cortex-debug/wiki/SWO-Output

haneefdm avatar Apr 16 '21 09:04 haneefdm

Hint for (me) writing the documentation for this. The Advanced decoder must implement the interface defined in https://github.com/Marus/cortex-debug/blob/eda3058e580f70af9b512d0c2307a97d8d70ecd6/src/frontend/swo/common.ts#L87 and then it should be enough to set the path to this javascript implementation (file, module) into the "decoder" option + setting the "ports" option. "config" can be used to send a JSON object into init function for custom config properties.

PhilippHaefele avatar Jan 05 '22 22:01 PhilippHaefele

Hello, this topic is still actual for me, do you have any template for this?

kusstas avatar Dec 29 '22 17:12 kusstas

Hi for me is this topic still important, I did the following:

  • setup the config in lauch.json
  • created a decoder .ts file transpiled then in js

premise:

  • I first time i try to integrate somethings in vscde
  • beginner in .js .ts...

launch.json

...
"rttConfig": {
  "enabled": true,
  "address": "auto",
  "decoders": [
    {
      "port": 0,
      "type": "console",
      "label": "RTT Channel 0"
    },
    {
      "ports":[0],
      "type": "advanced",
      "decoder": "${workspaceFolder}/extern/debug_rtt/advancedecoder/decoder.js",
      "config":{
        "ports":[0],
        "type": "advanced",
        "var1":"this is var 1.",
        "graphid":"id"
      },
    },
  ]
},
...

decoder.ts

import * as vscode from 'vscode';
import { SWOAdvancedDecoderConfig } from './common';
import { AdvancedDecoder } from '../common';
import * as fs from 'fs';


class MYAdvancedDecoder implements AdvancedDecoder {
    private output:(output: string)=>void;
    private cc:number;
    private count:number;
    private graphId: string;


    init(
        config: SWOAdvancedDecoderConfig,
        outputData: (output: string) => void,
        graphData: (data: number, id: string) => void):void
        {
            this.output=outputData;
            this.count=0;
            this.cc=10;
            this.graphId=config.graphId;
        }
    
    public softwareEvent(port:number,data: Buffer) {
        this.count++;
        this.output(`${this.count},${data.length}: ${data.buffer}\n`);
    }

    public synchronized() {}
    public lostSynchronization() {}
    public typeName():string{return "advanced";};
    public outputLabel(): string{return "rtt";}
}

export default MYAdvancedDecoder;

remarks

  • As proof of concept it is working. I see the output of this.output('${this.count},${data.length}: ${data.buffer}\n'); in the OUTPUT terminal.

but

  • this.output can not be used in init method because is uninitialized. I dont'know if it was designed to do so...what is exactly the meaning of using OUTPUT vs. TERMINAL
  • at any new start a new OUTPUT is created, the old remain in the list...how can i close the OUTPUT?
  • Some Hints where to start using a terminal instead of OUTPUT?

e-sr avatar Mar 01 '23 12:03 e-sr

@e-sr Would you mind editing the Wiki and adding a section for this topic. Thnaks btw.

https://github.com/Marus/cortex-debug/wiki/SWO-Output

Question though, you have references to items from ./common. Did, you make a copy of our common.ts file? People may want to know how you compiled your ts in js. You can attach a tar.gz file of your sample project if you like.

I have never looked at this area myself, but some comments

s proof of concept it is working. I see the output of this.output('${this.count},${data.length}: ${data.buffer}\n'); in the OUTPUT terminal.

Not sure what you mean. Do you have a screenshot? What is an OUTPUT terminal. It appears it is going to an OutputChannel (one of the items in the OUTPUT tab) which is not a terminal. This was written in the days when Terminals were not flexible. When I ported almost everything to start using Terminals, I did not touch this part as I did not have an example project.

The idea I think is that you are given callbacks/functions to either outputData text information or call graphData for graphing or none. It is up to you how you transform the data arriving via the softwareEvent. You can save the data to a csv file also for instance or stream to another program. Everytime we get data on this port, an event is generated and you are supposed to use it for your own purposes. I don't think you are required to call the output function either.

this.output can not be used in init method because is uninitialized. I dont'know if it was designed to do so...what is exactly the meaning of using OUTPUT vs. TERMINAL

Depends on the version of the TS compiler. It is getting stricter and stricter. I would have a constructor or declare things like this if you want to avoid a constructor. I believe this was written when Typescript did not allow constructors on interfaces

    private output: (output: string)=>void | undefined;
    private cc = 0;
    private count = 0 ;
    private graphId = '';

And then you might get a warning/error on the following line, you can change it to the following

        this?.output(`${this.count},${data.length}: ${data.buffer}\n`);

I believe you are supposed to use the id you are given. Not sure.

            this.graphId = id;

haneefdm avatar Mar 01 '23 15:03 haneefdm

I will look into redirecting the OUTPUT to a terminal if you are willing to test it. Yes, opening new windows is also problematic. What I might do is to create the terminal on your first output to that terminal in case you never use it. Once created, it will be cleared for every new use and will just stay there until closed.

haneefdm avatar Mar 01 '23 15:03 haneefdm

@haneefdm will try to get it working properly and then if the case i will update the documentation. But i will need some time... yes of curse with OUTPUT terminal i mean the output tab.

e-sr avatar Mar 02 '23 08:03 e-sr

@diggit

I recently made a TraceDecoder that can parse a variety of mixed data types from one or more channels and display it on real time graph.

You can take a look at the decoder implementation as an example. The repository is also based on TypeScript and complies to JS. This can be a good example for those who wants to setup a more complex project.

Also, I encountered an issue in the base AdvancedDecoder that prevents graph data being sent to the actual graph. The fix was trivial. You can find the fix in #961

Hopefully this helps.

aq1018 avatar Nov 28 '23 03:11 aq1018