short update 0x0010

hey there, just a short update from my site to keep this blog running. lately I learned much new stuff, but also struggled a bit (I asked a second, I guess more specific question on StackOverflow which was not answered after 5 minutes and wasn’t even yet – so I deleted it after a while; so I would now rate this site from superduperextracool down to very very helpful).

there are just some things that have come to my mind and I want to share with you.

first thing is, I talked about this OSEK tp function to send and receive data recently in some former entrys.

I found this good example from another user from StackOverflow:

„Take a look at the OSEK_TP CANoe demo. It shows how to transmit and receive date over ISO-TP (Transport Protocol, ISO 15765-2). See the nodeA.can file and the OSEL_TP API reference for implementation details.

Here is minimal example:

Create and configure a connection:

long handle;
handle = CanTpCreateConnection(0);    // 0 = Normal mode
CanTpSetTxIdentifier(handle, 0x700);  // Tx CAN-ID
CanTpSetRxIdentifier(handle, 0x708);  // Rx CAN-ID

Send data:

BYTE data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
CanTpSendData(handle, data, elcount(data));

To receive data, you have to implement the following callback function:

void CanTp_ReceptionInd(long connHandle, byte data[])
{
    write("Received %d byte on connection %d: [%02x] ...",
            elcount(data), connHandle, data[0]);
}

You can also check out the „CCI_Implementation.cin“ that should hide somewhere in your CAN (Demo)folders. I think this should do it for the moment.

Another topic is, that for my latest release of simulation to colleagues I thought it was a good idea to create a changelog, to track changes in future. via Google I found this helpful (well, at least a bit funny) site:

keepachangelog .

So if you ever consider writing a changelog, this might be a good start.

Please note also, that I added a link, describing how to go with a CANAlyzer Demo-Version from Vector to test (without license or HW at least), some of the CANoe features (untested).
I hope it works.

 

 

short update 0x0010

meeting the community 0x0009

Dear everybody, yesterday and today were quite successful days for me. Since this is a blog, I will tell you how I first get in touch with programming community in my life (well, that is half the truth, once I registered for an National Instruments Labview forum, but never participated actively). It was quite easy: I registered myself at Stack Overflow, which is some kind of programming community/a platform for Q&A regarding programming questions.

The reason was, I don’t had a clue, how to proceed with the problem I wrote about some entries ago (read a buffer, while buffersize in total exceeds memorysize I can get with one request). I believe there are a lot of elegant solutions, including state machines, while/if/-statements etc, but since I’m a beginner, I prefer to stick with the „solid“ but complicated coding right now. Maybe at some point I have more knowledge to do it in a more efficient way.

So my idea was, registering at Stack Overflow and ask my question(s). Registration was quite easy, and the steps to finally ask my question self describing.

CAPLQ

A very short time after my question, I got really good help from 2 guys (thanks at users @Shark @Lundin):

CAPLA

 

with which help I was able to build my working code (I segregated my memory-read function in [n] functions, where n = triggered from function n-1 via on timer trigger):

 

variables

{
  msTimer ReadReqTimer;
  …
  msTimer ReadReqTimerN;
  int ReadTimeDef = 1000;  // 1 second timer (when used as msTimer as stated above)
 
  byte rqBuffer[256];     // request buffer (Tx data) – 256 bytes
  byte rsBuffer[256];     // receive buffer (Rx data)
  byte rsBuffer1[256];   // help buffer for reiceiving 1
  …
  byte rsBufferN[1024];         // help buffer for receiving N
  char Outputstring[2048];  // array/buffer for output function
  int diagnosticaction = 0;    // value for different diagnosis cases/actions
  dword glbHandle = 0;         // handling of output function
 
}

