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

Hinterlasse einen Kommentar