Implemented NFC Card Reader Code from https://git.sterul.com/student-projects/dhbw...
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / nfcreader / MifareDESFire / ValueFileSettings.java
1 package de.dhbwloe.campusapp.nfcreader.MifareDESFire;
2
3 import android.util.Log;
4
5 import de.dhbwloe.campusapp.nfcreader.Hex;
6
7 /**
8  * Created by stefan on 22.01.16.
9  */
10 public class ValueFileSettings extends FileSettings {
11     private int lowerLimit;
12     private int upperLimit;
13     private int limitedCreditValue;
14     private boolean limitedCreditEnabled;
15
16     public ValueFileSettings(String fileType, String communicationSettings, String accessRights, int lowerLimit, int upperLimit, int limitedCreditValue, boolean limitedCreditEnabled) {
17         super(fileType, communicationSettings, accessRights);
18         this.lowerLimit = lowerLimit;
19         this.upperLimit = upperLimit;
20         this.limitedCreditValue = limitedCreditValue;
21         this.limitedCreditEnabled = limitedCreditEnabled;
22     }
23
24     public static ValueFileSettings createByRawData(Byte[] rawData) {
25         String fileType = Hex.hexToString(Hex.subByteArray(0, 1, rawData));
26         String communicationSettings = Hex.hexToString(Hex.subByteArray(1, 2, rawData));
27         String accessRights = Hex.hexToString(Hex.reverseByteOrder(Hex.subByteArray(2,4, rawData)));
28         int lowerLimit = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(4, 8, rawData)));
29         int upperLimit = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(8,12, rawData)));
30         int limitedCreditValue = Hex.hexToInteger(Hex.reverseByteOrder(Hex.subByteArray(12,16, rawData)));
31         //TODO: Fix this
32         boolean limitedCreditEnabled = true;
33
34         return new ValueFileSettings(fileType, communicationSettings, accessRights, lowerLimit, upperLimit, limitedCreditValue, limitedCreditEnabled);
35     }
36
37
38     /**
39      *  Returns the lower limit of the value
40      * @return Lower limit
41      */
42     public int getLowerLimit() {
43         return lowerLimit;
44     }
45
46
47     /**
48      *  Returns the upper limit of the value
49      * @return Upper limit
50      */
51     public int getUpperLimit() {
52         return upperLimit;
53     }
54
55
56     /**
57      *  Returns the limited credit value
58      * @return Limited credit value
59      */
60     public int getLimitedCreditValue() {
61         return limitedCreditValue;
62     }
63
64
65     /**
66      * Returns if the limited credit feature is enabled on this value file
67      * DO NOT USE AT THE MOMENT!
68      * @return Is limited credit enabled?
69      */
70     public boolean getLimitedCreditEnabled() {
71         Log.e("ValueFileSettings", "Method not implemented, result is not valid");
72         return limitedCreditEnabled;
73     }
74 }