function [] = CanCallback(rxCh)

global CircBuff;
global S_idx;
global RecentSeqNum;
global RecentSeqNum_ID0;
global RecentSeqNum_ID1;
global RecentSeqNum_ID2;
global RecentSeqNum_ID3;
global RecentSeqNum_PS_ID0;
global RecentSeqNum_PS_ID1;
global RecentSeqNum_PS_ID2;
global RecentSeqNum_BC_ID1;


%disp('Can msg recieved');

rxMsg = receive(rxCh, Inf);
[srcID, dataID, seq_num] = DecodeCanID(rxMsg);
idx = find(srcID == SourceID());
if(~isempty(idx))
  RecentSeqNum = max(seq_num(idx));  
end

idx = find((dataID == 0) & (srcID == SourceID()));
if(~isempty(idx))
       CircBuff(seq_num(idx)+1,S_idx.speed) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'int16'),'double') *.5;    
      CircBuff(seq_num(idx)+1,S_idx.StdDev) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'int16'),'double') /2; 
       CircBuff(seq_num(idx)+1,S_idx.iTemp1) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'int16'),'double'); 
       CircBuff(seq_num(idx)+1,S_idx.VBus) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double') * .01;
      CircBuff(seq_num(idx)+1,S_idx.Pmeas) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'int16'),'double') * .5;  
      RecentSeqNum_ID0 = max(seq_num(idx)); 
     % disp(['Ptarg = ' num2str(CircBuff(seq_num(idx)+1,S_idx.iTemp1)) '    Pmeas = ' num2str(CircBuff(seq_num(idx)+1,S_idx.Pmeas))]);
end

idx = find((dataID == 1) & (srcID == SourceID()));
if(~isempty(idx))
     CircBuff(seq_num(idx)+1,S_idx.IBridge) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'int16'),'double') / 500;
     CircBuff(seq_num(idx)+1,S_idx.ILoad) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'int16'),'double') / 500; 
     CircBuff(seq_num(idx)+1,S_idx.Force) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double') *.001;    
     unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16')
     CircBuff(seq_num(idx)+1,S_idx.comp_press) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16'),'double')*.001;    

     RecentSeqNum_ID1 = max(seq_num(idx)); 
end

idx = find((dataID == 2) & (srcID == SourceID()));
if(~isempty(idx))
 CircBuff(seq_num(idx)+1,S_idx.BridgeDC) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double')  / 40.96;
 CircBuff(seq_num(idx)+1,S_idx.LoadDC) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16'),'double')  / 40.96;
 CircBuff(seq_num(idx)+1,S_idx.ScaleFactor) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double')  / 100.0;
 CircBuff(seq_num(idx)+1,S_idx.RetractFactor) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16'),'double')  / 100.0;
 
 RecentSeqNum_ID2 = max(seq_num(idx)); 
end

idx = find((dataID == 3) & (srcID == SourceID()));
if(~isempty(idx))
    CircBuff(seq_num(idx)+1,S_idx.Vtarget) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double') * .01;
    CircBuff(seq_num(idx)+1,S_idx.Status) = unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16');
    CircBuff(seq_num(idx)+1,S_idx.StdDevTarget) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double') /2;
    CircBuff(seq_num(idx)+1,S_idx.DbarMin) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16'),'double') /40.96;

    RecentSeqNum_ID3 = max(seq_num(idx)); 
end

%Collect pneumatic spring data
idx =  find((dataID == 0) & (srcID == 1));
if(~isempty(idx))
    CircBuff(seq_num(idx)+1,S_idx.LoadCell) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double');
    CircBuff(seq_num(idx)+1,S_idx.PistonPosition) = cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16'),'double') * .1;
    CircBuff(seq_num(idx)+1,S_idx.UpperSpringPressure) = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'double') * .1;
    CircBuff(seq_num(idx)+1,S_idx.LowerSpringPressure) = cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16'),'double') * .1;
    
    CircBuff(seq_num(idx)+1,S_idx.StringPot) = (CircBuff(seq_num(idx)+1,S_idx.UpperSpringPressure)-18.9)*(71.5-0)/(294.2-18.9);
    %CircBuff(seq_num(idx)+1,S_idx.TestMachineLoadCell) = CircBuff(seq_num(idx)+1,S_idx.LowerSpringPressure); % (CircBuff(seq_num(idx)+1,S_idx.LowerSpringPressure)-.726)*(10000-30)/(299.99-.726);
    
    %CircBuff(seq_num(idx)+1,S_idx.TestMachineLoadCell) = -134.2303 + 37.70*CircBuff(seq_num(idx)+1,S_idx.LowerSpringPressure);
    CircBuff(seq_num(idx)+1,S_idx.TestMachineLoadCell) = (CircBuff(seq_num(idx)+1,S_idx.LowerSpringPressure)-1.59)*8758/(262.7-1.59);
    
    RecentSeqNum_PS_ID0 = max(seq_num(idx)); 
end


  idx =  find((dataID == 1) & (srcID == 1));
if(~isempty(idx))
    
 %   epoch = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'uint32') * 2^16  + cast(unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16'),'uint32');
 %   CircBuff(seq_num(idx)+1,S_idx.epoch) = cast(epoch,'double');
 %   sal = cast(unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16'),'uint32') * 2^16  + cast(unpack(rxMsg(idx), 48, 16, 'LittleEndian', 'uint16'),'uint32');
  %  CircBuff(seq_num(idx)+1,S_idx.CTD_Sal) = cast(sal,'double') /1000000;
    CircBuff(seq_num(idx)+1,S_idx.epoch) = cast(unpack(rxMsg(idx), 0, 32, 'LittleEndian', 'uint32'),'double');
    CircBuff(seq_num(idx)+1,S_idx.CTD_Sal) = cast(unpack(rxMsg(idx), 32, 32, 'LittleEndian', 'uint32'),'double')/1000000;

    RecentSeqNum_PS_ID1 = max(seq_num(idx)); 
end  
    



  idx =  find((dataID == 2) & (srcID == 1));
if(~isempty(idx))
    CircBuff(seq_num(idx)+1,S_idx.CTD_Temp) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double') /1000;
    CircBuff(seq_num(idx)+1,S_idx.PSpringStatus) = unpack(rxMsg(idx), 16, 16, 'LittleEndian', 'uint16');
    
    RecentSeqNum_PS_ID2 = max(seq_num(idx)); 
end  
    



%Collect battery controller data
idx =  find((dataID == 1) & (srcID == 0));
if(~isempty(idx))
    CircBuff(seq_num(idx)+1,S_idx.GroundFault) = cast(unpack(rxMsg(idx), 0, 16, 'LittleEndian', 'uint16'),'double')/1000;
    CircBuff(seq_num(idx)+1,S_idx.BattControllerStatus) = unpack(rxMsg(idx), 32, 16, 'LittleEndian', 'uint16');
    RecentSeqNum_BC_ID1 = max(seq_num(idx)); 
end

end
    


