/[H7]/branches/linux-serial/server/serialthread.cpp
ViewVC logotype

Contents of /branches/linux-serial/server/serialthread.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 72 - (show annotations) (download)
Tue Mar 20 19:36:35 2007 UTC (17 years, 2 months ago) by torben
File size: 1326 byte(s)
Enhanced serialthread...

1 #include <iostream>
2
3 #include "globalstorage.h"
4 #include "serialthread.h"
5
6
7 inline void msleep(int s)
8 {
9 usleep(s*1000);
10 }
11
12 SerialThread::SerialThread()
13 : Thread()
14 {
15 }
16
17
18 void SerialThread::operator()()
19 {
20 const int delay = 5;
21 mStopped = false;
22
23 GlobalStorage* store = GlobalStorage::instance();
24 CH7Serial& serial = store->serialPort;
25
26 while (mContinue)
27 {
28 msleep(50);
29
30 store->led3 = serial.readTarget(0);
31 msleep(delay);
32
33 store->led4 = serial.readTarget(1);
34 msleep(delay);
35 writeCommand();
36
37 store->led5 = serial.readTarget(2);
38 msleep(delay);
39
40 store->switch2 = serial.readTarget(3);
41 msleep(delay);
42 writeCommand();
43
44 store->switch3 = serial.readTarget(4);
45 msleep(delay);
46
47 store->potmeter = serial.readTarget(5);
48 msleep(delay);
49
50 store->temp = serial.readTarget(6);
51 std::cout << store->potmeter << std::endl;
52
53 writeCommand();
54 }
55 mStopped = true;
56 }
57
58 void SerialThread::writeCommand()
59 {
60 GlobalStorage* store = GlobalStorage::instance();
61 CH7Serial& serial = store->serialPort;
62
63 boost::mutex::scoped_lock lock(store->writeMutex);
64
65 if (! store->commands.empty() )
66 {
67 WriteCommand cmd = store->commands.front();
68 store->commands.pop();
69 std::cout << "Command:"<< (int) cmd.target<<","<< (int) cmd.data << std::endl;
70 serial.writeTarget( cmd.target, cmd.data);
71 msleep(5);
72 }
73 }

  ViewVC Help
Powered by ViewVC 1.1.20