Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
434 arune 1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Threading;
5
 
6
public class Daemon {
7
 
8
    private SerialConnection sc;
9
    private bool running;
10
    const byte DEBUG_LEVEL = 2; //0, 1, 2, 3
11
    private TcpServer tcps;
12
 
13
    public Daemon(SerialConnection sc) {
14
        this.sc = sc;
15
        running = true;
16
    }
17
 
18
    public void stop () {
19
        running = false;
20
        Thread.Sleep(40);
21
        tcps.stop();
22
 
23
        // send a disconnect to avr? (call a function in serialconnection)
24
 
25
        //...för varje tcp-server...
26
    }
27
 
28
    public void addServer (TcpServer tcps) {
29
        //...lägg till servern i en lista...
30
        this.tcps = tcps;
31
        Thread t = new Thread(tcps.thread);
32
        t.Start();
33
    }
34
 
35
    public void thread() {
36
        CanPacket cp = null;
37
        while (running) {
436 arune 38
            Thread.Sleep(5);
434 arune 39
            bool hasMessage = sc.getPacket(out cp);
40
            if (hasMessage) {
41
                tcps.sendCanPacket(cp);
42
 
43
                if (DEBUG_LEVEL>2) { Console.WriteLine(cp.toRawString()); }
44
            }
45
        }
46
    }
47
}