public static ORCATransitEvent parseRecrd(PhysicalCard.Desfire.DesfireRecord record)
        {
            ORCATransitEvent _event = new ORCATransitEvent();

            byte[] d = record.Data;

            long tStamp = ((0x0F & d[3]) << 28)
                          | (d[4] << 20)
                          | (d[5] << 12)
                          | (d[6] << 4)
                          | (d[7] >> 4);

            _event.eventTime = DateTimeOffset.FromUnixTimeSeconds(tStamp).DateTime.ToLocalTime();

            _event.mCoach = ((d[9] & 0xf) << 12) | (d[10] << 4) | ((d[11] & 0xf0) >> 4);

            if (d[15] == 0xFF || d[15] == 0x00)
            {
                // According to FareBot, this is a strange edge-case that has not yet been figured out.
                _event.mEventCost = 0;
            }
            else
            {
                _event.mEventCost = (d[15] << 7) | (d[16] >> 1);
            }

            _event.mNewBalance    = (d[34] << 8) | d[35];
            _event.mTransitAgency = (ORCA.ORCACard.AgencyType)((byte)((d[3] & 0xF0) >> 4));
            _event.mActionType    = (ORCA.ORCACard.CardActionType)((byte)(d[17]));

            System.Diagnostics.Debug.WriteLine("DATA: " + Convert.ToBase64String(d));

            return(_event);
        }
示例#2
0
        public ORCACard(PhysicalCard.PhysicalCard card) : base(card)
        {
            // get serial no and friends.

            PhysicalCard.Desfire.DesfireCard c = card as PhysicalCard.Desfire.DesfireCard;
            serial  = (int)c.getApplication(AID_SPECIAL).getFile(0xF).Data.MakeLong(5, 3);
            balance = c.getApplication(AID_ORCA).getFile(0x04).Data.MakeUint16(41, false);

            PhysicalCard.Desfire.File.RecordFile recFile = (PhysicalCard.Desfire.File.RecordFile)(c.getApplication(AID_ORCA).getFile(0x02));

            PhysicalCard.Desfire.File.Settings.RecordSettings recSettings = (PhysicalCard.Desfire.File.Settings.RecordSettings)recFile.Settings;

            ORCATransitEvent[] evs = new ORCATransitEvent[recSettings.CurRecords];

            for (int evIdx = 0; evIdx < recSettings.CurRecords; evIdx++)
            {
                evs[evIdx] = ORCATransitEvent.parseRecrd(recFile[evIdx]);
            }
            events = evs;
        }