Rev 1594 | Rev 1596 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1592 | runge | 1 | #include <iostream> |
| 1594 | runge | 2 | #include <fstream> |
| 3 | #include <vector> |
||
| 4 | #include <string> |
||
| 1592 | runge | 5 | |
| 6 | #include <boost/bind.hpp> |
||
| 1594 | runge | 7 | #include <boost/program_options.hpp> |
| 1592 | runge | 8 | |
| 9 | #include "net/Manager.h" |
||
| 1595 | runge | 10 | #include "net/types.h" |
| 1592 | runge | 11 | |
| 1593 | runge | 12 | #include "timer/Manager.h" |
| 1595 | runge | 13 | #include "timer/types.h" |
| 1593 | runge | 14 | |
| 1594 | runge | 15 | #include "config/Manager.h" |
| 1593 | runge | 16 | |
| 1594 | runge | 17 | #include "logging/Logger.h" |
| 18 | |||
| 1592 | runge | 19 | using namespace atom; |
| 1593 | runge | 20 | |
| 1592 | runge | 21 | |
| 22 | net::Manager::Pointer NM = net::Manager::Instance(); |
||
| 23 | |||
| 1593 | runge | 24 | net::ServerId server_id = 0; |
| 25 | timer::TimerId timer_id; |
||
| 26 | |||
| 27 | void Main_SlotOnNewState(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state) |
||
| 1592 | runge | 28 | { |
| 29 | std::cout << "client:" << client_id << " - New state: " << client_state << std::endl; |
||
| 30 | } |
||
| 31 | |||
| 1593 | runge | 32 | void Main_SlotOnNewData(net::ClientId client_id, net::ServerId server_id, net::Buffer data) |
| 1592 | runge | 33 | { |
| 34 | std::string s(data.data()); |
||
| 35 | |||
| 36 | std::cout << "client:" << client_id << " - New data: " << s << std::endl; |
||
| 37 | |||
| 1593 | runge | 38 | net::Buffer out_data; |
| 1592 | runge | 39 | |
| 1593 | runge | 40 | strncpy(out_data.c_array(), data.data(), out_data.size()); |
| 1592 | runge | 41 | |
| 1595 | runge | 42 | NM->Disconnect(client_id); |
| 43 | |||
| 44 | std::cout << "client after disconnect" << s << std::endl; |
||
| 1592 | runge | 45 | } |
| 46 | |||
| 1593 | runge | 47 | void Main_SlotOnTimeout(timer::TimerId timer_id) |
| 48 | { |
||
| 49 | std::cout << "timer:" << timer_id << " - expired" << std::endl; |
||
| 50 | |||
| 51 | std::string out_string = "Timeout!"; |
||
| 52 | |||
| 53 | net::Buffer out_data; |
||
| 54 | |||
| 55 | strncpy(out_data.c_array(), out_string.data(), out_data.size()); |
||
| 56 | |||
| 1595 | runge | 57 | // NM->SendToAll(server_id, out_data); |
| 1593 | runge | 58 | } |
| 59 | |||
| 1592 | runge | 60 | int main(int argc, char **argv) |
| 61 | { |
||
| 1594 | runge | 62 | logging::Logger LOG("Main"); |
| 63 | |||
| 64 | config::Manager::Pointer CM = config::Manager::Instance(); |
||
| 1592 | runge | 65 | |
| 1594 | runge | 66 | if (!CM->Set(argc, argv)) |
| 67 | { |
||
| 68 | return 0; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (CM->Exist("MonitorPort")) |
||
| 72 | { |
||
| 73 | LOG.Info("MonitorPort: " + boost::lexical_cast<std::string>(CM->GetAsInt("MonitorPort"))); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (CM->Exist("CanNet")) |
||
| 77 | { |
||
| 78 | std::vector<std::string> cannets = CM->GetAsStringVector("CanNet"); |
||
| 79 | |||
| 80 | for (int n = 0; n < cannets.size(); n++) |
||
| 81 | { |
||
| 82 | LOG.Info("CanNet[" + boost::lexical_cast<std::string>(n) + "]=" + cannets[n]); |
||
| 83 | } |
||
| 84 | |||
| 85 | } |
||
| 1595 | runge | 86 | |
| 87 | /* timer::Manager::Pointer TM = timer::Manager::Instance(); |
||
| 1594 | runge | 88 | |
| 89 | |||
| 1595 | runge | 90 | TM->Set(10000, true); |
| 1594 | runge | 91 | |
| 1593 | runge | 92 | TM->ConnectSlots(boost::bind(&Main_SlotOnTimeout, _1)); |
| 1595 | runge | 93 | */ |
| 1593 | runge | 94 | |
| 95 | std::cout << "connect slots2" << std::endl; |
||
| 96 | NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2, _3), boost::bind(&Main_SlotOnNewData, _1, _2, _3)); |
||
| 97 | |||
| 98 | |||
| 1592 | runge | 99 | try |
| 100 | { |
||
| 1595 | runge | 101 | // server_id = NM->StartServer(net::PROTOCOL_SERIAL, 2000); |
| 1593 | runge | 102 | |
| 1595 | runge | 103 | // timer_id = TM->Set(10000, true); |
| 1593 | runge | 104 | |
| 1592 | runge | 105 | |
| 1595 | runge | 106 | net::ClientId client_id_udp = NM->Connect(net::PROTOCOL_SERIAL, "/dev/ttyUSB0", 57600); |
| 107 | |||
| 1592 | runge | 108 | std::cout << "connected" << std::endl; |
| 109 | |||
| 110 | char c[2] = { 251, 0 }; |
||
| 1595 | runge | 111 | |
| 112 | std::cout << "before send " << std::endl; |
||
| 113 | |||
| 114 | NM->SendTo(client_id_udp, std::string(c)); |
||
| 1592 | runge | 115 | } |
| 116 | catch (std::exception e) |
||
| 117 | { |
||
| 118 | std::cerr << e.what() << std::endl; |
||
| 119 | } |
||
| 120 | |||
| 121 | std::cout << "sleep" << std::endl; |
||
| 122 | |||
| 123 | sleep(100000000); |
||
| 124 | |||
| 125 | return 0; |
||
| 126 | } |