├── .gitignore ├── CMakeLists.txt ├── Documentation ├── MOOSV-10-256.pdf ├── examples │ ├── activequeuecomms.py │ ├── binarycomms.py │ ├── callbackcomms.py │ ├── callbackcomms_timewarp.py │ └── simplecomms.py └── python-moos.lyx ├── LICENSE ├── README.md └── pyMOOS.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | /.DS_Store 2 | /build 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project (python-moos) 3 | find_package(MOOS 10 REQUIRED) 4 | 5 | FIND_PACKAGE(PythonInterp 2.7) 6 | if(PYTHONINTERP_FOUND) 7 | EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('INCLUDEDIR')" OUTPUT_VARIABLE PYTHON_INCLUDE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) 8 | EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('LIBDIR')" OUTPUT_VARIABLE PYTHON_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) 9 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 10 | set(PYTHON_LIBRARIES "${PYTHON_LIB_PATH}/libpython2.7.dylib" CACHE FILEPATH "Path to the libpython2.7.dylib library file" FORCE) 11 | if(IS_DIRECTORY "${PYTHON_INCLUDE_PATH}/Python2.7") 12 | set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/Python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE) 13 | else() 14 | set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE) 15 | endif() 16 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 17 | set(PYTHON_LIBRARIES "${PYTHON_LIB_PATH}/x86_64-linux-gnu/libpython2.7.so" CACHE FILEPATH "Path to the libpython2.7.so library file" FORCE) 18 | if(IS_DIRECTORY "${PYTHON_INCLUDE_PATH}/Python2.7") 19 | set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/Python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE) 20 | else() 21 | set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE) 22 | endif() 23 | endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 24 | 25 | set(PYTHONLIBS_FOUND TRUE) 26 | message(STATUS "PYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARIES}") 27 | message(STATUS "PYTHON_INCLUDE_DIR:FILEPATH=${PYTHON_INCLUDE_DIRS}") 28 | 29 | else() 30 | find_package(PythonLibs) # default to standard cmake approach 31 | endif(PYTHONINTERP_FOUND) 32 | 33 | if(PYTHONLIBS_FOUND) 34 | include_directories("${PYTHON_INCLUDE_DIRS}") 35 | else() 36 | message(FATAL_ERROR "Unable to find PythonLibs.") 37 | endif() 38 | 39 | find_package(Boost REQUIRED python) 40 | set(Boost_USE_STATIC_LIBS ON) 41 | set(Boost_USE_MULTITHREADED ON) 42 | set(Boost_USE_STATIC_RUNTIME ON) 43 | 44 | if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 45 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) 46 | endif() 47 | 48 | if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 49 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 50 | endif() 51 | if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 52 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 53 | endif() 54 | 55 | 56 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${MOOS_INCLUDE_DIRS}) 57 | 58 | set(src 59 | pyMOOS.cpp 60 | ) 61 | 62 | add_library(pymoos SHARED ${src}) 63 | 64 | set_target_properties( pymoos 65 | PROPERTIES 66 | SUFFIX ".so" 67 | ) 68 | 69 | set_target_properties(pymoos 70 | PROPERTIES 71 | PREFIX "") 72 | 73 | 74 | file(GLOB ExampleFiles ${CMAKE_SOURCE_DIR}/Documentation/examples/*.py) 75 | add_custom_target(copy) 76 | get_target_property(pymoosLocation pymoos LOCATION) 77 | get_filename_component(pymoosDir ${pymoosLocation} PATH) 78 | foreach(ExampleFile ${ExampleFiles}) 79 | add_custom_command(TARGET copy PRE_BUILD 80 | COMMAND ${CMAKE_COMMAND} -E 81 | copy ${ExampleFile} ${pymoosDir}) 82 | endforeach() 83 | add_dependencies(pymoos copy) 84 | 85 | 86 | TARGET_LINK_LIBRARIES(pymoos ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES}) 87 | -------------------------------------------------------------------------------- /Documentation/MOOSV-10-256.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themoos/python-moos/68a8f3c9ee8fc8d509f7743a7b78d050f1b6654c/Documentation/MOOSV-10-256.pdf -------------------------------------------------------------------------------- /Documentation/examples/activequeuecomms.py: -------------------------------------------------------------------------------- 1 | import pymoos 2 | import time 3 | 4 | 5 | #simple example which uses an active queue to handle received messages 6 | #you can send any number of messages to any number of active queues 7 | comms = pymoos.comms() 8 | 9 | def c(): 10 | comms.register('simple_var',0) 11 | return True 12 | 13 | def queue_callback(msg): 14 | msg.trace(); 15 | return True; 16 | 17 | def main(): 18 | 19 | comms.set_on_connect_callback(c); 20 | comms.add_active_queue('the_queue',queue_callback) 21 | comms.add_message_route_to_active_queue('the_queue','simple_var') 22 | comms.run('localhost',9000,'pymoos') 23 | 24 | while True: 25 | time.sleep(1) 26 | comms.notify('simple_var','hello world',pymoos.time()); 27 | 28 | if __name__=="__main__": 29 | main() 30 | 31 | -------------------------------------------------------------------------------- /Documentation/examples/binarycomms.py: -------------------------------------------------------------------------------- 1 | 2 | import pymoos 3 | import time 4 | 5 | 6 | #simple example which uses an active queue to handle received messages 7 | #you can send any number of messages to any number of active queues 8 | #here we send binary data just to show we can 9 | comms = pymoos.comms() 10 | 11 | def c(): 12 | comms.register('binary_var',0) 13 | return True 14 | 15 | def queue_callback(msg): 16 | if msg.is_binary(): 17 | b = bytearray(msg.binary_data()) 18 | print 'received ', len(b), 'bytes' 19 | return True; 20 | 21 | def main(): 22 | comms.set_on_connect_callback(c); 23 | comms.add_active_queue('the_queue',queue_callback) 24 | comms.add_message_route_to_active_queue('the_queue','binary_var') 25 | comms.run('localhost',9000,'pymoos') 26 | 27 | while True: 28 | time.sleep(1) 29 | x = bytearray( [0, 3, 0x15, 2, 6, 0xAA] ) 30 | comms.notify_binary('binary_var',bytes(x),pymoos.time()); 31 | 32 | 33 | if __name__=="__main__": 34 | main() 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Documentation/examples/callbackcomms.py: -------------------------------------------------------------------------------- 1 | import pymoos 2 | import time 3 | 4 | #another simple example - here we install a callback which 5 | #fires every time mail arrives. We need to call fetch to 6 | #retrieve it though. We send mail in simple forever loop 7 | #We also subscribe to the same message.. 8 | 9 | comms = pymoos.comms() 10 | 11 | def c(): 12 | return comms.register('simple_var',0) 13 | 14 | def m(): 15 | map(lambda msg: msg.trace(), comms.fetch() ) 16 | return True 17 | 18 | def main(): 19 | 20 | comms.set_on_connect_callback(c); 21 | comms.set_on_mail_callback(m); 22 | comms.run('localhost',9000,'pymoos') 23 | 24 | while True: 25 | time.sleep(1) 26 | comms.notify('simple_var','a string',pymoos.time()); 27 | 28 | if __name__=="__main__": 29 | main() -------------------------------------------------------------------------------- /Documentation/examples/callbackcomms_timewarp.py: -------------------------------------------------------------------------------- 1 | import pymoos 2 | import time 3 | 4 | #another simple example - here we install a callback which 5 | #fires every time mail arrives. We need to call fetch to 6 | #retrieve it though. We send mail in simple forever loop 7 | #We also subscribe to the same message.. 8 | 9 | #This version demonstrates setting and using a timewarp that allows speeding up 10 | #simulations with MOOS 11 | 12 | comms = pymoos.comms() 13 | 14 | def c(): 15 | print("\t|-Time Warp @ {0:.1f} \n".format(pymoos.get_moos_timewarp())) 16 | print("\t|-Time Warp delay @ {0:.1f} ms \n".format( \ 17 | comms.get_comms_control_timewarp_scale_factor()*pymoos.get_moos_timewarp())) 18 | return comms.register('simple_var',0) 19 | 20 | def m(): 21 | map(lambda msg: msg.trace(), comms.fetch() ) 22 | return True 23 | 24 | def main(): 25 | 26 | comms.set_on_connect_callback(c) 27 | comms.set_on_mail_callback(m) 28 | pymoos.set_moos_timewarp(10) 29 | comms.set_comms_control_timewarp_scale_factor(0.4) 30 | comms.run('localhost',9000,'pymoos') 31 | 32 | while True: 33 | time.sleep(1.0) 34 | comms.notify('simple_var','a string',pymoos.time()) 35 | 36 | if __name__=="__main__": 37 | main() -------------------------------------------------------------------------------- /Documentation/examples/simplecomms.py: -------------------------------------------------------------------------------- 1 | import pymoos 2 | import time 3 | 4 | # A super simple example: 5 | # a) we make a comms object, and run it 6 | # b) we enter a forever loop in which we both send notifications 7 | # and check and print mail (with fetch) 8 | # c) the map(lambda,,,) bit simply applies trace() to every message to print 9 | # a summary of the message. 10 | 11 | comms = pymoos.comms() 12 | 13 | def on_connect(): 14 | return comms.register('simple_var',0) 15 | 16 | def main(): 17 | # my code here 18 | comms.set_on_connect_callback(on_connect); 19 | comms.run('localhost',9000,'pymoos') 20 | 21 | while True: 22 | time.sleep(1) 23 | comms.notify('simple_var','hello world',pymoos.time()); 24 | map(lambda msg: msg.trace(), comms.fetch()) 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /Documentation/python-moos.lyx: -------------------------------------------------------------------------------- 1 | #LyX 2.0 created this file. For more info see http://www.lyx.org/ 2 | \lyxformat 413 3 | \begin_document 4 | \begin_header 5 | \textclass paper 6 | \begin_preamble 7 | \usepackage{verbatim} 8 | %\usepackage{xcolor} 9 | \usepackage{listings} 10 | \usepackage{textcomp} 11 | \lstdefinestyle{Bash} 12 | {language=bash, 13 | keywordstyle=\color{blue}, 14 | basicstyle=\ttfamily, 15 | morekeywords={moosuser@machine}, 16 | alsoletter={:~$}, 17 | morekeywords=[2]{moosuser@machine:}, 18 | keywordstyle=[2]{\color{red}}, 19 | literate={\$}{{\textcolor{red}{\$}}}1 20 | {:}{{\textcolor{red}{:}}}1 21 | {~}{{\textcolor{red}{\textasciitilde}}}1, 22 | } 23 | 24 | \usepackage[usenames,dvipsnames]{xcolor} 25 | 26 | \usepackage{listings} 27 | \definecolor{codebg}{HTML}{E0E0F0} 28 | \lstset{ 29 | tabsize=4, 30 | language=Python, 31 | basicstyle=\small, 32 | upquote=true, 33 | %aboveskip={1.5\baselineskip}, 34 | columns=fixed, 35 | showstringspaces=false, 36 | extendedchars=true, 37 | breaklines=true, 38 | framesep=10pt, 39 | prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, 40 | frame=single, 41 | showtabs=false, 42 | showspaces=false, 43 | showstringspaces=false, 44 | identifierstyle=\ttfamily, 45 | keywordstyle=\color[rgb]{0,0,1}, 46 | commentstyle=\color[rgb]{0.133,0.545,0.133}, 47 | stringstyle=\color[rgb]{0.627,0.126,0.941}, 48 | backgroundcolor=\color{codebg}, 49 | } 50 | \end_preamble 51 | \use_default_options true 52 | \begin_modules 53 | eqs-within-sections 54 | figs-within-sections 55 | logicalmkup 56 | \end_modules 57 | \maintain_unincluded_children false 58 | \language english 59 | \language_package default 60 | \inputencoding auto 61 | \fontencoding global 62 | \font_roman default 63 | \font_sans default 64 | \font_typewriter default 65 | \font_default_family default 66 | \use_non_tex_fonts false 67 | \font_sc false 68 | \font_osf false 69 | \font_sf_scale 100 70 | \font_tt_scale 100 71 | 72 | \graphics default 73 | \default_output_format default 74 | \output_sync 0 75 | \bibtex_command default 76 | \index_command default 77 | \paperfontsize default 78 | \spacing single 79 | \use_hyperref false 80 | \papersize default 81 | \use_geometry true 82 | \use_amsmath 1 83 | \use_esint 1 84 | \use_mhchem 1 85 | \use_mathdots 1 86 | \cite_engine basic 87 | \use_bibtopic false 88 | \use_indices false 89 | \paperorientation portrait 90 | \suppress_date false 91 | \use_refstyle 1 92 | \index Index 93 | \shortcut idx 94 | \color #008000 95 | \end_index 96 | \leftmargin 3cm 97 | \topmargin 3cm 98 | \rightmargin 3cm 99 | \bottommargin 3cm 100 | \secnumdepth 2 101 | \tocdepth 2 102 | \paragraph_separation indent 103 | \paragraph_indentation default 104 | \quotes_language english 105 | \papercolumns 1 106 | \papersides 1 107 | \paperpagestyle default 108 | \tracking_changes false 109 | \output_changes false 110 | \html_math_output 0 111 | \html_css_as_file 0 112 | \html_be_strict false 113 | \end_header 114 | 115 | \begin_body 116 | 117 | \begin_layout Title 118 | python-moos: Python for MOOS:V10 Communications 119 | \end_layout 120 | 121 | \begin_layout Author 122 | Paul Newman, University of Oxford 123 | \end_layout 124 | 125 | \begin_layout Standard 126 | \align center 127 | \begin_inset Graphics 128 | filename MOOSV-10-256.pdf 129 | width 3cm 130 | 131 | \end_inset 132 | 133 | 134 | \end_layout 135 | 136 | \begin_layout Standard 137 | \align center 138 | \begin_inset ERT 139 | status open 140 | 141 | \begin_layout Plain Layout 142 | 143 | 144 | \backslash 145 | vspace{2cm} 146 | \end_layout 147 | 148 | \end_inset 149 | 150 | ....ten years on 151 | \end_layout 152 | 153 | \begin_layout Standard 154 | \align center 155 | \begin_inset ERT 156 | status open 157 | 158 | \begin_layout Plain Layout 159 | 160 | 161 | \backslash 162 | vspace{2cm} 163 | \end_layout 164 | 165 | \end_inset 166 | 167 | 10.0.2 168 | \end_layout 169 | 170 | \begin_layout Standard 171 | \begin_inset Newpage newpage 172 | \end_inset 173 | 174 | 175 | \end_layout 176 | 177 | \begin_layout Standard 178 | \begin_inset CommandInset toc 179 | LatexCommand tableofcontents 180 | 181 | \end_inset 182 | 183 | 184 | \end_layout 185 | 186 | \begin_layout Standard 187 | \begin_inset Newpage newpage 188 | \end_inset 189 | 190 | 191 | \end_layout 192 | 193 | \begin_layout Section 194 | Getting Started - Acquiring and Building MOOS 195 | \end_layout 196 | 197 | \begin_layout Standard 198 | If you already have MOOS::V10 installed and built you can skip this section. 199 | \end_layout 200 | 201 | \begin_layout Subsection 202 | Before you start you will need... 203 | \end_layout 204 | 205 | \begin_layout Itemize 206 | a working compiler like 207 | \family typewriter 208 | gcc 209 | \family default 210 | or 211 | \family typewriter 212 | clang 213 | \end_layout 214 | 215 | \begin_layout Itemize 216 | 217 | \family typewriter 218 | CMake 219 | \family default 220 | installed 221 | \end_layout 222 | 223 | \begin_layout Itemize 224 | 225 | \family typewriter 226 | git 227 | \family default 228 | installed (well actually this is optional as you can download the source 229 | code as .zip file and we won't make much use of git in this tutorial) 230 | \end_layout 231 | 232 | \begin_layout Itemize 233 | boost (http://www.boost.org) installed. 234 | Why you might ask? Well python-moos uses the boost python suite to facilitate 235 | binding MOOS to python. 236 | It is dead good. 237 | You will need boost-python installed. 238 | \end_layout 239 | 240 | \begin_layout Subsection 241 | Downloading and Building MOOS V10 242 | \begin_inset CommandInset label 243 | LatexCommand label 244 | name "sub:Downloading-and-Building" 245 | 246 | \end_inset 247 | 248 | 249 | \end_layout 250 | 251 | \begin_layout Standard 252 | We shall begin where we should and check out a version of MOOS-V10 from 253 | a git repos. 254 | We will follow good practice and do an out of place build - the source 255 | code will go in 256 | \begin_inset Quotes eld 257 | \end_inset 258 | 259 | src 260 | \begin_inset Quotes erd 261 | \end_inset 262 | 263 | and we will build in 264 | \begin_inset Quotes eld 265 | \end_inset 266 | 267 | build 268 | \begin_inset Quotes erd 269 | \end_inset 270 | 271 | . 272 | We will also, after fetching the source switch to the 273 | \begin_inset Quotes eld 274 | \end_inset 275 | 276 | devel 277 | \begin_inset Quotes erd 278 | \end_inset 279 | 280 | branch because here we are living on the edge 281 | \begin_inset Foot 282 | status open 283 | 284 | \begin_layout Plain Layout 285 | if you want to know what branches are available type 286 | \family typewriter 287 | git branch 288 | \end_layout 289 | 290 | \end_inset 291 | 292 | 293 | \family typewriter 294 | . 295 | \end_layout 296 | 297 | \begin_layout Standard 298 | \begin_inset ERT 299 | status open 300 | 301 | \begin_layout Plain Layout 302 | 303 | 304 | \backslash 305 | begin{lstlisting}[style=Bash] 306 | \end_layout 307 | 308 | \begin_layout Plain Layout 309 | 310 | pmn@mac:~$ mkdir core-moos-v10 311 | \end_layout 312 | 313 | \begin_layout Plain Layout 314 | 315 | pmn@mac:~$ cd core-moos-v10 316 | \end_layout 317 | 318 | \begin_layout Plain Layout 319 | 320 | pmn@mac:~$ git clone https://github.com/themoos/core-moos.git src 321 | \end_layout 322 | 323 | \begin_layout Plain Layout 324 | 325 | pmn@mac:~$ mkdir build 326 | \end_layout 327 | 328 | \begin_layout Plain Layout 329 | 330 | pmn@mac:~$ cd build 331 | \end_layout 332 | 333 | \begin_layout Plain Layout 334 | 335 | pmn@mac:~$ ccmake ../src 336 | \end_layout 337 | 338 | \begin_layout Plain Layout 339 | 340 | 341 | \backslash 342 | end{lstlisting} 343 | \end_layout 344 | 345 | \end_inset 346 | 347 | 348 | \end_layout 349 | 350 | \begin_layout Standard 351 | At this point you should, after hitting 'c' a couple of times be presented 352 | with a CMake screen that looks like that shown in Figure 353 | \begin_inset CommandInset ref 354 | LatexCommand ref 355 | reference "fig:The-default-build" 356 | 357 | \end_inset 358 | 359 | (note some of the entries are platform dependent so don't worry if what 360 | you see is not identical to this). 361 | 362 | \end_layout 363 | 364 | \begin_layout Standard 365 | \begin_inset Float figure 366 | wide false 367 | sideways false 368 | status open 369 | 370 | \begin_layout Plain Layout 371 | \align center 372 | \begin_inset Graphics 373 | filename ../../examples-docs-moos/docs/images/v10-simple-build.pdf 374 | width 90col% 375 | 376 | \end_inset 377 | 378 | 379 | \begin_inset Caption 380 | 381 | \begin_layout Plain Layout 382 | \begin_inset CommandInset label 383 | LatexCommand label 384 | name "fig:The-default-build" 385 | 386 | \end_inset 387 | 388 | The default build screen for MOOS V10. 389 | 390 | \end_layout 391 | 392 | \end_inset 393 | 394 | 395 | \end_layout 396 | 397 | \begin_layout Plain Layout 398 | 399 | \end_layout 400 | 401 | \end_inset 402 | 403 | 404 | \end_layout 405 | 406 | \begin_layout Standard 407 | \begin_inset ERT 408 | status open 409 | 410 | \begin_layout Plain Layout 411 | 412 | 413 | \backslash 414 | vspace{5mm} 415 | \end_layout 416 | 417 | \end_inset 418 | 419 | 420 | \end_layout 421 | 422 | \begin_layout Standard 423 | You are are now in a position to build the MOOS. 424 | So press 'c' until 'g' appears, then press 'g' and you are good to go. 425 | Then at the terminal prompt type 'make' to build the project. 426 | Two directories should have been created 427 | \series bold 428 | bin 429 | \series default 430 | and 431 | \series bold 432 | lib. 433 | 434 | \series default 435 | In lib you will see 436 | \family typewriter 437 | libMOOS.a 438 | \family default 439 | and in 440 | \family typewriter 441 | bin 442 | \family default 443 | you will find the newly created 444 | \family typewriter 445 | MOOSDB 446 | \family default 447 | and some other fabulous tools like 448 | \begin_inset Flex Noun 449 | status collapsed 450 | 451 | \begin_layout Plain Layout 452 | umm 453 | \end_layout 454 | 455 | \end_inset 456 | 457 | , 458 | \begin_inset Flex Noun 459 | status collapsed 460 | 461 | \begin_layout Plain Layout 462 | mtm 463 | \end_layout 464 | 465 | \end_inset 466 | 467 | and 468 | \begin_inset Flex Noun 469 | status collapsed 470 | 471 | \begin_layout Plain Layout 472 | mqos 473 | \end_layout 474 | 475 | \end_inset 476 | 477 | . 478 | Nice job. 479 | \end_layout 480 | 481 | \begin_layout Section 482 | Acquiring python-moos 483 | \end_layout 484 | 485 | \begin_layout Standard 486 | \begin_inset Flex Noun 487 | status collapsed 488 | 489 | \begin_layout Plain Layout 490 | python-moos 491 | \end_layout 492 | 493 | \end_inset 494 | 495 | is hosted on github (at time of writing) but where ever you get it from 496 | the build path looks somethign like this. 497 | 498 | \end_layout 499 | 500 | \begin_layout Standard 501 | \begin_inset ERT 502 | status open 503 | 504 | \begin_layout Plain Layout 505 | 506 | 507 | \backslash 508 | begin{lstlisting}[style=Bash] 509 | \end_layout 510 | 511 | \begin_layout Plain Layout 512 | 513 | pmn@mac:~$ mkdir python-moos 514 | \end_layout 515 | 516 | \begin_layout Plain Layout 517 | 518 | pmn@mac:~$ cd python-moos 519 | \end_layout 520 | 521 | \begin_layout Plain Layout 522 | 523 | pmn@mac:~$ git clone https://github.com/themoos/python-moos.git src 524 | \end_layout 525 | 526 | \begin_layout Plain Layout 527 | 528 | pmn@mac:~$ mkdir build 529 | \end_layout 530 | 531 | \begin_layout Plain Layout 532 | 533 | pmn@mac:~$ cd build 534 | \end_layout 535 | 536 | \begin_layout Plain Layout 537 | 538 | pmn@mac:~$ ccmake ../src 539 | \end_layout 540 | 541 | \begin_layout Plain Layout 542 | 543 | 544 | \backslash 545 | end{lstlisting} 546 | \end_layout 547 | 548 | \end_inset 549 | 550 | 551 | \end_layout 552 | 553 | \begin_layout Standard 554 | At the end of this process you should see in the build director some example 555 | python scripts and the python-moos library (most likely called pymoos.so). 556 | This object is importable into python. 557 | The next section will show how. 558 | 559 | \end_layout 560 | 561 | \begin_layout Section 562 | Getting help 563 | \end_layout 564 | 565 | \begin_layout Standard 566 | You can see quickly seewhat goodies are offered by a class by calling for 567 | example 568 | \family typewriter 569 | dir(pymoos.comms), 570 | \family default 571 | 572 | \begin_inset Flex Code 573 | status collapsed 574 | 575 | \begin_layout Plain Layout 576 | dir(pymoos.comms) 577 | \end_layout 578 | 579 | \end_inset 580 | 581 | or dir(pymoos.moos_msg). 582 | For example: 583 | \end_layout 584 | 585 | \begin_layout Standard 586 | \begin_inset ERT 587 | status open 588 | 589 | \begin_layout Plain Layout 590 | 591 | 592 | \backslash 593 | begin{lstlisting}[style=Bash] 594 | \end_layout 595 | 596 | \begin_layout Plain Layout 597 | 598 | pmn@mac:~$ python 599 | \end_layout 600 | 601 | \begin_layout Plain Layout 602 | 603 | pmn@mac:~$>> import pymoos 604 | \end_layout 605 | 606 | \begin_layout Plain Layout 607 | 608 | pmn@mac:~$>> dir(pymoos.comms) 609 | \end_layout 610 | 611 | \begin_layout Plain Layout 612 | 613 | pmn@mac:~$>>....'add_active_queue', 'add_message_route_to_active_queue', 'close', 614 | 'do_local_time_correction', 'enable_comms_status_monitoring', 'fetch', 615 | 'get_client_comms_status', 'get_client_comms_statuses', 'get_comms_control_time 616 | warp_scale_factor', 'get_community_name', 'get_description', 'get_moos_name',... 617 | \end_layout 618 | 619 | \begin_layout Plain Layout 620 | 621 | 622 | \backslash 623 | end{lstlisting} 624 | \end_layout 625 | 626 | \end_inset 627 | 628 | Alternatively you can access help via python's 'help' interface which will 629 | show you all the methods supported and the c++ signatures they wrap. 630 | \end_layout 631 | 632 | \begin_layout Standard 633 | \begin_inset ERT 634 | status open 635 | 636 | \begin_layout Plain Layout 637 | 638 | 639 | \backslash 640 | begin{lstlisting}[style=Bash] 641 | \end_layout 642 | 643 | \begin_layout Plain Layout 644 | 645 | pmn@mac:~$ python 646 | \end_layout 647 | 648 | \begin_layout Plain Layout 649 | 650 | pmn@mac:~$>> import pymoos 651 | \end_layout 652 | 653 | \begin_layout Plain Layout 654 | 655 | pmn@mac:~$>> help(pymoos.moos_msg) 656 | \end_layout 657 | 658 | \begin_layout Plain Layout 659 | 660 | | 661 | \end_layout 662 | 663 | \begin_layout Plain Layout 664 | 665 | | binary_data_size(...) 666 | \end_layout 667 | 668 | \begin_layout Plain Layout 669 | 670 | | binary_data_size( (moos_msg)arg1) -> int : 671 | \end_layout 672 | 673 | \begin_layout Plain Layout 674 | 675 | | 676 | \end_layout 677 | 678 | \begin_layout Plain Layout 679 | 680 | | C++ signature : 681 | \end_layout 682 | 683 | \begin_layout Plain Layout 684 | 685 | | unsigned int binary_data_size(CMOOSMsg {lvalue}) 686 | \end_layout 687 | 688 | \begin_layout Plain Layout 689 | 690 | | 691 | \end_layout 692 | 693 | \begin_layout Plain Layout 694 | 695 | | double(...) 696 | \end_layout 697 | 698 | \begin_layout Plain Layout 699 | 700 | | double( (moos_msg)arg1) -> float : 701 | \end_layout 702 | 703 | \begin_layout Plain Layout 704 | 705 | | 706 | \end_layout 707 | 708 | \begin_layout Plain Layout 709 | 710 | | C++ signature : 711 | \end_layout 712 | 713 | \begin_layout Plain Layout 714 | 715 | | double double(CMOOSMsg {lvalue}) 716 | \end_layout 717 | 718 | \begin_layout Plain Layout 719 | 720 | | 721 | \end_layout 722 | 723 | \begin_layout Plain Layout 724 | 725 | | double_aux(...) 726 | \end_layout 727 | 728 | \begin_layout Plain Layout 729 | 730 | | double_aux( (moos_msg)arg1) -> float : 731 | \end_layout 732 | 733 | \begin_layout Plain Layout 734 | 735 | | 736 | \end_layout 737 | 738 | \begin_layout Plain Layout 739 | 740 | | C++ signature : 741 | \end_layout 742 | 743 | \begin_layout Plain Layout 744 | 745 | | double double_aux(CMOOSMsg {lvalue}) 746 | \end_layout 747 | 748 | \begin_layout Plain Layout 749 | 750 | | 751 | \end_layout 752 | 753 | \begin_layout Plain Layout 754 | 755 | | is_binary(...) 756 | \end_layout 757 | 758 | \begin_layout Plain Layout 759 | 760 | | is_binary( (moos_msg)arg1) -> bool : 761 | \end_layout 762 | 763 | \begin_layout Plain Layout 764 | 765 | 766 | \backslash 767 | end{lstlisting} 768 | \end_layout 769 | 770 | \end_inset 771 | 772 | 773 | \end_layout 774 | 775 | \begin_layout Section 776 | A simple python-moos example 777 | \end_layout 778 | 779 | \begin_layout Standard 780 | Lets start with the simplest possible MOOS interface - a simple program 781 | that connects to a MOOS community occasionally sends a message and also 782 | subscribes to a message - in this case the same one). 783 | 784 | \end_layout 785 | 786 | \begin_layout Standard 787 | \begin_inset ERT 788 | status open 789 | 790 | \begin_layout Plain Layout 791 | 792 | 793 | \backslash 794 | lstinputlisting[caption={A simple example using python-moos}]{examples/simplecom 795 | ms.py} 796 | \end_layout 797 | 798 | \end_inset 799 | 800 | 801 | \end_layout 802 | 803 | \begin_layout Subsection* 804 | pymoos::comms 805 | \end_layout 806 | 807 | \begin_layout Standard 808 | Looking at this example, first we import 809 | \begin_inset Flex Noun 810 | status collapsed 811 | 812 | \begin_layout Plain Layout 813 | pymoos 814 | \end_layout 815 | 816 | \end_inset 817 | 818 | and make ourselves a 819 | \begin_inset Flex Code 820 | status collapsed 821 | 822 | \begin_layout Plain Layout 823 | pymoos.comms 824 | \end_layout 825 | 826 | \end_inset 827 | 828 | object. 829 | This is the object that provides MOOS comms functionality. 830 | 831 | \end_layout 832 | 833 | \begin_layout Standard 834 | Then we define a function, 835 | \begin_inset Flex Code 836 | status collapsed 837 | 838 | \begin_layout Plain Layout 839 | on_connect 840 | \end_layout 841 | 842 | \end_inset 843 | 844 | which will be called when we connect to a MOOSDB and in which, as all good 845 | moos citizens do, we regsiter our interest in messages. 846 | In this case we want to know about any changes made to 847 | \family typewriter 848 | simple_var 849 | \family default 850 | . 851 | 852 | \end_layout 853 | 854 | \begin_layout Standard 855 | Then we define a main which begins with installing the connection callback, 856 | running the the comms and entering a simple a 857 | \begin_inset Flex Code 858 | status collapsed 859 | 860 | \begin_layout Plain Layout 861 | while 862 | \end_layout 863 | 864 | \end_inset 865 | 866 | (1) which sleeps for a second, sends a message and then polls the comms 867 | object to see if any messages have arrived (with 868 | \begin_inset Flex Code 869 | status collapsed 870 | 871 | \begin_layout Plain Layout 872 | comms.fetch() 873 | \end_layout 874 | 875 | \end_inset 876 | 877 | ) and, if they have, prints them all out using some fancy python 878 | \begin_inset Quotes eld 879 | \end_inset 880 | 881 | map 882 | \begin_inset Quotes erd 883 | \end_inset 884 | 885 | functionality and the 886 | \begin_inset Flex Code 887 | status collapsed 888 | 889 | \begin_layout Plain Layout 890 | pymoos.moos_msg.trace() 891 | \end_layout 892 | 893 | \end_inset 894 | 895 | method. 896 | Note that 897 | \family typewriter 898 | fetch() 899 | \family default 900 | returns a python list of 901 | \family typewriter 902 | moos_msg 903 | \family default 904 | s. 905 | \end_layout 906 | 907 | \begin_layout Standard 908 | So we have now seen a trivial example using polling to retrieve any incoming 909 | messages. 910 | Before we up our game, it is worth quickly looking at 911 | \family typewriter 912 | pymoos.moos_msg. 913 | \end_layout 914 | 915 | \begin_layout Subsection* 916 | pymoos::moos_msg 917 | \end_layout 918 | 919 | \begin_layout Standard 920 | Where in c++ land we have 921 | \family typewriter 922 | CMOOSMsg 923 | \family default 924 | , in python land we have 925 | \family typewriter 926 | pymoos.moos_msg. 927 | 928 | \family default 929 | Many of the methods of the former are exposed in the latter. 930 | Again you can see them by calling 931 | \family typewriter 932 | dir(pymoos.moos_msg). 933 | 934 | \family default 935 | 936 | \end_layout 937 | 938 | \begin_layout Section 939 | A python-moos example with a message callback 940 | \end_layout 941 | 942 | \begin_layout Standard 943 | In the next example, we install a messaging callback( we call it 944 | \family typewriter 945 | m() 946 | \family default 947 | here). 948 | Everytime mail arrives we are given the opportunity to grab it using fetch() 949 | and print it. 950 | 951 | \end_layout 952 | 953 | \begin_layout Standard 954 | \begin_inset ERT 955 | status open 956 | 957 | \begin_layout Plain Layout 958 | 959 | 960 | \backslash 961 | lstinputlisting[caption={A msg callback example using python-moos}]{examples/cal 962 | lbackcomms.py} 963 | \end_layout 964 | 965 | \end_inset 966 | 967 | 968 | \end_layout 969 | 970 | \begin_layout Standard 971 | But do be careful.... 972 | \family typewriter 973 | m() 974 | \family default 975 | is being called in a different thread to the 976 | \family typewriter 977 | while() 978 | \family default 979 | loop in main. 980 | The python interpreter is appropriately locked though so don't panic too 981 | much. 982 | \end_layout 983 | 984 | \begin_layout Section 985 | A python-moos example with active queues 986 | \end_layout 987 | 988 | \begin_layout Standard 989 | Active queues are a mechanism to route messages to dedicated handling threads 990 | or 'queues'. 991 | As messages are received they can be distributed according to preferences 992 | configured by a simple API, to activie queues. 993 | Each named queue processes messages sequentially and applies a user specified 994 | callback to each message. 995 | \end_layout 996 | 997 | \begin_layout Standard 998 | \begin_inset ERT 999 | status open 1000 | 1001 | \begin_layout Plain Layout 1002 | 1003 | 1004 | \backslash 1005 | lstinputlisting[caption={A msg callback example using python-moos}]{examples/act 1006 | ivequeuecomms.py} 1007 | \end_layout 1008 | 1009 | \end_inset 1010 | 1011 | 1012 | \end_layout 1013 | 1014 | \begin_layout Standard 1015 | The important lines are 1016 | \end_layout 1017 | 1018 | \begin_layout Standard 1019 | \begin_inset ERT 1020 | status open 1021 | 1022 | \begin_layout Plain Layout 1023 | 1024 | 1025 | \backslash 1026 | begin{lstlisting}[language=Python] 1027 | \end_layout 1028 | 1029 | \begin_layout Plain Layout 1030 | 1031 | comms.add_active_queue('the_queue' , queue_callback ) 1032 | \end_layout 1033 | 1034 | \begin_layout Plain Layout 1035 | 1036 | comms.add_message_route_to_active_queue ('the_queue' , 'binary_var' ) 1037 | \end_layout 1038 | 1039 | \begin_layout Plain Layout 1040 | 1041 | 1042 | \backslash 1043 | end{lstlisting} 1044 | \end_layout 1045 | 1046 | \end_inset 1047 | 1048 | 1049 | \end_layout 1050 | 1051 | \begin_layout Standard 1052 | The first line creates an active queue called ' 1053 | \family typewriter 1054 | the_queue 1055 | \family default 1056 | ' and attaches the function 1057 | \family typewriter 1058 | queue 1059 | \family default 1060 | _ 1061 | \family typewriter 1062 | callback 1063 | \family default 1064 | to it. 1065 | The second line instructs the comms object to place a copy of any message 1066 | called 'binary_var' into this queue so it will end up being processed by 1067 | 1068 | \family typewriter 1069 | queue 1070 | \family default 1071 | _ 1072 | \family typewriter 1073 | callback. 1074 | \end_layout 1075 | 1076 | \begin_layout Section 1077 | Dealing with binary data 1078 | \end_layout 1079 | 1080 | \begin_layout Standard 1081 | MOOS is at home with binary data of course. 1082 | The next example makes this clear by building on the previous active queue 1083 | example. 1084 | You can see if someone sent you binary data via the 1085 | \family typewriter 1086 | moos_msg.is_binary() 1087 | \family default 1088 | method. 1089 | And you can send binary data with the 1090 | \family typewriter 1091 | comms.binary_notify() 1092 | \family default 1093 | method 1094 | \end_layout 1095 | 1096 | \begin_layout Standard 1097 | \begin_inset ERT 1098 | status open 1099 | 1100 | \begin_layout Plain Layout 1101 | 1102 | 1103 | \backslash 1104 | lstinputlisting[caption={sending and receiving binary data using python-moos}]{e 1105 | xamples/binarycomms.py} 1106 | \end_layout 1107 | 1108 | \end_inset 1109 | 1110 | 1111 | \end_layout 1112 | 1113 | \end_body 1114 | \end_document 1115 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | python-moos 2 | =========== 3 | 4 | python bindings for MOOS 5 | -------------------------------------------------------------------------------- /pyMOOS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MOOS/libMOOS/Comms/MOOSMsg.h" 3 | #include "MOOS/libMOOS/Comms/MOOSCommClient.h" 4 | #include "MOOS/libMOOS/Comms/MOOSAsyncCommClient.h" 5 | 6 | #include 7 | #include 8 | 9 | 10 | 11 | typedef std::vector MsgVector; 12 | typedef std::vector CommsStatusVector; 13 | 14 | namespace bp = boost::python; 15 | 16 | struct pyMOOSException : std::exception { 17 | pyMOOSException() { 18 | } 19 | ; 20 | virtual ~pyMOOSException() throw () { 21 | } 22 | ; 23 | 24 | pyMOOSException(const std::string & s) : 25 | s_(s) { 26 | } 27 | char const* what() const throw () { 28 | return s_.c_str(); 29 | } 30 | std::string s_; 31 | }; 32 | 33 | void MOOSExceptionTranslator(const pyMOOSException & e) { 34 | // Use the Python 'C' API to set up an exception object 35 | PyErr_SetString(PyExc_RuntimeError, e.what()); 36 | } 37 | 38 | namespace MOOS { 39 | 40 | /** this is a class which wraps MOOS::MOOSAsyncCommClient to provide 41 | * and interface more suitable for python wrapping 42 | */ 43 | class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient { 44 | private: 45 | typedef MOOSAsyncCommClient BASE; 46 | public: 47 | 48 | ~AsyncCommsWrapper(){ 49 | Close(true); 50 | } 51 | 52 | bool Run(const std::string & sServer, int Port, const std::string & sMyName) { 53 | return BASE::Run(sServer, Port, sMyName, 0);//Comms Tick not used in Async version 54 | } 55 | 56 | //we can support vectors of objects by not lists so 57 | //here we have a funtion which copies a list to vector 58 | MsgVector FetchMailAsVector() { 59 | MsgVector v; 60 | MOOSMSG_LIST M; 61 | if (Fetch(M)) { 62 | std::copy(M.begin(), M.end(), std::back_inserter(v)); 63 | } 64 | 65 | return v; 66 | } 67 | 68 | /* python strings can be binary lets make this specific*/ 69 | bool NotifyBinary(const std::string& sKey, const std::string & sData, 70 | double dfTime) { 71 | CMOOSMsg M(MOOS_NOTIFY, sKey, sData.size(), (void *) sData.data(), 72 | dfTime); 73 | return BASE::Post(M); 74 | } 75 | 76 | static bool on_connect_delegate(void * pParam) { 77 | MOOS::AsyncCommsWrapper * pMe = 78 | static_cast (pParam); 79 | return pMe->on_connect(); 80 | } 81 | bool SetOnConnectCallback(bp::object func) { 82 | BASE: SetOnConnectCallBack(on_connect_delegate, this); 83 | on_connect_object_ = func; 84 | return true; 85 | } 86 | 87 | bool Close(bool nice){ 88 | bool bResult = false; 89 | 90 | Py_BEGIN_ALLOW_THREADS 91 | //PyGILState_STATE gstate = PyGILState_Ensure(); 92 | closing_ = true; 93 | bResult = BASE::Close(true); 94 | 95 | //PyGILState_Release(gstate); 96 | Py_END_ALLOW_THREADS 97 | 98 | return bResult; 99 | } 100 | 101 | 102 | bool on_connect() { 103 | 104 | bool bResult = false; 105 | 106 | PyGILState_STATE gstate = PyGILState_Ensure(); 107 | try { 108 | bp::object result = on_connect_object_(); 109 | bResult = bp::extract(result); 110 | } catch (const bp::error_already_set& e) { 111 | PyGILState_Release(gstate); 112 | throw pyMOOSException( 113 | "OnConnect:: caught an exception thrown in python callback"); 114 | } 115 | 116 | PyGILState_Release(gstate); 117 | 118 | return bResult; 119 | 120 | } 121 | 122 | bool SetOnMailCallback(bp::object func) { 123 | BASE: SetOnMailCallBack(on_mail_delegate, this); 124 | on_mail_object_ = func; 125 | return true; 126 | } 127 | 128 | static bool on_mail_delegate(void * pParam) { 129 | MOOS::AsyncCommsWrapper * pMe = 130 | static_cast (pParam); 131 | return pMe->on_mail(); 132 | } 133 | 134 | bool on_mail() { 135 | bool bResult = false; 136 | 137 | PyGILState_STATE gstate = PyGILState_Ensure(); 138 | try { 139 | if(!closing_){ 140 | bp::object result = on_mail_object_(); 141 | bResult = bp::extract(result); 142 | } 143 | } catch (const bp::error_already_set& e) { 144 | PyGILState_Release(gstate); 145 | throw pyMOOSException( 146 | "OnMail:: caught an exception thrown in python callback"); 147 | } 148 | 149 | PyGILState_Release(gstate); 150 | 151 | return bResult; 152 | } 153 | 154 | static bool active_queue_delegate(CMOOSMsg & M, void* pParam) { 155 | MeAndQueue * maq = static_cast (pParam); 156 | return maq->me_->OnQueue(M, maq->queue_name_); 157 | } 158 | 159 | bool OnQueue(CMOOSMsg & M, const std::string & sQueueName) { 160 | std::map::iterator q; 161 | 162 | { 163 | MOOS::ScopedLock L(queue_api_lock_); 164 | q = active_queue_details_.find(sQueueName); 165 | if (q == active_queue_details_.end()) 166 | return false; 167 | } 168 | 169 | bool bResult = false; 170 | 171 | PyGILState_STATE gstate = PyGILState_Ensure(); 172 | try { 173 | bp::object result = q->second->func_(M); 174 | bResult = bp::extract(result); 175 | } catch (const bp::error_already_set& e) { 176 | PyGILState_Release(gstate); 177 | throw pyMOOSException( 178 | "ActiveQueue:: caught an exception thrown in python callback"); 179 | } 180 | 181 | PyGILState_Release(gstate); 182 | 183 | return bResult; 184 | 185 | } 186 | 187 | virtual bool AddActiveQueue(const std::string & sQueueName, bp::object func) { 188 | 189 | MOOS::ScopedLock L(queue_api_lock_); 190 | 191 | MeAndQueue* maq = new MeAndQueue; 192 | maq->me_ = this; 193 | maq->queue_name_ = sQueueName; 194 | maq->func_ = func; 195 | 196 | std::cerr << "adding active queue OK\n"; 197 | 198 | active_queue_details_[sQueueName] = maq; 199 | return BASE::AddActiveQueue(sQueueName, active_queue_delegate, maq); 200 | 201 | } 202 | 203 | 204 | private: 205 | 206 | /** this is a structure which is used to dispatch 207 | * active queue callbacks 208 | */ 209 | struct MeAndQueue { 210 | AsyncCommsWrapper* me_; 211 | std::string queue_name_; 212 | bp::object func_; 213 | }; 214 | std::map active_queue_details_; 215 | CMOOSLock queue_api_lock_; 216 | 217 | /** callback functions (stored) */ 218 | bp::object on_connect_object_; 219 | bp::object on_mail_object_; 220 | 221 | /** close connection flag */ 222 | bool closing_; 223 | }; 224 | } 225 | ;//namesapce 226 | 227 | //////////////////////////////////////////////////////////////////////////////////////////// 228 | /** here comes the boost python stuff */ 229 | //////////////////////////////////////////////////////////////////////////////////////////// 230 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_overloads, f, 1, 2) 231 | ; 232 | BOOST_PYTHON_FUNCTION_OVERLOADS(time_overloads, MOOSTime, 0, 1) 233 | ; 234 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(notify_overloads_2_3, Notify, 2,3) 235 | ; 236 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(notify_overloads_3_4, Notify, 3,4) 237 | ; 238 | 239 | BOOST_PYTHON_MODULE(pymoos) 240 | { 241 | bp::docstring_options local_docstring_options(true, true, false); 242 | 243 | PyEval_InitThreads(); 244 | 245 | 246 | /********************************************************************* 247 | MOOSMsg e class 248 | *********************************************************************/ 249 | 250 | bp::class_("moos_msg","Bar class") 251 | .def("time", &CMOOSMsg::GetTime) 252 | .def("trace",&CMOOSMsg::Trace) 253 | 254 | .def("name", &CMOOSMsg::GetKey) 255 | .def("key", &CMOOSMsg::GetKey) 256 | .def("is_name", &CMOOSMsg::IsName) 257 | 258 | .def("source", &CMOOSMsg::GetSource) 259 | 260 | .def("is_double", &CMOOSMsg::IsDouble) 261 | 262 | .def("double", &CMOOSMsg::GetDouble) 263 | .def("double_aux",&CMOOSMsg::GetDoubleAux) 264 | 265 | .def("is_string", &CMOOSMsg::IsString) 266 | .def("string", &CMOOSMsg::GetString) 267 | 268 | .def("is_binary", &CMOOSMsg::IsBinary) 269 | .def("binary_data",&CMOOSMsg::GetString) 270 | .def("binary_data_size",&CMOOSMsg::GetBinaryDataSize) 271 | .def("mark_as_binary",&CMOOSMsg::MarkAsBinary); 272 | 273 | 274 | /********************************************************************* 275 | vector of messages 276 | *********************************************************************/ 277 | 278 | bp::class_("moos_msg_list") 279 | .def(bp::vector_indexing_suite()); 280 | 281 | 282 | /********************************************************************* 283 | communications status class 284 | *********************************************************************/ 285 | 286 | bp::class_("moos_comms_status") 287 | .def("appraise",&MOOS::ClientCommsStatus::Appraise) 288 | .def("print",&MOOS::ClientCommsStatus::Write); 289 | 290 | 291 | /********************************************************************* 292 | vector of communications status classes 293 | *********************************************************************/ 294 | 295 | bp::class_("moos_comms_status_list") 296 | .def(bp::vector_indexing_suite()); 297 | 298 | 299 | /********************************************************************* 300 | comms base class 301 | *********************************************************************/ 302 | 303 | bp::class_("base_comms_object", bp::no_init); 304 | 305 | /********************************************************************* 306 | synchronous comms base class 307 | *********************************************************************/ 308 | bp::class_, boost::noncopyable>("base_sync_comms",bp::no_init) 309 | 310 | .def("register",static_cast (&CMOOSCommClient::Register)) 311 | .def("register",static_cast (&CMOOSCommClient::Register)) 312 | .def("is_registered_for",&CMOOSCommClient::IsRegisteredFor) 313 | 314 | .def("notify",static_cast (&CMOOSCommClient::Notify),notify_overloads_2_3()) 315 | .def("notify",static_cast (&CMOOSCommClient::Notify),notify_overloads_2_3()) 316 | .def("notify",static_cast (&CMOOSCommClient::Notify)) 317 | .def("notify",static_cast (&CMOOSCommClient::Notify)) 318 | .def("notify",static_cast (&CMOOSCommClient::Notify)) 319 | .def("notify",static_cast (&CMOOSCommClient::Notify)) 320 | 321 | .def("get_community_name", &CMOOSCommClient::GetCommunityName) 322 | .def("get_moos_name",&CMOOSCommClient::GetMOOSName) 323 | 324 | .def("close", &CMOOSCommClient::Close) 325 | 326 | .def("get_published", &CMOOSCommClient::GetPublished) 327 | .def("get_registered",&CMOOSCommClient::GetRegistered) 328 | .def("get_description",&CMOOSCommClient::GetDescription) 329 | 330 | .def("is_running", &CMOOSCommClient::IsRunning) 331 | .def("is_asynchronous",&CMOOSCommClient::IsAsynchronous) 332 | .def("is_connected",&CMOOSCommClient::IsConnected) 333 | .def("wait_until_connected",&CMOOSCommClient::WaitUntilConnected) 334 | 335 | .def("get_number_of_unread_messages",&CMOOSCommClient::GetNumberOfUnreadMessages) 336 | 337 | .def("get_number_of_unsent_messages",&CMOOSCommClient::GetNumberOfUnsentMessages) 338 | .def("get_number_bytes_sent",&CMOOSCommClient::GetNumBytesSent) 339 | .def("get_number_bytes_read",&CMOOSCommClient::GetNumBytesReceived) 340 | .def("get_number_messages_sent",&CMOOSCommClient::GetNumMsgsSent) 341 | .def("get_number_message_read",&CMOOSCommClient::GetNumMsgsReceived) 342 | .def("set_comms_control_timewarp_scale_factor",&CMOOSCommClient::SetCommsControlTimeWarpScaleFactor) 343 | .def("get_comms_control_timewarp_scale_factor", &CMOOSCommClient::GetCommsControlTimeWarpScaleFactor) 344 | .def("do_local_time_correction",&CMOOSCommClient::DoLocalTimeCorrection) 345 | 346 | .def("set_verbose_debug", &CMOOSCommClient::SetVerboseDebug) 347 | .def("set_comms_tick",&CMOOSCommClient::SetCommsTick) 348 | .def("set_quiet",&CMOOSCommClient::SetQuiet) 349 | 350 | .def("enable_comms_status_monitoring",&CMOOSCommClient::EnableCommsStatusMonitoring) 351 | .def("get_client_comms_status",&CMOOSCommClient::GetClientCommsStatus) 352 | .def("get_client_comms_statuses",&CMOOSCommClient::GetClientCommsStatuses) 353 | 354 | ; 355 | 356 | 357 | /********************************************************************* 358 | Asynchronous comms base class 359 | *********************************************************************/ 360 | 361 | bp::class_,boost::noncopyable>("base_async_comms", bp::no_init) 362 | .def("run",&MOOS::MOOSAsyncCommClient::Run); 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | /*********************************************************************/ 371 | /** FINALLY HERE IS THE CLASS WE EXPECT TO BE INSTANTIATED IN PYTHON */ 372 | /*********************************************************************/ 373 | //this is the one to use 374 | bp::class_,boost::noncopyable>("comms") 375 | 376 | .def("run", &MOOS::AsyncCommsWrapper::Run) 377 | .def("close", &MOOS::AsyncCommsWrapper::Close) 378 | 379 | .def("fetch",&MOOS::AsyncCommsWrapper::FetchMailAsVector) 380 | .def("set_on_connect_callback",&MOOS::AsyncCommsWrapper::SetOnConnectCallback) 381 | .def("set_on_mail_callback",&MOOS::AsyncCommsWrapper::SetOnMailCallback) 382 | .def("notify_binary",&MOOS::AsyncCommsWrapper::NotifyBinary) 383 | .def("add_active_queue",&MOOS::AsyncCommsWrapper::AddActiveQueue) 384 | .def("remove_message_route_to_active_queue",&MOOS::AsyncCommsWrapper::RemoveMessageRouteToActiveQueue) 385 | .def("remove_active_queue",&MOOS::AsyncCommsWrapper::RemoveActiveQueue) 386 | .def("has_active_queue",&MOOS::AsyncCommsWrapper::HasActiveQueue) 387 | .def("print_message_to_active_queue_routing",&MOOS::AsyncCommsWrapper::PrintMessageToActiveQueueRouting) 388 | .def("add_message_route_to_active_queue",static_cast (&MOOS::AsyncCommsWrapper::AddMessageRouteToActiveQueue)) 389 | 390 | ; 391 | 392 | 393 | /********************************************************************* 394 | some MOOS Utilities 395 | *********************************************************************/ 396 | 397 | /** here are some global help functions */ 398 | bp::def("time", &MOOSTime, time_overloads()); 399 | bp::def("local_time", &MOOSLocalTime, time_overloads()); 400 | bp::def("is_little_end_in", &IsLittleEndian); 401 | bp::def("set_moos_timewarp", &SetMOOSTimeWarp); 402 | bp::def("get_moos_timewarp", &GetMOOSTimeWarp); 403 | 404 | bp::register_exception_translator(&MOOSExceptionTranslator); 405 | 406 | } --------------------------------------------------------------------------------