Emulator GUI - Disable PIDs bug [resolved]

Inquiry and support for Freematics products
Post Reply
rhobison
Posts: 1
Joined: Sat Aug 27, 2016 5:22 am

Emulator GUI - Disable PIDs bug [resolved]

Post by rhobison »

There is a bug on the emulator GUI (v1.0.4) code when enable/disable PIDs.
Depending on what PIDs are disabled/enabled, the AT command for the operation is generated incorrectly.
For example, the GUI generates the following command when some combination of enable/disable PIDs of the page "Throttle" is done:

Code: Select all

ATSET 0140=91,3,bf,a3


The correct AT command would be "ATSET 0140=91,03,bf,a3" (added a leading 0 on the second byte).
I managed to track the bug on the function togglePID(), contained in the file emulator.js.
Below is the corrected function:

Code: Select all

function togglePID(pid, enabled)
{
   var i = parseInt(pid, 16) & 0xff;
   pidDisabled[i] = !enabled;
   var specialPid = i & 0xE0;
   var val = 0;
   var vals = "";
   var pidTmp = specialPid + 1;
   var valHex;
   for (m = 0; m < 4; m++) {
      val = 0;
      for (n = 1; n <= 8; n++) {
         val <<= 1;
         if (!pidDisabled[pidTmp++]) val |= 1;
      }
      // vals += val.toString(16) + ",";  <-- toString(16) does not add leading zero in case val < 0x10
      
      // Corrected code. Always add a leading zero and do substr if necessary.
      valHex = ( "0" + val.toString(16) );
      vals += ( ( valHex.length > 2 ) ? valHex.substring(1) : valHex ) + ",";
   }
   specialPid |= 0x100;
   var cmd = "ATSET 0" + specialPid.toString(16) + "=" + vals.substr(0, vals.length - 1);
   if (!sendCommand(cmd)) {
      alert("Unable to set PID " + specialPid.toString(16));
      return false;
   } else {
      alert("PID " + pid + " is " + (enabled ? "enabled" : "disabled"));
   }
}


I am not a JavaScript expert, so if there is a better way to do this, feel free to comment.

[]'s
Rhobison Alves Pereira
sagar0810
Posts: 6
Joined: Wed Jun 14, 2017 12:30 am

Re: Emulator GUI - Disable PIDs bug [resolved]

Post by sagar0810 »

Hi rhobison,

Is there any command available which can be used to enable/disable PID like other AT cmd to set PID values, Clear DTC. Using GUI this functinality is achieved but what if i want to do it programmatically.

Thanks in advance.
sagar0810
Posts: 6
Joined: Wed Jun 14, 2017 12:30 am

Re: Emulator GUI - Disable PIDs bug [resolved]

Post by sagar0810 »

Hi rhobison,

Is there any direct AT command which can be used to disable a PID specifying PID value in HEX with enable or disable parameter.
Or we have to use same logic as defined in your GUI software source code.

Thanks in advance.
Post Reply