Subversion Repositories HomeAutomation

Rev

Rev 442 | Rev 453 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 442 Rev 450
Line 8... Line 8...
8
//  private byte sid = 0;
8
//  private byte sid = 0;
9
//  private byte rid = 0;
9
//  private byte rid = 0;
10
    private byte data_length = 0;
10
    private byte data_length = 0;
11
    private uint id = 0;
11
    private uint id = 0;
12
    private byte[] data = new byte[8];
12
    private byte[] data = new byte[8];
13
    private byte ext = 0;
13
    private byte ext = 1;
14
    private byte rtr = 0;
14
    private byte rtr = 0;
-
 
15
   
-
 
16
    public CanPacket() {
-
 
17
       
-
 
18
    }
15
   
19
   
16
    public CanPacket(byte[] raw,uint startIndex) {
20
    public CanPacket(byte[] raw,uint startIndex) {
17
        // 17 bytes, a packet.
21
        // 17 bytes, a packet.
18
        // UART_START_BYTE id[0] id[1] id[2] id[3] extended remote_request data_length d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7] UART_END_BYTE
22
        // UART_START_BYTE id[0] id[1] id[2] id[3] extended remote_request data_length d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7] UART_END_BYTE
19
        /*
23
        /*
Line 26... Line 30...
26
        *
30
        *
27
        */
31
        */
28
       
32
       
29
       
33
       
30
        uint addr = (((uint)raw[startIndex + 3]) << 24) + (((uint)raw[startIndex + 2]) << 16) + (((uint)raw[startIndex + 1]) << 8) + (((uint)raw[startIndex + 0]));
34
        uint addr = (((uint)raw[startIndex + 3]) << 24) + (((uint)raw[startIndex + 2]) << 16) + (((uint)raw[startIndex + 1]) << 8) + (((uint)raw[startIndex + 0]));
31
       
35
       
32
        this.id = addr;
36
        this.id = addr;
33
        this.pktclass = (byte)((addr & 0x1E000000) >> 25);
37
        this.pktclass = (byte)((addr & 0x1E000000) >> 25);
34
//      this.type =  (byte)((addr & 0x00FF0000) >> 16);
38
//      this.type =  (byte)((addr & 0x00FF0000) >> 16);
35
//      this.sid =    (byte)((addr & 0x0000FF00) >> 8);
39
//      this.sid =    (byte)((addr & 0x0000FF00) >> 8);
36
//      this.rid =    (byte)((addr & 0x000000FF));
40
//      this.rid =    (byte)((addr & 0x000000FF));
Line 41... Line 45...
41
       
45
       
42
        for (int i = 0; i < 8; i++) this.data[i] = raw[startIndex + 7 + i];
46
        for (int i = 0; i < 8; i++) this.data[i] = raw[startIndex + 7 + i];
43
    }
47
    }
44
   
48
   
45
    public CanPacket(string raw) {
49
    public CanPacket(string raw) {
-
 
50
        //denna funktion fungerar sådär, se till att bygga en bättre parser
46
//  }
51
       
47
//  public void setData(string raw) {
-
 
48
        //1e00007f 1 0 04 03 02 01 96 3f 76 15
52
        //1e00007f 1 0 04 03 02 01 96 3f 76 15
49
        string [] split = null;
53
        string [] split = null;
50
        split = raw.Split( new Char [] {' '} );
54
        split = raw.Split( new Char [] {' '} );
51
        if ((split.Length >= 3) && (split.Length <= 11)) {
55
        if ((split.Length >= 3) && (split.Length <= 11)) {
52
            try {
56
            try {
Line 97... Line 101...
97
        return (this.id==cpm.getId() && this.data_length==cpm.getDataLength());
101
        return (this.id==cpm.getId() && this.data_length==cpm.getDataLength());
98
       
102
       
99
    }
103
    }
100
   
104
   
101
    public uint getId() { return this.id; }
105
    public uint getId() { return this.id; }
-
 
106
    public void setId(uint id) { this.id = id; }
102
    public byte getPktClass(){ return this.pktclass; }
107
    //public byte getPktClass(){ return this.pktclass; }
103
//  public uint getType(){ return this.type; }
108
//  public uint getType(){ return this.type; }
104
//  public uint getSid(){ return this.sid; }
109
//  public uint getSid(){ return this.sid; }
105
//  public uint getRid(){ return this.sid; }
110
//  public uint getRid(){ return this.sid; }
-
 
111
    public void setDataLength(byte datalength){ this.data_length=datalength; }
106
    public byte getDataLength(){ return this.data_length; }
112
    public byte getDataLength(){ return this.data_length; }
107
    public byte[] getData(){ return this.data; }
113
    public byte[] getData(){ return this.data; }
-
 
114
    public void setExt(byte ext) { this.ext = ext; }
108
   
115
   
109
//  public override string ToString() {
116
//  public override string ToString() {
110
//      string str = "";
117
//      string str = "";
111
       
118
       
112
//      str = "pktclass: "+pktclass.ToString()+", type: "+type.ToString()+", sid: "+sid.ToString()+", rid: "+rid.ToString()+",data_length: "+data_length.ToString()+", data: ";
119
//      str = "pktclass: "+pktclass.ToString()+", type: "+type.ToString()+", sid: "+sid.ToString()+", rid: "+rid.ToString()+",data_length: "+data_length.ToString()+", data: ";