function [] = LabTxtDisplayCanCallback(rxCh)

global CircBuff;
global R_idx;
global MaxSeqNum;
global fileID;
global seq_num_last;
global active_display;

persistent jdx;


SRC_ID = 2;  %Specific to Power Converter

rxMsg = receive(rxCh, Inf);
[srcID, dataID, seq_num] = DecodeCanID(rxMsg);

MaxSeqNum = 0;
%if(~exist('jdx'))
%    disp('jdx doesnt exist');
%    jdx = uint8(0);
%end
if(isempty(jdx))
   jdx = uint8(0); 
end

%Command and Reporting Scale Factors (cnts/engineering unit)
CRSF_RPM = 2;       %cnts per RPM
CRSF_VOLTAGE = 100;  %cnts per Volt
CRSF_CURRENT = 500;  %cnts per Amp
CRSF_TIME  =  1000;  %cnts per Second
CRSF_POWER  = 1;     %cnts per Watt
CRSF_PERCENTAGES = 100;   %cnts per 100 percent
CRSF_PRESSURE = 1000;    %cnts per psi
CRSF_TORQUE = 500;    %cnts per N-m

ID = 0;
idx = find((dataID == ID) & (srcID == SRC_ID));
if(~isempty(idx))
    jdx = bitset(jdx,ID+1);
    CircBuff(seq_num(idx)+1,R_idx.DataIDs) = bitset(CircBuff(seq_num(idx)+1,R_idx.DataIDs),ID+1);
    
    CircBuff(seq_num(idx)+1,R_idx.RPM) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'int16'),'double')/CRSF_RPM;
    CircBuff(seq_num(idx)+1,R_idx.VBus) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16'),'double')/CRSF_VOLTAGE;
    CircBuff(seq_num(idx)+1,R_idx.Iwind) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT; 
    CircBuff(seq_num(idx)+1,R_idx.IBatt) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT;
     
    max_sn = max(seq_num(idx));
    if(max_sn > MaxSeqNum)
        MaxSeqNum = max_sn;
    end
end

ID = 1;
idx = find((dataID == ID) & (srcID == SRC_ID));
if(~isempty(idx))
    jdx = bitset(jdx,ID+1);
    CircBuff(seq_num(idx)+1,R_idx.DataIDs) = bitset(CircBuff(seq_num(idx)+1,R_idx.DataIDs),ID+1);
    CircBuff(seq_num(idx)+1,R_idx.Status) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double');
    CircBuff(seq_num(idx)+1,R_idx.LoadDumpCurrent) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16'),'double')/CRSF_CURRENT;   
    CircBuff(seq_num(idx)+1,R_idx.TargetVoltage) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double')/CRSF_VOLTAGE;   
    CircBuff(seq_num(idx)+1,R_idx.TargetCurrent) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT;

    max_sn = max(seq_num(idx));
    if(max_sn > MaxSeqNum)
        MaxSeqNum = max_sn;
    end
end

ID = 2;
idx = find((dataID == ID) & (srcID == SRC_ID));
if(~isempty(idx))
    jdx = bitset(jdx,ID+1);
    CircBuff(seq_num(idx)+1,R_idx.DataIDs) = bitset(CircBuff(seq_num(idx)+1,R_idx.DataIDs),ID+1);
    CircBuff(seq_num(idx)+1,R_idx.DiffPress) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'int16'),'double')/CRSF_PRESSURE;
    CircBuff(seq_num(idx)+1,R_idx.StdDev) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'int16'),'double')/CRSF_RPM;   
    CircBuff(seq_num(idx)+1,R_idx.ScaleFactor) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'int16'),'double')/CRSF_PERCENTAGES;   
    CircBuff(seq_num(idx)+1,R_idx.RetractFactor) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'int16'),'double')/CRSF_PERCENTAGES;   
    max_sn = max(seq_num(idx));
    if(max_sn > MaxSeqNum)
        MaxSeqNum = max_sn;
    end
end

ID = 3;
idx = find((dataID == ID) & (srcID == SRC_ID));
if(~isempty(idx))
    jdx = bitset(jdx,ID+1);
    CircBuff(seq_num(idx)+1,R_idx.DataIDs) = bitset(CircBuff(seq_num(idx)+1,R_idx.DataIDs),ID+1);
    CircBuff(seq_num(idx)+1,R_idx.AuxTorque) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'int16'),'double')/CRSF_VOLTAGE;
    %CircBuff(seq_num(idx)+1,R_idx.AuxTorque) = 22.5879*(CircBuff(seq_num(idx)+1,R_idx.AuxTorque)-5.0)/5;  %22.6N-m per 10V of sensor, which is 5V of input.
    CircBuff(seq_num(idx)+1,R_idx.BiasCurrent) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT; 
    CircBuff(seq_num(idx)+1,R_idx.ChargeCurrentLimit) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT;   
    CircBuff(seq_num(idx)+1,R_idx.DrawCurrentLimit) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'int16'),'double')/CRSF_CURRENT;   
    max_sn = max(seq_num(idx));
    if(max_sn > MaxSeqNum)
        MaxSeqNum = max_sn;
    end
