|
1 /***************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 * |
|
7 * This file is part of the IgH EtherCAT Master. |
|
8 * |
|
9 * The IgH EtherCAT Master is free software; you can redistribute it and/or |
|
10 * modify it under the terms of the GNU General Public License version 2, as |
|
11 * published by the Free Software Foundation. |
|
12 * |
|
13 * The IgH EtherCAT Master is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
16 * Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License along |
|
19 * with the IgH EtherCAT Master; if not, write to the Free Software |
|
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 * |
|
22 * --- |
|
23 * |
|
24 * The license mentioned above concerns the source code only. Using the |
|
25 * EtherCAT technology and brand is only permitted in compliance with the |
|
26 * industrial property and similar rights of Beckhoff Automation GmbH. |
|
27 * |
|
28 ****************************************************************************/ |
|
29 |
|
30 #include <iomanip> |
|
31 using namespace std; |
|
32 |
|
33 #include "SoeCommand.h" |
|
34 |
|
35 /*****************************************************************************/ |
|
36 |
|
37 SoeCommand::SoeCommand(const string &name, const string &briefDesc): |
|
38 Command(name, briefDesc) |
|
39 { |
|
40 } |
|
41 |
|
42 /*****************************************************************************/ |
|
43 |
|
44 uint16_t SoeCommand::parseIdn(const string &str) |
|
45 { |
|
46 uint16_t idn = 0x0000; |
|
47 stringstream s, err; |
|
48 |
|
49 if (!str.length()) { |
|
50 err << "Zero-size string not allowed!"; |
|
51 throw runtime_error(err.str()); |
|
52 } |
|
53 |
|
54 if (str[0] == 'S' || str[0] == 'P') { |
|
55 unsigned int num; |
|
56 unsigned char c; |
|
57 |
|
58 s << str; |
|
59 |
|
60 s >> c; |
|
61 if (c == 'P') { |
|
62 idn |= 0x8000; |
|
63 } |
|
64 |
|
65 s >> c; |
|
66 if (s.fail() || c != '-') { |
|
67 err << "'-' expected!"; |
|
68 throw runtime_error(err.str()); |
|
69 } |
|
70 |
|
71 s >> num; |
|
72 if (s.fail() || num > 7) { |
|
73 err << "Invalid parameter set number!"; |
|
74 throw runtime_error(err.str()); |
|
75 } |
|
76 idn |= num << 12; |
|
77 |
|
78 s >> c; |
|
79 if (s.fail() || c != '-') { |
|
80 err << "'-' expected!"; |
|
81 throw runtime_error(err.str()); |
|
82 } |
|
83 |
|
84 s >> num; |
|
85 if (s.fail() || num > 4095) { |
|
86 err << "Invalid data block number!"; |
|
87 throw runtime_error(err.str()); |
|
88 } |
|
89 idn |= num; |
|
90 |
|
91 s.peek(); |
|
92 if (!s.eof()) { |
|
93 err << "Additional input!"; |
|
94 throw runtime_error(err.str()); |
|
95 } |
|
96 } else { |
|
97 s << str; |
|
98 s >> resetiosflags(ios::basefield) >> idn; |
|
99 if (s.fail()) { |
|
100 err << "Invalid number!"; |
|
101 throw runtime_error(err.str()); |
|
102 } |
|
103 } |
|
104 |
|
105 return idn; |
|
106 } |
|
107 |
|
108 /****************************************************************************/ |