Changeset 18718
- Timestamp:
- 01/06/17 16:03:47 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FACT++_lidctrl_usb/src/lidctrl.cc
r18717 r18718 1 1 #include <functional> 2 3 2 #include <boost/bind.hpp> 3 #include <cstdlib> 4 4 5 5 #include "Dim.h" … … 30 30 class ConnectionLid : public ConnectionUSB 31 31 { 32 vector<uint8_t> fRecievedBytes; 33 DimDescribedService fDimLid; 32 vector<char> fRecievedBytes; 33 34 State::states_t state; 34 35 private: 35 36 … … 37 38 void HandleReceivedData(const boost::system::error_code&, size_t bytes_received, int type, int counter) 38 39 { 39 Out() << fRecievedBytes; 40 AsyncRead(ba::buffer(fRecievedBytes, 100), 0, 0); 41 40 string search_string("system_state="); 41 string s(fRecievedBytes.begin(), fRecievedBytes.end()); 42 Out() << s << endl << endl; 43 int pos=s.find(search_string); 44 string part = s.substr(pos + search_string.size(), 1); 45 int state_number = atoi(part.c_str()); 46 Out() << "system state = " << state_number << endl; 47 if (state_number == 0) 48 { 49 state = State::kClosed; 50 } 51 if (state_number == 4) 52 { 53 state = State::kOpen; 54 } 55 AsyncRead(ba::buffer(fRecievedBytes, 1024), 0, 0); 42 56 } 43 57 … … 46 60 void ConnectionEstablished() 47 61 { 48 AsyncRead(ba::buffer(fRecievedBytes, 10 0), 0, 0);62 AsyncRead(ba::buffer(fRecievedBytes, 1024), 0, 0); 49 63 } 50 64 … … 54 68 ConnectionUSB(ioservice, imp()), 55 69 fRecievedBytes(1024), 56 fDimLid("LID_CTRL_USB/STUFF", "S:1","|Stuff[foo]:some text.")70 state(State::kOpen) 57 71 { 58 72 SetLogStream(&imp); … … 61 75 State::states_t GetStatus() 62 76 { 63 return State::kOpen;77 return state; 64 78 } 65 79 }; … … 95 109 S fLid; 96 110 97 int Disconnect() 98 { 99 fLid.PostClose(-1); 111 int Execute() 112 { 113 return fLid.GetStatus(); 114 } 115 116 117 int Open() 118 { 119 std::array<char, 1> cmd = {{'o'}}; 120 fLid.PostMessage(cmd); 100 121 return T::GetCurrentState(); 101 122 } 102 103 int Reconnect(const EventImp &evt) 104 { 105 fLid.PostClose(-1); 106 ba::io_service::poll(); 107 fLid.PostClose(0); 123 124 int Close() 125 { 126 std::array<char, 1> cmd = {{'c'}}; 127 fLid.PostMessage(cmd); 108 128 return T::GetCurrentState(); 109 }110 111 int Execute()112 {113 const int state = fLid.GetStatus();114 return state;115 129 } 116 130 … … 156 170 control.add_options() 157 171 ("no-dim,d", po_bool(), "Disable dim services") 158 ("dev", var<string>( ), "Device address of USB port to lid-arduino")172 ("dev", var<string>("lid-arduino"), "Device address of USB port to lid-arduino") 159 173 ("quiet,q", po_bool(true), "Disable printing contents of all received messages (except dynamic data) in clear text.") 160 174 ;
Note:
See TracChangeset
for help on using the changeset viewer.