Subversion Repositories HomeAutomation

Rev

Rev 457 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 457 Rev 1397
Line 49... Line 49...
49
    public CanPacket(string raw) {
49
    public CanPacket(string raw) {
50
        //denna funktion fungerar sådär, se till att bygga en bättre parser
50
        //denna funktion fungerar sådär, se till att bygga en bättre parser
51
       
51
       
52
        //1e00007f 1 0 04 03 02 01 96 3f 76 15
52
        //1e00007f 1 0 04 03 02 01 96 3f 76 15
53
        string [] split = null;
53
        string [] split = null;
54
        split = raw.Split( new Char [] {' '} );
54
        //split = raw.Split( new Char [] {' '} );
-
 
55
        split = raw.Split( ' ' );
55
        if ((split.Length >= 3) && (split.Length <= 11)) {
56
        if ((split.Length >= 3) && (split.Length <= 11)) {
56
            try {
57
            try {
57
                id = System.Convert.ToUInt32(split[0].Trim(), 16);
58
                id = System.Convert.ToUInt32(split[0].Trim(), 16);
58
            }
59
            }
59
            catch {
60
            catch {
60
                Console.WriteLine("overflow 1");
61
                Console.WriteLine("\noverflow 1 <"+split[0].Trim()+">\n");
61
            }
62
            }
62
            try {
63
            try {
63
                ext = (byte)(System.Convert.ToUInt32(split[1].Trim(), 16)&0xFF);
64
                ext = (byte)(System.Convert.ToUInt32(split[1].Trim(), 16)&0xFF);
64
            }
65
            }
65
            catch {
66
            catch {
66
                Console.WriteLine("overflow 2");
67
                Console.WriteLine("\noverflow 2 <"+split[1].Trim()+">\n");
67
            }
68
            }
68
            try {
69
            try {
69
                rtr = (byte)(System.Convert.ToUInt32(split[2].Trim(), 16)&0xFF);
70
                rtr = (byte)(System.Convert.ToUInt32(split[2].Trim(), 16)&0xFF);
70
            }
71
            }
71
            catch {
72
            catch {
72
                Console.WriteLine("overflow 3");
73
                Console.WriteLine("\noverflow 3 <"+split[2].Trim()+">\n");
73
            }
74
            }
74
            try {
-
 
75
                //testa ext och rtr!
75
            //testa ext och rtr!
-
 
76
            string dummy="";
-
 
77
            try {
76
               
78
               
77
                for (int i = 0; i < split.Length-3; i++) {
79
                for (int i = 0; i < split.Length-3; i++) {
78
                    string dummy = split[i+3].Trim();
80
                    dummy = split[i+3].Trim();
79
                    if (dummy.Length == 0) break;
81
                    if (dummy.Length == 0) break;
80
                    data_length = (byte)((i+1)&0xFF);
82
                    data_length = (byte)((i+1)&0xFF);
81
                    //Console.WriteLine("i: " + i + " i+3: " + (i+3) + " split[i+3]: " +split[i+3]);
83
                    //Console.WriteLine("i: " + i + " i+3: " + (i+3) + " split[i+3]: " +split[i+3]);
82
                    data[i] = (byte)(System.Convert.ToUInt32(dummy, 16)&0xFF);
84
                    data[i] = (byte)(System.Convert.ToUInt32(dummy, 16)&0xFF);
83
                }
85
                }
84
            }
86
            }
85
            catch {
87
            catch {
86
                Console.WriteLine("overflow 4");
88
                Console.WriteLine("\noverflow 4 <"+dummy+">\n");
87
            }
89
            }
88
        }
90
        }
89
       
91
       
90
    }
92
    }
91
   
93