function [] = CanCallback(rxCh)

global CircBuff;
global S_idx;
global RecentSeqNum;

%disp('Can msg recieved');

rxMsg = receive(rxCh, Inf);
%[srcID, dataID, seq_num] = DecodeCanID(rxMsg);
%size(rxMsg)
%foo = unpack(rxMsg, 0, 16, 'LittleEndian', 'uint16');
%size(foo)
foo = rxMsg.ID;
size(foo)
for Msg = rxMsg  %Loop through all messaged returned from "recieve".
  [srcID, dataID, seq_num] = DecodeCanID(Msg);

   if(srcID == SourceID())  %Data is from power converter controller as defined in function called SourceID

    switch dataID
    case 0  %Two floats.  Time and Voltage
      CircBuff(seq_num+1,S_idx.time) = unpack(Msg, 0, 32, 'LittleEndian', 'single');
      CircBuff(seq_num+1,S_idx.VBus) = unpack(Msg, 32, 32, 'LittleEndian', 'single');  
      RecentSeqNum = seq_num;

    case 1  %Four Ints.  P1DC`, Pmeas,DbarMin,lag
      CircBuff(seq_num+1,S_idx.P1DC1) = unpack(Msg, 0, 16, 'LittleEndian', 'uint16');
      CircBuff(seq_num+1,S_idx.Pmeas) = unpack(Msg, 16, 16, 'LittleEndian', 'uint16');  
      CircBuff(seq_num+1,S_idx.DbarMin) = unpack(Msg, 32, 16, 'LittleEndian', 'uint16');
      CircBuff(seq_num+1,S_idx.lag) = unpack(Msg, 48, 16, 'LittleEndian', 'uint16');    
      
    case 2  % Four Ints.  iTemp1, iTemp2, iTemp3, iTemp4
      CircBuff(seq_num+1,S_idx.iTemp1) = unpack(Msg, 0, 16, 'LittleEndian', 'uint16');
      CircBuff(seq_num+1,S_idx.iTemp2) = unpack(Msg, 16, 16, 'LittleEndian', 'uint16');  
      CircBuff(seq_num+1,S_idx.iTemp3) = unpack(Msg, 32, 16, 'LittleEndian', 'uint16');
      CircBuff(seq_num+1,S_idx.iTemp4) = unpack(Msg, 48, 16, 'LittleEndian', 'uint16'); 
      
    case 3  %Two Floats.  voltage target and current target
      CircBuff(seq_num+1,S_idx.Vtarget) = unpack(Msg, 0, 32, 'LittleEndian', 'single');
      CircBuff(seq_num+1,S_idx.Itarget) = unpack(Msg, 32, 32, 'LittleEndian', 'single');  
      
    case 4  %Two Floats.  IBridge and ILoad
      CircBuff(seq_num+1,S_idx.IBridge) = unpack(Msg, 0, 32, 'LittleEndian', 'single');
      CircBuff(seq_num+1,S_idx.ILoad) = unpack(Msg, 32, 32, 'LittleEndian', 'single');        

    case 5  %Two Floats.  BridgeDC and LoadDC
      CircBuff(seq_num+1,S_idx.BridgeDC) = unpack(Msg, 0, 32, 'LittleEndian', 'single');
      CircBuff(seq_num+1,S_idx.LoadDC) = unpack(Msg, 32, 32, 'LittleEndian', 'single');   

    case 6  %Two Floats.  RPMs and Torque      
      CircBuff(seq_num+1,S_idx.speed) = unpack(Msg, 0, 32, 'LittleEndian', 'single');
      CircBuff(seq_num+1,S_idx.torque) = unpack(Msg, 32, 32, 'LittleEndian', 'single');      
      
    otherwise
        warning(['Unknown dataID:  ' num2str(dataID)]);
    end
   
  end  
end
        
    
    
    
    
end
    