end

allpackets = bin2dec('0001111');

idx = find(CircBuff(:,R_idx.DataIDs) >= allpackets);

if(jdx == allpackets);
 jdx = uint8(0);
 str{1} = sprintf("%5.1f RPM  %5.2fV %5.2fA  %5.2fA    ",CircBuff(idx(end),R_idx.RPM), CircBuff(idx(end),R_idx.VBus),CircBuff(idx(end),R_idx.Iwind),CircBuff(idx(end),R_idx.IBatt));
 str{2} = sprintf("%s  %5.2fA  %5.1fV  %5.2fA      ",dec2bin(CircBuff(idx(end),R_idx.Status),16), CircBuff(idx(end),R_idx.LoadDumpCurrent),CircBuff(idx(end),R_idx.TargetVoltage),CircBuff(idx(end),R_idx.TargetCurrent));
 str{3} = sprintf("%5.2fpsi  %5.2f RPM  %5.2f  %5.2f    ",CircBuff(idx(end),R_idx.DiffPress), CircBuff(idx(end),R_idx.StdDev),CircBuff(idx(end),R_idx.ScaleFactor),CircBuff(idx(end),R_idx.RetractFactor));
 str{4} = sprintf("%5.2f N-m  %5.2fA  %5.2fA %5.2fA  ",CircBuff(idx(end),R_idx.AuxTorque), CircBuff(idx(end),R_idx.BiasCurrent),CircBuff(idx(end),R_idx.ChargeCurrentLimit), CircBuff(idx(end),R_idx.DrawCurrentLimit));

 str2{1} = sprintf("%5.1f  %5.2f  %5.2f  %5.2f    ",CircBuff(idx(end),R_idx.RPM), CircBuff(idx(end),R_idx.VBus),CircBuff(idx(end),R_idx.Iwind),CircBuff(idx(end),R_idx.IBatt));
 str2{2} = sprintf("%s  %5.2f  %5.1f  %5.2f      ",dec2bin(CircBuff(idx(end),R_idx.Status),16), CircBuff(idx(end),R_idx.LoadDumpCurrent),CircBuff(idx(end),R_idx.TargetVoltage),CircBuff(idx(end),R_idx.TargetCurrent));
 str2{3} = sprintf("%5.2f  %5.2f   %5.2f  %5.2f    ",CircBuff(idx(end),R_idx.DiffPress), CircBuff(idx(end),R_idx.StdDev),CircBuff(idx(end),R_idx.ScaleFactor),CircBuff(idx(end),R_idx.RetractFactor));
 str2{4} = sprintf("%5.2f  %5.2f   %5.2f %5.2f   ",CircBuff(idx(end),R_idx.AuxTorque), CircBuff(idx(end),R_idx.BiasCurrent),CircBuff(idx(end),R_idx.ChargeCurrentLimit), CircBuff(idx(end),R_idx.DrawCurrentLimit));

 
 MechPower = CircBuff(idx(end),R_idx.AuxTorque)*CircBuff(idx(end),R_idx.RPM)*2*pi/60;
 ElecPower = CircBuff(idx(end),R_idx.VBus)*(CircBuff(idx(end),R_idx.LoadDumpCurrent)+CircBuff(idx(end),R_idx.IBatt));
 GeneratorEff = abs(ElecPower)/abs(MechPower);
 MotorEff = abs(MechPower)/abs(ElecPower);
 DerivedQuantities_str = sprintf("%5.2f W  %5.2f W  %5.3f  %5.3f",MechPower,ElecPower,GeneratorEff,MotorEff);
 DerivedQuantities_str2 = sprintf("%5.2f   %5.2f   %5.3f  %5.3f",MechPower,ElecPower,GeneratorEff,MotorEff);

 if(active_display)
   output = datestr(now,'HH:MM:SS.FFF ');
   for i = 1:length(str)
     %disp(str{i}); 
     if(exist('fileID') > 0)
       if(fileID > 2) 
        fprintf(fileID,'%s ',str2{i});
       end
     end
      output = [output sprintf('%s ',str{i})];
   end
   output = [output sprintf('%s ',DerivedQuantities_str)];
   disp(output);
   if(exist('fileID') > 0)
     if(fileID > 2)
       fprintf(fileID,'%s ',DerivedQuantities_str2);
       fprintf(fileID,'\n');
     end
   end
  % fclose(fileID);
 end
 
 seq_num_last = idx(end);
 
 CircBuff(idx,R_idx.DataIDs) = 0;
end