31 #include <iomanip> |
31 #include <iomanip> |
32 using namespace std; |
32 using namespace std; |
33 |
33 |
34 #include "CommandMaster.h" |
34 #include "CommandMaster.h" |
35 |
35 |
|
36 #define MAX_TIME_STR_SIZE 50 |
|
37 |
36 /*****************************************************************************/ |
38 /*****************************************************************************/ |
37 |
39 |
38 CommandMaster::CommandMaster(): |
40 CommandMaster::CommandMaster(): |
39 Command("master", "Show master and Ethernet device information.") |
41 Command("master", "Show master and Ethernet device information.") |
40 { |
42 { |
63 void CommandMaster::execute(MasterDevice &m, const StringVector &args) |
65 void CommandMaster::execute(MasterDevice &m, const StringVector &args) |
64 { |
66 { |
65 ec_ioctl_master_t data; |
67 ec_ioctl_master_t data; |
66 stringstream err; |
68 stringstream err; |
67 unsigned int i; |
69 unsigned int i; |
|
70 time_t epoch; |
|
71 char time_str[MAX_TIME_STR_SIZE + 1]; |
|
72 size_t time_str_size; |
68 |
73 |
69 if (args.size()) { |
74 if (args.size()) { |
70 err << "'" << getName() << "' takes no arguments!"; |
75 err << "'" << getName() << "' takes no arguments!"; |
71 throwInvalidUsageException(err); |
76 throwInvalidUsageException(err); |
72 } |
77 } |
84 case 2: cout << "Operation"; break; |
89 case 2: cout << "Operation"; break; |
85 default: cout << "???"; |
90 default: cout << "???"; |
86 } |
91 } |
87 |
92 |
88 cout << endl |
93 cout << endl |
89 << " Slaves: " << data.slave_count << endl; |
94 << " Slaves: " << data.slave_count << endl |
|
95 << " Ethernet devices:" << endl; |
90 |
96 |
91 for (i = 0; i < 2; i++) { |
97 for (i = 0; i < 2; i++) { |
92 cout << " Device" << i << ": "; |
98 cout << " " << (i == 0 ? "Main" : "Backup") << ": "; |
93 if (data.devices[i].address[0] == 0x00 |
99 if (data.devices[i].address[0] == 0x00 |
94 && data.devices[i].address[1] == 0x00 |
100 && data.devices[i].address[1] == 0x00 |
95 && data.devices[i].address[2] == 0x00 |
101 && data.devices[i].address[2] == 0x00 |
96 && data.devices[i].address[3] == 0x00 |
102 && data.devices[i].address[3] == 0x00 |
97 && data.devices[i].address[4] == 0x00 |
103 && data.devices[i].address[4] == 0x00 |
105 << setw(2) << (unsigned int) data.devices[i].address[3] << ":" |
111 << setw(2) << (unsigned int) data.devices[i].address[3] << ":" |
106 << setw(2) << (unsigned int) data.devices[i].address[4] << ":" |
112 << setw(2) << (unsigned int) data.devices[i].address[4] << ":" |
107 << setw(2) << (unsigned int) data.devices[i].address[5] << " (" |
113 << setw(2) << (unsigned int) data.devices[i].address[5] << " (" |
108 << (data.devices[i].attached ? "attached" : "waiting...") |
114 << (data.devices[i].attached ? "attached" : "waiting...") |
109 << ")" << endl << dec |
115 << ")" << endl << dec |
110 << " Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl |
116 << " Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl |
111 << " Tx count: " << data.devices[i].tx_count << endl |
117 << " Tx count: " << data.devices[i].tx_count << endl |
112 << " Rx count: " << data.devices[i].rx_count; |
118 << " Rx count: " << data.devices[i].rx_count; |
113 } |
119 } |
114 cout << endl; |
120 cout << endl; |
115 } |
121 } |
|
122 |
|
123 cout << " Distributed clocks:" << endl |
|
124 << " Reference clock: "; |
|
125 if (data.ref_clock != 0xffff) { |
|
126 cout << "Slave " << dec << data.ref_clock; |
|
127 } else { |
|
128 cout << "None"; |
|
129 } |
|
130 cout << endl |
|
131 << " Application time: " << data.app_time << endl |
|
132 << " "; |
|
133 |
|
134 epoch = data.app_time / 1000000000 + 946684800ULL; |
|
135 time_str_size = strftime(time_str, MAX_TIME_STR_SIZE, |
|
136 "%Y-%m-%d %H:%M:%S", gmtime(&epoch)); |
|
137 cout << string(time_str, time_str_size) << "." |
|
138 << setfill('0') << setw(9) << data.app_time % 1000000000 << endl; |
116 } |
139 } |
117 |
140 |
118 /*****************************************************************************/ |
141 /*****************************************************************************/ |