Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Chris Murphy | ||||
Approved revision: | 44 | ||||
Merged at revision: | 43 | ||||
Proposed branch: | lp:~tes/goby/time_fix | ||||
Merge into: | lp:goby/trunk | ||||
Diff against target: |
13742 lines (+5010/-4748) 107 files modified
CMakeLists.txt (+2/-2) COPYING (+1/-2) src/acomms.h (+31/-0) src/acomms/acomms_constants.h (+49/-52) src/acomms/amac.h (+1/-1) src/acomms/bind.h (+43/-44) src/acomms/dccl.h (+1/-1) src/acomms/examples/chat/CMakeLists.txt (+1/-1) src/acomms/examples/chat/chat.cpp (+21/-19) src/acomms/libamac/CMakeLists.txt (+2/-2) src/acomms/libamac/examples/amac_simple/CMakeLists.txt (+1/-1) src/acomms/libamac/examples/amac_simple/amac_simple.cpp (+10/-10) src/acomms/libamac/mac_manager.cpp (+42/-40) src/acomms/libamac/mac_manager.h (+247/-249) src/acomms/libdccl/CMakeLists.txt (+2/-2) src/acomms/libdccl/dccl.cpp (+106/-95) src/acomms/libdccl/dccl.h (+480/-480) src/acomms/libdccl/dccl_constants.h (+7/-4) src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt (+1/-1) src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp (+4/-4) src/acomms/libdccl/examples/delta/CMakeLists.txt (+1/-1) src/acomms/libdccl/examples/delta/delta.cpp (+6/-6) src/acomms/libdccl/examples/plusnet/CMakeLists.txt (+1/-1) src/acomms/libdccl/examples/plusnet/plusnet.cpp (+9/-8) src/acomms/libdccl/examples/test/CMakeLists.txt (+1/-1) src/acomms/libdccl/examples/test/test.cpp (+21/-20) src/acomms/libdccl/examples/test/test.xml (+2/-2) src/acomms/libdccl/examples/two_message/CMakeLists.txt (+1/-1) src/acomms/libdccl/examples/two_message/two_message.cpp (+5/-4) src/acomms/libdccl/message.cpp (+71/-68) src/acomms/libdccl/message.h (+195/-193) src/acomms/libdccl/message_algorithms.cpp (+9/-8) src/acomms/libdccl/message_algorithms.h (+38/-37) src/acomms/libdccl/message_publish.cpp (+25/-25) src/acomms/libdccl/message_publish.h (+58/-56) src/acomms/libdccl/message_val.cpp (+71/-67) src/acomms/libdccl/message_val.h (+143/-142) src/acomms/libdccl/message_var.cpp (+24/-24) src/acomms/libdccl/message_var.h (+125/-124) src/acomms/libdccl/message_var_bool.h (+9/-6) src/acomms/libdccl/message_var_enum.h (+68/-66) src/acomms/libdccl/message_var_float.cpp (+13/-16) src/acomms/libdccl/message_var_float.h (+66/-65) src/acomms/libdccl/message_var_head.h (+189/-171) src/acomms/libdccl/message_var_hex.h (+55/-52) src/acomms/libdccl/message_var_int.h (+16/-15) src/acomms/libdccl/message_var_static.h (+40/-39) src/acomms/libdccl/message_var_string.h (+70/-69) src/acomms/libdccl/message_xml_callbacks.cpp (+16/-14) src/acomms/libdccl/message_xml_callbacks.h (+62/-61) src/acomms/libdccl/tools/analyze_dccl_xml/CMakeLists.txt (+1/-1) src/acomms/libdccl/tools/analyze_dccl_xml/analyze_dccl_xml.cpp (+3/-3) src/acomms/libmodemdriver/CMakeLists.txt (+2/-2) src/acomms/libmodemdriver/driver_base.cpp (+6/-6) src/acomms/libmodemdriver/driver_base.h (+177/-160) src/acomms/libmodemdriver/examples/driver_simple/CMakeLists.txt (+1/-1) src/acomms/libmodemdriver/examples/driver_simple/driver_simple.cpp (+8/-8) src/acomms/libmodemdriver/mm_driver.cpp (+58/-71) src/acomms/libmodemdriver/mm_driver.h (+155/-153) src/acomms/libqueue/CMakeLists.txt (+2/-2) src/acomms/libqueue/examples/multimessage/CMakeLists.txt (+1/-1) src/acomms/libqueue/examples/multimessage/multimessage.cpp (+13/-13) src/acomms/libqueue/examples/queue_simple/CMakeLists.txt (+1/-1) src/acomms/libqueue/examples/queue_simple/queue_simple.cpp (+11/-10) src/acomms/libqueue/queue.cpp (+27/-29) src/acomms/libqueue/queue.h (+82/-79) src/acomms/libqueue/queue_config.cpp (+1/-1) src/acomms/libqueue/queue_config.h (+134/-133) src/acomms/libqueue/queue_constants.h (+13/-9) src/acomms/libqueue/queue_key.h (+35/-34) src/acomms/libqueue/queue_manager.cpp (+74/-76) src/acomms/libqueue/queue_manager.h (+309/-308) src/acomms/libqueue/queue_xml_callbacks.cpp (+3/-3) src/acomms/libqueue/queue_xml_callbacks.h (+56/-53) src/acomms/modem_driver.h (+2/-2) src/acomms/modem_message.h (+299/-279) src/acomms/queue.h (+1/-1) src/acomms/xml/tags.h (+139/-133) src/util.h (+31/-0) src/util/CMakeLists.txt (+2/-3) src/util/asioclient.h (+4/-3) src/util/binary.h (+170/-0) src/util/flexostream.h (+0/-26) src/util/libasioclient/CMakeLists.txt (+2/-2) src/util/libasioclient/client_base.h (+4/-3) src/util/libasioclient/nmea_sentence.cpp (+6/-17) src/util/libasioclient/nmea_sentence.h (+6/-9) src/util/libasioclient/serial_client.cpp (+7/-7) src/util/libasioclient/serial_client.h (+5/-3) src/util/libasioclient/tcp_client.cpp (+7/-7) src/util/libasioclient/tcp_client.h (+5/-2) src/util/libflexostream/CMakeLists.txt (+0/-5) src/util/liblogger/CMakeLists.txt (+2/-2) src/util/liblogger/flex_ncurses.cpp (+69/-69) src/util/liblogger/flex_ncurses.h (+218/-215) src/util/liblogger/flex_ostream.cpp (+6/-6) src/util/liblogger/flex_ostream.h (+6/-1) src/util/liblogger/flex_ostreambuf.cpp (+21/-15) src/util/liblogger/flex_ostreambuf.h (+17/-11) src/util/liblogger/logger_manipulators.cpp (+2/-2) src/util/liblogger/logger_manipulators.h (+0/-1) src/util/liblogger/term_color.h (+10/-8) src/util/logger.h (+2/-1) src/util/sci.h (+64/-0) src/util/string.h (+165/-0) src/util/tes_utils.h (+0/-386) src/util/time.h (+103/-0) |
||||
To merge this branch: | bzr merge lp:~tes/goby/time_fix | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Murphy | Approve | ||
Review via email:
|
Commit message
Description of the change
1. Consistent source of time based on boost::posix_time. Should be minimal / no use of <ctime> and UNIX double time. Any such use should be flagged as a bug from now on.
2. Renamed and consolidated namespaces:
dccl -> goby::acomms
queue -> goby::acomms
modem -> goby::acomms
micromodem -> goby::acomms
amac -> goby::acomms
tes_util -> goby::util
serial-> goby::util
Renamed a few classes to resolve resulting ambiguity and increase consistency:
dccl::Message* -> DCCLMessage*
modem::Message -> ModemMessage
3. Reworked util libraries:
libstreamlogger + libflexcout -> liblogger
libserial -> libasioclient
tes_utils.h -> time.h / sci.h / string.h
4. Changed header file structure slightly. For example, must #include "goby/acomms/
Added courtesy headers for all of goby::acomms and goby::util.
5. Documentation will need to be update to reflect these changes. I still need to do that, but I think we shouldn't have that delay the merge.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Chris Murphy (chrismurf) wrote : | # |
(In summary, looks good, I agree with the philosophy, but obviously didn't do a 100% code review).
- 45. By toby <toby@eis>
-
fixed some Doxygen comments to reflect new namespaces
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
toby schneider (tes) wrote : | # |
<ctime> is needed because there are (currently unused) conversions between ptime and time_t in util/time.h. Merged into lp:goby as 43
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2009-12-18 02:50:00 +0000 | |||
3 | +++ CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
4 | @@ -23,7 +23,7 @@ | |||
5 | 23 | 23 | ||
6 | 24 | # set instructions for `make install` | 24 | # set instructions for `make install` |
7 | 25 | install(DIRECTORY ${goby_BIN_DIR}/ DESTINATION /usr/local/bin FILE_PERMISSIONS WORLD_EXECUTE) | 25 | install(DIRECTORY ${goby_BIN_DIR}/ DESTINATION /usr/local/bin FILE_PERMISSIONS WORLD_EXECUTE) |
9 | 26 | install(DIRECTORY ${goby_LIB_DIR}/ DESTINATION /usr/local/lib/goby) | 26 | install(DIRECTORY ${goby_LIB_DIR}/ DESTINATION /usr/local/lib) |
10 | 27 | install(DIRECTORY ${goby_INC_DIR}/ DESTINATION /usr/local/include/goby) | 27 | install(DIRECTORY ${goby_INC_DIR}/ DESTINATION /usr/local/include/goby) |
11 | 28 | 28 | ||
12 | 29 | # find packages, libraries, and headers | 29 | # find packages, libraries, and headers |
13 | @@ -51,7 +51,7 @@ | |||
14 | 51 | # copy to goby/include | 51 | # copy to goby/include |
15 | 52 | file(GLOB_RECURSE INCLUDE_FILES RELATIVE ${goby_SRC_DIR} src/*.h) | 52 | file(GLOB_RECURSE INCLUDE_FILES RELATIVE ${goby_SRC_DIR} src/*.h) |
16 | 53 | foreach(I ${INCLUDE_FILES}) | 53 | foreach(I ${INCLUDE_FILES}) |
18 | 54 | configure_file(${goby_SRC_DIR}/${I} ${goby_INC_DIR}/${I}) | 54 | configure_file(${goby_SRC_DIR}/${I} ${goby_INC_DIR}/goby/${I}) |
19 | 55 | endforeach() | 55 | endforeach() |
20 | 56 | 56 | ||
21 | 57 | # let cmake know where the headers are | 57 | # let cmake know where the headers are |
22 | 58 | 58 | ||
23 | === modified file 'COPYING' | |||
24 | --- COPYING 2010-07-14 22:03:13 +0000 | |||
25 | +++ COPYING 2010-07-15 12:38:39 +0000 | |||
26 | @@ -2,8 +2,7 @@ | |||
27 | 2 | copying goby | 2 | copying goby |
28 | 3 | ~~~~~~~~~~~~ | 3 | ~~~~~~~~~~~~ |
29 | 4 | 4 | ||
32 | 5 | goby is copyright 2008, 2009 by | 5 | goby is copyright 2008, 2009, 2010 as listed in the individual header files. |
31 | 6 | - t. schneider tes@mit.edu | ||
33 | 7 | 6 | ||
34 | 8 | see header files of individual components for copyright details. | 7 | see header files of individual components for copyright details. |
35 | 9 | 8 | ||
36 | 10 | 9 | ||
37 | === added file 'src/acomms.h' | |||
38 | --- src/acomms.h 1970-01-01 00:00:00 +0000 | |||
39 | +++ src/acomms.h 2010-07-15 12:38:39 +0000 | |||
40 | @@ -0,0 +1,31 @@ | |||
41 | 1 | // copyright 2010 t. schneider tes@mit.edu | ||
42 | 2 | // | ||
43 | 3 | // this file is part of goby- | ||
44 | 4 | // | ||
45 | 5 | // This program is free software: you can redistribute it and/or modify | ||
46 | 6 | // it under the terms of the GNU General Public License as published by | ||
47 | 7 | // the Free Software Foundation, either version 3 of the License, or | ||
48 | 8 | // (at your option) any later version. | ||
49 | 9 | // | ||
50 | 10 | // This software is distributed in the hope that it will be useful, | ||
51 | 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
52 | 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
53 | 13 | // GNU General Public License for more details. | ||
54 | 14 | // | ||
55 | 15 | // You should have received a copy of the GNU General Public License | ||
56 | 16 | // along with this software. If not, see <http://www.gnu.org/licenses/>. | ||
57 | 17 | |||
58 | 18 | |||
59 | 19 | // courtesy header for all the goby acomms libraries | ||
60 | 20 | |||
61 | 21 | #ifndef ACOMMSCOURTESY20100713H | ||
62 | 22 | #define ACOMMSCOURTESY20100713H | ||
63 | 23 | |||
64 | 24 | #include "goby/acomms/dccl.h" | ||
65 | 25 | #include "goby/acomms/queue.h" | ||
66 | 26 | #include "goby/acomms/bind.h" | ||
67 | 27 | #include "goby/acomms/modem_driver.h" | ||
68 | 28 | #include "goby/acomms/modem_message.h" | ||
69 | 29 | #include "goby/acomms/amac.h" | ||
70 | 30 | |||
71 | 31 | #endif | ||
72 | 0 | 32 | ||
73 | === modified file 'src/acomms/acomms_constants.h' | |||
74 | --- src/acomms/acomms_constants.h 2010-03-20 06:09:16 +0000 | |||
75 | +++ src/acomms/acomms_constants.h 2010-07-15 12:38:39 +0000 | |||
76 | @@ -22,61 +22,58 @@ | |||
77 | 22 | #include <limits> | 22 | #include <limits> |
78 | 23 | #include <bitset> | 23 | #include <bitset> |
79 | 24 | 24 | ||
83 | 25 | #include "util/tes_utils.h" | 25 | namespace goby |
81 | 26 | |||
82 | 27 | namespace acomms | ||
84 | 28 | { | 26 | { |
118 | 29 | const unsigned BITS_IN_BYTE = 8; | 27 | |
119 | 30 | // one hex char is a nibble (4 bits), two nibbles per byte | 28 | namespace acomms |
87 | 31 | const unsigned NIBS_IN_BYTE = 2; | ||
88 | 32 | |||
89 | 33 | const unsigned BROADCAST_ID = 0; | ||
90 | 34 | const unsigned char DCCL_CCL_HEADER = 32; | ||
91 | 35 | |||
92 | 36 | const double NaN = std::numeric_limits<double>::quiet_NaN(); | ||
93 | 37 | |||
94 | 38 | const unsigned NUM_HEADER_BYTES = 6; | ||
95 | 39 | const unsigned NUM_HEADER_NIBS = 6*NIBS_IN_BYTE; | ||
96 | 40 | |||
97 | 41 | const unsigned NUM_HEADER_PARTS = 8; | ||
98 | 42 | enum DCCLHeaderPart { head_ccl_id = 0, | ||
99 | 43 | head_dccl_id = 1, | ||
100 | 44 | head_time = 2, | ||
101 | 45 | head_src_id = 3, | ||
102 | 46 | head_dest_id = 4, | ||
103 | 47 | head_multimessage_flag = 5, | ||
104 | 48 | head_broadcast_flag = 6, | ||
105 | 49 | head_unused = 7 | ||
106 | 50 | }; | ||
107 | 51 | |||
108 | 52 | const std::string DCCL_HEADER_NAMES [] = { "_ccl_id", | ||
109 | 53 | "_id", | ||
110 | 54 | "_time", | ||
111 | 55 | "_src_id", | ||
112 | 56 | "_dest_id", | ||
113 | 57 | "_multimessage_flag", | ||
114 | 58 | "_broadcast_flag", | ||
115 | 59 | "_unused", | ||
116 | 60 | }; | ||
117 | 61 | inline std::string to_str(DCCLHeaderPart p) | ||
120 | 62 | { | 29 | { |
122 | 63 | return DCCL_HEADER_NAMES[p]; | 30 | const unsigned BITS_IN_BYTE = 8; |
123 | 31 | // one hex char is a nibble (4 bits), two nibbles per byte | ||
124 | 32 | const unsigned NIBS_IN_BYTE = 2; | ||
125 | 33 | |||
126 | 34 | const unsigned BROADCAST_ID = 0; | ||
127 | 35 | const unsigned char DCCL_CCL_HEADER = 32; | ||
128 | 36 | |||
129 | 37 | const double NaN = std::numeric_limits<double>::quiet_NaN(); | ||
130 | 38 | |||
131 | 39 | const unsigned DCCL_NUM_HEADER_BYTES = 6; | ||
132 | 40 | |||
133 | 41 | const unsigned DCCL_NUM_HEADER_PARTS = 8; | ||
134 | 42 | |||
135 | 43 | enum DCCLHeaderPart { head_ccl_id = 0, | ||
136 | 44 | head_dccl_id = 1, | ||
137 | 45 | head_time = 2, | ||
138 | 46 | head_src_id = 3, | ||
139 | 47 | head_dest_id = 4, | ||
140 | 48 | head_multimessage_flag = 5, | ||
141 | 49 | head_broadcast_flag = 6, | ||
142 | 50 | head_unused = 7 | ||
143 | 51 | }; | ||
144 | 52 | |||
145 | 53 | const std::string DCCL_HEADER_NAMES [] = { "_ccl_id", | ||
146 | 54 | "_id", | ||
147 | 55 | "_time", | ||
148 | 56 | "_src_id", | ||
149 | 57 | "_dest_id", | ||
150 | 58 | "_multimessage_flag", | ||
151 | 59 | "_broadcast_flag", | ||
152 | 60 | "_unused", | ||
153 | 61 | }; | ||
154 | 62 | inline std::string to_str(DCCLHeaderPart p) | ||
155 | 63 | { | ||
156 | 64 | return DCCL_HEADER_NAMES[p]; | ||
157 | 65 | } | ||
158 | 66 | |||
159 | 67 | enum DCCLHeaderBits { head_ccl_id_size = 8, | ||
160 | 68 | head_dccl_id_size = 9, | ||
161 | 69 | head_time_size = 17, | ||
162 | 70 | head_src_id_size = 5, | ||
163 | 71 | head_dest_id_size = 5, | ||
164 | 72 | head_flag_size = 1, | ||
165 | 73 | head_unused_size = 2 | ||
166 | 74 | }; | ||
167 | 75 | |||
168 | 64 | } | 76 | } |
169 | 65 | |||
170 | 66 | enum DCCLHeaderBits { head_ccl_id_size = 8, | ||
171 | 67 | head_dccl_id_size = 9, | ||
172 | 68 | head_time_size = 17, | ||
173 | 69 | head_src_id_size = 5, | ||
174 | 70 | head_dest_id_size = 5, | ||
175 | 71 | head_flag_size = 1, | ||
176 | 72 | head_unused_size = 2 | ||
177 | 73 | }; | ||
178 | 74 | |||
179 | 75 | const double NOT_A_TIME = -1; | ||
180 | 76 | 77 | ||
181 | 77 | // this is Micro-Modem specific and is used by libmac, therefore | ||
182 | 78 | // we must get rid of it at some point soon... | ||
183 | 79 | const unsigned PACKET_SIZE [] = { 32, 32, 64, 256, 256, 256 }; | ||
184 | 80 | } | 78 | } |
185 | 81 | |||
186 | 82 | #endif | 79 | #endif |
187 | 83 | 80 | ||
188 | === modified file 'src/acomms/amac.h' | |||
189 | --- src/acomms/amac.h 2010-01-16 05:42:56 +0000 | |||
190 | +++ src/acomms/amac.h 2010-07-15 12:38:39 +0000 | |||
191 | @@ -20,7 +20,7 @@ | |||
192 | 20 | #ifndef AMACCOURTESY20091211H | 20 | #ifndef AMACCOURTESY20091211H |
193 | 21 | #define AMACCOURTESY20091211H | 21 | #define AMACCOURTESY20091211H |
194 | 22 | 22 | ||
196 | 23 | #include "acomms/libamac/mac_manager.h" | 23 | #include "goby/acomms/libamac/mac_manager.h" |
197 | 24 | 24 | ||
198 | 25 | #endif | 25 | #endif |
199 | 26 | 26 | ||
200 | 27 | 27 | ||
201 | === modified file 'src/acomms/bind.h' | |||
202 | --- src/acomms/bind.h 2010-06-15 04:51:47 +0000 | |||
203 | +++ src/acomms/bind.h 2010-07-15 12:38:39 +0000 | |||
204 | @@ -23,58 +23,57 @@ | |||
205 | 23 | 23 | ||
206 | 24 | #include <boost/bind.hpp> | 24 | #include <boost/bind.hpp> |
207 | 25 | 25 | ||
212 | 26 | #include "acomms/dccl.h" | 26 | #include "goby/acomms/dccl.h" |
213 | 27 | #include "acomms/queue.h" | 27 | #include "goby/acomms/queue.h" |
214 | 28 | #include "acomms/modem_driver.h" | 28 | #include "goby/acomms/modem_driver.h" |
215 | 29 | #include "acomms/amac.h" | 29 | #include "goby/acomms/amac.h" |
216 | 30 | 30 | ||
219 | 31 | /// utilites for dealing with goby-acomms | 31 | namespace goby |
218 | 32 | namespace acomms_util | ||
220 | 33 | { | 32 | { |
221 | 33 | namespace acomms | ||
222 | 34 | { | ||
223 | 34 | 35 | ||
224 | 35 | /// binds the driver link-layer callbacks to the QueueManager | 36 | /// binds the driver link-layer callbacks to the QueueManager |
235 | 36 | void bind(modem::DriverBase& driver, queue::QueueManager& queue_manager) | 37 | void bind(ModemDriverBase& driver, QueueManager& queue_manager) |
236 | 37 | { | 38 | { |
237 | 38 | using boost::bind; | 39 | using boost::bind; |
238 | 39 | driver.set_receive_cb | 40 | driver.set_receive_cb |
239 | 40 | (bind(&queue::QueueManager::receive_incoming_modem_data, &queue_manager, _1)); | 41 | (bind(&QueueManager::receive_incoming_modem_data, &queue_manager, _1)); |
240 | 41 | driver.set_ack_cb | 42 | driver.set_ack_cb |
241 | 42 | (bind(&queue::QueueManager::handle_modem_ack, &queue_manager, _1)); | 43 | (bind(&QueueManager::handle_modem_ack, &queue_manager, _1)); |
242 | 43 | driver.set_datarequest_cb | 44 | driver.set_datarequest_cb |
243 | 44 | (bind(&queue::QueueManager::provide_outgoing_modem_data, &queue_manager, _1, _2)); | 45 | (bind(&QueueManager::provide_outgoing_modem_data, &queue_manager, _1, _2)); |
244 | 45 | } | 46 | |
245 | 47 | driver.set_destination_cb(boost::bind(&QueueManager::request_next_destination, &queue_manager, _1)); | ||
246 | 48 | |||
247 | 49 | } | ||
248 | 46 | 50 | ||
249 | 47 | /// binds the MAC initiate transmission callback to the driver and the driver parsed message callback to the MAC | 51 | /// binds the MAC initiate transmission callback to the driver and the driver parsed message callback to the MAC |
256 | 48 | void bind(amac::MACManager& mac, modem::DriverBase& driver) | 52 | void bind(MACManager& mac, ModemDriverBase& driver) |
257 | 49 | { | 53 | { |
258 | 50 | mac.set_initiate_transmission_cb(boost::bind(&modem::DriverBase::initiate_transmission, &driver, _1)); | 54 | mac.set_initiate_transmission_cb(boost::bind(&ModemDriverBase::initiate_transmission, &driver, _1)); |
259 | 51 | mac.set_initiate_ranging_cb(boost::bind(&modem::DriverBase::initiate_ranging, &driver, _1)); | 55 | mac.set_initiate_ranging_cb(boost::bind(&ModemDriverBase::initiate_ranging, &driver, _1)); |
260 | 52 | driver.set_in_parsed_cb(boost::bind(&amac::MACManager::process_message, &mac, _1)); | 56 | mac.set_destination_cb(boost::bind(&ModemDriverBase::request_next_destination, &driver, _1)); |
261 | 53 | } | 57 | driver.set_in_parsed_cb(boost::bind(&MACManager::process_message, &mac, _1)); |
262 | 58 | } | ||
263 | 54 | 59 | ||
284 | 55 | /// binds the MAC destination request to the queue_manager | 60 | |
285 | 56 | void bind(amac::MACManager& mac, queue::QueueManager& queue_manager) | 61 | /// bind all three (shortcut to calling the other three bind functions) |
286 | 57 | { | 62 | void bind(ModemDriverBase& driver, QueueManager& queue_manager, MACManager& mac) |
287 | 58 | mac.set_destination_cb(boost::bind(&queue::QueueManager::request_next_destination, &queue_manager, _1)); | 63 | { |
288 | 59 | } | 64 | bind(driver, queue_manager); |
289 | 60 | 65 | bind(mac, driver); | |
290 | 61 | /// bind all three (shortcut to calling the other three bind functions) | 66 | } |
291 | 62 | void bind(modem::DriverBase& driver, queue::QueueManager& queue_manager, amac::MACManager& mac) | 67 | |
292 | 63 | { | 68 | // examples |
293 | 64 | bind(driver, queue_manager); | 69 | /// \example acomms/examples/chat/chat.cpp |
294 | 65 | bind(mac, driver); | 70 | /// chat.xml |
295 | 66 | bind(mac, queue_manager); | 71 | /// \verbinclude chat.xml |
296 | 67 | } | 72 | /// chat.cpp |
297 | 68 | 73 | ||
298 | 69 | // examples | 74 | |
299 | 70 | /// \example acomms/examples/chat/chat.cpp | 75 | } |
280 | 71 | /// chat.xml | ||
281 | 72 | /// \verbinclude chat.xml | ||
282 | 73 | /// chat.cpp | ||
283 | 74 | |||
300 | 75 | 76 | ||
301 | 76 | } | 77 | } |
302 | 77 | 78 | ||
303 | 78 | |||
304 | 79 | |||
305 | 80 | #endif | 79 | #endif |
306 | 81 | 80 | ||
307 | === modified file 'src/acomms/dccl.h' | |||
308 | --- src/acomms/dccl.h 2009-12-16 20:12:41 +0000 | |||
309 | +++ src/acomms/dccl.h 2010-07-15 12:38:39 +0000 | |||
310 | @@ -22,6 +22,6 @@ | |||
311 | 22 | #ifndef DCCLCOURTESY20091211H | 22 | #ifndef DCCLCOURTESY20091211H |
312 | 23 | #define DCCLCOURTESY20091211H | 23 | #define DCCLCOURTESY20091211H |
313 | 24 | 24 | ||
315 | 25 | #include "acomms/libdccl/dccl.h" | 25 | #include "goby/acomms/libdccl/dccl.h" |
316 | 26 | 26 | ||
317 | 27 | #endif | 27 | #endif |
318 | 28 | 28 | ||
319 | === modified file 'src/acomms/examples/chat/CMakeLists.txt' | |||
320 | --- src/acomms/examples/chat/CMakeLists.txt 2010-01-22 02:52:25 +0000 | |||
321 | +++ src/acomms/examples/chat/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
322 | @@ -1,2 +1,2 @@ | |||
323 | 1 | add_executable(chat chat.cpp chat_curses.cpp) | 1 | add_executable(chat chat.cpp chat_curses.cpp) |
325 | 2 | target_link_libraries(chat ${Boost_LIBRARIES} queue amac dccl modemdriver) | 2 | target_link_libraries(chat ${Boost_LIBRARIES} goby_queue goby_amac goby_dccl goby_modemdriver) |
326 | 3 | 3 | ||
327 | === modified file 'src/acomms/examples/chat/chat.cpp' | |||
328 | --- src/acomms/examples/chat/chat.cpp 2010-03-10 01:14:38 +0000 | |||
329 | +++ src/acomms/examples/chat/chat.cpp 2010-07-15 12:38:39 +0000 | |||
330 | @@ -22,27 +22,29 @@ | |||
331 | 22 | 22 | ||
332 | 23 | #include <iostream> | 23 | #include <iostream> |
333 | 24 | 24 | ||
340 | 25 | #include "acomms/dccl.h" | 25 | #include "goby/acomms/dccl.h" |
341 | 26 | #include "acomms/queue.h" | 26 | #include "goby/acomms/queue.h" |
342 | 27 | #include "acomms/modem_driver.h" | 27 | #include "goby/acomms/modem_driver.h" |
343 | 28 | #include "acomms/amac.h" | 28 | #include "goby/acomms/amac.h" |
344 | 29 | #include "acomms/modem_message.h" | 29 | #include "goby/acomms/modem_message.h" |
345 | 30 | #include "acomms/bind.h" | 30 | #include "goby/acomms/bind.h" |
346 | 31 | 31 | ||
347 | 32 | #include <boost/lexical_cast.hpp> | 32 | #include <boost/lexical_cast.hpp> |
348 | 33 | 33 | ||
349 | 34 | #include "chat_curses.h" | 34 | #include "chat_curses.h" |
350 | 35 | 35 | ||
351 | 36 | using namespace goby::acomms; | ||
352 | 37 | |||
353 | 36 | int startup_failure(); | 38 | int startup_failure(); |
356 | 37 | void received_data(queue::QueueKey, const modem::Message&); | 39 | void received_data(QueueKey, const ModemMessage&); |
357 | 38 | void received_ack(queue::QueueKey, const modem::Message&); | 40 | void received_ack(QueueKey, const ModemMessage&); |
358 | 39 | std::string decode_received(unsigned id, const std::string& data); | 41 | std::string decode_received(unsigned id, const std::string& data); |
359 | 40 | 42 | ||
360 | 41 | std::ofstream fout_; | 43 | std::ofstream fout_; |
365 | 42 | dccl::DCCLCodec dccl_; | 44 | DCCLCodec dccl_; |
366 | 43 | queue::QueueManager q_manager_(&fout_); | 45 | QueueManager q_manager_(&fout_); |
367 | 44 | micromodem::MMDriver mm_driver_(&fout_); | 46 | MMDriver mm_driver_(&fout_); |
368 | 45 | amac::MACManager mac_(&fout_); | 47 | MACManager mac_(&fout_); |
369 | 46 | ChatCurses curses_; | 48 | ChatCurses curses_; |
370 | 47 | 49 | ||
371 | 48 | 50 | ||
372 | @@ -77,7 +79,7 @@ | |||
373 | 77 | } | 79 | } |
374 | 78 | 80 | ||
375 | 79 | // bind the callbacks of these libraries | 81 | // bind the callbacks of these libraries |
377 | 80 | acomms_util::bind(mm_driver_, q_manager_, mac_); | 82 | bind(mm_driver_, q_manager_, mac_); |
378 | 81 | 83 | ||
379 | 82 | // | 84 | // |
380 | 83 | // Initiate DCCL (libdccl) | 85 | // Initiate DCCL (libdccl) |
381 | @@ -100,7 +102,7 @@ | |||
382 | 100 | // | 102 | // |
383 | 101 | // Initiate medium access control (libamac) | 103 | // Initiate medium access control (libamac) |
384 | 102 | // | 104 | // |
386 | 103 | mac_.set_type(amac::mac_slotted_tdma); | 105 | mac_.set_type(mac_slotted_tdma); |
387 | 104 | mac_.set_rate(0); | 106 | mac_.set_rate(0); |
388 | 105 | mac_.set_slot_time(15); | 107 | mac_.set_slot_time(15); |
389 | 106 | mac_.set_expire_cycles(5); | 108 | mac_.set_expire_cycles(5); |
390 | @@ -133,7 +135,7 @@ | |||
391 | 133 | 135 | ||
392 | 134 | if(!line.empty()) | 136 | if(!line.empty()) |
393 | 135 | { | 137 | { |
395 | 136 | std::map<std::string, dccl::MessageVal> vals; | 138 | std::map<std::string, DCCLMessageVal> vals; |
396 | 137 | vals["message"] = line; | 139 | vals["message"] = line; |
397 | 138 | 140 | ||
398 | 139 | std::string hex_out; | 141 | std::string hex_out; |
399 | @@ -141,7 +143,7 @@ | |||
400 | 141 | unsigned message_id = 1; | 143 | unsigned message_id = 1; |
401 | 142 | dccl_.encode(message_id, hex_out, vals); | 144 | dccl_.encode(message_id, hex_out, vals); |
402 | 143 | 145 | ||
404 | 144 | modem::Message message_out; | 146 | ModemMessage message_out; |
405 | 145 | message_out.set_data(hex_out); | 147 | message_out.set_data(hex_out); |
406 | 146 | // send this message to my buddy! | 148 | // send this message to my buddy! |
407 | 147 | message_out.set_dest(buddy_id); | 149 | message_out.set_dest(buddy_id); |
408 | @@ -171,12 +173,12 @@ | |||
409 | 171 | return 1; | 173 | return 1; |
410 | 172 | } | 174 | } |
411 | 173 | 175 | ||
413 | 174 | void received_data(queue::QueueKey key, const modem::Message& message_in) | 176 | void received_data(QueueKey key, const ModemMessage& message_in) |
414 | 175 | { | 177 | { |
415 | 176 | curses_.post_message(message_in.src(), decode_received(key.id(), message_in.data())); | 178 | curses_.post_message(message_in.src(), decode_received(key.id(), message_in.data())); |
416 | 177 | } | 179 | } |
417 | 178 | 180 | ||
419 | 179 | void received_ack(queue::QueueKey key, const modem::Message& ack_message) | 181 | void received_ack(QueueKey key, const ModemMessage& ack_message) |
420 | 180 | { | 182 | { |
421 | 181 | 183 | ||
422 | 182 | curses_.post_message | 184 | curses_.post_message |
423 | @@ -187,7 +189,7 @@ | |||
424 | 187 | 189 | ||
425 | 188 | std::string decode_received(unsigned id, const std::string& data) | 190 | std::string decode_received(unsigned id, const std::string& data) |
426 | 189 | { | 191 | { |
428 | 190 | std::map<std::string, dccl::MessageVal> vals; | 192 | std::map<std::string, DCCLMessageVal> vals; |
429 | 191 | dccl_.decode(id, data, vals); | 193 | dccl_.decode(id, data, vals); |
430 | 192 | return vals["message"]; | 194 | return vals["message"]; |
431 | 193 | } | 195 | } |
432 | 194 | 196 | ||
433 | === modified file 'src/acomms/libamac/CMakeLists.txt' | |||
434 | --- src/acomms/libamac/CMakeLists.txt 2010-01-21 04:25:08 +0000 | |||
435 | +++ src/acomms/libamac/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
436 | @@ -4,8 +4,8 @@ | |||
437 | 4 | include_directories(${Boost_INCLUDE_DIR}) | 4 | include_directories(${Boost_INCLUDE_DIR}) |
438 | 5 | 5 | ||
439 | 6 | file(GLOB SRC *.cpp *.c) | 6 | file(GLOB SRC *.cpp *.c) |
442 | 7 | add_library(amac SHARED ${SRC}) | 7 | add_library(goby_amac SHARED ${SRC}) |
443 | 8 | target_link_libraries(amac streamlogger ${Boost_LIBRARIES}) | 8 | target_link_libraries(goby_amac goby_logger ${Boost_LIBRARIES}) |
444 | 9 | endif() | 9 | endif() |
445 | 10 | 10 | ||
446 | 11 | add_subdirectory(examples) | 11 | add_subdirectory(examples) |
447 | 12 | \ No newline at end of file | 12 | \ No newline at end of file |
448 | 13 | 13 | ||
449 | === modified file 'src/acomms/libamac/examples/amac_simple/CMakeLists.txt' | |||
450 | --- src/acomms/libamac/examples/amac_simple/CMakeLists.txt 2010-01-22 02:52:25 +0000 | |||
451 | +++ src/acomms/libamac/examples/amac_simple/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
452 | @@ -1,2 +1,2 @@ | |||
453 | 1 | add_executable(amac_simple amac_simple.cpp) | 1 | add_executable(amac_simple amac_simple.cpp) |
454 | 2 | target_link_libraries(amac_simple amac) | ||
455 | 3 | \ No newline at end of file | 2 | \ No newline at end of file |
456 | 3 | target_link_libraries(amac_simple goby_amac) | ||
457 | 4 | \ No newline at end of file | 4 | \ No newline at end of file |
458 | 5 | 5 | ||
459 | === modified file 'src/acomms/libamac/examples/amac_simple/amac_simple.cpp' | |||
460 | --- src/acomms/libamac/examples/amac_simple/amac_simple.cpp 2010-01-22 02:52:25 +0000 | |||
461 | +++ src/acomms/libamac/examples/amac_simple/amac_simple.cpp 2010-07-15 12:38:39 +0000 | |||
462 | @@ -13,12 +13,12 @@ | |||
463 | 13 | // You should have received a copy of the GNU General Public License | 13 | // You should have received a copy of the GNU General Public License |
464 | 14 | // along with this software. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this software. If not, see <http://www.gnu.org/licenses/>. |
465 | 15 | 15 | ||
468 | 16 | #include "acomms/amac.h" | 16 | #include "goby/acomms/amac.h" |
469 | 17 | #include "acomms/modem_message.h" | 17 | #include "goby/acomms/modem_message.h" |
470 | 18 | #include <iostream> | 18 | #include <iostream> |
471 | 19 | 19 | ||
472 | 20 | int next_dest(unsigned); | 20 | int next_dest(unsigned); |
474 | 21 | void init_transmission(const modem::Message&); | 21 | void init_transmission(const goby::acomms::ModemMessage&); |
475 | 22 | 22 | ||
476 | 23 | int main(int argc, char* argv[]) | 23 | int main(int argc, char* argv[]) |
477 | 24 | { | 24 | { |
478 | @@ -26,12 +26,12 @@ | |||
479 | 26 | // | 26 | // |
480 | 27 | // 1. Create a MACManager and feed it a std::ostream to log to | 27 | // 1. Create a MACManager and feed it a std::ostream to log to |
481 | 28 | // | 28 | // |
483 | 29 | amac::MACManager mac(&std::cout); | 29 | goby::acomms::MACManager mac(&std::cout); |
484 | 30 | 30 | ||
485 | 31 | // | 31 | // |
486 | 32 | // 2. Configure it for TDMA with basic peer discovery, rate 0, 10 second slots, and expire vehicles after 2 cycles of no communications. also, we are modem id 1. | 32 | // 2. Configure it for TDMA with basic peer discovery, rate 0, 10 second slots, and expire vehicles after 2 cycles of no communications. also, we are modem id 1. |
487 | 33 | // | 33 | // |
489 | 34 | mac.set_type(amac::mac_slotted_tdma); | 34 | mac.set_type(goby::acomms::mac_slotted_tdma); |
490 | 35 | mac.set_rate(0); | 35 | mac.set_rate(0); |
491 | 36 | mac.set_slot_time(10); | 36 | mac.set_slot_time(10); |
492 | 37 | mac.set_expire_cycles(2); | 37 | mac.set_expire_cycles(2); |
493 | @@ -43,7 +43,7 @@ | |||
494 | 43 | 43 | ||
495 | 44 | // give callback for the next destination. this is called before a cycle is initiated, and would be bound to queue::QueueManager::request_next_destination if using libqueue. | 44 | // give callback for the next destination. this is called before a cycle is initiated, and would be bound to queue::QueueManager::request_next_destination if using libqueue. |
496 | 45 | mac.set_destination_cb(&next_dest); | 45 | mac.set_destination_cb(&next_dest); |
498 | 46 | // give a callback to use for actually initiating the transmission. this would be bound to modem::DriverBase::initiate_transmission if using libmodemdriver. | 46 | // give a callback to use for actually initiating the transmission. this would be bound to goby::acomms::ModemDriverBase::initiate_transmission if using libmodemdriver. |
499 | 47 | mac.set_initiate_transmission_cb(&init_transmission); | 47 | mac.set_initiate_transmission_cb(&init_transmission); |
500 | 48 | 48 | ||
501 | 49 | // | 49 | // |
502 | @@ -60,8 +60,8 @@ | |||
503 | 60 | // 5. Discover some friends (modem ids 2 & 3) | 60 | // 5. Discover some friends (modem ids 2 & 3) |
504 | 61 | // | 61 | // |
505 | 62 | 62 | ||
508 | 63 | mac.process_message(modem::Message("src=2")); | 63 | mac.process_message(goby::acomms::ModemMessage("src=2")); |
509 | 64 | mac.process_message(modem::Message("src=3")); | 64 | mac.process_message(goby::acomms::ModemMessage("src=3")); |
510 | 65 | 65 | ||
511 | 66 | // | 66 | // |
512 | 67 | // 6. Run it, hearing consistently from #3, but #2 has gone silent and will be expired after 2 cycles | 67 | // 6. Run it, hearing consistently from #3, but #2 has gone silent and will be expired after 2 cycles |
513 | @@ -71,7 +71,7 @@ | |||
514 | 71 | { | 71 | { |
515 | 72 | mac.do_work(); | 72 | mac.do_work(); |
516 | 73 | sleep(1); | 73 | sleep(1); |
518 | 74 | mac.process_message(modem::Message("src=3")); | 74 | mac.process_message(goby::acomms::ModemMessage("src=3")); |
519 | 75 | } | 75 | } |
520 | 76 | 76 | ||
521 | 77 | return 0; | 77 | return 0; |
522 | @@ -83,7 +83,7 @@ | |||
523 | 83 | return 10; | 83 | return 10; |
524 | 84 | } | 84 | } |
525 | 85 | 85 | ||
527 | 86 | void init_transmission(const modem::Message& init_message) | 86 | void init_transmission(const goby::acomms::ModemMessage& init_message) |
528 | 87 | { | 87 | { |
529 | 88 | std::cout << "starting transmission with these values: " << init_message << std::endl; | 88 | std::cout << "starting transmission with these values: " << init_message << std::endl; |
530 | 89 | } | 89 | } |
531 | 90 | 90 | ||
532 | === modified file 'src/acomms/libamac/mac_manager.cpp' | |||
533 | --- src/acomms/libamac/mac_manager.cpp 2010-07-11 16:20:55 +0000 | |||
534 | +++ src/acomms/libamac/mac_manager.cpp 2010-07-15 12:38:39 +0000 | |||
535 | @@ -1,4 +1,4 @@ | |||
537 | 1 | // copyright 2009 t. schneider tes@mit.edu | 1 | // copyright 2009, 2010 t. schneider tes@mit.edu |
538 | 2 | // | 2 | // |
539 | 3 | // this file is part of libamac, a medium access control for | 3 | // this file is part of libamac, a medium access control for |
540 | 4 | // acoustic networks. | 4 | // acoustic networks. |
541 | @@ -27,13 +27,15 @@ | |||
542 | 27 | #include <boost/bind.hpp> | 27 | #include <boost/bind.hpp> |
543 | 28 | #include <boost/foreach.hpp> | 28 | #include <boost/foreach.hpp> |
544 | 29 | 29 | ||
548 | 30 | #include "acomms/modem_message.h" | 30 | #include "goby/acomms/modem_message.h" |
549 | 31 | #include "acomms/libdccl/dccl_constants.h" | 31 | #include "goby/acomms/libdccl/dccl_constants.h" |
550 | 32 | #include "util/streamlogger.h" | 32 | #include "goby/util/logger.h" |
551 | 33 | 33 | ||
552 | 34 | #include "mac_manager.h" | 34 | #include "mac_manager.h" |
553 | 35 | 35 | ||
555 | 36 | amac::MACManager::MACManager(std::ostream* os /* =0 */) | 36 | using goby::util::goby_time; |
556 | 37 | |||
557 | 38 | goby::acomms::MACManager::MACManager(std::ostream* os /* =0 */) | ||
558 | 37 | : rate_(0), | 39 | : rate_(0), |
559 | 38 | slot_time_(15), | 40 | slot_time_(15), |
560 | 39 | expire_cycles_(5), | 41 | expire_cycles_(5), |
561 | @@ -45,34 +47,34 @@ | |||
562 | 45 | type_(mac_notype) | 47 | type_(mac_notype) |
563 | 46 | { } | 48 | { } |
564 | 47 | 49 | ||
566 | 48 | amac::MACManager::~MACManager() | 50 | goby::acomms::MACManager::~MACManager() |
567 | 49 | { } | 51 | { } |
568 | 50 | 52 | ||
570 | 51 | void amac::MACManager::do_work() | 53 | void goby::acomms::MACManager::do_work() |
571 | 52 | { | 54 | { |
573 | 53 | // if(os_) *os_ << group("mac") << "timer is running: " << std::boolalpha << timer_is_running_ << std::endl; | 55 | // if(os_) *os_ << group("mac") << "timer is running: " << std::boolalpha << timer_is_running_ << std::endl; |
574 | 54 | 56 | ||
575 | 55 | // let the io service execute ready handlers (in this case, is the timer up?) | 57 | // let the io service execute ready handlers (in this case, is the timer up?) |
576 | 56 | if(timer_is_running_) io_.poll(); | 58 | if(timer_is_running_) io_.poll(); |
577 | 57 | } | 59 | } |
578 | 58 | 60 | ||
580 | 59 | void amac::MACManager::restart_timer() | 61 | void goby::acomms::MACManager::restart_timer() |
581 | 60 | { | 62 | { |
582 | 61 | // cancel any old timer jobs waiting | 63 | // cancel any old timer jobs waiting |
583 | 62 | timer_.cancel(); | 64 | timer_.cancel(); |
584 | 63 | timer_.expires_at(next_slot_t_); | 65 | timer_.expires_at(next_slot_t_); |
586 | 64 | timer_.async_wait(boost::bind(&amac::MACManager::send_poll, this, _1)); | 66 | timer_.async_wait(boost::bind(&MACManager::send_poll, this, _1)); |
587 | 65 | timer_is_running_ = true; | 67 | timer_is_running_ = true; |
588 | 66 | } | 68 | } |
589 | 67 | 69 | ||
591 | 68 | void amac::MACManager::stop_timer() | 70 | void goby::acomms::MACManager::stop_timer() |
592 | 69 | { | 71 | { |
593 | 70 | timer_is_running_ = false; | 72 | timer_is_running_ = false; |
594 | 71 | timer_.cancel(); | 73 | timer_.cancel(); |
595 | 72 | } | 74 | } |
596 | 73 | 75 | ||
597 | 74 | 76 | ||
599 | 75 | void amac::MACManager::startup() | 77 | void goby::acomms::MACManager::startup() |
600 | 76 | { | 78 | { |
601 | 77 | switch(type_) | 79 | switch(type_) |
602 | 78 | { | 80 | { |
603 | @@ -80,17 +82,17 @@ | |||
604 | 80 | if(os_) *os_ << group("mac") | 82 | if(os_) *os_ << group("mac") |
605 | 81 | << "Using the Slotted TDMA MAC scheme with autodiscovery" | 83 | << "Using the Slotted TDMA MAC scheme with autodiscovery" |
606 | 82 | << std::endl; | 84 | << std::endl; |
613 | 83 | blank_it_ = add_slot(amac::Slot(acomms::BROADCAST_ID, | 85 | blank_it_ = add_slot(Slot(acomms::BROADCAST_ID, |
614 | 84 | amac::Slot::query_destination, | 86 | Slot::query_destination, |
615 | 85 | rate_, | 87 | rate_, |
616 | 86 | amac::Slot::slot_data, | 88 | Slot::slot_data, |
617 | 87 | slot_time_, | 89 | slot_time_, |
618 | 88 | boost::posix_time::ptime(boost::posix_time::pos_infin))); | 90 | boost::posix_time::ptime(boost::posix_time::pos_infin))); |
619 | 89 | 91 | ||
622 | 90 | add_slot(amac::Slot(modem_id_, | 92 | add_slot(Slot(modem_id_, |
623 | 91 | amac::Slot::query_destination, | 93 | Slot::query_destination, |
624 | 92 | rate_, | 94 | rate_, |
626 | 93 | amac::Slot::slot_data, | 95 | Slot::slot_data, |
627 | 94 | slot_time_, | 96 | slot_time_, |
628 | 95 | boost::posix_time::ptime(boost::posix_time::pos_infin))); | 97 | boost::posix_time::ptime(boost::posix_time::pos_infin))); |
629 | 96 | 98 | ||
630 | @@ -107,7 +109,7 @@ | |||
631 | 107 | case mac_polled: | 109 | case mac_polled: |
632 | 108 | if(os_) *os_ << group("mac") | 110 | if(os_) *os_ << group("mac") |
633 | 109 | << "Using the Centralized Polling MAC scheme" << std::endl; | 111 | << "Using the Centralized Polling MAC scheme" << std::endl; |
635 | 110 | next_slot_t_ = now(); | 112 | next_slot_t_ = goby_time(); |
636 | 111 | break; | 113 | break; |
637 | 112 | 114 | ||
638 | 113 | default: | 115 | default: |
639 | @@ -118,7 +120,7 @@ | |||
640 | 118 | restart_timer(); | 120 | restart_timer(); |
641 | 119 | } | 121 | } |
642 | 120 | 122 | ||
644 | 121 | void amac::MACManager::send_poll(const asio::error_code& e) | 123 | void goby::acomms::MACManager::send_poll(const asio::error_code& e) |
645 | 122 | { | 124 | { |
646 | 123 | // canceled the last timer | 125 | // canceled the last timer |
647 | 124 | if(e == asio::error::operation_aborted) return; | 126 | if(e == asio::error::operation_aborted) return; |
648 | @@ -129,7 +131,7 @@ | |||
649 | 129 | bool send_poll = true; | 131 | bool send_poll = true; |
650 | 130 | 132 | ||
651 | 131 | int destination = (s.dest() == Slot::query_destination) | 133 | int destination = (s.dest() == Slot::query_destination) |
653 | 132 | ? callback_dest(acomms::PACKET_SIZE[s.rate()]) : s.dest(); | 134 | ? callback_dest(s.rate()) : s.dest(); |
654 | 133 | 135 | ||
655 | 134 | switch(type_) | 136 | switch(type_) |
656 | 135 | { | 137 | { |
657 | @@ -157,13 +159,13 @@ | |||
658 | 157 | *os_ << " ]" << std::endl; | 159 | *os_ << " ]" << std::endl; |
659 | 158 | 160 | ||
660 | 159 | *os_ << group("mac") << s.type_as_string() << " slot is starting: {" << s.src() << " to " | 161 | *os_ << group("mac") << s.type_as_string() << " slot is starting: {" << s.src() << " to " |
662 | 160 | << destination << " @ " << s.rate() << "}" << std::endl; | 162 | << destination << " @ " << s.rate() << "}" << std::endl; |
663 | 161 | } | 163 | } |
664 | 162 | 164 | ||
665 | 163 | 165 | ||
666 | 164 | if(send_poll) | 166 | if(send_poll) |
667 | 165 | { | 167 | { |
669 | 166 | modem::Message m; | 168 | ModemMessage m; |
670 | 167 | switch(s.type()) | 169 | switch(s.type()) |
671 | 168 | { | 170 | { |
672 | 169 | case Slot::slot_data: | 171 | case Slot::slot_data: |
673 | @@ -214,12 +216,12 @@ | |||
674 | 214 | restart_timer(); | 216 | restart_timer(); |
675 | 215 | } | 217 | } |
676 | 216 | 218 | ||
678 | 217 | boost::posix_time::ptime amac::MACManager::next_cycle_time() | 219 | boost::posix_time::ptime goby::acomms::MACManager::next_cycle_time() |
679 | 218 | { | 220 | { |
680 | 219 | using namespace boost::gregorian; | 221 | using namespace boost::gregorian; |
681 | 220 | using namespace boost::posix_time; | 222 | using namespace boost::posix_time; |
682 | 221 | 223 | ||
684 | 222 | int since_day_start = now().time_of_day().total_seconds(); | 224 | int since_day_start = goby_time().time_of_day().total_seconds(); |
685 | 223 | cycles_since_day_start_ = (floor(since_day_start/cycle_length()) + 1); | 225 | cycles_since_day_start_ = (floor(since_day_start/cycle_length()) + 1); |
686 | 224 | 226 | ||
687 | 225 | if(os_) *os_ << group("mac") << "cycles since day start: " | 227 | if(os_) *os_ << group("mac") << "cycles since day start: " |
688 | @@ -232,7 +234,7 @@ | |||
689 | 232 | return ptime(day_clock::universal_day(), seconds(secs_to_next)); | 234 | return ptime(day_clock::universal_day(), seconds(secs_to_next)); |
690 | 233 | } | 235 | } |
691 | 234 | 236 | ||
693 | 235 | void amac::MACManager::process_message(const modem::Message& m) | 237 | void goby::acomms::MACManager::process_message(const ModemMessage& m) |
694 | 236 | { | 238 | { |
695 | 237 | unsigned id = m.src(); | 239 | unsigned id = m.src(); |
696 | 238 | 240 | ||
697 | @@ -249,7 +251,7 @@ | |||
698 | 249 | 251 | ||
699 | 250 | slot_order_.push_back | 252 | slot_order_.push_back |
700 | 251 | (id2slot_.insert | 253 | (id2slot_.insert |
702 | 252 | (std::pair<unsigned, Slot> (id, Slot(id, Slot::query_destination, rate_, Slot::slot_data, slot_time_, now())))); | 254 | (std::pair<unsigned, Slot> (id, Slot(id, Slot::query_destination, rate_, Slot::slot_data, slot_time_, goby_time())))); |
703 | 253 | 255 | ||
704 | 254 | slot_order_.sort(); | 256 | slot_order_.sort(); |
705 | 255 | 257 | ||
706 | @@ -259,17 +261,17 @@ | |||
707 | 259 | { | 261 | { |
708 | 260 | std::pair<id2slot_it, id2slot_it> p = id2slot_.equal_range(id); | 262 | std::pair<id2slot_it, id2slot_it> p = id2slot_.equal_range(id); |
709 | 261 | for(id2slot_it it = p.first; it != p.second; ++it) | 263 | for(id2slot_it it = p.first; it != p.second; ++it) |
711 | 262 | it->second.set_last_heard_time(now()); | 264 | it->second.set_last_heard_time(goby_time()); |
712 | 263 | } | 265 | } |
713 | 264 | } | 266 | } |
714 | 265 | 267 | ||
716 | 266 | void amac::MACManager::expire_ids() | 268 | void goby::acomms::MACManager::expire_ids() |
717 | 267 | { | 269 | { |
718 | 268 | bool reset = false; | 270 | bool reset = false; |
719 | 269 | 271 | ||
720 | 270 | for(id2slot_it it = id2slot_.begin(), n = id2slot_.end(); it != n; ++it) | 272 | for(id2slot_it it = id2slot_.begin(), n = id2slot_.end(); it != n; ++it) |
721 | 271 | { | 273 | { |
723 | 272 | if(it->second.last_heard_time() < now()-boost::posix_time::seconds(cycle_length()*expire_cycles_) && it->first != modem_id_) | 274 | if(it->second.last_heard_time() < goby_time()-boost::posix_time::seconds(cycle_length()*expire_cycles_) && it->first != modem_id_) |
724 | 273 | { | 275 | { |
725 | 274 | if(os_) *os_ << group("mac") << "removed id " << it->first | 276 | if(os_) *os_ << group("mac") << "removed id " << it->first |
726 | 275 | << " after not hearing for " << expire_cycles_ | 277 | << " after not hearing for " << expire_cycles_ |
727 | @@ -284,7 +286,7 @@ | |||
728 | 284 | if(reset) process_cycle_size_change(); | 286 | if(reset) process_cycle_size_change(); |
729 | 285 | } | 287 | } |
730 | 286 | 288 | ||
732 | 287 | void amac::MACManager::process_cycle_size_change() | 289 | void goby::acomms::MACManager::process_cycle_size_change() |
733 | 288 | { | 290 | { |
734 | 289 | next_slot_t_ = next_cycle_time(); | 291 | next_slot_t_ = next_cycle_time(); |
735 | 290 | if(os_) *os_ << group("mac") << "the MAC TDMA next cycle begins at time: " | 292 | if(os_) *os_ << group("mac") << "the MAC TDMA next cycle begins at time: " |
736 | @@ -296,7 +298,7 @@ | |||
737 | 296 | } | 298 | } |
738 | 297 | 299 | ||
739 | 298 | 300 | ||
741 | 299 | unsigned amac::MACManager::cycle_sum() | 301 | unsigned goby::acomms::MACManager::cycle_sum() |
742 | 300 | { | 302 | { |
743 | 301 | unsigned s = 0; | 303 | unsigned s = 0; |
744 | 302 | BOOST_FOREACH(id2slot_it it, slot_order_) | 304 | BOOST_FOREACH(id2slot_it it, slot_order_) |
745 | @@ -304,7 +306,7 @@ | |||
746 | 304 | return s; | 306 | return s; |
747 | 305 | } | 307 | } |
748 | 306 | 308 | ||
750 | 307 | void amac::MACManager::position_blank() | 309 | void goby::acomms::MACManager::position_blank() |
751 | 308 | { | 310 | { |
752 | 309 | unsigned blank_pos = cycle_length() - ((cycles_since_day_start_ % ENTROPY) == (cycle_sum() % ENTROPY)) - 1; | 311 | unsigned blank_pos = cycle_length() - ((cycles_since_day_start_ % ENTROPY) == (cycle_sum() % ENTROPY)) - 1; |
753 | 310 | 312 | ||
754 | @@ -319,11 +321,11 @@ | |||
755 | 319 | current_slot_ = slot_order_.begin(); | 321 | current_slot_ = slot_order_.begin(); |
756 | 320 | } | 322 | } |
757 | 321 | 323 | ||
759 | 322 | std::map<unsigned, amac::Slot>::iterator amac::MACManager::add_slot(const amac::Slot& s) | 324 | std::map<unsigned, goby::acomms::Slot>::iterator goby::acomms::MACManager::add_slot(const Slot& s) |
760 | 323 | { | 325 | { |
761 | 324 | bool do_timer_start = slot_order_.empty(); | 326 | bool do_timer_start = slot_order_.empty(); |
762 | 325 | 327 | ||
764 | 326 | std::map<unsigned, amac::Slot>::iterator it = | 328 | std::map<unsigned, Slot>::iterator it = |
765 | 327 | id2slot_.insert(std::pair<unsigned, Slot>(s.src(), s)); | 329 | id2slot_.insert(std::pair<unsigned, Slot>(s.src(), s)); |
766 | 328 | 330 | ||
767 | 329 | slot_order_.push_back(it); | 331 | slot_order_.push_back(it); |
768 | @@ -333,14 +335,14 @@ | |||
769 | 333 | 335 | ||
770 | 334 | if(do_timer_start) | 336 | if(do_timer_start) |
771 | 335 | { | 337 | { |
773 | 336 | next_slot_t_ = now(); | 338 | next_slot_t_ = goby_time(); |
774 | 337 | restart_timer(); | 339 | restart_timer(); |
775 | 338 | } | 340 | } |
776 | 339 | 341 | ||
777 | 340 | return it; | 342 | return it; |
778 | 341 | } | 343 | } |
779 | 342 | 344 | ||
781 | 343 | bool amac::MACManager::remove_slot(const amac::Slot& s) | 345 | bool goby::acomms::MACManager::remove_slot(const Slot& s) |
782 | 344 | { | 346 | { |
783 | 345 | bool removed_a_slot = false; | 347 | bool removed_a_slot = false; |
784 | 346 | 348 | ||
785 | 347 | 349 | ||
786 | === modified file 'src/acomms/libamac/mac_manager.h' | |||
787 | --- src/acomms/libamac/mac_manager.h 2010-07-11 16:20:55 +0000 | |||
788 | +++ src/acomms/libamac/mac_manager.h 2010-07-15 12:38:39 +0000 | |||
789 | @@ -1,4 +1,4 @@ | |||
791 | 1 | // copyright 2009 t. schneider tes@mit.edu | 1 | // copyright 2009, 2010 t. schneider tes@mit.edu |
792 | 2 | // | 2 | // |
793 | 3 | // this file is part of libamac, a medium access control for | 3 | // this file is part of libamac, a medium access control for |
794 | 4 | // acoustic networks. | 4 | // acoustic networks. |
795 | @@ -23,268 +23,266 @@ | |||
796 | 23 | #define MAC20091019H | 23 | #define MAC20091019H |
797 | 24 | 24 | ||
798 | 25 | #include <boost/lexical_cast.hpp> | 25 | #include <boost/lexical_cast.hpp> |
799 | 26 | #include <boost/date_time/posix_time/posix_time.hpp> | ||
800 | 27 | #include <boost/function.hpp> | 26 | #include <boost/function.hpp> |
801 | 28 | #include "asio.hpp" | 27 | #include "asio.hpp" |
802 | 29 | 28 | ||
804 | 30 | namespace modem { class Message; } | 29 | #include "goby/util/time.h" |
805 | 31 | 30 | ||
810 | 32 | /// \brief contains the medium access control objects | 31 | namespace goby |
807 | 33 | /// | ||
808 | 34 | /// Use \code #include <goby/acomms/amac.h> \endcode to gain access to all these objects. | ||
809 | 35 | namespace amac | ||
811 | 36 | { | 32 | { |
826 | 37 | /// \name Acoustic MAC Library callback function type definitions | 33 | namespace acomms |
827 | 38 | //@{ | 34 | { |
828 | 39 | 35 | class ModemMessage; | |
829 | 40 | /// \brief boost::function for a function taking a unsigned and returning an integer. | 36 | /// \name Acoustic MAC Library callback function type definitions |
830 | 41 | /// | 37 | //@{ |
831 | 42 | /// Think of this as a generalized version of a function pointer (int (*) (unsigned)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. | 38 | |
832 | 43 | typedef boost::function<int (unsigned)> IdFunc; | 39 | /// \brief boost::function for a function taking a unsigned and returning an integer. |
833 | 44 | 40 | /// | |
834 | 45 | /// \brief boost::function for a function taking a single modem::Message reference. | 41 | /// Think of this as a generalized version of a function pointer (int (*) (unsigned)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. |
835 | 46 | /// | 42 | typedef boost::function<int (unsigned)> MACIdFunc; |
836 | 47 | /// Think of this as a generalized version of a function pointer (void (*)(modem::Message&)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. | 43 | |
837 | 48 | typedef boost::function<void (const modem::Message & message)> MsgFunc1; | 44 | /// \brief boost::function for a function taking a single acomms::ModemMessage reference. |
838 | 49 | 45 | /// | |
839 | 50 | //@} | 46 | /// Think of this as a generalized version of a function pointer (void (*)(acomms::ModemMessage&)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. |
840 | 47 | typedef boost::function<void (const acomms::ModemMessage & message)> MACMsgFunc1; | ||
841 | 48 | |||
842 | 49 | //@} | ||
843 | 51 | 50 | ||
844 | 52 | /// Enumeration of MAC types | 51 | /// Enumeration of MAC types |
850 | 53 | enum MACType { | 52 | enum MACType { |
851 | 54 | mac_notype, /*!< no MAC */ | 53 | mac_notype, /*!< no MAC */ |
852 | 55 | mac_slotted_tdma, /*!< decentralized time division multiple access */ | 54 | mac_slotted_tdma, /*!< decentralized time division multiple access */ |
853 | 56 | mac_polled /*!< centralized polling */ | 55 | mac_polled /*!< centralized polling */ |
854 | 57 | }; | 56 | }; |
855 | 58 | 57 | ||
862 | 59 | /// Represents a slot of the TDMA cycle | 58 | /// Represents a slot of the TDMA cycle |
863 | 60 | class Slot | 59 | class Slot |
858 | 61 | { | ||
859 | 62 | public: | ||
860 | 63 | /// Enumeration of slot types | ||
861 | 64 | enum SlotType | ||
864 | 65 | { | 60 | { |
869 | 66 | slot_notype, /*!< useless slot */ | 61 | public: |
870 | 67 | slot_data, /*!< slot to send data packet */ | 62 | /// Enumeration of slot types |
871 | 68 | slot_ping /*!< slot to send ping (ranging) */ | 63 | enum SlotType |
872 | 69 | }; | 64 | { |
873 | 65 | slot_notype, /*!< useless slot */ | ||
874 | 66 | slot_data, /*!< slot to send data packet */ | ||
875 | 67 | slot_ping /*!< slot to send ping (ranging) */ | ||
876 | 68 | }; | ||
877 | 70 | 69 | ||
923 | 71 | /// \name Constructors/Destructor | 70 | /// \name Constructors/Destructor |
924 | 72 | //@{ | 71 | //@{ |
925 | 73 | /// \brief Default constructor. | 72 | /// \brief Default constructor. |
926 | 74 | /// | 73 | /// |
927 | 75 | /// \param src id representing sender of the data packet or ping | 74 | /// \param src id representing sender of the data packet or ping |
928 | 76 | /// \param dest id representing destination of the data packet or ping | 75 | /// \param dest id representing destination of the data packet or ping |
929 | 77 | /// \param rate value 0-5 representing modem transmission rate. 0 is slowest, 5 is fastest | 76 | /// \param rate value 0-5 representing modem transmission rate. 0 is slowest, 5 is fastest |
930 | 78 | /// \param type amac::Slot::SlotType of this slot | 77 | /// \param type amac::Slot::SlotType of this slot |
931 | 79 | /// \param slot_time length of time this slot should last in seconds | 78 | /// \param slot_time length of time this slot should last in seconds |
932 | 80 | /// \param last_heard_time last time (in seconds since 1/1/70) the src vehicle was heard from | 79 | /// \param last_heard_time last time (in seconds since 1/1/70) the src vehicle was heard from |
933 | 81 | Slot(unsigned src = 0, | 80 | Slot(unsigned src = 0, |
934 | 82 | unsigned dest = 0, | 81 | unsigned dest = 0, |
935 | 83 | int rate = 0, | 82 | int rate = 0, |
936 | 84 | SlotType type = slot_notype, | 83 | SlotType type = slot_notype, |
937 | 85 | unsigned slot_time = 15, | 84 | unsigned slot_time = 15, |
938 | 86 | boost::posix_time::ptime last_heard_time = boost::posix_time::not_a_date_time) | 85 | boost::posix_time::ptime last_heard_time = boost::posix_time::not_a_date_time) |
939 | 87 | : src_(src), | 86 | : src_(src), |
940 | 88 | dest_(dest), | 87 | dest_(dest), |
941 | 89 | rate_(rate), | 88 | rate_(rate), |
942 | 90 | type_(type), | 89 | type_(type), |
943 | 91 | slot_time_(slot_time), | 90 | slot_time_(slot_time), |
944 | 92 | last_heard_time_(last_heard_time) | 91 | last_heard_time_(last_heard_time) |
945 | 93 | { } | 92 | { } |
946 | 94 | 93 | ||
947 | 95 | //@} | 94 | //@} |
948 | 96 | 95 | ||
949 | 97 | /// \name Set | 96 | /// \name Set |
950 | 98 | //@{ | 97 | //@{ |
951 | 99 | void set_src(unsigned src) { src_ = src; } | 98 | void set_src(unsigned src) { src_ = src; } |
952 | 100 | void set_dest(int dest) { dest_ = dest; } | 99 | void set_dest(int dest) { dest_ = dest; } |
953 | 101 | void set_rate(int rate) { rate_ = rate; } | 100 | void set_rate(int rate) { rate_ = rate; } |
954 | 102 | void set_type(SlotType type) { type_ = type; } | 101 | void set_type(SlotType type) { type_ = type; } |
955 | 103 | void set_last_heard_time(boost::posix_time::ptime t) { last_heard_time_ = t; } | 102 | void set_last_heard_time(boost::posix_time::ptime t) { last_heard_time_ = t; } |
956 | 104 | void set_slot_time(unsigned t) { slot_time_ = t; } | 103 | void set_slot_time(unsigned t) { slot_time_ = t; } |
957 | 105 | //@} | 104 | //@} |
958 | 106 | 105 | ||
959 | 107 | /// \name Get | 106 | /// \name Get |
960 | 108 | //@{ | 107 | //@{ |
961 | 109 | unsigned src() const { return src_; } | 108 | unsigned src() const { return src_; } |
962 | 110 | int dest() const { return dest_; } | 109 | int dest() const { return dest_; } |
963 | 111 | int rate() const { return rate_; } | 110 | int rate() const { return rate_; } |
964 | 112 | SlotType type() const { return type_; } | 111 | SlotType type() const { return type_; } |
965 | 113 | std::string type_as_string() const | 112 | std::string type_as_string() const |
921 | 114 | { | ||
922 | 115 | switch(type_) | ||
966 | 116 | { | 113 | { |
970 | 117 | case slot_data: return "data"; | 114 | switch(type_) |
971 | 118 | case slot_ping: return "ping"; | 115 | { |
972 | 119 | default: return "unknown"; | 116 | case slot_data: return "data"; |
973 | 117 | case slot_ping: return "ping"; | ||
974 | 118 | default: return "unknown"; | ||
975 | 119 | } | ||
976 | 120 | } | 120 | } |
977 | 121 | |||
978 | 122 | boost::posix_time::ptime last_heard_time() const { return last_heard_time_; } | ||
979 | 123 | unsigned slot_time() const { return slot_time_; } | ||
980 | 124 | //@} | ||
981 | 125 | |||
982 | 126 | enum { query_destination = -1 }; | ||
983 | 127 | |||
984 | 128 | |||
985 | 129 | private: | ||
986 | 130 | unsigned src_; | ||
987 | 131 | int dest_; | ||
988 | 132 | int rate_; | ||
989 | 133 | SlotType type_; | ||
990 | 134 | unsigned slot_time_; | ||
991 | 135 | boost::posix_time::ptime last_heard_time_; | ||
992 | 136 | }; | ||
993 | 137 | |||
994 | 138 | inline std::ostream& operator<<(std::ostream& os, const Slot& s) | ||
995 | 139 | { return os << "src: " << s.src() << " | dest: " << s.dest() << " | rate: " << s.rate() << " | slot_time: " << s.slot_time(); } | ||
996 | 140 | |||
997 | 141 | |||
998 | 142 | /// provides an API to the goby-acomms MAC library. | ||
999 | 143 | class MACManager | ||
1000 | 144 | { | ||
1001 | 145 | |||
1002 | 146 | public: | ||
1003 | 147 | |||
1004 | 148 | /// \name Constructors/Destructor | ||
1005 | 149 | //@{ | ||
1006 | 150 | /// \brief Default constructor. | ||
1007 | 151 | /// | ||
1008 | 152 | /// \param os std::ostream object or FlexOstream to capture all humanly readable runtime and debug information (optional). | ||
1009 | 153 | MACManager(std::ostream* os = 0); | ||
1010 | 154 | ~MACManager(); | ||
1011 | 155 | //@} | ||
1012 | 156 | |||
1013 | 157 | /// \brief Starts the MAC | ||
1014 | 158 | void startup(); | ||
1015 | 159 | /// \brief Must be called regularly for the MAC to perform its work | ||
1016 | 160 | void do_work(); | ||
1017 | 161 | |||
1018 | 162 | /// \brief Manually initiate a transmission out of the normal cycle. This is not normally called by the user of MACManager | ||
1019 | 163 | void send_poll(const asio::error_code&); | ||
1020 | 164 | |||
1021 | 165 | /// \brief Call every time a message is received from vehicle to "discover" this vehicle or reset the expire timer. Only needed when the type is amac::mac_slotted_tdma. | ||
1022 | 166 | /// | ||
1023 | 167 | /// \param message the new message (used to detect vehicles) | ||
1024 | 168 | void process_message(const acomms::ModemMessage& m); | ||
1025 | 169 | |||
1026 | 170 | /// \name Manipulate slots | ||
1027 | 171 | //@{ | ||
1028 | 172 | /// \return iterator to newly added slot | ||
1029 | 173 | std::map<unsigned, Slot>::iterator add_slot(const Slot& s); | ||
1030 | 174 | /// \brief removes any slots in the cycle where amac::operator==(const Slot&, const Slot&) is true. | ||
1031 | 175 | /// | ||
1032 | 176 | /// \return true if one or more slots are removed | ||
1033 | 177 | bool remove_slot(const Slot& s); | ||
1034 | 178 | void clear_all_slots() { id2slot_.clear(); slot_order_.clear(); } | ||
1035 | 179 | //@} | ||
1036 | 180 | |||
1037 | 181 | |||
1038 | 182 | /// \name Set | ||
1039 | 183 | //@{ | ||
1040 | 184 | void set_type(MACType type) { type_ = type; } | ||
1041 | 185 | void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; } | ||
1042 | 186 | void set_modem_id(const std::string& s) { set_modem_id(boost::lexical_cast<unsigned>(s)); } | ||
1043 | 187 | void set_rate(int rate) { rate_ = rate; } | ||
1044 | 188 | void set_rate(const std::string& s) { set_rate(boost::lexical_cast<int>(s)); } | ||
1045 | 189 | void set_slot_time(unsigned slot_time) { slot_time_ = slot_time; } | ||
1046 | 190 | void set_slot_time(const std::string& s) { set_slot_time(boost::lexical_cast<unsigned>(s)); } | ||
1047 | 191 | void set_expire_cycles(unsigned expire_cycles) { expire_cycles_ = expire_cycles; } | ||
1048 | 192 | void set_expire_cycles(const std::string& s) { set_expire_cycles(boost::lexical_cast<unsigned>(s)); } | ||
1049 | 193 | /// \brief Callback to call to request which vehicle id should be the next destination. Typically bound to queue::QueueManager::request_next_destination. | ||
1050 | 194 | // | ||
1051 | 195 | // \param func has the form int next_dest(unsigned size). the return value of func should be the next destination id, or -1 for no message to send. | ||
1052 | 196 | void set_destination_cb(MACIdFunc func) { callback_dest = func; } | ||
1053 | 197 | /// \brief Callback for initiate a tranmission. Typically bound to acomms::ModemDriverBase::initiate_transmission. | ||
1054 | 198 | void set_initiate_transmission_cb(MACMsgFunc1 func) { callback_initiate_transmission = func; } | ||
1055 | 199 | |||
1056 | 200 | /// \brief Callback for initiate ranging ("ping"). Typically bound to acomms::ModemDriverBase::initiate_ranging. | ||
1057 | 201 | void set_initiate_ranging_cb(MACMsgFunc1 func) { callback_initiate_ranging = func; } | ||
1058 | 202 | |||
1059 | 203 | //@} | ||
1060 | 204 | |||
1061 | 205 | /// \name Get | ||
1062 | 206 | //@{ | ||
1063 | 207 | int rate() { return rate_; } | ||
1064 | 208 | unsigned slot_time() { return slot_time_; } | ||
1065 | 209 | MACType type() { return type_; } | ||
1066 | 210 | //@} | ||
1067 | 211 | |||
1068 | 212 | |||
1069 | 213 | /// \example libamac/examples/amac_simple/amac_simple.cpp | ||
1070 | 214 | /// amac_simple.cpp | ||
1071 | 215 | |||
1072 | 216 | /// \example acomms/examples/chat/chat.cpp | ||
1073 | 217 | |||
1074 | 218 | private: | ||
1075 | 219 | enum { NO_AVAILABLE_DESTINATION = -1 }; | ||
1076 | 220 | MACIdFunc callback_dest; | ||
1077 | 221 | MACMsgFunc1 callback_initiate_transmission; | ||
1078 | 222 | MACMsgFunc1 callback_initiate_ranging; | ||
1079 | 223 | |||
1080 | 224 | boost::posix_time::ptime next_cycle_time(); | ||
1081 | 225 | |||
1082 | 226 | void restart_timer(); | ||
1083 | 227 | void stop_timer(); | ||
1084 | 228 | |||
1085 | 229 | void expire_ids(); | ||
1086 | 230 | void process_cycle_size_change(); | ||
1087 | 231 | |||
1088 | 232 | unsigned cycle_count() { return slot_order_.size(); } | ||
1089 | 233 | unsigned cycle_length() { return cycle_count() * slot_time_; } | ||
1090 | 234 | |||
1091 | 235 | unsigned cycle_sum(); | ||
1092 | 236 | void position_blank(); | ||
1093 | 237 | |||
1094 | 238 | private: | ||
1095 | 239 | // (bit)-rate id number | ||
1096 | 240 | int rate_; | ||
1097 | 241 | // size of each slot (seconds) | ||
1098 | 242 | unsigned slot_time_; | ||
1099 | 243 | // how many cycles before we remove someone? | ||
1100 | 244 | unsigned expire_cycles_; | ||
1101 | 245 | |||
1102 | 246 | std::ostream* os_; | ||
1103 | 247 | |||
1104 | 248 | unsigned modem_id_; | ||
1105 | 249 | |||
1106 | 250 | // asynchronous timer | ||
1107 | 251 | asio::io_service io_; | ||
1108 | 252 | asio::deadline_timer timer_; | ||
1109 | 253 | bool timer_is_running_; | ||
1110 | 254 | |||
1111 | 255 | boost::posix_time::ptime next_cycle_t_; | ||
1112 | 256 | boost::posix_time::ptime next_slot_t_; | ||
1113 | 257 | |||
1114 | 258 | // <id, last time heard from> | ||
1115 | 259 | typedef std::multimap<unsigned, Slot>::iterator id2slot_it; | ||
1116 | 260 | |||
1117 | 261 | id2slot_it blank_it_; | ||
1118 | 262 | std::list<id2slot_it> slot_order_; | ||
1119 | 263 | std::multimap<unsigned, Slot> id2slot_; | ||
1120 | 264 | |||
1121 | 265 | std::list<id2slot_it>::iterator current_slot_; | ||
1122 | 266 | |||
1123 | 267 | unsigned cycles_since_day_start_; | ||
1124 | 268 | |||
1125 | 269 | // entropy value used to determine how the "blank" slot moves around relative to the values of the modem ids. determining the proper value for this is a bit of work and i will detail when i have time. | ||
1126 | 270 | enum { ENTROPY = 5 }; | ||
1127 | 271 | MACType type_; | ||
1128 | 272 | }; | ||
1129 | 273 | |||
1130 | 274 | /// | ||
1131 | 275 | inline bool operator<(const std::map<unsigned, Slot>::iterator& a, const std::map<unsigned, Slot>::iterator& b) | ||
1132 | 276 | { return a->second.src() < b->second.src(); } | ||
1133 | 277 | |||
1134 | 278 | /// Are two amac::Slot equal? | ||
1135 | 279 | inline bool operator==(const Slot& a, const Slot& b) | ||
1136 | 280 | { | ||
1137 | 281 | return a.src() == b.src() && a.dest() == b.dest() && a.rate() == b.rate() && a.type() == b.type() && a.slot_time() == b.slot_time(); | ||
1138 | 121 | } | 282 | } |
1301 | 122 | 283 | ||
1302 | 123 | boost::posix_time::ptime last_heard_time() const { return last_heard_time_; } | 284 | |
1141 | 124 | unsigned slot_time() const { return slot_time_; } | ||
1142 | 125 | //@} | ||
1143 | 126 | |||
1144 | 127 | enum { query_destination = -1 }; | ||
1145 | 128 | |||
1146 | 129 | |||
1147 | 130 | private: | ||
1148 | 131 | unsigned src_; | ||
1149 | 132 | int dest_; | ||
1150 | 133 | int rate_; | ||
1151 | 134 | SlotType type_; | ||
1152 | 135 | unsigned slot_time_; | ||
1153 | 136 | boost::posix_time::ptime last_heard_time_; | ||
1154 | 137 | }; | ||
1155 | 138 | |||
1156 | 139 | inline std::ostream& operator<<(std::ostream& os, const Slot& s) | ||
1157 | 140 | { return os << "src: " << s.src() << " | dest: " << s.dest() << " | rate: " << s.rate() << " | slot_time: " << s.slot_time(); } | ||
1158 | 141 | |||
1159 | 142 | |||
1160 | 143 | /// provides an API to the goby-acomms MAC library. | ||
1161 | 144 | class MACManager | ||
1162 | 145 | { | ||
1163 | 146 | |||
1164 | 147 | public: | ||
1165 | 148 | |||
1166 | 149 | /// \name Constructors/Destructor | ||
1167 | 150 | //@{ | ||
1168 | 151 | /// \brief Default constructor. | ||
1169 | 152 | /// | ||
1170 | 153 | /// \param os std::ostream object or FlexOstream to capture all humanly readable runtime and debug information (optional). | ||
1171 | 154 | MACManager(std::ostream* os = 0); | ||
1172 | 155 | ~MACManager(); | ||
1173 | 156 | //@} | ||
1174 | 157 | |||
1175 | 158 | /// \brief Starts the MAC | ||
1176 | 159 | void startup(); | ||
1177 | 160 | /// \brief Must be called regularly for the MAC to perform its work | ||
1178 | 161 | void do_work(); | ||
1179 | 162 | |||
1180 | 163 | /// \brief Manually initiate a transmission out of the normal cycle. This is not normally called by the user of MACManager | ||
1181 | 164 | void send_poll(const asio::error_code&); | ||
1182 | 165 | |||
1183 | 166 | /// \brief Call every time a message is received from vehicle to "discover" this vehicle or reset the expire timer. Only needed when the type is amac::mac_slotted_tdma. | ||
1184 | 167 | /// | ||
1185 | 168 | /// \param message the new message (used to detect vehicles) | ||
1186 | 169 | void process_message(const modem::Message& m); | ||
1187 | 170 | |||
1188 | 171 | /// \name Manipulate slots | ||
1189 | 172 | //@{ | ||
1190 | 173 | /// \return iterator to newly added slot | ||
1191 | 174 | std::map<unsigned, amac::Slot>::iterator add_slot(const amac::Slot& s); | ||
1192 | 175 | /// \brief removes any slots in the cycle where amac::operator==(const Slot&, const Slot&) is true. | ||
1193 | 176 | /// | ||
1194 | 177 | /// \return true if one or more slots are removed | ||
1195 | 178 | bool remove_slot(const amac::Slot& s); | ||
1196 | 179 | void clear_all_slots() { id2slot_.clear(); slot_order_.clear(); } | ||
1197 | 180 | //@} | ||
1198 | 181 | |||
1199 | 182 | |||
1200 | 183 | /// \name Set | ||
1201 | 184 | //@{ | ||
1202 | 185 | void set_type(MACType type) { type_ = type; } | ||
1203 | 186 | void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; } | ||
1204 | 187 | void set_modem_id(const std::string& s) { set_modem_id(boost::lexical_cast<unsigned>(s)); } | ||
1205 | 188 | void set_rate(int rate) { rate_ = rate; } | ||
1206 | 189 | void set_rate(const std::string& s) { set_rate(boost::lexical_cast<int>(s)); } | ||
1207 | 190 | void set_slot_time(unsigned slot_time) { slot_time_ = slot_time; } | ||
1208 | 191 | void set_slot_time(const std::string& s) { set_slot_time(boost::lexical_cast<unsigned>(s)); } | ||
1209 | 192 | void set_expire_cycles(unsigned expire_cycles) { expire_cycles_ = expire_cycles; } | ||
1210 | 193 | void set_expire_cycles(const std::string& s) { set_expire_cycles(boost::lexical_cast<unsigned>(s)); } | ||
1211 | 194 | /// \brief Callback to call to request which vehicle id should be the next destination. Typically bound to queue::QueueManager::request_next_destination. | ||
1212 | 195 | // | ||
1213 | 196 | // \param func has the form int next_dest(unsigned size). the return value of func should be the next destination id, or -1 for no message to send. | ||
1214 | 197 | void set_destination_cb(IdFunc func) { callback_dest = func; } | ||
1215 | 198 | /// \brief Callback for initiate a tranmission. Typically bound to modem::DriverBase::initiate_transmission. | ||
1216 | 199 | void set_initiate_transmission_cb(MsgFunc1 func) { callback_initiate_transmission = func; } | ||
1217 | 200 | |||
1218 | 201 | /// \brief Callback for initiate ranging ("ping"). Typically bound to modem::DriverBase::initiate_ranging. | ||
1219 | 202 | void set_initiate_ranging_cb(MsgFunc1 func) { callback_initiate_ranging = func; } | ||
1220 | 203 | |||
1221 | 204 | //@} | ||
1222 | 205 | |||
1223 | 206 | /// \name Get | ||
1224 | 207 | //@{ | ||
1225 | 208 | int rate() { return rate_; } | ||
1226 | 209 | unsigned slot_time() { return slot_time_; } | ||
1227 | 210 | MACType type() { return type_; } | ||
1228 | 211 | //@} | ||
1229 | 212 | |||
1230 | 213 | |||
1231 | 214 | /// \example libamac/examples/amac_simple/amac_simple.cpp | ||
1232 | 215 | /// amac_simple.cpp | ||
1233 | 216 | |||
1234 | 217 | /// \example acomms/examples/chat/chat.cpp | ||
1235 | 218 | |||
1236 | 219 | private: | ||
1237 | 220 | enum { NO_AVAILABLE_DESTINATION = -1 }; | ||
1238 | 221 | IdFunc callback_dest; | ||
1239 | 222 | MsgFunc1 callback_initiate_transmission; | ||
1240 | 223 | MsgFunc1 callback_initiate_ranging; | ||
1241 | 224 | |||
1242 | 225 | boost::posix_time::ptime next_cycle_time(); | ||
1243 | 226 | |||
1244 | 227 | void restart_timer(); | ||
1245 | 228 | void stop_timer(); | ||
1246 | 229 | |||
1247 | 230 | void expire_ids(); | ||
1248 | 231 | void process_cycle_size_change(); | ||
1249 | 232 | |||
1250 | 233 | unsigned cycle_count() { return slot_order_.size(); } | ||
1251 | 234 | unsigned cycle_length() { return cycle_count() * slot_time_; } | ||
1252 | 235 | |||
1253 | 236 | boost::posix_time::ptime now() { return boost::posix_time::second_clock::universal_time(); } | ||
1254 | 237 | unsigned cycle_sum(); | ||
1255 | 238 | void position_blank(); | ||
1256 | 239 | |||
1257 | 240 | private: | ||
1258 | 241 | // (bit)-rate id number | ||
1259 | 242 | int rate_; | ||
1260 | 243 | // size of each slot (seconds) | ||
1261 | 244 | unsigned slot_time_; | ||
1262 | 245 | // how many cycles before we remove someone? | ||
1263 | 246 | unsigned expire_cycles_; | ||
1264 | 247 | |||
1265 | 248 | std::ostream* os_; | ||
1266 | 249 | |||
1267 | 250 | unsigned modem_id_; | ||
1268 | 251 | |||
1269 | 252 | // asynchronous timer | ||
1270 | 253 | asio::io_service io_; | ||
1271 | 254 | asio::deadline_timer timer_; | ||
1272 | 255 | bool timer_is_running_; | ||
1273 | 256 | |||
1274 | 257 | boost::posix_time::ptime next_cycle_t_; | ||
1275 | 258 | boost::posix_time::ptime next_slot_t_; | ||
1276 | 259 | |||
1277 | 260 | // <id, last time heard from> | ||
1278 | 261 | typedef std::multimap<unsigned, Slot>::iterator id2slot_it; | ||
1279 | 262 | |||
1280 | 263 | id2slot_it blank_it_; | ||
1281 | 264 | std::list<id2slot_it> slot_order_; | ||
1282 | 265 | std::multimap<unsigned, Slot> id2slot_; | ||
1283 | 266 | |||
1284 | 267 | std::list<id2slot_it>::iterator current_slot_; | ||
1285 | 268 | |||
1286 | 269 | unsigned cycles_since_day_start_; | ||
1287 | 270 | |||
1288 | 271 | // entropy value used to determine how the "blank" slot moves around relative to the values of the modem ids. determining the proper value for this is a bit of work and i will detail when i have time. | ||
1289 | 272 | enum { ENTROPY = 5 }; | ||
1290 | 273 | MACType type_; | ||
1291 | 274 | }; | ||
1292 | 275 | |||
1293 | 276 | /// | ||
1294 | 277 | inline bool operator<(const std::map<unsigned, Slot>::iterator& a, const std::map<unsigned, Slot>::iterator& b) | ||
1295 | 278 | { return a->second.src() < b->second.src(); } | ||
1296 | 279 | |||
1297 | 280 | /// Are two amac::Slot equal? | ||
1298 | 281 | inline bool operator==(const Slot& a, const Slot& b) | ||
1299 | 282 | { | ||
1300 | 283 | return a.src() == b.src() && a.dest() == b.dest() && a.rate() == b.rate() && a.type() == b.type() && a.slot_time() == b.slot_time(); | ||
1303 | 284 | } | 285 | } |
1304 | 285 | |||
1305 | 286 | |||
1306 | 287 | } | 286 | } |
1307 | 288 | 287 | ||
1308 | 289 | |||
1309 | 290 | #endif | 288 | #endif |
1310 | 291 | 289 | ||
1311 | === modified file 'src/acomms/libdccl/CMakeLists.txt' | |||
1312 | --- src/acomms/libdccl/CMakeLists.txt 2010-03-15 16:21:43 +0000 | |||
1313 | +++ src/acomms/libdccl/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
1314 | @@ -4,8 +4,8 @@ | |||
1315 | 4 | include_directories(${Boost_INCLUDE_DIR}) | 4 | include_directories(${Boost_INCLUDE_DIR}) |
1316 | 5 | 5 | ||
1317 | 6 | file(GLOB SRC *.cpp *.c) | 6 | file(GLOB SRC *.cpp *.c) |
1320 | 7 | add_library(dccl SHARED ${SRC}) | 7 | add_library(goby_dccl SHARED ${SRC}) |
1321 | 8 | target_link_libraries(dccl xerces-c crypto++) | 8 | target_link_libraries(goby_dccl xerces-c crypto++ ${Boost_LIBRARIES}) |
1322 | 9 | endif() | 9 | endif() |
1323 | 10 | 10 | ||
1324 | 11 | add_subdirectory(examples) | 11 | add_subdirectory(examples) |
1325 | 12 | 12 | ||
1326 | === modified file 'src/acomms/libdccl/dccl.cpp' | |||
1327 | --- src/acomms/libdccl/dccl.cpp 2010-06-15 04:51:47 +0000 | |||
1328 | +++ src/acomms/libdccl/dccl.cpp 2010-07-15 12:38:39 +0000 | |||
1329 | @@ -26,31 +26,39 @@ | |||
1330 | 26 | #include "dccl.h" | 26 | #include "dccl.h" |
1331 | 27 | #include "message_xml_callbacks.h" | 27 | #include "message_xml_callbacks.h" |
1332 | 28 | 28 | ||
1333 | 29 | using goby::util::goby_time; | ||
1334 | 30 | |||
1335 | 29 | ///////////////////// | 31 | ///////////////////// |
1336 | 30 | // public methods (general use) | 32 | // public methods (general use) |
1337 | 31 | ///////////////////// | 33 | ///////////////////// |
1339 | 32 | dccl::DCCLCodec::DCCLCodec() : start_time_(time(NULL)), modem_id_(0) | 34 | goby::acomms::DCCLCodec::DCCLCodec() |
1340 | 35 | : start_time_(goby_time()), | ||
1341 | 36 | modem_id_(0) | ||
1342 | 33 | { } | 37 | { } |
1343 | 34 | 38 | ||
1345 | 35 | dccl::DCCLCodec::DCCLCodec(const std::string& file, const std::string schema) : start_time_(time(NULL)), modem_id_(0) | 39 | goby::acomms::DCCLCodec::DCCLCodec(const std::string& file, const std::string schema) |
1346 | 40 | : start_time_(goby_time()), | ||
1347 | 41 | modem_id_(0) | ||
1348 | 36 | { add_xml_message_file(file, schema); } | 42 | { add_xml_message_file(file, schema); } |
1349 | 37 | 43 | ||
1352 | 38 | dccl::DCCLCodec::DCCLCodec(const std::set<std::string>& files, | 44 | goby::acomms::DCCLCodec::DCCLCodec(const std::set<std::string>& files, |
1353 | 39 | const std::string schema) : start_time_(time(NULL)), modem_id_(0) | 45 | const std::string schema) |
1354 | 46 | : start_time_(goby_time()), | ||
1355 | 47 | modem_id_(0) | ||
1356 | 40 | { | 48 | { |
1357 | 41 | BOOST_FOREACH(const std::string& s, files) | 49 | BOOST_FOREACH(const std::string& s, files) |
1358 | 42 | add_xml_message_file(s, schema); | 50 | add_xml_message_file(s, schema); |
1359 | 43 | } | 51 | } |
1360 | 44 | 52 | ||
1362 | 45 | std::set<unsigned> dccl::DCCLCodec::add_xml_message_file(const std::string& xml_file, | 53 | std::set<unsigned> goby::acomms::DCCLCodec::add_xml_message_file(const std::string& xml_file, |
1363 | 46 | const std::string xml_schema) | 54 | const std::string xml_schema) |
1364 | 47 | { | 55 | { |
1365 | 48 | size_t begin_size = messages_.size(); | 56 | size_t begin_size = messages_.size(); |
1366 | 49 | 57 | ||
1367 | 50 | 58 | ||
1368 | 51 | // Register handlers for XML parsing | 59 | // Register handlers for XML parsing |
1371 | 52 | MessageContentHandler content(messages_); | 60 | DCCLMessageContentHandler content(messages_); |
1372 | 53 | MessageErrorHandler error; | 61 | DCCLMessageErrorHandler error; |
1373 | 54 | // instantiate a parser for the xml message files | 62 | // instantiate a parser for the xml message files |
1374 | 55 | XMLParser parser(content, error); | 63 | XMLParser parser(content, error); |
1375 | 56 | // parse(file, [schema]) | 64 | // parse(file, [schema]) |
1376 | @@ -77,59 +85,59 @@ | |||
1377 | 77 | return added_ids; | 85 | return added_ids; |
1378 | 78 | } | 86 | } |
1379 | 79 | 87 | ||
1381 | 80 | std::set<unsigned> dccl::DCCLCodec::all_message_ids() | 88 | std::set<unsigned> goby::acomms::DCCLCodec::all_message_ids() |
1382 | 81 | { | 89 | { |
1383 | 82 | std::set<unsigned> s; | 90 | std::set<unsigned> s; |
1385 | 83 | BOOST_FOREACH(const Message &msg, messages_) | 91 | BOOST_FOREACH(const DCCLMessage &msg, messages_) |
1386 | 84 | s.insert(msg.id()); | 92 | s.insert(msg.id()); |
1387 | 85 | return s; | 93 | return s; |
1388 | 86 | } | 94 | } |
1390 | 87 | std::set<std::string> dccl::DCCLCodec::all_message_names() | 95 | std::set<std::string> goby::acomms::DCCLCodec::all_message_names() |
1391 | 88 | { | 96 | { |
1392 | 89 | std::set<std::string> s; | 97 | std::set<std::string> s; |
1394 | 90 | BOOST_FOREACH(const Message &msg, messages_) | 98 | BOOST_FOREACH(const DCCLMessage &msg, messages_) |
1395 | 91 | s.insert(msg.name()); | 99 | s.insert(msg.name()); |
1396 | 92 | return s; | 100 | return s; |
1397 | 93 | } | 101 | } |
1398 | 94 | 102 | ||
1399 | 95 | 103 | ||
1401 | 96 | std::string dccl::DCCLCodec::summary() const | 104 | std::string goby::acomms::DCCLCodec::summary() const |
1402 | 97 | { | 105 | { |
1403 | 98 | std::string out; | 106 | std::string out; |
1405 | 99 | for(std::vector<Message>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 107 | for(std::vector<DCCLMessage>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) |
1406 | 100 | out += it->get_display(); | 108 | out += it->get_display(); |
1407 | 101 | return out; | 109 | return out; |
1408 | 102 | } | 110 | } |
1409 | 103 | 111 | ||
1411 | 104 | std::string dccl::DCCLCodec::brief_summary() const | 112 | std::string goby::acomms::DCCLCodec::brief_summary() const |
1412 | 105 | { | 113 | { |
1413 | 106 | std::string out; | 114 | std::string out; |
1415 | 107 | for(std::vector<Message>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 115 | for(std::vector<DCCLMessage>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) |
1416 | 108 | out += it->get_short_display(); | 116 | out += it->get_short_display(); |
1417 | 109 | return out; | 117 | return out; |
1418 | 110 | } | 118 | } |
1419 | 111 | 119 | ||
1434 | 112 | void dccl::DCCLCodec::add_algorithm(const std::string& name, AlgFunction1 func) | 120 | void goby::acomms::DCCLCodec::add_algorithm(const std::string& name, AlgFunction1 func) |
1435 | 113 | { | 121 | { |
1436 | 114 | AlgorithmPerformer* ap = AlgorithmPerformer::getInstance(); | 122 | DCCLAlgorithmPerformer* ap = DCCLAlgorithmPerformer::getInstance(); |
1437 | 115 | ap -> add_algorithm(name, func); | 123 | ap -> add_algorithm(name, func); |
1438 | 116 | } | 124 | } |
1439 | 117 | 125 | ||
1440 | 118 | void dccl::DCCLCodec::add_adv_algorithm(const std::string& name, AlgFunction2 func) | 126 | void goby::acomms::DCCLCodec::add_adv_algorithm(const std::string& name, AlgFunction2 func) |
1441 | 119 | { | 127 | { |
1442 | 120 | AlgorithmPerformer* ap = AlgorithmPerformer::getInstance(); | 128 | DCCLAlgorithmPerformer* ap = DCCLAlgorithmPerformer::getInstance(); |
1443 | 121 | ap -> add_algorithm(name, func); | 129 | ap -> add_algorithm(name, func); |
1444 | 122 | } | 130 | } |
1445 | 123 | 131 | ||
1446 | 124 | 132 | ||
1447 | 125 | std::ostream& dccl::operator<< (std::ostream& out, const DCCLCodec& d) | 133 | std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLCodec& d) |
1448 | 126 | { | 134 | { |
1449 | 127 | out << d.summary(); | 135 | out << d.summary(); |
1450 | 128 | return out; | 136 | return out; |
1451 | 129 | } | 137 | } |
1452 | 130 | 138 | ||
1453 | 131 | 139 | ||
1455 | 132 | std::ostream& dccl::operator<< (std::ostream& out, const std::set<std::string>& s) | 140 | std::ostream& goby::acomms::operator<< (std::ostream& out, const std::set<std::string>& s) |
1456 | 133 | { | 141 | { |
1457 | 134 | out << "std::set<std::string>:" << std::endl; | 142 | out << "std::set<std::string>:" << std::endl; |
1458 | 135 | for (std::set<std::string>::const_iterator it = s.begin(), n = s.end(); it != n; ++it) | 143 | for (std::set<std::string>::const_iterator it = s.begin(), n = s.end(); it != n; ++it) |
1459 | @@ -137,7 +145,7 @@ | |||
1460 | 137 | return out; | 145 | return out; |
1461 | 138 | } | 146 | } |
1462 | 139 | 147 | ||
1464 | 140 | std::ostream& dccl::operator<< (std::ostream& out, const std::set<unsigned>& s) | 148 | std::ostream& goby::acomms::operator<< (std::ostream& out, const std::set<unsigned>& s) |
1465 | 141 | { | 149 | { |
1466 | 142 | out << "std::set<unsigned>:" << std::endl; | 150 | out << "std::set<unsigned>:" << std::endl; |
1467 | 143 | for (std::set<unsigned>::const_iterator it = s.begin(), n = s.end(); it != n; ++it) | 151 | for (std::set<unsigned>::const_iterator it = s.begin(), n = s.end(); it != n; ++it) |
1468 | @@ -155,9 +163,9 @@ | |||
1469 | 155 | // to be processed. this allows the SAME moos trigger variable | 163 | // to be processed. this allows the SAME moos trigger variable |
1470 | 156 | // to be used to trigger creation of different messages based on the | 164 | // to be used to trigger creation of different messages based on the |
1471 | 157 | // contents of the trigger message itself. | 165 | // contents of the trigger message itself. |
1473 | 158 | bool dccl::DCCLCodec::is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value) | 166 | bool goby::acomms::DCCLCodec::is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value) |
1474 | 159 | { | 167 | { |
1476 | 160 | for (std::vector<dccl::Message>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 168 | for (std::vector<DCCLMessage>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) |
1477 | 161 | { | 169 | { |
1478 | 162 | if(key == it->trigger_var() && (it->trigger_mandatory() == "" || value.find(it->trigger_mandatory()) != std::string::npos)) | 170 | if(key == it->trigger_var() && (it->trigger_mandatory() == "" || value.find(it->trigger_mandatory()) != std::string::npos)) |
1479 | 163 | id.insert(it->id()); | 171 | id.insert(it->id()); |
1480 | @@ -165,11 +173,14 @@ | |||
1481 | 165 | return (id.empty()) ? false : true; | 173 | return (id.empty()) ? false : true; |
1482 | 166 | } | 174 | } |
1483 | 167 | 175 | ||
1485 | 168 | bool dccl::DCCLCodec::is_time_trigger(std::set<unsigned>& id) | 176 | bool goby::acomms::DCCLCodec::is_time_trigger(std::set<unsigned>& id) |
1486 | 169 | { | 177 | { |
1488 | 170 | for (std::vector<dccl::Message>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 178 | using boost::posix_time::seconds; |
1489 | 179 | |||
1490 | 180 | for (std::vector<DCCLMessage>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | ||
1491 | 171 | { | 181 | { |
1493 | 172 | if(it->trigger_type() == "time" && time(NULL) > (start_time_ + it->trigger_number() * it->trigger_time())) | 182 | if(it->trigger_type() == "time" && |
1494 | 183 | goby_time() > (start_time_ + seconds(it->trigger_number() * it->trigger_time()))) | ||
1495 | 173 | { | 184 | { |
1496 | 174 | id.insert(it->id()); | 185 | id.insert(it->id()); |
1497 | 175 | // increment message counter | 186 | // increment message counter |
1498 | @@ -181,9 +192,9 @@ | |||
1499 | 181 | } | 192 | } |
1500 | 182 | 193 | ||
1501 | 183 | 194 | ||
1503 | 184 | bool dccl::DCCLCodec::is_incoming(unsigned& id, const std::string& key) | 195 | bool goby::acomms::DCCLCodec::is_incoming(unsigned& id, const std::string& key) |
1504 | 185 | { | 196 | { |
1506 | 186 | for (std::vector<dccl::Message>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 197 | for (std::vector<DCCLMessage>::const_iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) |
1507 | 187 | { | 198 | { |
1508 | 188 | if (key == it->in_var()) | 199 | if (key == it->in_var()) |
1509 | 189 | { | 200 | { |
1510 | @@ -199,55 +210,55 @@ | |||
1511 | 199 | ///////////////////// | 210 | ///////////////////// |
1512 | 200 | 211 | ||
1513 | 201 | 212 | ||
1515 | 202 | void dccl::DCCLCodec::check_duplicates() | 213 | void goby::acomms::DCCLCodec::check_duplicates() |
1516 | 203 | { | 214 | { |
1519 | 204 | std::map<unsigned, std::vector<Message>::iterator> all_ids; | 215 | std::map<unsigned, std::vector<DCCLMessage>::iterator> all_ids; |
1520 | 205 | for(std::vector<Message>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) | 216 | for(std::vector<DCCLMessage>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it) |
1521 | 206 | { | 217 | { |
1522 | 207 | unsigned id = it->id(); | 218 | unsigned id = it->id(); |
1523 | 208 | 219 | ||
1525 | 209 | std::map<unsigned, std::vector<Message>::iterator>::const_iterator id_it = all_ids.find(id); | 220 | std::map<unsigned, std::vector<DCCLMessage>::iterator>::const_iterator id_it = all_ids.find(id); |
1526 | 210 | if(id_it != all_ids.end()) | 221 | if(id_it != all_ids.end()) |
1527 | 211 | throw std::runtime_error(std::string("DCCL: duplicate variable id " + boost::lexical_cast<std::string>(id) + " specified for " + it->name() + " and " + id_it->second->name())); | 222 | throw std::runtime_error(std::string("DCCL: duplicate variable id " + boost::lexical_cast<std::string>(id) + " specified for " + it->name() + " and " + id_it->second->name())); |
1528 | 212 | 223 | ||
1530 | 213 | all_ids.insert(std::pair<unsigned, std::vector<Message>::iterator>(id, it)); | 224 | all_ids.insert(std::pair<unsigned, std::vector<DCCLMessage>::iterator>(id, it)); |
1531 | 214 | } | 225 | } |
1532 | 215 | } | 226 | } |
1533 | 216 | 227 | ||
1566 | 217 | std::vector<dccl::Message>::const_iterator dccl::DCCLCodec::to_iterator(const std::string& message_name) const | 228 | std::vector<goby::acomms::DCCLMessage>::const_iterator goby::acomms::DCCLCodec::to_iterator(const std::string& message_name) const |
1567 | 218 | { | 229 | { |
1568 | 219 | if(name2messages_.count(message_name)) | 230 | if(name2messages_.count(message_name)) |
1569 | 220 | return messages_.begin() + name2messages_.find(message_name)->second; | 231 | return messages_.begin() + name2messages_.find(message_name)->second; |
1570 | 221 | else | 232 | else |
1571 | 222 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + message_name + "] which is not loaded")); | 233 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + message_name + "] which is not loaded")); |
1572 | 223 | } | 234 | } |
1573 | 224 | std::vector<dccl::Message>::iterator dccl::DCCLCodec::to_iterator(const std::string& message_name) | 235 | std::vector<goby::acomms::DCCLMessage>::iterator goby::acomms::DCCLCodec::to_iterator(const std::string& message_name) |
1574 | 225 | { | 236 | { |
1575 | 226 | if(name2messages_.count(message_name)) | 237 | if(name2messages_.count(message_name)) |
1576 | 227 | return messages_.begin() + name2messages_.find(message_name)->second; | 238 | return messages_.begin() + name2messages_.find(message_name)->second; |
1577 | 228 | else | 239 | else |
1578 | 229 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + message_name + "] which is not loaded")); | 240 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + message_name + "] which is not loaded")); |
1579 | 230 | } | 241 | } |
1580 | 231 | std::vector<dccl::Message>::const_iterator dccl::DCCLCodec::to_iterator(const unsigned& id) const | 242 | std::vector<goby::acomms::DCCLMessage>::const_iterator goby::acomms::DCCLCodec::to_iterator(const unsigned& id) const |
1581 | 232 | { | 243 | { |
1582 | 233 | if(id2messages_.count(id)) | 244 | if(id2messages_.count(id)) |
1583 | 234 | return messages_.begin() + id2messages_.find(id)->second; | 245 | return messages_.begin() + id2messages_.find(id)->second; |
1584 | 235 | else | 246 | else |
1585 | 236 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + boost::lexical_cast<std::string>(id) + "] which is not loaded")); | 247 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + boost::lexical_cast<std::string>(id) + "] which is not loaded")); |
1586 | 237 | } | 248 | } |
1587 | 238 | 249 | ||
1588 | 239 | std::vector<dccl::Message>::iterator dccl::DCCLCodec::to_iterator(const unsigned& id) | 250 | std::vector<goby::acomms::DCCLMessage>::iterator goby::acomms::DCCLCodec::to_iterator(const unsigned& id) |
1589 | 240 | { | 251 | { |
1590 | 241 | if(id2messages_.count(id)) | 252 | if(id2messages_.count(id)) |
1591 | 242 | return messages_.begin() + id2messages_.find(id)->second; | 253 | return messages_.begin() + id2messages_.find(id)->second; |
1592 | 243 | else | 254 | else |
1593 | 244 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + boost::lexical_cast<std::string>(id) + "] which is not loaded")); | 255 | throw std::runtime_error(std::string("DCCL: attempted an operation on message [" + boost::lexical_cast<std::string>(id) + "] which is not loaded")); |
1594 | 245 | } | 256 | } |
1595 | 246 | 257 | ||
1596 | 247 | 258 | ||
1597 | 248 | void dccl::DCCLCodec::encode_private(std::vector<Message>::iterator it, | 259 | void goby::acomms::DCCLCodec::encode_private(std::vector<DCCLMessage>::iterator it, |
1598 | 249 | std::string& out, | 260 | std::string& out, |
1600 | 250 | std::map<std::string, std::vector<MessageVal> > in /* copy */) | 261 | std::map<std::string, std::vector<DCCLMessageVal> > in /* copy */) |
1601 | 251 | { | 262 | { |
1602 | 252 | // 1. encode parts | 263 | // 1. encode parts |
1603 | 253 | std::string body, head; | 264 | std::string body, head; |
1604 | @@ -267,9 +278,9 @@ | |||
1605 | 267 | hex_encode(out); | 278 | hex_encode(out); |
1606 | 268 | } | 279 | } |
1607 | 269 | 280 | ||
1609 | 270 | void dccl::DCCLCodec::decode_private(std::vector<Message>::iterator it, | 281 | void goby::acomms::DCCLCodec::decode_private(std::vector<DCCLMessage>::iterator it, |
1610 | 271 | std::string in, | 282 | std::string in, |
1612 | 272 | std::map<std::string, std::vector<MessageVal> >& out) | 283 | std::map<std::string, std::vector<DCCLMessageVal> >& out) |
1613 | 273 | { | 284 | { |
1614 | 274 | // 4. hex decode | 285 | // 4. hex decode |
1615 | 275 | hex_decode(in); | 286 | hex_decode(in); |
1616 | @@ -278,9 +289,9 @@ | |||
1617 | 278 | in.resize(in.find_last_not_of(char(0))+1); | 289 | in.resize(in.find_last_not_of(char(0))+1); |
1618 | 279 | 290 | ||
1619 | 280 | // 3. split body and header (avoid substr::out_of_range) | 291 | // 3. split body and header (avoid substr::out_of_range) |
1623 | 281 | std::string body = (acomms::NUM_HEADER_BYTES < in.size()) ? | 292 | std::string body = (DCCL_NUM_HEADER_BYTES < in.size()) ? |
1624 | 282 | in.substr(acomms::NUM_HEADER_BYTES) : ""; | 293 | in.substr(DCCL_NUM_HEADER_BYTES) : ""; |
1625 | 283 | std::string head = in.substr(0, acomms::NUM_HEADER_BYTES); | 294 | std::string head = in.substr(0, DCCL_NUM_HEADER_BYTES); |
1626 | 284 | 295 | ||
1627 | 285 | // 2. decrypt | 296 | // 2. decrypt |
1628 | 286 | if(!crypto_key_.empty()) decrypt(body, head); | 297 | if(!crypto_key_.empty()) decrypt(body, head); |
1629 | @@ -293,33 +304,33 @@ | |||
1630 | 293 | 304 | ||
1631 | 294 | } | 305 | } |
1632 | 295 | 306 | ||
1636 | 296 | void dccl::DCCLCodec::encode_private(std::vector<Message>::iterator it, | 307 | void goby::acomms::DCCLCodec::encode_private(std::vector<DCCLMessage>::iterator it, |
1637 | 297 | modem::Message& out_msg, | 308 | ModemMessage& out_msg, |
1638 | 298 | const std::map<std::string, std::vector<MessageVal> >& in) | 309 | const std::map<std::string, std::vector<DCCLMessageVal> >& in) |
1639 | 299 | { | 310 | { |
1640 | 300 | std::string out; | 311 | std::string out; |
1641 | 301 | encode_private(it, out, in); | 312 | encode_private(it, out, in); |
1642 | 302 | 313 | ||
1644 | 303 | dccl::DCCLHeaderDecoder head_dec(out); | 314 | DCCLHeaderDecoder head_dec(out); |
1645 | 304 | 315 | ||
1646 | 305 | out_msg.set_data(out); | 316 | out_msg.set_data(out); |
1647 | 306 | 317 | ||
1651 | 307 | MessageVal& t = head_dec[acomms::head_time]; | 318 | DCCLMessageVal& t = head_dec[head_time]; |
1652 | 308 | MessageVal& src = head_dec[acomms::head_src_id]; | 319 | DCCLMessageVal& src = head_dec[head_src_id]; |
1653 | 309 | MessageVal& dest = head_dec[acomms::head_dest_id]; | 320 | DCCLMessageVal& dest = head_dec[head_dest_id]; |
1654 | 310 | 321 | ||
1656 | 311 | out_msg.set_t(long(t)); | 322 | out_msg.set_time(double(t)); |
1657 | 312 | out_msg.set_src(long(src)); | 323 | out_msg.set_src(long(src)); |
1658 | 313 | out_msg.set_dest(long(dest)); | 324 | out_msg.set_dest(long(dest)); |
1659 | 314 | } | 325 | } |
1660 | 315 | 326 | ||
1664 | 316 | void dccl::DCCLCodec::decode_private(std::vector<Message>::iterator it, | 327 | void goby::acomms::DCCLCodec::decode_private(std::vector<DCCLMessage>::iterator it, |
1665 | 317 | const modem::Message& in_msg, | 328 | const ModemMessage& in_msg, |
1666 | 318 | std::map<std::string,std::vector<MessageVal> >& out) | 329 | std::map<std::string,std::vector<DCCLMessageVal> >& out) |
1667 | 319 | { decode_private(it, in_msg.data(), out); } | 330 | { decode_private(it, in_msg.data(), out); } |
1668 | 320 | 331 | ||
1669 | 321 | 332 | ||
1671 | 322 | void dccl::DCCLCodec::set_crypto_passphrase(const std::string& s) | 333 | void goby::acomms::DCCLCodec::set_crypto_passphrase(const std::string& s) |
1672 | 323 | { | 334 | { |
1673 | 324 | using namespace CryptoPP; | 335 | using namespace CryptoPP; |
1674 | 325 | 336 | ||
1675 | @@ -328,7 +339,7 @@ | |||
1676 | 328 | } | 339 | } |
1677 | 329 | 340 | ||
1678 | 330 | 341 | ||
1680 | 331 | void dccl::DCCLCodec::encrypt(std::string& s, const std::string& nonce) | 342 | void goby::acomms::DCCLCodec::encrypt(std::string& s, const std::string& nonce) |
1681 | 332 | { | 343 | { |
1682 | 333 | using namespace CryptoPP; | 344 | using namespace CryptoPP; |
1683 | 334 | 345 | ||
1684 | @@ -346,7 +357,7 @@ | |||
1685 | 346 | s = cipher; | 357 | s = cipher; |
1686 | 347 | } | 358 | } |
1687 | 348 | 359 | ||
1689 | 349 | void dccl::DCCLCodec::decrypt(std::string& s, const std::string& nonce) | 360 | void goby::acomms::DCCLCodec::decrypt(std::string& s, const std::string& nonce) |
1690 | 350 | { | 361 | { |
1691 | 351 | using namespace CryptoPP; | 362 | using namespace CryptoPP; |
1692 | 352 | 363 | ||
1693 | 353 | 364 | ||
1694 | === modified file 'src/acomms/libdccl/dccl.h' | |||
1695 | --- src/acomms/libdccl/dccl.h 2010-06-15 04:51:47 +0000 | |||
1696 | +++ src/acomms/libdccl/dccl.h 2010-07-15 12:38:39 +0000 | |||
1697 | @@ -1,5 +1,5 @@ | |||
1698 | 1 | // copyright 2009 t. schneider tes@mit.edu | 1 | // copyright 2009 t. schneider tes@mit.edu |
1700 | 2 | // | 2 | // |
1701 | 3 | // this file is part of the Dynamic Compact Control Language (DCCL), | 3 | // this file is part of the Dynamic Compact Control Language (DCCL), |
1702 | 4 | // the goby-acomms codec. goby-acomms is a collection of libraries | 4 | // the goby-acomms codec. goby-acomms is a collection of libraries |
1703 | 5 | // for acoustic underwater networking | 5 | // for acoustic underwater networking |
1704 | @@ -20,7 +20,6 @@ | |||
1705 | 20 | #ifndef DCCL20091211H | 20 | #ifndef DCCL20091211H |
1706 | 21 | #define DCCL20091211H | 21 | #define DCCL20091211H |
1707 | 22 | 22 | ||
1708 | 23 | #include <ctime> | ||
1709 | 24 | #include <string> | 23 | #include <string> |
1710 | 25 | #include <set> | 24 | #include <set> |
1711 | 26 | #include <map> | 25 | #include <map> |
1712 | @@ -28,494 +27,495 @@ | |||
1713 | 28 | #include <stdexcept> | 27 | #include <stdexcept> |
1714 | 29 | #include <vector> | 28 | #include <vector> |
1715 | 30 | 29 | ||
1717 | 31 | #include "acomms/xml/xml_parser.h" | 30 | #include "goby/acomms/xml/xml_parser.h" |
1718 | 31 | #include "goby/util/time.h" | ||
1719 | 32 | 32 | ||
1720 | 33 | #include "message.h" | 33 | #include "message.h" |
1721 | 34 | #include "message_val.h" | 34 | #include "message_val.h" |
1722 | 35 | 35 | ||
1727 | 36 | /// \brief contains Dynamic Compact Control Language objects. | 36 | namespace goby |
1724 | 37 | /// | ||
1725 | 38 | /// Use \code #include <goby/acomms/dccl.h> \endcode to gain access to all these objects. | ||
1726 | 39 | namespace dccl | ||
1728 | 40 | { | 37 | { |
1729 | 41 | 38 | ||
2031 | 42 | /// use this for displaying a human readable version | 39 | namespace acomms |
2032 | 43 | template<typename Value> | 40 | { |
2033 | 44 | std::ostream& operator<< (std::ostream& out, const std::map<std::string, Value>& m) | 41 | |
2034 | 45 | { | 42 | /// use this for displaying a human readable version |
2035 | 46 | typedef std::pair<std::string, Value> P; | 43 | template<typename Value> |
2036 | 47 | BOOST_FOREACH(const P& p, m) | 44 | std::ostream& operator<< (std::ostream& out, const std::map<std::string, Value>& m) |
2037 | 48 | { | 45 | { |
2038 | 49 | out << "\t" << "key: " << p.first << std::endl | 46 | typedef std::pair<std::string, Value> P; |
2039 | 50 | << "\t" << "value: " << p.second << std::endl; | 47 | BOOST_FOREACH(const P& p, m) |
2040 | 51 | } | 48 | { |
2041 | 52 | return out; | 49 | out << "\t" << "key: " << p.first << std::endl |
2042 | 53 | } | 50 | << "\t" << "value: " << p.second << std::endl; |
2043 | 54 | 51 | } | |
2044 | 55 | template<typename Value> | 52 | return out; |
2045 | 56 | std::ostream& operator<< (std::ostream& out, const std::multimap<std::string, Value>& m) | 53 | } |
2046 | 57 | { | 54 | |
2047 | 58 | typedef std::pair<std::string, Value> P; | 55 | template<typename Value> |
2048 | 59 | BOOST_FOREACH(const P& p, m) | 56 | std::ostream& operator<< (std::ostream& out, const std::multimap<std::string, Value>& m) |
2049 | 60 | { | 57 | { |
2050 | 61 | out << "\t" << "key: " << p.first << std::endl | 58 | typedef std::pair<std::string, Value> P; |
2051 | 62 | << "\t" << "value: " << p.second << std::endl; | 59 | BOOST_FOREACH(const P& p, m) |
2052 | 63 | } | 60 | { |
2053 | 64 | return out; | 61 | out << "\t" << "key: " << p.first << std::endl |
2054 | 65 | } | 62 | << "\t" << "value: " << p.second << std::endl; |
2055 | 66 | 63 | } | |
2056 | 67 | 64 | return out; | |
2057 | 68 | /// use this for displaying a human readable version of this STL object | 65 | } |
2058 | 69 | std::ostream& operator<< (std::ostream& out, const std::set<unsigned>& s); | 66 | |
2059 | 70 | /// use this for displaying a human readable version of this STL object | 67 | |
2060 | 71 | std::ostream& operator<< (std::ostream& out, const std::set<std::string>& s); | 68 | /// use this for displaying a human readable version of this STL object |
2061 | 72 | 69 | std::ostream& operator<< (std::ostream& out, const std::set<unsigned>& s); | |
2062 | 73 | 70 | /// use this for displaying a human readable version of this STL object | |
2063 | 74 | 71 | std::ostream& operator<< (std::ostream& out, const std::set<std::string>& s); | |
2064 | 75 | /// provides an API to the Dynamic CCL Codec. | 72 | |
2065 | 76 | class DCCLCodec | 73 | |
2066 | 77 | { | 74 | |
2067 | 78 | public: | 75 | /// provides an API to the Dynamic CCL Codec. |
2068 | 79 | /// \name Constructors/Destructor | 76 | class DCCLCodec |
2069 | 80 | //@{ | 77 | { |
2070 | 81 | /// \brief Instantiate with no XML files. | 78 | public: |
2071 | 82 | DCCLCodec(); | 79 | /// \name Constructors/Destructor |
2072 | 83 | /// \brief Instantiate with a single XML file. | 80 | //@{ |
2073 | 84 | /// | 81 | /// \brief Instantiate with no XML files. |
2074 | 85 | /// \param file path to an XML message file (i.e. contains \ref tag_layout and (optionally) \ref tag_publish sections) to parse for use by the codec. | 82 | DCCLCodec(); |
2075 | 86 | /// \param schema path (absolute or relative to the XML file path) for the validating schema (message_schema.xsd) (optional). | 83 | /// \brief Instantiate with a single XML file. |
2076 | 87 | DCCLCodec(const std::string& file, const std::string schema = ""); | 84 | /// |
2077 | 88 | 85 | /// \param file path to an XML message file (i.e. contains \ref tag_layout and (optionally) \ref tag_publish sections) to parse for use by the codec. | |
2078 | 89 | /// \brief Instantiate with a set of XML files. | 86 | /// \param schema path (absolute or relative to the XML file path) for the validating schema (message_schema.xsd) (optional). |
2079 | 90 | /// | 87 | DCCLCodec(const std::string& file, const std::string schema = ""); |
2080 | 91 | /// \param files set of paths to XML message files to parse for use by the codec. | 88 | |
2081 | 92 | /// \param schema path (absolute or relative to the XML file path) for the validating schema (message_schema.xsd) (optional). | 89 | /// \brief Instantiate with a set of XML files. |
2082 | 93 | DCCLCodec(const std::set<std::string>& files, const std::string schema = ""); | 90 | /// |
2083 | 94 | 91 | /// \param files set of paths to XML message files to parse for use by the codec. | |
2084 | 95 | /// destructor | 92 | /// \param schema path (absolute or relative to the XML file path) for the validating schema (message_schema.xsd) (optional). |
2085 | 96 | ~DCCLCodec() {} | 93 | DCCLCodec(const std::set<std::string>& files, const std::string schema = ""); |
2086 | 97 | //@} | 94 | |
2087 | 98 | 95 | /// destructor | |
2088 | 99 | /// \name Initialization Methods. | 96 | ~DCCLCodec() {} |
2089 | 100 | /// | 97 | //@} |
2090 | 101 | /// These methods are intended to be called before doing any work with the class. However, | 98 | |
2091 | 102 | /// they may be called at any time as desired. | 99 | /// \name Initialization Methods. |
2092 | 103 | //@{ | 100 | /// |
2093 | 104 | 101 | /// These methods are intended to be called before doing any work with the class. However, | |
2094 | 105 | /// \brief Add more messages to this instance of the codec. | 102 | /// they may be called at any time as desired. |
2095 | 106 | /// | 103 | //@{ |
2096 | 107 | /// \param xml_file path to the xml file to parse and add to this codec. | 104 | |
2097 | 108 | /// \param xml_schema path to the message_schema.xsd file to validate XML with. if using a relative path this | 105 | /// \brief Add more messages to this instance of the codec. |
2098 | 109 | /// must be relative to the directory of the xml_file, not the present working directory. if not provided | 106 | /// |
2099 | 110 | /// no validation is done. | 107 | /// \param xml_file path to the xml file to parse and add to this codec. |
2100 | 111 | /// \return returns id of the last message file parsed. note that there can be more than one message in a file | 108 | /// \param xml_schema path to the message_schema.xsd file to validate XML with. if using a relative path this |
2101 | 112 | std::set<unsigned> add_xml_message_file(const std::string& xml_file, const std::string xml_schema = ""); | 109 | /// must be relative to the directory of the xml_file, not the present working directory. if not provided |
2102 | 113 | 110 | /// no validation is done. | |
2103 | 114 | /// \brief Set the schema used for xml syntax checking. | 111 | /// \return returns id of the last message file parsed. note that there can be more than one message in a file |
2104 | 115 | /// | 112 | std::set<unsigned> add_xml_message_file(const std::string& xml_file, const std::string xml_schema = ""); |
2105 | 116 | /// location is relative to the XML file location! | 113 | |
2106 | 117 | /// if you have XML files in different places you must pass the | 114 | /// \brief Set the schema used for xml syntax checking. |
2107 | 118 | /// proper relative path (or just use absolute paths) | 115 | /// |
2108 | 119 | /// \param schema location of the message_schema.xsd file | 116 | /// location is relative to the XML file location! |
2109 | 120 | void set_schema(const std::string& schema) { xml_schema_ = schema; } | 117 | /// if you have XML files in different places you must pass the |
2110 | 121 | 118 | /// proper relative path (or just use absolute paths) | |
2111 | 122 | /// \brief Set a passphrase for encrypting all messages with | 119 | /// \param schema location of the message_schema.xsd file |
2112 | 123 | /// | 120 | void set_schema(const std::string& schema) { xml_schema_ = schema; } |
2113 | 124 | /// \param passphrase text passphrase | 121 | |
2114 | 125 | void set_crypto_passphrase(const std::string& passphrase); | 122 | /// \brief Set a passphrase for encrypting all messages with |
2115 | 126 | 123 | /// | |
2116 | 127 | /// \brief Set the %modem id for this vehicle. | 124 | /// \param passphrase text passphrase |
2117 | 128 | /// | 125 | void set_crypto_passphrase(const std::string& passphrase); |
2118 | 129 | /// \param modem_id unique (within a network) number representing the %modem on this vehicle. | 126 | |
2119 | 130 | void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; } | 127 | /// \brief Set the %modem id for this vehicle. |
2120 | 131 | 128 | /// | |
2121 | 132 | 129 | /// \param modem_id unique (within a network) number representing the %modem on this vehicle. | |
2122 | 133 | 130 | void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; } | |
2123 | 134 | /// \brief Add an algorithm callback for a dccl::MessageVal. The return value is stored back into the input parameter (dccl::MessageVal). See test.cpp for an example. | 131 | |
2124 | 135 | /// | 132 | |
2125 | 136 | /// \param name name of the algorithm (\xmltag{... algorithm="name"}) | 133 | |
2126 | 137 | /// \param func has the form void name(dccl::MessageVal& val_to_edit) (see dccl::AdvAlgFunction1). can be a function pointer (&name) or | 134 | /// \brief Add an algorithm callback for a MessageVal. The return value is stored back into the input parameter (MessageVal). See test.cpp for an example. |
2127 | 138 | /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html) | 135 | /// |
2128 | 139 | void add_algorithm(const std::string& name, AlgFunction1 func); | 136 | /// \param name name of the algorithm (\xmltag{... algorithm="name"}) |
2129 | 140 | 137 | /// \param func has the form void name(MessageVal& val_to_edit) (see AdvAlgFunction1). can be a function pointer (&name) or | |
2130 | 141 | /// \brief Add an advanced algorithm callback for any DCCL C++ type that may also require knowledge of all the other message variables | 138 | /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html) |
2131 | 142 | /// and can optionally have additional parameters | 139 | void add_algorithm(const std::string& name, AlgFunction1 func); |
2132 | 143 | /// | 140 | |
2133 | 144 | /// \param name name of the algorithm (\xmltag{... algorithm="name:param1:param2"}) | 141 | /// \brief Add an advanced algorithm callback for any DCCL C++ type that may also require knowledge of all the other message variables |
2134 | 145 | /// \param func has the form | 142 | /// and can optionally have additional parameters |
2135 | 146 | /// void name(MessageVal& val_to_edit, | 143 | /// |
2136 | 147 | /// const std::vector<std::string> params, | 144 | /// \param name name of the algorithm (\xmltag{... algorithm="name:param1:param2"}) |
2137 | 148 | /// const std::map<std::string,MessageVal>& vals) (see dccl::AdvAlgFunction3). func can be a function pointer (&name) or | 145 | /// \param func has the form |
2138 | 149 | /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html). | 146 | /// void name(MessageVal& val_to_edit, |
2139 | 150 | /// \param params (passed to func) a list of colon separated parameters passed by the user in the XML file. param[0] is the name. | 147 | /// const std::vector<std::string> params, |
2140 | 151 | /// \param vals (passed to func) a map of \ref tag_name to current values for all message variables. | 148 | /// const std::map<std::string,MessageVal>& vals) (see AdvAlgFunction3). func can be a function pointer (&name) or |
2141 | 152 | void add_adv_algorithm(const std::string& name, AlgFunction2 func); | 149 | /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html). |
2142 | 153 | //@} | 150 | /// \param params (passed to func) a list of colon separated parameters passed by the user in the XML file. param[0] is the name. |
2143 | 154 | 151 | /// \param vals (passed to func) a map of \ref tag_name to current values for all message variables. | |
2144 | 155 | /// \name Codec functions. | 152 | void add_adv_algorithm(const std::string& name, AlgFunction2 func); |
2145 | 156 | /// | 153 | //@} |
2146 | 157 | /// This is where the real work happens. | 154 | |
2147 | 158 | //@{ | 155 | /// \name Codec functions. |
2148 | 159 | /// \brief Encode a message. | 156 | /// |
2149 | 160 | /// | 157 | /// This is where the real work happens. |
2150 | 161 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) | 158 | //@{ |
2151 | 162 | /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem | 159 | /// \brief Encode a message. |
2152 | 163 | /// \param m map of std::string (\ref tag_name) to a vector of dccl::MessageVal representing the values to encode. No fields can be arrays using this call. If fields are arrays, all values but the first in the array will be set to NaN or blank. | 160 | /// |
2153 | 164 | template<typename Key> | 161 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) |
2154 | 165 | void encode(const Key& k, std::string& hex, | 162 | /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem |
2155 | 166 | const std::map<std::string, MessageVal>& m) | 163 | /// \param m map of std::string (\ref tag_name) to a vector of MessageVal representing the values to encode. No fields can be arrays using this call. If fields are arrays, all values but the first in the array will be set to NaN or blank. |
2156 | 167 | { | 164 | template<typename Key> |
2157 | 168 | std::map<std::string, std::vector<MessageVal> > vm; | 165 | void encode(const Key& k, std::string& hex, |
2158 | 169 | 166 | const std::map<std::string, DCCLMessageVal>& m) | |
2159 | 170 | typedef std::pair<std::string,MessageVal> P; | 167 | { |
2160 | 171 | BOOST_FOREACH(const P& p, m) | 168 | std::map<std::string, std::vector<DCCLMessageVal> > vm; |
2161 | 172 | vm.insert(std::pair<std::string,std::vector<MessageVal> >(p.first, p.second)); | 169 | |
2162 | 173 | 170 | typedef std::pair<std::string,DCCLMessageVal> P; | |
2163 | 174 | encode_private(to_iterator(k), hex, vm); | 171 | BOOST_FOREACH(const P& p, m) |
2164 | 175 | } | 172 | vm.insert(std::pair<std::string,std::vector<DCCLMessageVal> >(p.first, p.second)); |
2165 | 176 | 173 | ||
2166 | 177 | /// \brief Encode a message. | 174 | encode_private(to_iterator(k), hex, vm); |
2167 | 178 | /// | 175 | } |
2168 | 179 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) | 176 | |
2169 | 180 | /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem | 177 | /// \brief Encode a message. |
2170 | 181 | /// \param m map of std::string (\ref tag_name) to a vector of dccl::MessageVal representing the values to encode. Fields can be arrays. | 178 | /// |
2171 | 182 | template<typename Key> | 179 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) |
2172 | 183 | void encode(const Key& k, std::string& hex, | 180 | /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem |
2173 | 184 | const std::map<std::string, std::vector<MessageVal> >& m) | 181 | /// \param m map of std::string (\ref tag_name) to a vector of MessageVal representing the values to encode. Fields can be arrays. |
2174 | 185 | { encode_private(to_iterator(k), hex, m); } | 182 | template<typename Key> |
2175 | 186 | 183 | void encode(const Key& k, std::string& hex, | |
2176 | 187 | 184 | const std::map<std::string, std::vector<DCCLMessageVal> >& m) | |
2177 | 188 | /// \brief Decode a message. | 185 | { encode_private(to_iterator(k), hex, m); } |
2178 | 189 | /// | 186 | |
2179 | 190 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message | 187 | |
2180 | 191 | /// \param hex the hexadecimal to be decoded. | 188 | /// \brief Decode a message. |
2181 | 192 | /// \param m map of std::string (\ref tag_name) to dccl::MessageVal to store the values to be decoded. No fields can be arrays using this call. If fields are arrays, only the first value is returned. | 189 | /// |
2182 | 193 | template<typename Key> | 190 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message |
2183 | 194 | void decode(const Key& k, const std::string& hex, | 191 | /// \param hex the hexadecimal to be decoded. |
2184 | 195 | std::map<std::string, MessageVal>& m) | 192 | /// \param m map of std::string (\ref tag_name) to MessageVal to store the values to be decoded. No fields can be arrays using this call. If fields are arrays, only the first value is returned. |
2185 | 196 | { | 193 | template<typename Key> |
2186 | 197 | std::map<std::string, std::vector<MessageVal> > vm; | 194 | void decode(const Key& k, const std::string& hex, |
2187 | 198 | 195 | std::map<std::string, DCCLMessageVal>& m) | |
2188 | 199 | decode_private(to_iterator(k), hex, vm); | 196 | { |
2189 | 200 | 197 | std::map<std::string, std::vector<DCCLMessageVal> > vm; | |
2190 | 201 | typedef std::pair<std::string,std::vector<MessageVal> > P; | 198 | |
2191 | 202 | BOOST_FOREACH(const P& p, vm) | 199 | decode_private(to_iterator(k), hex, vm); |
2192 | 203 | m.insert(std::pair<std::string,MessageVal>(p.first, MessageVal(p.second))); | 200 | |
2193 | 204 | } | 201 | typedef std::pair<std::string,std::vector<DCCLMessageVal> > P; |
2194 | 205 | 202 | BOOST_FOREACH(const P& p, vm) | |
2195 | 206 | /// \brief Decode a message. | 203 | m.insert(std::pair<std::string,DCCLMessageVal>(p.first, DCCLMessageVal(p.second))); |
2196 | 207 | /// | 204 | } |
2197 | 208 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message | 205 | |
2198 | 209 | /// \param hex the hexadecimal to be decoded. | 206 | /// \brief Decode a message. |
2199 | 210 | /// \param m map of std::string (\ref tag_name) to dccl::MessageVal to store the values to be decoded | 207 | /// |
2200 | 211 | template<typename Key> | 208 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message |
2201 | 212 | void decode(const Key& k, const std::string& hex, | 209 | /// \param hex the hexadecimal to be decoded. |
2202 | 213 | std::map<std::string, std::vector<MessageVal> >& m) | 210 | /// \param m map of std::string (\ref tag_name) to MessageVal to store the values to be decoded |
2203 | 214 | { decode_private(to_iterator(k), hex, m); } | 211 | template<typename Key> |
2204 | 215 | 212 | void decode(const Key& k, const std::string& hex, | |
2205 | 216 | 213 | std::map<std::string, std::vector<DCCLMessageVal> >& m) | |
2206 | 217 | //@} | 214 | { decode_private(to_iterator(k), hex, m); } |
2207 | 218 | 215 | ||
2208 | 219 | /// \name Informational Methods | 216 | |
2209 | 220 | /// | 217 | //@} |
2210 | 221 | //@{ | 218 | |
2211 | 222 | /// long summary of a message for a given Key (std::string name or unsigned id) | 219 | /// \name Informational Methods |
2212 | 223 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) | 220 | /// |
2213 | 224 | template<typename Key> | 221 | //@{ |
2214 | 225 | std::string summary(const Key& k) const | 222 | /// long summary of a message for a given Key (std::string name or unsigned id) |
2215 | 226 | { return to_iterator(k)->get_display(); } | 223 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) |
2216 | 227 | /// long summary of a message for all loaded messages | 224 | template<typename Key> |
2217 | 228 | std::string summary() const; | 225 | std::string summary(const Key& k) const |
2218 | 229 | 226 | { return to_iterator(k)->get_display(); } | |
2219 | 230 | /// brief summary of a message for a given Key (std::string name or unsigned id) | 227 | /// long summary of a message for all loaded messages |
2220 | 231 | template<typename Key> | 228 | std::string summary() const; |
2221 | 232 | std::string brief_summary(const Key& k) const | 229 | |
2222 | 233 | { return to_iterator(k)->get_short_display(); } | 230 | /// brief summary of a message for a given Key (std::string name or unsigned id) |
2223 | 234 | /// brief summary of a message for all loaded messages | 231 | template<typename Key> |
2224 | 235 | std::string brief_summary() const; | 232 | std::string brief_summary(const Key& k) const |
2225 | 236 | 233 | { return to_iterator(k)->get_short_display(); } | |
2226 | 237 | /// how many message are loaded? | 234 | /// brief summary of a message for all loaded messages |
2227 | 238 | /// \return number of messages loaded | 235 | std::string brief_summary() const; |
2228 | 239 | unsigned message_count() { return messages_.size(); } | 236 | |
2229 | 240 | 237 | /// how many message are loaded? | |
2230 | 241 | /// \return repeat value (number of copies of the message per encode) | 238 | /// \return number of messages loaded |
2231 | 242 | template<typename Key> | 239 | unsigned message_count() { return messages_.size(); } |
2232 | 243 | unsigned get_repeat(const Key& k) | 240 | |
2233 | 244 | { return to_iterator(k)->repeat(); } | 241 | /// \return repeat value (number of copies of the message per encode) |
2234 | 245 | 242 | template<typename Key> | |
2235 | 246 | /// \return set of all message ids loaded | 243 | unsigned get_repeat(const Key& k) |
2236 | 247 | std::set<unsigned> all_message_ids(); | 244 | { return to_iterator(k)->repeat(); } |
2237 | 248 | /// \return set of all message names loaded | 245 | |
2238 | 249 | std::set<std::string> all_message_names(); | 246 | /// \return set of all message ids loaded |
2239 | 250 | /// \return map of names to DCCL types needed to encode a given message | 247 | std::set<unsigned> all_message_ids(); |
2240 | 251 | template<typename Key> | 248 | /// \return set of all message names loaded |
2241 | 252 | std::map<std::string, std::string> message_var_names(const Key& k) const | 249 | std::set<std::string> all_message_names(); |
2242 | 253 | { return to_iterator(k)->message_var_names(); } | 250 | /// \return map of names to DCCL types needed to encode a given message |
2243 | 254 | 251 | template<typename Key> | |
2244 | 255 | /// \param id message id | 252 | std::map<std::string, std::string> message_var_names(const Key& k) const |
2245 | 256 | /// \return name of message | 253 | { return to_iterator(k)->message_var_names(); } |
2246 | 257 | std::string id2name(unsigned id) {return to_iterator(id)->name();} | 254 | |
2247 | 258 | /// \param name message name | 255 | /// \param id message id |
2248 | 259 | /// \return id of message | 256 | /// \return name of message |
2249 | 260 | unsigned name2id(const std::string& name) {return to_iterator(name)->id();} | 257 | std::string id2name(unsigned id) {return to_iterator(id)->name();} |
2250 | 261 | //@} | 258 | /// \param name message name |
2251 | 262 | 259 | /// \return id of message | |
2252 | 263 | 260 | unsigned name2id(const std::string& name) {return to_iterator(name)->id();} | |
2253 | 264 | /// \name Publish/subscribe architecture related methods | 261 | //@} |
2254 | 265 | /// \brief Methods written largely to support DCCL in the context of a publish/subscribe architecture (e.g., see MOOS (http://www.robots.ox.ac.uk/~mobile/MOOS/wiki/pmwiki.php)). The other methods provide a complete interface for encoding and decoding DCCL messages. However, the methods listed here extend the functionality to allow for | 262 | |
2255 | 266 | /// <ul> | 263 | |
2256 | 267 | /// <li> message creation triggering (a message is encoded on a certain event, either time based or publish based) </li> | 264 | /// \name Publish/subscribe architecture related methods |
2257 | 268 | /// <li> encoding that will parse strings of the form: "key1=value,key2=value,key3=value" </li> | 265 | /// \brief Methods written largely to support DCCL in the context of a publish/subscribe architecture (e.g., see MOOS (http://www.robots.ox.ac.uk/~mobile/MOOS/wiki/pmwiki.php)). The other methods provide a complete interface for encoding and decoding DCCL messages. However, the methods listed here extend the functionality to allow for |
2258 | 269 | /// <li> decoding to an arbitrarily formatted string (similar concept to printf) </li> | 266 | /// <ul> |
2259 | 270 | /// </ul> | 267 | /// <li> message creation triggering (a message is encoded on a certain event, either time based or publish based) </li> |
2260 | 271 | /// These methods will be useful if you are interested in any of the features mentioned above. | 268 | /// <li> encoding that will parse strings of the form: "key1=value,key2=value,key3=value" </li> |
2261 | 272 | 269 | /// <li> decoding to an arbitrarily formatted string (similar concept to printf) </li> | |
2262 | 273 | //@{ | 270 | /// </ul> |
2263 | 274 | /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags | 271 | /// These methods will be useful if you are interested in any of the features mentioned above. |
2264 | 275 | /// | 272 | |
2265 | 276 | /// Values can be passed in on one or more maps of names to values, similar to DCCLCodec::encode. | 273 | //@{ |
2266 | 277 | /// Casts are made and string parsing of key=value comma delimited fields is performed. | 274 | /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags |
2267 | 278 | /// This differs substantially from the behavior of encode above. | 275 | /// |
2268 | 279 | /// For example, take this message variable: | 276 | /// Values can be passed in on one or more maps of names to values, similar to DCCLCodec::encode. |
2269 | 280 | /*! \verbatim | 277 | /// Casts are made and string parsing of key=value comma delimited fields is performed. |
2270 | 281 | <int> | 278 | /// This differs substantially from the behavior of encode above. |
2271 | 282 | <name>myint</name> | 279 | /// For example, take this message variable: |
2272 | 283 | <src_var>somevar</src_var> | 280 | /*! \verbatim |
2273 | 284 | </int> \endverbatim | 281 | <int> |
2274 | 285 | */ | 282 | <name>myint</name> |
2275 | 286 | /// | 283 | <src_var>somevar</src_var> |
2276 | 287 | /// Using this method you can pass vals["somevar"] = "mystring=foo,blah=dog,myint=32" | 284 | </int> \endverbatim |
2277 | 288 | /// or vals["somevar"] = 32.0 | 285 | */ |
2278 | 289 | /// and both cases will properly parse out 32 as the value for this field. | 286 | /// |
2279 | 290 | /// In comparison, using the normal encode you would pass vals["myint"] = 32 | 287 | /// Using this method you can pass vals["somevar"] = "mystring=foo,blah=dog,myint=32" |
2280 | 291 | /// | 288 | /// or vals["somevar"] = 32.0 |
2281 | 292 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) | 289 | /// and both cases will properly parse out 32 as the value for this field. |
2282 | 293 | /// \param msg modem::Message or std::string for encoded message to be stored. | 290 | /// In comparison, using the normal encode you would pass vals["myint"] = 32 |
2283 | 294 | /// \param vals map of source variable name to dccl::MessageVal values. | 291 | /// |
2284 | 295 | template<typename Key> | 292 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) |
2285 | 296 | void pubsub_encode(const Key& k, | 293 | /// \param msg ModemMessage or std::string for encoded message to be stored. |
2286 | 297 | modem::Message& msg, | 294 | /// \param vals map of source variable name to MessageVal values. |
2287 | 298 | const std::map<std::string, std::vector<dccl::MessageVal> >& pubsub_vals) | 295 | template<typename Key> |
2288 | 299 | { | 296 | void pubsub_encode(const Key& k, |
2289 | 300 | std::vector<dccl::Message>::iterator it = to_iterator(k); | 297 | ModemMessage& msg, |
2290 | 301 | 298 | const std::map<std::string, std::vector<DCCLMessageVal> >& pubsub_vals) | |
2291 | 302 | std::map<std::string, std::vector<dccl::MessageVal> > vals; | 299 | { |
2292 | 303 | // clean the pubsub vals into dccl vals | 300 | std::vector<DCCLMessage>::iterator it = to_iterator(k); |
2293 | 304 | // using <src_var/> tag, do casts from double, pull strings from key=value,key=value, etc. | 301 | |
2294 | 305 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, it->layout()) | 302 | std::map<std::string, std::vector<DCCLMessageVal> > vals; |
2295 | 306 | mv->read_pubsub_vars(vals, pubsub_vals); | 303 | // clean the pubsub vals into dccl vals |
2296 | 307 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, it->header()) | 304 | // using <src_var/> tag, do casts from double, pull strings from key=value,key=value, etc. |
2297 | 308 | mv->read_pubsub_vars(vals, pubsub_vals); | 305 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, it->layout()) |
2298 | 309 | 306 | mv->read_pubsub_vars(vals, pubsub_vals); | |
2299 | 310 | encode_private(it, msg, vals); | 307 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, it->header()) |
2300 | 311 | } | 308 | mv->read_pubsub_vars(vals, pubsub_vals); |
2301 | 312 | 309 | ||
2302 | 313 | /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags | 310 | encode_private(it, msg, vals); |
2303 | 314 | /// | 311 | } |
2304 | 315 | /// Use this version if you do not have vectors of src_var values | 312 | |
2305 | 316 | template<typename Key> | 313 | /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags |
2306 | 317 | void pubsub_encode(const Key& k, | 314 | /// |
2307 | 318 | modem::Message& msg, | 315 | /// Use this version if you do not have vectors of src_var values |
2308 | 319 | const std::map<std::string, MessageVal>& pubsub_vals) | 316 | template<typename Key> |
2309 | 320 | { | 317 | void pubsub_encode(const Key& k, |
2310 | 321 | std::map<std::string, std::vector<MessageVal> > vm; | 318 | ModemMessage& msg, |
2311 | 322 | 319 | const std::map<std::string, DCCLMessageVal>& pubsub_vals) | |
2312 | 323 | typedef std::pair<std::string,MessageVal> P; | 320 | { |
2313 | 324 | BOOST_FOREACH(const P& p, pubsub_vals) | 321 | std::map<std::string, std::vector<DCCLMessageVal> > vm; |
2314 | 325 | vm.insert(std::pair<std::string,std::vector<MessageVal> >(p.first, p.second)); | 322 | |
2315 | 326 | 323 | typedef std::pair<std::string,DCCLMessageVal> P; | |
2316 | 327 | pubsub_encode(k, msg, vm); | 324 | BOOST_FOREACH(const P& p, pubsub_vals) |
2317 | 328 | } | 325 | vm.insert(std::pair<std::string,std::vector<DCCLMessageVal> >(p.first, p.second)); |
2318 | 329 | 326 | ||
2319 | 330 | 327 | pubsub_encode(k, msg, vm); | |
2320 | 331 | /// \brief Decode a message using formatting specified in \ref tag_publish tags. | 328 | } |
2321 | 332 | /// | 329 | |
2322 | 333 | /// Values will be received in two maps, one of strings and the other of doubles. The \ref tag_publish value will be placed | 330 | |
2323 | 334 | /// either based on the "type" parameter of the \ref tag_publish_var tag (e.g. \<publish_var type="long"\>SOMEVAR\</publish_var\> will be placed as a long). If no type parameter is given and the variable is numeric (e.g. "23242.23") it will be considered a double. If not numeric, it will be considered a string. | 331 | /// \brief Decode a message using formatting specified in \ref tag_publish tags. |
2324 | 335 | /// | 332 | /// |
2325 | 336 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) | 333 | /// Values will be received in two maps, one of strings and the other of doubles. The \ref tag_publish value will be placed |
2326 | 337 | /// \param msg modem::Message or std::string to be decode. | 334 | /// either based on the "type" parameter of the \ref tag_publish_var tag (e.g. \<publish_var type="long"\>SOMEVAR\</publish_var\> will be placed as a long). If no type parameter is given and the variable is numeric (e.g. "23242.23") it will be considered a double. If not numeric, it will be considered a string. |
2327 | 338 | /// \param vals pointer to std::multimap of publish variable name to std::string values. | 335 | /// |
2328 | 339 | template<typename Key> | 336 | /// \param k can either be std::string (the name of the message) or unsigned (the id of the message) |
2329 | 340 | void pubsub_decode(const Key& k, | 337 | /// \param msg ModemMessage or std::string to be decode. |
2330 | 341 | const modem::Message& msg, | 338 | /// \param vals pointer to std::multimap of publish variable name to std::string values. |
2331 | 342 | std::multimap<std::string, dccl::MessageVal>& pubsub_vals) | 339 | template<typename Key> |
2332 | 340 | void pubsub_decode(const Key& k, | ||
2333 | 341 | const ModemMessage& msg, | ||
2334 | 342 | std::multimap<std::string, DCCLMessageVal>& pubsub_vals) | ||
2335 | 343 | 343 | ||
2507 | 344 | { | 344 | { |
2508 | 345 | std::vector<dccl::Message>::iterator it = to_iterator(k); | 345 | std::vector<DCCLMessage>::iterator it = to_iterator(k); |
2509 | 346 | 346 | ||
2510 | 347 | std::map<std::string, std::vector<dccl::MessageVal> > vals; | 347 | std::map<std::string, std::vector<DCCLMessageVal> > vals; |
2511 | 348 | decode_private(it, msg, vals); | 348 | decode_private(it, msg, vals); |
2512 | 349 | 349 | ||
2513 | 350 | // go through all the publishes_ and fill in the format strings | 350 | // go through all the publishes_ and fill in the format strings |
2514 | 351 | BOOST_FOREACH(Publish& p, it->publishes()) | 351 | BOOST_FOREACH(DCCLPublish& p, it->publishes()) |
2515 | 352 | p.write_publish(vals, pubsub_vals); | 352 | p.write_publish(vals, pubsub_vals); |
2516 | 353 | } | 353 | } |
2517 | 354 | 354 | ||
2518 | 355 | 355 | ||
2519 | 356 | /// what moos variables do i need to provide to create a message with a call to encode_using_src_vars | 356 | /// what moos variables do i need to provide to create a message with a call to encode_using_src_vars |
2520 | 357 | template<typename Key> | 357 | template<typename Key> |
2521 | 358 | std::set<std::string> get_pubsub_src_vars(const Key& k) | 358 | std::set<std::string> get_pubsub_src_vars(const Key& k) |
2522 | 359 | { return to_iterator(k)->get_pubsub_src_vars(); } | 359 | { return to_iterator(k)->get_pubsub_src_vars(); } |
2523 | 360 | 360 | ||
2524 | 361 | /// for a given message name, all architecture variables (sources, input, destination, trigger) | 361 | /// for a given message name, all architecture variables (sources, input, destination, trigger) |
2525 | 362 | template<typename Key> | 362 | template<typename Key> |
2526 | 363 | std::set<std::string> get_pubsub_all_vars(const Key& k) | 363 | std::set<std::string> get_pubsub_all_vars(const Key& k) |
2527 | 364 | { return to_iterator(k)->get_pubsub_all_vars(); } | 364 | { return to_iterator(k)->get_pubsub_all_vars(); } |
2528 | 365 | 365 | ||
2529 | 366 | /// all architecture variables needed for encoding (includes trigger) | 366 | /// all architecture variables needed for encoding (includes trigger) |
2530 | 367 | template<typename Key> | 367 | template<typename Key> |
2531 | 368 | std::set<std::string> get_pubsub_encode_vars(const Key& k) | 368 | std::set<std::string> get_pubsub_encode_vars(const Key& k) |
2532 | 369 | { return to_iterator(k)->get_pubsub_encode_vars(); } | 369 | { return to_iterator(k)->get_pubsub_encode_vars(); } |
2533 | 370 | 370 | ||
2534 | 371 | /// for a given message, all architecture variables for decoding (input) | 371 | /// for a given message, all architecture variables for decoding (input) |
2535 | 372 | template<typename Key> | 372 | template<typename Key> |
2536 | 373 | std::set<std::string> get_pubsub_decode_vars(const Key& k) | 373 | std::set<std::string> get_pubsub_decode_vars(const Key& k) |
2537 | 374 | { return to_iterator(k)->get_pubsub_decode_vars(); } | 374 | { return to_iterator(k)->get_pubsub_decode_vars(); } |
2538 | 375 | 375 | ||
2539 | 376 | /// returns outgoing architecture hexadecimal variable | 376 | /// returns outgoing architecture hexadecimal variable |
2540 | 377 | template<typename Key> | 377 | template<typename Key> |
2541 | 378 | std::string get_outgoing_hex_var(const Key& k) | 378 | std::string get_outgoing_hex_var(const Key& k) |
2542 | 379 | { return to_iterator(k)->out_var(); } | 379 | { return to_iterator(k)->out_var(); } |
2543 | 380 | 380 | ||
2544 | 381 | /// returns incoming architecture hexadecimal variable | 381 | /// returns incoming architecture hexadecimal variable |
2545 | 382 | template<typename Key> | 382 | template<typename Key> |
2546 | 383 | std::string get_incoming_hex_var(const Key& k) | 383 | std::string get_incoming_hex_var(const Key& k) |
2547 | 384 | { return to_iterator(k)->in_var(); } | 384 | { return to_iterator(k)->in_var(); } |
2548 | 385 | 385 | ||
2549 | 386 | 386 | ||
2550 | 387 | /// \brief look if key / value are trigger for any loaded messages | 387 | /// \brief look if key / value are trigger for any loaded messages |
2551 | 388 | /// if so, store to id and return true | 388 | /// if so, store to id and return true |
2552 | 389 | bool is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value); | 389 | bool is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value); |
2553 | 390 | 390 | ||
2554 | 391 | /// \brief look if the time is right for trigger for any loaded messages | 391 | /// \brief look if the time is right for trigger for any loaded messages |
2555 | 392 | /// if so, store to id and return true | 392 | /// if so, store to id and return true |
2556 | 393 | bool is_time_trigger(std::set<unsigned>& id); | 393 | bool is_time_trigger(std::set<unsigned>& id); |
2557 | 394 | 394 | ||
2558 | 395 | /// \brief see if this key is for an incoming message | 395 | /// \brief see if this key is for an incoming message |
2559 | 396 | /// if so, return id for decoding | 396 | /// if so, return id for decoding |
2560 | 397 | bool is_incoming(unsigned& id, const std::string& key); | 397 | bool is_incoming(unsigned& id, const std::string& key); |
2561 | 398 | //@} | 398 | //@} |
2562 | 399 | 399 | ||
2563 | 400 | 400 | ||
2564 | 401 | // returns a reference to all Message objects. | 401 | // returns a reference to all DCCLMessage objects. |
2565 | 402 | 402 | ||
2566 | 403 | // this is only used if one needs more control than DCCLCodec | 403 | // this is only used if one needs more control than DCCLCodec |
2567 | 404 | // provides | 404 | // provides |
2568 | 405 | std::vector<Message>& messages() {return messages_;} | 405 | std::vector<DCCLMessage>& messages() {return messages_;} |
2569 | 406 | 406 | ||
2570 | 407 | 407 | ||
2571 | 408 | /// \example libdccl/examples/dccl_simple/dccl_simple.cpp | 408 | /// \example libdccl/examples/dccl_simple/dccl_simple.cpp |
2572 | 409 | /// simple.xml | 409 | /// simple.xml |
2573 | 410 | /// \verbinclude dccl_simple/simple.xml | 410 | /// \verbinclude dccl_simple/simple.xml |
2574 | 411 | /// dccl_simple.cpp | 411 | /// dccl_simple.cpp |
2575 | 412 | 412 | ||
2576 | 413 | /// \example libdccl/examples/plusnet/plusnet.cpp | 413 | /// \example libdccl/examples/plusnet/plusnet.cpp |
2577 | 414 | /// nafcon_command.xml | 414 | /// nafcon_command.xml |
2578 | 415 | /// \verbinclude nafcon_command.xml | 415 | /// \verbinclude nafcon_command.xml |
2579 | 416 | /// nafcon_report.xml | 416 | /// nafcon_report.xml |
2580 | 417 | /// \verbinclude nafcon_report.xml | 417 | /// \verbinclude nafcon_report.xml |
2581 | 418 | /// plusnet.cpp | 418 | /// plusnet.cpp |
2582 | 419 | 419 | ||
2583 | 420 | /// \example libdccl/examples/test/test.cpp | 420 | /// \example libdccl/examples/test/test.cpp |
2584 | 421 | /// test.xml | 421 | /// test.xml |
2585 | 422 | /// \verbinclude test.xml | 422 | /// \verbinclude test.xml |
2586 | 423 | /// test.cpp | 423 | /// test.cpp |
2587 | 424 | 424 | ||
2588 | 425 | /// \example libdccl/examples/two_message/two_message.cpp | 425 | /// \example libdccl/examples/two_message/two_message.cpp |
2589 | 426 | /// two_message.xml | 426 | /// two_message.xml |
2590 | 427 | /// \verbinclude two_message.xml | 427 | /// \verbinclude two_message.xml |
2591 | 428 | /// two_message.cpp | 428 | /// two_message.cpp |
2592 | 429 | 429 | ||
2593 | 430 | /// \example acomms/examples/chat/chat.cpp | 430 | /// \example acomms/examples/chat/chat.cpp |
2594 | 431 | 431 | ||
2595 | 432 | private: | 432 | private: |
2596 | 433 | std::vector<Message>::const_iterator to_iterator(const std::string& message_name) const; | 433 | std::vector<DCCLMessage>::const_iterator to_iterator(const std::string& message_name) const; |
2597 | 434 | std::vector<Message>::iterator to_iterator(const std::string& message_name); | 434 | std::vector<DCCLMessage>::iterator to_iterator(const std::string& message_name); |
2598 | 435 | std::vector<Message>::const_iterator to_iterator(const unsigned& id) const; | 435 | std::vector<DCCLMessage>::const_iterator to_iterator(const unsigned& id) const; |
2599 | 436 | std::vector<Message>::iterator to_iterator(const unsigned& id); | 436 | std::vector<DCCLMessage>::iterator to_iterator(const unsigned& id); |
2600 | 437 | 437 | ||
2601 | 438 | // in map not passed by reference because we want to be able to modify it | 438 | // in map not passed by reference because we want to be able to modify it |
2602 | 439 | void encode_private(std::vector<Message>::iterator it, | 439 | void encode_private(std::vector<DCCLMessage>::iterator it, |
2603 | 440 | std::string& out, | 440 | std::string& out, |
2604 | 441 | std::map<std::string, std::vector<MessageVal> > in); | 441 | std::map<std::string, std::vector<DCCLMessageVal> > in); |
2605 | 442 | 442 | ||
2606 | 443 | // in string not passed by reference because we want to be able to modify it | 443 | // in string not passed by reference because we want to be able to modify it |
2607 | 444 | void decode_private(std::vector<Message>::iterator it, | 444 | void decode_private(std::vector<DCCLMessage>::iterator it, |
2608 | 445 | std::string in, | 445 | std::string in, |
2609 | 446 | std::map<std::string, std::vector<MessageVal> >& out); | 446 | std::map<std::string, std::vector<DCCLMessageVal> >& out); |
2610 | 447 | 447 | ||
2611 | 448 | void encode_private(std::vector<Message>::iterator it, | 448 | void encode_private(std::vector<DCCLMessage>::iterator it, |
2612 | 449 | modem::Message& out_msg, | 449 | ModemMessage& out_msg, |
2613 | 450 | const std::map<std::string, std::vector<MessageVal> >& in); | 450 | const std::map<std::string, std::vector<DCCLMessageVal> >& in); |
2614 | 451 | 451 | ||
2615 | 452 | void decode_private(std::vector<Message>::iterator it, | 452 | void decode_private(std::vector<DCCLMessage>::iterator it, |
2616 | 453 | const modem::Message& in_msg, | 453 | const ModemMessage& in_msg, |
2617 | 454 | std::map<std::string, std::vector<MessageVal> >& out); | 454 | std::map<std::string, std::vector<DCCLMessageVal> >& out); |
2618 | 455 | 455 | ||
2619 | 456 | void check_duplicates(); | 456 | void check_duplicates(); |
2620 | 457 | 457 | ||
2621 | 458 | 458 | ||
2622 | 459 | void encrypt(std::string& s, const std::string& nonce); | 459 | void encrypt(std::string& s, const std::string& nonce); |
2623 | 460 | void decrypt(std::string& s, const std::string& nonce); | 460 | void decrypt(std::string& s, const std::string& nonce); |
2624 | 461 | 461 | ||
2625 | 462 | private: | 462 | private: |
2626 | 463 | std::vector<Message> messages_; | 463 | std::vector<DCCLMessage> messages_; |
2627 | 464 | std::map<std::string, size_t> name2messages_; | 464 | std::map<std::string, size_t> name2messages_; |
2628 | 465 | std::map<unsigned, size_t> id2messages_; | 465 | std::map<unsigned, size_t> id2messages_; |
2629 | 466 | 466 | ||
2630 | 467 | std::string xml_schema_; | 467 | std::string xml_schema_; |
2631 | 468 | time_t start_time_; | 468 | boost::posix_time::ptime start_time_; |
2632 | 469 | 469 | ||
2633 | 470 | unsigned modem_id_; | 470 | unsigned modem_id_; |
2634 | 471 | 471 | ||
2635 | 472 | std::string crypto_key_; | 472 | std::string crypto_key_; |
2636 | 473 | }; | 473 | }; |
2637 | 474 | 474 | ||
2638 | 475 | /// outputs information about all available messages (same as std::string summary()) | 475 | /// outputs information about all available messages (same as std::string summary()) |
2639 | 476 | std::ostream& operator<< (std::ostream& out, const DCCLCodec& d); | 476 | std::ostream& operator<< (std::ostream& out, const DCCLCodec& d); |
2640 | 477 | 477 | ||
2641 | 478 | 478 | ||
2642 | 479 | class DCCLHeaderEncoder | 479 | class DCCLHeaderEncoder |
2643 | 480 | { | 480 | { |
2644 | 481 | public: | 481 | public: |
2645 | 482 | DCCLHeaderEncoder(const std::map<std::string, std::vector<MessageVal> >& in) | 482 | DCCLHeaderEncoder(const std::map<std::string, std::vector<DCCLMessageVal> >& in) |
2646 | 483 | { | 483 | { |
2647 | 484 | std::map<std::string, std::vector<MessageVal> > in_copy = in; | 484 | std::map<std::string, std::vector<DCCLMessageVal> > in_copy = in; |
2648 | 485 | msg_.head_encode(encoded_, in_copy); | 485 | msg_.head_encode(encoded_, in_copy); |
2649 | 486 | hex_encode(encoded_); | 486 | hex_encode(encoded_); |
2650 | 487 | } | 487 | } |
2651 | 488 | std::string& get() { return encoded_; } | 488 | std::string& get() { return encoded_; } |
2652 | 489 | 489 | ||
2653 | 490 | private: | 490 | private: |
2654 | 491 | Message msg_; | 491 | DCCLMessage msg_; |
2655 | 492 | std::string encoded_; | 492 | std::string encoded_; |
2656 | 493 | }; | 493 | }; |
2657 | 494 | 494 | ||
2658 | 495 | class DCCLHeaderDecoder | 495 | class DCCLHeaderDecoder |
2659 | 496 | { | 496 | { |
2660 | 497 | public: | 497 | public: |
2661 | 498 | DCCLHeaderDecoder(const std::string& in_orig) | 498 | DCCLHeaderDecoder(const std::string& in_orig) |
2662 | 499 | { | 499 | { |
2663 | 500 | std::string in = in_orig.substr(0, acomms::NUM_HEADER_NIBS); | 500 | std::string in = in_orig.substr(0, DCCL_NUM_HEADER_BYTES*NIBS_IN_BYTE); |
2664 | 501 | hex_decode(in); | 501 | hex_decode(in); |
2665 | 502 | msg_.head_decode(in, decoded_); | 502 | msg_.head_decode(in, decoded_); |
2666 | 503 | } | 503 | } |
2667 | 504 | std::map<std::string, std::vector<MessageVal> >& get() { return decoded_; } | 504 | std::map<std::string, std::vector<DCCLMessageVal> >& get() { return decoded_; } |
2668 | 505 | MessageVal& operator[] (const std::string& s) | 505 | DCCLMessageVal& operator[] (const std::string& s) |
2669 | 506 | { return decoded_[s][0]; } | 506 | { return decoded_[s][0]; } |
2670 | 507 | MessageVal& operator[] (acomms::DCCLHeaderPart p) | 507 | DCCLMessageVal& operator[] (DCCLHeaderPart p) |
2671 | 508 | { return decoded_[acomms::to_str(p)][0]; } | 508 | { return decoded_[to_str(p)][0]; } |
2672 | 509 | 509 | ||
2673 | 510 | 510 | ||
2674 | 511 | private: | 511 | private: |
2675 | 512 | Message msg_; | 512 | DCCLMessage msg_; |
2676 | 513 | std::map<std::string, std::vector<MessageVal> > decoded_; | 513 | std::map<std::string, std::vector<DCCLMessageVal> > decoded_; |
2677 | 514 | }; | 514 | }; |
2678 | 515 | 515 | ||
2679 | 516 | 516 | ||
2680 | 517 | } | ||
2681 | 517 | } | 518 | } |
2682 | 518 | 519 | ||
2683 | 519 | 520 | ||
2684 | 520 | |||
2685 | 521 | #endif | 521 | #endif |
2686 | 522 | 522 | ||
2687 | === modified file 'src/acomms/libdccl/dccl_constants.h' | |||
2688 | --- src/acomms/libdccl/dccl_constants.h 2010-06-15 04:51:47 +0000 | |||
2689 | +++ src/acomms/libdccl/dccl_constants.h 2010-07-15 12:38:39 +0000 | |||
2690 | @@ -28,9 +28,12 @@ | |||
2691 | 28 | #include <crypto++/filters.h> | 28 | #include <crypto++/filters.h> |
2692 | 29 | #include <crypto++/hex.h> | 29 | #include <crypto++/hex.h> |
2693 | 30 | 30 | ||
2697 | 31 | #include "acomms/acomms_constants.h" | 31 | #include "goby/acomms/acomms_constants.h" |
2698 | 32 | 32 | ||
2699 | 33 | namespace dccl | 33 | namespace goby |
2700 | 34 | { | ||
2701 | 35 | |||
2702 | 36 | namespace acomms | ||
2703 | 34 | { | 37 | { |
2704 | 35 | 38 | ||
2705 | 36 | /// Enumeration of DCCL types used for sending messages. dccl_enum and dccl_string primarily map to cpp_string, dccl_bool to cpp_bool, dccl_int to cpp_long, dccl_float to cpp_double | 39 | /// Enumeration of DCCL types used for sending messages. dccl_enum and dccl_string primarily map to cpp_string, dccl_bool to cpp_bool, dccl_int to cpp_long, dccl_float to cpp_double |
2706 | @@ -111,5 +114,5 @@ | |||
2707 | 111 | 114 | ||
2708 | 112 | 115 | ||
2709 | 113 | } | 116 | } |
2711 | 114 | 117 | } | |
2712 | 115 | #endif | 118 | #endif |
2713 | 116 | 119 | ||
2714 | === modified file 'src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt' | |||
2715 | --- src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt 2010-01-22 02:52:25 +0000 | |||
2716 | +++ src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
2717 | @@ -1,2 +1,2 @@ | |||
2718 | 1 | add_executable(dccl_simple dccl_simple.cpp) | 1 | add_executable(dccl_simple dccl_simple.cpp) |
2719 | 2 | target_link_libraries(dccl_simple dccl) | ||
2720 | 3 | \ No newline at end of file | 2 | \ No newline at end of file |
2721 | 3 | target_link_libraries(dccl_simple goby_dccl) | ||
2722 | 4 | \ No newline at end of file | 4 | \ No newline at end of file |
2723 | 5 | 5 | ||
2724 | === modified file 'src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp' | |||
2725 | --- src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp 2010-03-15 16:21:43 +0000 | |||
2726 | +++ src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp 2010-07-15 12:38:39 +0000 | |||
2727 | @@ -17,17 +17,17 @@ | |||
2728 | 17 | // encodes/decodes a string using the DCCL codec library | 17 | // encodes/decodes a string using the DCCL codec library |
2729 | 18 | // assumes prior knowledge of the message format (required fields) | 18 | // assumes prior knowledge of the message format (required fields) |
2730 | 19 | 19 | ||
2732 | 20 | #include "acomms/dccl.h" | 20 | #include "goby/acomms/dccl.h" |
2733 | 21 | #include <iostream> | 21 | #include <iostream> |
2734 | 22 | 22 | ||
2736 | 23 | using dccl::operator<<; | 23 | using goby::acomms::operator<<; |
2737 | 24 | 24 | ||
2738 | 25 | int main() | 25 | int main() |
2739 | 26 | { | 26 | { |
2740 | 27 | // initialize input contents to encoder. since | 27 | // initialize input contents to encoder. since |
2741 | 28 | // simple.xml only has a <string/> message var | 28 | // simple.xml only has a <string/> message var |
2742 | 29 | // we only need one map. | 29 | // we only need one map. |
2744 | 30 | std::map<std::string, dccl::MessageVal> val_map; | 30 | std::map<std::string, goby::acomms::DCCLMessageVal> val_map; |
2745 | 31 | 31 | ||
2746 | 32 | // initialize output hexadecimal | 32 | // initialize output hexadecimal |
2747 | 33 | std::string hex; | 33 | std::string hex; |
2748 | @@ -37,7 +37,7 @@ | |||
2749 | 37 | // instantiate the parser with a single xml file (simple.xml). | 37 | // instantiate the parser with a single xml file (simple.xml). |
2750 | 38 | // also pass the schema, relative to simple.xml, for XML validity | 38 | // also pass the schema, relative to simple.xml, for XML validity |
2751 | 39 | // checking (syntax). | 39 | // checking (syntax). |
2753 | 40 | dccl::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml", | 40 | goby::acomms::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml", |
2754 | 41 | "../../message_schema.xsd"); | 41 | "../../message_schema.xsd"); |
2755 | 42 | 42 | ||
2756 | 43 | 43 | ||
2757 | 44 | 44 | ||
2758 | === modified file 'src/acomms/libdccl/examples/delta/CMakeLists.txt' | |||
2759 | --- src/acomms/libdccl/examples/delta/CMakeLists.txt 2010-03-05 03:32:48 +0000 | |||
2760 | +++ src/acomms/libdccl/examples/delta/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
2761 | @@ -1,2 +1,2 @@ | |||
2762 | 1 | add_executable(delta delta.cpp) | 1 | add_executable(delta delta.cpp) |
2763 | 2 | target_link_libraries(delta dccl) | ||
2764 | 3 | \ No newline at end of file | 2 | \ No newline at end of file |
2765 | 3 | target_link_libraries(delta goby_dccl) | ||
2766 | 4 | \ No newline at end of file | 4 | \ No newline at end of file |
2767 | 5 | 5 | ||
2768 | === modified file 'src/acomms/libdccl/examples/delta/delta.cpp' | |||
2769 | --- src/acomms/libdccl/examples/delta/delta.cpp 2010-03-10 01:14:38 +0000 | |||
2770 | +++ src/acomms/libdccl/examples/delta/delta.cpp 2010-07-15 12:38:39 +0000 | |||
2771 | @@ -17,22 +17,22 @@ | |||
2772 | 17 | // encodes/decodes several fields using delta encoding | 17 | // encodes/decodes several fields using delta encoding |
2773 | 18 | 18 | ||
2774 | 19 | 19 | ||
2776 | 20 | #include "acomms/dccl.h" | 20 | #include "goby/acomms/dccl.h" |
2777 | 21 | #include <iostream> | 21 | #include <iostream> |
2778 | 22 | 22 | ||
2780 | 23 | using dccl::operator<<; | 23 | using goby::acomms::operator<<; |
2781 | 24 | 24 | ||
2782 | 25 | int main() | 25 | int main() |
2783 | 26 | { | 26 | { |
2786 | 27 | std::vector< std::map<std::string, dccl::MessageVal> > vals_vect; | 27 | std::vector< std::map<std::string, acomms::DCCLMessageVal> > vals_vect; |
2787 | 28 | std::map<std::string, dccl::MessageVal> vals; | 28 | std::map<std::string, acomms::DCCLMessageVal> vals; |
2788 | 29 | 29 | ||
2789 | 30 | // initialize output hexadecimal | 30 | // initialize output hexadecimal |
2790 | 31 | std::string hex; | 31 | std::string hex; |
2791 | 32 | 32 | ||
2792 | 33 | std::cout << "loading xml file: delta.xml" << std::endl; | 33 | std::cout << "loading xml file: delta.xml" << std::endl; |
2793 | 34 | 34 | ||
2795 | 35 | dccl::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/delta/delta.xml", | 35 | goby::acomms::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/delta/delta.xml", |
2796 | 36 | "../../message_schema.xsd"); | 36 | "../../message_schema.xsd"); |
2797 | 37 | 37 | ||
2798 | 38 | std::cout << dccl << std::endl; | 38 | std::cout << dccl << std::endl; |
2799 | @@ -77,7 +77,7 @@ | |||
2800 | 77 | 77 | ||
2801 | 78 | // dccl.delta_decode(1, hex, 0, &vals_vect, 0, 0); | 78 | // dccl.delta_decode(1, hex, 0, &vals_vect, 0, 0); |
2802 | 79 | 79 | ||
2804 | 80 | for(std::vector< std::map<std::string, dccl::MessageVal> >::iterator | 80 | for(std::vector< std::map<std::string, acomms::DCCLMessageVal> >::iterator |
2805 | 81 | it = vals_vect.begin(), | 81 | it = vals_vect.begin(), |
2806 | 82 | n = vals_vect.end(); | 82 | n = vals_vect.end(); |
2807 | 83 | it != n; | 83 | it != n; |
2808 | 84 | 84 | ||
2809 | === modified file 'src/acomms/libdccl/examples/plusnet/CMakeLists.txt' | |||
2810 | --- src/acomms/libdccl/examples/plusnet/CMakeLists.txt 2009-12-18 02:50:00 +0000 | |||
2811 | +++ src/acomms/libdccl/examples/plusnet/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
2812 | @@ -1,2 +1,2 @@ | |||
2813 | 1 | add_executable(plusnet plusnet.cpp) | 1 | add_executable(plusnet plusnet.cpp) |
2815 | 2 | target_link_libraries(plusnet dccl) | 2 | target_link_libraries(plusnet goby_dccl) |
2816 | 3 | 3 | ||
2817 | === modified file 'src/acomms/libdccl/examples/plusnet/plusnet.cpp' | |||
2818 | --- src/acomms/libdccl/examples/plusnet/plusnet.cpp 2010-03-20 06:09:16 +0000 | |||
2819 | +++ src/acomms/libdccl/examples/plusnet/plusnet.cpp 2010-07-15 12:38:39 +0000 | |||
2820 | @@ -20,18 +20,19 @@ | |||
2821 | 20 | 20 | ||
2822 | 21 | // this is an example showing some of the "MOOS" related features of libdccl that can be used (if desired) in the absence of MOOS | 21 | // this is an example showing some of the "MOOS" related features of libdccl that can be used (if desired) in the absence of MOOS |
2823 | 22 | 22 | ||
2825 | 23 | #include "acomms/dccl.h" | 23 | #include "goby/acomms/dccl.h" |
2826 | 24 | 24 | ||
2827 | 25 | #include <exception> | 25 | #include <exception> |
2828 | 26 | #include <iostream> | 26 | #include <iostream> |
2829 | 27 | 27 | ||
2831 | 28 | using dccl::operator<<; | 28 | using namespace goby; |
2832 | 29 | using goby::acomms::operator<<; | ||
2833 | 29 | 30 | ||
2834 | 30 | int main() | 31 | int main() |
2835 | 31 | { | 32 | { |
2836 | 32 | std::cout << "loading nafcon xml files" << std::endl; | 33 | std::cout << "loading nafcon xml files" << std::endl; |
2837 | 33 | 34 | ||
2839 | 34 | dccl::DCCLCodec dccl; | 35 | acomms::DCCLCodec dccl; |
2840 | 35 | dccl.add_xml_message_file(DCCL_EXAMPLES_DIR "/plusnet/nafcon_command.xml", "../../message_schema.xsd"); | 36 | dccl.add_xml_message_file(DCCL_EXAMPLES_DIR "/plusnet/nafcon_command.xml", "../../message_schema.xsd"); |
2841 | 36 | dccl.add_xml_message_file(DCCL_EXAMPLES_DIR "/plusnet/nafcon_report.xml", "../../message_schema.xsd"); | 37 | dccl.add_xml_message_file(DCCL_EXAMPLES_DIR "/plusnet/nafcon_report.xml", "../../message_schema.xsd"); |
2842 | 37 | 38 | ||
2843 | @@ -45,10 +46,10 @@ | |||
2844 | 45 | << std::string(30, '#') << std::endl; | 46 | << std::string(30, '#') << std::endl; |
2845 | 46 | 47 | ||
2846 | 47 | // initialize input contents to encoder | 48 | // initialize input contents to encoder |
2848 | 48 | std::map<std::string, dccl::MessageVal> in_vals; | 49 | std::map<std::string, acomms::DCCLMessageVal> in_vals; |
2849 | 49 | 50 | ||
2850 | 50 | // initialize output message | 51 | // initialize output message |
2852 | 51 | modem::Message msg; | 52 | acomms::ModemMessage msg; |
2853 | 52 | 53 | ||
2854 | 53 | in_vals["PLUSNET_MESSAGES"] = "MessageType=SENSOR_STATUS,SensorReportType=0,SourcePlatformId=1,DestinationPlatformId=3,Timestamp=1191947446.91117,NodeLatitude=47.7448,NodeLongitude=-122.845,NodeDepth=0.26,NodeCEP=0,NodeHeading=169.06,NodeSpeed=0,MissionState=2,MissionType=2,LastGPSTimestamp=1191947440,PowerLife=6,SensorHealth=0,RecorderState=1,RecorderLife=0,NodeSpecificInfo0=0,NodeSpecificInfo1=0,NodeSpecificInfo2=23,NodeSpecificInfo3=0,NodeSpecificInfo4=3,NodeSpecificInfo5=0"; | 54 | in_vals["PLUSNET_MESSAGES"] = "MessageType=SENSOR_STATUS,SensorReportType=0,SourcePlatformId=1,DestinationPlatformId=3,Timestamp=1191947446.91117,NodeLatitude=47.7448,NodeLongitude=-122.845,NodeDepth=0.26,NodeCEP=0,NodeHeading=169.06,NodeSpeed=0,MissionState=2,MissionType=2,LastGPSTimestamp=1191947440,PowerLife=6,SensorHealth=0,RecorderState=1,RecorderLife=0,NodeSpecificInfo0=0,NodeSpecificInfo1=0,NodeSpecificInfo2=23,NodeSpecificInfo3=0,NodeSpecificInfo4=3,NodeSpecificInfo5=0"; |
2855 | 54 | 55 | ||
2856 | @@ -57,15 +58,15 @@ | |||
2857 | 57 | 58 | ||
2858 | 58 | dccl.pubsub_encode("SENSOR_STATUS", msg, in_vals); | 59 | dccl.pubsub_encode("SENSOR_STATUS", msg, in_vals); |
2859 | 59 | 60 | ||
2861 | 60 | std::cout << "received dccl::Message: " | 61 | std::cout << "received acomms::DCCLMessage: " |
2862 | 61 | << msg.serialize() | 62 | << msg.serialize() |
2863 | 62 | << std::endl; | 63 | << std::endl; |
2864 | 63 | 64 | ||
2865 | 64 | 65 | ||
2867 | 65 | std::multimap<std::string, dccl::MessageVal> out_vals; | 66 | std::multimap<std::string, acomms::DCCLMessageVal> out_vals; |
2868 | 66 | 67 | ||
2869 | 67 | 68 | ||
2871 | 68 | std::cout << "passed dccl::Message to decoder: " | 69 | std::cout << "passed acomms::DCCLMessage to decoder: " |
2872 | 69 | << msg.serialize() | 70 | << msg.serialize() |
2873 | 70 | << std::endl; | 71 | << std::endl; |
2874 | 71 | 72 | ||
2875 | 72 | 73 | ||
2876 | === modified file 'src/acomms/libdccl/examples/test/CMakeLists.txt' | |||
2877 | --- src/acomms/libdccl/examples/test/CMakeLists.txt 2009-12-02 05:18:28 +0000 | |||
2878 | +++ src/acomms/libdccl/examples/test/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
2879 | @@ -1,2 +1,2 @@ | |||
2880 | 1 | add_executable(dccl_test test.cpp) | 1 | add_executable(dccl_test test.cpp) |
2881 | 2 | target_link_libraries(dccl_test dccl) | ||
2882 | 3 | \ No newline at end of file | 2 | \ No newline at end of file |
2883 | 3 | target_link_libraries(dccl_test goby_dccl) | ||
2884 | 4 | \ No newline at end of file | 4 | \ No newline at end of file |
2885 | 5 | 5 | ||
2886 | === modified file 'src/acomms/libdccl/examples/test/test.cpp' | |||
2887 | --- src/acomms/libdccl/examples/test/test.cpp 2010-06-15 04:51:47 +0000 | |||
2888 | +++ src/acomms/libdccl/examples/test/test.cpp 2010-07-15 12:38:39 +0000 | |||
2889 | @@ -14,41 +14,42 @@ | |||
2890 | 14 | // along with this software. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this software. If not, see <http://www.gnu.org/licenses/>. |
2891 | 15 | 15 | ||
2892 | 16 | 16 | ||
2894 | 17 | #include "acomms/dccl.h" | 17 | #include "goby/acomms/dccl.h" |
2895 | 18 | #include <iostream> | 18 | #include <iostream> |
2896 | 19 | #include <cassert> | 19 | #include <cassert> |
2897 | 20 | 20 | ||
2899 | 21 | using dccl::operator<<; | 21 | using namespace goby; |
2900 | 22 | using goby::acomms::operator<<; | ||
2901 | 22 | 23 | ||
2903 | 23 | void plus1(dccl::MessageVal& mv) | 24 | void plus1(acomms::DCCLMessageVal& mv) |
2904 | 24 | { | 25 | { |
2905 | 25 | long l = mv; | 26 | long l = mv; |
2906 | 26 | ++l; | 27 | ++l; |
2907 | 27 | mv = l; | 28 | mv = l; |
2908 | 28 | } | 29 | } |
2909 | 29 | 30 | ||
2911 | 30 | void times2(dccl::MessageVal& mv) | 31 | void times2(acomms::DCCLMessageVal& mv) |
2912 | 31 | { | 32 | { |
2913 | 32 | double d = mv; | 33 | double d = mv; |
2914 | 33 | d *= 2; | 34 | d *= 2; |
2915 | 34 | mv = d; | 35 | mv = d; |
2916 | 35 | } | 36 | } |
2917 | 36 | 37 | ||
2919 | 37 | void prepend_fat(dccl::MessageVal& mv) | 38 | void prepend_fat(acomms::DCCLMessageVal& mv) |
2920 | 38 | { | 39 | { |
2921 | 39 | std::string s = mv; | 40 | std::string s = mv; |
2922 | 40 | s = "fat_" + s; | 41 | s = "fat_" + s; |
2923 | 41 | mv = s; | 42 | mv = s; |
2924 | 42 | } | 43 | } |
2925 | 43 | 44 | ||
2927 | 44 | void invert(dccl::MessageVal& mv) | 45 | void invert(acomms::DCCLMessageVal& mv) |
2928 | 45 | { | 46 | { |
2929 | 46 | bool b = mv; | 47 | bool b = mv; |
2930 | 47 | b ^= 1; | 48 | b ^= 1; |
2931 | 48 | mv = b; | 49 | mv = b; |
2932 | 49 | } | 50 | } |
2933 | 50 | 51 | ||
2935 | 51 | void algsum(dccl::MessageVal& mv, const std::vector<dccl::MessageVal>& ref_vals) | 52 | void algsum(acomms::DCCLMessageVal& mv, const std::vector<acomms::DCCLMessageVal>& ref_vals) |
2936 | 52 | { | 53 | { |
2937 | 53 | double d = 0; | 54 | double d = 0; |
2938 | 54 | // index 0 is the name ("sum"), so start at 1 | 55 | // index 0 is the name ("sum"), so start at 1 |
2939 | @@ -65,7 +66,7 @@ | |||
2940 | 65 | std::cout << "loading xml file: test.xml" << std::endl; | 66 | std::cout << "loading xml file: test.xml" << std::endl; |
2941 | 66 | 67 | ||
2942 | 67 | // instantiate the parser with a single xml file | 68 | // instantiate the parser with a single xml file |
2944 | 68 | dccl::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/test/test.xml", "../../message_schema.xsd"); | 69 | acomms::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/test/test.xml", "../../message_schema.xsd"); |
2945 | 69 | 70 | ||
2946 | 70 | std::cout << dccl << std::endl; | 71 | std::cout << dccl << std::endl; |
2947 | 71 | 72 | ||
2948 | @@ -79,32 +80,32 @@ | |||
2949 | 79 | // must be kept secret! | 80 | // must be kept secret! |
2950 | 80 | dccl.set_crypto_passphrase("my_passphrase!"); | 81 | dccl.set_crypto_passphrase("my_passphrase!"); |
2951 | 81 | 82 | ||
2953 | 82 | std::map<std::string, std::vector<dccl::MessageVal> > in; | 83 | std::map<std::string, std::vector<acomms::DCCLMessageVal> > in; |
2954 | 83 | 84 | ||
2955 | 84 | bool b = true; | 85 | bool b = true; |
2957 | 85 | std::vector<dccl::MessageVal> e; | 86 | std::vector<acomms::DCCLMessageVal> e; |
2958 | 86 | e.push_back("dog"); | 87 | e.push_back("dog"); |
2959 | 87 | e.push_back("cat"); | 88 | e.push_back("cat"); |
2960 | 88 | e.push_back("emu"); | 89 | e.push_back("emu"); |
2961 | 89 | 90 | ||
2962 | 90 | std::string s = "raccoon"; | 91 | std::string s = "raccoon"; |
2964 | 91 | std::vector<dccl::MessageVal> i; | 92 | std::vector<acomms::DCCLMessageVal> i; |
2965 | 92 | i.push_back(30); | 93 | i.push_back(30); |
2966 | 93 | i.push_back(40); | 94 | i.push_back(40); |
2968 | 94 | std::vector<dccl::MessageVal> f; | 95 | std::vector<acomms::DCCLMessageVal> f; |
2969 | 95 | f.push_back(-12.5); | 96 | f.push_back(-12.5); |
2970 | 96 | f.push_back(1); | 97 | f.push_back(1); |
2971 | 97 | 98 | ||
2972 | 98 | std::string h = "abcd1234"; | 99 | std::string h = "abcd1234"; |
2977 | 99 | std::vector<dccl::MessageVal> sum(2,0); | 100 | std::vector<acomms::DCCLMessageVal> sum(2,0); |
2978 | 100 | 101 | ||
2979 | 101 | 102 | ||
2980 | 102 | in["B"] = std::vector<dccl::MessageVal>(1,b); | 103 | in["B"] = std::vector<acomms::DCCLMessageVal>(1,b); |
2981 | 103 | in["E"] = e; | 104 | in["E"] = e; |
2983 | 104 | in["S"] = std::vector<dccl::MessageVal>(1,s); | 105 | in["S"] = std::vector<acomms::DCCLMessageVal>(1,s); |
2984 | 105 | in["I"] = i; | 106 | in["I"] = i; |
2985 | 106 | in["F"] = f; | 107 | in["F"] = f; |
2987 | 107 | in["H"] = std::vector<dccl::MessageVal>(1,h); | 108 | in["H"] = std::vector<acomms::DCCLMessageVal>(1,h); |
2988 | 108 | in["SUM"] = sum; | 109 | in["SUM"] = sum; |
2989 | 109 | 110 | ||
2990 | 110 | std::string hex; | 111 | std::string hex; |
2991 | @@ -117,7 +118,7 @@ | |||
2992 | 117 | hex.resize(hex.length() + 20,'0'); | 118 | hex.resize(hex.length() + 20,'0'); |
2993 | 118 | std::cout << "hex in: " << hex << std::endl; | 119 | std::cout << "hex in: " << hex << std::endl; |
2994 | 119 | 120 | ||
2996 | 120 | std::map<std::string, std::vector<dccl::MessageVal> > out; | 121 | std::map<std::string, std::vector<acomms::DCCLMessageVal> > out; |
2997 | 121 | 122 | ||
2998 | 122 | dccl.decode(4, hex, out); | 123 | dccl.decode(4, hex, out); |
2999 | 123 | 124 | ||
3000 | @@ -129,7 +130,7 @@ | |||
3001 | 129 | i[0] = int(i[0]) + 1; | 130 | i[0] = int(i[0]) + 1; |
3002 | 130 | i[1] = int(i[1]) + 1; | 131 | i[1] = int(i[1]) + 1; |
3003 | 131 | 132 | ||
3005 | 132 | dccl::MessageVal tmp = b; | 133 | acomms::DCCLMessageVal tmp = b; |
3006 | 133 | invert(tmp); | 134 | invert(tmp); |
3007 | 134 | b = tmp; | 135 | b = tmp; |
3008 | 135 | 136 | ||
3009 | 136 | 137 | ||
3010 | === modified file 'src/acomms/libdccl/examples/test/test.xml' | |||
3011 | --- src/acomms/libdccl/examples/test/test.xml 2010-06-15 04:51:47 +0000 | |||
3012 | +++ src/acomms/libdccl/examples/test/test.xml 2010-07-15 12:38:39 +0000 | |||
3013 | @@ -2,9 +2,9 @@ | |||
3014 | 2 | <message_set> | 2 | <message_set> |
3015 | 3 | <message> | 3 | <message> |
3016 | 4 | <name>TEST</name> | 4 | <name>TEST</name> |
3018 | 5 | <size>256</size> | 5 | <size>128</size> |
3019 | 6 | <id>4</id> | 6 | <id>4</id> |
3021 | 7 | <repeat>5</repeat> | 7 | <repeat/> |
3022 | 8 | <layout> | 8 | <layout> |
3023 | 9 | <static> | 9 | <static> |
3024 | 10 | <name>Stat</name> | 10 | <name>Stat</name> |
3025 | 11 | 11 | ||
3026 | === modified file 'src/acomms/libdccl/examples/two_message/CMakeLists.txt' | |||
3027 | --- src/acomms/libdccl/examples/two_message/CMakeLists.txt 2009-12-02 05:18:28 +0000 | |||
3028 | +++ src/acomms/libdccl/examples/two_message/CMakeLists.txt 2010-07-15 12:38:39 +0000 | |||
3029 | @@ -1,2 +1,2 @@ | |||
3030 | 1 | add_executable(two_message two_message.cpp) | 1 | add_executable(two_message two_message.cpp) |
3031 | 2 | target_link_libraries(two_message dccl) | ||
3032 | 3 | \ No newline at end of file | 2 | \ No newline at end of file |
3033 | 3 | target_link_libraries(two_message goby_dccl) | ||
3034 | 4 | \ No newline at end of file | 4 | \ No newline at end of file |
3035 | 5 | 5 | ||
3036 | === modified file 'src/acomms/libdccl/examples/two_message/two_message.cpp' | |||
3037 | --- src/acomms/libdccl/examples/two_message/two_message.cpp 2010-03-22 02:52:39 +0000 | |||
3038 | +++ src/acomms/libdccl/examples/two_message/two_message.cpp 2010-07-15 12:38:39 +0000 | |||
3039 | @@ -17,11 +17,12 @@ | |||
3040 | 17 | // encodes/decodes the message given in the pGeneralCodec documentation | 17 | // encodes/decodes the message given in the pGeneralCodec documentation |
3041 | 18 | // also includes the simple.xml file to show example of DCCLCodec instantiation | 18 | // also includes the simple.xml file to show example of DCCLCodec instantiation |
3042 | 19 | // with multiple files | 19 | // with multiple files |
3044 | 20 | #include "acomms/dccl.h" | 20 | #include "goby/acomms/dccl.h" |
3045 | 21 | #include <exception> | 21 | #include <exception> |
3046 | 22 | #include <iostream> | 22 | #include <iostream> |
3047 | 23 | 23 | ||
3049 | 24 | using dccl::operator<<; | 24 | using namespace goby; |
3050 | 25 | using goby::acomms::operator<<; | ||
3051 | 25 | 26 | ||
3052 | 26 | 27 | ||
3053 | 27 | int main() | 28 | int main() |
3054 | @@ -33,7 +34,7 @@ | |||
3055 | 33 | xml_files.insert(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml"); | 34 | xml_files.insert(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml"); |
3056 | 34 | xml_files.insert(DCCL_EXAMPLES_DIR "/two_message/two_message.xml"); | 35 | xml_files.insert(DCCL_EXAMPLES_DIR "/two_message/two_message.xml"); |
3057 | 35 | 36 | ||
3059 | 36 | dccl::DCCLCodec dccl(xml_files, "../../message_schema.xsd"); | 37 | acomms::DCCLCodec dccl(xml_files, "../../message_schema.xsd"); |
3060 | 37 | 38 | ||
3061 | 38 | // show some useful information about all the loaded messages | 39 | // show some useful information about all the loaded messages |
3062 | 39 | std::cout << std::string(30, '#') << std::endl | 40 | std::cout << std::string(30, '#') << std::endl |
3063 | @@ -75,7 +76,7 @@ | |||
3064 | 75 | << std::string(30, '#') << std::endl; | 76 | << std::string(30, '#') << std::endl; |
3065 | 76 | 77 | ||
3066 | 77 | // initialize input contents to encoder | 78 | // initialize input contents to encoder |
3068 | 78 | std::map<std::string, dccl::MessageVal> vals; | 79 | std::map<std::string, acomms::DCCLMessageVal> vals; |
3069 | 79 | 80 | ||
3070 | 80 | // initialize output hexadecimal | 81 | // initialize output hexadecimal |
3071 | 81 | std::string hex2, hex3; | 82 | std::string hex2, hex3; |
3072 | 82 | 83 | ||
3073 | === modified file 'src/acomms/libdccl/message.cpp' | |||
3074 | --- src/acomms/libdccl/message.cpp 2010-07-11 16:20:55 +0000 | |||
3075 | +++ src/acomms/libdccl/message.cpp 2010-07-15 12:38:39 +0000 | |||
3076 | @@ -22,7 +22,7 @@ | |||
3077 | 22 | 22 | ||
3078 | 23 | #include "message.h" | 23 | #include "message.h" |
3079 | 24 | 24 | ||
3081 | 25 | dccl::Message::Message():size_(0), | 25 | goby::acomms::DCCLMessage::DCCLMessage():size_(0), |
3082 | 26 | trigger_number_(1), | 26 | trigger_number_(1), |
3083 | 27 | body_bits_(0), | 27 | body_bits_(0), |
3084 | 28 | id_(0), | 28 | id_(0), |
3085 | @@ -30,61 +30,64 @@ | |||
3086 | 30 | repeat_enabled_(false), | 30 | repeat_enabled_(false), |
3087 | 31 | repeat_(1) | 31 | repeat_(1) |
3088 | 32 | { | 32 | { |
3106 | 33 | header_.resize(acomms::NUM_HEADER_PARTS); | 33 | header_.resize(DCCL_NUM_HEADER_PARTS); |
3107 | 34 | header_[acomms::head_ccl_id] = | 34 | header_[head_ccl_id] = |
3108 | 35 | boost::shared_ptr<MessageVar>(new MessageVarCCLID()); | 35 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarCCLID()); |
3109 | 36 | header_[acomms::head_dccl_id] = | 36 | header_[head_dccl_id] = |
3110 | 37 | boost::shared_ptr<MessageVar>(new MessageVarDCCLID()); | 37 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarDCCLID()); |
3111 | 38 | header_[acomms::head_time] = | 38 | header_[head_time] = |
3112 | 39 | boost::shared_ptr<MessageVar>(new MessageVarTime()); | 39 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarTime()); |
3113 | 40 | header_[acomms::head_src_id] = | 40 | header_[head_src_id] = |
3114 | 41 | boost::shared_ptr<MessageVar>(new MessageVarSrc()); | 41 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarSrc()); |
3115 | 42 | header_[acomms::head_dest_id] = | 42 | header_[head_dest_id] = |
3116 | 43 | boost::shared_ptr<MessageVar>(new MessageVarDest()); | 43 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarDest()); |
3117 | 44 | header_[acomms::head_multimessage_flag] = | 44 | header_[head_multimessage_flag] = |
3118 | 45 | boost::shared_ptr<MessageVar>(new MessageVarMultiMessageFlag()); | 45 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarMultiMessageFlag()); |
3119 | 46 | header_[acomms::head_broadcast_flag] = | 46 | header_[head_broadcast_flag] = |
3120 | 47 | boost::shared_ptr<MessageVar>(new MessageVarBroadcastFlag()); | 47 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarBroadcastFlag()); |
3121 | 48 | header_[acomms::head_unused] = | 48 | header_[head_unused] = |
3122 | 49 | boost::shared_ptr<MessageVar>(new MessageVarUnused()); | 49 | boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarUnused()); |
3123 | 50 | } | 50 | } |
3124 | 51 | 51 | ||
3125 | 52 | 52 | ||
3126 | 53 | // add a new message_var to the current messages vector | 53 | // add a new message_var to the current messages vector |
3128 | 54 | void dccl::Message::add_message_var(const std::string& type) | 54 | void goby::acomms::DCCLMessage::add_message_var(const std::string& type) |
3129 | 55 | { | 55 | { |
3130 | 56 | if(type == "static") | 56 | if(type == "static") |
3132 | 57 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarStatic())); | 57 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarStatic())); |
3133 | 58 | else if(type == "int") | 58 | else if(type == "int") |
3135 | 59 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarInt())); | 59 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarInt())); |
3136 | 60 | else if(type == "string") | 60 | else if(type == "string") |
3138 | 61 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarString())); | 61 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarString())); |
3139 | 62 | else if(type == "float") | 62 | else if(type == "float") |
3141 | 63 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarFloat())); | 63 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarFloat())); |
3142 | 64 | else if(type == "enum") | 64 | else if(type == "enum") |
3144 | 65 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarEnum())); | 65 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarEnum())); |
3145 | 66 | else if(type == "bool") | 66 | else if(type == "bool") |
3147 | 67 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarBool())); | 67 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarBool())); |
3148 | 68 | else if(type == "hex") | 68 | else if(type == "hex") |
3150 | 69 | layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarHex())); | 69 | layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarHex())); |
3151 | 70 | } | 70 | } |
3152 | 71 | 71 | ||
3153 | 72 | // add a new publish, i.e. a set of parameters to publish | 72 | // add a new publish, i.e. a set of parameters to publish |
3154 | 73 | // upon receipt of an incoming (hex) message | 73 | // upon receipt of an incoming (hex) message |
3156 | 74 | void dccl::Message::add_publish() | 74 | void goby::acomms::DCCLMessage::add_publish() |
3157 | 75 | { | 75 | { |
3159 | 76 | Publish p; | 76 | DCCLPublish p; |
3160 | 77 | publishes_.push_back(p); | 77 | publishes_.push_back(p); |
3161 | 78 | } | 78 | } |
3162 | 79 | 79 | ||
3163 | 80 | // a number of tasks to perform after reading in an entire <message> from | 80 | // a number of tasks to perform after reading in an entire <message> from |
3164 | 81 | // the xml file | 81 | // the xml file |
3166 | 82 | void dccl::Message::preprocess() | 82 | void goby::acomms::DCCLMessage::preprocess() |
3167 | 83 | { | 83 | { |
3168 | 84 | if(requested_bytes_total() <= bytes_head()) | ||
3169 | 85 | throw(std::runtime_error(std::string("<size> must be larger than the header size of " + boost::lexical_cast<std::string>(bytes_head())))); | ||
3170 | 86 | |||
3171 | 84 | // calculate number of repeated messages that will fit and put this in `repeat_`. | 87 | // calculate number of repeated messages that will fit and put this in `repeat_`. |
3172 | 85 | if(repeat_enabled_) | 88 | if(repeat_enabled_) |
3173 | 86 | { | 89 | { |
3175 | 87 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_) | 90 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3176 | 88 | { | 91 | { |
3177 | 89 | if(mv->array_length() != 1) | 92 | if(mv->array_length() != 1) |
3178 | 90 | throw(std::runtime_error("<repeat> is not allowed on messages with arrays (<array_length> not 1)")); | 93 | throw(std::runtime_error("<repeat> is not allowed on messages with arrays (<array_length> not 1)")); |
3179 | @@ -105,7 +108,7 @@ | |||
3180 | 105 | body_bits_ = calc_total_size(); | 108 | body_bits_ = calc_total_size(); |
3181 | 106 | 109 | ||
3182 | 107 | // initialize header vars | 110 | // initialize header vars |
3184 | 108 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_) | 111 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_) |
3185 | 109 | mv->initialize(trigger_var_); | 112 | mv->initialize(trigger_var_); |
3186 | 110 | 113 | ||
3187 | 111 | 114 | ||
3188 | @@ -115,7 +118,7 @@ | |||
3189 | 115 | } | 118 | } |
3190 | 116 | 119 | ||
3191 | 117 | // iterate over publishes_ | 120 | // iterate over publishes_ |
3193 | 118 | BOOST_FOREACH(Publish& p, publishes_) | 121 | BOOST_FOREACH(DCCLPublish& p, publishes_) |
3194 | 119 | p.initialize(*this); | 122 | p.initialize(*this); |
3195 | 120 | 123 | ||
3196 | 121 | // set incoming_var / outgoing_var if not set | 124 | // set incoming_var / outgoing_var if not set |
3197 | @@ -125,18 +128,18 @@ | |||
3198 | 125 | out_var_ = "OUT_" + boost::to_upper_copy(name_) + "_HEX_" + boost::lexical_cast<std::string>(size_) + "B"; | 128 | out_var_ = "OUT_" + boost::to_upper_copy(name_) + "_HEX_" + boost::lexical_cast<std::string>(size_) + "B"; |
3199 | 126 | } | 129 | } |
3200 | 127 | 130 | ||
3202 | 128 | void dccl::Message::set_repeat_array_length() | 131 | void goby::acomms::DCCLMessage::set_repeat_array_length() |
3203 | 129 | { | 132 | { |
3206 | 130 | // set array_length_ for repeated messages for all MessageVars | 133 | // set array_length_ for repeated messages for all DCCLMessageVars |
3207 | 131 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_) | 134 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3208 | 132 | mv->set_array_length(repeat_); | 135 | mv->set_array_length(repeat_); |
3209 | 133 | } | 136 | } |
3210 | 134 | 137 | ||
3212 | 135 | unsigned dccl::Message::calc_total_size() | 138 | unsigned goby::acomms::DCCLMessage::calc_total_size() |
3213 | 136 | { | 139 | { |
3214 | 137 | unsigned body_bits = 0; | 140 | unsigned body_bits = 0; |
3215 | 138 | // iterate over layout_ | 141 | // iterate over layout_ |
3217 | 139 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_) | 142 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3218 | 140 | { | 143 | { |
3219 | 141 | mv->initialize(trigger_var_); | 144 | mv->initialize(trigger_var_); |
3220 | 142 | // calculate total bits for the message from the bits for each message_var | 145 | // calculate total bits for the message from the bits for each message_var |
3221 | @@ -147,15 +150,15 @@ | |||
3222 | 147 | 150 | ||
3223 | 148 | 151 | ||
3224 | 149 | 152 | ||
3226 | 150 | std::map<std::string, std::string> dccl::Message::message_var_names() const | 153 | std::map<std::string, std::string> goby::acomms::DCCLMessage::message_var_names() const |
3227 | 151 | { | 154 | { |
3228 | 152 | std::map<std::string, std::string> s; | 155 | std::map<std::string, std::string> s; |
3230 | 153 | BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, layout_) | 156 | BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3231 | 154 | s.insert(std::pair<std::string, std::string>(mv->name(), type_to_string(mv->type()))); | 157 | s.insert(std::pair<std::string, std::string>(mv->name(), type_to_string(mv->type()))); |
3232 | 155 | return s; | 158 | return s; |
3233 | 156 | } | 159 | } |
3234 | 157 | 160 | ||
3236 | 158 | std::set<std::string> dccl::Message::get_pubsub_encode_vars() | 161 | std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_encode_vars() |
3237 | 159 | { | 162 | { |
3238 | 160 | std::set<std::string> s = get_pubsub_src_vars(); | 163 | std::set<std::string> s = get_pubsub_src_vars(); |
3239 | 161 | if(trigger_type_ == "publish") | 164 | if(trigger_type_ == "publish") |
3240 | @@ -163,14 +166,14 @@ | |||
3241 | 163 | return s; | 166 | return s; |
3242 | 164 | } | 167 | } |
3243 | 165 | 168 | ||
3245 | 166 | std::set<std::string> dccl::Message::get_pubsub_decode_vars() | 169 | std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_decode_vars() |
3246 | 167 | { | 170 | { |
3247 | 168 | std::set<std::string> s; | 171 | std::set<std::string> s; |
3248 | 169 | s.insert(in_var_); | 172 | s.insert(in_var_); |
3249 | 170 | return s; | 173 | return s; |
3250 | 171 | } | 174 | } |
3251 | 172 | 175 | ||
3253 | 173 | std::set<std::string> dccl::Message::get_pubsub_all_vars() | 176 | std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_all_vars() |
3254 | 174 | { | 177 | { |
3255 | 175 | std::set<std::string> s_enc = get_pubsub_encode_vars(); | 178 | std::set<std::string> s_enc = get_pubsub_encode_vars(); |
3256 | 176 | std::set<std::string> s_dec = get_pubsub_decode_vars(); | 179 | std::set<std::string> s_dec = get_pubsub_decode_vars(); |
3257 | @@ -181,25 +184,25 @@ | |||
3258 | 181 | return s; | 184 | return s; |
3259 | 182 | } | 185 | } |
3260 | 183 | 186 | ||
3262 | 184 | std::set<std::string> dccl::Message::get_pubsub_src_vars() | 187 | std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_src_vars() |
3263 | 185 | { | 188 | { |
3264 | 186 | std::set<std::string> s; | 189 | std::set<std::string> s; |
3265 | 187 | 190 | ||
3267 | 188 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_) | 191 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3268 | 189 | s.insert(mv->source_var()); | 192 | s.insert(mv->source_var()); |
3270 | 190 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_) | 193 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_) |
3271 | 191 | s.insert(mv->source_var()); | 194 | s.insert(mv->source_var()); |
3272 | 192 | 195 | ||
3273 | 193 | return s; | 196 | return s; |
3274 | 194 | } | 197 | } |
3275 | 195 | 198 | ||
3276 | 196 | 199 | ||
3278 | 197 | void dccl::Message::body_encode(std::string& body, std::map<std::string, std::vector<MessageVal> >& in) | 200 | void goby::acomms::DCCLMessage::body_encode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& in) |
3279 | 198 | { | 201 | { |
3280 | 199 | boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body())); | 202 | boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body())); |
3281 | 200 | 203 | ||
3282 | 201 | // 1. encode each variable into the bitset | 204 | // 1. encode each variable into the bitset |
3284 | 202 | for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = layout_.begin(), | 205 | for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = layout_.begin(), |
3285 | 203 | n = layout_.end(); | 206 | n = layout_.end(); |
3286 | 204 | it != n; | 207 | it != n; |
3287 | 205 | ++it) | 208 | ++it) |
3288 | @@ -214,7 +217,7 @@ | |||
3289 | 214 | body.resize(body.find_last_not_of(char(0))+1); | 217 | body.resize(body.find_last_not_of(char(0))+1); |
3290 | 215 | } | 218 | } |
3291 | 216 | 219 | ||
3293 | 217 | void dccl::Message::body_decode(std::string& body, std::map<std::string, std::vector<MessageVal> >& out) | 220 | void goby::acomms::DCCLMessage::body_decode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& out) |
3294 | 218 | { | 221 | { |
3295 | 219 | boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body())); | 222 | boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body())); |
3296 | 220 | 223 | ||
3297 | @@ -225,7 +228,7 @@ | |||
3298 | 225 | string2bitset(body_bits, body); | 228 | string2bitset(body_bits, body); |
3299 | 226 | 229 | ||
3300 | 227 | // 1. pull the bits off the message in the reverse that they were put on | 230 | // 1. pull the bits off the message in the reverse that they were put on |
3302 | 228 | for (std::vector< boost::shared_ptr<MessageVar> >::reverse_iterator it = layout_.rbegin(), | 231 | for (std::vector< boost::shared_ptr<DCCLMessageVar> >::reverse_iterator it = layout_.rbegin(), |
3303 | 229 | n = layout_.rend(); | 232 | n = layout_.rend(); |
3304 | 230 | it != n; | 233 | it != n; |
3305 | 231 | ++it) | 234 | ++it) |
3306 | @@ -234,9 +237,9 @@ | |||
3307 | 234 | } | 237 | } |
3308 | 235 | } | 238 | } |
3309 | 236 | 239 | ||
3311 | 237 | void dccl::Message::set_head_defaults(std::map<std::string, std::vector<MessageVal> >& in, unsigned modem_id) | 240 | void goby::acomms::DCCLMessage::set_head_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& in, unsigned modem_id) |
3312 | 238 | { | 241 | { |
3314 | 239 | for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = header_.begin(), | 242 | for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = header_.begin(), |
3315 | 240 | n = header_.end(); | 243 | n = header_.end(); |
3316 | 241 | it != n; | 244 | it != n; |
3317 | 242 | ++it) | 245 | ++it) |
3318 | @@ -245,12 +248,12 @@ | |||
3319 | 245 | } | 248 | } |
3320 | 246 | } | 249 | } |
3321 | 247 | 250 | ||
3323 | 248 | void dccl::Message::head_encode(std::string& head, std::map<std::string, std::vector<MessageVal> >& in) | 251 | void goby::acomms::DCCLMessage::head_encode(std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& in) |
3324 | 249 | { | 252 | { |
3326 | 250 | boost::dynamic_bitset<unsigned char> head_bits(bytes2bits(acomms::NUM_HEADER_BYTES)); | 253 | boost::dynamic_bitset<unsigned char> head_bits(bytes2bits(DCCL_NUM_HEADER_BYTES)); |
3327 | 251 | 254 | ||
3328 | 252 | 255 | ||
3330 | 253 | for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = header_.begin(), | 256 | for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = header_.begin(), |
3331 | 254 | n = header_.end(); | 257 | n = header_.end(); |
3332 | 255 | it != n; | 258 | it != n; |
3333 | 256 | ++it) | 259 | ++it) |
3334 | @@ -261,12 +264,12 @@ | |||
3335 | 261 | bitset2string(head_bits, head); | 264 | bitset2string(head_bits, head); |
3336 | 262 | } | 265 | } |
3337 | 263 | 266 | ||
3339 | 264 | void dccl::Message::head_decode(const std::string& head, std::map<std::string, std::vector<MessageVal> >& out) | 267 | void goby::acomms::DCCLMessage::head_decode(const std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& out) |
3340 | 265 | { | 268 | { |
3342 | 266 | boost::dynamic_bitset<unsigned char> head_bits(bytes2bits(acomms::NUM_HEADER_BYTES)); | 269 | boost::dynamic_bitset<unsigned char> head_bits(bytes2bits(DCCL_NUM_HEADER_BYTES)); |
3343 | 267 | string2bitset(head_bits, head); | 270 | string2bitset(head_bits, head); |
3344 | 268 | 271 | ||
3346 | 269 | for (std::vector< boost::shared_ptr<MessageVar> >::reverse_iterator it = header_.rbegin(), n = header_.rend(); | 272 | for (std::vector< boost::shared_ptr<DCCLMessageVar> >::reverse_iterator it = header_.rbegin(), n = header_.rend(); |
3347 | 270 | it != n; | 273 | it != n; |
3348 | 271 | ++it) | 274 | ++it) |
3349 | 272 | { | 275 | { |
3350 | @@ -274,20 +277,20 @@ | |||
3351 | 274 | } | 277 | } |
3352 | 275 | } | 278 | } |
3353 | 276 | 279 | ||
3355 | 277 | boost::shared_ptr<dccl::MessageVar> dccl::Message::name2message_var(const std::string& name) | 280 | boost::shared_ptr<goby::acomms::DCCLMessageVar> goby::acomms::DCCLMessage::name2message_var(const std::string& name) |
3356 | 278 | { | 281 | { |
3358 | 279 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_) | 282 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3359 | 280 | { | 283 | { |
3360 | 281 | if(mv->name() == name) return mv; | 284 | if(mv->name() == name) return mv; |
3361 | 282 | } | 285 | } |
3363 | 283 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_) | 286 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_) |
3364 | 284 | { | 287 | { |
3365 | 285 | if(mv->name() == name) return mv; | 288 | if(mv->name() == name) return mv; |
3366 | 286 | } | 289 | } |
3367 | 287 | 290 | ||
3368 | 288 | throw std::runtime_error(std::string("DCCL: no such name \"" + name + "\" found in <layout> or <header>")); | 291 | throw std::runtime_error(std::string("DCCL: no such name \"" + name + "\" found in <layout> or <header>")); |
3369 | 289 | 292 | ||
3371 | 290 | return boost::shared_ptr<dccl::MessageVar>(); | 293 | return boost::shared_ptr<DCCLMessageVar>(); |
3372 | 291 | } | 294 | } |
3373 | 292 | 295 | ||
3374 | 293 | //////////////////////////// | 296 | //////////////////////////// |
3375 | @@ -295,8 +298,8 @@ | |||
3376 | 295 | //////////////////////////// | 298 | //////////////////////////// |
3377 | 296 | 299 | ||
3378 | 297 | 300 | ||
3381 | 298 | // a long visual display of all the parameters for a Message | 301 | // a long visual display of all the parameters for a DCCLMessage |
3382 | 299 | std::string dccl::Message::get_display() const | 302 | std::string goby::acomms::DCCLMessage::get_display() const |
3383 | 300 | { | 303 | { |
3384 | 301 | const unsigned int num_stars = 20; | 304 | const unsigned int num_stars = 20; |
3385 | 302 | 305 | ||
3386 | @@ -335,12 +338,12 @@ | |||
3387 | 335 | ss << "actual size {bytes} [bits]: {" << used_bytes_total() << "} [" << used_bits_total() << "]" << std::endl; | 338 | ss << "actual size {bytes} [bits]: {" << used_bytes_total() << "} [" << used_bits_total() << "]" << std::endl; |
3388 | 336 | 339 | ||
3389 | 337 | ss << ">>>> HEADER <<<<" << std::endl; | 340 | ss << ">>>> HEADER <<<<" << std::endl; |
3391 | 338 | BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, header_) | 341 | BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, header_) |
3392 | 339 | ss << *mv; | 342 | ss << *mv; |
3393 | 340 | 343 | ||
3394 | 341 | ss << ">>>> LAYOUT (message_vars) <<<<" << std::endl; | 344 | ss << ">>>> LAYOUT (message_vars) <<<<" << std::endl; |
3395 | 342 | 345 | ||
3397 | 343 | BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, layout_) | 346 | BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, layout_) |
3398 | 344 | ss << *mv; | 347 | ss << *mv; |
3399 | 345 | 348 | ||
3400 | 346 | if(is_moos) | 349 | if(is_moos) |
3401 | @@ -348,7 +351,7 @@ | |||
3402 | 348 | 351 | ||
3403 | 349 | ss << ">>>> PUBLISHES <<<<" << std::endl; | 352 | ss << ">>>> PUBLISHES <<<<" << std::endl; |
3404 | 350 | 353 | ||
3406 | 351 | BOOST_FOREACH(const Publish& p, publishes_) | 354 | BOOST_FOREACH(const DCCLPublish& p, publishes_) |
3407 | 352 | ss << p; | 355 | ss << p; |
3408 | 353 | } | 356 | } |
3409 | 354 | 357 | ||
3410 | @@ -359,7 +362,7 @@ | |||
3411 | 359 | } | 362 | } |
3412 | 360 | 363 | ||
3413 | 361 | // a much shorter rundown of the Message parameters | 364 | // a much shorter rundown of the Message parameters |
3415 | 362 | std::string dccl::Message::get_short_display() const | 365 | std::string goby::acomms::DCCLMessage::get_short_display() const |
3416 | 363 | { | 366 | { |
3417 | 364 | std::stringstream ss; | 367 | std::stringstream ss; |
3418 | 365 | 368 | ||
3419 | @@ -384,7 +387,7 @@ | |||
3420 | 384 | } | 387 | } |
3421 | 385 | 388 | ||
3422 | 386 | // overloaded << | 389 | // overloaded << |
3424 | 387 | std::ostream& dccl::operator<< (std::ostream& out, const Message& message) | 390 | std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLMessage& message) |
3425 | 388 | { | 391 | { |
3426 | 389 | out << message.get_display(); | 392 | out << message.get_display(); |
3427 | 390 | return out; | 393 | return out; |
3428 | 391 | 394 | ||
3429 | === modified file 'src/acomms/libdccl/message.h' | |||
3430 | --- src/acomms/libdccl/message.h 2010-07-11 16:20:55 +0000 | |||
3431 | +++ src/acomms/libdccl/message.h 2010-07-15 12:38:39 +0000 | |||
3432 | @@ -31,8 +31,7 @@ | |||
3433 | 31 | #include <boost/foreach.hpp> | 31 | #include <boost/foreach.hpp> |
3434 | 32 | #include <boost/shared_ptr.hpp> | 32 | #include <boost/shared_ptr.hpp> |
3435 | 33 | 33 | ||
3438 | 34 | #include "util/tes_utils.h" | 34 | #include "goby/acomms/modem_message.h" |
3437 | 35 | #include "acomms/modem_message.h" | ||
3439 | 36 | 35 | ||
3440 | 37 | #include "message_var.h" | 36 | #include "message_var.h" |
3441 | 38 | #include "message_var_int.h" | 37 | #include "message_var_int.h" |
3442 | @@ -47,197 +46,200 @@ | |||
3443 | 47 | #include "message_publish.h" | 46 | #include "message_publish.h" |
3444 | 48 | #include "dccl_constants.h" | 47 | #include "dccl_constants.h" |
3445 | 49 | 48 | ||
3447 | 50 | namespace dccl | 49 | |
3448 | 50 | namespace goby | ||
3449 | 51 | { | 51 | { |
3639 | 52 | 52 | namespace acomms | |
3640 | 53 | // the Message itself | 53 | { |
3641 | 54 | class Message | 54 | |
3642 | 55 | { | 55 | // the DCCLMessage itself |
3643 | 56 | public: | 56 | class DCCLMessage |
3644 | 57 | Message(); | 57 | { |
3645 | 58 | 58 | public: | |
3646 | 59 | // set | 59 | DCCLMessage(); |
3647 | 60 | void set_name(const std::string& name) {name_ = name;} | 60 | |
3648 | 61 | 61 | // set | |
3649 | 62 | void set_id(unsigned id) | 62 | void set_name(const std::string& name) {name_ = name;} |
3650 | 63 | { id_ = id; } | 63 | |
3651 | 64 | template<typename T> void set_id(const T& t) | 64 | void set_id(unsigned id) |
3652 | 65 | { set_id(boost::lexical_cast<unsigned>(t)); } | 65 | { id_ = id; } |
3653 | 66 | 66 | template<typename T> void set_id(const T& t) | |
3654 | 67 | void set_trigger(const std::string& trigger_type) | 67 | { set_id(boost::lexical_cast<unsigned>(t)); } |
3655 | 68 | { trigger_type_ = trigger_type; } | 68 | |
3656 | 69 | 69 | void set_trigger(const std::string& trigger_type) | |
3657 | 70 | void set_trigger_var(const std::string& trigger_var) | 70 | { trigger_type_ = trigger_type; } |
3658 | 71 | { trigger_var_ = trigger_var; } | 71 | |
3659 | 72 | 72 | void set_trigger_var(const std::string& trigger_var) | |
3660 | 73 | void set_trigger_time(double trigger_time) | 73 | { trigger_var_ = trigger_var; } |
3661 | 74 | { trigger_time_ = trigger_time; } | 74 | |
3662 | 75 | template<typename T> void set_trigger_time(const T& t) | 75 | void set_trigger_time(double trigger_time) |
3663 | 76 | { set_trigger_time(boost::lexical_cast<double>(t)); } | 76 | { trigger_time_ = trigger_time; } |
3664 | 77 | 77 | template<typename T> void set_trigger_time(const T& t) | |
3665 | 78 | void set_trigger_mandatory(const std::string& trigger_mandatory) | 78 | { set_trigger_time(boost::lexical_cast<double>(t)); } |
3666 | 79 | { trigger_mandatory_ = trigger_mandatory; } | 79 | |
3667 | 80 | 80 | void set_trigger_mandatory(const std::string& trigger_mandatory) | |
3668 | 81 | void set_in_var(const std::string& in_var) | 81 | { trigger_mandatory_ = trigger_mandatory; } |
3669 | 82 | { in_var_ = in_var; } | 82 | |
3670 | 83 | 83 | void set_in_var(const std::string& in_var) | |
3671 | 84 | void set_out_var(const std::string& out_var) | 84 | { in_var_ = in_var; } |
3672 | 85 | { out_var_ = out_var; } | 85 | |
3673 | 86 | 86 | void set_out_var(const std::string& out_var) | |
3674 | 87 | void set_size(unsigned size) | 87 | { out_var_ = out_var; } |
3675 | 88 | { size_ = size; } | 88 | |
3676 | 89 | 89 | void set_size(unsigned size) | |
3677 | 90 | template<typename T> void set_size(const T& t) | 90 | { size_ = size; } |
3678 | 91 | { set_size(boost::lexical_cast<unsigned>(t)); } | 91 | |
3679 | 92 | 92 | template<typename T> void set_size(const T& t) | |
3680 | 93 | void set_repeat_enabled(unsigned repeat_enabled) | 93 | { set_size(boost::lexical_cast<unsigned>(t)); } |
3681 | 94 | { repeat_enabled_ = repeat_enabled; } | 94 | |
3682 | 95 | template<typename T> void set_repeat_enabled(const T& t) | 95 | void set_repeat_enabled(unsigned repeat_enabled) |
3683 | 96 | { set_repeat_enabled(boost::lexical_cast<unsigned>(t)); } | 96 | { repeat_enabled_ = repeat_enabled; } |
3684 | 97 | 97 | template<typename T> void set_repeat_enabled(const T& t) | |
3685 | 98 | void add_message_var(const std::string& type); | 98 | { set_repeat_enabled(boost::lexical_cast<unsigned>(t)); } |
3686 | 99 | void add_publish(); | 99 | |
3687 | 100 | 100 | void add_message_var(const std::string& type); | |
3688 | 101 | //get | 101 | void add_publish(); |
3689 | 102 | std::string name() const { return name_; } | 102 | |
3690 | 103 | unsigned id() const { return id_; } | 103 | //get |
3691 | 104 | std::string trigger_var() const { return trigger_var_; } | 104 | std::string name() const { return name_; } |
3692 | 105 | std::string trigger_mandatory() const { return trigger_mandatory_; } | 105 | unsigned id() const { return id_; } |
3693 | 106 | double trigger_time() const { return trigger_time_; } | 106 | std::string trigger_var() const { return trigger_var_; } |
3694 | 107 | unsigned trigger_number() const { return trigger_number_; } | 107 | std::string trigger_mandatory() const { return trigger_mandatory_; } |
3695 | 108 | std::string trigger_type() const { return trigger_type_; } | 108 | double trigger_time() const { return trigger_time_; } |
3696 | 109 | std::string in_var() const { return in_var_; } | 109 | unsigned trigger_number() const { return trigger_number_; } |
3697 | 110 | std::string out_var() const { return out_var_; } | 110 | std::string trigger_type() const { return trigger_type_; } |
3698 | 111 | bool repeat_enabled() const { return repeat_enabled_; } | 111 | std::string in_var() const { return in_var_; } |
3699 | 112 | unsigned repeat() const { return repeat_; } | 112 | std::string out_var() const { return out_var_; } |
3700 | 113 | 113 | bool repeat_enabled() const { return repeat_enabled_; } | |
3701 | 114 | MessageVar& last_message_var() { return *layout_.back(); } | 114 | unsigned repeat() const { return repeat_; } |
3702 | 115 | MessageVar& header_var(acomms::DCCLHeaderPart p) { return *header_[p]; } | 115 | |
3703 | 116 | Publish& last_publish() { return publishes_.back(); } | 116 | DCCLMessageVar& last_message_var() { return *layout_.back(); } |
3704 | 117 | 117 | DCCLMessageVar& header_var(acomms::DCCLHeaderPart p) { return *header_[p]; } | |
3705 | 118 | std::vector< boost::shared_ptr<MessageVar> >& layout() { return layout_; } | 118 | DCCLPublish& last_publish() { return publishes_.back(); } |
3706 | 119 | std::vector< boost::shared_ptr<MessageVar> >& header() { return header_; } | 119 | |
3707 | 120 | std::vector<Publish>& publishes() { return publishes_; } | 120 | std::vector< boost::shared_ptr<DCCLMessageVar> >& layout() { return layout_; } |
3708 | 121 | 121 | std::vector< boost::shared_ptr<DCCLMessageVar> >& header() { return header_; } | |
3709 | 122 | std::set<std::string> get_pubsub_encode_vars(); | 122 | std::vector<DCCLPublish>& publishes() { return publishes_; } |
3710 | 123 | std::set<std::string> get_pubsub_decode_vars(); | 123 | |
3711 | 124 | std::set<std::string> get_pubsub_src_vars(); | 124 | std::set<std::string> get_pubsub_encode_vars(); |
3712 | 125 | std::set<std::string> get_pubsub_all_vars(); | 125 | std::set<std::string> get_pubsub_decode_vars(); |
3713 | 126 | 126 | std::set<std::string> get_pubsub_src_vars(); | |
3714 | 127 | boost::shared_ptr<MessageVar> name2message_var(const std::string& name); | 127 | std::set<std::string> get_pubsub_all_vars(); |
3715 | 128 | 128 | ||
3716 | 129 | 129 | boost::shared_ptr<DCCLMessageVar> name2message_var(const std::string& name); | |
3717 | 130 | //other | 130 | |
3718 | 131 | std::string get_display() const; | 131 | |
3719 | 132 | std::string get_short_display() const; | 132 | //other |
3720 | 133 | std::map<std::string, std::string> message_var_names() const; | 133 | std::string get_display() const; |
3721 | 134 | void preprocess(); | 134 | std::string get_short_display() const; |
3722 | 135 | void set_repeat_array_length(); | 135 | std::map<std::string, std::string> message_var_names() const; |
3723 | 136 | unsigned calc_total_size(); | 136 | void preprocess(); |
3724 | 137 | 137 | void set_repeat_array_length(); | |
3725 | 138 | void set_head_defaults(std::map<std::string, std::vector<MessageVal> >& in, unsigned modem_id); | 138 | unsigned calc_total_size(); |
3726 | 139 | 139 | ||
3727 | 140 | 140 | void set_head_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& in, unsigned modem_id); | |
3728 | 141 | void head_encode(std::string& head, std::map<std::string, std::vector<MessageVal> >& in); | 141 | |
3729 | 142 | void head_decode(const std::string& head, std::map<std::string, std::vector<MessageVal> >& out); | 142 | |
3730 | 143 | 143 | void head_encode(std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& in); | |
3731 | 144 | void body_encode(std::string& body, std::map<std::string, std::vector<MessageVal> >& in); | 144 | void head_decode(const std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& out); |
3732 | 145 | void body_decode(std::string& body, std::map<std::string, std::vector<MessageVal> >& out); | 145 | |
3733 | 146 | 146 | void body_encode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& in); | |
3734 | 147 | // increment, means increase trigger number | 147 | void body_decode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& out); |
3735 | 148 | // prefix ++Message | 148 | |
3736 | 149 | Message& operator++() | 149 | // increment, means increase trigger number |
3737 | 150 | { ++trigger_number_; return(*this); } | 150 | // prefix ++DCCLMessage |
3738 | 151 | // postfix Message++ | 151 | DCCLMessage& operator++() |
3739 | 152 | const Message operator++(int) | 152 | { ++trigger_number_; return(*this); } |
3740 | 153 | { Message tmp(*this); ++(*this); return tmp;} | 153 | // postfix DCCLMessage++ |
3741 | 154 | 154 | const DCCLMessage operator++(int) | |
3742 | 155 | 155 | { DCCLMessage tmp(*this); ++(*this); return tmp;} | |
3743 | 156 | private: | 156 | |
3744 | 157 | unsigned bytes_head() const | 157 | |
3745 | 158 | { return acomms::NUM_HEADER_BYTES; } | 158 | private: |
3746 | 159 | unsigned bits_head() const | 159 | unsigned bytes_head() const |
3747 | 160 | { return bytes2bits(acomms::NUM_HEADER_BYTES); } | 160 | { return acomms::DCCL_NUM_HEADER_BYTES; } |
3748 | 161 | 161 | unsigned bits_head() const | |
3749 | 162 | // more efficient way to do ceil(total_bits / 8) | 162 | { return bytes2bits(acomms::DCCL_NUM_HEADER_BYTES); } |
3750 | 163 | // to get the number of bytes rounded up. | 163 | |
3751 | 164 | 164 | // more efficient way to do ceil(total_bits / 8) | |
3752 | 165 | enum { BYTE_MASK = 7 }; // 00000111 | 165 | // to get the number of bytes rounded up. |
3753 | 166 | unsigned used_bytes_body() const | 166 | |
3754 | 167 | { | 167 | enum { BYTE_MASK = 7 }; // 00000111 |
3755 | 168 | return (body_bits_& BYTE_MASK) ? | 168 | unsigned used_bytes_body() const |
3756 | 169 | bits2bytes(body_bits_) + 1 : | 169 | { |
3757 | 170 | bits2bytes(body_bits_); | 170 | return (body_bits_& BYTE_MASK) ? |
3758 | 171 | } | 171 | bits2bytes(body_bits_) + 1 : |
3759 | 172 | 172 | bits2bytes(body_bits_); | |
3760 | 173 | unsigned used_bytes_total() const | 173 | } |
3761 | 174 | { return bytes_head() + used_bytes_body(); } | 174 | |
3762 | 175 | 175 | unsigned used_bytes_total() const | |
3763 | 176 | unsigned used_bits_body() const | 176 | { return bytes_head() + used_bytes_body(); } |
3764 | 177 | { return body_bits_; } | 177 | |
3765 | 178 | 178 | unsigned used_bits_body() const | |
3766 | 179 | unsigned used_bits_total() const | 179 | { return body_bits_; } |
3767 | 180 | { return bits_head() + used_bits_body(); } | 180 | |
3768 | 181 | 181 | unsigned used_bits_total() const | |
3769 | 182 | unsigned requested_bytes_body() const | 182 | { return bits_head() + used_bits_body(); } |
3770 | 183 | { return size_ - acomms::NUM_HEADER_BYTES; } | 183 | |
3771 | 184 | 184 | unsigned requested_bytes_body() const | |
3772 | 185 | unsigned requested_bytes_total() const | 185 | { return size_ - acomms::DCCL_NUM_HEADER_BYTES; } |
3773 | 186 | { return size_; } | 186 | |
3774 | 187 | 187 | unsigned requested_bytes_total() const | |
3775 | 188 | unsigned requested_bits_body() const | 188 | { return size_; } |
3776 | 189 | { return bytes2bits(size_ - acomms::NUM_HEADER_BYTES); } | 189 | |
3777 | 190 | 190 | unsigned requested_bits_body() const | |
3778 | 191 | unsigned requested_bits_total() const | 191 | { return bytes2bits(size_ - acomms::DCCL_NUM_HEADER_BYTES); } |
3779 | 192 | { return bytes2bits(size_); } | 192 | |
3780 | 193 | 193 | unsigned requested_bits_total() const | |
3781 | 194 | 194 | { return bytes2bits(size_); } | |
3782 | 195 | private: | 195 | |
3783 | 196 | // total request size of message, e.g. 32 bytes | 196 | |
3784 | 197 | unsigned size_; | 197 | private: |
3785 | 198 | 198 | // total request size of message, e.g. 32 bytes | |
3786 | 199 | unsigned trigger_number_; | 199 | unsigned size_; |
3787 | 200 | // actual used bits in body part of message (not including header bits) | 200 | |
3788 | 201 | unsigned body_bits_; | 201 | unsigned trigger_number_; |
3789 | 202 | 202 | // actual used bits in body part of message (not including header bits) | |
3790 | 203 | unsigned id_; | 203 | unsigned body_bits_; |
3791 | 204 | unsigned modem_id_; | 204 | |
3792 | 205 | double trigger_time_; | 205 | unsigned id_; |
3793 | 206 | 206 | unsigned modem_id_; | |
3794 | 207 | bool repeat_enabled_; | 207 | double trigger_time_; |
3795 | 208 | unsigned repeat_; | 208 | |
3796 | 209 | 209 | bool repeat_enabled_; | |
3797 | 210 | std::string name_; | 210 | unsigned repeat_; |
3798 | 211 | std::string trigger_type_; | 211 | |
3799 | 212 | std::string trigger_var_; | 212 | std::string name_; |
3800 | 213 | std::string trigger_mandatory_; | 213 | std::string trigger_type_; |
3801 | 214 | std::string in_var_; | 214 | std::string trigger_var_; |
3802 | 215 | std::string out_var_; | 215 | std::string trigger_mandatory_; |
3803 | 216 | 216 | std::string in_var_; | |
3804 | 217 | std::vector< boost::shared_ptr<MessageVar> > layout_; | 217 | std::string out_var_; |
3805 | 218 | std::vector< boost::shared_ptr<MessageVar> > header_; | 218 | |
3806 | 219 | 219 | std::vector< boost::shared_ptr<DCCLMessageVar> > layout_; | |
3807 | 220 | 220 | std::vector< boost::shared_ptr<DCCLMessageVar> > header_; | |
3808 | 221 | std::vector<Publish> publishes_; | 221 | |
3809 | 222 | 222 | ||
3810 | 223 | }; | 223 | std::vector<DCCLPublish> publishes_; |
3811 | 224 | 224 | ||
3812 | 225 | 225 | }; | |
3813 | 226 | inline void bitset2string(const boost::dynamic_bitset<unsigned char>& body_bits, | 226 | |
3814 | 227 | std::string& body) | 227 | |
3815 | 228 | { | 228 | inline void bitset2string(const boost::dynamic_bitset<unsigned char>& body_bits, |
3816 | 229 | body.resize(body_bits.num_blocks()); // resize the string to fit the bitset | 229 | std::string& body) |
3817 | 230 | to_block_range(body_bits, body.rbegin()); | 230 | { |
3818 | 231 | } | 231 | body.resize(body_bits.num_blocks()); // resize the string to fit the bitset |
3819 | 232 | 232 | to_block_range(body_bits, body.rbegin()); | |
3820 | 233 | inline void string2bitset(boost::dynamic_bitset<unsigned char>& body_bits, | 233 | } |
3821 | 234 | const std::string& body) | 234 | |
3822 | 235 | { | 235 | inline void string2bitset(boost::dynamic_bitset<unsigned char>& body_bits, |
3823 | 236 | from_block_range(body.rbegin(), body.rend(), body_bits); | 236 | const std::string& body) |
3824 | 237 | } | 237 | { |
3825 | 238 | 238 | from_block_range(body.rbegin(), body.rend(), body_bits); | |
3826 | 239 | 239 | } | |
3827 | 240 | std::ostream& operator<< (std::ostream& out, const Message& message); | 240 | |
3828 | 241 | |||
3829 | 242 | std::ostream& operator<< (std::ostream& out, const DCCLMessage& message); | ||
3830 | 243 | } | ||
3831 | 241 | } | 244 | } |
3832 | 242 | |||
3833 | 243 | #endif | 245 | #endif |
3834 | 244 | 246 | ||
3835 | === modified file 'src/acomms/libdccl/message_algorithms.cpp' | |||
3836 | --- src/acomms/libdccl/message_algorithms.cpp 2010-06-15 04:51:47 +0000 | |||
3837 | +++ src/acomms/libdccl/message_algorithms.cpp 2010-07-15 12:38:39 +0000 | |||
3838 | @@ -22,33 +22,34 @@ | |||
3839 | 22 | #include "message_algorithms.h" | 22 | #include "message_algorithms.h" |
3840 | 23 | #include "message_val.h" | 23 | #include "message_val.h" |
3841 | 24 | 24 | ||
3843 | 25 | dccl::AlgorithmPerformer* dccl::AlgorithmPerformer::inst_ = NULL; | 25 | #include "goby/util/string.h" |
3844 | 26 | |||
3845 | 27 | goby::acomms::DCCLAlgorithmPerformer* goby::acomms::DCCLAlgorithmPerformer::inst_ = 0; | ||
3846 | 26 | 28 | ||
3847 | 27 | // singleton class, use this to get pointer | 29 | // singleton class, use this to get pointer |
3849 | 28 | dccl::AlgorithmPerformer* dccl::AlgorithmPerformer::getInstance() | 30 | goby::acomms::DCCLAlgorithmPerformer* goby::acomms::DCCLAlgorithmPerformer::getInstance() |
3850 | 29 | { | 31 | { |
3853 | 30 | if(inst_ == NULL) | 32 | if(!inst_) inst_ = new DCCLAlgorithmPerformer(); |
3852 | 31 | inst_ = new AlgorithmPerformer(); | ||
3854 | 32 | 33 | ||
3855 | 33 | return(inst_); | 34 | return(inst_); |
3856 | 34 | } | 35 | } |
3857 | 35 | 36 | ||
3859 | 36 | void dccl::AlgorithmPerformer::algorithm(MessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<MessageVal> >& vals) | 37 | void goby::acomms::DCCLAlgorithmPerformer::algorithm(DCCLMessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<DCCLMessageVal> >& vals) |
3860 | 37 | { | 38 | { |
3861 | 38 | if(in.empty()) return; | 39 | if(in.empty()) return; |
3862 | 39 | 40 | ||
3863 | 40 | // algo_name:ref_variable_name1:ref_variable_name2... | 41 | // algo_name:ref_variable_name1:ref_variable_name2... |
3864 | 41 | 42 | ||
3866 | 42 | std::vector<std::string>ref_vars = tes_util::explode(algorithm, ':', true); | 43 | std::vector<std::string>ref_vars = util::explode(algorithm, ':', true); |
3867 | 43 | 44 | ||
3868 | 44 | std::string alg; | 45 | std::string alg; |
3870 | 45 | std::vector<MessageVal> tied_vals; | 46 | std::vector<DCCLMessageVal> tied_vals; |
3871 | 46 | 47 | ||
3872 | 47 | for(std::vector<std::string>::size_type i = 1, n = ref_vars.size(); | 48 | for(std::vector<std::string>::size_type i = 1, n = ref_vars.size(); |
3873 | 48 | i < n; | 49 | i < n; |
3874 | 49 | ++i) | 50 | ++i) |
3875 | 50 | { | 51 | { |
3877 | 51 | std::map<std::string, std::vector<dccl::MessageVal> >::const_iterator it = vals.find(ref_vars[i]); | 52 | std::map<std::string, std::vector<DCCLMessageVal> >::const_iterator it = vals.find(ref_vars[i]); |
3878 | 52 | if(it != vals.end() && array_index < it->second.size()) | 53 | if(it != vals.end() && array_index < it->second.size()) |
3879 | 53 | tied_vals.push_back(it->second[array_index]); | 54 | tied_vals.push_back(it->second[array_index]); |
3880 | 54 | else | 55 | else |
3881 | 55 | 56 | ||
3882 | === modified file 'src/acomms/libdccl/message_algorithms.h' | |||
3883 | --- src/acomms/libdccl/message_algorithms.h 2010-06-15 04:51:47 +0000 | |||
3884 | +++ src/acomms/libdccl/message_algorithms.h 2010-07-15 12:38:39 +0000 | |||
3885 | @@ -28,45 +28,46 @@ | |||
3886 | 28 | 28 | ||
3887 | 29 | #include <boost/algorithm/string.hpp> | 29 | #include <boost/algorithm/string.hpp> |
3888 | 30 | #include <boost/function.hpp> | 30 | #include <boost/function.hpp> |
3891 | 31 | 31 | namespace goby | |
3890 | 32 | namespace dccl | ||
3892 | 33 | { | 32 | { |
3894 | 34 | class MessageVal; | 33 | namespace acomms |
3895 | 34 | { | ||
3896 | 35 | class DCCLMessageVal; | ||
3897 | 35 | 36 | ||
3930 | 36 | /// \brief boost::function for a function taking a single dccl::MessageVal reference. Used for algorithm callbacks. | 37 | /// \brief boost::function for a function taking a single DCCLMessageVal reference. Used for algorithm callbacks. |
3931 | 37 | /// | 38 | /// |
3932 | 38 | /// Think of this as a generalized version of a function pointer (void (*)(dccl::MessageVal&)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. | 39 | /// Think of this as a generalized version of a function pointer (void (*)(DCCLMessageVal&)). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. |
3933 | 39 | typedef boost::function<void (MessageVal&)> AlgFunction1; | 40 | typedef boost::function<void (DCCLMessageVal&)> AlgFunction1; |
3934 | 40 | /// \brief boost::function for a function taking a dccl::MessageVal reference, and the MessageVal of a second part of the message. Used for algorithm callbacks. | 41 | /// \brief boost::function for a function taking a dccl::MessageVal reference, and the MessageVal of a second part of the message. Used for algorithm callbacks. |
3935 | 41 | /// | 42 | /// |
3936 | 42 | /// Think of this as a generalized version of a function pointer (void (*)(MessageVal&, const MessageVal&). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. | 43 | /// Think of this as a generalized version of a function pointer (void (*)(DCCLMessageVal&, const DCCLMessageVal&). See http://www.boost.org/doc/libs/1_34_0/doc/html/function.html for more on boost:function. |
3937 | 43 | typedef boost::function<void (MessageVal&, const std::vector<MessageVal>&)> AlgFunction2; | 44 | typedef boost::function<void (DCCLMessageVal&, const std::vector<DCCLMessageVal>&)> AlgFunction2; |
3938 | 44 | 45 | ||
3939 | 45 | class AlgorithmPerformer | 46 | class DCCLAlgorithmPerformer |
3940 | 46 | { | 47 | { |
3941 | 47 | public: | 48 | public: |
3942 | 48 | static AlgorithmPerformer* getInstance(); | 49 | static DCCLAlgorithmPerformer* getInstance(); |
3943 | 49 | 50 | ||
3944 | 50 | void algorithm(MessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<MessageVal> >& vals); | 51 | void algorithm(DCCLMessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<DCCLMessageVal> >& vals); |
3945 | 51 | 52 | ||
3946 | 52 | void add_algorithm(const std::string& name, AlgFunction1 func) | 53 | void add_algorithm(const std::string& name, AlgFunction1 func) |
3947 | 53 | { adv_map1_[name] = func; } | 54 | { adv_map1_[name] = func; } |
3948 | 54 | 55 | ||
3949 | 55 | void add_algorithm(const std::string& name, AlgFunction2 func) | 56 | void add_algorithm(const std::string& name, AlgFunction2 func) |
3950 | 56 | { adv_map2_[name] = func; } | 57 | { adv_map2_[name] = func; } |
3951 | 57 | 58 | ||
3952 | 58 | private: | 59 | private: |
3953 | 59 | static AlgorithmPerformer* inst_; | 60 | static DCCLAlgorithmPerformer* inst_; |
3954 | 60 | std::map<std::string, AlgFunction1> adv_map1_; | 61 | std::map<std::string, AlgFunction1> adv_map1_; |
3955 | 61 | std::map<std::string, AlgFunction2> adv_map2_; | 62 | std::map<std::string, AlgFunction2> adv_map2_; |
3956 | 62 | 63 | ||
3957 | 63 | AlgorithmPerformer() | 64 | DCCLAlgorithmPerformer() |
3958 | 64 | {} | 65 | {} |
3959 | 65 | 66 | ||
3960 | 66 | AlgorithmPerformer(const AlgorithmPerformer&); | 67 | DCCLAlgorithmPerformer(const DCCLAlgorithmPerformer&); |
3961 | 67 | AlgorithmPerformer& operator = (const AlgorithmPerformer&); | 68 | DCCLAlgorithmPerformer& operator = (const DCCLAlgorithmPerformer&); |
3962 | 68 | 69 | ||
3964 | 69 | }; | 70 | }; |
3965 | 71 | } | ||
3966 | 70 | } | 72 | } |
3967 | 71 | |||
3968 | 72 | #endif | 73 | #endif |
3969 | 73 | 74 | ||
3970 | === modified file 'src/acomms/libdccl/message_publish.cpp' | |||
3971 | --- src/acomms/libdccl/message_publish.cpp 2010-06-15 04:51:47 +0000 | |||
3972 | +++ src/acomms/libdccl/message_publish.cpp 2010-07-15 12:38:39 +0000 | |||
3973 | @@ -22,9 +22,9 @@ | |||
3974 | 22 | #include "message_publish.h" | 22 | #include "message_publish.h" |
3975 | 23 | #include "message.h" | 23 | #include "message.h" |
3976 | 24 | 24 | ||
3978 | 25 | using acomms::NaN; | 25 | using goby::acomms::NaN; |
3979 | 26 | 26 | ||
3981 | 27 | void dccl::Publish::initialize(Message& msg) | 27 | void goby::acomms::DCCLPublish::initialize(DCCLMessage& msg) |
3982 | 28 | { | 28 | { |
3983 | 29 | repeat_ = msg.repeat(); | 29 | repeat_ = msg.repeat(); |
3984 | 30 | 30 | ||
3985 | @@ -36,7 +36,7 @@ | |||
3986 | 36 | // add names for any <all/> publishes and empty std::vector for algorithms | 36 | // add names for any <all/> publishes and empty std::vector for algorithms |
3987 | 37 | if(use_all_names_) | 37 | if(use_all_names_) |
3988 | 38 | { | 38 | { |
3990 | 39 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, msg.header()) | 39 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, msg.header()) |
3991 | 40 | { | 40 | { |
3992 | 41 | // ignore header pieces not explicitly overloaded by the <name> tag | 41 | // ignore header pieces not explicitly overloaded by the <name> tag |
3993 | 42 | if(!mv->name().empty() && !(mv->name()[0] == '_')) | 42 | if(!mv->name().empty() && !(mv->name()[0] == '_')) |
3994 | @@ -47,7 +47,7 @@ | |||
3995 | 47 | } | 47 | } |
3996 | 48 | } | 48 | } |
3997 | 49 | 49 | ||
3999 | 50 | BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, msg.layout()) | 50 | BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, msg.layout()) |
4000 | 51 | { | 51 | { |
4001 | 52 | add_message_var(mv); | 52 | add_message_var(mv); |
4002 | 53 | // add an empty std::vector for algorithms (no algorithms allowed for <all/> tag) | 53 | // add an empty std::vector for algorithms (no algorithms allowed for <all/> tag) |
4003 | @@ -60,7 +60,7 @@ | |||
4004 | 60 | if(!format_set_) | 60 | if(!format_set_) |
4005 | 61 | { | 61 | { |
4006 | 62 | std::string format_str; | 62 | std::string format_str; |
4008 | 63 | for (std::vector<boost::shared_ptr<MessageVar> >::size_type j = 0, m = message_vars_.size(); j < m; ++j) | 63 | for (std::vector<boost::shared_ptr<DCCLMessageVar> >::size_type j = 0, m = message_vars_.size(); j < m; ++j) |
4009 | 64 | { | 64 | { |
4010 | 65 | if (m > 1) | 65 | if (m > 1) |
4011 | 66 | { | 66 | { |
4012 | @@ -102,10 +102,10 @@ | |||
4013 | 102 | } | 102 | } |
4014 | 103 | 103 | ||
4015 | 104 | 104 | ||
4020 | 105 | void dccl::Publish::fill_format(const std::map<std::string,std::vector<MessageVal> >& vals, | 105 | void goby::acomms::DCCLPublish::fill_format(const std::map<std::string,std::vector<DCCLMessageVal> >& vals, |
4021 | 106 | std::string& key, | 106 | std::string& key, |
4022 | 107 | std::string& value, | 107 | std::string& value, |
4023 | 108 | unsigned repeat_index) | 108 | unsigned repeat_index) |
4024 | 109 | { | 109 | { |
4025 | 110 | std::string filled_value; | 110 | std::string filled_value; |
4026 | 111 | // format is a boost library class for replacing printf and its ilk | 111 | // format is a boost library class for replacing printf and its ilk |
4027 | @@ -120,10 +120,10 @@ | |||
4028 | 120 | f.parse(input_format); | 120 | f.parse(input_format); |
4029 | 121 | 121 | ||
4030 | 122 | // iterate over the message_vars and fill in the format field | 122 | // iterate over the message_vars and fill in the format field |
4032 | 123 | for (std::vector<boost::shared_ptr<MessageVar> >::size_type k = 0, o = message_vars_.size(); k < o; ++k) | 123 | for (std::vector<boost::shared_ptr<DCCLMessageVar> >::size_type k = 0, o = message_vars_.size(); k < o; ++k) |
4033 | 124 | { | 124 | { |
4036 | 125 | std::vector<MessageVal> vm = vals.find(message_vars_[k]->name())->second; | 125 | std::vector<DCCLMessageVal> vm = vals.find(message_vars_[k]->name())->second; |
4037 | 126 | for(std::vector<MessageVal>::size_type i = (repeat_ > 1) ? repeat_index : 0, | 126 | for(std::vector<DCCLMessageVal>::size_type i = (repeat_ > 1) ? repeat_index : 0, |
4038 | 127 | n = (repeat_ > 1) ? repeat_index + 1 : vm.size(); | 127 | n = (repeat_ > 1) ? repeat_index + 1 : vm.size(); |
4039 | 128 | i < n; | 128 | i < n; |
4040 | 129 | ++i) | 129 | ++i) |
4041 | @@ -159,8 +159,8 @@ | |||
4042 | 159 | 159 | ||
4043 | 160 | 160 | ||
4044 | 161 | 161 | ||
4047 | 162 | void dccl::Publish::write_publish(const std::map<std::string,std::vector<MessageVal> >& vals, | 162 | void goby::acomms::DCCLPublish::write_publish(const std::map<std::string,std::vector<DCCLMessageVal> >& vals, |
4048 | 163 | std::multimap<std::string,MessageVal>& pubsub_vals) | 163 | std::multimap<std::string,DCCLMessageVal>& pubsub_vals) |
4049 | 164 | 164 | ||
4050 | 165 | { | 165 | { |
4051 | 166 | for(unsigned i = 0, n = repeat_; | 166 | for(unsigned i = 0, n = repeat_; |
4052 | @@ -173,29 +173,29 @@ | |||
4053 | 173 | // user sets to string | 173 | // user sets to string |
4054 | 174 | if(type_ == cpp_string) | 174 | if(type_ == cpp_string) |
4055 | 175 | { | 175 | { |
4057 | 176 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_val)); | 176 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_val)); |
4058 | 177 | continue; | 177 | continue; |
4059 | 178 | } | 178 | } |
4060 | 179 | 179 | ||
4063 | 180 | // pass through a MessageVal to do the type conversions | 180 | // pass through a DCCLMessageVal to do the type conversions |
4064 | 181 | MessageVal mv = out_val; | 181 | DCCLMessageVal mv = out_val; |
4065 | 182 | double out_dval = mv; | 182 | double out_dval = mv; |
4066 | 183 | if(type_ == cpp_double) | 183 | if(type_ == cpp_double) |
4067 | 184 | { | 184 | { |
4069 | 185 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_dval)); | 185 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_dval)); |
4070 | 186 | continue; | 186 | continue; |
4071 | 187 | } | 187 | } |
4072 | 188 | long out_lval = mv; | 188 | long out_lval = mv; |
4073 | 189 | if(type_ == cpp_long) | 189 | if(type_ == cpp_long) |
4074 | 190 | { | 190 | { |
4076 | 191 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_lval)); | 191 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_lval)); |
4077 | 192 | continue; | 192 | continue; |
4078 | 193 | 193 | ||
4079 | 194 | } | 194 | } |
4080 | 195 | bool out_bval = mv; | 195 | bool out_bval = mv; |
4081 | 196 | if(type_ == cpp_bool) | 196 | if(type_ == cpp_bool) |
4082 | 197 | { | 197 | { |
4084 | 198 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_bval)); | 198 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_bval)); |
4085 | 199 | continue; | 199 | continue; |
4086 | 200 | } | 200 | } |
4087 | 201 | 201 | ||
4088 | @@ -205,14 +205,14 @@ | |||
4089 | 205 | catch (boost::bad_lexical_cast &) { is_numeric = false; } | 205 | catch (boost::bad_lexical_cast &) { is_numeric = false; } |
4090 | 206 | 206 | ||
4091 | 207 | if(!is_numeric) | 207 | if(!is_numeric) |
4093 | 208 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_val)); | 208 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_val)); |
4094 | 209 | else | 209 | else |
4096 | 210 | pubsub_vals.insert(std::pair<std::string, MessageVal>(out_var, out_dval)); | 210 | pubsub_vals.insert(std::pair<std::string, DCCLMessageVal>(out_var, out_dval)); |
4097 | 211 | } | 211 | } |
4098 | 212 | } | 212 | } |
4099 | 213 | 213 | ||
4100 | 214 | 214 | ||
4102 | 215 | std::string dccl::Publish::get_display() const | 215 | std::string goby::acomms::DCCLPublish::get_display() const |
4103 | 216 | { | 216 | { |
4104 | 217 | std::stringstream ss; | 217 | std::stringstream ss; |
4105 | 218 | 218 | ||
4106 | @@ -220,7 +220,7 @@ | |||
4107 | 220 | ss << ")moos_var: {" << var_ << "}" << std::endl; | 220 | ss << ")moos_var: {" << var_ << "}" << std::endl; |
4108 | 221 | ss << "\tvalue: \"" << format_ << "\"" << std::endl; | 221 | ss << "\tvalue: \"" << format_ << "\"" << std::endl; |
4109 | 222 | ss << "\tmessage_vars:" << std::endl; | 222 | ss << "\tmessage_vars:" << std::endl; |
4111 | 223 | for (std::vector<boost::shared_ptr<MessageVar> >::size_type j = 0, m = message_vars_.size(); j < m; ++j) | 223 | for (std::vector<boost::shared_ptr<DCCLMessageVar> >::size_type j = 0, m = message_vars_.size(); j < m; ++j) |
4112 | 224 | { | 224 | { |
4113 | 225 | ss << "\t\t" << (j+1) << ": " << message_vars_[j]->name(); | 225 | ss << "\t\t" << (j+1) << ": " << message_vars_[j]->name(); |
4114 | 226 | 226 | ||
4115 | @@ -240,7 +240,7 @@ | |||
4116 | 240 | } | 240 | } |
4117 | 241 | 241 | ||
4118 | 242 | // overloaded << | 242 | // overloaded << |
4120 | 243 | std::ostream& dccl::operator<< (std::ostream& out, const Publish& publish) | 243 | std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLPublish& publish) |
4121 | 244 | { | 244 | { |
4122 | 245 | out << publish.get_display(); | 245 | out << publish.get_display(); |
4123 | 246 | return out; | 246 | return out; |
4124 | 247 | 247 | ||
4125 | === modified file 'src/acomms/libdccl/message_publish.h' | |||
4126 | --- src/acomms/libdccl/message_publish.h 2010-06-15 04:51:47 +0000 | |||
4127 | +++ src/acomms/libdccl/message_publish.h 2010-07-15 12:38:39 +0000 | |||
4128 | @@ -31,77 +31,79 @@ | |||
4129 | 31 | #include "message_algorithms.h" | 31 | #include "message_algorithms.h" |
4130 | 32 | #include "dccl_constants.h" | 32 | #include "dccl_constants.h" |
4131 | 33 | 33 | ||
4133 | 34 | namespace dccl | 34 | namespace goby |
4134 | 35 | { | 35 | { |
4136 | 36 | class Message; | 36 | namespace acomms |
4137 | 37 | { | ||
4138 | 38 | class DCCLMessage; | ||
4139 | 37 | 39 | ||
4140 | 38 | // defines (a single) thing to do with the decoded message | 40 | // defines (a single) thing to do with the decoded message |
4141 | 39 | // that is, where do we publish it and what should we include in the | 41 | // that is, where do we publish it and what should we include in the |
4142 | 40 | // published message | 42 | // published message |
4167 | 41 | class Publish | 43 | class DCCLPublish |
4168 | 42 | { | 44 | { |
4169 | 43 | public: | 45 | public: |
4170 | 44 | Publish() : var_(""), | 46 | DCCLPublish() : var_(""), |
4171 | 45 | format_(""), | 47 | format_(""), |
4172 | 46 | format_set_(false), | 48 | format_set_(false), |
4173 | 47 | use_all_names_(false), | 49 | use_all_names_(false), |
4174 | 48 | type_(cpp_notype), | 50 | type_(cpp_notype), |
4175 | 49 | ap_(AlgorithmPerformer::getInstance()), | 51 | ap_(DCCLAlgorithmPerformer::getInstance()), |
4176 | 50 | repeat_(1) | 52 | repeat_(1) |
4177 | 51 | { } | 53 | { } |
4178 | 52 | 54 | ||
4179 | 53 | //set | 55 | //set |
4180 | 54 | 56 | ||
4181 | 55 | void set_var(std::string var) {var_=var;} | 57 | void set_var(std::string var) {var_=var;} |
4182 | 56 | void set_format(std::string format) {format_=format; format_set_ = true;} | 58 | void set_format(std::string format) {format_=format; format_set_ = true;} |
4183 | 57 | void set_use_all_names(bool use_all_names) {use_all_names_ = use_all_names;} | 59 | void set_use_all_names(bool use_all_names) {use_all_names_ = use_all_names;} |
4184 | 58 | void set_type(DCCLCppType type) {type_ = type;} | 60 | void set_type(DCCLCppType type) {type_ = type;} |
4185 | 59 | 61 | ||
4186 | 60 | void add_name(const std::string& name) {names_.push_back(name);} | 62 | void add_name(const std::string& name) {names_.push_back(name);} |
4187 | 61 | void add_message_var(boost::shared_ptr<MessageVar> mv) {message_vars_.push_back(mv);} | 63 | void add_message_var(boost::shared_ptr<DCCLMessageVar> mv) {message_vars_.push_back(mv);} |
4188 | 62 | void add_algorithms(const std::vector<std::string> algorithms) {algorithms_.push_back(algorithms);} | 64 | void add_algorithms(const std::vector<std::string> algorithms) {algorithms_.push_back(algorithms);} |
4189 | 63 | 65 | ||
4190 | 64 | //get | 66 | //get |
4191 | 65 | // std::string var() const {return var_;} | 67 | // std::string var() const {return var_;} |
4192 | 66 | // std::string format() const {return format_;} | 68 | // std::string format() const {return format_;} |
4193 | 67 | // bool format_set() const {return format_set_;} | 69 | // bool format_set() const {return format_set_;} |
4194 | 68 | // bool use_all_names() const {return use_all_names_;} | 70 | // bool use_all_names() const {return use_all_names_;} |
4195 | 69 | 71 | ||
4197 | 70 | DCCLCppType type() {return type_;} | 72 | DCCLCppType type() {return type_;} |
4198 | 71 | // std::vector<std::string> const& names() {return names_;} | 73 | // std::vector<std::string> const& names() {return names_;} |
4199 | 72 | // std::vector<std::vector<std::string> > const& algorithms(){return algorithms_;} | 74 | // std::vector<std::vector<std::string> > const& algorithms(){return algorithms_;} |
4200 | 73 | 75 | ||
4201 | 74 | 76 | ||
4217 | 75 | std::string get_display() const; | 77 | std::string get_display() const; |
4218 | 76 | 78 | ||
4219 | 77 | void write_publish(const std::map<std::string,std::vector<MessageVal> >& vals, | 79 | void write_publish(const std::map<std::string,std::vector<DCCLMessageVal> >& vals, |
4220 | 78 | std::multimap<std::string,MessageVal>& pubsub_vals); | 80 | std::multimap<std::string,DCCLMessageVal>& pubsub_vals); |
4221 | 79 | 81 | ||
4222 | 80 | 82 | ||
4223 | 81 | 83 | ||
4224 | 82 | 84 | ||
4225 | 83 | void initialize(Message& msg); | 85 | void initialize(DCCLMessage& msg); |
4226 | 84 | 86 | ||
4227 | 85 | private: | 87 | private: |
4228 | 86 | void fill_format(const std::map<std::string,std::vector<MessageVal> >& vals, | 88 | void fill_format(const std::map<std::string,std::vector<DCCLMessageVal> >& vals, |
4229 | 87 | std::string& key, | 89 | std::string& key, |
4230 | 88 | std::string& value, | 90 | std::string& value, |
4231 | 89 | unsigned repeat_index); | 91 | unsigned repeat_index); |
4232 | 90 | 92 | ||
4245 | 91 | private: | 93 | private: |
4246 | 92 | std::string var_; | 94 | std::string var_; |
4247 | 93 | std::string format_; | 95 | std::string format_; |
4248 | 94 | bool format_set_; | 96 | bool format_set_; |
4249 | 95 | bool use_all_names_; | 97 | bool use_all_names_; |
4250 | 96 | DCCLCppType type_; | 98 | DCCLCppType type_; |
4251 | 97 | std::vector<std::string> names_; | 99 | std::vector<std::string> names_; |
4252 | 98 | std::vector<boost::shared_ptr<MessageVar> > message_vars_; | 100 | std::vector<boost::shared_ptr<DCCLMessageVar> > message_vars_; |
4253 | 99 | std::vector< std::vector<std::string> > algorithms_; | 101 | std::vector< std::vector<std::string> > algorithms_; |
4254 | 100 | AlgorithmPerformer* ap_; | 102 | DCCLAlgorithmPerformer* ap_; |
4255 | 101 | unsigned repeat_; | 103 | unsigned repeat_; |
4256 | 102 | }; | 104 | }; |
4257 | 103 | 105 | ||
4259 | 104 | std::ostream& operator<< (std::ostream& out, const Publish& publish); | 106 | std::ostream& operator<< (std::ostream& out, const DCCLPublish& publish); |
4260 | 107 | } | ||
4261 | 105 | } | 108 | } |
4262 | 106 | |||
4263 | 107 | #endif | 109 | #endif |
4264 | 108 | 110 | ||
4265 | === modified file 'src/acomms/libdccl/message_val.cpp' | |||
4266 | --- src/acomms/libdccl/message_val.cpp 2010-07-13 01:57:57 +0000 | |||
4267 | +++ src/acomms/libdccl/message_val.cpp 2010-07-15 12:38:39 +0000 | |||
4268 | @@ -17,13 +17,17 @@ | |||
4269 | 17 | // You should have received a copy of the GNU General Public License | 17 | // You should have received a copy of the GNU General Public License |
4270 | 18 | // along with this software. If not, see <http://www.gnu.org/licenses/>. | 18 | // along with this software. If not, see <http://www.gnu.org/licenses/>. |
4271 | 19 | 19 | ||
4273 | 20 | #include <exception> | 20 | #include <stdexcept> |
4274 | 21 | #include <iomanip> | ||
4275 | 21 | 22 | ||
4276 | 22 | #include <boost/foreach.hpp> | 23 | #include <boost/foreach.hpp> |
4277 | 23 | 24 | ||
4278 | 25 | #include "goby/util/string.h" | ||
4279 | 26 | #include "goby/util/sci.h" | ||
4280 | 27 | |||
4281 | 24 | #include "message_val.h" | 28 | #include "message_val.h" |
4282 | 25 | 29 | ||
4284 | 26 | void dccl::MessageVal::init() | 30 | void goby::acomms::DCCLMessageVal::init() |
4285 | 27 | { | 31 | { |
4286 | 28 | sval_ = ""; | 32 | sval_ = ""; |
4287 | 29 | dval_ = 0; | 33 | dval_ = 0; |
4288 | @@ -34,27 +38,27 @@ | |||
4289 | 34 | } | 38 | } |
4290 | 35 | 39 | ||
4291 | 36 | 40 | ||
4293 | 37 | dccl::MessageVal::MessageVal() | 41 | goby::acomms::DCCLMessageVal::DCCLMessageVal() |
4294 | 38 | { init(); } | 42 | { init(); } |
4295 | 39 | 43 | ||
4296 | 40 | 44 | ||
4314 | 41 | dccl::MessageVal::MessageVal(const std::string& s) | 45 | goby::acomms::DCCLMessageVal::DCCLMessageVal(const std::string& s) |
4315 | 42 | { | 46 | { |
4316 | 43 | init(); | 47 | init(); |
4317 | 44 | sval_ = s; | 48 | sval_ = s; |
4318 | 45 | type_ = cpp_string; | 49 | type_ = cpp_string; |
4319 | 46 | } | 50 | } |
4320 | 47 | 51 | ||
4321 | 48 | 52 | ||
4322 | 49 | dccl::MessageVal::MessageVal(const char* s) | 53 | goby::acomms::DCCLMessageVal::DCCLMessageVal(const char* s) |
4323 | 50 | { | 54 | { |
4324 | 51 | init(); | 55 | init(); |
4325 | 52 | sval_ = s; | 56 | sval_ = s; |
4326 | 53 | type_ = cpp_string; | 57 | type_ = cpp_string; |
4327 | 54 | } | 58 | } |
4328 | 55 | 59 | ||
4329 | 56 | 60 | ||
4330 | 57 | dccl::MessageVal::MessageVal(double d, int p /* = MAX_DBL_PRECISION*/ ) | 61 | goby::acomms::DCCLMessageVal::DCCLMessageVal(double d, int p /* = MAX_DBL_PRECISION*/ ) |
4331 | 58 | { | 62 | { |
4332 | 59 | init(); | 63 | init(); |
4333 | 60 | dval_ = d; | 64 | dval_ = d; |
4334 | @@ -62,28 +66,28 @@ | |||
4335 | 62 | type_ = cpp_double; | 66 | type_ = cpp_double; |
4336 | 63 | } | 67 | } |
4337 | 64 | 68 | ||
4339 | 65 | dccl::MessageVal::MessageVal(float f) | 69 | goby::acomms::DCCLMessageVal::DCCLMessageVal(float f) |
4340 | 66 | { | 70 | { |
4341 | 67 | init(); | 71 | init(); |
4342 | 68 | dval_ = f; | 72 | dval_ = f; |
4343 | 69 | type_ = cpp_double; | 73 | type_ = cpp_double; |
4344 | 70 | } | 74 | } |
4345 | 71 | 75 | ||
4347 | 72 | dccl::MessageVal::MessageVal(long l) | 76 | goby::acomms::DCCLMessageVal::DCCLMessageVal(long l) |
4348 | 73 | { | 77 | { |
4349 | 74 | init(); | 78 | init(); |
4350 | 75 | lval_ = l; | 79 | lval_ = l; |
4351 | 76 | type_ = cpp_long; | 80 | type_ = cpp_long; |
4352 | 77 | } | 81 | } |
4353 | 78 | 82 | ||
4355 | 79 | dccl::MessageVal::MessageVal(int i) | 83 | goby::acomms::DCCLMessageVal::DCCLMessageVal(int i) |
4356 | 80 | { | 84 | { |
4357 | 81 | init(); | 85 | init(); |
4358 | 82 | lval_ = i; | 86 | lval_ = i; |
4359 | 83 | type_ = cpp_long; | 87 | type_ = cpp_long; |
4360 | 84 | } | 88 | } |
4361 | 85 | 89 | ||
4363 | 86 | dccl::MessageVal::MessageVal(bool b) | 90 | goby::acomms::DCCLMessageVal::DCCLMessageVal(bool b) |
4364 | 87 | { | 91 | { |
4365 | 88 | init(); | 92 | init(); |
4366 | 89 | bval_ = b; | 93 | bval_ = b; |
4367 | @@ -91,26 +95,26 @@ | |||
4368 | 91 | } | 95 | } |
4369 | 92 | 96 | ||
4370 | 93 | 97 | ||
4372 | 94 | dccl::MessageVal::MessageVal(const std::vector<MessageVal>& vm) | 98 | goby::acomms::DCCLMessageVal::DCCLMessageVal(const std::vector<DCCLMessageVal>& vm) |
4373 | 95 | { | 99 | { |
4374 | 96 | if(vm.size() != 1) | 100 | if(vm.size() != 1) |
4376 | 97 | throw(std::runtime_error("vector cast to MessageVal failed: vector is not size 1")); | 101 | throw(std::runtime_error("vector cast to DCCLMessageVal failed: vector is not size 1")); |
4377 | 98 | else | 102 | else |
4378 | 99 | *this = vm[0]; | 103 | *this = vm[0]; |
4379 | 100 | } | 104 | } |
4380 | 101 | 105 | ||
4381 | 102 | 106 | ||
4383 | 103 | void dccl::MessageVal::set(std::string sval) | 107 | void goby::acomms::DCCLMessageVal::set(std::string sval) |
4384 | 104 | { sval_ = sval; type_ = cpp_string; } | 108 | { sval_ = sval; type_ = cpp_string; } |
4386 | 105 | void dccl::MessageVal::set(double dval, int precision /* = MAX_DBL_PRECISION */) | 109 | void goby::acomms::DCCLMessageVal::set(double dval, int precision /* = MAX_DBL_PRECISION */) |
4387 | 106 | { dval_ = dval; type_ = cpp_double; precision_ = precision; } | 110 | { dval_ = dval; type_ = cpp_double; precision_ = precision; } |
4389 | 107 | void dccl::MessageVal::set(long lval) | 111 | void goby::acomms::DCCLMessageVal::set(long lval) |
4390 | 108 | { lval_ = lval; type_ = cpp_long; } | 112 | { lval_ = lval; type_ = cpp_long; } |
4392 | 109 | void dccl::MessageVal::set(bool bval) | 113 | void goby::acomms::DCCLMessageVal::set(bool bval) |
4393 | 110 | { bval_ = bval; type_ = cpp_bool; } | 114 | { bval_ = bval; type_ = cpp_bool; } |
4394 | 111 | 115 | ||
4395 | 112 | 116 | ||
4397 | 113 | bool dccl::MessageVal::get(std::string& s) const | 117 | bool goby::acomms::DCCLMessageVal::get(std::string& s) const |
4398 | 114 | { | 118 | { |
4399 | 115 | std::stringstream ss; | 119 | std::stringstream ss; |
4400 | 116 | switch(type_) | 120 | switch(type_) |
4401 | @@ -141,14 +145,14 @@ | |||
4402 | 141 | } | 145 | } |
4403 | 142 | } | 146 | } |
4404 | 143 | 147 | ||
4406 | 144 | bool dccl::MessageVal::get(bool& b) const | 148 | bool goby::acomms::DCCLMessageVal::get(bool& b) const |
4407 | 145 | { | 149 | { |
4408 | 146 | switch(type_) | 150 | switch(type_) |
4409 | 147 | { | 151 | { |
4410 | 148 | case cpp_string: | 152 | case cpp_string: |
4412 | 149 | if(tes_util::stricmp(sval_, "true") || tes_util::stricmp(sval_, "1")) | 153 | if(util::stricmp(sval_, "true") || util::stricmp(sval_, "1")) |
4413 | 150 | b = true; | 154 | b = true; |
4415 | 151 | else if(tes_util::stricmp(sval_, "false") || tes_util::stricmp(sval_, "0")) | 155 | else if(util::stricmp(sval_, "false") || util::stricmp(sval_, "0")) |
4416 | 152 | b = false; | 156 | b = false; |
4417 | 153 | else | 157 | else |
4418 | 154 | return false; | 158 | return false; |
4419 | @@ -173,7 +177,7 @@ | |||
4420 | 173 | } | 177 | } |
4421 | 174 | } | 178 | } |
4422 | 175 | 179 | ||
4424 | 176 | bool dccl::MessageVal::get(long& t) const | 180 | bool goby::acomms::DCCLMessageVal::get(long& t) const |
4425 | 177 | { | 181 | { |
4426 | 178 | switch(type_) | 182 | switch(type_) |
4427 | 179 | { | 183 | { |
4428 | @@ -181,13 +185,13 @@ | |||
4429 | 181 | try | 185 | try |
4430 | 182 | { | 186 | { |
4431 | 183 | double d = boost::lexical_cast<double>(sval_); | 187 | double d = boost::lexical_cast<double>(sval_); |
4433 | 184 | t = boost::numeric_cast<long>(tes_util::sci_round(d, 0)); | 188 | t = boost::numeric_cast<long>(util::unbiased_round(d, 0)); |
4434 | 185 | } | 189 | } |
4435 | 186 | catch (...) | 190 | catch (...) |
4436 | 187 | { | 191 | { |
4438 | 188 | if(tes_util::stricmp(sval_, "true")) | 192 | if(util::stricmp(sval_, "true")) |
4439 | 189 | t = 1; | 193 | t = 1; |
4441 | 190 | else if(tes_util::stricmp(sval_, "false")) | 194 | else if(util::stricmp(sval_, "false")) |
4442 | 191 | t = 0; | 195 | t = 0; |
4443 | 192 | else | 196 | else |
4444 | 193 | return false; | 197 | return false; |
4445 | @@ -195,7 +199,7 @@ | |||
4446 | 195 | return true; | 199 | return true; |
4447 | 196 | 200 | ||
4448 | 197 | case cpp_double: | 201 | case cpp_double: |
4450 | 198 | try { t = boost::numeric_cast<long>(tes_util::sci_round(dval_, 0)); } | 202 | try { t = boost::numeric_cast<long>(util::unbiased_round(dval_, 0)); } |
4451 | 199 | catch(...) { return false; } | 203 | catch(...) { return false; } |
4452 | 200 | return true; | 204 | return true; |
4453 | 201 | 205 | ||
4454 | @@ -212,7 +216,7 @@ | |||
4455 | 212 | } | 216 | } |
4456 | 213 | } | 217 | } |
4457 | 214 | 218 | ||
4459 | 215 | bool dccl::MessageVal::get(double& d) const | 219 | bool goby::acomms::DCCLMessageVal::get(double& d) const |
4460 | 216 | { | 220 | { |
4461 | 217 | switch(type_) | 221 | switch(type_) |
4462 | 218 | { | 222 | { |
4463 | @@ -220,9 +224,9 @@ | |||
4464 | 220 | try { d = boost::lexical_cast<double>(sval_); } | 224 | try { d = boost::lexical_cast<double>(sval_); } |
4465 | 221 | catch (boost::bad_lexical_cast &) | 225 | catch (boost::bad_lexical_cast &) |
4466 | 222 | { | 226 | { |
4468 | 223 | if(tes_util::stricmp(sval_, "true")) | 227 | if(util::stricmp(sval_, "true")) |
4469 | 224 | d = 1; | 228 | d = 1; |
4471 | 225 | else if(tes_util::stricmp(sval_, "false")) | 229 | else if(util::stricmp(sval_, "false")) |
4472 | 226 | d = 0; | 230 | d = 0; |
4473 | 227 | else | 231 | else |
4474 | 228 | return false; | 232 | return false; |
4475 | @@ -251,7 +255,7 @@ | |||
4476 | 251 | 255 | ||
4477 | 252 | 256 | ||
4478 | 253 | 257 | ||
4480 | 254 | dccl::MessageVal::operator double() const | 258 | goby::acomms::DCCLMessageVal::operator double() const |
4481 | 255 | { | 259 | { |
4482 | 256 | double d; | 260 | double d; |
4483 | 257 | if(get(d)) return d; | 261 | if(get(d)) return d; |
4484 | @@ -259,48 +263,48 @@ | |||
4485 | 259 | } | 263 | } |
4486 | 260 | 264 | ||
4487 | 261 | 265 | ||
4489 | 262 | dccl::MessageVal::operator bool() const | 266 | goby::acomms::DCCLMessageVal::operator bool() const |
4490 | 263 | { | 267 | { |
4491 | 264 | bool b; | 268 | bool b; |
4492 | 265 | if(get(b)) return b; | 269 | if(get(b)) return b; |
4493 | 266 | else return false; | 270 | else return false; |
4494 | 267 | } | 271 | } |
4495 | 268 | 272 | ||
4497 | 269 | dccl::MessageVal::operator std::string() const | 273 | goby::acomms::DCCLMessageVal::operator std::string() const |
4498 | 270 | { | 274 | { |
4499 | 271 | std::string s; | 275 | std::string s; |
4500 | 272 | if(get(s)) return s; | 276 | if(get(s)) return s; |
4501 | 273 | else return ""; | 277 | else return ""; |
4502 | 274 | } | 278 | } |
4503 | 275 | 279 | ||
4505 | 276 | dccl::MessageVal::operator long() const | 280 | goby::acomms::DCCLMessageVal::operator long() const |
4506 | 277 | { | 281 | { |
4507 | 278 | long l; | 282 | long l; |
4508 | 279 | if(get(l)) return l; | 283 | if(get(l)) return l; |
4509 | 280 | else return 0; | 284 | else return 0; |
4510 | 281 | } | 285 | } |
4511 | 282 | 286 | ||
4523 | 283 | dccl::MessageVal::operator int() const | 287 | goby::acomms::DCCLMessageVal::operator int() const |
4524 | 284 | { | 288 | { |
4525 | 285 | return long(*this); | 289 | return long(*this); |
4526 | 286 | } | 290 | } |
4527 | 287 | 291 | ||
4528 | 288 | dccl::MessageVal::operator unsigned() const | 292 | goby::acomms::DCCLMessageVal::operator unsigned() const |
4529 | 289 | { | 293 | { |
4530 | 290 | return long(*this); | 294 | return long(*this); |
4531 | 291 | } | 295 | } |
4532 | 292 | 296 | ||
4533 | 293 | dccl::MessageVal::operator float() const | 297 | goby::acomms::DCCLMessageVal::operator float() const |
4534 | 294 | { | 298 | { |
4535 | 295 | return double(*this); | 299 | return double(*this); |
4536 | 296 | } | 300 | } |
4537 | 297 | 301 | ||
4539 | 298 | dccl::MessageVal::operator std::vector<MessageVal>() const | 302 | goby::acomms::DCCLMessageVal::operator std::vector<DCCLMessageVal>() const |
4540 | 299 | { | 303 | { |
4542 | 300 | return std::vector<MessageVal>(1, *this); | 304 | return std::vector<DCCLMessageVal>(1, *this); |
4543 | 301 | } | 305 | } |
4544 | 302 | 306 | ||
4546 | 303 | bool dccl::MessageVal::operator==(const MessageVal& mv) const | 307 | bool goby::acomms::DCCLMessageVal::operator==(const DCCLMessageVal& mv) const |
4547 | 304 | { | 308 | { |
4548 | 305 | switch(mv.type_) | 309 | switch(mv.type_) |
4549 | 306 | { | 310 | { |
4550 | @@ -312,25 +316,25 @@ | |||
4551 | 312 | } | 316 | } |
4552 | 313 | } | 317 | } |
4553 | 314 | 318 | ||
4555 | 315 | bool dccl::MessageVal::operator==(const std::string& s) const | 319 | bool goby::acomms::DCCLMessageVal::operator==(const std::string& s) const |
4556 | 316 | { | 320 | { |
4557 | 317 | std::string us; | 321 | std::string us; |
4558 | 318 | return get(us) && us == s; | 322 | return get(us) && us == s; |
4559 | 319 | } | 323 | } |
4560 | 320 | 324 | ||
4562 | 321 | bool dccl::MessageVal::operator==(double d) const | 325 | bool goby::acomms::DCCLMessageVal::operator==(double d) const |
4563 | 322 | { | 326 | { |
4564 | 323 | double us; | 327 | double us; |
4565 | 324 | return get(us) && us == d; | 328 | return get(us) && us == d; |
4566 | 325 | } | 329 | } |
4567 | 326 | 330 | ||
4569 | 327 | bool dccl::MessageVal::operator==(long l) const | 331 | bool goby::acomms::DCCLMessageVal::operator==(long l) const |
4570 | 328 | { | 332 | { |
4571 | 329 | long us; | 333 | long us; |
4572 | 330 | return get(us) && us == l; | 334 | return get(us) && us == l; |
4573 | 331 | } | 335 | } |
4574 | 332 | 336 | ||
4576 | 333 | bool dccl::MessageVal::operator==(bool b) const | 337 | bool goby::acomms::DCCLMessageVal::operator==(bool b) const |
4577 | 334 | { | 338 | { |
4578 | 335 | bool us; | 339 | bool us; |
4579 | 336 | return get(us) && us == b; | 340 | return get(us) && us == b; |
4580 | @@ -338,7 +342,7 @@ | |||
4581 | 338 | 342 | ||
4582 | 339 | 343 | ||
4583 | 340 | 344 | ||
4585 | 341 | std::ostream& dccl::operator<<(std::ostream& os, const dccl::MessageVal& mv) | 345 | std::ostream& goby::acomms::operator<<(std::ostream& os, const goby::acomms::DCCLMessageVal& mv) |
4586 | 342 | { | 346 | { |
4587 | 343 | switch(mv.type_) | 347 | switch(mv.type_) |
4588 | 344 | { | 348 | { |
4589 | @@ -351,10 +355,10 @@ | |||
4590 | 351 | } | 355 | } |
4591 | 352 | 356 | ||
4592 | 353 | 357 | ||
4594 | 354 | std::ostream& dccl::operator<<(std::ostream& os, const std::vector<dccl::MessageVal>& vm) | 358 | std::ostream& goby::acomms::operator<<(std::ostream& os, const std::vector<goby::acomms::DCCLMessageVal>& vm) |
4595 | 355 | { | 359 | { |
4596 | 356 | int j=0; | 360 | int j=0; |
4598 | 357 | BOOST_FOREACH(const dccl::MessageVal& m, vm) | 361 | BOOST_FOREACH(const DCCLMessageVal& m, vm) |
4599 | 358 | { | 362 | { |
4600 | 359 | if(j) os << ","; | 363 | if(j) os << ","; |
4601 | 360 | os << m; | 364 | os << m; |
4602 | 361 | 365 | ||
4603 | === modified file 'src/acomms/libdccl/message_val.h' | |||
4604 | --- src/acomms/libdccl/message_val.h 2010-06-15 04:51:47 +0000 | |||
4605 | +++ src/acomms/libdccl/message_val.h 2010-07-15 12:38:39 +0000 | |||
4606 | @@ -25,157 +25,158 @@ | |||
4607 | 25 | #include <boost/numeric/conversion/cast.hpp> | 25 | #include <boost/numeric/conversion/cast.hpp> |
4608 | 26 | #include <boost/lexical_cast.hpp> | 26 | #include <boost/lexical_cast.hpp> |
4609 | 27 | 27 | ||
4610 | 28 | #include "util/tes_utils.h" | ||
4611 | 29 | #include "dccl_constants.h" | 28 | #include "dccl_constants.h" |
4612 | 30 | 29 | ||
4614 | 31 | namespace dccl | 30 | namespace goby |
4615 | 32 | { | 31 | { |
4616 | 32 | namespace acomms | ||
4617 | 33 | { | ||
4618 | 33 | 34 | ||
4619 | 34 | /// defines a DCCL value | 35 | /// defines a DCCL value |
4730 | 35 | class MessageVal | 36 | class DCCLMessageVal |
4731 | 36 | { | 37 | { |
4732 | 37 | public: | 38 | public: |
4733 | 38 | enum { MAX_DBL_PRECISION = 15 }; | 39 | enum { MAX_DBL_PRECISION = 15 }; |
4734 | 39 | 40 | ||
4735 | 40 | /// \name Constructors/Destructor | 41 | /// \name Constructors/Destructor |
4736 | 41 | //@{ | 42 | //@{ |
4737 | 42 | /// empty | 43 | /// empty |
4738 | 43 | MessageVal(); | 44 | DCCLMessageVal(); |
4739 | 44 | 45 | ||
4740 | 45 | /// construct with string value | 46 | /// construct with string value |
4741 | 46 | MessageVal(const std::string& s); | 47 | DCCLMessageVal(const std::string& s); |
4742 | 47 | 48 | ||
4743 | 48 | /// construct with char* value | 49 | /// construct with char* value |
4744 | 49 | MessageVal(const char* s); | 50 | DCCLMessageVal(const char* s); |
4745 | 50 | 51 | ||
4746 | 51 | /// construct with double value, optionally giving the precision of the double (number of decimal places) which is used if a cast to std::string is required in the future. | 52 | /// construct with double value, optionally giving the precision of the double (number of decimal places) which is used if a cast to std::string is required in the future. |
4747 | 52 | MessageVal(double d, int p = MAX_DBL_PRECISION); | 53 | DCCLMessageVal(double d, int p = MAX_DBL_PRECISION); |
4748 | 53 | 54 | ||
4749 | 54 | /// construct with long value | 55 | /// construct with long value |
4750 | 55 | MessageVal(long l); | 56 | DCCLMessageVal(long l); |
4751 | 56 | 57 | ||
4752 | 57 | /// construct with int value | 58 | /// construct with int value |
4753 | 58 | MessageVal(int i); | 59 | DCCLMessageVal(int i); |
4754 | 59 | 60 | ||
4755 | 60 | /// construct with float value | 61 | /// construct with float value |
4756 | 61 | MessageVal(float f); | 62 | DCCLMessageVal(float f); |
4757 | 62 | 63 | ||
4758 | 63 | /// construct with bool value | 64 | /// construct with bool value |
4759 | 64 | MessageVal(bool b); | 65 | DCCLMessageVal(bool b); |
4760 | 65 | 66 | ||
4761 | 66 | /// construct with vector | 67 | /// construct with vector |
4762 | 67 | MessageVal(const std::vector<MessageVal>& vm); | 68 | DCCLMessageVal(const std::vector<DCCLMessageVal>& vm); |
4763 | 68 | 69 | ||
4764 | 69 | 70 | ||
4765 | 70 | 71 | ||
4766 | 71 | //@} | 72 | //@} |
4767 | 72 | 73 | ||
4768 | 73 | /// \name Setters | 74 | /// \name Setters |
4769 | 74 | //@{ | 75 | //@{ |
4770 | 75 | /// set the value with a string (overwrites previous value regardless of type) | 76 | /// set the value with a string (overwrites previous value regardless of type) |
4771 | 76 | void set(std::string sval); | 77 | void set(std::string sval); |
4772 | 77 | /// \brief set the value with a double (overwrites previous value regardless of type) | 78 | /// \brief set the value with a double (overwrites previous value regardless of type) |
4773 | 78 | /// \param dval values to set | 79 | /// \param dval values to set |
4774 | 79 | /// \param precision decimal places of precision to preserve if this is cast to a string | 80 | /// \param precision decimal places of precision to preserve if this is cast to a string |
4775 | 80 | void set(double dval, int precision = MAX_DBL_PRECISION); | 81 | void set(double dval, int precision = MAX_DBL_PRECISION); |
4776 | 81 | /// set the value with a long (overwrites previous value regardless of type) | 82 | /// set the value with a long (overwrites previous value regardless of type) |
4777 | 82 | void set(long lval); | 83 | void set(long lval); |
4778 | 83 | /// set the value with a bool (overwrites previous value regardless of type) | 84 | /// set the value with a bool (overwrites previous value regardless of type) |
4779 | 84 | void set(bool bval); | 85 | void set(bool bval); |
4780 | 85 | 86 | ||
4781 | 86 | //@} | 87 | //@} |
4782 | 87 | 88 | ||
4783 | 88 | /// \name Getters | 89 | /// \name Getters |
4784 | 89 | //@{ | 90 | //@{ |
4785 | 90 | /// \brief extract as std::string (all reasonable casts are done) | 91 | /// \brief extract as std::string (all reasonable casts are done) |
4786 | 91 | /// \param s std::string to store value in | 92 | /// \param s std::string to store value in |
4787 | 92 | /// \return successfully extracted (and if necessary successfully cast to this type) | 93 | /// \return successfully extracted (and if necessary successfully cast to this type) |
4788 | 93 | bool get(std::string& s) const; | 94 | bool get(std::string& s) const; |
4789 | 94 | /// \brief extract as bool (all reasonable casts are done) | 95 | /// \brief extract as bool (all reasonable casts are done) |
4790 | 95 | /// \param b bool to store value in | 96 | /// \param b bool to store value in |
4791 | 96 | /// \return successfully extracted (and if necessary successfully cast to this type) | 97 | /// \return successfully extracted (and if necessary successfully cast to this type) |
4792 | 97 | bool get(bool& b) const; | 98 | bool get(bool& b) const; |
4793 | 98 | /// \brief extract as long (all reasonable casts are done) | 99 | /// \brief extract as long (all reasonable casts are done) |
4794 | 99 | /// \param t long to store value in | 100 | /// \param t long to store value in |
4795 | 100 | /// \return successfully extracted (and if necessary successfully cast to this type) | 101 | /// \return successfully extracted (and if necessary successfully cast to this type) |
4796 | 101 | bool get(long& t) const; | 102 | bool get(long& t) const; |
4797 | 102 | /// \brief extract as double (all reasonable casts are done) | 103 | /// \brief extract as double (all reasonable casts are done) |
4798 | 103 | /// \param d double to store value in | 104 | /// \param d double to store value in |
4799 | 104 | /// \return successfully extracted (and if necessary successfully cast to this type) | 105 | /// \return successfully extracted (and if necessary successfully cast to this type) |
4800 | 105 | bool get(double& d) const; | 106 | bool get(double& d) const; |
4801 | 106 | 107 | ||
4802 | 107 | /// | 108 | /// |
4803 | 108 | /// allows statements of the form \code double d = MessageVal("3.23"); \endcode | 109 | /// allows statements of the form \code double d = DCCLMessageVal("3.23"); \endcode |
4804 | 109 | operator double() const; | 110 | operator double() const; |
4805 | 110 | 111 | ||
4806 | 111 | /// | 112 | /// |
4807 | 112 | /// allows statements of the form \code bool b = MessageVal("1"); \endcode | 113 | /// allows statements of the form \code bool b = DCCLMessageVal("1"); \endcode |
4808 | 113 | operator bool() const; | 114 | operator bool() const; |
4809 | 114 | 115 | ||
4810 | 115 | /// | 116 | /// |
4811 | 116 | /// allows statements of the form \code std::string s = MessageVal(3); \endcode | 117 | /// allows statements of the form \code std::string s = DCCLMessageVal(3); \endcode |
4812 | 117 | operator std::string() const; | 118 | operator std::string() const; |
4813 | 118 | 119 | ||
4814 | 119 | /// | 120 | /// |
4815 | 120 | /// allows statements of the form \code long l = MessageVal(5); \endcode | 121 | /// allows statements of the form \code long l = DCCLMessageVal(5); \endcode |
4816 | 121 | operator long() const; | 122 | operator long() const; |
4817 | 122 | 123 | ||
4818 | 123 | /// | 124 | /// |
4819 | 124 | /// allows statements of the form \code int i = MessageVal(2); \endcode | 125 | /// allows statements of the form \code int i = DCCLMessageVal(2); \endcode |
4820 | 125 | operator int() const; | 126 | operator int() const; |
4821 | 126 | 127 | ||
4822 | 127 | /// | 128 | /// |
4823 | 128 | /// allows statements of the form \code unsigned u = MessageVal(2); \endcode | 129 | /// allows statements of the form \code unsigned u = DCCLMessageVal(2); \endcode |
4824 | 129 | operator unsigned() const; | 130 | operator unsigned() const; |
4825 | 130 | 131 | ||
4826 | 131 | /// | 132 | /// |
4827 | 132 | /// allows statements of the form \code float f = MessageVal("3.5"); \endcode | 133 | /// allows statements of the form \code float f = DCCLMessageVal("3.5"); \endcode |
4828 | 133 | operator float() const; | 134 | operator float() const; |
4829 | 134 | 135 | ||
4830 | 135 | operator std::vector<MessageVal>() const; | 136 | operator std::vector<DCCLMessageVal>() const; |
4831 | 136 | 137 | ||
4832 | 137 | 138 | ||
4833 | 138 | /// what type is the original type of this MessageVal? | 139 | /// what type is the original type of this DCCLMessageVal? |
4834 | 139 | DCCLCppType type() const { return type_; } | 140 | DCCLCppType type() const { return type_; } |
4835 | 140 | 141 | ||
4836 | 141 | /// was this just constructed with MessageVal() ? | 142 | /// was this just constructed with DCCLMessageVal() ? |
4837 | 142 | bool empty() const { return type_ == cpp_notype; } | 143 | bool empty() const { return type_ == cpp_notype; } |
4838 | 143 | 144 | ||
4839 | 144 | unsigned precision() const { return precision_; } | 145 | unsigned precision() const { return precision_; } |
4840 | 145 | 146 | ||
4841 | 146 | //@} | 147 | //@} |
4842 | 147 | 148 | ||
4843 | 148 | 149 | ||
4872 | 149 | /// \name Comparison | 150 | /// \name Comparison |
4873 | 150 | //@{ | 151 | //@{ |
4874 | 151 | bool operator==(const MessageVal& mv) const; | 152 | bool operator==(const DCCLMessageVal& mv) const; |
4875 | 152 | bool operator==(const std::string& s) const; | 153 | bool operator==(const std::string& s) const; |
4876 | 153 | bool operator==(double d) const; | 154 | bool operator==(double d) const; |
4877 | 154 | bool operator==(long l) const; | 155 | bool operator==(long l) const; |
4878 | 155 | bool operator==(bool b) const; | 156 | bool operator==(bool b) const; |
4879 | 156 | 157 | ||
4880 | 157 | // @} | 158 | // @} |
4881 | 158 | 159 | ||
4882 | 159 | private: | 160 | private: |
4883 | 160 | void init(); | 161 | void init(); |
4884 | 161 | 162 | ||
4885 | 162 | friend std::ostream& operator<<(std::ostream& os, const MessageVal& mv); | 163 | friend std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv); |
4886 | 163 | 164 | ||
4887 | 164 | private: | 165 | private: |
4888 | 165 | std::string sval_; | 166 | std::string sval_; |
4889 | 166 | double dval_; | 167 | double dval_; |
4890 | 167 | long lval_; | 168 | long lval_; |
4891 | 168 | bool bval_; | 169 | bool bval_; |
4892 | 169 | 170 | ||
4893 | 170 | unsigned precision_; | 171 | unsigned precision_; |
4894 | 171 | 172 | ||
4895 | 172 | DCCLCppType type_; | 173 | DCCLCppType type_; |
4896 | 173 | }; | 174 | }; |
4897 | 174 | 175 | ||
4898 | 175 | std::ostream& operator<<(std::ostream& os, const dccl::MessageVal& mv); | 176 | std::ostream& operator<<(std::ostream& os, const acomms::DCCLMessageVal& mv); |
4899 | 176 | std::ostream& operator<<(std::ostream& os, const std::vector<dccl::MessageVal>& vm); | 177 | std::ostream& operator<<(std::ostream& os, const std::vector<acomms::DCCLMessageVal>& vm); |
4900 | 178 | } | ||
4901 | 179 | |||
4902 | 177 | } | 180 | } |
4903 | 178 | 181 | ||
4904 | 179 | |||
4905 | 180 | |||
4906 | 181 | #endif | 182 | #endif |
4907 | 182 | 183 | ||
4908 | === modified file 'src/acomms/libdccl/message_var.cpp' | |||
4909 | --- src/acomms/libdccl/message_var.cpp 2010-06-15 04:51:47 +0000 | |||
4910 | +++ src/acomms/libdccl/message_var.cpp 2010-07-15 12:38:39 +0000 | |||
4911 | @@ -19,21 +19,21 @@ | |||
4912 | 19 | 19 | ||
4913 | 20 | #include <boost/foreach.hpp> | 20 | #include <boost/foreach.hpp> |
4914 | 21 | 21 | ||
4916 | 22 | #include "util/tes_utils.h" | 22 | #include "goby/util/string.h" |
4917 | 23 | 23 | ||
4918 | 24 | #include "message_var.h" | 24 | #include "message_var.h" |
4919 | 25 | #include "message_val.h" | 25 | #include "message_val.h" |
4920 | 26 | #include "dccl_constants.h" | 26 | #include "dccl_constants.h" |
4921 | 27 | #include "message_algorithms.h" | 27 | #include "message_algorithms.h" |
4922 | 28 | 28 | ||
4924 | 29 | dccl::MessageVar::MessageVar() | 29 | goby::acomms::DCCLMessageVar::DCCLMessageVar() |
4925 | 30 | : array_length_(1), | 30 | : array_length_(1), |
4926 | 31 | is_key_frame_(true), | 31 | is_key_frame_(true), |
4927 | 32 | source_set_(false), | 32 | source_set_(false), |
4929 | 33 | ap_(AlgorithmPerformer::getInstance()) | 33 | ap_(DCCLAlgorithmPerformer::getInstance()) |
4930 | 34 | { } | 34 | { } |
4931 | 35 | 35 | ||
4933 | 36 | void dccl::MessageVar::initialize(const std::string& trigger_var) | 36 | void goby::acomms::DCCLMessageVar::initialize(const std::string& trigger_var) |
4934 | 37 | { | 37 | { |
4935 | 38 | // add trigger_var_ as source_var for any message_vars without a source | 38 | // add trigger_var_ as source_var for any message_vars without a source |
4936 | 39 | if(!source_set_) | 39 | if(!source_set_) |
4937 | @@ -43,30 +43,30 @@ | |||
4938 | 43 | 43 | ||
4939 | 44 | } | 44 | } |
4940 | 45 | 45 | ||
4942 | 46 | void dccl::MessageVar::set_defaults(std::map<std::string,std::vector<MessageVal> >& vals, unsigned modem_id, unsigned id) | 46 | void goby::acomms::DCCLMessageVar::set_defaults(std::map<std::string,std::vector<DCCLMessageVal> >& vals, unsigned modem_id, unsigned id) |
4943 | 47 | { | 47 | { |
4944 | 48 | vals[name_].resize(array_length_); | 48 | vals[name_].resize(array_length_); |
4945 | 49 | 49 | ||
4947 | 50 | std::vector<MessageVal>& vm = vals[name_]; | 50 | std::vector<DCCLMessageVal>& vm = vals[name_]; |
4948 | 51 | 51 | ||
4950 | 52 | for(std::vector<MessageVal>::size_type i = 0, n = vm.size(); i < n; ++i) | 52 | for(std::vector<DCCLMessageVal>::size_type i = 0, n = vm.size(); i < n; ++i) |
4951 | 53 | set_defaults_specific(vm[i], modem_id, id); | 53 | set_defaults_specific(vm[i], modem_id, id); |
4952 | 54 | 54 | ||
4953 | 55 | } | 55 | } |
4954 | 56 | 56 | ||
4955 | 57 | 57 | ||
4957 | 58 | void dccl::MessageVar::var_encode(std::map<std::string,std::vector<MessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits) | 58 | void goby::acomms::DCCLMessageVar::var_encode(std::map<std::string,std::vector<DCCLMessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits) |
4958 | 59 | { | 59 | { |
4960 | 60 | // ensure that every MessageVar has the full number of (maybe blank) MessageVals | 60 | // ensure that every DCCLMessageVar has the full number of (maybe blank) DCCLMessageVals |
4961 | 61 | vals[name_].resize(array_length_); | 61 | vals[name_].resize(array_length_); |
4962 | 62 | 62 | ||
4963 | 63 | // copy so algorithms can modify directly and not affect other algorithms' use of original values | 63 | // copy so algorithms can modify directly and not affect other algorithms' use of original values |
4965 | 64 | std::vector<MessageVal> vm = vals[name_]; | 64 | std::vector<DCCLMessageVal> vm = vals[name_]; |
4966 | 65 | 65 | ||
4967 | 66 | // write all the delta values first | 66 | // write all the delta values first |
4968 | 67 | is_key_frame_ = false; | 67 | is_key_frame_ = false; |
4969 | 68 | 68 | ||
4971 | 69 | for(std::vector<MessageVal>::size_type i = 0, n = vm.size(); i < n; ++i) | 69 | for(std::vector<DCCLMessageVal>::size_type i = 0, n = vm.size(); i < n; ++i) |
4972 | 70 | { | 70 | { |
4973 | 71 | for(std::vector<std::string>::size_type j = 0, m = algorithms_.size(); j < m; ++j) | 71 | for(std::vector<std::string>::size_type j = 0, m = algorithms_.size(); j < m; ++j) |
4974 | 72 | ap_->algorithm(vm[i], i, algorithms_[j], vals); | 72 | ap_->algorithm(vm[i], i, algorithms_[j], vals); |
4975 | @@ -83,7 +83,7 @@ | |||
4976 | 83 | encode_value(key_val_, bits); | 83 | encode_value(key_val_, bits); |
4977 | 84 | } | 84 | } |
4978 | 85 | 85 | ||
4980 | 86 | void dccl::MessageVar::encode_value(const MessageVal& val, boost::dynamic_bitset<unsigned char>& bits) | 86 | void goby::acomms::DCCLMessageVar::encode_value(const DCCLMessageVal& val, boost::dynamic_bitset<unsigned char>& bits) |
4981 | 87 | { | 87 | { |
4982 | 88 | bits <<= calc_size(); | 88 | bits <<= calc_size(); |
4983 | 89 | 89 | ||
4984 | @@ -94,7 +94,7 @@ | |||
4985 | 94 | } | 94 | } |
4986 | 95 | 95 | ||
4987 | 96 | 96 | ||
4989 | 97 | void dccl::MessageVar::var_decode(std::map<std::string,std::vector<MessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits) | 97 | void goby::acomms::DCCLMessageVar::var_decode(std::map<std::string,std::vector<DCCLMessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits) |
4990 | 98 | { | 98 | { |
4991 | 99 | vals[name_].resize(array_length_); | 99 | vals[name_].resize(array_length_); |
4992 | 100 | 100 | ||
4993 | @@ -106,7 +106,7 @@ | |||
4994 | 106 | boost::dynamic_bitset<unsigned char> remove_bits = bits; | 106 | boost::dynamic_bitset<unsigned char> remove_bits = bits; |
4995 | 107 | remove_bits.resize(calc_size()); | 107 | remove_bits.resize(calc_size()); |
4996 | 108 | 108 | ||
4998 | 109 | MessageVal val = decode_specific(remove_bits); | 109 | DCCLMessageVal val = decode_specific(remove_bits); |
4999 | 110 | 110 | ||
5000 | 111 | bits >>= calc_size(); | 111 | bits >>= calc_size(); |
1) util/time.h still #includes <ctime>, but compiles fine without it. Probably okay to remove it, or is there a dependency I didn't see?
2) seems reasonable to me. I'll probably just do a 'using namespace goby' 99% of the time, but I can live with that. Consistent naming is a good thing.
3) looks good from a quick review.
4) did not review.
5) agreed.
- c