MSCAN Updated

Dependents:   FBRLogger

Fork of MSCAN by Vesko Karadzhov

Committer:
veskokaradzhov
Date:
Wed Mar 06 17:33:14 2013 +0000
Revision:
6:c857749f9c0c
Parent:
0:4bd0966a0718
c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
intrinseca 0:4bd0966a0718 1 #include "MSCANHeader.h"
intrinseca 0:4bd0966a0718 2
intrinseca 0:4bd0966a0718 3 MSCANHeader::MSCANHeader()
intrinseca 0:4bd0966a0718 4 {
intrinseca 0:4bd0966a0718 5
intrinseca 0:4bd0966a0718 6 }
intrinseca 0:4bd0966a0718 7
intrinseca 0:4bd0966a0718 8 MSCANHeader::MSCANHeader(char to, char from, char type, char block, short offset)
intrinseca 0:4bd0966a0718 9 {
intrinseca 0:4bd0966a0718 10 to_id = to;
intrinseca 0:4bd0966a0718 11 from_id = from;
intrinseca 0:4bd0966a0718 12 msg_type = type;
intrinseca 0:4bd0966a0718 13 var_blk = block;
intrinseca 0:4bd0966a0718 14 var_offset = offset;
intrinseca 0:4bd0966a0718 15 }
intrinseca 0:4bd0966a0718 16
intrinseca 0:4bd0966a0718 17 //MS encodes most of the request params in the message ID.
intrinseca 0:4bd0966a0718 18 //Alignment is weird because the ID really includes some non-data bits. MS worked round these, mBed just skips them
intrinseca 0:4bd0966a0718 19
intrinseca 0:4bd0966a0718 20 //0-2 3 bits Spare on MSII
intrinseca 0:4bd0966a0718 21 //3-6 4 bits Block to get data from. 7 = outpc, all the stuff that MS sends to the PC via serial
intrinseca 0:4bd0966a0718 22 //7-10 4 bits To ID - 0 for MS
intrinseca 0:4bd0966a0718 23 //11-14 4 bits From ID - Using 3 here for no good reason
intrinseca 0:4bd0966a0718 24 //15-17 3 bits Message type. 1 to get data, response has 2
intrinseca 0:4bd0966a0718 25 //18-28 11 bits Offset into the block in bits 3-6. Look in the INI file for Tuner Studio to find these,
intrinseca 0:4bd0966a0718 26 // [OutputChannels] section starting line 3036
intrinseca 0:4bd0966a0718 27
intrinseca 0:4bd0966a0718 28 void MSCANHeader::parse(int id)
intrinseca 0:4bd0966a0718 29 {
intrinseca 0:4bd0966a0718 30 var_offset = (id & 0x1FFC0000) >> 18;
intrinseca 0:4bd0966a0718 31 msg_type = (id & 0x00038000) >> 15;
intrinseca 0:4bd0966a0718 32 from_id = (id & 0x00007800) >> 11;
intrinseca 0:4bd0966a0718 33 to_id = (id & 0x00000780) >> 7;
intrinseca 0:4bd0966a0718 34 var_blk = (id & 0x00000078) >> 3;
intrinseca 0:4bd0966a0718 35 }
intrinseca 0:4bd0966a0718 36
intrinseca 0:4bd0966a0718 37 int MSCANHeader::build()
intrinseca 0:4bd0966a0718 38 {
intrinseca 0:4bd0966a0718 39 int id = 0;
intrinseca 0:4bd0966a0718 40
intrinseca 0:4bd0966a0718 41 id |= (var_offset & 0x7FF) << 18;
intrinseca 0:4bd0966a0718 42 id |= (msg_type & 0x7) << 15;
intrinseca 0:4bd0966a0718 43 id |= (from_id & 0xF) << 11;
intrinseca 0:4bd0966a0718 44 id |= (to_id & 0xF) << 7;
intrinseca 0:4bd0966a0718 45 id |= (var_blk & 0xF) << 3;
intrinseca 0:4bd0966a0718 46
intrinseca 0:4bd0966a0718 47 return id;
intrinseca 0:4bd0966a0718 48 }