├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── LICENSE
├── README.md
├── installDeps.sh
└── src
├── CMakeLists.txt
├── common
├── CMakeLists.txt
├── format
│ ├── file_format.h
│ ├── file_format_legacy.cpp
│ ├── file_format_legacy.h
│ ├── file_format_timestamp_type_size_raw_message.cpp
│ ├── file_format_timestamp_type_size_raw_message.h
│ └── message_type.h
├── logfile.cpp
├── logfile.h
├── network.cpp
├── network.h
├── recorder.cpp
├── recorder.h
├── timer.cpp
└── timer.h
├── examples
├── CMakeLists.txt
└── examplereader.cpp
├── logconvert
├── CMakeLists.txt
└── logconvert.cpp
├── logplayer
├── CMakeLists.txt
├── logplayer.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── player.cpp
└── player.h
├── logrecorder
├── CMakeLists.txt
└── logrecorder.cpp
├── protobuf
├── CMakeLists.txt
├── messages_robocup_ssl_detection.proto
├── messages_robocup_ssl_geometry.proto
├── messages_robocup_ssl_geometry_legacy.proto
├── messages_robocup_ssl_wrapper.proto
├── messages_robocup_ssl_wrapper_legacy.proto
├── ssl_referee.cpp
├── ssl_referee.h
└── ssl_referee.proto
└── qt
├── CMakeLists.txt
├── multicastsocket.cpp
├── multicastsocket.h
├── qtiocompressor.cpp
└── qtiocompressor.h
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | language: cpp
3 | os: linux
4 | dist: trusty
5 | compiler:
6 | - gcc
7 |
8 | before_install:
9 | - sudo apt-get update -qq
10 | - sudo ./installDeps.sh
11 | - 'if [ "$CMAKE_ARGS" = "-DUSE_QT5=True" ]; then sudo apt-get install -qq qtbase5-dev; fi'
12 |
13 | env:
14 | - CMAKE_ARGS=""
15 | - CMAKE_ARGS="-DUSE_QT5=True"
16 |
17 | script:
18 | - mkdir -p build
19 | - cd build
20 | - cmake $CMAKE_ARGS ..
21 | - make
22 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(ssl-logtools)
2 |
3 | set(USE_QT5 FALSE CACHE BOOL "Use Qt5 instead of Qt4")
4 | if(USE_QT5)
5 | cmake_minimum_required(VERSION 2.8.9)
6 | if(POLICY CMP0020)
7 | cmake_policy(SET CMP0020 NEW) # remove if CMake >= 2.8.11 required
8 | endif()
9 | if(POLICY CMP0043) # compatibility with CMake 3.0.1
10 | cmake_policy(SET CMP0043 OLD)
11 | endif()
12 | if(POLICY CMP0071) # compatibility with CMake 3.10.0
13 | cmake_policy(SET CMP0071 OLD)
14 | endif()
15 | else()
16 | cmake_minimum_required(VERSION 2.8.2)
17 | endif()
18 |
19 | find_package(Threads REQUIRED)
20 | find_package(Protobuf REQUIRED)
21 |
22 | if(USE_QT5)
23 | set(CMAKE_INCLUDE_CURRENT_DIR ON)
24 | set(CMAKE_AUTOMOC ON)
25 | find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED)
26 | # replaced by automoc
27 | macro(qt4_wrap_cpp VARNAME)
28 | set(${VARNAME} "")
29 | endmacro()
30 | # wrap functions
31 | macro(qt4_wrap_ui)
32 | qt5_wrap_ui(${ARGN})
33 | endmacro()
34 | macro(qt4_add_resources)
35 | qt5_add_resources(${ARGN})
36 | endmacro()
37 | else()
38 | find_package(Qt4 4.6.0 COMPONENTS QtCore QtGui QtNetwork REQUIRED)
39 | endif()
40 |
41 | find_package(Boost 1.42.0 COMPONENTS program_options REQUIRED)
42 | find_package(ZLIB REQUIRED)
43 |
44 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
45 |
46 | add_subdirectory(src)
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc. {http://fsf.org/}
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see {http://www.gnu.org/licenses/}.
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | ssl-logtools Copyright (C) 2013 Michael Bleier
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | {http://www.gnu.org/licenses/}.
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | {http://www.gnu.org/philosophy/why-not-lgpl.html}.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ssl-logtools
2 | ============
3 |
4 | Log recording tools for RoboCup Small Size League games
5 |
6 | Copyright (c) 2013 Robotics Erlangen e.V.
7 | http://www.robotics-erlangen.de/
8 | info@robotics-erlangen.de
9 |
10 | This software was written by team members of ER-Force at
11 | Robotics Erlangen e.V., Germany.
12 |
13 | The ssl-logtools can record and playback the messages of SSL-Vision
14 | (https://github.com/RoboCup-SSL/ssl-vision) and the SSL-RefBox
15 | (https://github.com/RoboCup-SSL/ssl-refbox).
16 |
17 | Compiling:
18 | ------------
19 |
20 | All programs should compile on GNU/Linux, Windows and Mac OS X.
21 |
22 | In order to build the ssl-logtools you will need:
23 | * cmake-2.8.2
24 | * g++-4.1
25 | * qt-gui-4.6.0
26 | * boost-program-options-1.42.0
27 | * zlib-1.2.7
28 | * protobuf-2.0.0
29 |
30 | The recommended way of building a project with CMake is by doing an
31 | out-of-source build. This can be done like this:
32 |
33 | > mkdir build
34 | > cd build
35 | > cmake ..
36 | > make
37 |
38 | Binaries will be created in the subdirectory "bin" of the "build" folder.
39 |
40 | Example Usage:
41 | ------------
42 |
43 | Record log:
44 | > logrecorder -o /tmp/test.log
45 |
46 | Record log and write it to gzip compressed file:
47 | > logrecorder --compress -o /tmp/test.log.gz
48 |
49 | Automatically create a new log for each new game based on the referee commands:
50 | > logdaemon -o /tmp/logs/
51 |
52 | Print help message with all available command-line options:
53 | > logrecorder --help
54 |
55 | Commands can be aborted using Control-C.
56 |
57 | Both uncompressed (*.log) and gzip compressed (*.log.gz) log files can be played back
58 | using "logplayer".
59 |
60 | Reading Log Files Using Your Own Software:
61 | ------------
62 |
63 | If you want to read the log files using your own software, look at the class
64 | "LogFile" in "src/common/logfile.h".
65 |
66 | Alternatively a plain C++ example for reading log files with minimal dependecies
67 | is provided in "src/examples".
68 |
69 | Default Binary Format of the Log Files:
70 | ------------
71 |
72 | The log files are created by default in format version 1.
73 |
74 | Each log file starts with the following header:
75 |
76 | > 1: String - File type ("SSL_LOG_FILE")
77 | > 2: Int32 - Log file format version
78 |
79 | Format version 1 encodes the protobuf messages in the following format:
80 |
81 | > 1: Int64 - Receiver timestamp in ns
82 | > 2: Int32 - Message type
83 | > 3: Int32 - Size of binary protobuf message
84 | > 4: String - Binary protobuf message
85 |
86 | The message types are:
87 |
88 | > MESSAGE_BLANK = 0 (ignore message)
89 | > MESSAGE_UNKNOWN = 1 (try to guess message type by parsing the data)
90 | > MESSAGE_SSL_VISION_2010 = 2
91 | > MESSAGE_SSL_REFBOX_2013 = 3
92 | > MESSAGE_SSL_VISION_2014 = 4
93 |
94 | To convert any supported log to file format version 1 run:
95 | > logconvert -f 1 -i /tmp/in.log -o /tmp/out.log
96 |
97 | License:
98 | ------------
99 |
100 | The software is licensed to you under the GNU General Public License
101 | Version 3. The license can be found in the file "LICENSE".
102 |
103 | Source:
104 | ------------
105 |
106 | The latest version of this software can be obtained at
107 | https://github.com/RoboCup-SSL/ssl-logtools.
108 |
--------------------------------------------------------------------------------
/installDeps.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # stop on errors
4 | set -e
5 |
6 | if [ "`id -nu`" != "root" ]; then
7 | echo "Must be called as root or with sudo"
8 | exit 1
9 | fi
10 |
11 | if which dnf 2>/dev/null >/dev/null; then
12 | FLAGS="-y"
13 | dnf $FLAGS install cmake gcc-c++ git protobuf-compiler zlib-devel boost-program-options
14 | fi
15 |
16 | if which apt-get 2>/dev/null >/dev/null; then
17 | FLAGS="-qq -y"
18 | apt-get $FLAGS install cmake g++ git libprotobuf-dev protobuf-compiler zlib1g-dev libboost-program-options-dev
19 | fi
20 |
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
2 | include_directories(${CMAKE_BINARY_DIR}/src)
3 |
4 | add_subdirectory(protobuf)
5 | add_subdirectory(qt)
6 | add_subdirectory(common)
7 |
8 | add_subdirectory(logconvert)
9 | #add_subdirectory(logdaemon)
10 | add_subdirectory(logplayer)
11 | add_subdirectory(logrecorder)
12 |
13 | add_subdirectory(examples)
14 |
--------------------------------------------------------------------------------
/src/common/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${PROTOBUF_INCLUDE_DIR})
2 |
3 | set(SOURCES
4 | recorder.cpp
5 |
6 | network.cpp
7 | timer.cpp
8 | timer.h
9 |
10 | logfile.cpp
11 | logfile.h
12 |
13 | format/message_type.h
14 | format/file_format.h
15 | format/file_format_legacy.cpp
16 | format/file_format_legacy.h
17 | format/file_format_timestamp_type_size_raw_message.cpp
18 | format/file_format_timestamp_type_size_raw_message.h
19 | )
20 |
21 | set(MOC_SOURCES
22 | recorder.h
23 | network.h
24 | )
25 |
26 | qt4_wrap_cpp(MOC_SOURCES ${MOC_SOURCES})
27 |
28 | add_library(common ${SOURCES} ${MOC_SOURCES})
29 | target_link_libraries(common protobuf qt)
30 | if(USE_QT5)
31 | target_link_libraries(common Qt5::Core Qt5::Network)
32 | else()
33 | target_link_libraries(common ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
34 | include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR})
35 | endif()
36 |
37 | if(WIN32)
38 | target_link_libraries(common wsock32)
39 | endif()
40 |
--------------------------------------------------------------------------------
/src/common/format/file_format.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef FILE_FORMAT_H
13 | #define FILE_FORMAT_H
14 |
15 | #include "message_type.h"
16 | #include
17 |
18 | class FileFormat
19 | {
20 | public:
21 | FileFormat(int version) : m_version(version) {}
22 |
23 | public:
24 | int version() { return m_version; }
25 |
26 | public:
27 | virtual void writeHeaderToStream(QDataStream& stream) = 0;
28 | virtual bool readHeaderFromStream(QDataStream& stream) = 0;
29 |
30 | public:
31 | virtual void writeMessageToStream(QDataStream& stream, const QByteArray& data, qint64 time, MessageType type) = 0;
32 | virtual bool readMessageFromStream(QDataStream& stream, QByteArray& data, qint64& time, MessageType& type) = 0;
33 |
34 | private:
35 | int m_version;
36 | };
37 |
38 | #endif // FILE_FORMAT_H
39 |
--------------------------------------------------------------------------------
/src/common/format/file_format_legacy.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "file_format_legacy.h"
13 |
14 | FileFormatLegacy::FileFormatLegacy() :
15 | FileFormat(0)
16 | {
17 |
18 | }
19 |
20 | FileFormatLegacy::~FileFormatLegacy()
21 | {
22 |
23 | }
24 |
25 | void FileFormatLegacy::writeHeaderToStream(QDataStream& stream)
26 | {
27 | stream << QString("SSL_LOG_FILE");
28 | stream << version();
29 | }
30 |
31 | bool FileFormatLegacy::readHeaderFromStream(QDataStream& stream)
32 | {
33 | QString name;
34 | stream >> name;
35 |
36 | int format;
37 | stream >> format;
38 |
39 | if (name == "SSL_LOG_FILE" && format == version()) {
40 | return true;
41 | }
42 |
43 | return false;
44 | }
45 |
46 | void FileFormatLegacy::writeMessageToStream(QDataStream& stream, const QByteArray& data, qint64 time, MessageType type)
47 | {
48 | stream << time;
49 | stream << qCompress(data);
50 | }
51 |
52 | bool FileFormatLegacy::readMessageFromStream(QDataStream& stream, QByteArray& data, qint64& time, MessageType& type)
53 | {
54 | type = MESSAGE_UNKNOWN;
55 |
56 | stream >> time;
57 | QByteArray compressedPacket;
58 | stream >> compressedPacket;
59 | data = qUncompress(compressedPacket);
60 |
61 | return true;
62 | }
63 |
--------------------------------------------------------------------------------
/src/common/format/file_format_legacy.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef FILE_FORMAT_LEGACY_H
13 | #define FILE_FORMAT_LEGACY_H
14 |
15 | #include "file_format.h"
16 |
17 | class FileFormatLegacy : public FileFormat
18 | {
19 | public:
20 | FileFormatLegacy();
21 | ~FileFormatLegacy();
22 |
23 | public:
24 | void writeHeaderToStream(QDataStream& stream);
25 | bool readHeaderFromStream(QDataStream& stream);
26 |
27 | public:
28 | void writeMessageToStream(QDataStream& stream, const QByteArray& data, qint64 time, MessageType type);
29 | bool readMessageFromStream(QDataStream& stream, QByteArray& data, qint64& time, MessageType& type);
30 | };
31 |
32 | #endif // FILE_FORMAT_LEGACY_H
33 |
--------------------------------------------------------------------------------
/src/common/format/file_format_timestamp_type_size_raw_message.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "file_format_timestamp_type_size_raw_message.h"
13 |
14 | FileFormatTimestampTypeSizeRawMessage::FileFormatTimestampTypeSizeRawMessage() :
15 | FileFormat(1)
16 | {
17 |
18 | }
19 |
20 | FileFormatTimestampTypeSizeRawMessage::~FileFormatTimestampTypeSizeRawMessage()
21 | {
22 |
23 | }
24 |
25 | void FileFormatTimestampTypeSizeRawMessage::writeHeaderToStream(QDataStream& stream)
26 | {
27 | stream.writeRawData("SSL_LOG_FILE", 12);
28 | stream << (qint32) version();
29 | }
30 |
31 | bool FileFormatTimestampTypeSizeRawMessage::readHeaderFromStream(QDataStream& stream)
32 | {
33 | char name[13];
34 | name[12] = '\0';
35 | stream.readRawData(name, sizeof(name) - 1);
36 |
37 | qint32 version;
38 | stream >> version;
39 |
40 | if (QString(name) == "SSL_LOG_FILE" && version == this->version()) {
41 | return true;
42 | }
43 |
44 | return false;
45 | }
46 |
47 | void FileFormatTimestampTypeSizeRawMessage::writeMessageToStream(QDataStream& stream, const QByteArray& data, qint64 time, MessageType type)
48 | {
49 | stream << time;
50 | stream << (qint32) type;
51 | stream << data;
52 | }
53 |
54 | bool FileFormatTimestampTypeSizeRawMessage::readMessageFromStream(QDataStream& stream, QByteArray& data, qint64& time, MessageType& type)
55 | {
56 | stream >> time;
57 | qint32 typeValue;
58 | stream >> typeValue;
59 | type = (MessageType) typeValue;
60 | stream >> data;
61 |
62 | return true;
63 | }
64 |
--------------------------------------------------------------------------------
/src/common/format/file_format_timestamp_type_size_raw_message.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef FILE_FORMAT_TIMESTAMP_TYPE_SIZE_RAW_MESSAGE_H
13 | #define FILE_FORMAT_TIMESTAMP_TYPE_SIZE_RAW_MESSAGE_H
14 |
15 | #include "file_format.h"
16 |
17 | class FileFormatTimestampTypeSizeRawMessage : public FileFormat
18 | {
19 | public:
20 | FileFormatTimestampTypeSizeRawMessage();
21 | ~FileFormatTimestampTypeSizeRawMessage();
22 |
23 | public:
24 | void writeHeaderToStream(QDataStream& stream);
25 | bool readHeaderFromStream(QDataStream& stream);
26 |
27 | public:
28 | void writeMessageToStream(QDataStream& stream, const QByteArray& data, qint64 time, MessageType type);
29 | bool readMessageFromStream(QDataStream& stream, QByteArray& data, qint64& time, MessageType& type);
30 | };
31 |
32 | #endif // FILE_FORMAT_TIMESTAMP_TYPE_SIZE_RAW_MESSAGE_H
33 |
--------------------------------------------------------------------------------
/src/common/format/message_type.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef MESSAGE_TYPE_H
13 | #define MESSAGE_TYPE_H
14 |
15 | enum MessageType
16 | {
17 | MESSAGE_BLANK = 0,
18 | MESSAGE_UNKNOWN = 1,
19 | MESSAGE_SSL_VISION_2010 = 2,
20 | MESSAGE_SSL_REFBOX_2013 = 3,
21 | MESSAGE_SSL_VISION_2014 = 4
22 | };
23 |
24 | #endif // MESSAGE_TYPE_H
25 |
--------------------------------------------------------------------------------
/src/common/logfile.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "logfile.h"
13 | #include "qt/qtiocompressor.h"
14 | #include "format/file_format_legacy.h"
15 | #include "format/file_format_timestamp_type_size_raw_message.h"
16 | #include
17 | #include
18 |
19 | const int LogFile::DEFAULT_FILE_FORMAT_VERSION;
20 |
21 | LogFile::LogFile(const QString& filename, bool compressed, int formatVersion) :
22 | m_filename(filename),
23 | m_compressed(compressed),
24 | m_formatVersion(formatVersion),
25 | m_io(NULL),
26 | m_file(NULL),
27 | m_compressor(NULL)
28 | {
29 | addFormat(new FileFormatLegacy());
30 | addFormat(new FileFormatTimestampTypeSizeRawMessage());
31 | }
32 |
33 | LogFile::~LogFile()
34 | {
35 | close();
36 | qDeleteAll(m_formatMap);
37 | }
38 |
39 | bool LogFile::addFormat(FileFormat* format)
40 | {
41 | if (m_formatMap.contains(format->version())) {
42 | std::cout << "Error adding log format!" << std::endl;
43 | std::cout << "Format version " << format->version() << " has been used twice." << std::endl;
44 |
45 | return false;
46 | }
47 |
48 | m_formatMap[format->version()] = format;
49 |
50 | return true;
51 | }
52 |
53 | bool LogFile::openRead()
54 | {
55 | foreach (FileFormat* format, m_formatMap) {
56 | close();
57 |
58 | Q_ASSERT(m_file == NULL);
59 | m_file = new QFile(m_filename);
60 |
61 | if (!m_file->open(QIODevice::ReadOnly)) {
62 | std::cout << "Error opening log file \"" << m_filename.toStdString() << "\"!" << std::endl;
63 | close();
64 |
65 | return false;
66 | }
67 |
68 | if (m_compressed) {
69 | Q_ASSERT(m_compressor == NULL);
70 | m_compressor = new QtIOCompressor(m_file);
71 | m_compressor->setStreamFormat(QtIOCompressor::GzipFormat);
72 | m_compressor->open(QIODevice::ReadOnly);
73 |
74 | m_io = m_compressor;
75 | } else {
76 | m_io = m_file;
77 | }
78 |
79 | QDataStream stream(m_io);
80 |
81 | if (format->readHeaderFromStream(stream)) {
82 | std::cout << "Detected log file format version " << format->version() << "." << std::endl;
83 | m_formatVersion = format->version();
84 |
85 | return true;
86 | }
87 | }
88 |
89 | std::cout << "Error log file corrupted or format is not supported!" << std::endl;
90 | close();
91 |
92 | return false;
93 | }
94 |
95 | bool LogFile::openWrite()
96 | {
97 | close();
98 |
99 | FileFormat* format = m_formatMap.value(m_formatVersion, NULL);
100 |
101 | if (format == NULL) {
102 | std::cout << "Error log file format is not supported!" << std::endl;
103 |
104 | return false;
105 | }
106 |
107 | Q_ASSERT(m_file == NULL);
108 | m_file = new QFile(m_filename);
109 |
110 | if (!m_file->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
111 | std::cout << "Error opening log file \"" << m_filename.toStdString() << "\"!" << std::endl;
112 |
113 | return false;
114 | }
115 |
116 | if (m_compressed) {
117 | Q_ASSERT(m_compressor == NULL);
118 | m_compressor = new QtIOCompressor(m_file);
119 | m_compressor->setStreamFormat(QtIOCompressor::GzipFormat);
120 | m_compressor->open(QIODevice::WriteOnly);
121 |
122 | m_io = m_compressor;
123 | } else {
124 | m_io = m_file;
125 | }
126 |
127 | QDataStream stream(m_io);
128 | format->writeHeaderToStream(stream);
129 |
130 | return true;
131 | }
132 |
133 | void LogFile::close()
134 | {
135 | m_io = NULL;
136 |
137 | delete m_compressor;
138 | m_compressor = NULL;
139 |
140 | delete m_file;
141 | m_file = NULL;
142 | }
143 |
144 | void LogFile::saveMessage(const QByteArray& data, qint64 time, MessageType type)
145 | {
146 | if (m_io == NULL || !m_io->isWritable()) {
147 | return;
148 | }
149 |
150 | FileFormat* format = m_formatMap.value(m_formatVersion, NULL);
151 |
152 | if (format == NULL) {
153 | std::cout << "Error log file format is not supported!" << std::endl;
154 |
155 | return;
156 | }
157 |
158 | QDataStream stream(m_io);
159 | stream.setVersion(QDataStream::Qt_4_6);
160 |
161 | format->writeMessageToStream(stream, data, time, type);
162 | }
163 |
164 | bool LogFile::readMessage(QByteArray& data, qint64& time, MessageType& type)
165 | {
166 | if (m_io == NULL || !m_io->isReadable()) {
167 | return false;
168 | }
169 |
170 | FileFormat* format = m_formatMap.value(m_formatVersion, NULL);
171 |
172 | if (format == NULL) {
173 | std::cout << "Error log file format is not supported!" << std::endl;
174 |
175 | return false;
176 | }
177 |
178 | QDataStream stream(m_io);
179 | stream.setVersion(QDataStream::Qt_4_6);
180 |
181 | if (stream.atEnd()) {
182 | return false;
183 | }
184 |
185 | return format->readMessageFromStream(stream, data, time, type);
186 | }
187 |
--------------------------------------------------------------------------------
/src/common/logfile.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef LOGFILE_H
13 | #define LOGFILE_H
14 |
15 | #include "format/file_format.h"
16 | #include
17 | #include
18 |
19 | class QtIOCompressor;
20 |
21 | class LogFile
22 | {
23 | public:
24 | LogFile(const QString& filename, bool compressed = false, int formatVersion = DEFAULT_FILE_FORMAT_VERSION);
25 | ~LogFile();
26 |
27 | public:
28 | bool openRead();
29 | bool openWrite();
30 | void close();
31 |
32 | public:
33 | void saveMessage(const QByteArray& data, qint64 time, MessageType type);
34 | bool readMessage(QByteArray& data, qint64& time, MessageType& type);
35 |
36 | private:
37 | bool addFormat(FileFormat* format);
38 |
39 | private:
40 | QString m_filename;
41 | bool m_compressed;
42 | int m_formatVersion;
43 | QMap m_formatMap;
44 | QIODevice* m_io;
45 | QFile* m_file;
46 | QtIOCompressor* m_compressor;
47 |
48 | public:
49 | static const int DEFAULT_FILE_FORMAT_VERSION = 1;
50 | };
51 |
52 | #endif // LOG_FILE_H
53 |
--------------------------------------------------------------------------------
/src/common/network.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "qt/multicastsocket.h"
13 | #include "network.h"
14 | #include "timer.h"
15 | #include
16 |
17 | /*!
18 | * \class Network
19 | * \brief UDP multicast receiver and transmitter
20 | *
21 | * This class is designed to timestamp an incoming packet as early as possible
22 | * by being moved to a dedicated worker thread.
23 | */
24 |
25 | /*!
26 | * \fn void Network::gotPacket(QByteArray data, qint64 time)
27 | * \brief This signal is emitted whenever a new packet has been received
28 | * \param data The received packet
29 | * \param time Timestamp at which the packet has been received
30 | */
31 |
32 | /*!
33 | * \brief Constructor
34 | * \param groupAddress Address of the multicast group to listen on
35 | * \param port Port to listen on
36 | */
37 | Network::Network(const QHostAddress &groupAddress, quint16 localPort, quint16 targetPort) :
38 | m_groupAddress(groupAddress),
39 | m_localPort(localPort),
40 | m_targetPort(targetPort),
41 | m_socket(NULL)
42 | {
43 | }
44 |
45 | /*!
46 | * \brief Destructor
47 | */
48 | Network::~Network()
49 | {
50 | disconnect();
51 | }
52 |
53 | /*!
54 | * \brief Start listening on the socket
55 | */
56 | void Network::connect()
57 | {
58 | disconnect();
59 |
60 | m_socket = new MulticastSocket(this);
61 | QObject::connect(m_socket, SIGNAL(readyRead()), SLOT(readData()));
62 | #if QT_VERSION >= 0x050000
63 | m_socket->bind(QHostAddress::AnyIPv4, m_localPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
64 | #else
65 | m_socket->bind(QHostAddress::Any, m_localPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
66 | #endif
67 | m_socket->joinMulticastGroup(m_groupAddress);
68 |
69 | if (m_socket->state() != QAbstractSocket::BoundState) {
70 | foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
71 | m_socket->joinMulticastGroup(m_groupAddress, iface);
72 | }
73 | }
74 |
75 | m_socket->setSocketOption(QAbstractSocket::MulticastLoopbackOption, QVariant(1));
76 | }
77 |
78 | /*!
79 | * \brief Stop listening on the socket
80 | */
81 | void Network::disconnect()
82 | {
83 | delete m_socket;
84 | m_socket = NULL;
85 | }
86 |
87 | /*!
88 | * \brief Read a packet from the socket and emit \ref gotPacket
89 | */
90 | void Network::readData()
91 | {
92 | QByteArray data;
93 | data.resize(m_socket->pendingDatagramSize());
94 | m_socket->readDatagram(data.data(), data.size());
95 | emit gotPacket(data, Timer::systemTime());
96 | }
97 |
98 | /*!
99 | * \brief Write a packet to the socket
100 | */
101 | void Network::writeData(const QByteArray& data)
102 | {
103 | m_socket->writeDatagram(data, m_groupAddress, m_targetPort);
104 | }
105 |
--------------------------------------------------------------------------------
/src/common/network.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef NETWORK_H
13 | #define NETWORK_H
14 |
15 | #include
16 |
17 | class Network : public QObject
18 | {
19 | Q_OBJECT
20 |
21 | public:
22 | Network(const QHostAddress &groupAddress, quint16 localPort, quint16 targetPort);
23 | ~Network();
24 |
25 | signals:
26 | void gotPacket(QByteArray data, qint64 time);
27 |
28 | public:
29 | void writeData(const QByteArray& data);
30 |
31 | public slots:
32 | void connect();
33 | void disconnect();
34 |
35 | private slots:
36 | void readData();
37 |
38 | private:
39 | QHostAddress m_groupAddress;
40 | quint16 m_localPort;
41 | quint16 m_targetPort;
42 | QUdpSocket *m_socket;
43 | };
44 |
45 | #endif // NETWORK_H
46 |
--------------------------------------------------------------------------------
/src/common/recorder.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "recorder.h"
13 | #include "protobuf/ssl_referee.pb.h"
14 | #include "protobuf/messages_robocup_ssl_wrapper.pb.h"
15 | #include "protobuf/messages_robocup_ssl_wrapper_legacy.pb.h"
16 | #include
17 | #include
18 |
19 | Recorder::Recorder() :
20 | m_logFile(NULL),
21 | m_referee(NULL),
22 | m_vision(NULL),
23 | m_legacyVision(NULL),
24 | m_networkThread(NULL)
25 | {
26 | m_networkThread = new QThread(this);
27 | }
28 |
29 | Recorder::~Recorder()
30 | {
31 | stop();
32 |
33 | std::cout << "\r" << "Recorded " << m_visionFrames << " vision packets, " << m_legacyVisionFrames << " legacy vision packets and " << m_refereeFrames << " referee packets." << std::endl;
34 | std::cout << "Finished recording." << std::endl;
35 | }
36 |
37 | bool Recorder::start(const QString& filename, bool compress, int formatVersion)
38 | {
39 | m_visionFrames = 0;
40 | m_legacyVisionFrames = 0;
41 | m_refereeFrames = 0;
42 |
43 | // open writeable log file
44 | Q_ASSERT(m_logFile == NULL);
45 | m_logFile = new LogFile(filename, compress, formatVersion);
46 | if (!m_logFile->openWrite()) {
47 | return false;
48 | }
49 |
50 | // create referee socket
51 | Q_ASSERT(m_referee == NULL);
52 | m_referee = new Network(QHostAddress("224.5.23.1"), 10003, 0);
53 | m_referee->moveToThread(m_networkThread);
54 | QObject::connect(m_networkThread, SIGNAL(started()), m_referee, SLOT(connect()));
55 | QObject::connect(m_networkThread, SIGNAL(finished()), m_referee, SLOT(disconnect()));
56 | QObject::connect(m_referee, SIGNAL(gotPacket(QByteArray, qint64)), SLOT(recordRefereePacket(QByteArray, qint64)));
57 |
58 | // create vision socket
59 | Q_ASSERT(m_vision == NULL);
60 | m_vision = new Network(QHostAddress("224.5.23.2"), 10006, 0);
61 | m_vision->moveToThread(m_networkThread);
62 | QObject::connect(m_networkThread, SIGNAL(started()), m_vision, SLOT(connect()));
63 | QObject::connect(m_networkThread, SIGNAL(finished()), m_vision, SLOT(disconnect()));
64 | QObject::connect(m_vision, SIGNAL(gotPacket(QByteArray, qint64)), SLOT(recordVisionPacket(QByteArray, qint64)));
65 |
66 | // create legacy vision socket
67 | Q_ASSERT(m_legacyVision == NULL);
68 | m_legacyVision = new Network(QHostAddress("224.5.23.2"), 10005, 0);
69 | m_legacyVision->moveToThread(m_networkThread);
70 | QObject::connect(m_networkThread, SIGNAL(started()), m_legacyVision, SLOT(connect()));
71 | QObject::connect(m_networkThread, SIGNAL(finished()), m_legacyVision, SLOT(disconnect()));
72 | QObject::connect(m_legacyVision, SIGNAL(gotPacket(QByteArray, qint64)), SLOT(recordLegacyVisionPacket(QByteArray, qint64)));
73 |
74 | m_networkThread->start();
75 |
76 | std::cout << "Started recording to \"" << filename.toStdString() << "\" using file format version " << formatVersion << "." << std::endl;
77 |
78 | return true;
79 | }
80 |
81 | void Recorder::stop()
82 | {
83 | m_networkThread->quit();
84 | m_networkThread->wait();
85 |
86 | delete m_referee;
87 | m_referee = NULL;
88 |
89 | delete m_vision;
90 | m_vision = NULL;
91 |
92 | delete m_legacyVision;
93 | m_legacyVision = NULL;
94 |
95 | delete m_logFile;
96 | m_logFile = NULL;
97 | }
98 |
99 | void Recorder::recordRefereePacket(const QByteArray& data, qint64 time)
100 | {
101 | // check if packet is valid
102 | SSL_Referee packet;
103 | if (!packet.ParseFromArray(data.data(), data.size())) {
104 | std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << (double) time / 1e9 << ": Error failed to parse referee packet!" << std::endl << std::flush;
105 | return;
106 | }
107 |
108 | // save packet to log file
109 | if (m_logFile == NULL) {
110 | return;
111 | }
112 | m_logFile->saveMessage(data, time, MESSAGE_SSL_REFBOX_2013);
113 |
114 | m_refereeFrames++;
115 | std::cout << "\r" << "Recorded " << m_visionFrames << " vision packets, " << m_legacyVisionFrames << " legacy vision packets and " << m_refereeFrames << " referee packets." << std::flush;
116 | }
117 |
118 | void Recorder::recordVisionPacket(const QByteArray& data, qint64 time)
119 | {
120 | // check if packet is valid
121 | SSL_WrapperPacket packet;
122 | if (!packet.ParseFromArray(data.data(), data.size())) {
123 | std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << (double) time / 1e9 << ": Error failed to parse legacy vision packet!" << std::endl << std::flush;
124 | return;
125 | }
126 |
127 | // save packet to logfile
128 | if (m_logFile == NULL) {
129 | return;
130 | }
131 | m_logFile->saveMessage(data, time, MESSAGE_SSL_VISION_2014);
132 | m_visionFrames++;
133 | std::cout << "\r" << "Recorded " << m_visionFrames << " vision packets, " << m_legacyVisionFrames << " legacy vision packets and " << m_refereeFrames << " referee packets." << std::flush;
134 | }
135 |
136 | void Recorder::recordLegacyVisionPacket(const QByteArray& data, qint64 time)
137 | {
138 | // check if packet is valid
139 | RoboCup2014Legacy::Wrapper::SSL_WrapperPacket packet;
140 | if (!packet.ParseFromArray(data.data(), data.size())) {
141 | std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << (double) time / 1e9 << ": Error failed to parse vision packet!" << std::endl << std::flush;
142 | return;
143 | }
144 |
145 | // save packet to logfile
146 | if (m_logFile == NULL) {
147 | return;
148 | }
149 | m_logFile->saveMessage(data, time, MESSAGE_SSL_VISION_2010);
150 | m_legacyVisionFrames++;
151 | std::cout << "\r" << "Recorded " << m_visionFrames << " vision packets, " << m_legacyVisionFrames << " legacy vision packets and " << m_refereeFrames << " referee packets." << std::flush;
152 | }
153 |
--------------------------------------------------------------------------------
/src/common/recorder.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef RECORDER_H
13 | #define RECORDER_H
14 |
15 | #include "network.h"
16 | #include "logfile.h"
17 | #include
18 |
19 | class Recorder : public QObject
20 | {
21 | Q_OBJECT
22 |
23 | public:
24 | Recorder();
25 | ~Recorder();
26 |
27 | public:
28 | bool start(const QString& filename, bool compress = false, int formatVersion = LogFile::DEFAULT_FILE_FORMAT_VERSION);
29 | void stop();
30 |
31 | private slots:
32 | void recordRefereePacket(const QByteArray& data, qint64 time);
33 | void recordVisionPacket(const QByteArray& data, qint64 time);
34 | void recordLegacyVisionPacket(const QByteArray& data, qint64 time);
35 |
36 | private:
37 | LogFile* m_logFile;
38 | Network* m_referee;
39 | Network* m_vision;
40 | Network* m_legacyVision;
41 | QThread* m_networkThread;
42 | long m_visionFrames;
43 | long m_legacyVisionFrames;
44 | long m_refereeFrames;
45 | };
46 |
47 | #endif // RECORDER_H
48 |
--------------------------------------------------------------------------------
/src/common/timer.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "timer.h"
13 |
14 | #if _POSIX_TIMERS > 0
15 | #define WITH_POSIX_TIMERS
16 | #endif
17 |
18 | #ifdef WITH_POSIX_TIMERS
19 | #include
20 | #else
21 | #include
22 | #ifdef Q_OS_WIN
23 | #include
24 | #endif // Q_OS_WIN
25 | #endif
26 |
27 | /*!
28 | * \class Timer
29 | * \brief High precision timer
30 | */
31 |
32 | /*!
33 | * \brief Creates a new timer object
34 | */
35 | Timer::Timer() :
36 | m_scaling(1.0)
37 | {
38 | m_start = systemTime();
39 | }
40 |
41 | /*!
42 | * \brief Sets time scaling. Time is guaranteed to be continous
43 | * \param scaling New scaling factor
44 | */
45 | void Timer::setScaling(double scaling)
46 | {
47 | Q_ASSERT(scaling >= 0);
48 | // scaling is relative to start time, update start to prevent a jump
49 | m_start = currentTime();
50 | m_scaling = scaling;
51 | }
52 |
53 | /*!
54 | * \brief Reset timer to current time and reset Scaling
55 | */
56 | void Timer::reset()
57 | {
58 | m_scaling = 1.0;
59 | m_start = systemTime();
60 | }
61 |
62 | /*!
63 | * \brief Query internal time
64 | * \return The internal time in nanoseconds
65 | */
66 | qint64 Timer::currentTime() const
67 | {
68 | const qint64 sys = systemTime();
69 | return m_start + (sys - m_start) * m_scaling;
70 | }
71 |
72 | /*!
73 | * \brief Query system time
74 | * \return The current system time in nanoseconds
75 | */
76 | qint64 Timer::systemTime()
77 | {
78 | #ifdef WITH_POSIX_TIMERS
79 | timespec ts;
80 | ts.tv_sec = 0;
81 | ts.tv_nsec = 0;
82 | if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
83 | return 0;
84 |
85 | return qint64(ts.tv_sec) * 1000000000LL + qint64(ts.tv_nsec);
86 | #else // WITH_POSIX_TIMERS
87 | #ifdef Q_OS_WIN
88 | static bool isInitialized = false;
89 |
90 | static quint64 timerFrequency;
91 | static quint64 startTick;
92 | static quint64 startTime;
93 |
94 | if (!isInitialized) {
95 | isInitialized = true;
96 | timerFrequency = 0; // !!! disable QueryPerformanceCounter for initialization
97 | startTime = Timer::systemTime(); // get time via gettimeofday
98 |
99 | // the timing provided by this code is far from optimal, but it should do
100 | // as the time deltas are what we're interested in.
101 | LARGE_INTEGER freq;
102 | // set timerFrequency to zero if QueryPerformanceCounter can't be used
103 | if (!QueryPerformanceFrequency(&freq)) {
104 | timerFrequency = 0;
105 | } else {
106 | timerFrequency = freq.QuadPart;
107 | }
108 | if (timerFrequency > 0) {
109 | LARGE_INTEGER ticks;
110 | if (QueryPerformanceCounter(&ticks)) {
111 | startTick = ticks.QuadPart;
112 | } else {
113 | timerFrequency = 0;
114 | }
115 | }
116 | }
117 |
118 | if (timerFrequency > 0) {
119 | LARGE_INTEGER ticks;
120 | if (QueryPerformanceCounter(&ticks)) {
121 | return (ticks.QuadPart - startTick) * 1000000000LL / timerFrequency + startTime;
122 | }
123 | }
124 | #endif // Q_OS_WIN
125 |
126 | timeval tv;
127 | if (gettimeofday(&tv, NULL) != 0)
128 | return 0;
129 |
130 | return qint64(tv.tv_sec) * 1000000000LL + qint64(tv.tv_usec) * 1000LL;
131 | #endif // WITH_POSIX_TIMERS
132 | }
133 |
--------------------------------------------------------------------------------
/src/common/timer.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef TIMER_H
13 | #define TIMER_H
14 |
15 | #include
16 |
17 | class Timer
18 | {
19 | public:
20 | Timer();
21 |
22 | public:
23 | void setScaling(double scaling);
24 | void reset();
25 | qint64 currentTime() const;
26 |
27 | public:
28 | static qint64 systemTime();
29 |
30 | private:
31 | double m_scaling;
32 | qint64 m_start;
33 | };
34 |
35 | #endif // TIMER_H
36 |
--------------------------------------------------------------------------------
/src/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${PROTOBUF_INCLUDE_DIR})
2 |
3 | set(SOURCES
4 | examplereader.cpp
5 | )
6 |
7 | add_executable(examplereader ${SOURCES})
8 | target_link_libraries(examplereader protobuf)
9 | set_target_properties(examplereader PROPERTIES EXCLUDE_FROM_ALL true)
10 |
--------------------------------------------------------------------------------
/src/examples/examplereader.cpp:
--------------------------------------------------------------------------------
1 | #include "protobuf/ssl_referee.pb.h"
2 | #include "protobuf/messages_robocup_ssl_wrapper.pb.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | struct FileHeader
11 | {
12 | char name[12]; // SSL_LOG_FILE
13 | int32_t version; // Default file format is version 1
14 | };
15 |
16 | const char* DEFAULT_FILE_HEADER_NAME = "SSL_LOG_FILE";
17 | const int32_t DEFAULT_FILE_VERSION = 1;
18 |
19 | struct DataHeader
20 | {
21 | int64_t timestamp; // Timestamp in ns
22 | int32_t messageType; // Message type
23 | int32_t messageSize; // Size of protobuf message in bytes
24 | };
25 |
26 | enum MessageType
27 | {
28 | MESSAGE_BLANK = 0,
29 | MESSAGE_UNKNOWN = 1,
30 | MESSAGE_SSL_VISION_2010 = 2,
31 | MESSAGE_SSL_REFBOX_2013 = 3
32 | };
33 |
34 | int main(int argc, char *argv[])
35 | {
36 | if (argc != 2) {
37 | std::cout << "No input file name specified!" << std::endl;
38 | std::cout << "Please run \"examplereader \"." << std::endl;
39 |
40 | return -1;
41 | }
42 |
43 | const char *filename = argv[1];
44 |
45 | std::ifstream in(filename, std::ios_base::in | std::ios_base::binary);
46 |
47 | if (!in.is_open()) {
48 | std::cerr << "Error opening log file \"" << filename << "\"!" << std::endl;
49 | }
50 |
51 | FileHeader fileHeader;
52 | in.read((char*) &fileHeader, sizeof(fileHeader));
53 | // Log data is stored big endian, convert to host byte order
54 | fileHeader.version = be32toh(fileHeader.version);
55 |
56 | if (strncmp(fileHeader.name, DEFAULT_FILE_HEADER_NAME, sizeof(fileHeader.name)) == 0) {
57 | std::cout << "File format version " << fileHeader.version << " detected." << std::endl;
58 |
59 | if (fileHeader.version == DEFAULT_FILE_VERSION) {
60 | unsigned long refereePackets = 0;
61 | unsigned long visionPackets = 0;
62 |
63 | while (!in.eof()) {
64 | DataHeader dataHeader;
65 | in.read((char*) &dataHeader, sizeof(dataHeader));
66 | // Log data is stored big endian, convert to host byte order
67 | dataHeader.timestamp = be64toh(dataHeader.timestamp);
68 | dataHeader.messageType = be32toh(dataHeader.messageType);
69 | dataHeader.messageSize = be32toh(dataHeader.messageSize);
70 |
71 | char* data = new char[dataHeader.messageSize];
72 | in.read(data, dataHeader.messageSize);
73 |
74 | if (dataHeader.messageType == MESSAGE_SSL_VISION_2010) {
75 | SSL_WrapperPacket packet;
76 | if (packet.ParseFromArray(data, dataHeader.messageSize)) {
77 | visionPackets++;
78 | std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << (double) dataHeader.timestamp / 1e9
79 | << ": Read " << visionPackets << " vision packets and " << refereePackets << " referee packets!" << std::endl;
80 | } else {
81 | std::cerr << "Error parsing vision packet!" << std::endl;
82 | }
83 | } else if (dataHeader.messageType == MESSAGE_SSL_REFBOX_2013) {
84 | SSL_Referee packet;
85 | if (packet.ParseFromArray(data, dataHeader.messageSize)) {
86 | refereePackets++;
87 | std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << (double) dataHeader.timestamp / 1e9
88 | << ": Read " << visionPackets << " vision packets and " << refereePackets << " referee packets!" << std::endl;
89 | } else {
90 | std::cerr << "Error parsing vision packet!" << std::endl;
91 | }
92 | }
93 |
94 | delete data;
95 | }
96 | }
97 | } else {
98 | std::cerr << "Error log file is unsupported or corrupted!" << std::endl;
99 | }
100 |
101 | return 0;
102 | }
103 |
--------------------------------------------------------------------------------
/src/logconvert/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${PROTOBUF_INCLUDE_DIR})
2 | include_directories(${Boost_INCLUDE_DIRS})
3 |
4 | set(SOURCES
5 | logconvert.cpp
6 | )
7 |
8 | add_executable(logconvert ${SOURCES})
9 | target_link_libraries(logconvert common ${Boost_LIBRARIES})
10 | if(USE_QT5)
11 | target_link_libraries(logconvert Qt5::Core)
12 | else()
13 | target_link_libraries(logconvert ${QT_QTCORE_LIBRARY})
14 | include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
15 | endif()
16 |
--------------------------------------------------------------------------------
/src/logconvert/logconvert.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "common/logfile.h"
13 | #include "protobuf/ssl_referee.pb.h"
14 | #include "protobuf/messages_robocup_ssl_wrapper_legacy.pb.h"
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | int main(int argc, char *argv[])
21 | {
22 | QCoreApplication app(argc, argv);
23 |
24 | app.setApplicationName("logconvert");
25 | app.setOrganizationName("ssl-logtools");
26 |
27 | std::string fileIn;
28 | std::string fileOut;
29 | int formatVersion;
30 |
31 | boost::program_options::options_description desc("Available options");
32 | desc.add_options()
33 | ("help,h", "Print help message.")
34 | ("compress,c", "Use gzip compression.")
35 | ("format,f", boost::program_options::value(&formatVersion)->default_value(LogFile::DEFAULT_FILE_FORMAT_VERSION), "File format version.")
36 | ("input,i", boost::program_options::value(&fileIn)->default_value(""), "Input file.")
37 | ("output,o", boost::program_options::value(&fileOut)->default_value(""), "Output file.")
38 | ;
39 |
40 | boost::program_options::variables_map vm;
41 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
42 | boost::program_options::notify(vm);
43 |
44 | if (vm.count("help")) {
45 | std::cout << desc << std::endl;
46 | return 1;
47 | }
48 |
49 | if (fileIn.size() < 1) {
50 | std::cout << "No input file specified!" << std::endl;
51 | std::cout << desc << std::endl;
52 | return -1;
53 | }
54 |
55 | if (fileOut.size() < 1) {
56 | std::cout << "No output file specified!" << std::endl;
57 | std::cout << desc << std::endl;
58 | return -1;
59 | }
60 |
61 | QString filenameIn = QString::fromStdString(fileIn);
62 | QString filenameOut = QString::fromStdString(fileOut);
63 |
64 | if (filenameIn == filenameOut) {
65 | std::cout << "Output file must be different from input file!" << std::endl;
66 | std::cout << desc << std::endl;
67 | return -1;
68 | }
69 |
70 | QFileInfo fileInfo(filenameIn);
71 | bool compressed = false;
72 | if (fileInfo.suffix() == "gz") {
73 | compressed = true;
74 | }
75 |
76 | LogFile in(filenameIn, compressed);
77 | LogFile out(filenameOut, vm.count("compressed"), formatVersion);
78 |
79 | if (!in.openRead() || !out.openWrite()) {
80 | return -1;
81 | }
82 |
83 | QByteArray data;
84 | qint64 time;
85 | MessageType type;
86 |
87 | RoboCup2014Legacy::Wrapper::SSL_WrapperPacket visionPacket;
88 | SSL_Referee refereePacket;
89 |
90 | while (in.readMessage(data, time, type)) {
91 | // OK, let's try to figure this out by parsing the message
92 | if (type == MESSAGE_UNKNOWN) {
93 | if (refereePacket.ParseFromArray(data.data(), data.size())) {
94 | type = MESSAGE_SSL_REFBOX_2013;
95 | } else if (visionPacket.ParseFromArray(data.data(), data.size())) {
96 | type = MESSAGE_SSL_VISION_2010;
97 | }
98 | }
99 |
100 | out.saveMessage(data, time, type);
101 | }
102 |
103 | return 0;
104 | }
105 |
--------------------------------------------------------------------------------
/src/logplayer/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${PROTOBUF_INCLUDE_DIR})
2 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
3 |
4 | set(SOURCES
5 | logplayer.cpp
6 | mainwindow.cpp
7 | player.cpp
8 | )
9 |
10 | set(MOC_SOURCES
11 | mainwindow.h
12 | player.h
13 | )
14 |
15 | set(UI_SOURCES
16 | mainwindow.ui
17 | )
18 |
19 | qt4_wrap_cpp(MOC_SOURCES ${MOC_SOURCES})
20 | qt4_wrap_ui(UIC_SOURCES ${UI_SOURCES})
21 |
22 | add_executable(logplayer ${SOURCES} ${MOC_SOURCES} ${UIC_SOURCES})
23 | target_link_libraries(logplayer common)
24 | if(USE_QT5)
25 | target_link_libraries(logplayer Qt5::Widgets Qt5::Network)
26 | else()
27 | target_link_libraries(logplayer ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY})
28 | include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR})
29 | endif()
30 |
--------------------------------------------------------------------------------
/src/logplayer/logplayer.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "mainwindow.h"
13 | #include
14 |
15 | int main(int argc, char *argv[])
16 | {
17 | QApplication app(argc, argv);
18 |
19 | app.setApplicationName("logplayer");
20 | app.setOrganizationName("ssl-logtools");
21 |
22 | MainWindow window;
23 | window.show();
24 |
25 | if(argc > 1)
26 | {
27 | QString filename(argv[1]);
28 | window.loadFile(&filename);
29 | window.setStopped(false);
30 | }
31 |
32 | return app.exec();
33 | }
34 |
--------------------------------------------------------------------------------
/src/logplayer/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "mainwindow.h"
13 | #include "ui_mainwindow.h"
14 | #include
15 | #include
16 |
17 | MainWindow::MainWindow(QWidget* parent) :
18 | QMainWindow(parent),
19 | m_ui(new Ui::MainWindow),
20 | m_stopped(true),
21 | m_currentFrame(0)
22 | {
23 | m_ui->setupUi(this);
24 |
25 | m_ui->btnOpen->setIcon(QIcon::fromTheme("document-open"));
26 | m_ui->btnPlay->setIcon(QIcon::fromTheme("media-playback-start"));
27 |
28 | connect(m_ui->btnOpen, SIGNAL(clicked()), SLOT(openFile()));
29 | connect(m_ui->actionOpen, SIGNAL(triggered()), SLOT(openFile()));
30 | connect(m_ui->btnPlay, SIGNAL(clicked()), SLOT(toggleStopped()));
31 | connect(m_ui->actionPlay, SIGNAL(triggered()), SLOT(toggleStopped()));
32 | connect(m_ui->horizontalSlider, SIGNAL(sliderReleased()), SLOT(userSliderChange()));
33 |
34 | m_statusLabel = new QLabel;
35 | statusBar()->addPermanentWidget(m_statusLabel);
36 |
37 | QSettings s;
38 | s.beginGroup("MainWindow");
39 | restoreGeometry(s.value("Geometry").toByteArray());
40 | restoreState(s.value("State").toByteArray());
41 | s.endGroup();
42 |
43 | connect(&m_player, SIGNAL(positionChanged(int,double)), SLOT(updatePosition(int,double)));
44 |
45 | setStopped(true);
46 | }
47 |
48 | MainWindow::~MainWindow()
49 | {
50 | delete m_ui;
51 | }
52 |
53 | void MainWindow::closeEvent(QCloseEvent* e)
54 | {
55 | QSettings s;
56 |
57 | s.beginGroup("MainWindow");
58 | s.setValue("Geometry", saveGeometry());
59 | s.setValue("State", saveState());
60 | s.endGroup();
61 |
62 | QMainWindow::closeEvent(e);
63 | }
64 |
65 | void MainWindow::openFile()
66 | {
67 | setStopped(true);
68 |
69 | QString filename = QFileDialog::getOpenFileName(this, "Select log file", "", "Log files (*.log *.log.gz)");
70 |
71 | if (!filename.isEmpty()) {
72 | loadFile(&filename);
73 | }
74 | }
75 |
76 | void MainWindow::loadFile(const QString *filename)
77 | {
78 | m_currentFrame = 0;
79 |
80 | int maxFrame;
81 | double duration;
82 |
83 | if (m_player.load(*filename, maxFrame, duration)) {
84 | m_ui->horizontalSlider->setValue(0);
85 | m_ui->horizontalSlider->setMaximum(maxFrame);
86 |
87 | m_ui->lblPacketMax->setText(QString::number(maxFrame));
88 | m_ui->lblTimeMax->setText(QString("%1:%2.%3")
89 | .arg((int) (duration / 1E9) / 60)
90 | .arg((int) (duration / 1E9) % 60, 2, 10, QChar('0'))
91 | .arg((int) (duration / 1E6) % 1000, 3, 10, QChar('0')));
92 |
93 | QFileInfo fileInfo(*filename);
94 | m_statusLabel->setText(fileInfo.fileName());
95 | }
96 | }
97 |
98 | void MainWindow::userSliderChange()
99 | {
100 | int value = m_ui->horizontalSlider->value();
101 | seekFrame(value);
102 | }
103 |
104 | void MainWindow::seekFrame(int frame)
105 | {
106 | m_currentFrame = frame;
107 |
108 | if (!m_stopped) {
109 | m_player.stop();
110 | m_player.start(m_currentFrame);
111 | }
112 | }
113 |
114 | void MainWindow::toggleStopped()
115 | {
116 | setStopped(!m_stopped);
117 | }
118 |
119 | void MainWindow::setStopped(bool p)
120 | {
121 | m_stopped = p | !m_player.good();
122 |
123 | if (m_stopped) {
124 | m_ui->btnPlay->setIcon(QIcon::fromTheme("media-playback-start"));
125 | m_ui->actionPlay->setText("Play");
126 | m_player.stop();
127 | } else {
128 | m_ui->btnPlay->setIcon(QIcon::fromTheme("media-playback-stop"));
129 | m_ui->actionPlay->setText("Stop");
130 | m_player.start(m_currentFrame);
131 | }
132 | }
133 |
134 | void MainWindow::updatePosition(int frame, double time)
135 | {
136 | m_currentFrame = frame;
137 |
138 | if (!m_ui->horizontalSlider->isSliderDown()) {
139 | m_ui->horizontalSlider->setValue(frame);
140 | }
141 |
142 | m_ui->lblPacketCurrent->setText(QString::number(frame));
143 | m_ui->lblTimeCurrent->setText(QString("%1:%2.%3")
144 | .arg((int) (time / 1E9) / 60)
145 | .arg((int) (time / 1E9) % 60, 2, 10, QChar('0'))
146 | .arg((int) (time / 1E6) % 1000, 3, 10, QChar('0')));
147 | }
148 |
--------------------------------------------------------------------------------
/src/logplayer/mainwindow.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef MAINWINDOW_H
13 | #define MAINWINDOW_H
14 |
15 | #include "player.h"
16 | #include
17 | #include
18 |
19 | namespace Ui {
20 | class MainWindow;
21 | }
22 |
23 | class MainWindow : public QMainWindow
24 | {
25 | Q_OBJECT
26 |
27 | public:
28 | explicit MainWindow(QWidget *parent = 0);
29 | ~MainWindow();
30 | void loadFile(const QString *filename);
31 | void setStopped(bool p);
32 |
33 | protected:
34 | void closeEvent(QCloseEvent *e);
35 |
36 | private slots:
37 | void openFile();
38 | void toggleStopped();
39 | void userSliderChange();
40 | void seekFrame(int frame);
41 | void updatePosition(int frame, double time);
42 |
43 | private:
44 | Ui::MainWindow* m_ui;
45 | QLabel* m_statusLabel;
46 | Player m_player;
47 | int m_currentFrame;
48 | bool m_stopped;
49 | };
50 |
51 | #endif // MAINWINDOW_H
52 |
--------------------------------------------------------------------------------
/src/logplayer/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 133
11 |
12 |
13 |
14 | Log Player
15 |
16 |
17 |
18 | -
19 |
20 |
-
21 |
22 |
23 | ...
24 |
25 |
26 |
27 | -
28 |
29 |
30 | ...
31 |
32 |
33 |
34 | -
35 |
36 |
-
37 |
38 |
39 | 00:00.000
40 |
41 |
42 |
43 | -
44 |
45 |
46 |
47 | 100
48 | 0
49 |
50 |
51 |
52 | 0
53 |
54 |
55 |
56 |
57 |
58 | -
59 |
60 |
61 | 0
62 |
63 |
64 | 1000
65 |
66 |
67 | Qt::Horizontal
68 |
69 |
70 |
71 | -
72 |
73 |
-
74 |
75 |
76 | 00:00.000
77 |
78 |
79 |
80 | -
81 |
82 |
83 |
84 | 100
85 | 0
86 |
87 |
88 |
89 | 0
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
124 |
125 |
126 |
127 | Step
128 |
129 |
130 | Step
131 |
132 |
133 | .
134 |
135 |
136 |
137 |
138 | Open
139 |
140 |
141 | Ctrl+O
142 |
143 |
144 |
145 |
146 | Quit
147 |
148 |
149 | Ctrl+Q
150 |
151 |
152 |
153 |
154 | Play
155 |
156 |
157 | Space
158 |
159 |
160 |
161 |
162 |
163 |
164 | actionQuit
165 | triggered()
166 | MainWindow
167 | close()
168 |
169 |
170 | -1
171 | -1
172 |
173 |
174 | 399
175 | 66
176 |
177 |
178 |
179 |
180 |
181 |
--------------------------------------------------------------------------------
/src/logplayer/player.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "player.h"
13 | #include "common/timer.h"
14 | #include "protobuf/ssl_referee.pb.h"
15 | #include "protobuf/messages_robocup_ssl_wrapper_legacy.pb.h"
16 | #include
17 | #include
18 |
19 | Player::Player() :
20 | m_referee(NULL),
21 | m_vision(NULL),
22 | m_legacyVision(NULL)
23 | {
24 | // create referee socket
25 | Q_ASSERT(m_referee == NULL);
26 | m_referee = new Network(QHostAddress("224.5.23.1"), 0, 10003);
27 | m_referee->connect();
28 |
29 | // create vision socket
30 | Q_ASSERT(m_vision == NULL);
31 | m_vision = new Network(QHostAddress("224.5.23.2"), 0, 10006);
32 | m_vision->connect();
33 |
34 | // create legacy vision socket
35 | Q_ASSERT(m_legacyVision == NULL);
36 | m_legacyVision = new Network(QHostAddress("224.5.23.2"), 0, 10005);
37 | m_legacyVision->connect();
38 | }
39 |
40 | Player::~Player()
41 | {
42 | stop();
43 |
44 | delete m_referee;
45 | m_referee = NULL;
46 |
47 | delete m_vision;
48 | m_vision = NULL;
49 |
50 | delete m_legacyVision;
51 | m_legacyVision = NULL;
52 |
53 | qDeleteAll(packets);
54 | packets.clear();
55 | }
56 |
57 | bool Player::load(const QString& filename, int& maxFrame, double& duration) {
58 | QFileInfo fileInfo(filename);
59 |
60 | bool compressed = false;
61 |
62 | if (fileInfo.suffix() == "gz") {
63 | compressed = true;
64 | }
65 |
66 | LogFile file(filename, compressed);
67 |
68 | if (!file.openRead()) {
69 | return false;
70 | }
71 |
72 | qDeleteAll(packets);
73 | packets.clear();
74 |
75 | for (;;) {
76 | Frame* packet = new Frame;
77 |
78 | if (!file.readMessage(packet->data, packet->time, packet->type)) {
79 | delete packet;
80 | break;
81 | }
82 |
83 | packets.append(packet);
84 | }
85 |
86 | maxFrame = packets.size() - 1;
87 | duration = packets.last()->time - packets.first()->time;
88 | return true;
89 | }
90 |
91 | bool Player::start(int position)
92 | {
93 | if (position > packets.size() - 1) {
94 | return false;
95 | }
96 |
97 | m_currentFrame = position;
98 |
99 | m_mayRun = true;
100 | QThread::start();
101 |
102 | return true;
103 | }
104 |
105 | void Player::stop()
106 | {
107 | m_mayRun = false;
108 | wait();
109 | }
110 |
111 | bool Player::good()
112 | {
113 | return packets.size() > 0;
114 | }
115 |
116 | void Player::sendMessage(const Frame* packet)
117 | {
118 | RoboCup2014Legacy::Wrapper::SSL_WrapperPacket legacyVisionPacket;
119 | SSL_Referee refereePacket;
120 |
121 | if (packet->type == MESSAGE_BLANK) {
122 | // ignore
123 | } else if (packet->type == MESSAGE_UNKNOWN) {
124 | // OK, let's try to figure this out by parsing the message
125 | if (refereePacket.ParseFromArray(packet->data.data(), packet->data.size())) {
126 | m_referee->writeData(packet->data);
127 | } else if (legacyVisionPacket.ParseFromArray(packet->data.data(), packet->data.size())) {
128 | m_legacyVision->writeData(packet->data);
129 | } else {
130 | std::cout << "Error unsupported or corrupt packet found in log file!" << std::endl;
131 | }
132 | } else if (packet->type == MESSAGE_SSL_VISION_2010) {
133 | m_legacyVision->writeData(packet->data);
134 | } else if (packet->type == MESSAGE_SSL_REFBOX_2013) {
135 | m_referee->writeData(packet->data);
136 | } else if (packet->type == MESSAGE_SSL_VISION_2014) {
137 | m_vision->writeData(packet->data);
138 | } else {
139 | std::cout << "Error unsupported message type found in log file!" << std::endl;
140 | }
141 | }
142 |
143 | void Player::run()
144 | {
145 | sendMessage(packets.at(m_currentFrame));
146 |
147 | const qint64 startTime = Timer::systemTime();
148 | const qint64 referenceTime = packets.at(m_currentFrame)->time;
149 |
150 | while (m_mayRun && ++m_currentFrame < packets.size() && this->isRunning()) {
151 | Frame* packet = packets.at(m_currentFrame);
152 |
153 | qint64 sleepTime = ((packet->time - referenceTime) - (Timer::systemTime() - startTime)) / 1000;
154 |
155 | if (sleepTime > 0) {
156 | QThread::currentThread()->usleep(sleepTime);
157 | }
158 |
159 | sendMessage(packet);
160 |
161 | emit positionChanged(m_currentFrame, packet->time - packets.first()->time);
162 | }
163 |
164 | emit finished();
165 | }
166 |
--------------------------------------------------------------------------------
/src/logplayer/player.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef PLAYER_H
13 | #define PLAYER_H
14 |
15 | #include "common/logfile.h"
16 | #include "common/network.h"
17 | #include
18 |
19 | class Player : public QThread
20 | {
21 | Q_OBJECT
22 |
23 | public:
24 | struct Frame {
25 | qint64 time;
26 | MessageType type;
27 | QByteArray data;
28 | };
29 |
30 | public:
31 | Player();
32 | ~Player();
33 |
34 | signals:
35 | void positionChanged(int frame, double time);
36 | void finished();
37 |
38 | public:
39 | bool load(const QString& filename, int& maxFrame, double& duration);
40 | bool start(int position);
41 | void stop();
42 | void pause(bool pause);
43 | bool good();
44 |
45 | private:
46 | void run();
47 | void sendMessage(const Frame* packet);
48 |
49 | private:
50 | QList packets;
51 | Network* m_referee;
52 | Network* m_vision;
53 | Network* m_legacyVision;
54 | bool m_mayRun;
55 | int m_currentFrame;
56 | };
57 |
58 | #endif // PLAYER_H
59 |
--------------------------------------------------------------------------------
/src/logrecorder/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${Boost_INCLUDE_DIRS})
2 |
3 | set(SOURCES
4 | logrecorder.cpp
5 | )
6 |
7 | add_executable(logrecorder ${SOURCES})
8 | target_link_libraries(logrecorder common ${Boost_LIBRARIES})
9 | if(USE_QT5)
10 | target_link_libraries(logrecorder Qt5::Core Qt5::Network)
11 | else()
12 | target_link_libraries(logrecorder ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
13 | include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR})
14 | endif()
15 |
--------------------------------------------------------------------------------
/src/logrecorder/logrecorder.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "common/recorder.h"
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | void signalHandler(int)
20 | {
21 | QCoreApplication::quit();
22 | }
23 |
24 | int main(int argc, char *argv[])
25 | {
26 | QCoreApplication app(argc, argv);
27 |
28 | app.setApplicationName("logrecorder");
29 | app.setOrganizationName("ssl-logtools");
30 |
31 | signal(SIGABRT, &signalHandler);
32 | signal(SIGTERM, &signalHandler);
33 | signal(SIGINT, &signalHandler);
34 |
35 | std::string filename;
36 | int formatVersion;
37 |
38 | boost::program_options::options_description desc("Available options");
39 | desc.add_options()
40 | ("help,h", "Print help message.")
41 | ("compress,c", "Use gzip compression.")
42 | ("format,f", boost::program_options::value(&formatVersion)->default_value(LogFile::DEFAULT_FILE_FORMAT_VERSION), "File format version.")
43 | ("output,o", boost::program_options::value(&filename)->default_value(""), "Output file.")
44 | ;
45 |
46 | boost::program_options::variables_map vm;
47 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
48 | boost::program_options::notify(vm);
49 |
50 | if (vm.count("help")) {
51 | std::cout << desc << std::endl;
52 | return 1;
53 | }
54 |
55 | if (filename.size() < 1) {
56 | std::cout << "No output file specified!" << std::endl;
57 | std::cout << desc << std::endl;
58 | return -1;
59 | }
60 |
61 | Recorder recorder;
62 | if (!recorder.start(QString::fromStdString(filename), vm.count("compress"), formatVersion)) {
63 | return -1;
64 | }
65 |
66 | return app.exec();
67 | }
68 |
--------------------------------------------------------------------------------
/src/protobuf/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(${PROTOBUF_INCLUDE_DIR})
2 |
3 | set(PROTO_FILES
4 | messages_robocup_ssl_detection.proto
5 | messages_robocup_ssl_geometry.proto
6 | messages_robocup_ssl_geometry_legacy.proto
7 | ssl_referee.proto
8 | messages_robocup_ssl_wrapper.proto
9 | messages_robocup_ssl_wrapper_legacy.proto
10 | )
11 |
12 | protobuf_generate_cpp(PROTO_SOURCES PROTO_HEADERS ${PROTO_FILES})
13 |
14 | add_library(protobuf ${PROTO_SOURCES} ${PROTO_HEADERS} ${PROTO_FILES})
15 | target_link_libraries(protobuf ${PROTOBUF_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
16 |
17 |
--------------------------------------------------------------------------------
/src/protobuf/messages_robocup_ssl_detection.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | message SSL_DetectionBall {
4 | required float confidence = 1;
5 | optional uint32 area = 2;
6 | required float x = 3;
7 | required float y = 4;
8 | optional float z = 5;
9 | required float pixel_x = 6;
10 | required float pixel_y = 7;
11 | }
12 |
13 | message SSL_DetectionRobot {
14 | required float confidence = 1;
15 | optional uint32 robot_id = 2;
16 | required float x = 3;
17 | required float y = 4;
18 | optional float orientation = 5;
19 | required float pixel_x = 6;
20 | required float pixel_y = 7;
21 | optional float height = 8;
22 | }
23 |
24 | message SSL_DetectionFrame {
25 | required uint32 frame_number = 1;
26 | required double t_capture = 2;
27 | required double t_sent = 3;
28 | required uint32 camera_id = 4;
29 | repeated SSL_DetectionBall balls = 5;
30 | repeated SSL_DetectionRobot robots_yellow = 6;
31 | repeated SSL_DetectionRobot robots_blue = 7;
32 | }
33 |
--------------------------------------------------------------------------------
/src/protobuf/messages_robocup_ssl_geometry.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | // A 2D float vector.
4 | message Vector2f {
5 | required float x = 1;
6 | required float y = 2;
7 | }
8 |
9 | // Represents a field marking as a line segment represented by a start point p1,
10 | // and end point p2, and a line thickness. The start and end points are along
11 | // the center of the line, so the thickness of the line extends by thickness / 2
12 | // on either side of the line.
13 | message SSL_FieldLineSegment {
14 | // Name of this field marking.
15 | required string name = 1;
16 | // Start point of the line segment.
17 | required Vector2f p1 = 2;
18 | // End point of the line segment.
19 | required Vector2f p2 = 3;
20 | // Thickness of the line segment.
21 | required float thickness = 4;
22 | }
23 |
24 | // Represents a field marking as a circular arc segment represented by center point, a
25 | // start angle, an end angle, and an arc thickness.
26 | message SSL_FieldCicularArc {
27 | // Name of this field marking.
28 | required string name = 1;
29 | // Center point of the circular arc.
30 | required Vector2f center = 2;
31 | // Radius of the arc.
32 | required float radius = 3;
33 | // Start angle in counter-clockwise order.
34 | required float a1 = 4;
35 | // End angle in counter-clockwise order.
36 | required float a2 = 5;
37 | // Thickness of the arc.
38 | required float thickness = 6;
39 | }
40 |
41 | message SSL_GeometryFieldSize {
42 | required int32 field_length = 1;
43 | required int32 field_width = 2;
44 | required int32 goal_width = 3;
45 | required int32 goal_depth = 4;
46 | required int32 boundary_width = 5;
47 | repeated SSL_FieldLineSegment field_lines = 6;
48 | repeated SSL_FieldCicularArc field_arcs = 7;
49 | }
50 |
51 | message SSL_GeometryCameraCalibration {
52 | required uint32 camera_id = 1;
53 | required float focal_length = 2;
54 | required float principal_point_x = 3;
55 | required float principal_point_y = 4;
56 | required float distortion = 5;
57 | required float q0 = 6;
58 | required float q1 = 7;
59 | required float q2 = 8;
60 | required float q3 = 9;
61 | required float tx = 10;
62 | required float ty = 11;
63 | required float tz = 12;
64 | optional float derived_camera_world_tx = 13;
65 | optional float derived_camera_world_ty = 14;
66 | optional float derived_camera_world_tz = 15;
67 | }
68 |
69 | message SSL_GeometryData {
70 | required SSL_GeometryFieldSize field = 1;
71 | repeated SSL_GeometryCameraCalibration calib = 2;
72 | }
73 |
--------------------------------------------------------------------------------
/src/protobuf/messages_robocup_ssl_geometry_legacy.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | import "messages_robocup_ssl_geometry.proto";
4 | package RoboCup2014Legacy.Geometry;
5 |
6 | message SSL_GeometryFieldSize {
7 | required int32 line_width = 1;
8 | required int32 field_length = 2;
9 | required int32 field_width = 3;
10 | required int32 boundary_width = 4;
11 | required int32 referee_width = 5;
12 | required int32 goal_width = 6;
13 | required int32 goal_depth = 7;
14 | required int32 goal_wall_width = 8;
15 | required int32 center_circle_radius = 9;
16 | required int32 defense_radius = 10;
17 | required int32 defense_stretch = 11;
18 | required int32 free_kick_from_defense_dist = 12;
19 | required int32 penalty_spot_from_field_line_dist = 13;
20 | required int32 penalty_line_from_spot_dist = 14;
21 | }
22 |
23 | // SSL_GeometryCameraCalibration is identical to the one defined in
24 | // messages_robocup_ssl_geometry.proto .
25 |
26 | message SSL_GeometryData {
27 | required SSL_GeometryFieldSize field = 1;
28 | repeated SSL_GeometryCameraCalibration calib = 2;
29 | }
30 |
--------------------------------------------------------------------------------
/src/protobuf/messages_robocup_ssl_wrapper.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | import "messages_robocup_ssl_detection.proto";
4 | import "messages_robocup_ssl_geometry.proto";
5 |
6 | message SSL_WrapperPacket {
7 | optional SSL_DetectionFrame detection = 1;
8 | optional SSL_GeometryData geometry = 2;
9 | }
10 |
--------------------------------------------------------------------------------
/src/protobuf/messages_robocup_ssl_wrapper_legacy.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | import "messages_robocup_ssl_detection.proto";
4 | import "messages_robocup_ssl_geometry_legacy.proto";
5 |
6 | package RoboCup2014Legacy.Wrapper;
7 |
8 | message SSL_WrapperPacket {
9 | optional SSL_DetectionFrame detection = 1;
10 | optional RoboCup2014Legacy.Geometry.SSL_GeometryData geometry = 2;
11 | }
12 |
--------------------------------------------------------------------------------
/src/protobuf/ssl_referee.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Robotic Activities Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * All rights reserved. *
7 | * *
8 | ***************************************************************************/
9 |
10 | #include "ssl_referee.h"
11 |
12 | /*!
13 | * \brief Initializes team info with default values
14 | * \param teamInfo The team info to initialize
15 | */
16 | void teamInfoSetDefault(SSL_Referee::TeamInfo *teamInfo)
17 | {
18 | teamInfo->set_name("");
19 | teamInfo->set_score(0);
20 | teamInfo->set_red_cards(0);
21 | teamInfo->set_yellow_cards(0);
22 | teamInfo->set_timeouts(4);
23 | teamInfo->set_timeout_time(5 * 60 * 1000*1000);
24 | teamInfo->set_goalie(0);
25 | assert(teamInfo->IsInitialized());
26 | }
27 |
--------------------------------------------------------------------------------
/src/protobuf/ssl_referee.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Robotic Activities Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * All rights reserved. *
7 | * *
8 | ***************************************************************************/
9 |
10 | #ifndef SSL_REFEREE_H
11 | #define SSL_REFEREE_H
12 |
13 | #include "protobuf/ssl_referee.pb.h"
14 |
15 | void teamInfoSetDefault(SSL_Referee::TeamInfo *teamInfo);
16 |
17 | #endif // SSL_REFEREE_H
18 |
--------------------------------------------------------------------------------
/src/protobuf/ssl_referee.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | // Each UDP packet contains one of these messages.
4 | message SSL_Referee {
5 | // The UNIX timestamp when the packet was sent, in microseconds.
6 | // Divide by 1,000,000 to get a time_t.
7 | required uint64 packet_timestamp = 1;
8 |
9 | // These are the "coarse" stages of the game.
10 | enum Stage {
11 | // The first half is about to start.
12 | // A kickoff is called within this stage.
13 | // This stage ends with the NORMAL_START.
14 | NORMAL_FIRST_HALF_PRE = 0;
15 | // The first half of the normal game, before half time.
16 | NORMAL_FIRST_HALF = 1;
17 | // Half time between first and second halves.
18 | NORMAL_HALF_TIME = 2;
19 | // The second half is about to start.
20 | // A kickoff is called within this stage.
21 | // This stage ends with the NORMAL_START.
22 | NORMAL_SECOND_HALF_PRE = 3;
23 | // The second half of the normal game, after half time.
24 | NORMAL_SECOND_HALF = 4;
25 | // The break before extra time.
26 | EXTRA_TIME_BREAK = 5;
27 | // The first half of extra time is about to start.
28 | // A kickoff is called within this stage.
29 | // This stage ends with the NORMAL_START.
30 | EXTRA_FIRST_HALF_PRE = 6;
31 | // The first half of extra time.
32 | EXTRA_FIRST_HALF = 7;
33 | // Half time between first and second extra halves.
34 | EXTRA_HALF_TIME = 8;
35 | // The second half of extra time is about to start.
36 | // A kickoff is called within this stage.
37 | // This stage ends with the NORMAL_START.
38 | EXTRA_SECOND_HALF_PRE = 9;
39 | // The second half of extra time.
40 | EXTRA_SECOND_HALF = 10;
41 | // The break before penalty shootout.
42 | PENALTY_SHOOTOUT_BREAK = 11;
43 | // The penalty shootout.
44 | PENALTY_SHOOTOUT = 12;
45 | // The game is over.
46 | POST_GAME = 13;
47 | }
48 | required Stage stage = 2;
49 |
50 | // The number of microseconds left in the stage.
51 | // The following stages have this value; the rest do not:
52 | // NORMAL_FIRST_HALF
53 | // NORMAL_HALF_TIME
54 | // NORMAL_SECOND_HALF
55 | // EXTRA_TIME_BREAK
56 | // EXTRA_FIRST_HALF
57 | // EXTRA_HALF_TIME
58 | // EXTRA_SECOND_HALF
59 | // PENALTY_SHOOTOUT_BREAK
60 | //
61 | // If the stage runs over its specified time, this value
62 | // becomes negative.
63 | optional sint32 stage_time_left = 3;
64 |
65 | // These are the "fine" states of play on the field.
66 | enum Command {
67 | // All robots should completely stop moving.
68 | HALT = 0;
69 | // Robots must keep 50 cm from the ball.
70 | STOP = 1;
71 | // A prepared kickoff or penalty may now be taken.
72 | NORMAL_START = 2;
73 | // The ball is dropped and free for either team.
74 | FORCE_START = 3;
75 | // The yellow team may move into kickoff position.
76 | PREPARE_KICKOFF_YELLOW = 4;
77 | // The blue team may move into kickoff position.
78 | PREPARE_KICKOFF_BLUE = 5;
79 | // The yellow team may move into penalty position.
80 | PREPARE_PENALTY_YELLOW = 6;
81 | // The blue team may move into penalty position.
82 | PREPARE_PENALTY_BLUE = 7;
83 | // The yellow team may take a direct free kick.
84 | DIRECT_FREE_YELLOW = 8;
85 | // The blue team may take a direct free kick.
86 | DIRECT_FREE_BLUE = 9;
87 | // The yellow team may take an indirect free kick.
88 | INDIRECT_FREE_YELLOW = 10;
89 | // The blue team may take an indirect free kick.
90 | INDIRECT_FREE_BLUE = 11;
91 | // The yellow team is currently in a timeout.
92 | TIMEOUT_YELLOW = 12;
93 | // The blue team is currently in a timeout.
94 | TIMEOUT_BLUE = 13;
95 | // The yellow team just scored a goal.
96 | // For information only.
97 | // For rules compliance, teams must treat as STOP.
98 | GOAL_YELLOW = 14;
99 | // The blue team just scored a goal.
100 | GOAL_BLUE = 15;
101 | }
102 | required Command command = 4;
103 |
104 | // The number of commands issued since startup (mod 2^32).
105 | required uint32 command_counter = 5;
106 |
107 | // The UNIX timestamp when the command was issued, in microseconds.
108 | // This value changes only when a new command is issued, not on each packet.
109 | required uint64 command_timestamp = 6;
110 |
111 | // Information about a single team.
112 | message TeamInfo {
113 | // The team's name (empty string if operator has not typed anything).
114 | required string name = 1;
115 | // The number of goals scored by the team during normal play and overtime.
116 | required uint32 score = 2;
117 | // The number of red cards issued to the team since the beginning of the game.
118 | required uint32 red_cards = 3;
119 | // The amount of time (in microseconds) left on each yellow card issued to the team.
120 | // If no yellow cards are issued, this array has no elements.
121 | // Otherwise, times are ordered from smallest to largest.
122 | repeated uint32 yellow_card_times = 4 [packed=true];
123 | // The total number of yellow cards ever issued to the team.
124 | required uint32 yellow_cards = 5;
125 | // The number of timeouts this team can still call.
126 | // If in a timeout right now, that timeout is excluded.
127 | required uint32 timeouts = 6;
128 | // The number of microseconds of timeout this team can use.
129 | required uint32 timeout_time = 7;
130 | // The pattern number of this team's goalie.
131 | required uint32 goalie = 8;
132 | }
133 |
134 | // Information about the two teams.
135 | required TeamInfo yellow = 7;
136 | required TeamInfo blue = 8;
137 | }
138 |
--------------------------------------------------------------------------------
/src/qt/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(SOURCES
2 | multicastsocket.cpp
3 | multicastsocket.h
4 |
5 | qtiocompressor.cpp
6 | )
7 |
8 | set(MOC_SOURCES
9 | qtiocompressor.h
10 | )
11 |
12 | qt4_wrap_cpp(MOC_SOURCES ${MOC_SOURCES})
13 |
14 | add_library(qt ${SOURCES} ${MOC_SOURCES})
15 | target_link_libraries(qt ${ZLIB_LIBRARIES})
16 | if(USE_QT5)
17 | target_link_libraries(qt Qt5::Core Qt5::Network)
18 | else()
19 | target_link_libraries(qt ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
20 | include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR})
21 | endif()
22 |
23 | if(WIN32)
24 | target_link_libraries(qt wsock32)
25 | endif()
26 |
--------------------------------------------------------------------------------
/src/qt/multicastsocket.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #include "multicastsocket.h"
13 | #include
14 |
15 | #ifdef Q_OS_WIN
16 | #include
17 | #else
18 | #include
19 | #endif
20 |
21 | /*!
22 | * \class MulticastSocket
23 | * \brief Extension of QUdpSocket to provide UDP multicast features
24 | *
25 | * This class implements multicast features from Qt 4.7. As soon as
26 | * the dependency is raised to 4.7 this class can be removed.
27 | */
28 |
29 | MulticastSocket::MulticastSocket(QObject *parent) :
30 | QUdpSocket(parent)
31 | {
32 | }
33 |
34 | bool MulticastSocket::joinMulticastGroup(const QHostAddress &groupAddress)
35 | {
36 | return joinMulticastGroup(groupAddress, QNetworkInterface());
37 | }
38 |
39 | bool MulticastSocket::joinMulticastGroup(const QHostAddress& groupAddress, const QNetworkInterface& iface)
40 | {
41 | bool success = false;
42 |
43 | foreach (const QNetworkAddressEntry& addressEntry, iface.addressEntries()) {
44 | const QHostAddress interfaceAddress = addressEntry.ip();
45 |
46 | if (interfaceAddress.protocol() == IPv4Protocol) {
47 | ip_mreq mreq;
48 | mreq.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
49 | mreq.imr_interface.s_addr = htonl(interfaceAddress.toIPv4Address());
50 |
51 | const bool error = setsockopt(socketDescriptor(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*) &mreq, sizeof(mreq)) == -1;
52 | if (error)
53 | setErrorString(strerror(errno));
54 | else
55 | success = true;
56 | }
57 | }
58 |
59 | return success;
60 | }
61 |
--------------------------------------------------------------------------------
/src/qt/multicastsocket.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (c) 2013 Robotics Erlangen e.V. *
3 | * http://www.robotics-erlangen.de/ *
4 | * info@robotics-erlangen.de *
5 | * *
6 | * This file may be licensed under the terms of the GNU General Public *
7 | * License Version 3, as published by the Free Software Foundation. *
8 | * You can find it here: http://www.gnu.org/licenses/gpl.html *
9 | * *
10 | ***************************************************************************/
11 |
12 | #ifndef MULTICASTSOCKET_H
13 | #define MULTICASTSOCKET_H
14 |
15 | #include
16 | #include
17 |
18 | class MulticastSocket : public QUdpSocket
19 | {
20 | public:
21 | explicit MulticastSocket(QObject *parent = 0);
22 |
23 | public:
24 | bool joinMulticastGroup(const QHostAddress &groupAddress);
25 | bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface);
26 | };
27 |
28 | #endif // MULTICASTSOCKET_H
29 |
--------------------------------------------------------------------------------
/src/qt/qtiocompressor.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of a Qt Solutions component.
8 | **
9 | ** Commercial Usage
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
11 | ** accordance with the Qt Solutions Commercial License Agreement provided
12 | ** with the Software or, alternatively, in accordance with the terms
13 | ** contained in a written agreement between you and Nokia.
14 | **
15 | ** GNU Lesser General Public License Usage
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
17 | ** General Public License version 2.1 as published by the Free Software
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
19 | ** packaging of this file. Please review the following information to
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 | **
23 | ** In addition, as a special exception, Nokia gives you certain
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
25 | ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
26 | ** package.
27 | **
28 | ** GNU General Public License Usage
29 | ** Alternatively, this file may be used under the terms of the GNU
30 | ** General Public License version 3.0 as published by the Free Software
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
32 | ** packaging of this file. Please review the following information to
33 | ** ensure the GNU General Public License version 3.0 requirements will be
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
35 | **
36 | ** Please note Third Party Software included with Qt Solutions may impose
37 | ** additional restrictions and it is the user's responsibility to ensure
38 | ** that they have met the licensing requirements of the GPL, LGPL, or Qt
39 | ** Solutions Commercial license and the relevant license of the Third
40 | ** Party Software they are using.
41 | **
42 | ** If you are unsure which license is appropriate for your use, please
43 | ** contact Nokia at qt-info@nokia.com.
44 | **
45 | ****************************************************************************/
46 |
47 | #include "qtiocompressor.h"
48 | #include "zlib.h"
49 | #include
50 |
51 | typedef Bytef ZlibByte;
52 | typedef uInt ZlibSize;
53 |
54 | class QtIOCompressorPrivate {
55 | QtIOCompressor *q_ptr;
56 | Q_DECLARE_PUBLIC(QtIOCompressor)
57 | public:
58 | enum State {
59 | // Read state
60 | NotReadFirstByte,
61 | InStream,
62 | EndOfStream,
63 | // Write state
64 | NoBytesWritten,
65 | BytesWritten,
66 | // Common
67 | Closed,
68 | Error
69 | };
70 |
71 | QtIOCompressorPrivate(QtIOCompressor *q_ptr, QIODevice *device, int compressionLevel, int bufferSize);
72 | ~QtIOCompressorPrivate();
73 | void flushZlib(int flushMode);
74 | bool writeBytes(ZlibByte *buffer, ZlibSize outputSize);
75 | void setZlibError(const QString &erroMessage, int zlibErrorCode);
76 |
77 | QIODevice *device;
78 | bool manageDevice;
79 | z_stream zlibStream;
80 | const int compressionLevel;
81 | const ZlibSize bufferSize;
82 | ZlibByte *buffer;
83 | State state;
84 | QtIOCompressor::StreamFormat streamFormat;
85 | };
86 |
87 | /*!
88 | \internal
89 | */
90 | QtIOCompressorPrivate::QtIOCompressorPrivate(QtIOCompressor *q_ptr, QIODevice *device, int compressionLevel, int bufferSize)
91 | :q_ptr(q_ptr)
92 | ,device(device)
93 | ,compressionLevel(compressionLevel)
94 | ,bufferSize(bufferSize)
95 | ,buffer(new ZlibByte[bufferSize])
96 | ,state(Closed)
97 | ,streamFormat(QtIOCompressor::ZlibFormat)
98 | {
99 | // Use default zlib memory management.
100 | zlibStream.zalloc = Z_NULL;
101 | zlibStream.zfree = Z_NULL;
102 | zlibStream.opaque = Z_NULL;
103 | }
104 |
105 | /*!
106 | \internal
107 | */
108 | QtIOCompressorPrivate::~QtIOCompressorPrivate()
109 | {
110 | delete[] buffer;
111 | }
112 |
113 | /*!
114 | \internal
115 | Flushes the zlib stream.
116 | */
117 | void QtIOCompressorPrivate::flushZlib(int flushMode)
118 | {
119 | // No input.
120 | zlibStream.next_in = 0;
121 | zlibStream.avail_in = 0;
122 | int status;
123 | do {
124 | zlibStream.next_out = buffer;
125 | zlibStream.avail_out = bufferSize;
126 | status = deflate(&zlibStream, flushMode);
127 | if (status != Z_OK && status != Z_STREAM_END) {
128 | state = QtIOCompressorPrivate::Error;
129 | setZlibError(QT_TRANSLATE_NOOP("QtIOCompressor", "Internal zlib error when compressing: "), status);
130 | return;
131 | }
132 |
133 | ZlibSize outputSize = bufferSize - zlibStream.avail_out;
134 |
135 | // Try to write data from the buffer to to the underlying device, return on failure.
136 | if (!writeBytes(buffer, outputSize))
137 | return;
138 |
139 | // If the mode is Z_FNISH we must loop until we get Z_STREAM_END,
140 | // else we loop as long as zlib is able to fill the output buffer.
141 | } while ((flushMode == Z_FINISH && status != Z_STREAM_END) || (flushMode != Z_FINISH && zlibStream.avail_out == 0));
142 |
143 | if (flushMode == Z_FINISH)
144 | Q_ASSERT(status == Z_STREAM_END);
145 | else
146 | Q_ASSERT(status == Z_OK);
147 | }
148 |
149 | /*!
150 | \internal
151 | Writes outputSize bytes from buffer to the inderlying device.
152 | */
153 | bool QtIOCompressorPrivate::writeBytes(ZlibByte *buffer, ZlibSize outputSize)
154 | {
155 | Q_Q(QtIOCompressor);
156 | ZlibSize totalBytesWritten = 0;
157 | // Loop until all bytes are written to the underlying device.
158 | do {
159 | const qint64 bytesWritten = device->write(reinterpret_cast(buffer), outputSize);
160 | if (bytesWritten == -1) {
161 | q->setErrorString(QT_TRANSLATE_NOOP("QtIOCompressor", "Error writing to underlying device: ") + device->errorString());
162 | return false;
163 | }
164 | totalBytesWritten += bytesWritten;
165 | } while (totalBytesWritten != outputSize);
166 |
167 | // put up a flag so that the device will be flushed on close.
168 | state = BytesWritten;
169 | return true;
170 | }
171 |
172 | /*!
173 | \internal
174 | Sets the error string to errorMessage + zlib error string for zlibErrorCode
175 | */
176 | void QtIOCompressorPrivate::setZlibError(const QString &errorMessage, int zlibErrorCode)
177 | {
178 | Q_Q(QtIOCompressor);
179 | // Watch out, zlibErrorString may be null.
180 | const char * const zlibErrorString = zError(zlibErrorCode);
181 | QString errorString;
182 | if (zlibErrorString)
183 | errorString = errorMessage + zlibErrorString;
184 | else
185 | errorString = errorMessage + " Unknown error, code " + QString::number(zlibErrorCode);
186 |
187 | q->setErrorString(errorString);
188 | }
189 |
190 | /*! \class QtIOCompressor
191 | \brief The QtIOCompressor class is a QIODevice that compresses data streams.
192 |
193 | A QtIOCompressor object is constructed with a pointer to an
194 | underlying QIODevice. Data written to the QtIOCompressor object
195 | will be compressed before it is written to the underlying
196 | QIODevice. Similary, if you read from the QtIOCompressor object,
197 | the data will be read from the underlying device and then
198 | decompressed.
199 |
200 | QtIOCompressor is a sequential device, which means that it does
201 | not support seeks or random access. Internally, QtIOCompressor
202 | uses the zlib library to compress and uncompress data.
203 |
204 | Usage examples:
205 | Writing compressed data to a file:
206 | \code
207 | QFile file("foo");
208 | QtIOCompressor compressor(&file);
209 | compressor.open(QIODevice::WriteOnly);
210 | compressor.write(QByteArray() << "The quick brown fox");
211 | compressor.close();
212 | \endcode
213 |
214 | Reading compressed data from a file:
215 | \code
216 | QFile file("foo");
217 | QtIOCompressor compressor(&file);
218 | compressor.open(QIODevice::ReadOnly);
219 | const QByteArray text = compressor.readAll();
220 | compressor.close();
221 | \endcode
222 |
223 | QtIOCompressor can also read and write compressed data in
224 | different compressed formats, ref. StreamFormat. Use
225 | setStreamFormat() before open() to select format.
226 | */
227 |
228 | /*!
229 | \enum QtIOCompressor::StreamFormat
230 | This enum specifies which stream format to use.
231 |
232 | \value ZlibFormat: This is the default and has the smallest overhead.
233 |
234 | \value GzipFormat: This format is compatible with the gzip file
235 | format, but has more overhead than ZlibFormat. Note: requires zlib
236 | version 1.2.x or higher at runtime.
237 |
238 | \value RawZipFormat: This is compatible with the most common
239 | compression method of the data blocks contained in ZIP
240 | archives. Note: ZIP file headers are not read or generated, so
241 | setting this format, by itself, does not let QtIOCompressor read
242 | or write ZIP files. Ref. the ziplist example program.
243 |
244 | \sa setStreamFormat()
245 | */
246 |
247 | /*!
248 | Constructs a QtIOCompressor using the given \a device as the underlying device.
249 |
250 | The allowed value range for \a compressionLevel is 0 to 9, where 0 means no compression
251 | and 9 means maximum compression. The default value is 6.
252 |
253 | \a bufferSize specifies the size of the internal buffer used when reading from and writing to the
254 | underlying device. The default value is 65KB. Using a larger value allows for faster compression and
255 | deompression at the expense of memory usage.
256 | */
257 | QtIOCompressor::QtIOCompressor(QIODevice *device, int compressionLevel, int bufferSize)
258 | :d_ptr(new QtIOCompressorPrivate(this, device, compressionLevel, bufferSize))
259 | {}
260 |
261 | /*!
262 | Destroys the QtIOCompressor, closing it if neccesary.
263 | */
264 | QtIOCompressor::~QtIOCompressor()
265 | {
266 | Q_D(QtIOCompressor);
267 | close();
268 | delete d;
269 | }
270 |
271 | /*!
272 | Sets the format on the compressed stream to \a format.
273 |
274 | \sa QtIOCompressor::StreamFormat
275 | */
276 | void QtIOCompressor::setStreamFormat(StreamFormat format)
277 | {
278 | Q_D(QtIOCompressor);
279 |
280 | // Print a waning if the compile-time version of zlib does not support gzip.
281 | if (format == GzipFormat && checkGzipSupport(ZLIB_VERSION) == false)
282 | qWarning("QtIOCompressor::setStreamFormat: zlib 1.2.x or higher is "
283 | "required to use the gzip format. Current version is: %s",
284 | ZLIB_VERSION);
285 |
286 | d->streamFormat = format;
287 | }
288 |
289 | /*!
290 | Returns the format set on the compressed stream.
291 | \sa QtIOCompressor::StreamFormat
292 | */
293 | QtIOCompressor::StreamFormat QtIOCompressor::streamFormat() const
294 | {
295 | Q_D(const QtIOCompressor);
296 | return d->streamFormat;
297 | }
298 |
299 | /*!
300 | Returns true if the zlib library in use supports the gzip format, false otherwise.
301 | */
302 | bool QtIOCompressor::isGzipSupported()
303 | {
304 | return checkGzipSupport(zlibVersion());
305 | }
306 |
307 | /*!
308 | \reimp
309 | */
310 | bool QtIOCompressor::isSequential() const
311 | {
312 | return true;
313 | }
314 |
315 | /*!
316 | Opens the QtIOCompressor in \a mode. Only ReadOnly and WriteOnly is supported.
317 | This functon will return false if you try to open in other modes.
318 |
319 | If the underlying device is not opened, this function will open it in a suitable mode. If this happens
320 | the device will also be closed when close() is called.
321 |
322 | If the underlying device is already opened, its openmode must be compatable with \a mode.
323 |
324 | Returns true on success, false on error.
325 |
326 | \sa close()
327 | */
328 | bool QtIOCompressor::open(OpenMode mode)
329 | {
330 | Q_D(QtIOCompressor);
331 | if (isOpen()) {
332 | qWarning("QtIOCompressor::open: device already open");
333 | return false;
334 | }
335 |
336 | // Check for correct mode: ReadOnly xor WriteOnly
337 | const bool read = (bool)(mode & ReadOnly);
338 | const bool write = (bool)(mode & WriteOnly);
339 | const bool both = (read && write);
340 | const bool neither = !(read || write);
341 | if (both || neither) {
342 | qWarning("QtIOCompressor::open: QtIOCompressor can only be opened in the ReadOnly or WriteOnly modes");
343 | return false;
344 | }
345 |
346 | // If the underlying device is open, check that is it opened in a compatible mode.
347 | if (d->device->isOpen()) {
348 | d->manageDevice = false;
349 | const OpenMode deviceMode = d->device->openMode();
350 | if (read && !(deviceMode & ReadOnly)) {
351 | qWarning("QtIOCompressor::open: underlying device must be open in one of the ReadOnly or WriteOnly modes");
352 | return false;
353 | } else if (write && !(deviceMode & WriteOnly)) {
354 | qWarning("QtIOCompressor::open: underlying device must be open in one of the ReadOnly or WriteOnly modes");
355 | return false;
356 | }
357 |
358 | // If the underlying device is closed, open it.
359 | } else {
360 | d->manageDevice = true;
361 | if (d->device->open(mode) == false) {
362 | setErrorString(QT_TRANSLATE_NOOP("QtIOCompressor", "Error opening underlying device: ") + d->device->errorString());
363 | return false;
364 | }
365 | }
366 |
367 | // Initialize zlib for deflating or inflating.
368 |
369 | // The second argument to inflate/deflateInit2 is the windowBits parameter,
370 | // which also controls what kind of compression stream headers to use.
371 | // The default value for this is 15. Passing a value greater than 15
372 | // enables gzip headers and then subtracts 16 form the windowBits value.
373 | // (So passing 31 gives gzip headers and 15 windowBits). Passing a negative
374 | // value selects no headers hand then negates the windowBits argument.
375 | int windowBits;
376 | switch (d->streamFormat) {
377 | case QtIOCompressor::GzipFormat:
378 | windowBits = 31;
379 | break;
380 | case QtIOCompressor::RawZipFormat:
381 | windowBits = -15;
382 | break;
383 | default:
384 | windowBits = 15;
385 | }
386 |
387 | int status;
388 | if (read) {
389 | d->state = QtIOCompressorPrivate::NotReadFirstByte;
390 | d->zlibStream.avail_in = 0;
391 | d->zlibStream.next_in = 0;
392 | if (d->streamFormat == QtIOCompressor::ZlibFormat) {
393 | status = inflateInit(&d->zlibStream);
394 | } else {
395 | if (checkGzipSupport(zlibVersion()) == false) {
396 | setErrorString(QT_TRANSLATE_NOOP("QtIOCompressor::open", "The gzip format not supported in this version of zlib."));
397 | return false;
398 | }
399 |
400 | status = inflateInit2(&d->zlibStream, windowBits);
401 | }
402 | } else {
403 | d->state = QtIOCompressorPrivate::NoBytesWritten;
404 | if (d->streamFormat == QtIOCompressor::ZlibFormat)
405 | status = deflateInit(&d->zlibStream, d->compressionLevel);
406 | else
407 | status = deflateInit2(&d->zlibStream, d->compressionLevel, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY);
408 | }
409 |
410 | // Handle error.
411 | if (status != Z_OK) {
412 | d->setZlibError(QT_TRANSLATE_NOOP("QtIOCompressor::open", "Internal zlib error: "), status);
413 | return false;
414 | }
415 | return QIODevice::open(mode);
416 | }
417 |
418 | /*!
419 | Closes the QtIOCompressor, and also the underlying device if it was opened by QtIOCompressor.
420 | \sa open()
421 | */
422 | void QtIOCompressor::close()
423 | {
424 | Q_D(QtIOCompressor);
425 | if (isOpen() == false)
426 | return;
427 |
428 | // Flush and close the zlib stream.
429 | if (openMode() & ReadOnly) {
430 | d->state = QtIOCompressorPrivate::NotReadFirstByte;
431 | inflateEnd(&d->zlibStream);
432 | } else {
433 | if (d->state == QtIOCompressorPrivate::BytesWritten) { // Only flush if we have written anything.
434 | d->state = QtIOCompressorPrivate::NoBytesWritten;
435 | d->flushZlib(Z_FINISH);
436 | }
437 | deflateEnd(&d->zlibStream);
438 | }
439 |
440 | // Close the underlying device if we are managing it.
441 | if (d->manageDevice)
442 | d->device->close();
443 |
444 | QIODevice::close();
445 | }
446 |
447 | /*!
448 | Flushes the internal buffer.
449 |
450 | Each time you call flush, all data written to the QtIOCompressor is compressed and written to the
451 | underlying device. Calling this function can reduce the compression ratio. The underlying device
452 | is not flushed.
453 |
454 | Calling this function when QtIOCompressor is in ReadOnly mode has no effect.
455 | */
456 | void QtIOCompressor::flush()
457 | {
458 | Q_D(QtIOCompressor);
459 | if (isOpen() == false || openMode() & ReadOnly)
460 | return;
461 |
462 | d->flushZlib(Z_SYNC_FLUSH);
463 | }
464 |
465 | /*!
466 | Returns 1 if there might be data available for reading, or 0 if there is no data available.
467 |
468 | There is unfortunately no way of knowing how much data there is available when dealing with compressed streams.
469 |
470 | Also, since the remaining compressed data might be a part of the meta-data that ends the compressed stream (and
471 | therefore will yield no uncompressed data), you cannot assume that a read after getting a 1 from this function will return data.
472 | */
473 | qint64 QtIOCompressor::bytesAvailable() const
474 | {
475 | Q_D(const QtIOCompressor);
476 | if ((openMode() & ReadOnly) == false)
477 | return 0;
478 |
479 | int numBytes = 0;
480 |
481 | switch (d->state) {
482 | case QtIOCompressorPrivate::NotReadFirstByte:
483 | numBytes = d->device->bytesAvailable();
484 | break;
485 | case QtIOCompressorPrivate::InStream:
486 | numBytes = 1;
487 | break;
488 | case QtIOCompressorPrivate::EndOfStream:
489 | case QtIOCompressorPrivate::Error:
490 | default:
491 | numBytes = 0;
492 | break;
493 | };
494 |
495 | numBytes += QIODevice::bytesAvailable();
496 |
497 | if (numBytes > 0)
498 | return 1;
499 | else
500 | return 0;
501 | }
502 |
503 | /*!
504 | \internal
505 | Reads and decompresses data from the underlying device.
506 | */
507 | qint64 QtIOCompressor::readData(char *data, qint64 maxSize)
508 | {
509 | Q_D(QtIOCompressor);
510 |
511 | if (d->state == QtIOCompressorPrivate::EndOfStream)
512 | return 0;
513 |
514 | if (d->state == QtIOCompressorPrivate::Error)
515 | return -1;
516 |
517 | // We are ging to try to fill the data buffer
518 | d->zlibStream.next_out = reinterpret_cast(data);
519 | d->zlibStream.avail_out = maxSize;
520 |
521 | int status;
522 | do {
523 | // Read data if if the input buffer is empty. There could be data in the buffer
524 | // from a previous readData call.
525 | if (d->zlibStream.avail_in == 0) {
526 | qint64 bytesAvalible = d->device->read(reinterpret_cast(d->buffer), d->bufferSize);
527 | d->zlibStream.next_in = d->buffer;
528 | d->zlibStream.avail_in = bytesAvalible;
529 |
530 | if (bytesAvalible == -1) {
531 | d->state = QtIOCompressorPrivate::Error;
532 | setErrorString(QT_TRANSLATE_NOOP("QtIOCompressor", "Error reading data from underlying device: ") + d->device->errorString());
533 | return -1;
534 | }
535 |
536 | if (d->state != QtIOCompressorPrivate::InStream) {
537 | // If we are not in a stream and get 0 bytes, we are probably trying to read from an empty device.
538 | if(bytesAvalible == 0)
539 | return 0;
540 | else if (bytesAvalible > 0)
541 | d->state = QtIOCompressorPrivate::InStream;
542 | }
543 | }
544 |
545 | // Decompress.
546 | status = inflate(&d->zlibStream, Z_SYNC_FLUSH);
547 | switch (status) {
548 | case Z_NEED_DICT:
549 | case Z_DATA_ERROR:
550 | case Z_MEM_ERROR:
551 | d->state = QtIOCompressorPrivate::Error;
552 | d->setZlibError(QT_TRANSLATE_NOOP("QtIOCompressor", "Internal zlib error when decompressing: "), status);
553 | return -1;
554 | case Z_BUF_ERROR: // No more input and zlib can not privide more output - Not an error, we can try to read again when we have more input.
555 | return 0;
556 | break;
557 | }
558 | // Loop util data buffer is full or we reach the end of the input stream.
559 | } while (d->zlibStream.avail_out != 0 && status != Z_STREAM_END);
560 |
561 | if (status == Z_STREAM_END) {
562 | d->state = QtIOCompressorPrivate::EndOfStream;
563 |
564 | // Unget any data left in the read buffer.
565 | for (int i = d->zlibStream.avail_in; i >= 0; --i)
566 | d->device->ungetChar(*reinterpret_cast(d->zlibStream.next_in + i));
567 | }
568 |
569 | const ZlibSize outputSize = maxSize - d->zlibStream.avail_out;
570 | return outputSize;
571 | }
572 |
573 |
574 | /*!
575 | \internal
576 | Compresses and writes data to the underlying device.
577 | */
578 | qint64 QtIOCompressor::writeData(const char *data, qint64 maxSize)
579 | {
580 | if (maxSize < 1)
581 | return 0;
582 | Q_D(QtIOCompressor);
583 | d->zlibStream.next_in = reinterpret_cast(const_cast(data));
584 | d->zlibStream.avail_in = maxSize;
585 |
586 | if (d->state == QtIOCompressorPrivate::Error)
587 | return -1;
588 |
589 | do {
590 | d->zlibStream.next_out = d->buffer;
591 | d->zlibStream.avail_out = d->bufferSize;
592 | const int status = deflate(&d->zlibStream, Z_NO_FLUSH);
593 | if (status != Z_OK) {
594 | d->state = QtIOCompressorPrivate::Error;
595 | d->setZlibError(QT_TRANSLATE_NOOP("QtIOCompressor", "Internal zlib error when compressing: "), status);
596 | return -1;
597 | }
598 |
599 | ZlibSize outputSize = d->bufferSize - d->zlibStream.avail_out;
600 |
601 | // Try to write data from the buffer to to the underlying device, return -1 on failure.
602 | if (d->writeBytes(d->buffer, outputSize) == false)
603 | return -1;
604 |
605 | } while (d->zlibStream.avail_out == 0); // run until output is not full.
606 | Q_ASSERT(d->zlibStream.avail_in == 0);
607 |
608 | return maxSize;
609 | }
610 |
611 | /*
612 | \internal
613 | Checks if the run-time zlib version is 1.2.x or higher.
614 | */
615 | bool QtIOCompressor::checkGzipSupport(const char * const versionString)
616 | {
617 | if (strlen(versionString) < 3)
618 | return false;
619 |
620 | if (versionString[0] == '0' || (versionString[0] == '1' && (versionString[2] == '0' || versionString[2] == '1' )))
621 | return false;
622 |
623 | return true;
624 | }
625 |
--------------------------------------------------------------------------------
/src/qt/qtiocompressor.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of a Qt Solutions component.
8 | **
9 | ** Commercial Usage
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
11 | ** accordance with the Qt Solutions Commercial License Agreement provided
12 | ** with the Software or, alternatively, in accordance with the terms
13 | ** contained in a written agreement between you and Nokia.
14 | **
15 | ** GNU Lesser General Public License Usage
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
17 | ** General Public License version 2.1 as published by the Free Software
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
19 | ** packaging of this file. Please review the following information to
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 | **
23 | ** In addition, as a special exception, Nokia gives you certain
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
25 | ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
26 | ** package.
27 | **
28 | ** GNU General Public License Usage
29 | ** Alternatively, this file may be used under the terms of the GNU
30 | ** General Public License version 3.0 as published by the Free Software
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
32 | ** packaging of this file. Please review the following information to
33 | ** ensure the GNU General Public License version 3.0 requirements will be
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
35 | **
36 | ** Please note Third Party Software included with Qt Solutions may impose
37 | ** additional restrictions and it is the user's responsibility to ensure
38 | ** that they have met the licensing requirements of the GPL, LGPL, or Qt
39 | ** Solutions Commercial license and the relevant license of the Third
40 | ** Party Software they are using.
41 | **
42 | ** If you are unsure which license is appropriate for your use, please
43 | ** contact Nokia at qt-info@nokia.com.
44 | **
45 | ****************************************************************************/
46 |
47 | #ifndef QTIOCOMPRESSOR_H
48 | #define QTIOCOMPRESSOR_H
49 |
50 | #include
51 |
52 | #if defined(Q_WS_WIN)
53 | # if !defined(QT_QTIOCOMPRESSOR_EXPORT) && !defined(QT_QTIOCOMPRESSOR_IMPORT)
54 | # define QT_QTIOCOMPRESSOR_EXPORT
55 | # elif defined(QT_QTIOCOMPRESSOR_IMPORT)
56 | # if defined(QT_QTIOCOMPRESSOR_EXPORT)
57 | # undef QT_QTIOCOMPRESSOR_EXPORT
58 | # endif
59 | # define QT_QTIOCOMPRESSOR_EXPORT __declspec(dllimport)
60 | # elif defined(QT_QTIOCOMPRESSOR_EXPORT)
61 | # undef QT_QTIOCOMPRESSOR_EXPORT
62 | # define QT_QTIOCOMPRESSOR_EXPORT __declspec(dllexport)
63 | # endif
64 | #else
65 | # define QT_QTIOCOMPRESSOR_EXPORT
66 | #endif
67 |
68 | class QtIOCompressorPrivate;
69 | class QT_QTIOCOMPRESSOR_EXPORT QtIOCompressor : public QIODevice
70 | {
71 | Q_OBJECT
72 | public:
73 | enum StreamFormat { ZlibFormat, GzipFormat, RawZipFormat };
74 | QtIOCompressor(QIODevice *device, int compressionLevel = 6, int bufferSize = 65500);
75 | ~QtIOCompressor();
76 | void setStreamFormat(StreamFormat format);
77 | StreamFormat streamFormat() const;
78 | static bool isGzipSupported();
79 | bool isSequential() const;
80 | bool open(OpenMode mode);
81 | void close();
82 | void flush();
83 | qint64 bytesAvailable() const;
84 | protected:
85 | qint64 readData(char * data, qint64 maxSize);
86 | qint64 writeData(const char * data, qint64 maxSize);
87 | private:
88 | static bool checkGzipSupport(const char * const versionString);
89 | QtIOCompressorPrivate *d_ptr;
90 | Q_DECLARE_PRIVATE(QtIOCompressor)
91 | Q_DISABLE_COPY(QtIOCompressor)
92 | };
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------