Subversion Repositories HomeAutomation

Rev

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

Rev 436 Rev 444
Line 5... Line 5...
5
 
5
 
6
public class Daemon {
6
public class Daemon {
7
   
7
   
8
    private SerialConnection sc;
8
    private SerialConnection sc;
9
    private bool running;
9
    private bool running;
10
    const byte DEBUG_LEVEL = 2; //0, 1, 2, 3
10
    const byte DEBUG_LEVEL = 3; //0, 1, 2, 3
11
    private TcpServer tcps;
11
    private TcpServer tcps;
12
   
12
   
13
    public Daemon(SerialConnection sc) {
13
    public Daemon(SerialConnection sc) {
14
        this.sc = sc;
14
        this.sc = sc;
15
        running = true;
15
        running = true;
Line 38... Line 38...
38
            Thread.Sleep(5);
38
            Thread.Sleep(5);
39
            bool hasMessage = sc.getPacket(out cp);
39
            bool hasMessage = sc.getPacket(out cp);
40
            if (hasMessage) {
40
            if (hasMessage) {
41
                tcps.sendCanPacket(cp);
41
                tcps.sendCanPacket(cp);
42
               
42
               
43
                if (DEBUG_LEVEL>2) { Console.WriteLine(cp.toRawString()); }
43
                if (DEBUG_LEVEL>2) { Console.WriteLine(">"+cp.toRawString()); }
-
 
44
            }
-
 
45
           
-
 
46
            string tcpdata;
-
 
47
            bool hasData = tcps.getData(out tcpdata);
-
 
48
            if (hasData) {
-
 
49
                if (tcpdata.Length>3) {
-
 
50
                    //string canraw = tcpdata.Substring(4);
-
 
51
                    cp = new CanPacket(tcpdata.Substring(4));
-
 
52
                    //cp.setData(tcpdata.Substring(4));
-
 
53
                    if (sc.writePacket(cp)) {
-
 
54
                        if (DEBUG_LEVEL>2) { Console.WriteLine("<"+cp.toRawString()); }
-
 
55
                    }
-
 
56
                }
44
            }
57
            }
45
        }
58
        }
46
    }
59
    }
47
}
60
}