1 /***************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 ****************************************************************************/ |
|
6 |
|
7 #ifndef __EC_MASTER_H__ |
|
8 #define __EC_MASTER_H__ |
|
9 |
|
10 #include <stdexcept> |
|
11 #include <string> |
|
12 #include <vector> |
|
13 #include <list> |
|
14 using namespace std; |
|
15 |
|
16 #include "../include/ecrt.h" |
|
17 #include "../master/ioctl.h" |
|
18 |
|
19 /****************************************************************************/ |
|
20 |
|
21 class MasterException: |
|
22 public runtime_error |
|
23 { |
|
24 public: |
|
25 /** Constructor with std::string parameter. */ |
|
26 MasterException( |
|
27 const string &s /**< Message. */ |
|
28 ): runtime_error(s) {} |
|
29 |
|
30 /** Constructor with const char pointer parameter. */ |
|
31 MasterException( |
|
32 const char *s /**< Message. */ |
|
33 ): runtime_error(s) {} |
|
34 }; |
|
35 |
|
36 /****************************************************************************/ |
|
37 |
|
38 class Master |
|
39 { |
|
40 public: |
|
41 Master(); |
|
42 ~Master(); |
|
43 |
|
44 void setIndex(unsigned int); |
|
45 |
|
46 enum Verbosity { |
|
47 Quiet, |
|
48 Normal, |
|
49 Verbose |
|
50 }; |
|
51 void setVerbosity(Verbosity); |
|
52 |
|
53 void writeAlias(int, bool, const vector<string> &); |
|
54 void showConfigs(); |
|
55 void outputData(int); |
|
56 void setDebug(const vector<string> &); |
|
57 void showDomains(int); |
|
58 void showMaster(); |
|
59 void listPdos(int); |
|
60 void listSdos(int); |
|
61 void sdoDownload(int, const string &, const vector<string> &); |
|
62 void sdoUpload(int, const string &, const vector<string> &); |
|
63 void showSlaves(int); |
|
64 void siiRead(int); |
|
65 void siiWrite(int, bool, const vector<string> &); |
|
66 void requestStates(int, const vector<string> &); |
|
67 void generateXml(int); |
|
68 |
|
69 protected: |
|
70 enum Permissions {Read, ReadWrite}; |
|
71 void open(Permissions); |
|
72 void close(); |
|
73 |
|
74 void writeSlaveAlias(uint16_t, uint16_t); |
|
75 typedef list<ec_ioctl_config_t> ConfigList; |
|
76 void showDetailedConfigs(const ConfigList &); |
|
77 void listConfigs(const ConfigList &); |
|
78 void outputDomainData(unsigned int); |
|
79 enum {BreakAfterBytes = 16}; |
|
80 void showDomain(unsigned int); |
|
81 void listSlavePdos(uint16_t, bool = false); |
|
82 void listSlaveSdos(uint16_t, bool = false); |
|
83 void listSlaves(int); |
|
84 void showSlave(uint16_t); |
|
85 void generateSlaveXml(uint16_t); |
|
86 unsigned int slaveCount(); |
|
87 void getMaster(ec_ioctl_master_t *); |
|
88 void getConfig(ec_ioctl_config_t *, unsigned int); |
|
89 void getConfigPdo(ec_ioctl_config_pdo_t *, unsigned int, uint8_t, |
|
90 uint16_t); |
|
91 void getConfigPdoEntry(ec_ioctl_config_pdo_entry_t *, unsigned int, |
|
92 uint8_t, uint16_t, uint8_t); |
|
93 void getConfigSdo(ec_ioctl_config_sdo_t *, unsigned int, unsigned int); |
|
94 void getDomain(ec_ioctl_domain_t *, unsigned int); |
|
95 void getFmmu(ec_ioctl_domain_fmmu_t *, unsigned int, unsigned int); |
|
96 void getData(ec_ioctl_domain_data_t *, unsigned int, unsigned int, |
|
97 unsigned char *); |
|
98 void getSlave(ec_ioctl_slave_t *, uint16_t); |
|
99 void getSync(ec_ioctl_slave_sync_t *, uint16_t, uint8_t); |
|
100 void getPdo(ec_ioctl_slave_sync_pdo_t *, uint16_t, uint8_t, uint8_t); |
|
101 void getPdoEntry(ec_ioctl_slave_sync_pdo_entry_t *, uint16_t, uint8_t, |
|
102 uint8_t, uint8_t); |
|
103 void getSdo(ec_ioctl_slave_sdo_t *, uint16_t, uint16_t); |
|
104 void getSdoEntry(ec_ioctl_slave_sdo_entry_t *, uint16_t, int, uint8_t); |
|
105 void requestState(uint16_t, uint8_t); |
|
106 |
|
107 static string slaveState(uint8_t); |
|
108 static void printRawData(const uint8_t *, unsigned int); |
|
109 static uint8_t calcSiiCrc(const uint8_t *, unsigned int); |
|
110 |
|
111 private: |
|
112 enum {DefaultBufferSize = 1024}; |
|
113 |
|
114 unsigned int index; |
|
115 Verbosity verbosity; |
|
116 int fd; |
|
117 }; |
|
118 |
|
119 /****************************************************************************/ |
|
120 |
|
121 #endif |
|