MSCAN Updated

Dependents:   FBRLogger

Fork of MSCAN by Vesko Karadzhov

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MSCANHeader.cpp Source File

MSCANHeader.cpp

00001 #include "MSCANHeader.h"
00002 
00003 MSCANHeader::MSCANHeader()
00004 {
00005 
00006 }
00007 
00008 MSCANHeader::MSCANHeader(char to, char from, char type, char block, short offset)
00009 {
00010     to_id = to;
00011     from_id = from;
00012     msg_type = type;
00013     var_blk = block;
00014     var_offset = offset;
00015 }
00016 
00017 //MS encodes most of the request params in the message ID.
00018 //Alignment is weird because the ID really includes some non-data bits. MS worked round these, mBed just skips them
00019 
00020 //0-2   3 bits Spare on MSII
00021 //3-6   4 bits Block to get data from. 7 = outpc, all the stuff that MS sends to the PC via serial
00022 //7-10  4 bits To ID - 0 for MS
00023 //11-14 4 bits From ID - Using 3 here for no good reason
00024 //15-17 3 bits Message type. 1 to get data, response has 2
00025 //18-28 11 bits Offset into the block in bits 3-6. Look in the INI file for Tuner Studio to find these, 
00026 //              [OutputChannels] section starting line 3036
00027 
00028 void MSCANHeader::parse(int id)
00029 {
00030     var_offset = (id & 0x1FFC0000) >> 18;
00031     msg_type =   (id & 0x00038000) >> 15;
00032     from_id =    (id & 0x00007800) >> 11;
00033     to_id =      (id & 0x00000780) >> 7;
00034     var_blk =    (id & 0x00000078) >> 3;
00035 }
00036 
00037 int MSCANHeader::build()
00038 {
00039     int id = 0;
00040     
00041     id |= (var_offset & 0x7FF)  << 18;
00042     id |= (msg_type & 0x7)      << 15;
00043     id |= (from_id & 0xF)       << 11;
00044     id |= (to_id & 0xF)         << 7;
00045     id |= (var_blk & 0xF)       << 3;
00046     
00047     return id;
00048 }