void Diagnosisrequest ( byte diagnosticaction) /* I have built different cases for different diagnosis actions here */
{
  case  1:   /* case1: read memory */
… /*some code for validation in between*/
        {
 rqBuffer[0] = 0x01;  /* I defined the data transferred with a send request via CAN msg (transport via OSEK fct) */
 rqBuffer[1] = 0x02;  /* this would be data 01 02 03 04 (lets assume this would be a function to read my memory) */
 rqBuffer[2] = 0x03; 
 rqBuffer[3] = 0x04;

         … /*some code for sending this request via OSEK fct*/
 
        setTimer (ReadReqTimer, ReadTimeDef);         
      }

break;
}
on timer ReadReqTimer
{
   if (condition) /* a condition for validation of Response */
     {
          
        /* start last request:   analog you would define your requests 2, 3, 4..n, like how much steps do you need. */
 diagnosticaction = XYZ;  /* see definition below*/
         rqBuf[0] = 0x01;
         rqBuf[1] = 0x02;  
        rqBuf[2] = 0x03;
        rqBuf[3] = 0x05; /* this would be data 01 02 03 05 (lets assume this would be a function to read another part of memory) */      

         … /*some code for sending this request via OSEK fct
       setTimer ( ReadReqTimer1, ReadTimeDef);  // set next timer … ReadReqTimer1, 2, … n
       
     }
}
void handleResponse
{
 switch(diagnosticaction)
     {
    case  0: /*some other case, e.g. no action*/
    break;
  case  1:  /* read memory */
   if (rsBufer[0] == 0xXYZ)  // XYZ would be a hex-number (e.g. 01), for checking a valid incoming response message
           {
           memcpy(rsBuffer1, rsBuffer, 1024);
            }
   else if (condition)
doSomethingorDoNothing;
   break;   // brake statement, this is important to terminate case
 
     
     
      case XYZ:  /* our latest case for memory-read – copy together the buffer from former response Buffers and print it to a file (see also former blogentry) */
       if (rsBufer[0] == 0xXYZ)   /* XYZ would be a hex-number (e.g. 01), for checking a valid incoming response message */
           {
            memcpy(rsBufferN, rsBuffer, 1024);
            glbHandle = openFileWrite („filename.txt“,0);   /* Format and print buffer data */
            snprintf(Outputstring, elcount(Outputstring), „memory read:  %02X %02X %02X % 02X %02X %02X\n“, rsBuffer1[1], rsBuffer1[…], rsBuffer1[n], rsBufferN[1], rsBufferN[…], rsBufferN[n]);
    filePutString (Outputstring, elcount(Outputstring),glbHandle);
    fileClose(glbHandle);
   }
   else if (condition)
   doSomethingorDoNothing;
   break;   /* brake statement, this is always important to terminate case */

       }
}

 

 

 

 

meeting the community 0x0009

receive one Msg, send another Msg 0x0008

Hello everybody,

in the last days I was working more on other things, but now I just returned for some more small CAPL action.

For first time I had the problem to send a CAN Msg, when I receive another CAN-Msg (because for the moment, most of my diagnosis node based on: sending a request/Msg — data will be send (Request/Tx) and received (Response/Rx) via OSEK function–> analyze the Rx data)

I knew which data this should be (I looked for it in the trace), because I wanted to actively send it from a node as a substitute CAN frame for another node I deactivated, and where this signal originally comes from.

You can also find some help for this in the ‚ ProgrammingWithCAPL ‚ by chapter 11.3.

so lets say in trace I have seen, that I want to transmit data with ID 789, Data DLC is 4 and data is 0x01 0x02 0x03 0x04. Than one solution would be the following:

variables  /* declare Msg in the variables section */

{

message 0x789 myNewMsg = {dlc = 4};

}

on message TriggerMsg /*as you know, CAPL is not time- but event based. For trigger, in this case I choose another CAN Msg, that should be there if my new signal is also there; „on message“ is a CAPL function, „TriggerMsg“ is a example-name */

{

 myNewMsg.byte(0)= 0x01;

 myNewMsg.byte(1)= 0x02;

 myNewMsg.byte(2)= 0x03;

 myNewMsg.byte(3)= 0x04;

output(myNewMsg);

}

 

 

 

 

receive one Msg, send another Msg 0x0008