0

I am new to POS programming using C language. I want to loop through the returned hex data and also print it to the screen after sending the APDU command and getting a response. Here is my main problem requirements.

  1. First I elect the EMV Application using PSE method 1PAY.SYS.DD01

  2. I read the record of the PSE which returns me the AID

  3. I select the AID currently I'm using cards with VISA AIDs (A0 00 00 00 03 10 10 and A0 00 00 00 03 20 10) 3.I read the record of the AID interestingly for the first AID, it returns the magnetic stripe info without using GPO command first while the second one for some cards it requires them so I next get the GPO to process it

  4. I then read the records from the card. The problem is I am outputting this byte info so its easy for me to track what's going on but the POS terminal I am using can only output a given number of characters on the screen. First I have space for 18 bytes, then I can have up to maximum of 35 bytes to display after clearing the screen everytime the user presses the arrow down button.

  5. To do this, I used some variables below

    int variab = 0,
        offset = 18,
        remainingBytes = apduResp.LenOut - 18,
        limit = apduResp.LenOut,
        AIDChooser = 0;    // To track output data scroll
    
    // option
    if (apduResp.LenOut == 0)
    {
        offset = 0;
        remainingBytes = 0;
        limit = 0;
    }
    else if (apduResp.LenOut > 0)
    {
        int variab = 0,
            offset = 18,
            remainingBytes = apduResp.LenOut - 18,
            limit = apduResp.LenOut,
            AIDChooser = 0;
    }
    

    Then I put the code below in a loop that runs while the arrow down key is pressed I read all the data and this is what it is supposed to do

i) Read all response bytes and the length
ii) check if the remaining bytes are more than 35, add 35 to the loop offset and then print the next 35 up to the limit which is (offset + 35). and if the remaining bytes are less than 35, print them out and stop.
The problem is when the intial data length is 0, pressing the scroll button doesn't show subsequent data but if the initial response data is greater than zero, the function works as required, can anyone figure out what I'm doing wrong?

if (remainingBytes > 35)
{
    limit = offset + 35;
    for (i_sn = offset; i_sn < limit; i_sn++)
    {
        sn_display += sprintf(sn_display, "%02X ", `apduResp.DataOut[i_sn]);
        TP_LcdPrintf(" %s", te);
    }

    offset = limit;             // Change
    // offset
    remainingBytes = apduResp.LenOut - limit;   // Reduce
    // remaining bytes
}

else if (remainingBytes == 0)
{
    TP_LcdPrintf(" %s", " No more data\n  Press Cancel to\n  return");
}
else if (remainingBytes > 0 && remainingBytes < 35)
{
    for (i_sn = offset; i_sn < apduResp.LenOut; i_sn++)
    {
        sn_display += sprintf(sn_display, "%02X ", apduResp.DataOut[i_sn]);
        TP_LcdPrintf(" %s", te);
    }
    offset = limit;
    remainingBytes = apduResp.LenOut - limit;
}
////indent: Standard input:32: Error:Stmt nesting error.
}
lurker
  • 56,987
  • 9
  • 69
  • 103
  • 2
    I'm sorry but your Monte Carlo approach to code formatting code has made it quite difficult to read. Try Google searching "C code formatting conventions" and tidy it up. You'll get more positive responses here if you do. If you're on a Linux machine, see `man indent`. – lurker Nov 20 '15 at 16:14
  • I have edited it again please check @lurker but yo didn't have to downvote me I am new to using stackoverflow maybe helping me format the code was a better courtsey thanks – Chris N. Tyler Nov 20 '15 at 16:23
  • I did not downvote you. Someone else did. Probably for some of the reasons I gave. I was just providing some advice. Your code is still as messy as it was before, by the way. ;) – lurker Nov 20 '15 at 16:37
  • 2
    OK, I reformatted your code for you using `indent` (which is what I recommended). `indent` identified some statement syntax issues (I left it in as a comment). Besides that, in the first block of code you have under #5, you have some variables you are initializing in the `else` part of an `if` statement that are declared, initialized, but then never used. So their values will not be "seen" outside of that `if` statement block because their scope is all inside `else { ... }` – lurker Nov 20 '15 at 16:57
  • 1
    @lurker thanks it finally worked and thanks for the formatting. Its really tidy as well. can you just add that as an answer so I can accept it? – Chris N. Tyler Nov 23 '15 at 08:38

1 Answers1

0

… in the first block of code you have under #5, you have some variables you are initializing in the else part of an if statement that are declared, initialized, but then never used. So their values will not be "seen" outside of that if statement block because their scope is all inside else { ... } – lurker

Armali
  • 18,255
  • 14
  • 57
  • 171