Merge lp:~tes/goby/time_fix into lp:goby/trunk

Proposed by toby schneider
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
Reviewer Review Type Date Requested Status
Chris Murphy Approve
Review via email: mp+29948@code.launchpad.net

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/dccl.h" instead of #include "acomms/dccl.h". This reflects the structure for > make install (which puts headers in /usr/local/include/goby/...)

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.

To post a comment you must log in.
Revision history for this message
Chris Murphy (chrismurf) wrote :

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

review: Approve
Revision history for this message
Chris Murphy (chrismurf) wrote :

(In summary, looks good, I agree with the philosophy, but obviously didn't do a 100% code review).

lp:~tes/goby/time_fix updated
45. By toby <toby@eis>

fixed some Doxygen comments to reflect new namespaces

Revision history for this message
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2009-12-18 02:50:00 +0000
+++ CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -23,7 +23,7 @@
2323
24# set instructions for `make install`24# set instructions for `make install`
25install(DIRECTORY ${goby_BIN_DIR}/ DESTINATION /usr/local/bin FILE_PERMISSIONS WORLD_EXECUTE)25install(DIRECTORY ${goby_BIN_DIR}/ DESTINATION /usr/local/bin FILE_PERMISSIONS WORLD_EXECUTE)
26install(DIRECTORY ${goby_LIB_DIR}/ DESTINATION /usr/local/lib/goby)26install(DIRECTORY ${goby_LIB_DIR}/ DESTINATION /usr/local/lib)
27install(DIRECTORY ${goby_INC_DIR}/ DESTINATION /usr/local/include/goby)27install(DIRECTORY ${goby_INC_DIR}/ DESTINATION /usr/local/include/goby)
2828
29# find packages, libraries, and headers29# find packages, libraries, and headers
@@ -51,7 +51,7 @@
51# copy to goby/include51# copy to goby/include
52file(GLOB_RECURSE INCLUDE_FILES RELATIVE ${goby_SRC_DIR} src/*.h)52file(GLOB_RECURSE INCLUDE_FILES RELATIVE ${goby_SRC_DIR} src/*.h)
53foreach(I ${INCLUDE_FILES})53foreach(I ${INCLUDE_FILES})
54 configure_file(${goby_SRC_DIR}/${I} ${goby_INC_DIR}/${I})54 configure_file(${goby_SRC_DIR}/${I} ${goby_INC_DIR}/goby/${I})
55endforeach()55endforeach()
5656
57# let cmake know where the headers are57# let cmake know where the headers are
5858
=== modified file 'COPYING'
--- COPYING 2010-07-14 22:03:13 +0000
+++ COPYING 2010-07-15 12:38:39 +0000
@@ -2,8 +2,7 @@
2copying goby2copying goby
3~~~~~~~~~~~~3~~~~~~~~~~~~
44
5goby is copyright 2008, 2009 by5goby is copyright 2008, 2009, 2010 as listed in the individual header files.
6- t. schneider tes@mit.edu
76
8see header files of individual components for copyright details.7see header files of individual components for copyright details.
98
109
=== added file 'src/acomms.h'
--- src/acomms.h 1970-01-01 00:00:00 +0000
+++ src/acomms.h 2010-07-15 12:38:39 +0000
@@ -0,0 +1,31 @@
1// copyright 2010 t. schneider tes@mit.edu
2//
3// this file is part of goby-
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This software is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this software. If not, see <http://www.gnu.org/licenses/>.
17
18
19// courtesy header for all the goby acomms libraries
20
21#ifndef ACOMMSCOURTESY20100713H
22#define ACOMMSCOURTESY20100713H
23
24#include "goby/acomms/dccl.h"
25#include "goby/acomms/queue.h"
26#include "goby/acomms/bind.h"
27#include "goby/acomms/modem_driver.h"
28#include "goby/acomms/modem_message.h"
29#include "goby/acomms/amac.h"
30
31#endif
032
=== modified file 'src/acomms/acomms_constants.h'
--- src/acomms/acomms_constants.h 2010-03-20 06:09:16 +0000
+++ src/acomms/acomms_constants.h 2010-07-15 12:38:39 +0000
@@ -22,61 +22,58 @@
22#include <limits>22#include <limits>
23#include <bitset>23#include <bitset>
2424
25#include "util/tes_utils.h"25namespace goby
26
27namespace acomms
28{26{
29 const unsigned BITS_IN_BYTE = 8;27
30 // one hex char is a nibble (4 bits), two nibbles per byte28 namespace acomms
31 const unsigned NIBS_IN_BYTE = 2;
32
33 const unsigned BROADCAST_ID = 0;
34 const unsigned char DCCL_CCL_HEADER = 32;
35
36 const double NaN = std::numeric_limits<double>::quiet_NaN();
37
38 const unsigned NUM_HEADER_BYTES = 6;
39 const unsigned NUM_HEADER_NIBS = 6*NIBS_IN_BYTE;
40
41 const unsigned NUM_HEADER_PARTS = 8;
42 enum DCCLHeaderPart { head_ccl_id = 0,
43 head_dccl_id = 1,
44 head_time = 2,
45 head_src_id = 3,
46 head_dest_id = 4,
47 head_multimessage_flag = 5,
48 head_broadcast_flag = 6,
49 head_unused = 7
50 };
51
52 const std::string DCCL_HEADER_NAMES [] = { "_ccl_id",
53 "_id",
54 "_time",
55 "_src_id",
56 "_dest_id",
57 "_multimessage_flag",
58 "_broadcast_flag",
59 "_unused",
60 };
61 inline std::string to_str(DCCLHeaderPart p)
62 {29 {
63 return DCCL_HEADER_NAMES[p];30 const unsigned BITS_IN_BYTE = 8;
31 // one hex char is a nibble (4 bits), two nibbles per byte
32 const unsigned NIBS_IN_BYTE = 2;
33
34 const unsigned BROADCAST_ID = 0;
35 const unsigned char DCCL_CCL_HEADER = 32;
36
37 const double NaN = std::numeric_limits<double>::quiet_NaN();
38
39 const unsigned DCCL_NUM_HEADER_BYTES = 6;
40
41 const unsigned DCCL_NUM_HEADER_PARTS = 8;
42
43 enum DCCLHeaderPart { head_ccl_id = 0,
44 head_dccl_id = 1,
45 head_time = 2,
46 head_src_id = 3,
47 head_dest_id = 4,
48 head_multimessage_flag = 5,
49 head_broadcast_flag = 6,
50 head_unused = 7
51 };
52
53 const std::string DCCL_HEADER_NAMES [] = { "_ccl_id",
54 "_id",
55 "_time",
56 "_src_id",
57 "_dest_id",
58 "_multimessage_flag",
59 "_broadcast_flag",
60 "_unused",
61 };
62 inline std::string to_str(DCCLHeaderPart p)
63 {
64 return DCCL_HEADER_NAMES[p];
65 }
66
67 enum DCCLHeaderBits { head_ccl_id_size = 8,
68 head_dccl_id_size = 9,
69 head_time_size = 17,
70 head_src_id_size = 5,
71 head_dest_id_size = 5,
72 head_flag_size = 1,
73 head_unused_size = 2
74 };
75
64 }76 }
65
66 enum DCCLHeaderBits { head_ccl_id_size = 8,
67 head_dccl_id_size = 9,
68 head_time_size = 17,
69 head_src_id_size = 5,
70 head_dest_id_size = 5,
71 head_flag_size = 1,
72 head_unused_size = 2
73 };
74
75 const double NOT_A_TIME = -1;
7677
77 // this is Micro-Modem specific and is used by libmac, therefore
78 // we must get rid of it at some point soon...
79 const unsigned PACKET_SIZE [] = { 32, 32, 64, 256, 256, 256 };
80}78}
81
82#endif79#endif
8380
=== modified file 'src/acomms/amac.h'
--- src/acomms/amac.h 2010-01-16 05:42:56 +0000
+++ src/acomms/amac.h 2010-07-15 12:38:39 +0000
@@ -20,7 +20,7 @@
20#ifndef AMACCOURTESY20091211H20#ifndef AMACCOURTESY20091211H
21#define AMACCOURTESY20091211H21#define AMACCOURTESY20091211H
2222
23#include "acomms/libamac/mac_manager.h"23#include "goby/acomms/libamac/mac_manager.h"
2424
25#endif25#endif
2626
2727
=== modified file 'src/acomms/bind.h'
--- src/acomms/bind.h 2010-06-15 04:51:47 +0000
+++ src/acomms/bind.h 2010-07-15 12:38:39 +0000
@@ -23,58 +23,57 @@
2323
24#include <boost/bind.hpp>24#include <boost/bind.hpp>
2525
26#include "acomms/dccl.h"26#include "goby/acomms/dccl.h"
27#include "acomms/queue.h"27#include "goby/acomms/queue.h"
28#include "acomms/modem_driver.h"28#include "goby/acomms/modem_driver.h"
29#include "acomms/amac.h"29#include "goby/acomms/amac.h"
3030
31/// utilites for dealing with goby-acomms31namespace goby
32namespace acomms_util
33{32{
33 namespace acomms
34 {
34 35
35/// binds the driver link-layer callbacks to the QueueManager36/// binds the driver link-layer callbacks to the QueueManager
36 void bind(modem::DriverBase& driver, queue::QueueManager& queue_manager)37 void bind(ModemDriverBase& driver, QueueManager& queue_manager)
37 {38 {
38 using boost::bind;39 using boost::bind;
39 driver.set_receive_cb40 driver.set_receive_cb
40 (bind(&queue::QueueManager::receive_incoming_modem_data, &queue_manager, _1));41 (bind(&QueueManager::receive_incoming_modem_data, &queue_manager, _1));
41 driver.set_ack_cb42 driver.set_ack_cb
42 (bind(&queue::QueueManager::handle_modem_ack, &queue_manager, _1));43 (bind(&QueueManager::handle_modem_ack, &queue_manager, _1));
43 driver.set_datarequest_cb44 driver.set_datarequest_cb
44 (bind(&queue::QueueManager::provide_outgoing_modem_data, &queue_manager, _1, _2));45 (bind(&QueueManager::provide_outgoing_modem_data, &queue_manager, _1, _2));
45 }46
47 driver.set_destination_cb(boost::bind(&QueueManager::request_next_destination, &queue_manager, _1));
48
49 }
46 50
47/// binds the MAC initiate transmission callback to the driver and the driver parsed message callback to the MAC51/// binds the MAC initiate transmission callback to the driver and the driver parsed message callback to the MAC
48 void bind(amac::MACManager& mac, modem::DriverBase& driver)52 void bind(MACManager& mac, ModemDriverBase& driver)
49 {53 {
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));
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));
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));
53 }57 driver.set_in_parsed_cb(boost::bind(&MACManager::process_message, &mac, _1));
58 }
54 59
55/// binds the MAC destination request to the queue_manager60
56 void bind(amac::MACManager& mac, queue::QueueManager& queue_manager)61 /// bind all three (shortcut to calling the other three bind functions)
57 {62 void bind(ModemDriverBase& driver, QueueManager& queue_manager, MACManager& mac)
58 mac.set_destination_cb(boost::bind(&queue::QueueManager::request_next_destination, &queue_manager, _1));63 {
59 }64 bind(driver, queue_manager);
6065 bind(mac, driver);
61 /// bind all three (shortcut to calling the other three bind functions)66 }
62 void bind(modem::DriverBase& driver, queue::QueueManager& queue_manager, amac::MACManager& mac)67
63 {68 // examples
64 bind(driver, queue_manager);69 /// \example acomms/examples/chat/chat.cpp
65 bind(mac, driver);70 /// chat.xml
66 bind(mac, queue_manager);71 /// \verbinclude chat.xml
67 }72 /// chat.cpp
6873
69 // examples74
70 /// \example acomms/examples/chat/chat.cpp75 }
71 /// chat.xml
72 /// \verbinclude chat.xml
73 /// chat.cpp
74
7576
76}77}
7778
78
79
80#endif79#endif
8180
=== modified file 'src/acomms/dccl.h'
--- src/acomms/dccl.h 2009-12-16 20:12:41 +0000
+++ src/acomms/dccl.h 2010-07-15 12:38:39 +0000
@@ -22,6 +22,6 @@
22#ifndef DCCLCOURTESY20091211H22#ifndef DCCLCOURTESY20091211H
23#define DCCLCOURTESY20091211H23#define DCCLCOURTESY20091211H
2424
25#include "acomms/libdccl/dccl.h"25#include "goby/acomms/libdccl/dccl.h"
2626
27#endif27#endif
2828
=== modified file 'src/acomms/examples/chat/CMakeLists.txt'
--- src/acomms/examples/chat/CMakeLists.txt 2010-01-22 02:52:25 +0000
+++ src/acomms/examples/chat/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(chat chat.cpp chat_curses.cpp)1add_executable(chat chat.cpp chat_curses.cpp)
2target_link_libraries(chat ${Boost_LIBRARIES} queue amac dccl modemdriver)2target_link_libraries(chat ${Boost_LIBRARIES} goby_queue goby_amac goby_dccl goby_modemdriver)
33
=== modified file 'src/acomms/examples/chat/chat.cpp'
--- src/acomms/examples/chat/chat.cpp 2010-03-10 01:14:38 +0000
+++ src/acomms/examples/chat/chat.cpp 2010-07-15 12:38:39 +0000
@@ -22,27 +22,29 @@
2222
23#include <iostream>23#include <iostream>
2424
25#include "acomms/dccl.h"25#include "goby/acomms/dccl.h"
26#include "acomms/queue.h"26#include "goby/acomms/queue.h"
27#include "acomms/modem_driver.h"27#include "goby/acomms/modem_driver.h"
28#include "acomms/amac.h"28#include "goby/acomms/amac.h"
29#include "acomms/modem_message.h"29#include "goby/acomms/modem_message.h"
30#include "acomms/bind.h"30#include "goby/acomms/bind.h"
3131
32#include <boost/lexical_cast.hpp>32#include <boost/lexical_cast.hpp>
3333
34#include "chat_curses.h"34#include "chat_curses.h"
3535
36using namespace goby::acomms;
37
36int startup_failure();38int startup_failure();
37void received_data(queue::QueueKey, const modem::Message&);39void received_data(QueueKey, const ModemMessage&);
38void received_ack(queue::QueueKey, const modem::Message&);40void received_ack(QueueKey, const ModemMessage&);
39std::string decode_received(unsigned id, const std::string& data);41std::string decode_received(unsigned id, const std::string& data);
4042
41std::ofstream fout_;43std::ofstream fout_;
42dccl::DCCLCodec dccl_;44DCCLCodec dccl_;
43queue::QueueManager q_manager_(&fout_);45QueueManager q_manager_(&fout_);
44micromodem::MMDriver mm_driver_(&fout_);46MMDriver mm_driver_(&fout_);
45amac::MACManager mac_(&fout_);47MACManager mac_(&fout_);
46ChatCurses curses_;48ChatCurses curses_;
4749
4850
@@ -77,7 +79,7 @@
77 } 79 }
7880
79 // bind the callbacks of these libraries81 // bind the callbacks of these libraries
80 acomms_util::bind(mm_driver_, q_manager_, mac_);82 bind(mm_driver_, q_manager_, mac_);
81 83
82 //84 //
83 // Initiate DCCL (libdccl)85 // Initiate DCCL (libdccl)
@@ -100,7 +102,7 @@
100 //102 //
101 // Initiate medium access control (libamac)103 // Initiate medium access control (libamac)
102 //104 //
103 mac_.set_type(amac::mac_slotted_tdma);105 mac_.set_type(mac_slotted_tdma);
104 mac_.set_rate(0);106 mac_.set_rate(0);
105 mac_.set_slot_time(15);107 mac_.set_slot_time(15);
106 mac_.set_expire_cycles(5);108 mac_.set_expire_cycles(5);
@@ -133,7 +135,7 @@
133135
134 if(!line.empty())136 if(!line.empty())
135 {137 {
136 std::map<std::string, dccl::MessageVal> vals;138 std::map<std::string, DCCLMessageVal> vals;
137 vals["message"] = line;139 vals["message"] = line;
138140
139 std::string hex_out;141 std::string hex_out;
@@ -141,7 +143,7 @@
141 unsigned message_id = 1;143 unsigned message_id = 1;
142 dccl_.encode(message_id, hex_out, vals);144 dccl_.encode(message_id, hex_out, vals);
143 145
144 modem::Message message_out;146 ModemMessage message_out;
145 message_out.set_data(hex_out);147 message_out.set_data(hex_out);
146 // send this message to my buddy!148 // send this message to my buddy!
147 message_out.set_dest(buddy_id);149 message_out.set_dest(buddy_id);
@@ -171,12 +173,12 @@
171 return 1;173 return 1;
172}174}
173175
174void received_data(queue::QueueKey key, const modem::Message& message_in)176void received_data(QueueKey key, const ModemMessage& message_in)
175{ 177{
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()));
177}179}
178180
179void received_ack(queue::QueueKey key, const modem::Message& ack_message)181void received_ack(QueueKey key, const ModemMessage& ack_message)
180{182{
181 183
182 curses_.post_message184 curses_.post_message
@@ -187,7 +189,7 @@
187189
188std::string decode_received(unsigned id, const std::string& data)190std::string decode_received(unsigned id, const std::string& data)
189{191{
190 std::map<std::string, dccl::MessageVal> vals;192 std::map<std::string, DCCLMessageVal> vals;
191 dccl_.decode(id, data, vals);193 dccl_.decode(id, data, vals);
192 return vals["message"];194 return vals["message"];
193}195}
194196
=== modified file 'src/acomms/libamac/CMakeLists.txt'
--- src/acomms/libamac/CMakeLists.txt 2010-01-21 04:25:08 +0000
+++ src/acomms/libamac/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -4,8 +4,8 @@
4 include_directories(${Boost_INCLUDE_DIR})4 include_directories(${Boost_INCLUDE_DIR})
5 5
6 file(GLOB SRC *.cpp *.c)6 file(GLOB SRC *.cpp *.c)
7 add_library(amac SHARED ${SRC})7 add_library(goby_amac SHARED ${SRC})
8 target_link_libraries(amac streamlogger ${Boost_LIBRARIES})8 target_link_libraries(goby_amac goby_logger ${Boost_LIBRARIES})
9endif()9endif()
1010
11add_subdirectory(examples)11add_subdirectory(examples)
12\ No newline at end of file12\ No newline at end of file
1313
=== modified file 'src/acomms/libamac/examples/amac_simple/CMakeLists.txt'
--- src/acomms/libamac/examples/amac_simple/CMakeLists.txt 2010-01-22 02:52:25 +0000
+++ src/acomms/libamac/examples/amac_simple/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(amac_simple amac_simple.cpp)1add_executable(amac_simple amac_simple.cpp)
2target_link_libraries(amac_simple amac)
3\ No newline at end of file2\ No newline at end of file
3target_link_libraries(amac_simple goby_amac)
4\ No newline at end of file4\ No newline at end of file
55
=== modified file 'src/acomms/libamac/examples/amac_simple/amac_simple.cpp'
--- src/acomms/libamac/examples/amac_simple/amac_simple.cpp 2010-01-22 02:52:25 +0000
+++ src/acomms/libamac/examples/amac_simple/amac_simple.cpp 2010-07-15 12:38:39 +0000
@@ -13,12 +13,12 @@
13// You should have received a copy of the GNU General Public License13// You should have received a copy of the GNU General Public License
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/>.
1515
16#include "acomms/amac.h"16#include "goby/acomms/amac.h"
17#include "acomms/modem_message.h"17#include "goby/acomms/modem_message.h"
18#include <iostream>18#include <iostream>
1919
20int next_dest(unsigned);20int next_dest(unsigned);
21void init_transmission(const modem::Message&);21void init_transmission(const goby::acomms::ModemMessage&);
2222
23int main(int argc, char* argv[])23int main(int argc, char* argv[])
24{24{
@@ -26,12 +26,12 @@
26 //26 //
27 // 1. Create a MACManager and feed it a std::ostream to log to27 // 1. Create a MACManager and feed it a std::ostream to log to
28 //28 //
29 amac::MACManager mac(&std::cout);29 goby::acomms::MACManager mac(&std::cout);
3030
31 //31 //
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.
33 //33 //
34 mac.set_type(amac::mac_slotted_tdma);34 mac.set_type(goby::acomms::mac_slotted_tdma);
35 mac.set_rate(0);35 mac.set_rate(0);
36 mac.set_slot_time(10);36 mac.set_slot_time(10);
37 mac.set_expire_cycles(2);37 mac.set_expire_cycles(2);
@@ -43,7 +43,7 @@
4343
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.
45 mac.set_destination_cb(&next_dest);45 mac.set_destination_cb(&next_dest);
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.
47 mac.set_initiate_transmission_cb(&init_transmission);47 mac.set_initiate_transmission_cb(&init_transmission);
4848
49 //49 //
@@ -60,8 +60,8 @@
60 // 5. Discover some friends (modem ids 2 & 3)60 // 5. Discover some friends (modem ids 2 & 3)
61 //61 //
62 62
63 mac.process_message(modem::Message("src=2"));63 mac.process_message(goby::acomms::ModemMessage("src=2"));
64 mac.process_message(modem::Message("src=3"));64 mac.process_message(goby::acomms::ModemMessage("src=3"));
6565
66 //66 //
67 // 6. Run it, hearing consistently from #3, but #2 has gone silent and will be expired after 2 cycles67 // 6. Run it, hearing consistently from #3, but #2 has gone silent and will be expired after 2 cycles
@@ -71,7 +71,7 @@
71 {71 {
72 mac.do_work();72 mac.do_work();
73 sleep(1);73 sleep(1);
74 mac.process_message(modem::Message("src=3"));74 mac.process_message(goby::acomms::ModemMessage("src=3"));
75 }75 }
76 76
77 return 0;77 return 0;
@@ -83,7 +83,7 @@
83 return 10;83 return 10;
84}84}
8585
86void init_transmission(const modem::Message& init_message)86void init_transmission(const goby::acomms::ModemMessage& init_message)
87{87{
88 std::cout << "starting transmission with these values: " << init_message << std::endl;88 std::cout << "starting transmission with these values: " << init_message << std::endl;
89}89}
9090
=== modified file 'src/acomms/libamac/mac_manager.cpp'
--- src/acomms/libamac/mac_manager.cpp 2010-07-11 16:20:55 +0000
+++ src/acomms/libamac/mac_manager.cpp 2010-07-15 12:38:39 +0000
@@ -1,4 +1,4 @@
1// copyright 2009 t. schneider tes@mit.edu1// copyright 2009, 2010 t. schneider tes@mit.edu
2// 2//
3// this file is part of libamac, a medium access control for3// this file is part of libamac, a medium access control for
4// acoustic networks. 4// acoustic networks.
@@ -27,13 +27,15 @@
27#include <boost/bind.hpp>27#include <boost/bind.hpp>
28#include <boost/foreach.hpp>28#include <boost/foreach.hpp>
2929
30#include "acomms/modem_message.h"30#include "goby/acomms/modem_message.h"
31#include "acomms/libdccl/dccl_constants.h"31#include "goby/acomms/libdccl/dccl_constants.h"
32#include "util/streamlogger.h"32#include "goby/util/logger.h"
3333
34#include "mac_manager.h"34#include "mac_manager.h"
3535
36amac::MACManager::MACManager(std::ostream* os /* =0 */)36using goby::util::goby_time;
37
38goby::acomms::MACManager::MACManager(std::ostream* os /* =0 */)
37 : rate_(0),39 : rate_(0),
38 slot_time_(15),40 slot_time_(15),
39 expire_cycles_(5),41 expire_cycles_(5),
@@ -45,34 +47,34 @@
45 type_(mac_notype)47 type_(mac_notype)
46{ }48{ }
4749
48amac::MACManager::~MACManager()50goby::acomms::MACManager::~MACManager()
49{ }51{ }
5052
51void amac::MACManager::do_work()53void goby::acomms::MACManager::do_work()
52{54{
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;
54 56
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?)
56 if(timer_is_running_) io_.poll();58 if(timer_is_running_) io_.poll();
57}59}
5860
59void amac::MACManager::restart_timer()61void goby::acomms::MACManager::restart_timer()
60{ 62{
61 // cancel any old timer jobs waiting63 // cancel any old timer jobs waiting
62 timer_.cancel();64 timer_.cancel();
63 timer_.expires_at(next_slot_t_);65 timer_.expires_at(next_slot_t_);
64 timer_.async_wait(boost::bind(&amac::MACManager::send_poll, this, _1));66 timer_.async_wait(boost::bind(&MACManager::send_poll, this, _1));
65 timer_is_running_ = true;67 timer_is_running_ = true;
66}68}
6769
68void amac::MACManager::stop_timer()70void goby::acomms::MACManager::stop_timer()
69{71{
70 timer_is_running_ = false;72 timer_is_running_ = false;
71 timer_.cancel();73 timer_.cancel();
72}74}
7375
7476
75void amac::MACManager::startup()77void goby::acomms::MACManager::startup()
76{78{
77 switch(type_)79 switch(type_)
78 {80 {
@@ -80,17 +82,17 @@
80 if(os_) *os_ << group("mac")82 if(os_) *os_ << group("mac")
81 << "Using the Slotted TDMA MAC scheme with autodiscovery"83 << "Using the Slotted TDMA MAC scheme with autodiscovery"
82 << std::endl;84 << std::endl;
83 blank_it_ = add_slot(amac::Slot(acomms::BROADCAST_ID,85 blank_it_ = add_slot(Slot(acomms::BROADCAST_ID,
84 amac::Slot::query_destination,86 Slot::query_destination,
85 rate_,87 rate_,
86 amac::Slot::slot_data,88 Slot::slot_data,
87 slot_time_,89 slot_time_,
88 boost::posix_time::ptime(boost::posix_time::pos_infin)));90 boost::posix_time::ptime(boost::posix_time::pos_infin)));
8991
90 add_slot(amac::Slot(modem_id_,92 add_slot(Slot(modem_id_,
91 amac::Slot::query_destination,93 Slot::query_destination,
92 rate_,94 rate_,
93 amac::Slot::slot_data,95 Slot::slot_data,
94 slot_time_,96 slot_time_,
95 boost::posix_time::ptime(boost::posix_time::pos_infin)));97 boost::posix_time::ptime(boost::posix_time::pos_infin)));
9698
@@ -107,7 +109,7 @@
107 case mac_polled:109 case mac_polled:
108 if(os_) *os_ << group("mac")110 if(os_) *os_ << group("mac")
109 << "Using the Centralized Polling MAC scheme" << std::endl;111 << "Using the Centralized Polling MAC scheme" << std::endl;
110 next_slot_t_ = now();112 next_slot_t_ = goby_time();
111 break;113 break;
112114
113 default:115 default:
@@ -118,7 +120,7 @@
118 restart_timer();120 restart_timer();
119}121}
120122
121void amac::MACManager::send_poll(const asio::error_code& e)123void goby::acomms::MACManager::send_poll(const asio::error_code& e)
122{ 124{
123 // canceled the last timer125 // canceled the last timer
124 if(e == asio::error::operation_aborted) return; 126 if(e == asio::error::operation_aborted) return;
@@ -129,7 +131,7 @@
129 bool send_poll = true;131 bool send_poll = true;
130 132
131 int destination = (s.dest() == Slot::query_destination)133 int destination = (s.dest() == Slot::query_destination)
132 ? callback_dest(acomms::PACKET_SIZE[s.rate()]) : s.dest();134 ? callback_dest(s.rate()) : s.dest();
133 135
134 switch(type_)136 switch(type_)
135 {137 {
@@ -157,13 +159,13 @@
157 *os_ << " ]" << std::endl; 159 *os_ << " ]" << std::endl;
158160
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 "
160 << destination << " @ " << s.rate() << "}" << std::endl;162 << destination << " @ " << s.rate() << "}" << std::endl;
161 }163 }
162164
163 165
164 if(send_poll)166 if(send_poll)
165 {167 {
166 modem::Message m;168 ModemMessage m;
167 switch(s.type())169 switch(s.type())
168 {170 {
169 case Slot::slot_data:171 case Slot::slot_data:
@@ -214,12 +216,12 @@
214 restart_timer();216 restart_timer();
215}217}
216218
217 boost::posix_time::ptime amac::MACManager::next_cycle_time()219boost::posix_time::ptime goby::acomms::MACManager::next_cycle_time()
218{220{
219 using namespace boost::gregorian;221 using namespace boost::gregorian;
220 using namespace boost::posix_time;222 using namespace boost::posix_time;
221223
222 int since_day_start = now().time_of_day().total_seconds();224 int since_day_start = goby_time().time_of_day().total_seconds();
223 cycles_since_day_start_ = (floor(since_day_start/cycle_length()) + 1);225 cycles_since_day_start_ = (floor(since_day_start/cycle_length()) + 1);
224226
225 if(os_) *os_ << group("mac") << "cycles since day start: "227 if(os_) *os_ << group("mac") << "cycles since day start: "
@@ -232,7 +234,7 @@
232 return ptime(day_clock::universal_day(), seconds(secs_to_next));234 return ptime(day_clock::universal_day(), seconds(secs_to_next));
233}235}
234236
235void amac::MACManager::process_message(const modem::Message& m)237void goby::acomms::MACManager::process_message(const ModemMessage& m)
236{238{
237 unsigned id = m.src();239 unsigned id = m.src();
238 240
@@ -249,7 +251,7 @@
249 251
250 slot_order_.push_back252 slot_order_.push_back
251 (id2slot_.insert253 (id2slot_.insert
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()))));
253255
254 slot_order_.sort();256 slot_order_.sort();
255257
@@ -259,17 +261,17 @@
259 {261 {
260 std::pair<id2slot_it, id2slot_it> p = id2slot_.equal_range(id);262 std::pair<id2slot_it, id2slot_it> p = id2slot_.equal_range(id);
261 for(id2slot_it it = p.first; it != p.second; ++it)263 for(id2slot_it it = p.first; it != p.second; ++it)
262 it->second.set_last_heard_time(now());264 it->second.set_last_heard_time(goby_time());
263 }265 }
264}266}
265267
266void amac::MACManager::expire_ids()268void goby::acomms::MACManager::expire_ids()
267{269{
268 bool reset = false;270 bool reset = false;
269 271
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)
271 {273 {
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_)
273 { 275 {
274 if(os_) *os_ << group("mac") << "removed id " << it->first276 if(os_) *os_ << group("mac") << "removed id " << it->first
275 << " after not hearing for " << expire_cycles_277 << " after not hearing for " << expire_cycles_
@@ -284,7 +286,7 @@
284 if(reset) process_cycle_size_change();286 if(reset) process_cycle_size_change();
285}287}
286288
287void amac::MACManager::process_cycle_size_change()289void goby::acomms::MACManager::process_cycle_size_change()
288{290{
289 next_slot_t_ = next_cycle_time();291 next_slot_t_ = next_cycle_time();
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: "
@@ -296,7 +298,7 @@
296}298}
297299
298300
299unsigned amac::MACManager::cycle_sum()301unsigned goby::acomms::MACManager::cycle_sum()
300{302{
301 unsigned s = 0;303 unsigned s = 0;
302 BOOST_FOREACH(id2slot_it it, slot_order_)304 BOOST_FOREACH(id2slot_it it, slot_order_)
@@ -304,7 +306,7 @@
304 return s;306 return s;
305}307}
306308
307void amac::MACManager::position_blank()309void goby::acomms::MACManager::position_blank()
308{310{
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;
310 312
@@ -319,11 +321,11 @@
319 current_slot_ = slot_order_.begin();321 current_slot_ = slot_order_.begin();
320}322}
321323
322std::map<unsigned, amac::Slot>::iterator amac::MACManager::add_slot(const amac::Slot& s) 324std::map<unsigned, goby::acomms::Slot>::iterator goby::acomms::MACManager::add_slot(const Slot& s)
323{325{
324 bool do_timer_start = slot_order_.empty();326 bool do_timer_start = slot_order_.empty();
325327
326 std::map<unsigned, amac::Slot>::iterator it =328 std::map<unsigned, Slot>::iterator it =
327 id2slot_.insert(std::pair<unsigned, Slot>(s.src(), s));329 id2slot_.insert(std::pair<unsigned, Slot>(s.src(), s));
328330
329 slot_order_.push_back(it);331 slot_order_.push_back(it);
@@ -333,14 +335,14 @@
333 335
334 if(do_timer_start)336 if(do_timer_start)
335 {337 {
336 next_slot_t_ = now();338 next_slot_t_ = goby_time();
337 restart_timer();339 restart_timer();
338 }340 }
339 341
340 return it;342 return it;
341}343}
342344
343bool amac::MACManager::remove_slot(const amac::Slot& s) 345bool goby::acomms::MACManager::remove_slot(const Slot& s)
344{346{
345 bool removed_a_slot = false;347 bool removed_a_slot = false;
346 348
347349
=== modified file 'src/acomms/libamac/mac_manager.h'
--- src/acomms/libamac/mac_manager.h 2010-07-11 16:20:55 +0000
+++ src/acomms/libamac/mac_manager.h 2010-07-15 12:38:39 +0000
@@ -1,4 +1,4 @@
1// copyright 2009 t. schneider tes@mit.edu1// copyright 2009, 2010 t. schneider tes@mit.edu
2// 2//
3// this file is part of libamac, a medium access control for3// this file is part of libamac, a medium access control for
4// acoustic networks. 4// acoustic networks.
@@ -23,268 +23,266 @@
23#define MAC20091019H23#define MAC20091019H
2424
25#include <boost/lexical_cast.hpp>25#include <boost/lexical_cast.hpp>
26#include <boost/date_time/posix_time/posix_time.hpp>
27#include <boost/function.hpp>26#include <boost/function.hpp>
28#include "asio.hpp"27#include "asio.hpp"
2928
30namespace modem { class Message; }29#include "goby/util/time.h"
3130
32/// \brief contains the medium access control objects31namespace goby
33///
34/// Use \code #include <goby/acomms/amac.h> \endcode to gain access to all these objects.
35namespace amac
36{32{
37 /// \name Acoustic MAC Library callback function type definitions33 namespace acomms
38 //@{34 {
3935 class ModemMessage;
40 /// \brief boost::function for a function taking a unsigned and returning an integer.36 /// \name Acoustic MAC Library callback function type definitions
41 ///37 //@{
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
43 typedef boost::function<int (unsigned)> IdFunc;39 /// \brief boost::function for a function taking a unsigned and returning an integer.
4440 ///
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.
46 ///42 typedef boost::function<int (unsigned)> MACIdFunc;
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
48 typedef boost::function<void (const modem::Message & message)> MsgFunc1;44 /// \brief boost::function for a function taking a single acomms::ModemMessage reference.
4945 ///
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.
47 typedef boost::function<void (const acomms::ModemMessage & message)> MACMsgFunc1;
48
49 //@}
5150
52/// Enumeration of MAC types51/// Enumeration of MAC types
53 enum MACType {52 enum MACType {
54 mac_notype, /*!< no MAC */53 mac_notype, /*!< no MAC */
55 mac_slotted_tdma, /*!< decentralized time division multiple access */54 mac_slotted_tdma, /*!< decentralized time division multiple access */
56 mac_polled /*!< centralized polling */55 mac_polled /*!< centralized polling */
57 }; 56 };
5857
59 /// Represents a slot of the TDMA cycle58 /// Represents a slot of the TDMA cycle
60 class Slot59 class Slot
61 {
62 public:
63 /// Enumeration of slot types
64 enum SlotType
65 {60 {
66 slot_notype, /*!< useless slot */61 public:
67 slot_data, /*!< slot to send data packet */62 /// Enumeration of slot types
68 slot_ping /*!< slot to send ping (ranging) */63 enum SlotType
69 };64 {
65 slot_notype, /*!< useless slot */
66 slot_data, /*!< slot to send data packet */
67 slot_ping /*!< slot to send ping (ranging) */
68 };
70 69
71 /// \name Constructors/Destructor70 /// \name Constructors/Destructor
72 //@{ 71 //@{
73 /// \brief Default constructor.72 /// \brief Default constructor.
74 ///73 ///
75 /// \param src id representing sender of the data packet or ping74 /// \param src id representing sender of the data packet or ping
76 /// \param dest id representing destination of the data packet or ping75 /// \param dest id representing destination of the data packet or ping
77 /// \param rate value 0-5 representing modem transmission rate. 0 is slowest, 5 is fastest76 /// \param rate value 0-5 representing modem transmission rate. 0 is slowest, 5 is fastest
78 /// \param type amac::Slot::SlotType of this slot77 /// \param type amac::Slot::SlotType of this slot
79 /// \param slot_time length of time this slot should last in seconds78 /// \param slot_time length of time this slot should last in seconds
80 /// \param last_heard_time last time (in seconds since 1/1/70) the src vehicle was heard from79 /// \param last_heard_time last time (in seconds since 1/1/70) the src vehicle was heard from
81 Slot(unsigned src = 0,80 Slot(unsigned src = 0,
82 unsigned dest = 0,81 unsigned dest = 0,
83 int rate = 0,82 int rate = 0,
84 SlotType type = slot_notype,83 SlotType type = slot_notype,
85 unsigned slot_time = 15,84 unsigned slot_time = 15,
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)
87 : src_(src),86 : src_(src),
88 dest_(dest),87 dest_(dest),
89 rate_(rate),88 rate_(rate),
90 type_(type),89 type_(type),
91 slot_time_(slot_time),90 slot_time_(slot_time),
92 last_heard_time_(last_heard_time) 91 last_heard_time_(last_heard_time)
93 { }92 { }
9493
95 //@}94 //@}
9695
97 /// \name Set96 /// \name Set
98 //@{97 //@{
99 void set_src(unsigned src) { src_ = src; }98 void set_src(unsigned src) { src_ = src; }
100 void set_dest(int dest) { dest_ = dest; }99 void set_dest(int dest) { dest_ = dest; }
101 void set_rate(int rate) { rate_ = rate; }100 void set_rate(int rate) { rate_ = rate; }
102 void set_type(SlotType type) { type_ = type; }101 void set_type(SlotType type) { type_ = type; }
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; }
104 void set_slot_time(unsigned t) { slot_time_ = t; }103 void set_slot_time(unsigned t) { slot_time_ = t; }
105 //@}104 //@}
106105
107 /// \name Get106 /// \name Get
108 //@{107 //@{
109 unsigned src() const { return src_; }108 unsigned src() const { return src_; }
110 int dest() const { return dest_; }109 int dest() const { return dest_; }
111 int rate() const { return rate_; } 110 int rate() const { return rate_; }
112 SlotType type() const { return type_; }111 SlotType type() const { return type_; }
113 std::string type_as_string() const112 std::string type_as_string() const
114 {
115 switch(type_)
116 {113 {
117 case slot_data: return "data";114 switch(type_)
118 case slot_ping: return "ping";115 {
119 default: return "unknown";116 case slot_data: return "data";
117 case slot_ping: return "ping";
118 default: return "unknown";
119 }
120 }120 }
121
122 boost::posix_time::ptime last_heard_time() const { return last_heard_time_; }
123 unsigned slot_time() const { return slot_time_; }
124 //@}
125
126 enum { query_destination = -1 };
127
128
129 private:
130 unsigned src_;
131 int dest_;
132 int rate_;
133 SlotType type_;
134 unsigned slot_time_;
135 boost::posix_time::ptime last_heard_time_;
136 };
137
138 inline std::ostream& operator<<(std::ostream& os, const Slot& s)
139 { return os << "src: " << s.src() << " | dest: " << s.dest() << " | rate: " << s.rate() << " | slot_time: " << s.slot_time(); }
140
141
142 /// provides an API to the goby-acomms MAC library.
143 class MACManager
144 {
145
146 public:
147
148 /// \name Constructors/Destructor
149 //@{
150 /// \brief Default constructor.
151 ///
152 /// \param os std::ostream object or FlexOstream to capture all humanly readable runtime and debug information (optional).
153 MACManager(std::ostream* os = 0);
154 ~MACManager();
155 //@}
156
157 /// \brief Starts the MAC
158 void startup();
159 /// \brief Must be called regularly for the MAC to perform its work
160 void do_work();
161
162 /// \brief Manually initiate a transmission out of the normal cycle. This is not normally called by the user of MACManager
163 void send_poll(const asio::error_code&);
164
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.
166 ///
167 /// \param message the new message (used to detect vehicles)
168 void process_message(const acomms::ModemMessage& m);
169
170 /// \name Manipulate slots
171 //@{
172 /// \return iterator to newly added slot
173 std::map<unsigned, Slot>::iterator add_slot(const Slot& s);
174 /// \brief removes any slots in the cycle where amac::operator==(const Slot&, const Slot&) is true.
175 ///
176 /// \return true if one or more slots are removed
177 bool remove_slot(const Slot& s);
178 void clear_all_slots() { id2slot_.clear(); slot_order_.clear(); }
179 //@}
180
181
182 /// \name Set
183 //@{
184 void set_type(MACType type) { type_ = type; }
185 void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; }
186 void set_modem_id(const std::string& s) { set_modem_id(boost::lexical_cast<unsigned>(s)); }
187 void set_rate(int rate) { rate_ = rate; }
188 void set_rate(const std::string& s) { set_rate(boost::lexical_cast<int>(s)); }
189 void set_slot_time(unsigned slot_time) { slot_time_ = slot_time; }
190 void set_slot_time(const std::string& s) { set_slot_time(boost::lexical_cast<unsigned>(s)); }
191 void set_expire_cycles(unsigned expire_cycles) { expire_cycles_ = expire_cycles; }
192 void set_expire_cycles(const std::string& s) { set_expire_cycles(boost::lexical_cast<unsigned>(s)); }
193 /// \brief Callback to call to request which vehicle id should be the next destination. Typically bound to queue::QueueManager::request_next_destination.
194 //
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.
196 void set_destination_cb(MACIdFunc func) { callback_dest = func; }
197 /// \brief Callback for initiate a tranmission. Typically bound to acomms::ModemDriverBase::initiate_transmission.
198 void set_initiate_transmission_cb(MACMsgFunc1 func) { callback_initiate_transmission = func; }
199
200 /// \brief Callback for initiate ranging ("ping"). Typically bound to acomms::ModemDriverBase::initiate_ranging.
201 void set_initiate_ranging_cb(MACMsgFunc1 func) { callback_initiate_ranging = func; }
202
203//@}
204
205 /// \name Get
206 //@{
207 int rate() { return rate_; }
208 unsigned slot_time() { return slot_time_; }
209 MACType type() { return type_; }
210 //@}
211
212
213 /// \example libamac/examples/amac_simple/amac_simple.cpp
214 /// amac_simple.cpp
215
216 /// \example acomms/examples/chat/chat.cpp
217
218 private:
219 enum { NO_AVAILABLE_DESTINATION = -1 };
220 MACIdFunc callback_dest;
221 MACMsgFunc1 callback_initiate_transmission;
222 MACMsgFunc1 callback_initiate_ranging;
223
224 boost::posix_time::ptime next_cycle_time();
225
226 void restart_timer();
227 void stop_timer();
228
229 void expire_ids();
230 void process_cycle_size_change();
231
232 unsigned cycle_count() { return slot_order_.size(); }
233 unsigned cycle_length() { return cycle_count() * slot_time_; }
234
235 unsigned cycle_sum();
236 void position_blank();
237
238 private:
239 // (bit)-rate id number
240 int rate_;
241 // size of each slot (seconds)
242 unsigned slot_time_;
243 // how many cycles before we remove someone?
244 unsigned expire_cycles_;
245
246 std::ostream* os_;
247
248 unsigned modem_id_;
249
250 // asynchronous timer
251 asio::io_service io_;
252 asio::deadline_timer timer_;
253 bool timer_is_running_;
254
255 boost::posix_time::ptime next_cycle_t_;
256 boost::posix_time::ptime next_slot_t_;
257
258 // <id, last time heard from>
259 typedef std::multimap<unsigned, Slot>::iterator id2slot_it;
260
261 id2slot_it blank_it_;
262 std::list<id2slot_it> slot_order_;
263 std::multimap<unsigned, Slot> id2slot_;
264
265 std::list<id2slot_it>::iterator current_slot_;
266
267 unsigned cycles_since_day_start_;
268
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.
270 enum { ENTROPY = 5 };
271 MACType type_;
272 };
273
274 ///
275 inline bool operator<(const std::map<unsigned, Slot>::iterator& a, const std::map<unsigned, Slot>::iterator& b)
276 { return a->second.src() < b->second.src(); }
277
278 /// Are two amac::Slot equal?
279 inline bool operator==(const Slot& a, const Slot& b)
280 {
281 return a.src() == b.src() && a.dest() == b.dest() && a.rate() == b.rate() && a.type() == b.type() && a.slot_time() == b.slot_time();
121 }282 }
122 283
123 boost::posix_time::ptime last_heard_time() const { return last_heard_time_; }284
124 unsigned slot_time() const { return slot_time_; }
125 //@}
126
127 enum { query_destination = -1 };
128
129
130 private:
131 unsigned src_;
132 int dest_;
133 int rate_;
134 SlotType type_;
135 unsigned slot_time_;
136 boost::posix_time::ptime last_heard_time_;
137 };
138
139 inline std::ostream& operator<<(std::ostream& os, const Slot& s)
140 { return os << "src: " << s.src() << " | dest: " << s.dest() << " | rate: " << s.rate() << " | slot_time: " << s.slot_time(); }
141
142
143 /// provides an API to the goby-acomms MAC library.
144 class MACManager
145 {
146
147 public:
148
149 /// \name Constructors/Destructor
150 //@{
151 /// \brief Default constructor.
152 ///
153 /// \param os std::ostream object or FlexOstream to capture all humanly readable runtime and debug information (optional).
154 MACManager(std::ostream* os = 0);
155 ~MACManager();
156 //@}
157
158 /// \brief Starts the MAC
159 void startup();
160 /// \brief Must be called regularly for the MAC to perform its work
161 void do_work();
162
163 /// \brief Manually initiate a transmission out of the normal cycle. This is not normally called by the user of MACManager
164 void send_poll(const asio::error_code&);
165
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.
167 ///
168 /// \param message the new message (used to detect vehicles)
169 void process_message(const modem::Message& m);
170
171 /// \name Manipulate slots
172 //@{
173 /// \return iterator to newly added slot
174 std::map<unsigned, amac::Slot>::iterator add_slot(const amac::Slot& s);
175 /// \brief removes any slots in the cycle where amac::operator==(const Slot&, const Slot&) is true.
176 ///
177 /// \return true if one or more slots are removed
178 bool remove_slot(const amac::Slot& s);
179 void clear_all_slots() { id2slot_.clear(); slot_order_.clear(); }
180 //@}
181
182
183 /// \name Set
184 //@{
185 void set_type(MACType type) { type_ = type; }
186 void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; }
187 void set_modem_id(const std::string& s) { set_modem_id(boost::lexical_cast<unsigned>(s)); }
188 void set_rate(int rate) { rate_ = rate; }
189 void set_rate(const std::string& s) { set_rate(boost::lexical_cast<int>(s)); }
190 void set_slot_time(unsigned slot_time) { slot_time_ = slot_time; }
191 void set_slot_time(const std::string& s) { set_slot_time(boost::lexical_cast<unsigned>(s)); }
192 void set_expire_cycles(unsigned expire_cycles) { expire_cycles_ = expire_cycles; }
193 void set_expire_cycles(const std::string& s) { set_expire_cycles(boost::lexical_cast<unsigned>(s)); }
194 /// \brief Callback to call to request which vehicle id should be the next destination. Typically bound to queue::QueueManager::request_next_destination.
195 //
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.
197 void set_destination_cb(IdFunc func) { callback_dest = func; }
198 /// \brief Callback for initiate a tranmission. Typically bound to modem::DriverBase::initiate_transmission.
199 void set_initiate_transmission_cb(MsgFunc1 func) { callback_initiate_transmission = func; }
200
201 /// \brief Callback for initiate ranging ("ping"). Typically bound to modem::DriverBase::initiate_ranging.
202 void set_initiate_ranging_cb(MsgFunc1 func) { callback_initiate_ranging = func; }
203
204//@}
205
206 /// \name Get
207 //@{
208 int rate() { return rate_; }
209 unsigned slot_time() { return slot_time_; }
210 MACType type() { return type_; }
211 //@}
212
213
214 /// \example libamac/examples/amac_simple/amac_simple.cpp
215 /// amac_simple.cpp
216
217 /// \example acomms/examples/chat/chat.cpp
218
219 private:
220 enum { NO_AVAILABLE_DESTINATION = -1 };
221 IdFunc callback_dest;
222 MsgFunc1 callback_initiate_transmission;
223 MsgFunc1 callback_initiate_ranging;
224
225 boost::posix_time::ptime next_cycle_time();
226
227 void restart_timer();
228 void stop_timer();
229
230 void expire_ids();
231 void process_cycle_size_change();
232
233 unsigned cycle_count() { return slot_order_.size(); }
234 unsigned cycle_length() { return cycle_count() * slot_time_; }
235
236 boost::posix_time::ptime now() { return boost::posix_time::second_clock::universal_time(); }
237 unsigned cycle_sum();
238 void position_blank();
239
240 private:
241 // (bit)-rate id number
242 int rate_;
243 // size of each slot (seconds)
244 unsigned slot_time_;
245 // how many cycles before we remove someone?
246 unsigned expire_cycles_;
247
248 std::ostream* os_;
249
250 unsigned modem_id_;
251
252 // asynchronous timer
253 asio::io_service io_;
254 asio::deadline_timer timer_;
255 bool timer_is_running_;
256
257 boost::posix_time::ptime next_cycle_t_;
258 boost::posix_time::ptime next_slot_t_;
259
260 // <id, last time heard from>
261 typedef std::multimap<unsigned, Slot>::iterator id2slot_it;
262
263 id2slot_it blank_it_;
264 std::list<id2slot_it> slot_order_;
265 std::multimap<unsigned, Slot> id2slot_;
266
267 std::list<id2slot_it>::iterator current_slot_;
268
269 unsigned cycles_since_day_start_;
270
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.
272 enum { ENTROPY = 5 };
273 MACType type_;
274 };
275
276 ///
277 inline bool operator<(const std::map<unsigned, Slot>::iterator& a, const std::map<unsigned, Slot>::iterator& b)
278 { return a->second.src() < b->second.src(); }
279
280 /// Are two amac::Slot equal?
281 inline bool operator==(const Slot& a, const Slot& b)
282 {
283 return a.src() == b.src() && a.dest() == b.dest() && a.rate() == b.rate() && a.type() == b.type() && a.slot_time() == b.slot_time();
284 }285 }
285
286
287}286}
288287
289
290#endif288#endif
291289
=== modified file 'src/acomms/libdccl/CMakeLists.txt'
--- src/acomms/libdccl/CMakeLists.txt 2010-03-15 16:21:43 +0000
+++ src/acomms/libdccl/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -4,8 +4,8 @@
4 include_directories(${Boost_INCLUDE_DIR})4 include_directories(${Boost_INCLUDE_DIR})
5 5
6 file(GLOB SRC *.cpp *.c)6 file(GLOB SRC *.cpp *.c)
7 add_library(dccl SHARED ${SRC})7 add_library(goby_dccl SHARED ${SRC})
8 target_link_libraries(dccl xerces-c crypto++)8 target_link_libraries(goby_dccl xerces-c crypto++ ${Boost_LIBRARIES})
9endif()9endif()
1010
11add_subdirectory(examples)11add_subdirectory(examples)
1212
=== modified file 'src/acomms/libdccl/dccl.cpp'
--- src/acomms/libdccl/dccl.cpp 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/dccl.cpp 2010-07-15 12:38:39 +0000
@@ -26,31 +26,39 @@
26#include "dccl.h"26#include "dccl.h"
27#include "message_xml_callbacks.h"27#include "message_xml_callbacks.h"
2828
29using goby::util::goby_time;
30
29/////////////////////31/////////////////////
30// public methods (general use)32// public methods (general use)
31/////////////////////33/////////////////////
32dccl::DCCLCodec::DCCLCodec() : start_time_(time(NULL)), modem_id_(0)34goby::acomms::DCCLCodec::DCCLCodec()
35 : start_time_(goby_time()),
36 modem_id_(0)
33{ }37{ }
34 38
35dccl::DCCLCodec::DCCLCodec(const std::string& file, const std::string schema) : start_time_(time(NULL)), modem_id_(0)39goby::acomms::DCCLCodec::DCCLCodec(const std::string& file, const std::string schema)
40 : start_time_(goby_time()),
41 modem_id_(0)
36{ add_xml_message_file(file, schema); }42{ add_xml_message_file(file, schema); }
37 43
38dccl::DCCLCodec::DCCLCodec(const std::set<std::string>& files,44goby::acomms::DCCLCodec::DCCLCodec(const std::set<std::string>& files,
39 const std::string schema) : start_time_(time(NULL)), modem_id_(0)45 const std::string schema)
46 : start_time_(goby_time()),
47 modem_id_(0)
40{48{
41 BOOST_FOREACH(const std::string& s, files)49 BOOST_FOREACH(const std::string& s, files)
42 add_xml_message_file(s, schema);50 add_xml_message_file(s, schema);
43}51}
4452
45std::set<unsigned> dccl::DCCLCodec::add_xml_message_file(const std::string& xml_file,53std::set<unsigned> goby::acomms::DCCLCodec::add_xml_message_file(const std::string& xml_file,
46 const std::string xml_schema)54 const std::string xml_schema)
47{55{
48 size_t begin_size = messages_.size();56 size_t begin_size = messages_.size();
49 57
50 58
51 // Register handlers for XML parsing59 // Register handlers for XML parsing
52 MessageContentHandler content(messages_);60 DCCLMessageContentHandler content(messages_);
53 MessageErrorHandler error;61 DCCLMessageErrorHandler error;
54 // instantiate a parser for the xml message files62 // instantiate a parser for the xml message files
55 XMLParser parser(content, error);63 XMLParser parser(content, error);
56 // parse(file, [schema])64 // parse(file, [schema])
@@ -77,59 +85,59 @@
77 return added_ids;85 return added_ids;
78}86}
7987
80std::set<unsigned> dccl::DCCLCodec::all_message_ids()88std::set<unsigned> goby::acomms::DCCLCodec::all_message_ids()
81{89{
82 std::set<unsigned> s;90 std::set<unsigned> s;
83 BOOST_FOREACH(const Message &msg, messages_)91 BOOST_FOREACH(const DCCLMessage &msg, messages_)
84 s.insert(msg.id());92 s.insert(msg.id());
85 return s;93 return s;
86} 94}
87std::set<std::string> dccl::DCCLCodec::all_message_names()95std::set<std::string> goby::acomms::DCCLCodec::all_message_names()
88{96{
89 std::set<std::string> s;97 std::set<std::string> s;
90 BOOST_FOREACH(const Message &msg, messages_)98 BOOST_FOREACH(const DCCLMessage &msg, messages_)
91 s.insert(msg.name());99 s.insert(msg.name());
92 return s;100 return s;
93}101}
94102
95 103
96std::string dccl::DCCLCodec::summary() const 104std::string goby::acomms::DCCLCodec::summary() const
97{ 105{
98 std::string out;106 std::string out;
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)
100 out += it->get_display();108 out += it->get_display();
101 return out;109 return out;
102}110}
103111
104std::string dccl::DCCLCodec::brief_summary() const 112std::string goby::acomms::DCCLCodec::brief_summary() const
105{ 113{
106 std::string out;114 std::string out;
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)
108 out += it->get_short_display();116 out += it->get_short_display();
109 return out;117 return out;
110}118}
111119
112void dccl::DCCLCodec::add_algorithm(const std::string& name, AlgFunction1 func)120void goby::acomms::DCCLCodec::add_algorithm(const std::string& name, AlgFunction1 func)
113{121{
114 AlgorithmPerformer* ap = AlgorithmPerformer::getInstance();122 DCCLAlgorithmPerformer* ap = DCCLAlgorithmPerformer::getInstance();
115 ap -> add_algorithm(name, func);123 ap -> add_algorithm(name, func);
116}124}
117125
118void dccl::DCCLCodec::add_adv_algorithm(const std::string& name, AlgFunction2 func)126void goby::acomms::DCCLCodec::add_adv_algorithm(const std::string& name, AlgFunction2 func)
119{127{
120 AlgorithmPerformer* ap = AlgorithmPerformer::getInstance();128 DCCLAlgorithmPerformer* ap = DCCLAlgorithmPerformer::getInstance();
121 ap -> add_algorithm(name, func);129 ap -> add_algorithm(name, func);
122}130}
123131
124132
125std::ostream& dccl::operator<< (std::ostream& out, const DCCLCodec& d)133std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLCodec& d)
126{134{
127 out << d.summary();135 out << d.summary();
128 return out;136 return out;
129}137}
130138
131139
132std::ostream& dccl::operator<< (std::ostream& out, const std::set<std::string>& s)140std::ostream& goby::acomms::operator<< (std::ostream& out, const std::set<std::string>& s)
133{141{
134 out << "std::set<std::string>:" << std::endl;142 out << "std::set<std::string>:" << std::endl;
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)
@@ -137,7 +145,7 @@
137 return out;145 return out;
138}146}
139147
140std::ostream& dccl::operator<< (std::ostream& out, const std::set<unsigned>& s)148std::ostream& goby::acomms::operator<< (std::ostream& out, const std::set<unsigned>& s)
141{149{
142 out << "std::set<unsigned>:" << std::endl;150 out << "std::set<unsigned>:" << std::endl;
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)
@@ -155,9 +163,9 @@
155// to be processed. this allows the SAME moos trigger variable163// to be processed. this allows the SAME moos trigger variable
156// to be used to trigger creation of different messages based on the164// to be used to trigger creation of different messages based on the
157// contents of the trigger message itself.165// contents of the trigger message itself.
158bool dccl::DCCLCodec::is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value)166bool goby::acomms::DCCLCodec::is_publish_trigger(std::set<unsigned>& id, const std::string& key, const std::string& value)
159{167{
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)
161 {169 {
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))
163 id.insert(it->id());171 id.insert(it->id());
@@ -165,11 +173,14 @@
165 return (id.empty()) ? false : true;173 return (id.empty()) ? false : true;
166}174}
167175
168bool dccl::DCCLCodec::is_time_trigger(std::set<unsigned>& id)176bool goby::acomms::DCCLCodec::is_time_trigger(std::set<unsigned>& id)
169{177{
170 for (std::vector<dccl::Message>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it)178 using boost::posix_time::seconds;
179
180 for (std::vector<DCCLMessage>::iterator it = messages_.begin(), n = messages_.end(); it != n; ++it)
171 {181 {
172 if(it->trigger_type() == "time" && time(NULL) > (start_time_ + it->trigger_number() * it->trigger_time()))182 if(it->trigger_type() == "time" &&
183 goby_time() > (start_time_ + seconds(it->trigger_number() * it->trigger_time())))
173 {184 {
174 id.insert(it->id());185 id.insert(it->id());
175 // increment message counter186 // increment message counter
@@ -181,9 +192,9 @@
181}192}
182193
183 194
184bool dccl::DCCLCodec::is_incoming(unsigned& id, const std::string& key)195bool goby::acomms::DCCLCodec::is_incoming(unsigned& id, const std::string& key)
185{196{
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)
187 {198 {
188 if (key == it->in_var())199 if (key == it->in_var())
189 {200 {
@@ -199,55 +210,55 @@
199/////////////////////210/////////////////////
200211
201212
202void dccl::DCCLCodec::check_duplicates()213void goby::acomms::DCCLCodec::check_duplicates()
203{214{
204 std::map<unsigned, std::vector<Message>::iterator> all_ids;215 std::map<unsigned, std::vector<DCCLMessage>::iterator> all_ids;
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)
206 {217 {
207 unsigned id = it->id();218 unsigned id = it->id();
208 219
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);
210 if(id_it != all_ids.end())221 if(id_it != all_ids.end())
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()));
212 223
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));
214 }225 }
215}226}
216227
217std::vector<dccl::Message>::const_iterator dccl::DCCLCodec::to_iterator(const std::string& message_name) const228std::vector<goby::acomms::DCCLMessage>::const_iterator goby::acomms::DCCLCodec::to_iterator(const std::string& message_name) const
218{229{
219 if(name2messages_.count(message_name))230 if(name2messages_.count(message_name))
220 return messages_.begin() + name2messages_.find(message_name)->second;231 return messages_.begin() + name2messages_.find(message_name)->second;
221 else232 else
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"));
223}234}
224std::vector<dccl::Message>::iterator dccl::DCCLCodec::to_iterator(const std::string& message_name)235std::vector<goby::acomms::DCCLMessage>::iterator goby::acomms::DCCLCodec::to_iterator(const std::string& message_name)
225{236{
226 if(name2messages_.count(message_name))237 if(name2messages_.count(message_name))
227 return messages_.begin() + name2messages_.find(message_name)->second;238 return messages_.begin() + name2messages_.find(message_name)->second;
228 else239 else
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"));
230}241}
231std::vector<dccl::Message>::const_iterator dccl::DCCLCodec::to_iterator(const unsigned& id) const242std::vector<goby::acomms::DCCLMessage>::const_iterator goby::acomms::DCCLCodec::to_iterator(const unsigned& id) const
232{243{
233 if(id2messages_.count(id))244 if(id2messages_.count(id))
234 return messages_.begin() + id2messages_.find(id)->second;245 return messages_.begin() + id2messages_.find(id)->second;
235 else246 else
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"));
237}248}
238249
239std::vector<dccl::Message>::iterator dccl::DCCLCodec::to_iterator(const unsigned& id)250std::vector<goby::acomms::DCCLMessage>::iterator goby::acomms::DCCLCodec::to_iterator(const unsigned& id)
240{251{
241 if(id2messages_.count(id))252 if(id2messages_.count(id))
242 return messages_.begin() + id2messages_.find(id)->second;253 return messages_.begin() + id2messages_.find(id)->second;
243 else254 else
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"));
245}256}
246257
247258
248void dccl::DCCLCodec::encode_private(std::vector<Message>::iterator it,259void goby::acomms::DCCLCodec::encode_private(std::vector<DCCLMessage>::iterator it,
249 std::string& out,260 std::string& out,
250 std::map<std::string, std::vector<MessageVal> > in /* copy */)261 std::map<std::string, std::vector<DCCLMessageVal> > in /* copy */)
251{262{
252 // 1. encode parts263 // 1. encode parts
253 std::string body, head;264 std::string body, head;
@@ -267,9 +278,9 @@
267 hex_encode(out);278 hex_encode(out);
268}279}
269280
270void dccl::DCCLCodec::decode_private(std::vector<Message>::iterator it,281void goby::acomms::DCCLCodec::decode_private(std::vector<DCCLMessage>::iterator it,
271 std::string in,282 std::string in,
272 std::map<std::string, std::vector<MessageVal> >& out)283 std::map<std::string, std::vector<DCCLMessageVal> >& out)
273{284{
274 // 4. hex decode285 // 4. hex decode
275 hex_decode(in);286 hex_decode(in);
@@ -278,9 +289,9 @@
278 in.resize(in.find_last_not_of(char(0))+1);289 in.resize(in.find_last_not_of(char(0))+1);
279 290
280 // 3. split body and header (avoid substr::out_of_range)291 // 3. split body and header (avoid substr::out_of_range)
281 std::string body = (acomms::NUM_HEADER_BYTES < in.size()) ?292 std::string body = (DCCL_NUM_HEADER_BYTES < in.size()) ?
282 in.substr(acomms::NUM_HEADER_BYTES) : "";293 in.substr(DCCL_NUM_HEADER_BYTES) : "";
283 std::string head = in.substr(0, acomms::NUM_HEADER_BYTES);294 std::string head = in.substr(0, DCCL_NUM_HEADER_BYTES);
284 295
285 // 2. decrypt296 // 2. decrypt
286 if(!crypto_key_.empty()) decrypt(body, head);297 if(!crypto_key_.empty()) decrypt(body, head);
@@ -293,33 +304,33 @@
293304
294}305}
295 306
296void dccl::DCCLCodec::encode_private(std::vector<Message>::iterator it,307void goby::acomms::DCCLCodec::encode_private(std::vector<DCCLMessage>::iterator it,
297 modem::Message& out_msg,308 ModemMessage& out_msg,
298 const std::map<std::string, std::vector<MessageVal> >& in)309 const std::map<std::string, std::vector<DCCLMessageVal> >& in)
299{310{
300 std::string out;311 std::string out;
301 encode_private(it, out, in);312 encode_private(it, out, in);
302313
303 dccl::DCCLHeaderDecoder head_dec(out);314 DCCLHeaderDecoder head_dec(out);
304315
305 out_msg.set_data(out);316 out_msg.set_data(out);
306 317
307 MessageVal& t = head_dec[acomms::head_time];318 DCCLMessageVal& t = head_dec[head_time];
308 MessageVal& src = head_dec[acomms::head_src_id];319 DCCLMessageVal& src = head_dec[head_src_id];
309 MessageVal& dest = head_dec[acomms::head_dest_id];320 DCCLMessageVal& dest = head_dec[head_dest_id];
310321
311 out_msg.set_t(long(t));322 out_msg.set_time(double(t));
312 out_msg.set_src(long(src));323 out_msg.set_src(long(src));
313 out_msg.set_dest(long(dest));324 out_msg.set_dest(long(dest));
314}325}
315326
316void dccl::DCCLCodec::decode_private(std::vector<Message>::iterator it,327void goby::acomms::DCCLCodec::decode_private(std::vector<DCCLMessage>::iterator it,
317 const modem::Message& in_msg,328 const ModemMessage& in_msg,
318 std::map<std::string,std::vector<MessageVal> >& out)329 std::map<std::string,std::vector<DCCLMessageVal> >& out)
319{ decode_private(it, in_msg.data(), out); }330{ decode_private(it, in_msg.data(), out); }
320331
321332
322void dccl::DCCLCodec::set_crypto_passphrase(const std::string& s)333void goby::acomms::DCCLCodec::set_crypto_passphrase(const std::string& s)
323{334{
324 using namespace CryptoPP;335 using namespace CryptoPP;
325336
@@ -328,7 +339,7 @@
328}339}
329340
330341
331void dccl::DCCLCodec::encrypt(std::string& s, const std::string& nonce)342void goby::acomms::DCCLCodec::encrypt(std::string& s, const std::string& nonce)
332{343{
333 using namespace CryptoPP;344 using namespace CryptoPP;
334345
@@ -346,7 +357,7 @@
346 s = cipher;357 s = cipher;
347}358}
348359
349void dccl::DCCLCodec::decrypt(std::string& s, const std::string& nonce)360void goby::acomms::DCCLCodec::decrypt(std::string& s, const std::string& nonce)
350{361{
351 using namespace CryptoPP;362 using namespace CryptoPP;
352363
353364
=== modified file 'src/acomms/libdccl/dccl.h'
--- src/acomms/libdccl/dccl.h 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/dccl.h 2010-07-15 12:38:39 +0000
@@ -1,5 +1,5 @@
1// copyright 2009 t. schneider tes@mit.edu1// copyright 2009 t. schneider tes@mit.edu
2// 2 //
3// this file is part of the Dynamic Compact Control Language (DCCL),3// this file is part of the Dynamic Compact Control Language (DCCL),
4// the goby-acomms codec. goby-acomms is a collection of libraries 4// the goby-acomms codec. goby-acomms is a collection of libraries
5// for acoustic underwater networking5// for acoustic underwater networking
@@ -20,7 +20,6 @@
20#ifndef DCCL20091211H20#ifndef DCCL20091211H
21#define DCCL20091211H21#define DCCL20091211H
2222
23#include <ctime>
24#include <string>23#include <string>
25#include <set>24#include <set>
26#include <map>25#include <map>
@@ -28,494 +27,495 @@
28#include <stdexcept>27#include <stdexcept>
29#include <vector>28#include <vector>
3029
31#include "acomms/xml/xml_parser.h"30#include "goby/acomms/xml/xml_parser.h"
31#include "goby/util/time.h"
3232
33#include "message.h"33#include "message.h"
34#include "message_val.h"34#include "message_val.h"
3535
36/// \brief contains Dynamic Compact Control Language objects.36namespace goby
37///
38/// Use \code #include <goby/acomms/dccl.h> \endcode to gain access to all these objects.
39namespace dccl
40{37{
4138
42 /// use this for displaying a human readable version39 namespace acomms
43 template<typename Value>40 {
44 std::ostream& operator<< (std::ostream& out, const std::map<std::string, Value>& m)41
45 {42 /// use this for displaying a human readable version
46 typedef std::pair<std::string, Value> P;43 template<typename Value>
47 BOOST_FOREACH(const P& p, m)44 std::ostream& operator<< (std::ostream& out, const std::map<std::string, Value>& m)
48 {45 {
49 out << "\t" << "key: " << p.first << std::endl46 typedef std::pair<std::string, Value> P;
50 << "\t" << "value: " << p.second << std::endl;47 BOOST_FOREACH(const P& p, m)
51 }48 {
52 return out;49 out << "\t" << "key: " << p.first << std::endl
53 }50 << "\t" << "value: " << p.second << std::endl;
5451 }
55 template<typename Value>52 return out;
56 std::ostream& operator<< (std::ostream& out, const std::multimap<std::string, Value>& m)53 }
57 {54
58 typedef std::pair<std::string, Value> P;55 template<typename Value>
59 BOOST_FOREACH(const P& p, m)56 std::ostream& operator<< (std::ostream& out, const std::multimap<std::string, Value>& m)
60 {57 {
61 out << "\t" << "key: " << p.first << std::endl58 typedef std::pair<std::string, Value> P;
62 << "\t" << "value: " << p.second << std::endl;59 BOOST_FOREACH(const P& p, m)
63 }60 {
64 return out;61 out << "\t" << "key: " << p.first << std::endl
65 }62 << "\t" << "value: " << p.second << std::endl;
6663 }
67 64 return out;
68 /// use this for displaying a human readable version of this STL object65 }
69 std::ostream& operator<< (std::ostream& out, const std::set<unsigned>& s);66
70 /// use this for displaying a human readable version of this STL object67
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
7269 std::ostream& operator<< (std::ostream& out, const std::set<unsigned>& s);
7370 /// use this for displaying a human readable version of this STL object
74 71 std::ostream& operator<< (std::ostream& out, const std::set<std::string>& s);
75 /// provides an API to the Dynamic CCL Codec.72
76 class DCCLCodec 73
77 {74
78 public:75 /// provides an API to the Dynamic CCL Codec.
79 /// \name Constructors/Destructor76 class DCCLCodec
80 //@{ 77 {
81 /// \brief Instantiate with no XML files.78 public:
82 DCCLCodec();79 /// \name Constructors/Destructor
83 /// \brief Instantiate with a single XML file.80 //@{
84 ///81 /// \brief Instantiate with no XML files.
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();
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.
87 DCCLCodec(const std::string& file, const std::string schema = "");84 ///
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.
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).
90 ///87 DCCLCodec(const std::string& file, const std::string schema = "");
91 /// \param files set of paths to XML message files to parse for use by the codec.88
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.
93 DCCLCodec(const std::set<std::string>& files, const std::string schema = "");90 ///
9491 /// \param files set of paths to XML message files to parse for use by the codec.
95 /// destructor92 /// \param schema path (absolute or relative to the XML file path) for the validating schema (message_schema.xsd) (optional).
96 ~DCCLCodec() {}93 DCCLCodec(const std::set<std::string>& files, const std::string schema = "");
97 //@}94
98 95 /// destructor
99 /// \name Initialization Methods.96 ~DCCLCodec() {}
100 ///97 //@}
101 /// These methods are intended to be called before doing any work with the class. However,98
102 /// they may be called at any time as desired.99 /// \name Initialization Methods.
103 //@{ 100 ///
104101 /// These methods are intended to be called before doing any work with the class. However,
105 /// \brief Add more messages to this instance of the codec.102 /// they may be called at any time as desired.
106 ///103 //@{
107 /// \param xml_file path to the xml file to parse and add to this codec.104
108 /// \param xml_schema path to the message_schema.xsd file to validate XML with. if using a relative path this105 /// \brief Add more messages to this instance of the codec.
109 /// must be relative to the directory of the xml_file, not the present working directory. if not provided106 ///
110 /// no validation is done.107 /// \param xml_file path to the xml file to parse and add to this codec.
111 /// \return returns id of the last message file parsed. note that there can be more than one message in a file108 /// \param xml_schema path to the message_schema.xsd file to validate XML with. if using a relative path this
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
113110 /// no validation is done.
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
115 /// 112 std::set<unsigned> add_xml_message_file(const std::string& xml_file, const std::string xml_schema = "");
116 /// location is relative to the XML file location!113
117 /// if you have XML files in different places you must pass the114 /// \brief Set the schema used for xml syntax checking.
118 /// proper relative path (or just use absolute paths)115 ///
119 /// \param schema location of the message_schema.xsd file116 /// location is relative to the XML file location!
120 void set_schema(const std::string& schema) { xml_schema_ = schema; }117 /// if you have XML files in different places you must pass the
121118 /// proper relative path (or just use absolute paths)
122 /// \brief Set a passphrase for encrypting all messages with119 /// \param schema location of the message_schema.xsd file
123 /// 120 void set_schema(const std::string& schema) { xml_schema_ = schema; }
124 /// \param passphrase text passphrase121
125 void set_crypto_passphrase(const std::string& passphrase);122 /// \brief Set a passphrase for encrypting all messages with
126123 ///
127 /// \brief Set the %modem id for this vehicle.124 /// \param passphrase text passphrase
128 ///125 void set_crypto_passphrase(const std::string& passphrase);
129 /// \param modem_id unique (within a network) number representing the %modem on this vehicle.126
130 void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; }127 /// \brief Set the %modem id for this vehicle.
131128 ///
132 129 /// \param modem_id unique (within a network) number representing the %modem on this vehicle.
133 130 void set_modem_id(unsigned modem_id) { modem_id_ = modem_id; }
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
135 ///132
136 /// \param name name of the algorithm (\xmltag{... algorithm="name"})133
137 /// \param func has the form void name(dccl::MessageVal& val_to_edit) (see dccl::AdvAlgFunction1). can be a function pointer (&name) or134 /// \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.
138 /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html)135 ///
139 void add_algorithm(const std::string& name, AlgFunction1 func);136 /// \param name name of the algorithm (\xmltag{... algorithm="name"})
140 137 /// \param func has the form void name(MessageVal& val_to_edit) (see AdvAlgFunction1). can be a function pointer (&name) or
141 /// \brief Add an advanced algorithm callback for any DCCL C++ type that may also require knowledge of all the other message variables138 /// any function object supported by boost::function (http://www.boost.org/doc/libs/1_34_0/doc/html/function.html)
142 /// and can optionally have additional parameters139 void add_algorithm(const std::string& name, AlgFunction1 func);
143 ///140
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
145 /// \param func has the form142 /// and can optionally have additional parameters
146 /// void name(MessageVal& val_to_edit,143 ///
147 /// const std::vector<std::string> params,144 /// \param name name of the algorithm (\xmltag{... algorithm="name:param1:param2"})
148 /// const std::map<std::string,MessageVal>& vals) (see dccl::AdvAlgFunction3). func can be a function pointer (&name) or145 /// \param func has the form
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,
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,
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
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).
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.
154 151 /// \param vals (passed to func) a map of \ref tag_name to current values for all message variables.
155 /// \name Codec functions.152 void add_adv_algorithm(const std::string& name, AlgFunction2 func);
156 ///153 //@}
157 /// This is where the real work happens.154
158 //@{ 155 /// \name Codec functions.
159 /// \brief Encode a message.156 ///
160 ///157 /// This is where the real work happens.
161 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)158 //@{
162 /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem159 /// \brief Encode a message.
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 ///
164 template<typename Key>161 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)
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
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.
167 {164 template<typename Key>
168 std::map<std::string, std::vector<MessageVal> > vm;165 void encode(const Key& k, std::string& hex,
169166 const std::map<std::string, DCCLMessageVal>& m)
170 typedef std::pair<std::string,MessageVal> P;167 {
171 BOOST_FOREACH(const P& p, m)168 std::map<std::string, std::vector<DCCLMessageVal> > vm;
172 vm.insert(std::pair<std::string,std::vector<MessageVal> >(p.first, p.second));169
173 170 typedef std::pair<std::string,DCCLMessageVal> P;
174 encode_private(to_iterator(k), hex, vm);171 BOOST_FOREACH(const P& p, m)
175 }172 vm.insert(std::pair<std::string,std::vector<DCCLMessageVal> >(p.first, p.second));
176173
177 /// \brief Encode a message.174 encode_private(to_iterator(k), hex, vm);
178 ///175 }
179 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)176
180 /// \param hex location for the encoded hexadecimal to be stored. this is suitable for sending to the Micro-Modem177 /// \brief Encode a message.
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 ///
182 template<typename Key>179 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)
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
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.
185 { encode_private(to_iterator(k), hex, m); }182 template<typename Key>
186183 void encode(const Key& k, std::string& hex,
187 184 const std::map<std::string, std::vector<DCCLMessageVal> >& m)
188 /// \brief Decode a message.185 { encode_private(to_iterator(k), hex, m); }
189 ///186
190 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message187
191 /// \param hex the hexadecimal to be decoded.188 /// \brief Decode a message.
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 ///
193 template<typename Key>190 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message
194 void decode(const Key& k, const std::string& hex,191 /// \param hex the hexadecimal to be decoded.
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.
196 {193 template<typename Key>
197 std::map<std::string, std::vector<MessageVal> > vm;194 void decode(const Key& k, const std::string& hex,
198195 std::map<std::string, DCCLMessageVal>& m)
199 decode_private(to_iterator(k), hex, vm);196 {
200 197 std::map<std::string, std::vector<DCCLMessageVal> > vm;
201 typedef std::pair<std::string,std::vector<MessageVal> > P;198
202 BOOST_FOREACH(const P& p, vm)199 decode_private(to_iterator(k), hex, vm);
203 m.insert(std::pair<std::string,MessageVal>(p.first, MessageVal(p.second)));200
204 }201 typedef std::pair<std::string,std::vector<DCCLMessageVal> > P;
205 202 BOOST_FOREACH(const P& p, vm)
206 /// \brief Decode a message.203 m.insert(std::pair<std::string,DCCLMessageVal>(p.first, DCCLMessageVal(p.second)));
207 ///204 }
208 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message205
209 /// \param hex the hexadecimal to be decoded.206 /// \brief Decode a message.
210 /// \param m map of std::string (\ref tag_name) to dccl::MessageVal to store the values to be decoded207 ///
211 template<typename Key>208 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message
212 void decode(const Key& k, const std::string& hex,209 /// \param hex the hexadecimal to be decoded.
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
214 { decode_private(to_iterator(k), hex, m); }211 template<typename Key>
215212 void decode(const Key& k, const std::string& hex,
216 213 std::map<std::string, std::vector<DCCLMessageVal> >& m)
217 //@}214 { decode_private(to_iterator(k), hex, m); }
218 215
219 /// \name Informational Methods216
220 ///217 //@}
221 //@{ 218
222 /// long summary of a message for a given Key (std::string name or unsigned id)219 /// \name Informational Methods
223 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)220 ///
224 template<typename Key>221 //@{
225 std::string summary(const Key& k) const222 /// long summary of a message for a given Key (std::string name or unsigned id)
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)
227 /// long summary of a message for all loaded messages224 template<typename Key>
228 std::string summary() const;225 std::string summary(const Key& k) const
229226 { return to_iterator(k)->get_display(); }
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
231 template<typename Key>228 std::string summary() const;
232 std::string brief_summary(const Key& k) const229
233 { return to_iterator(k)->get_short_display(); }230 /// brief summary of a message for a given Key (std::string name or unsigned id)
234 /// brief summary of a message for all loaded messages231 template<typename Key>
235 std::string brief_summary() const;232 std::string brief_summary(const Key& k) const
236233 { return to_iterator(k)->get_short_display(); }
237 /// how many message are loaded?234 /// brief summary of a message for all loaded messages
238 /// \return number of messages loaded235 std::string brief_summary() const;
239 unsigned message_count() { return messages_.size(); }236
240237 /// how many message are loaded?
241 /// \return repeat value (number of copies of the message per encode)238 /// \return number of messages loaded
242 template<typename Key>239 unsigned message_count() { return messages_.size(); }
243 unsigned get_repeat(const Key& k)240
244 { return to_iterator(k)->repeat(); }241 /// \return repeat value (number of copies of the message per encode)
245 242 template<typename Key>
246 /// \return set of all message ids loaded243 unsigned get_repeat(const Key& k)
247 std::set<unsigned> all_message_ids();244 { return to_iterator(k)->repeat(); }
248 /// \return set of all message names loaded245
249 std::set<std::string> all_message_names();246 /// \return set of all message ids loaded
250 /// \return map of names to DCCL types needed to encode a given message247 std::set<unsigned> all_message_ids();
251 template<typename Key>248 /// \return set of all message names loaded
252 std::map<std::string, std::string> message_var_names(const Key& k) const249 std::set<std::string> all_message_names();
253 { return to_iterator(k)->message_var_names(); }250 /// \return map of names to DCCL types needed to encode a given message
254 251 template<typename Key>
255 /// \param id message id252 std::map<std::string, std::string> message_var_names(const Key& k) const
256 /// \return name of message253 { return to_iterator(k)->message_var_names(); }
257 std::string id2name(unsigned id) {return to_iterator(id)->name();}254
258 /// \param name message name255 /// \param id message id
259 /// \return id of message256 /// \return name of message
260 unsigned name2id(const std::string& name) {return to_iterator(name)->id();}257 std::string id2name(unsigned id) {return to_iterator(id)->name();}
261 //@}258 /// \param name message name
262259 /// \return id of message
263260 unsigned name2id(const std::string& name) {return to_iterator(name)->id();}
264 /// \name Publish/subscribe architecture related methods261 //@}
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 for262
266 /// <ul>263
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
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
269 /// <li> decoding to an arbitrarily formatted string (similar concept to printf) </li>266 /// <ul>
270 /// </ul>267 /// <li> message creation triggering (a message is encoded on a certain event, either time based or publish based) </li>
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>
272 269 /// <li> decoding to an arbitrarily formatted string (similar concept to printf) </li>
273 //@{270 /// </ul>
274 /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags271 /// These methods will be useful if you are interested in any of the features mentioned above.
275 ///272
276 /// Values can be passed in on one or more maps of names to values, similar to DCCLCodec::encode. 273 //@{
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
278 /// This differs substantially from the behavior of encode above.275 ///
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.
280 /*! \verbatim277 /// Casts are made and string parsing of key=value comma delimited fields is performed.
281 <int>278 /// This differs substantially from the behavior of encode above.
282 <name>myint</name>279 /// For example, take this message variable:
283 <src_var>somevar</src_var>280 /*! \verbatim
284 </int> \endverbatim281 <int>
285 */282 <name>myint</name>
286 ///283 <src_var>somevar</src_var>
287 /// Using this method you can pass vals["somevar"] = "mystring=foo,blah=dog,myint=32"284 </int> \endverbatim
288 /// or vals["somevar"] = 32.0285 */
289 /// and both cases will properly parse out 32 as the value for this field.286 ///
290 /// In comparison, using the normal encode you would pass vals["myint"] = 32287 /// Using this method you can pass vals["somevar"] = "mystring=foo,blah=dog,myint=32"
291 ///288 /// or vals["somevar"] = 32.0
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.
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
294 /// \param vals map of source variable name to dccl::MessageVal values. 291 ///
295 template<typename Key>292 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)
296 void pubsub_encode(const Key& k,293 /// \param msg ModemMessage or std::string for encoded message to be stored.
297 modem::Message& msg,294 /// \param vals map of source variable name to MessageVal values.
298 const std::map<std::string, std::vector<dccl::MessageVal> >& pubsub_vals)295 template<typename Key>
299 {296 void pubsub_encode(const Key& k,
300 std::vector<dccl::Message>::iterator it = to_iterator(k);297 ModemMessage& msg,
301298 const std::map<std::string, std::vector<DCCLMessageVal> >& pubsub_vals)
302 std::map<std::string, std::vector<dccl::MessageVal> > vals;299 {
303 // clean the pubsub vals into dccl vals300 std::vector<DCCLMessage>::iterator it = to_iterator(k);
304 // using <src_var/> tag, do casts from double, pull strings from key=value,key=value, etc.301
305 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, it->layout())302 std::map<std::string, std::vector<DCCLMessageVal> > vals;
306 mv->read_pubsub_vars(vals, pubsub_vals);303 // clean the pubsub vals into dccl vals
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.
308 mv->read_pubsub_vars(vals, pubsub_vals);305 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, it->layout())
309 306 mv->read_pubsub_vars(vals, pubsub_vals);
310 encode_private(it, msg, vals);307 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, it->header())
311 }308 mv->read_pubsub_vars(vals, pubsub_vals);
312309
313 /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags310 encode_private(it, msg, vals);
314 /// 311 }
315 /// Use this version if you do not have vectors of src_var values312
316 template<typename Key>313 /// \brief Encode a message using \ref tag_src_var tags instead of \ref tag_name tags
317 void pubsub_encode(const Key& k,314 ///
318 modem::Message& msg,315 /// Use this version if you do not have vectors of src_var values
319 const std::map<std::string, MessageVal>& pubsub_vals)316 template<typename Key>
320 {317 void pubsub_encode(const Key& k,
321 std::map<std::string, std::vector<MessageVal> > vm;318 ModemMessage& msg,
322319 const std::map<std::string, DCCLMessageVal>& pubsub_vals)
323 typedef std::pair<std::string,MessageVal> P;320 {
324 BOOST_FOREACH(const P& p, pubsub_vals)321 std::map<std::string, std::vector<DCCLMessageVal> > vm;
325 vm.insert(std::pair<std::string,std::vector<MessageVal> >(p.first, p.second));322
326 323 typedef std::pair<std::string,DCCLMessageVal> P;
327 pubsub_encode(k, msg, vm);324 BOOST_FOREACH(const P& p, pubsub_vals)
328 }325 vm.insert(std::pair<std::string,std::vector<DCCLMessageVal> >(p.first, p.second));
329326
330 327 pubsub_encode(k, msg, vm);
331 /// \brief Decode a message using formatting specified in \ref tag_publish tags.328 }
332 ///329
333 /// Values will be received in two maps, one of strings and the other of doubles. The \ref tag_publish value will be placed330
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.
335 ///332 ///
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
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.
338 /// \param vals pointer to std::multimap of publish variable name to std::string values.335 ///
339 template<typename Key>336 /// \param k can either be std::string (the name of the message) or unsigned (the id of the message)
340 void pubsub_decode(const Key& k,337 /// \param msg ModemMessage or std::string to be decode.
341 const modem::Message& msg,338 /// \param vals pointer to std::multimap of publish variable name to std::string values.
342 std::multimap<std::string, dccl::MessageVal>& pubsub_vals)339 template<typename Key>
340 void pubsub_decode(const Key& k,
341 const ModemMessage& msg,
342 std::multimap<std::string, DCCLMessageVal>& pubsub_vals)
343 343
344 {344 {
345 std::vector<dccl::Message>::iterator it = to_iterator(k);345 std::vector<DCCLMessage>::iterator it = to_iterator(k);
346346
347 std::map<std::string, std::vector<dccl::MessageVal> > vals;347 std::map<std::string, std::vector<DCCLMessageVal> > vals;
348 decode_private(it, msg, vals);348 decode_private(it, msg, vals);
349349
350 // go through all the publishes_ and fill in the format strings350 // go through all the publishes_ and fill in the format strings
351 BOOST_FOREACH(Publish& p, it->publishes())351 BOOST_FOREACH(DCCLPublish& p, it->publishes())
352 p.write_publish(vals, pubsub_vals);352 p.write_publish(vals, pubsub_vals);
353 }353 }
354 354
355 355
356 /// what moos variables do i need to provide to create a message with a call to encode_using_src_vars356 /// what moos variables do i need to provide to create a message with a call to encode_using_src_vars
357 template<typename Key>357 template<typename Key>
358 std::set<std::string> get_pubsub_src_vars(const Key& k)358 std::set<std::string> get_pubsub_src_vars(const Key& k)
359 { return to_iterator(k)->get_pubsub_src_vars(); }359 { return to_iterator(k)->get_pubsub_src_vars(); }
360360
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)
362 template<typename Key>362 template<typename Key>
363 std::set<std::string> get_pubsub_all_vars(const Key& k)363 std::set<std::string> get_pubsub_all_vars(const Key& k)
364 { return to_iterator(k)->get_pubsub_all_vars(); }364 { return to_iterator(k)->get_pubsub_all_vars(); }
365365
366 /// all architecture variables needed for encoding (includes trigger)366 /// all architecture variables needed for encoding (includes trigger)
367 template<typename Key>367 template<typename Key>
368 std::set<std::string> get_pubsub_encode_vars(const Key& k)368 std::set<std::string> get_pubsub_encode_vars(const Key& k)
369 { return to_iterator(k)->get_pubsub_encode_vars(); }369 { return to_iterator(k)->get_pubsub_encode_vars(); }
370370
371 /// for a given message, all architecture variables for decoding (input)371 /// for a given message, all architecture variables for decoding (input)
372 template<typename Key>372 template<typename Key>
373 std::set<std::string> get_pubsub_decode_vars(const Key& k)373 std::set<std::string> get_pubsub_decode_vars(const Key& k)
374 { return to_iterator(k)->get_pubsub_decode_vars(); }374 { return to_iterator(k)->get_pubsub_decode_vars(); }
375 375
376 /// returns outgoing architecture hexadecimal variable376 /// returns outgoing architecture hexadecimal variable
377 template<typename Key>377 template<typename Key>
378 std::string get_outgoing_hex_var(const Key& k)378 std::string get_outgoing_hex_var(const Key& k)
379 { return to_iterator(k)->out_var(); }379 { return to_iterator(k)->out_var(); }
380380
381 /// returns incoming architecture hexadecimal variable381 /// returns incoming architecture hexadecimal variable
382 template<typename Key>382 template<typename Key>
383 std::string get_incoming_hex_var(const Key& k)383 std::string get_incoming_hex_var(const Key& k)
384 { return to_iterator(k)->in_var(); }384 { return to_iterator(k)->in_var(); }
385385
386 386
387 /// \brief look if key / value are trigger for any loaded messages387 /// \brief look if key / value are trigger for any loaded messages
388 /// if so, store to id and return true388 /// if so, store to id and return true
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);
390390
391 /// \brief look if the time is right for trigger for any loaded messages391 /// \brief look if the time is right for trigger for any loaded messages
392 /// if so, store to id and return true392 /// if so, store to id and return true
393 bool is_time_trigger(std::set<unsigned>& id);393 bool is_time_trigger(std::set<unsigned>& id);
394394
395 /// \brief see if this key is for an incoming message395 /// \brief see if this key is for an incoming message
396 /// if so, return id for decoding396 /// if so, return id for decoding
397 bool is_incoming(unsigned& id, const std::string& key);397 bool is_incoming(unsigned& id, const std::string& key);
398 //@}398 //@}
399399
400 400
401 // returns a reference to all Message objects.401 // returns a reference to all DCCLMessage objects.
402402
403 // this is only used if one needs more control than DCCLCodec403 // this is only used if one needs more control than DCCLCodec
404 // provides404 // provides
405 std::vector<Message>& messages() {return messages_;}405 std::vector<DCCLMessage>& messages() {return messages_;}
406 406
407407
408 /// \example libdccl/examples/dccl_simple/dccl_simple.cpp408 /// \example libdccl/examples/dccl_simple/dccl_simple.cpp
409 /// simple.xml409 /// simple.xml
410 /// \verbinclude dccl_simple/simple.xml410 /// \verbinclude dccl_simple/simple.xml
411 /// dccl_simple.cpp411 /// dccl_simple.cpp
412 412
413 /// \example libdccl/examples/plusnet/plusnet.cpp413 /// \example libdccl/examples/plusnet/plusnet.cpp
414 /// nafcon_command.xml414 /// nafcon_command.xml
415 /// \verbinclude nafcon_command.xml415 /// \verbinclude nafcon_command.xml
416 /// nafcon_report.xml416 /// nafcon_report.xml
417 /// \verbinclude nafcon_report.xml417 /// \verbinclude nafcon_report.xml
418 /// plusnet.cpp418 /// plusnet.cpp
419 419
420 /// \example libdccl/examples/test/test.cpp420 /// \example libdccl/examples/test/test.cpp
421 /// test.xml421 /// test.xml
422 /// \verbinclude test.xml 422 /// \verbinclude test.xml
423 /// test.cpp423 /// test.cpp
424 424
425 /// \example libdccl/examples/two_message/two_message.cpp425 /// \example libdccl/examples/two_message/two_message.cpp
426 /// two_message.xml426 /// two_message.xml
427 /// \verbinclude two_message.xml427 /// \verbinclude two_message.xml
428 /// two_message.cpp428 /// two_message.cpp
429429
430 /// \example acomms/examples/chat/chat.cpp430 /// \example acomms/examples/chat/chat.cpp
431 431
432 private:432 private:
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;
434 std::vector<Message>::iterator to_iterator(const std::string& message_name);434 std::vector<DCCLMessage>::iterator to_iterator(const std::string& message_name);
435 std::vector<Message>::const_iterator to_iterator(const unsigned& id) const;435 std::vector<DCCLMessage>::const_iterator to_iterator(const unsigned& id) const;
436 std::vector<Message>::iterator to_iterator(const unsigned& id); 436 std::vector<DCCLMessage>::iterator to_iterator(const unsigned& id);
437437
438 // in map not passed by reference because we want to be able to modify it438 // in map not passed by reference because we want to be able to modify it
439 void encode_private(std::vector<Message>::iterator it,439 void encode_private(std::vector<DCCLMessage>::iterator it,
440 std::string& out,440 std::string& out,
441 std::map<std::string, std::vector<MessageVal> > in);441 std::map<std::string, std::vector<DCCLMessageVal> > in);
442442
443 // in string not passed by reference because we want to be able to modify it443 // in string not passed by reference because we want to be able to modify it
444 void decode_private(std::vector<Message>::iterator it,444 void decode_private(std::vector<DCCLMessage>::iterator it,
445 std::string in,445 std::string in,
446 std::map<std::string, std::vector<MessageVal> >& out);446 std::map<std::string, std::vector<DCCLMessageVal> >& out);
447 447
448 void encode_private(std::vector<Message>::iterator it,448 void encode_private(std::vector<DCCLMessage>::iterator it,
449 modem::Message& out_msg,449 ModemMessage& out_msg,
450 const std::map<std::string, std::vector<MessageVal> >& in);450 const std::map<std::string, std::vector<DCCLMessageVal> >& in);
451 451
452 void decode_private(std::vector<Message>::iterator it,452 void decode_private(std::vector<DCCLMessage>::iterator it,
453 const modem::Message& in_msg,453 const ModemMessage& in_msg,
454 std::map<std::string, std::vector<MessageVal> >& out);454 std::map<std::string, std::vector<DCCLMessageVal> >& out);
455 455
456 void check_duplicates();456 void check_duplicates();
457457
458 458
459 void encrypt(std::string& s, const std::string& nonce);459 void encrypt(std::string& s, const std::string& nonce);
460 void decrypt(std::string& s, const std::string& nonce);460 void decrypt(std::string& s, const std::string& nonce);
461 461
462 private:462 private:
463 std::vector<Message> messages_;463 std::vector<DCCLMessage> messages_;
464 std::map<std::string, size_t> name2messages_;464 std::map<std::string, size_t> name2messages_;
465 std::map<unsigned, size_t> id2messages_;465 std::map<unsigned, size_t> id2messages_;
466466
467 std::string xml_schema_;467 std::string xml_schema_;
468 time_t start_time_;468 boost::posix_time::ptime start_time_;
469469
470 unsigned modem_id_;470 unsigned modem_id_;
471 471
472 std::string crypto_key_;472 std::string crypto_key_;
473 };473 };
474474
475 /// outputs information about all available messages (same as std::string summary())475 /// outputs information about all available messages (same as std::string summary())
476 std::ostream& operator<< (std::ostream& out, const DCCLCodec& d);476 std::ostream& operator<< (std::ostream& out, const DCCLCodec& d);
477477
478478
479 class DCCLHeaderEncoder479 class DCCLHeaderEncoder
480 {480 {
481 public:481 public:
482 DCCLHeaderEncoder(const std::map<std::string, std::vector<MessageVal> >& in)482 DCCLHeaderEncoder(const std::map<std::string, std::vector<DCCLMessageVal> >& in)
483 {483 {
484 std::map<std::string, std::vector<MessageVal> > in_copy = in;484 std::map<std::string, std::vector<DCCLMessageVal> > in_copy = in;
485 msg_.head_encode(encoded_, in_copy);485 msg_.head_encode(encoded_, in_copy);
486 hex_encode(encoded_);486 hex_encode(encoded_);
487 }487 }
488 std::string& get() { return encoded_; }488 std::string& get() { return encoded_; }
489489
490 private:490 private:
491 Message msg_;491 DCCLMessage msg_;
492 std::string encoded_; 492 std::string encoded_;
493 };493 };
494494
495 class DCCLHeaderDecoder495 class DCCLHeaderDecoder
496 {496 {
497 public:497 public:
498 DCCLHeaderDecoder(const std::string& in_orig)498 DCCLHeaderDecoder(const std::string& in_orig)
499 {499 {
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);
501 hex_decode(in); 501 hex_decode(in);
502 msg_.head_decode(in, decoded_);502 msg_.head_decode(in, decoded_);
503 } 503 }
504 std::map<std::string, std::vector<MessageVal> >& get() { return decoded_; }504 std::map<std::string, std::vector<DCCLMessageVal> >& get() { return decoded_; }
505 MessageVal& operator[] (const std::string& s)505 DCCLMessageVal& operator[] (const std::string& s)
506 { return decoded_[s][0]; }506 { return decoded_[s][0]; }
507 MessageVal& operator[] (acomms::DCCLHeaderPart p)507 DCCLMessageVal& operator[] (DCCLHeaderPart p)
508 { return decoded_[acomms::to_str(p)][0]; }508 { return decoded_[to_str(p)][0]; }
509509
510 510
511 private:511 private:
512 Message msg_;512 DCCLMessage msg_;
513 std::map<std::string, std::vector<MessageVal> > decoded_;513 std::map<std::string, std::vector<DCCLMessageVal> > decoded_;
514 };514 };
515515
516 516
517 }
517}518}
518519
519520
520
521#endif521#endif
522522
=== modified file 'src/acomms/libdccl/dccl_constants.h'
--- src/acomms/libdccl/dccl_constants.h 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/dccl_constants.h 2010-07-15 12:38:39 +0000
@@ -28,9 +28,12 @@
28#include <crypto++/filters.h>28#include <crypto++/filters.h>
29#include <crypto++/hex.h>29#include <crypto++/hex.h>
3030
31#include "acomms/acomms_constants.h"31#include "goby/acomms/acomms_constants.h"
3232
33namespace dccl33namespace goby
34{
35
36namespace acomms
34{37{
3538
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_double39/// 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
@@ -111,5 +114,5 @@
111 114
112115
113}116}
114117}
115#endif118#endif
116119
=== modified file 'src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt'
--- src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt 2010-01-22 02:52:25 +0000
+++ src/acomms/libdccl/examples/dccl_simple/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(dccl_simple dccl_simple.cpp)1add_executable(dccl_simple dccl_simple.cpp)
2target_link_libraries(dccl_simple dccl)
3\ No newline at end of file2\ No newline at end of file
3target_link_libraries(dccl_simple goby_dccl)
4\ No newline at end of file4\ No newline at end of file
55
=== modified file 'src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp'
--- src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp 2010-03-15 16:21:43 +0000
+++ src/acomms/libdccl/examples/dccl_simple/dccl_simple.cpp 2010-07-15 12:38:39 +0000
@@ -17,17 +17,17 @@
17// encodes/decodes a string using the DCCL codec library17// encodes/decodes a string using the DCCL codec library
18// assumes prior knowledge of the message format (required fields)18// assumes prior knowledge of the message format (required fields)
1919
20#include "acomms/dccl.h"20#include "goby/acomms/dccl.h"
21#include <iostream>21#include <iostream>
2222
23using dccl::operator<<;23using goby::acomms::operator<<;
2424
25int main()25int main()
26{26{
27 // initialize input contents to encoder. since27 // initialize input contents to encoder. since
28 // simple.xml only has a <string/> message var28 // simple.xml only has a <string/> message var
29 // we only need one map.29 // we only need one map.
30 std::map<std::string, dccl::MessageVal> val_map;30 std::map<std::string, goby::acomms::DCCLMessageVal> val_map;
3131
32 // initialize output hexadecimal32 // initialize output hexadecimal
33 std::string hex;33 std::string hex;
@@ -37,7 +37,7 @@
37 // instantiate the parser with a single xml file (simple.xml).37 // instantiate the parser with a single xml file (simple.xml).
38 // also pass the schema, relative to simple.xml, for XML validity38 // also pass the schema, relative to simple.xml, for XML validity
39 // checking (syntax).39 // checking (syntax).
40 dccl::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml",40 goby::acomms::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml",
41 "../../message_schema.xsd");41 "../../message_schema.xsd");
4242
43 43
4444
=== modified file 'src/acomms/libdccl/examples/delta/CMakeLists.txt'
--- src/acomms/libdccl/examples/delta/CMakeLists.txt 2010-03-05 03:32:48 +0000
+++ src/acomms/libdccl/examples/delta/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(delta delta.cpp)1add_executable(delta delta.cpp)
2target_link_libraries(delta dccl)
3\ No newline at end of file2\ No newline at end of file
3target_link_libraries(delta goby_dccl)
4\ No newline at end of file4\ No newline at end of file
55
=== modified file 'src/acomms/libdccl/examples/delta/delta.cpp'
--- src/acomms/libdccl/examples/delta/delta.cpp 2010-03-10 01:14:38 +0000
+++ src/acomms/libdccl/examples/delta/delta.cpp 2010-07-15 12:38:39 +0000
@@ -17,22 +17,22 @@
17// encodes/decodes several fields using delta encoding17// encodes/decodes several fields using delta encoding
1818
1919
20#include "acomms/dccl.h"20#include "goby/acomms/dccl.h"
21#include <iostream>21#include <iostream>
2222
23using dccl::operator<<;23using goby::acomms::operator<<;
2424
25int main()25int main()
26{26{
27 std::vector< std::map<std::string, dccl::MessageVal> > vals_vect;27 std::vector< std::map<std::string, acomms::DCCLMessageVal> > vals_vect;
28 std::map<std::string, dccl::MessageVal> vals;28 std::map<std::string, acomms::DCCLMessageVal> vals;
29 29
30 // initialize output hexadecimal30 // initialize output hexadecimal
31 std::string hex;31 std::string hex;
32 32
33 std::cout << "loading xml file: delta.xml" << std::endl;33 std::cout << "loading xml file: delta.xml" << std::endl;
3434
35 dccl::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/delta/delta.xml",35 goby::acomms::DCCLCodec dccl(DCCL_EXAMPLES_DIR "/delta/delta.xml",
36 "../../message_schema.xsd");36 "../../message_schema.xsd");
3737
38 std::cout << dccl << std::endl;38 std::cout << dccl << std::endl;
@@ -77,7 +77,7 @@
7777
78// dccl.delta_decode(1, hex, 0, &vals_vect, 0, 0);78// dccl.delta_decode(1, hex, 0, &vals_vect, 0, 0);
79 79
80 for(std::vector< std::map<std::string, dccl::MessageVal> >::iterator80 for(std::vector< std::map<std::string, acomms::DCCLMessageVal> >::iterator
81 it = vals_vect.begin(),81 it = vals_vect.begin(),
82 n = vals_vect.end();82 n = vals_vect.end();
83 it != n;83 it != n;
8484
=== modified file 'src/acomms/libdccl/examples/plusnet/CMakeLists.txt'
--- src/acomms/libdccl/examples/plusnet/CMakeLists.txt 2009-12-18 02:50:00 +0000
+++ src/acomms/libdccl/examples/plusnet/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(plusnet plusnet.cpp)1add_executable(plusnet plusnet.cpp)
2target_link_libraries(plusnet dccl)2target_link_libraries(plusnet goby_dccl)
33
=== modified file 'src/acomms/libdccl/examples/plusnet/plusnet.cpp'
--- src/acomms/libdccl/examples/plusnet/plusnet.cpp 2010-03-20 06:09:16 +0000
+++ src/acomms/libdccl/examples/plusnet/plusnet.cpp 2010-07-15 12:38:39 +0000
@@ -20,18 +20,19 @@
2020
21// this is an example showing some of the "MOOS" related features of libdccl that can be used (if desired) in the absence of MOOS21// this is an example showing some of the "MOOS" related features of libdccl that can be used (if desired) in the absence of MOOS
2222
23#include "acomms/dccl.h"23#include "goby/acomms/dccl.h"
2424
25#include <exception>25#include <exception>
26#include <iostream>26#include <iostream>
2727
28using dccl::operator<<;28using namespace goby;
29using goby::acomms::operator<<;
2930
30int main()31int main()
31{32{
32 std::cout << "loading nafcon xml files" << std::endl;33 std::cout << "loading nafcon xml files" << std::endl;
3334
34 dccl::DCCLCodec dccl;35 acomms::DCCLCodec dccl;
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");
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");
37 38
@@ -45,10 +46,10 @@
45 << std::string(30, '#') << std::endl;46 << std::string(30, '#') << std::endl;
4647
47 // initialize input contents to encoder48 // initialize input contents to encoder
48 std::map<std::string, dccl::MessageVal> in_vals;49 std::map<std::string, acomms::DCCLMessageVal> in_vals;
4950
50 // initialize output message51 // initialize output message
51 modem::Message msg;52 acomms::ModemMessage msg;
5253
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";
5455
@@ -57,15 +58,15 @@
57 58
58 dccl.pubsub_encode("SENSOR_STATUS", msg, in_vals);59 dccl.pubsub_encode("SENSOR_STATUS", msg, in_vals);
59 60
60 std::cout << "received dccl::Message: "61 std::cout << "received acomms::DCCLMessage: "
61 << msg.serialize()62 << msg.serialize()
62 << std::endl;63 << std::endl;
6364
64 65
65 std::multimap<std::string, dccl::MessageVal> out_vals;66 std::multimap<std::string, acomms::DCCLMessageVal> out_vals;
6667
67 68
68 std::cout << "passed dccl::Message to decoder: " 69 std::cout << "passed acomms::DCCLMessage to decoder: "
69 << msg.serialize()70 << msg.serialize()
70 << std::endl;71 << std::endl;
7172
7273
=== modified file 'src/acomms/libdccl/examples/test/CMakeLists.txt'
--- src/acomms/libdccl/examples/test/CMakeLists.txt 2009-12-02 05:18:28 +0000
+++ src/acomms/libdccl/examples/test/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(dccl_test test.cpp)1add_executable(dccl_test test.cpp)
2target_link_libraries(dccl_test dccl)
3\ No newline at end of file2\ No newline at end of file
3target_link_libraries(dccl_test goby_dccl)
4\ No newline at end of file4\ No newline at end of file
55
=== modified file 'src/acomms/libdccl/examples/test/test.cpp'
--- src/acomms/libdccl/examples/test/test.cpp 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/examples/test/test.cpp 2010-07-15 12:38:39 +0000
@@ -14,41 +14,42 @@
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/>.
1515
1616
17#include "acomms/dccl.h"17#include "goby/acomms/dccl.h"
18#include <iostream>18#include <iostream>
19#include <cassert>19#include <cassert>
2020
21using dccl::operator<<;21using namespace goby;
22using goby::acomms::operator<<;
2223
23void plus1(dccl::MessageVal& mv)24void plus1(acomms::DCCLMessageVal& mv)
24{25{
25 long l = mv;26 long l = mv;
26 ++l;27 ++l;
27 mv = l;28 mv = l;
28}29}
2930
30void times2(dccl::MessageVal& mv)31void times2(acomms::DCCLMessageVal& mv)
31{32{
32 double d = mv;33 double d = mv;
33 d *= 2;34 d *= 2;
34 mv = d;35 mv = d;
35}36}
3637
37void prepend_fat(dccl::MessageVal& mv)38void prepend_fat(acomms::DCCLMessageVal& mv)
38{39{
39 std::string s = mv;40 std::string s = mv;
40 s = "fat_" + s;41 s = "fat_" + s;
41 mv = s;42 mv = s;
42}43}
4344
44void invert(dccl::MessageVal& mv)45void invert(acomms::DCCLMessageVal& mv)
45{46{
46 bool b = mv;47 bool b = mv;
47 b ^= 1;48 b ^= 1;
48 mv = b;49 mv = b;
49}50}
5051
51void algsum(dccl::MessageVal& mv, const std::vector<dccl::MessageVal>& ref_vals)52void algsum(acomms::DCCLMessageVal& mv, const std::vector<acomms::DCCLMessageVal>& ref_vals)
52{53{
53 double d = 0;54 double d = 0;
54 // index 0 is the name ("sum"), so start at 155 // index 0 is the name ("sum"), so start at 1
@@ -65,7 +66,7 @@
65 std::cout << "loading xml file: test.xml" << std::endl;66 std::cout << "loading xml file: test.xml" << std::endl;
6667
67 // instantiate the parser with a single xml file68 // instantiate the parser with a single xml file
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");
6970
70 std::cout << dccl << std::endl;71 std::cout << dccl << std::endl;
71 72
@@ -79,32 +80,32 @@
79 // must be kept secret!80 // must be kept secret!
80 dccl.set_crypto_passphrase("my_passphrase!");81 dccl.set_crypto_passphrase("my_passphrase!");
81 82
82 std::map<std::string, std::vector<dccl::MessageVal> > in;83 std::map<std::string, std::vector<acomms::DCCLMessageVal> > in;
83 84
84 bool b = true; 85 bool b = true;
85 std::vector<dccl::MessageVal> e;86 std::vector<acomms::DCCLMessageVal> e;
86 e.push_back("dog");87 e.push_back("dog");
87 e.push_back("cat");88 e.push_back("cat");
88 e.push_back("emu");89 e.push_back("emu");
89 90
90 std::string s = "raccoon"; 91 std::string s = "raccoon";
91 std::vector<dccl::MessageVal> i;92 std::vector<acomms::DCCLMessageVal> i;
92 i.push_back(30);93 i.push_back(30);
93 i.push_back(40);94 i.push_back(40);
94 std::vector<dccl::MessageVal> f;95 std::vector<acomms::DCCLMessageVal> f;
95 f.push_back(-12.5);96 f.push_back(-12.5);
96 f.push_back(1);97 f.push_back(1);
97 98
98 std::string h = "abcd1234"; 99 std::string h = "abcd1234";
99 std::vector<dccl::MessageVal> sum(2,0);100 std::vector<acomms::DCCLMessageVal> sum(2,0);
100 101
101 102
102 in["B"] = std::vector<dccl::MessageVal>(1,b);103 in["B"] = std::vector<acomms::DCCLMessageVal>(1,b);
103 in["E"] = e;104 in["E"] = e;
104 in["S"] = std::vector<dccl::MessageVal>(1,s);105 in["S"] = std::vector<acomms::DCCLMessageVal>(1,s);
105 in["I"] = i;106 in["I"] = i;
106 in["F"] = f;107 in["F"] = f;
107 in["H"] = std::vector<dccl::MessageVal>(1,h);108 in["H"] = std::vector<acomms::DCCLMessageVal>(1,h);
108 in["SUM"] = sum;109 in["SUM"] = sum;
109110
110 std::string hex;111 std::string hex;
@@ -117,7 +118,7 @@
117 hex.resize(hex.length() + 20,'0');118 hex.resize(hex.length() + 20,'0');
118 std::cout << "hex in: " << hex << std::endl; 119 std::cout << "hex in: " << hex << std::endl;
119 120
120 std::map<std::string, std::vector<dccl::MessageVal> > out;121 std::map<std::string, std::vector<acomms::DCCLMessageVal> > out;
121 122
122 dccl.decode(4, hex, out);123 dccl.decode(4, hex, out);
123 124
@@ -129,7 +130,7 @@
129 i[0] = int(i[0]) + 1;130 i[0] = int(i[0]) + 1;
130 i[1] = int(i[1]) + 1;131 i[1] = int(i[1]) + 1;
131 132
132 dccl::MessageVal tmp = b;133 acomms::DCCLMessageVal tmp = b;
133 invert(tmp);134 invert(tmp);
134 b = tmp;135 b = tmp;
135 136
136137
=== modified file 'src/acomms/libdccl/examples/test/test.xml'
--- src/acomms/libdccl/examples/test/test.xml 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/examples/test/test.xml 2010-07-15 12:38:39 +0000
@@ -2,9 +2,9 @@
2<message_set>2<message_set>
3 <message>3 <message>
4 <name>TEST</name>4 <name>TEST</name>
5 <size>256</size>5 <size>128</size>
6 <id>4</id>6 <id>4</id>
7 <repeat>5</repeat>7 <repeat/>
8 <layout>8 <layout>
9 <static>9 <static>
10 <name>Stat</name>10 <name>Stat</name>
1111
=== modified file 'src/acomms/libdccl/examples/two_message/CMakeLists.txt'
--- src/acomms/libdccl/examples/two_message/CMakeLists.txt 2009-12-02 05:18:28 +0000
+++ src/acomms/libdccl/examples/two_message/CMakeLists.txt 2010-07-15 12:38:39 +0000
@@ -1,2 +1,2 @@
1add_executable(two_message two_message.cpp)1add_executable(two_message two_message.cpp)
2target_link_libraries(two_message dccl)
3\ No newline at end of file2\ No newline at end of file
3target_link_libraries(two_message goby_dccl)
4\ No newline at end of file4\ No newline at end of file
55
=== modified file 'src/acomms/libdccl/examples/two_message/two_message.cpp'
--- src/acomms/libdccl/examples/two_message/two_message.cpp 2010-03-22 02:52:39 +0000
+++ src/acomms/libdccl/examples/two_message/two_message.cpp 2010-07-15 12:38:39 +0000
@@ -17,11 +17,12 @@
17// encodes/decodes the message given in the pGeneralCodec documentation17// encodes/decodes the message given in the pGeneralCodec documentation
18// also includes the simple.xml file to show example of DCCLCodec instantiation18// also includes the simple.xml file to show example of DCCLCodec instantiation
19// with multiple files19// with multiple files
20#include "acomms/dccl.h"20#include "goby/acomms/dccl.h"
21#include <exception>21#include <exception>
22#include <iostream>22#include <iostream>
2323
24using dccl::operator<<;24using namespace goby;
25using goby::acomms::operator<<;
2526
2627
27int main()28int main()
@@ -33,7 +34,7 @@
33 xml_files.insert(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml");34 xml_files.insert(DCCL_EXAMPLES_DIR "/dccl_simple/simple.xml");
34 xml_files.insert(DCCL_EXAMPLES_DIR "/two_message/two_message.xml");35 xml_files.insert(DCCL_EXAMPLES_DIR "/two_message/two_message.xml");
35 36
36 dccl::DCCLCodec dccl(xml_files, "../../message_schema.xsd");37 acomms::DCCLCodec dccl(xml_files, "../../message_schema.xsd");
3738
38 // show some useful information about all the loaded messages39 // show some useful information about all the loaded messages
39 std::cout << std::string(30, '#') << std::endl40 std::cout << std::string(30, '#') << std::endl
@@ -75,7 +76,7 @@
75 << std::string(30, '#') << std::endl;76 << std::string(30, '#') << std::endl;
7677
77 // initialize input contents to encoder78 // initialize input contents to encoder
78 std::map<std::string, dccl::MessageVal> vals;79 std::map<std::string, acomms::DCCLMessageVal> vals;
79 80
80 // initialize output hexadecimal81 // initialize output hexadecimal
81 std::string hex2, hex3;82 std::string hex2, hex3;
8283
=== modified file 'src/acomms/libdccl/message.cpp'
--- src/acomms/libdccl/message.cpp 2010-07-11 16:20:55 +0000
+++ src/acomms/libdccl/message.cpp 2010-07-15 12:38:39 +0000
@@ -22,7 +22,7 @@
2222
23#include "message.h"23#include "message.h"
2424
25dccl::Message::Message():size_(0),25goby::acomms::DCCLMessage::DCCLMessage():size_(0),
26 trigger_number_(1), 26 trigger_number_(1),
27 body_bits_(0),27 body_bits_(0),
28 id_(0),28 id_(0),
@@ -30,61 +30,64 @@
30 repeat_enabled_(false),30 repeat_enabled_(false),
31 repeat_(1)31 repeat_(1)
32{32{
33 header_.resize(acomms::NUM_HEADER_PARTS);33 header_.resize(DCCL_NUM_HEADER_PARTS);
34 header_[acomms::head_ccl_id] =34 header_[head_ccl_id] =
35 boost::shared_ptr<MessageVar>(new MessageVarCCLID());35 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarCCLID());
36 header_[acomms::head_dccl_id] =36 header_[head_dccl_id] =
37 boost::shared_ptr<MessageVar>(new MessageVarDCCLID());37 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarDCCLID());
38 header_[acomms::head_time] =38 header_[head_time] =
39 boost::shared_ptr<MessageVar>(new MessageVarTime());39 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarTime());
40 header_[acomms::head_src_id] =40 header_[head_src_id] =
41 boost::shared_ptr<MessageVar>(new MessageVarSrc());41 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarSrc());
42 header_[acomms::head_dest_id] =42 header_[head_dest_id] =
43 boost::shared_ptr<MessageVar>(new MessageVarDest());43 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarDest());
44 header_[acomms::head_multimessage_flag] =44 header_[head_multimessage_flag] =
45 boost::shared_ptr<MessageVar>(new MessageVarMultiMessageFlag());45 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarMultiMessageFlag());
46 header_[acomms::head_broadcast_flag] =46 header_[head_broadcast_flag] =
47 boost::shared_ptr<MessageVar>(new MessageVarBroadcastFlag());47 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarBroadcastFlag());
48 header_[acomms::head_unused] =48 header_[head_unused] =
49 boost::shared_ptr<MessageVar>(new MessageVarUnused());49 boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarUnused());
50}50}
5151
52 52
53// add a new message_var to the current messages vector53// add a new message_var to the current messages vector
54void dccl::Message::add_message_var(const std::string& type)54void goby::acomms::DCCLMessage::add_message_var(const std::string& type)
55{55{
56 if(type == "static")56 if(type == "static")
57 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarStatic()));57 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarStatic()));
58 else if(type == "int")58 else if(type == "int")
59 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarInt()));59 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarInt()));
60 else if(type == "string")60 else if(type == "string")
61 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarString()));61 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarString()));
62 else if(type == "float")62 else if(type == "float")
63 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarFloat()));63 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarFloat()));
64 else if(type == "enum")64 else if(type == "enum")
65 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarEnum()));65 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarEnum()));
66 else if(type == "bool")66 else if(type == "bool")
67 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarBool()));67 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarBool()));
68 else if(type == "hex")68 else if(type == "hex")
69 layout_.push_back(boost::shared_ptr<MessageVar>(new MessageVarHex()));69 layout_.push_back(boost::shared_ptr<DCCLMessageVar>(new DCCLMessageVarHex()));
70}70}
7171
72// add a new publish, i.e. a set of parameters to publish72// add a new publish, i.e. a set of parameters to publish
73// upon receipt of an incoming (hex) message73// upon receipt of an incoming (hex) message
74void dccl::Message::add_publish()74void goby::acomms::DCCLMessage::add_publish()
75{75{
76 Publish p;76 DCCLPublish p;
77 publishes_.push_back(p);77 publishes_.push_back(p);
78}78}
7979
80// a number of tasks to perform after reading in an entire <message> from80// a number of tasks to perform after reading in an entire <message> from
81// the xml file81// the xml file
82void dccl::Message::preprocess()82void goby::acomms::DCCLMessage::preprocess()
83{83{
84 if(requested_bytes_total() <= bytes_head())
85 throw(std::runtime_error(std::string("<size> must be larger than the header size of " + boost::lexical_cast<std::string>(bytes_head()))));
86
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_`.
85 if(repeat_enabled_)88 if(repeat_enabled_)
86 {89 {
87 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_)90 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_)
88 {91 {
89 if(mv->array_length() != 1)92 if(mv->array_length() != 1)
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)"));
@@ -105,7 +108,7 @@
105 body_bits_ = calc_total_size();108 body_bits_ = calc_total_size();
106109
107 // initialize header vars110 // initialize header vars
108 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_)111 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_)
109 mv->initialize(trigger_var_);112 mv->initialize(trigger_var_);
110113
111 114
@@ -115,7 +118,7 @@
115 }118 }
116119
117 // iterate over publishes_120 // iterate over publishes_
118 BOOST_FOREACH(Publish& p, publishes_)121 BOOST_FOREACH(DCCLPublish& p, publishes_)
119 p.initialize(*this);122 p.initialize(*this);
120 123
121 // set incoming_var / outgoing_var if not set124 // set incoming_var / outgoing_var if not set
@@ -125,18 +128,18 @@
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";
126}129}
127130
128void dccl::Message::set_repeat_array_length()131void goby::acomms::DCCLMessage::set_repeat_array_length()
129{132{
130 // set array_length_ for repeated messages for all MessageVars133 // set array_length_ for repeated messages for all DCCLMessageVars
131 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_)134 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_)
132 mv->set_array_length(repeat_);135 mv->set_array_length(repeat_);
133}136}
134137
135unsigned dccl::Message::calc_total_size()138unsigned goby::acomms::DCCLMessage::calc_total_size()
136{139{
137 unsigned body_bits = 0;140 unsigned body_bits = 0;
138 // iterate over layout_141 // iterate over layout_
139 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_)142 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_)
140 {143 {
141 mv->initialize(trigger_var_);144 mv->initialize(trigger_var_);
142 // calculate total bits for the message from the bits for each message_var145 // calculate total bits for the message from the bits for each message_var
@@ -147,15 +150,15 @@
147150
148151
149152
150std::map<std::string, std::string> dccl::Message::message_var_names() const153std::map<std::string, std::string> goby::acomms::DCCLMessage::message_var_names() const
151{154{
152 std::map<std::string, std::string> s;155 std::map<std::string, std::string> s;
153 BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, layout_)156 BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, layout_)
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())));
155 return s;158 return s;
156}159}
157160
158std::set<std::string> dccl::Message::get_pubsub_encode_vars()161std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_encode_vars()
159{162{
160 std::set<std::string> s = get_pubsub_src_vars();163 std::set<std::string> s = get_pubsub_src_vars();
161 if(trigger_type_ == "publish")164 if(trigger_type_ == "publish")
@@ -163,14 +166,14 @@
163 return s;166 return s;
164}167}
165168
166std::set<std::string> dccl::Message::get_pubsub_decode_vars()169std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_decode_vars()
167{170{
168 std::set<std::string> s;171 std::set<std::string> s;
169 s.insert(in_var_);172 s.insert(in_var_);
170 return s;173 return s;
171}174}
172 175
173std::set<std::string> dccl::Message::get_pubsub_all_vars()176std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_all_vars()
174{177{
175 std::set<std::string> s_enc = get_pubsub_encode_vars();178 std::set<std::string> s_enc = get_pubsub_encode_vars();
176 std::set<std::string> s_dec = get_pubsub_decode_vars();179 std::set<std::string> s_dec = get_pubsub_decode_vars();
@@ -181,25 +184,25 @@
181 return s;184 return s;
182}185}
183 186
184std::set<std::string> dccl::Message::get_pubsub_src_vars()187std::set<std::string> goby::acomms::DCCLMessage::get_pubsub_src_vars()
185{188{
186 std::set<std::string> s;189 std::set<std::string> s;
187190
188 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_)191 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_)
189 s.insert(mv->source_var());192 s.insert(mv->source_var());
190 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_)193 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_)
191 s.insert(mv->source_var());194 s.insert(mv->source_var());
192 195
193 return s;196 return s;
194}197}
195198
196 199
197void dccl::Message::body_encode(std::string& body, std::map<std::string, std::vector<MessageVal> >& in)200void goby::acomms::DCCLMessage::body_encode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& in)
198{201{
199 boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body()));202 boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body()));
200203
201 // 1. encode each variable into the bitset204 // 1. encode each variable into the bitset
202 for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = layout_.begin(),205 for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = layout_.begin(),
203 n = layout_.end();206 n = layout_.end();
204 it != n;207 it != n;
205 ++it)208 ++it)
@@ -214,7 +217,7 @@
214 body.resize(body.find_last_not_of(char(0))+1);217 body.resize(body.find_last_not_of(char(0))+1);
215}218}
216219
217void dccl::Message::body_decode(std::string& body, std::map<std::string, std::vector<MessageVal> >& out)220void goby::acomms::DCCLMessage::body_decode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& out)
218{221{
219 boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body())); 222 boost::dynamic_bitset<unsigned char> body_bits(bytes2bits(used_bytes_body()));
220 223
@@ -225,7 +228,7 @@
225 string2bitset(body_bits, body);228 string2bitset(body_bits, body);
226 229
227 // 1. pull the bits off the message in the reverse that they were put on230 // 1. pull the bits off the message in the reverse that they were put on
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(),
229 n = layout_.rend();232 n = layout_.rend();
230 it != n;233 it != n;
231 ++it)234 ++it)
@@ -234,9 +237,9 @@
234 }237 }
235}238}
236239
237void dccl::Message::set_head_defaults(std::map<std::string, std::vector<MessageVal> >& in, unsigned modem_id)240void goby::acomms::DCCLMessage::set_head_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& in, unsigned modem_id)
238{241{
239 for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = header_.begin(),242 for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = header_.begin(),
240 n = header_.end();243 n = header_.end();
241 it != n;244 it != n;
242 ++it)245 ++it)
@@ -245,12 +248,12 @@
245 }248 }
246}249}
247250
248void dccl::Message::head_encode(std::string& head, std::map<std::string, std::vector<MessageVal> >& in)251void goby::acomms::DCCLMessage::head_encode(std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& in)
249{ 252{
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));
251254
252 255
253 for (std::vector< boost::shared_ptr<MessageVar> >::iterator it = header_.begin(),256 for (std::vector< boost::shared_ptr<DCCLMessageVar> >::iterator it = header_.begin(),
254 n = header_.end();257 n = header_.end();
255 it != n;258 it != n;
256 ++it)259 ++it)
@@ -261,12 +264,12 @@
261 bitset2string(head_bits, head);264 bitset2string(head_bits, head);
262}265}
263266
264void dccl::Message::head_decode(const std::string& head, std::map<std::string, std::vector<MessageVal> >& out)267void goby::acomms::DCCLMessage::head_decode(const std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& out)
265{268{
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));
267 string2bitset(head_bits, head);270 string2bitset(head_bits, head);
268271
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();
270 it != n;273 it != n;
271 ++it)274 ++it)
272 {275 {
@@ -274,20 +277,20 @@
274 }277 }
275}278}
276279
277boost::shared_ptr<dccl::MessageVar> dccl::Message::name2message_var(const std::string& name)280boost::shared_ptr<goby::acomms::DCCLMessageVar> goby::acomms::DCCLMessage::name2message_var(const std::string& name)
278{281{
279 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, layout_)282 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, layout_)
280 {283 {
281 if(mv->name() == name) return mv;284 if(mv->name() == name) return mv;
282 } 285 }
283 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, header_)286 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, header_)
284 {287 {
285 if(mv->name() == name) return mv;288 if(mv->name() == name) return mv;
286 }289 }
287290
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>"));
289 292
290 return boost::shared_ptr<dccl::MessageVar>();293 return boost::shared_ptr<DCCLMessageVar>();
291}294}
292295
293////////////////////////////296////////////////////////////
@@ -295,8 +298,8 @@
295////////////////////////////298////////////////////////////
296299
297 300
298// a long visual display of all the parameters for a Message301// a long visual display of all the parameters for a DCCLMessage
299std::string dccl::Message::get_display() const302std::string goby::acomms::DCCLMessage::get_display() const
300{303{
301 const unsigned int num_stars = 20;304 const unsigned int num_stars = 20;
302305
@@ -335,12 +338,12 @@
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;
336339
337 ss << ">>>> HEADER <<<<" << std::endl;340 ss << ">>>> HEADER <<<<" << std::endl;
338 BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, header_)341 BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, header_)
339 ss << *mv;342 ss << *mv;
340 343
341 ss << ">>>> LAYOUT (message_vars) <<<<" << std::endl;344 ss << ">>>> LAYOUT (message_vars) <<<<" << std::endl;
342345
343 BOOST_FOREACH(const boost::shared_ptr<MessageVar> mv, layout_)346 BOOST_FOREACH(const boost::shared_ptr<DCCLMessageVar> mv, layout_)
344 ss << *mv;347 ss << *mv;
345 348
346 if(is_moos)349 if(is_moos)
@@ -348,7 +351,7 @@
348351
349 ss << ">>>> PUBLISHES <<<<" << std::endl;352 ss << ">>>> PUBLISHES <<<<" << std::endl;
350 353
351 BOOST_FOREACH(const Publish& p, publishes_)354 BOOST_FOREACH(const DCCLPublish& p, publishes_)
352 ss << p;355 ss << p;
353 }356 }
354 357
@@ -359,7 +362,7 @@
359}362}
360363
361// a much shorter rundown of the Message parameters364// a much shorter rundown of the Message parameters
362std::string dccl::Message::get_short_display() const365std::string goby::acomms::DCCLMessage::get_short_display() const
363{366{
364 std::stringstream ss;367 std::stringstream ss;
365368
@@ -384,7 +387,7 @@
384}387}
385 388
386// overloaded <<389// overloaded <<
387std::ostream& dccl::operator<< (std::ostream& out, const Message& message)390std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLMessage& message)
388{391{
389 out << message.get_display();392 out << message.get_display();
390 return out;393 return out;
391394
=== modified file 'src/acomms/libdccl/message.h'
--- src/acomms/libdccl/message.h 2010-07-11 16:20:55 +0000
+++ src/acomms/libdccl/message.h 2010-07-15 12:38:39 +0000
@@ -31,8 +31,7 @@
31#include <boost/foreach.hpp>31#include <boost/foreach.hpp>
32#include <boost/shared_ptr.hpp>32#include <boost/shared_ptr.hpp>
3333
34#include "util/tes_utils.h"34#include "goby/acomms/modem_message.h"
35#include "acomms/modem_message.h"
3635
37#include "message_var.h"36#include "message_var.h"
38#include "message_var_int.h"37#include "message_var_int.h"
@@ -47,197 +46,200 @@
47#include "message_publish.h"46#include "message_publish.h"
48#include "dccl_constants.h"47#include "dccl_constants.h"
4948
50namespace dccl49
50namespace goby
51{51{
52 52 namespace acomms
53// the Message itself53 {
54 class Message 54
55 {55// the DCCLMessage itself
56 public:56 class DCCLMessage
57 Message();57 {
58 58 public:
59 // set59 DCCLMessage();
60 void set_name(const std::string& name) {name_ = name;}60
6161 // set
62 void set_id(unsigned id)62 void set_name(const std::string& name) {name_ = name;}
63 { id_ = id; }63
64 template<typename T> void set_id(const T& t)64 void set_id(unsigned id)
65 { set_id(boost::lexical_cast<unsigned>(t)); }65 { id_ = id; }
66 66 template<typename T> void set_id(const T& t)
67 void set_trigger(const std::string& trigger_type) 67 { set_id(boost::lexical_cast<unsigned>(t)); }
68 { trigger_type_ = trigger_type; }68
69 69 void set_trigger(const std::string& trigger_type)
70 void set_trigger_var(const std::string& trigger_var)70 { trigger_type_ = trigger_type; }
71 { trigger_var_ = trigger_var; }71
7272 void set_trigger_var(const std::string& trigger_var)
73 void set_trigger_time(double trigger_time)73 { trigger_var_ = trigger_var; }
74 { trigger_time_ = trigger_time; }74
75 template<typename T> void set_trigger_time(const T& t)75 void set_trigger_time(double trigger_time)
76 { set_trigger_time(boost::lexical_cast<double>(t)); } 76 { trigger_time_ = trigger_time; }
77 77 template<typename T> void set_trigger_time(const T& t)
78 void set_trigger_mandatory(const std::string& trigger_mandatory)78 { set_trigger_time(boost::lexical_cast<double>(t)); }
79 { trigger_mandatory_ = trigger_mandatory; }79
80 80 void set_trigger_mandatory(const std::string& trigger_mandatory)
81 void set_in_var(const std::string& in_var)81 { trigger_mandatory_ = trigger_mandatory; }
82 { in_var_ = in_var; }82
8383 void set_in_var(const std::string& in_var)
84 void set_out_var(const std::string& out_var)84 { in_var_ = in_var; }
85 { out_var_ = out_var; }85
8686 void set_out_var(const std::string& out_var)
87 void set_size(unsigned size)87 { out_var_ = out_var; }
88 { size_ = size; }88
8989 void set_size(unsigned size)
90 template<typename T> void set_size(const T& t)90 { size_ = size; }
91 { set_size(boost::lexical_cast<unsigned>(t)); }91
9292 template<typename T> void set_size(const T& t)
93 void set_repeat_enabled(unsigned repeat_enabled)93 { set_size(boost::lexical_cast<unsigned>(t)); }
94 { repeat_enabled_ = repeat_enabled; }94
95 template<typename T> void set_repeat_enabled(const T& t)95 void set_repeat_enabled(unsigned repeat_enabled)
96 { set_repeat_enabled(boost::lexical_cast<unsigned>(t)); }96 { repeat_enabled_ = repeat_enabled; }
97 97 template<typename T> void set_repeat_enabled(const T& t)
98 void add_message_var(const std::string& type); 98 { set_repeat_enabled(boost::lexical_cast<unsigned>(t)); }
99 void add_publish();99
100100 void add_message_var(const std::string& type);
101 //get101 void add_publish();
102 std::string name() const { return name_; }102
103 unsigned id() const { return id_; }103 //get
104 std::string trigger_var() const { return trigger_var_; }104 std::string name() const { return name_; }
105 std::string trigger_mandatory() const { return trigger_mandatory_; }105 unsigned id() const { return id_; }
106 double trigger_time() const { return trigger_time_; }106 std::string trigger_var() const { return trigger_var_; }
107 unsigned trigger_number() const { return trigger_number_; }107 std::string trigger_mandatory() const { return trigger_mandatory_; }
108 std::string trigger_type() const { return trigger_type_; }108 double trigger_time() const { return trigger_time_; }
109 std::string in_var() const { return in_var_; }109 unsigned trigger_number() const { return trigger_number_; }
110 std::string out_var() const { return out_var_; }110 std::string trigger_type() const { return trigger_type_; }
111 bool repeat_enabled() const { return repeat_enabled_; }111 std::string in_var() const { return in_var_; }
112 unsigned repeat() const { return repeat_; }112 std::string out_var() const { return out_var_; }
113113 bool repeat_enabled() const { return repeat_enabled_; }
114 MessageVar& last_message_var() { return *layout_.back(); }114 unsigned repeat() const { return repeat_; }
115 MessageVar& header_var(acomms::DCCLHeaderPart p) { return *header_[p]; }115
116 Publish& last_publish() { return publishes_.back(); } 116 DCCLMessageVar& last_message_var() { return *layout_.back(); }
117 117 DCCLMessageVar& header_var(acomms::DCCLHeaderPart p) { return *header_[p]; }
118 std::vector< boost::shared_ptr<MessageVar> >& layout() { return layout_; }118 DCCLPublish& last_publish() { return publishes_.back(); }
119 std::vector< boost::shared_ptr<MessageVar> >& header() { return header_; }119
120 std::vector<Publish>& publishes() { return publishes_; }120 std::vector< boost::shared_ptr<DCCLMessageVar> >& layout() { return layout_; }
121121 std::vector< boost::shared_ptr<DCCLMessageVar> >& header() { return header_; }
122 std::set<std::string> get_pubsub_encode_vars();122 std::vector<DCCLPublish>& publishes() { return publishes_; }
123 std::set<std::string> get_pubsub_decode_vars();123
124 std::set<std::string> get_pubsub_src_vars();124 std::set<std::string> get_pubsub_encode_vars();
125 std::set<std::string> get_pubsub_all_vars();125 std::set<std::string> get_pubsub_decode_vars();
126126 std::set<std::string> get_pubsub_src_vars();
127 boost::shared_ptr<MessageVar> name2message_var(const std::string& name);127 std::set<std::string> get_pubsub_all_vars();
128 128
129 129 boost::shared_ptr<DCCLMessageVar> name2message_var(const std::string& name);
130 //other130
131 std::string get_display() const;131
132 std::string get_short_display() const;132 //other
133 std::map<std::string, std::string> message_var_names() const;133 std::string get_display() const;
134 void preprocess();134 std::string get_short_display() const;
135 void set_repeat_array_length();135 std::map<std::string, std::string> message_var_names() const;
136 unsigned calc_total_size();136 void preprocess();
137 137 void set_repeat_array_length();
138 void set_head_defaults(std::map<std::string, std::vector<MessageVal> >& in, unsigned modem_id);138 unsigned calc_total_size();
139 139
140 140 void set_head_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& in, unsigned modem_id);
141 void head_encode(std::string& head, std::map<std::string, std::vector<MessageVal> >& in);141
142 void head_decode(const std::string& head, std::map<std::string, std::vector<MessageVal> >& out);142
143 143 void head_encode(std::string& head, std::map<std::string, std::vector<DCCLMessageVal> >& in);
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);
145 void body_decode(std::string& body, std::map<std::string, std::vector<MessageVal> >& out);145
146146 void body_encode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& in);
147 // increment, means increase trigger number147 void body_decode(std::string& body, std::map<std::string, std::vector<DCCLMessageVal> >& out);
148 // prefix ++Message148
149 Message& operator++()149 // increment, means increase trigger number
150 { ++trigger_number_; return(*this); }150 // prefix ++DCCLMessage
151 // postfix Message++151 DCCLMessage& operator++()
152 const Message operator++(int)152 { ++trigger_number_; return(*this); }
153 { Message tmp(*this); ++(*this); return tmp;}153 // postfix DCCLMessage++
154 154 const DCCLMessage operator++(int)
155 155 { DCCLMessage tmp(*this); ++(*this); return tmp;}
156 private:156
157 unsigned bytes_head() const157
158 { return acomms::NUM_HEADER_BYTES; }158 private:
159 unsigned bits_head() const159 unsigned bytes_head() const
160 { return bytes2bits(acomms::NUM_HEADER_BYTES); }160 { return acomms::DCCL_NUM_HEADER_BYTES; }
161161 unsigned bits_head() const
162 // more efficient way to do ceil(total_bits / 8)162 { return bytes2bits(acomms::DCCL_NUM_HEADER_BYTES); }
163 // to get the number of bytes rounded up.163
164 164 // more efficient way to do ceil(total_bits / 8)
165 enum { BYTE_MASK = 7 }; // 00000111165 // to get the number of bytes rounded up.
166 unsigned used_bytes_body() const166
167 {167 enum { BYTE_MASK = 7 }; // 00000111
168 return (body_bits_& BYTE_MASK) ?168 unsigned used_bytes_body() const
169 bits2bytes(body_bits_) + 1 :169 {
170 bits2bytes(body_bits_);170 return (body_bits_& BYTE_MASK) ?
171 }171 bits2bytes(body_bits_) + 1 :
172172 bits2bytes(body_bits_);
173 unsigned used_bytes_total() const173 }
174 { return bytes_head() + used_bytes_body(); }174
175175 unsigned used_bytes_total() const
176 unsigned used_bits_body() const176 { return bytes_head() + used_bytes_body(); }
177 { return body_bits_; }177
178 178 unsigned used_bits_body() const
179 unsigned used_bits_total() const179 { return body_bits_; }
180 { return bits_head() + used_bits_body(); }180
181 181 unsigned used_bits_total() const
182 unsigned requested_bytes_body() const182 { return bits_head() + used_bits_body(); }
183 { return size_ - acomms::NUM_HEADER_BYTES; }183
184184 unsigned requested_bytes_body() const
185 unsigned requested_bytes_total() const185 { return size_ - acomms::DCCL_NUM_HEADER_BYTES; }
186 { return size_; }186
187187 unsigned requested_bytes_total() const
188 unsigned requested_bits_body() const188 { return size_; }
189 { return bytes2bits(size_ - acomms::NUM_HEADER_BYTES); } 189
190190 unsigned requested_bits_body() const
191 unsigned requested_bits_total() const191 { return bytes2bits(size_ - acomms::DCCL_NUM_HEADER_BYTES); }
192 { return bytes2bits(size_); }192
193 193 unsigned requested_bits_total() const
194 194 { return bytes2bits(size_); }
195 private:195
196 // total request size of message, e.g. 32 bytes196
197 unsigned size_;197 private:
198 198 // total request size of message, e.g. 32 bytes
199 unsigned trigger_number_;199 unsigned size_;
200 // actual used bits in body part of message (not including header bits)200
201 unsigned body_bits_;201 unsigned trigger_number_;
202202 // actual used bits in body part of message (not including header bits)
203 unsigned id_;203 unsigned body_bits_;
204 unsigned modem_id_;204
205 double trigger_time_; 205 unsigned id_;
206206 unsigned modem_id_;
207 bool repeat_enabled_;207 double trigger_time_;
208 unsigned repeat_;208
209 209 bool repeat_enabled_;
210 std::string name_;210 unsigned repeat_;
211 std::string trigger_type_;211
212 std::string trigger_var_;212 std::string name_;
213 std::string trigger_mandatory_;213 std::string trigger_type_;
214 std::string in_var_;214 std::string trigger_var_;
215 std::string out_var_;215 std::string trigger_mandatory_;
216216 std::string in_var_;
217 std::vector< boost::shared_ptr<MessageVar> > layout_;217 std::string out_var_;
218 std::vector< boost::shared_ptr<MessageVar> > header_;218
219 219 std::vector< boost::shared_ptr<DCCLMessageVar> > layout_;
220 220 std::vector< boost::shared_ptr<DCCLMessageVar> > header_;
221 std::vector<Publish> publishes_;221
222222
223 };223 std::vector<DCCLPublish> publishes_;
224224
225225 };
226 inline void bitset2string(const boost::dynamic_bitset<unsigned char>& body_bits,226
227 std::string& body)227
228 {228 inline void bitset2string(const boost::dynamic_bitset<unsigned char>& body_bits,
229 body.resize(body_bits.num_blocks()); // resize the string to fit the bitset229 std::string& body)
230 to_block_range(body_bits, body.rbegin());230 {
231 }231 body.resize(body_bits.num_blocks()); // resize the string to fit the bitset
232 232 to_block_range(body_bits, body.rbegin());
233 inline void string2bitset(boost::dynamic_bitset<unsigned char>& body_bits,233 }
234 const std::string& body)234
235 {235 inline void string2bitset(boost::dynamic_bitset<unsigned char>& body_bits,
236 from_block_range(body.rbegin(), body.rend(), body_bits);236 const std::string& body)
237 }237 {
238238 from_block_range(body.rbegin(), body.rend(), body_bits);
239239 }
240 std::ostream& operator<< (std::ostream& out, const Message& message);240
241
242 std::ostream& operator<< (std::ostream& out, const DCCLMessage& message);
243 }
241}244}
242
243#endif245#endif
244246
=== modified file 'src/acomms/libdccl/message_algorithms.cpp'
--- src/acomms/libdccl/message_algorithms.cpp 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_algorithms.cpp 2010-07-15 12:38:39 +0000
@@ -22,33 +22,34 @@
22#include "message_algorithms.h"22#include "message_algorithms.h"
23#include "message_val.h"23#include "message_val.h"
2424
25dccl::AlgorithmPerformer* dccl::AlgorithmPerformer::inst_ = NULL;25#include "goby/util/string.h"
26
27goby::acomms::DCCLAlgorithmPerformer* goby::acomms::DCCLAlgorithmPerformer::inst_ = 0;
2628
27// singleton class, use this to get pointer29// singleton class, use this to get pointer
28dccl::AlgorithmPerformer* dccl::AlgorithmPerformer::getInstance()30goby::acomms::DCCLAlgorithmPerformer* goby::acomms::DCCLAlgorithmPerformer::getInstance()
29{31{
30 if(inst_ == NULL)32 if(!inst_) inst_ = new DCCLAlgorithmPerformer();
31 inst_ = new AlgorithmPerformer();
3233
33 return(inst_);34 return(inst_);
34}35}
3536
36void dccl::AlgorithmPerformer::algorithm(MessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<MessageVal> >& vals)37void goby::acomms::DCCLAlgorithmPerformer::algorithm(DCCLMessageVal& in, unsigned array_index, const std::string& algorithm, const std::map<std::string,std::vector<DCCLMessageVal> >& vals)
37{38{
38 if(in.empty()) return;39 if(in.empty()) return;
3940
40// algo_name:ref_variable_name1:ref_variable_name2...41// algo_name:ref_variable_name1:ref_variable_name2...
41 42
42 std::vector<std::string>ref_vars = tes_util::explode(algorithm, ':', true);43 std::vector<std::string>ref_vars = util::explode(algorithm, ':', true);
4344
44 std::string alg;45 std::string alg;
45 std::vector<MessageVal> tied_vals;46 std::vector<DCCLMessageVal> tied_vals;
4647
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();
48 i < n;49 i < n;
49 ++i)50 ++i)
50 {51 {
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]);
52 if(it != vals.end() && array_index < it->second.size())53 if(it != vals.end() && array_index < it->second.size())
53 tied_vals.push_back(it->second[array_index]);54 tied_vals.push_back(it->second[array_index]);
54 else55 else
5556
=== modified file 'src/acomms/libdccl/message_algorithms.h'
--- src/acomms/libdccl/message_algorithms.h 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_algorithms.h 2010-07-15 12:38:39 +0000
@@ -28,45 +28,46 @@
2828
29#include <boost/algorithm/string.hpp>29#include <boost/algorithm/string.hpp>
30#include <boost/function.hpp>30#include <boost/function.hpp>
3131namespace goby
32namespace dccl
33{32{
34 class MessageVal;33 namespace acomms
34 {
35 class DCCLMessageVal;
35 36
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.
37 ///38 ///
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.
39 typedef boost::function<void (MessageVal&)> AlgFunction1;40 typedef boost::function<void (DCCLMessageVal&)> AlgFunction1;
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.
41 ///42 ///
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.
43 typedef boost::function<void (MessageVal&, const std::vector<MessageVal>&)> AlgFunction2;44 typedef boost::function<void (DCCLMessageVal&, const std::vector<DCCLMessageVal>&)> AlgFunction2;
4445
45 class AlgorithmPerformer46 class DCCLAlgorithmPerformer
46 {47 {
47 public:48 public:
48 static AlgorithmPerformer* getInstance();49 static DCCLAlgorithmPerformer* getInstance();
4950
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);
51 52
52 void add_algorithm(const std::string& name, AlgFunction1 func)53 void add_algorithm(const std::string& name, AlgFunction1 func)
53 { adv_map1_[name] = func; }54 { adv_map1_[name] = func; }
5455
55 void add_algorithm(const std::string& name, AlgFunction2 func)56 void add_algorithm(const std::string& name, AlgFunction2 func)
56 { adv_map2_[name] = func; }57 { adv_map2_[name] = func; }
57 58
58 private:59 private:
59 static AlgorithmPerformer* inst_;60 static DCCLAlgorithmPerformer* inst_;
60 std::map<std::string, AlgFunction1> adv_map1_;61 std::map<std::string, AlgFunction1> adv_map1_;
61 std::map<std::string, AlgFunction2> adv_map2_;62 std::map<std::string, AlgFunction2> adv_map2_;
62 63
63 AlgorithmPerformer()64 DCCLAlgorithmPerformer()
64 {}65 {}
65 66
66 AlgorithmPerformer(const AlgorithmPerformer&);67 DCCLAlgorithmPerformer(const DCCLAlgorithmPerformer&);
67 AlgorithmPerformer& operator = (const AlgorithmPerformer&);68 DCCLAlgorithmPerformer& operator = (const DCCLAlgorithmPerformer&);
68 69
69 };70 };
71 }
70}72}
71
72#endif73#endif
7374
=== modified file 'src/acomms/libdccl/message_publish.cpp'
--- src/acomms/libdccl/message_publish.cpp 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_publish.cpp 2010-07-15 12:38:39 +0000
@@ -22,9 +22,9 @@
22#include "message_publish.h"22#include "message_publish.h"
23#include "message.h"23#include "message.h"
2424
25using acomms::NaN;25using goby::acomms::NaN;
2626
27void dccl::Publish::initialize(Message& msg)27void goby::acomms::DCCLPublish::initialize(DCCLMessage& msg)
28{28{
29 repeat_ = msg.repeat();29 repeat_ = msg.repeat();
3030
@@ -36,7 +36,7 @@
36 // add names for any <all/> publishes and empty std::vector for algorithms36 // add names for any <all/> publishes and empty std::vector for algorithms
37 if(use_all_names_)37 if(use_all_names_)
38 {38 {
39 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, msg.header())39 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, msg.header())
40 {40 {
41 // ignore header pieces not explicitly overloaded by the <name> tag41 // ignore header pieces not explicitly overloaded by the <name> tag
42 if(!mv->name().empty() && !(mv->name()[0] == '_'))42 if(!mv->name().empty() && !(mv->name()[0] == '_'))
@@ -47,7 +47,7 @@
47 }47 }
48 }48 }
49 49
50 BOOST_FOREACH(boost::shared_ptr<MessageVar> mv, msg.layout())50 BOOST_FOREACH(boost::shared_ptr<DCCLMessageVar> mv, msg.layout())
51 {51 {
52 add_message_var(mv);52 add_message_var(mv);
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)
@@ -60,7 +60,7 @@
60 if(!format_set_)60 if(!format_set_)
61 {61 {
62 std::string format_str;62 std::string format_str;
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)
64 {64 {
65 if (m > 1)65 if (m > 1)
66 {66 {
@@ -102,10 +102,10 @@
102}102}
103103
104104
105void dccl::Publish::fill_format(const std::map<std::string,std::vector<MessageVal> >& vals,105void goby::acomms::DCCLPublish::fill_format(const std::map<std::string,std::vector<DCCLMessageVal> >& vals,
106 std::string& key,106 std::string& key,
107 std::string& value,107 std::string& value,
108 unsigned repeat_index)108 unsigned repeat_index)
109{109{
110 std::string filled_value;110 std::string filled_value;
111 // format is a boost library class for replacing printf and its ilk111 // format is a boost library class for replacing printf and its ilk
@@ -120,10 +120,10 @@
120 f.parse(input_format);120 f.parse(input_format);
121 121
122 // iterate over the message_vars and fill in the format field122 // iterate over the message_vars and fill in the format field
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)
124 {124 {
125 std::vector<MessageVal> vm = vals.find(message_vars_[k]->name())->second;125 std::vector<DCCLMessageVal> vm = vals.find(message_vars_[k]->name())->second;
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,
127 n = (repeat_ > 1) ? repeat_index + 1 : vm.size();127 n = (repeat_ > 1) ? repeat_index + 1 : vm.size();
128 i < n;128 i < n;
129 ++i)129 ++i)
@@ -159,8 +159,8 @@
159159
160 160
161161
162void dccl::Publish::write_publish(const std::map<std::string,std::vector<MessageVal> >& vals,162void goby::acomms::DCCLPublish::write_publish(const std::map<std::string,std::vector<DCCLMessageVal> >& vals,
163 std::multimap<std::string,MessageVal>& pubsub_vals)163 std::multimap<std::string,DCCLMessageVal>& pubsub_vals)
164164
165{165{
166 for(unsigned i = 0, n = repeat_;166 for(unsigned i = 0, n = repeat_;
@@ -173,29 +173,29 @@
173 // user sets to string173 // user sets to string
174 if(type_ == cpp_string)174 if(type_ == cpp_string)
175 {175 {
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));
177 continue;177 continue;
178 }178 }
179 179
180 // pass through a MessageVal to do the type conversions180 // pass through a DCCLMessageVal to do the type conversions
181 MessageVal mv = out_val;181 DCCLMessageVal mv = out_val;
182 double out_dval = mv;182 double out_dval = mv;
183 if(type_ == cpp_double)183 if(type_ == cpp_double)
184 {184 {
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));
186 continue;186 continue;
187 }187 }
188 long out_lval = mv; 188 long out_lval = mv;
189 if(type_ == cpp_long)189 if(type_ == cpp_long)
190 {190 {
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));
192 continue;192 continue;
193 193
194 }194 }
195 bool out_bval = mv;195 bool out_bval = mv;
196 if(type_ == cpp_bool)196 if(type_ == cpp_bool)
197 {197 {
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));
199 continue;199 continue;
200 }200 }
201 201
@@ -205,14 +205,14 @@
205 catch (boost::bad_lexical_cast &) { is_numeric = false; }205 catch (boost::bad_lexical_cast &) { is_numeric = false; }
206 206
207 if(!is_numeric)207 if(!is_numeric)
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));
209 else209 else
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));
211 }211 }
212}212}
213213
214 214
215std::string dccl::Publish::get_display() const215std::string goby::acomms::DCCLPublish::get_display() const
216{216{
217 std::stringstream ss;217 std::stringstream ss;
218 218
@@ -220,7 +220,7 @@
220 ss << ")moos_var: {" << var_ << "}" << std::endl;220 ss << ")moos_var: {" << var_ << "}" << std::endl;
221 ss << "\tvalue: \"" << format_ << "\"" << std::endl;221 ss << "\tvalue: \"" << format_ << "\"" << std::endl;
222 ss << "\tmessage_vars:" << std::endl;222 ss << "\tmessage_vars:" << std::endl;
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)
224 {224 {
225 ss << "\t\t" << (j+1) << ": " << message_vars_[j]->name();225 ss << "\t\t" << (j+1) << ": " << message_vars_[j]->name();
226226
@@ -240,7 +240,7 @@
240}240}
241241
242// overloaded <<242// overloaded <<
243std::ostream& dccl::operator<< (std::ostream& out, const Publish& publish)243std::ostream& goby::acomms::operator<< (std::ostream& out, const DCCLPublish& publish)
244{244{
245 out << publish.get_display();245 out << publish.get_display();
246 return out;246 return out;
247247
=== modified file 'src/acomms/libdccl/message_publish.h'
--- src/acomms/libdccl/message_publish.h 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_publish.h 2010-07-15 12:38:39 +0000
@@ -31,77 +31,79 @@
31#include "message_algorithms.h"31#include "message_algorithms.h"
32#include "dccl_constants.h"32#include "dccl_constants.h"
3333
34namespace dccl34namespace goby
35{35{
36 class Message;36 namespace acomms
37 {
38 class DCCLMessage;
37 39
38// defines (a single) thing to do with the decoded message40// defines (a single) thing to do with the decoded message
39// that is, where do we publish it and what should we include in the41// that is, where do we publish it and what should we include in the
40// published message42// published message
41 class Publish43 class DCCLPublish
42 {44 {
43 public:45 public:
44 Publish() : var_(""),46 DCCLPublish() : var_(""),
45 format_(""),47 format_(""),
46 format_set_(false),48 format_set_(false),
47 use_all_names_(false),49 use_all_names_(false),
48 type_(cpp_notype),50 type_(cpp_notype),
49 ap_(AlgorithmPerformer::getInstance()),51 ap_(DCCLAlgorithmPerformer::getInstance()),
50 repeat_(1)52 repeat_(1)
51 { } 53 { }
5254
53 //set55 //set
54 56
55 void set_var(std::string var) {var_=var;}57 void set_var(std::string var) {var_=var;}
56 void set_format(std::string format) {format_=format; format_set_ = true;}58 void set_format(std::string format) {format_=format; format_set_ = true;}
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;}
58 void set_type(DCCLCppType type) {type_ = type;}60 void set_type(DCCLCppType type) {type_ = type;}
5961
60 void add_name(const std::string& name) {names_.push_back(name);}62 void add_name(const std::string& name) {names_.push_back(name);}
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);}
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);}
63 65
64 //get66 //get
65// std::string var() const {return var_;}67// std::string var() const {return var_;}
66// std::string format() const {return format_;}68// std::string format() const {return format_;}
67// bool format_set() const {return format_set_;}69// bool format_set() const {return format_set_;}
68// bool use_all_names() const {return use_all_names_;}70// bool use_all_names() const {return use_all_names_;}
69 71
70 DCCLCppType type() {return type_;}72 DCCLCppType type() {return type_;}
71// std::vector<std::string> const& names() {return names_;}73// std::vector<std::string> const& names() {return names_;}
72// std::vector<std::vector<std::string> > const& algorithms(){return algorithms_;}74// std::vector<std::vector<std::string> > const& algorithms(){return algorithms_;}
73 75
74 76
75 std::string get_display() const;77 std::string get_display() const;
7678
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,
78 std::multimap<std::string,MessageVal>& pubsub_vals);80 std::multimap<std::string,DCCLMessageVal>& pubsub_vals);
79 81
80 82
81 83
8284
83 void initialize(Message& msg);85 void initialize(DCCLMessage& msg);
8486
85 private:87 private:
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,
87 std::string& key,89 std::string& key,
88 std::string& value,90 std::string& value,
89 unsigned repeat_index);91 unsigned repeat_index);
90 92
91 private:93 private:
92 std::string var_;94 std::string var_;
93 std::string format_;95 std::string format_;
94 bool format_set_;96 bool format_set_;
95 bool use_all_names_;97 bool use_all_names_;
96 DCCLCppType type_;98 DCCLCppType type_;
97 std::vector<std::string> names_;99 std::vector<std::string> names_;
98 std::vector<boost::shared_ptr<MessageVar> > message_vars_;100 std::vector<boost::shared_ptr<DCCLMessageVar> > message_vars_;
99 std::vector< std::vector<std::string> > algorithms_;101 std::vector< std::vector<std::string> > algorithms_;
100 AlgorithmPerformer* ap_;102 DCCLAlgorithmPerformer* ap_;
101 unsigned repeat_;103 unsigned repeat_;
102 };104 };
103105
104 std::ostream& operator<< (std::ostream& out, const Publish& publish);106 std::ostream& operator<< (std::ostream& out, const DCCLPublish& publish);
107 }
105}108}
106
107#endif109#endif
108110
=== modified file 'src/acomms/libdccl/message_val.cpp'
--- src/acomms/libdccl/message_val.cpp 2010-07-13 01:57:57 +0000
+++ src/acomms/libdccl/message_val.cpp 2010-07-15 12:38:39 +0000
@@ -17,13 +17,17 @@
17// You should have received a copy of the GNU General Public License17// You should have received a copy of the GNU General Public License
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/>.
1919
20#include <exception>20#include <stdexcept>
21#include <iomanip>
2122
22#include <boost/foreach.hpp>23#include <boost/foreach.hpp>
2324
25#include "goby/util/string.h"
26#include "goby/util/sci.h"
27
24#include "message_val.h"28#include "message_val.h"
2529
26void dccl::MessageVal::init()30void goby::acomms::DCCLMessageVal::init()
27{31{
28 sval_ = "";32 sval_ = "";
29 dval_ = 0;33 dval_ = 0;
@@ -34,27 +38,27 @@
34}38}
3539
3640
37dccl::MessageVal::MessageVal()41goby::acomms::DCCLMessageVal::DCCLMessageVal()
38{ init(); }42{ init(); }
3943
4044
41dccl::MessageVal::MessageVal(const std::string& s)45goby::acomms::DCCLMessageVal::DCCLMessageVal(const std::string& s)
42{46{
43 init();47 init();
44 sval_ = s;48 sval_ = s;
45 type_ = cpp_string;49 type_ = cpp_string;
46}50}
4751
4852
49dccl::MessageVal::MessageVal(const char* s)53goby::acomms::DCCLMessageVal::DCCLMessageVal(const char* s)
50{54{
51 init();55 init();
52 sval_ = s;56 sval_ = s;
53 type_ = cpp_string;57 type_ = cpp_string;
54}58}
5559
5660
57dccl::MessageVal::MessageVal(double d, int p /* = MAX_DBL_PRECISION*/ )61goby::acomms::DCCLMessageVal::DCCLMessageVal(double d, int p /* = MAX_DBL_PRECISION*/ )
58{62{
59 init();63 init();
60 dval_ = d;64 dval_ = d;
@@ -62,28 +66,28 @@
62 type_ = cpp_double;66 type_ = cpp_double;
63}67}
6468
65dccl::MessageVal::MessageVal(float f)69goby::acomms::DCCLMessageVal::DCCLMessageVal(float f)
66{70{
67 init();71 init();
68 dval_ = f;72 dval_ = f;
69 type_ = cpp_double;73 type_ = cpp_double;
70}74}
7175
72dccl::MessageVal::MessageVal(long l)76goby::acomms::DCCLMessageVal::DCCLMessageVal(long l)
73{77{
74 init();78 init();
75 lval_ = l;79 lval_ = l;
76 type_ = cpp_long;80 type_ = cpp_long;
77} 81}
7882
79dccl::MessageVal::MessageVal(int i)83goby::acomms::DCCLMessageVal::DCCLMessageVal(int i)
80{84{
81 init();85 init();
82 lval_ = i;86 lval_ = i;
83 type_ = cpp_long;87 type_ = cpp_long;
84} 88}
8589
86dccl::MessageVal::MessageVal(bool b)90goby::acomms::DCCLMessageVal::DCCLMessageVal(bool b)
87{91{
88 init();92 init();
89 bval_ = b;93 bval_ = b;
@@ -91,26 +95,26 @@
91} 95}
9296
9397
94dccl::MessageVal::MessageVal(const std::vector<MessageVal>& vm)98goby::acomms::DCCLMessageVal::DCCLMessageVal(const std::vector<DCCLMessageVal>& vm)
95{99{
96 if(vm.size() != 1)100 if(vm.size() != 1)
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"));
98 else102 else
99 *this = vm[0];103 *this = vm[0];
100}104}
101105
102106
103void dccl::MessageVal::set(std::string sval)107void goby::acomms::DCCLMessageVal::set(std::string sval)
104{ sval_ = sval; type_ = cpp_string; }108{ sval_ = sval; type_ = cpp_string; }
105void dccl::MessageVal::set(double dval, int precision /* = MAX_DBL_PRECISION */)109void goby::acomms::DCCLMessageVal::set(double dval, int precision /* = MAX_DBL_PRECISION */)
106{ dval_ = dval; type_ = cpp_double; precision_ = precision; }110{ dval_ = dval; type_ = cpp_double; precision_ = precision; }
107void dccl::MessageVal::set(long lval)111void goby::acomms::DCCLMessageVal::set(long lval)
108{ lval_ = lval; type_ = cpp_long; }112{ lval_ = lval; type_ = cpp_long; }
109void dccl::MessageVal::set(bool bval)113void goby::acomms::DCCLMessageVal::set(bool bval)
110{ bval_ = bval; type_ = cpp_bool; }114{ bval_ = bval; type_ = cpp_bool; }
111115
112116
113bool dccl::MessageVal::get(std::string& s) const117bool goby::acomms::DCCLMessageVal::get(std::string& s) const
114{118{
115 std::stringstream ss;119 std::stringstream ss;
116 switch(type_)120 switch(type_)
@@ -141,14 +145,14 @@
141 }145 }
142}146}
143147
144bool dccl::MessageVal::get(bool& b) const148bool goby::acomms::DCCLMessageVal::get(bool& b) const
145{149{
146 switch(type_)150 switch(type_)
147 {151 {
148 case cpp_string:152 case cpp_string:
149 if(tes_util::stricmp(sval_, "true") || tes_util::stricmp(sval_, "1"))153 if(util::stricmp(sval_, "true") || util::stricmp(sval_, "1"))
150 b = true;154 b = true;
151 else if(tes_util::stricmp(sval_, "false") || tes_util::stricmp(sval_, "0"))155 else if(util::stricmp(sval_, "false") || util::stricmp(sval_, "0"))
152 b = false;156 b = false;
153 else157 else
154 return false;158 return false;
@@ -173,7 +177,7 @@
173 }177 }
174} 178}
175179
176bool dccl::MessageVal::get(long& t) const180bool goby::acomms::DCCLMessageVal::get(long& t) const
177{181{
178 switch(type_)182 switch(type_)
179 {183 {
@@ -181,13 +185,13 @@
181 try185 try
182 {186 {
183 double d = boost::lexical_cast<double>(sval_);187 double d = boost::lexical_cast<double>(sval_);
184 t = boost::numeric_cast<long>(tes_util::sci_round(d, 0));188 t = boost::numeric_cast<long>(util::unbiased_round(d, 0));
185 }189 }
186 catch (...)190 catch (...)
187 {191 {
188 if(tes_util::stricmp(sval_, "true"))192 if(util::stricmp(sval_, "true"))
189 t = 1;193 t = 1;
190 else if(tes_util::stricmp(sval_, "false"))194 else if(util::stricmp(sval_, "false"))
191 t = 0;195 t = 0;
192 else196 else
193 return false;197 return false;
@@ -195,7 +199,7 @@
195 return true;199 return true;
196200
197 case cpp_double:201 case cpp_double:
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)); }
199 catch(...) { return false; }203 catch(...) { return false; }
200 return true;204 return true;
201205
@@ -212,7 +216,7 @@
212 }216 }
213} 217}
214 218
215bool dccl::MessageVal::get(double& d) const219bool goby::acomms::DCCLMessageVal::get(double& d) const
216{220{
217 switch(type_)221 switch(type_)
218 {222 {
@@ -220,9 +224,9 @@
220 try { d = boost::lexical_cast<double>(sval_); }224 try { d = boost::lexical_cast<double>(sval_); }
221 catch (boost::bad_lexical_cast &)225 catch (boost::bad_lexical_cast &)
222 {226 {
223 if(tes_util::stricmp(sval_, "true"))227 if(util::stricmp(sval_, "true"))
224 d = 1;228 d = 1;
225 else if(tes_util::stricmp(sval_, "false"))229 else if(util::stricmp(sval_, "false"))
226 d = 0;230 d = 0;
227 else231 else
228 return false;232 return false;
@@ -251,7 +255,7 @@
251255
252256
253257
254dccl::MessageVal::operator double() const258goby::acomms::DCCLMessageVal::operator double() const
255{259{
256 double d;260 double d;
257 if(get(d)) return d;261 if(get(d)) return d;
@@ -259,48 +263,48 @@
259}263}
260264
261265
262dccl::MessageVal::operator bool() const266goby::acomms::DCCLMessageVal::operator bool() const
263{267{
264 bool b;268 bool b;
265 if(get(b)) return b;269 if(get(b)) return b;
266 else return false;270 else return false;
267}271}
268272
269dccl::MessageVal::operator std::string() const273goby::acomms::DCCLMessageVal::operator std::string() const
270{274{
271 std::string s;275 std::string s;
272 if(get(s)) return s;276 if(get(s)) return s;
273 else return "";277 else return "";
274}278}
275279
276dccl::MessageVal::operator long() const280goby::acomms::DCCLMessageVal::operator long() const
277{281{
278 long l;282 long l;
279 if(get(l)) return l;283 if(get(l)) return l;
280 else return 0;284 else return 0;
281}285}
282286
283dccl::MessageVal::operator int() const287goby::acomms::DCCLMessageVal::operator int() const
284{288{
285 return long(*this);289 return long(*this);
286}290}
287291
288dccl::MessageVal::operator unsigned() const292goby::acomms::DCCLMessageVal::operator unsigned() const
289{293{
290 return long(*this);294 return long(*this);
291}295}
292296
293dccl::MessageVal::operator float() const297goby::acomms::DCCLMessageVal::operator float() const
294{298{
295 return double(*this);299 return double(*this);
296}300}
297301
298dccl::MessageVal::operator std::vector<MessageVal>() const302goby::acomms::DCCLMessageVal::operator std::vector<DCCLMessageVal>() const
299{303{
300 return std::vector<MessageVal>(1, *this);304 return std::vector<DCCLMessageVal>(1, *this);
301}305}
302306
303bool dccl::MessageVal::operator==(const MessageVal& mv) const307bool goby::acomms::DCCLMessageVal::operator==(const DCCLMessageVal& mv) const
304{308{
305 switch(mv.type_)309 switch(mv.type_)
306 {310 {
@@ -312,25 +316,25 @@
312 }316 }
313}317}
314318
315bool dccl::MessageVal::operator==(const std::string& s) const319bool goby::acomms::DCCLMessageVal::operator==(const std::string& s) const
316{320{
317 std::string us;321 std::string us;
318 return get(us) && us == s;322 return get(us) && us == s;
319}323}
320324
321bool dccl::MessageVal::operator==(double d) const325bool goby::acomms::DCCLMessageVal::operator==(double d) const
322{326{
323 double us;327 double us;
324 return get(us) && us == d;328 return get(us) && us == d;
325}329}
326330
327bool dccl::MessageVal::operator==(long l) const331bool goby::acomms::DCCLMessageVal::operator==(long l) const
328{332{
329 long us;333 long us;
330 return get(us) && us == l;334 return get(us) && us == l;
331}335}
332336
333bool dccl::MessageVal::operator==(bool b) const337bool goby::acomms::DCCLMessageVal::operator==(bool b) const
334{338{
335 bool us;339 bool us;
336 return get(us) && us == b;340 return get(us) && us == b;
@@ -338,7 +342,7 @@
338342
339343
340344
341std::ostream& dccl::operator<<(std::ostream& os, const dccl::MessageVal& mv)345std::ostream& goby::acomms::operator<<(std::ostream& os, const goby::acomms::DCCLMessageVal& mv)
342{346{
343 switch(mv.type_)347 switch(mv.type_)
344 {348 {
@@ -351,10 +355,10 @@
351}355}
352356
353 357
354std::ostream& dccl::operator<<(std::ostream& os, const std::vector<dccl::MessageVal>& vm)358std::ostream& goby::acomms::operator<<(std::ostream& os, const std::vector<goby::acomms::DCCLMessageVal>& vm)
355{359{
356 int j=0;360 int j=0;
357 BOOST_FOREACH(const dccl::MessageVal& m, vm)361 BOOST_FOREACH(const DCCLMessageVal& m, vm)
358 {362 {
359 if(j) os << ",";363 if(j) os << ",";
360 os << m;364 os << m;
361365
=== modified file 'src/acomms/libdccl/message_val.h'
--- src/acomms/libdccl/message_val.h 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_val.h 2010-07-15 12:38:39 +0000
@@ -25,157 +25,158 @@
25#include <boost/numeric/conversion/cast.hpp>25#include <boost/numeric/conversion/cast.hpp>
26#include <boost/lexical_cast.hpp> 26#include <boost/lexical_cast.hpp>
2727
28#include "util/tes_utils.h"
29#include "dccl_constants.h"28#include "dccl_constants.h"
3029
31namespace dccl30namespace goby
32{31{
32 namespace acomms
33 {
33 34
34/// defines a DCCL value35/// defines a DCCL value
35 class MessageVal36 class DCCLMessageVal
36 {37 {
37 public:38 public:
38 enum { MAX_DBL_PRECISION = 15 };39 enum { MAX_DBL_PRECISION = 15 };
39 40
40 /// \name Constructors/Destructor41 /// \name Constructors/Destructor
41 //@{ 42 //@{
42 /// empty43 /// empty
43 MessageVal();44 DCCLMessageVal();
44 45
45 /// construct with string value46 /// construct with string value
46 MessageVal(const std::string& s);47 DCCLMessageVal(const std::string& s);
47 48
48 /// construct with char* value49 /// construct with char* value
49 MessageVal(const char* s);50 DCCLMessageVal(const char* s);
50 51
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.
52 MessageVal(double d, int p = MAX_DBL_PRECISION);53 DCCLMessageVal(double d, int p = MAX_DBL_PRECISION);
53 54
54 /// construct with long value55 /// construct with long value
55 MessageVal(long l);56 DCCLMessageVal(long l);
56 57
57 /// construct with int value58 /// construct with int value
58 MessageVal(int i);59 DCCLMessageVal(int i);
59 60
60 /// construct with float value61 /// construct with float value
61 MessageVal(float f);62 DCCLMessageVal(float f);
62 63
63 /// construct with bool value64 /// construct with bool value
64 MessageVal(bool b);65 DCCLMessageVal(bool b);
6566
66 /// construct with vector67 /// construct with vector
67 MessageVal(const std::vector<MessageVal>& vm);68 DCCLMessageVal(const std::vector<DCCLMessageVal>& vm);
6869
69 70
70 71
71 //@}72 //@}
7273
73 /// \name Setters74 /// \name Setters
74 //@{ 75 //@{
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)
76 void set(std::string sval);77 void set(std::string sval);
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)
78 /// \param dval values to set79 /// \param dval values to set
79 /// \param precision decimal places of precision to preserve if this is cast to a string80 /// \param precision decimal places of precision to preserve if this is cast to a string
80 void set(double dval, int precision = MAX_DBL_PRECISION);81 void set(double dval, int precision = MAX_DBL_PRECISION);
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)
82 void set(long lval);83 void set(long lval);
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)
84 void set(bool bval);85 void set(bool bval);
8586
86 //@}87 //@}
87 88
88 /// \name Getters89 /// \name Getters
89 //@{ 90 //@{
90 /// \brief extract as std::string (all reasonable casts are done)91 /// \brief extract as std::string (all reasonable casts are done)
91 /// \param s std::string to store value in92 /// \param s std::string to store value in
92 /// \return successfully extracted (and if necessary successfully cast to this type)93 /// \return successfully extracted (and if necessary successfully cast to this type)
93 bool get(std::string& s) const;94 bool get(std::string& s) const;
94 /// \brief extract as bool (all reasonable casts are done)95 /// \brief extract as bool (all reasonable casts are done)
95 /// \param b bool to store value in96 /// \param b bool to store value in
96 /// \return successfully extracted (and if necessary successfully cast to this type)97 /// \return successfully extracted (and if necessary successfully cast to this type)
97 bool get(bool& b) const;98 bool get(bool& b) const;
98 /// \brief extract as long (all reasonable casts are done)99 /// \brief extract as long (all reasonable casts are done)
99 /// \param t long to store value in100 /// \param t long to store value in
100 /// \return successfully extracted (and if necessary successfully cast to this type)101 /// \return successfully extracted (and if necessary successfully cast to this type)
101 bool get(long& t) const; 102 bool get(long& t) const;
102 /// \brief extract as double (all reasonable casts are done)103 /// \brief extract as double (all reasonable casts are done)
103 /// \param d double to store value in104 /// \param d double to store value in
104 /// \return successfully extracted (and if necessary successfully cast to this type)105 /// \return successfully extracted (and if necessary successfully cast to this type)
105 bool get(double& d) const;106 bool get(double& d) const;
106107
107 ///108 ///
108 /// allows statements of the form \code double d = MessageVal("3.23"); \endcode109 /// allows statements of the form \code double d = DCCLMessageVal("3.23"); \endcode
109 operator double() const;110 operator double() const;
110111
111 ///112 ///
112 /// allows statements of the form \code bool b = MessageVal("1"); \endcode113 /// allows statements of the form \code bool b = DCCLMessageVal("1"); \endcode
113 operator bool() const;114 operator bool() const;
114115
115 ///116 ///
116 /// allows statements of the form \code std::string s = MessageVal(3); \endcode117 /// allows statements of the form \code std::string s = DCCLMessageVal(3); \endcode
117 operator std::string() const;118 operator std::string() const;
118119
119 ///120 ///
120 /// allows statements of the form \code long l = MessageVal(5); \endcode121 /// allows statements of the form \code long l = DCCLMessageVal(5); \endcode
121 operator long() const;122 operator long() const;
122123
123 ///124 ///
124 /// allows statements of the form \code int i = MessageVal(2); \endcode125 /// allows statements of the form \code int i = DCCLMessageVal(2); \endcode
125 operator int() const;126 operator int() const;
126127
127 ///128 ///
128 /// allows statements of the form \code unsigned u = MessageVal(2); \endcode129 /// allows statements of the form \code unsigned u = DCCLMessageVal(2); \endcode
129 operator unsigned() const;130 operator unsigned() const;
130131
131 ///132 ///
132 /// allows statements of the form \code float f = MessageVal("3.5"); \endcode133 /// allows statements of the form \code float f = DCCLMessageVal("3.5"); \endcode
133 operator float() const;134 operator float() const;
134135
135 operator std::vector<MessageVal>() const;136 operator std::vector<DCCLMessageVal>() const;
136 137
137138
138 /// what type is the original type of this MessageVal?139 /// what type is the original type of this DCCLMessageVal?
139 DCCLCppType type() const { return type_; }140 DCCLCppType type() const { return type_; }
140 141
141 /// was this just constructed with MessageVal() ? 142 /// was this just constructed with DCCLMessageVal() ?
142 bool empty() const { return type_ == cpp_notype; } 143 bool empty() const { return type_ == cpp_notype; }
143144
144 unsigned precision() const { return precision_; }145 unsigned precision() const { return precision_; }
145 146
146//@}147//@}
147148
148149
149 /// \name Comparison150 /// \name Comparison
150 //@{ 151 //@{
151 bool operator==(const MessageVal& mv) const;152 bool operator==(const DCCLMessageVal& mv) const;
152 bool operator==(const std::string& s) const; 153 bool operator==(const std::string& s) const;
153 bool operator==(double d) const;154 bool operator==(double d) const;
154 bool operator==(long l) const;155 bool operator==(long l) const;
155 bool operator==(bool b) const;156 bool operator==(bool b) const;
156 157
157 // @}158 // @}
158 159
159 private:160 private:
160 void init();161 void init();
161 162
162 friend std::ostream& operator<<(std::ostream& os, const MessageVal& mv);163 friend std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
163 164
164 private:165 private:
165 std::string sval_;166 std::string sval_;
166 double dval_;167 double dval_;
167 long lval_;168 long lval_;
168 bool bval_;169 bool bval_;
169170
170 unsigned precision_;171 unsigned precision_;
171172
172 DCCLCppType type_;173 DCCLCppType type_;
173 };174 };
174175
175 std::ostream& operator<<(std::ostream& os, const dccl::MessageVal& mv);176 std::ostream& operator<<(std::ostream& os, const acomms::DCCLMessageVal& mv);
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);
178 }
179
177}180}
178181
179
180
181#endif182#endif
182183
=== modified file 'src/acomms/libdccl/message_var.cpp'
--- src/acomms/libdccl/message_var.cpp 2010-06-15 04:51:47 +0000
+++ src/acomms/libdccl/message_var.cpp 2010-07-15 12:38:39 +0000
@@ -19,21 +19,21 @@
1919
20#include <boost/foreach.hpp>20#include <boost/foreach.hpp>
2121
22#include "util/tes_utils.h"22#include "goby/util/string.h"
2323
24#include "message_var.h"24#include "message_var.h"
25#include "message_val.h"25#include "message_val.h"
26#include "dccl_constants.h"26#include "dccl_constants.h"
27#include "message_algorithms.h"27#include "message_algorithms.h"
2828
29dccl::MessageVar::MessageVar()29goby::acomms::DCCLMessageVar::DCCLMessageVar()
30 : array_length_(1),30 : array_length_(1),
31 is_key_frame_(true),31 is_key_frame_(true),
32 source_set_(false),32 source_set_(false),
33 ap_(AlgorithmPerformer::getInstance())33 ap_(DCCLAlgorithmPerformer::getInstance())
34{ }34{ }
3535
36void dccl::MessageVar::initialize(const std::string& trigger_var)36void goby::acomms::DCCLMessageVar::initialize(const std::string& trigger_var)
37{37{
38 // add trigger_var_ as source_var for any message_vars without a source38 // add trigger_var_ as source_var for any message_vars without a source
39 if(!source_set_)39 if(!source_set_)
@@ -43,30 +43,30 @@
4343
44}44}
4545
46void dccl::MessageVar::set_defaults(std::map<std::string,std::vector<MessageVal> >& vals, unsigned modem_id, unsigned id)46void goby::acomms::DCCLMessageVar::set_defaults(std::map<std::string,std::vector<DCCLMessageVal> >& vals, unsigned modem_id, unsigned id)
47{47{
48 vals[name_].resize(array_length_); 48 vals[name_].resize(array_length_);
4949
50 std::vector<MessageVal>& vm = vals[name_];50 std::vector<DCCLMessageVal>& vm = vals[name_];
5151
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)
53 set_defaults_specific(vm[i], modem_id, id);53 set_defaults_specific(vm[i], modem_id, id);
5454
55}55}
5656
57 57
58void dccl::MessageVar::var_encode(std::map<std::string,std::vector<MessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits)58void goby::acomms::DCCLMessageVar::var_encode(std::map<std::string,std::vector<DCCLMessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits)
59{ 59{
60 // ensure that every MessageVar has the full number of (maybe blank) MessageVals60 // ensure that every DCCLMessageVar has the full number of (maybe blank) DCCLMessageVals
61 vals[name_].resize(array_length_);61 vals[name_].resize(array_length_);
6262
63 // copy so algorithms can modify directly and not affect other algorithms' use of original values63 // copy so algorithms can modify directly and not affect other algorithms' use of original values
64 std::vector<MessageVal> vm = vals[name_];64 std::vector<DCCLMessageVal> vm = vals[name_];
65 65
66 // write all the delta values first66 // write all the delta values first
67 is_key_frame_ = false;67 is_key_frame_ = false;
68 68
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)
70 {70 {
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)
72 ap_->algorithm(vm[i], i, algorithms_[j], vals);72 ap_->algorithm(vm[i], i, algorithms_[j], vals);
@@ -83,7 +83,7 @@
83 encode_value(key_val_, bits);83 encode_value(key_val_, bits);
84}84}
8585
86void dccl::MessageVar::encode_value(const MessageVal& val, boost::dynamic_bitset<unsigned char>& bits)86void goby::acomms::DCCLMessageVar::encode_value(const DCCLMessageVal& val, boost::dynamic_bitset<unsigned char>& bits)
87{87{
88 bits <<= calc_size();88 bits <<= calc_size();
89 89
@@ -94,7 +94,7 @@
94}94}
9595
9696
97void dccl::MessageVar::var_decode(std::map<std::string,std::vector<MessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits)97void goby::acomms::DCCLMessageVar::var_decode(std::map<std::string,std::vector<DCCLMessageVal> >& vals, boost::dynamic_bitset<unsigned char>& bits)
98{98{
99 vals[name_].resize(array_length_);99 vals[name_].resize(array_length_);
100 100
@@ -106,7 +106,7 @@
106 boost::dynamic_bitset<unsigned char> remove_bits = bits;106 boost::dynamic_bitset<unsigned char> remove_bits = bits;
107 remove_bits.resize(calc_size());107 remove_bits.resize(calc_size());
108108
109 MessageVal val = decode_specific(remove_bits);109 DCCLMessageVal val = decode_specific(remove_bits);
110 110
111 bits >>= calc_size();111 bits >>= calc_size();
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: