cosmos 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +48 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/Guardfile +27 -0
- data/LICENSE.txt +879 -0
- data/Manifest.txt +1112 -0
- data/README.md +42 -0
- data/Rakefile +214 -0
- data/autohotkey/config/data/attitude.bin +0 -0
- data/autohotkey/config/data/diamond.STL +58 -0
- data/autohotkey/config/data/groundoff.gif +0 -0
- data/autohotkey/config/data/groundon.gif +0 -0
- data/autohotkey/config/data/position.bin +0 -0
- data/autohotkey/config/data/satellite.gif +0 -0
- data/autohotkey/config/data/tada.wav +0 -0
- data/autohotkey/config/system/system.txt +34 -0
- data/autohotkey/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt +41 -0
- data/autohotkey/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +15 -0
- data/autohotkey/config/targets/COSMOS/cmd_tlm_server.txt +6 -0
- data/autohotkey/config/targets/COSMOS/target.txt +5 -0
- data/autohotkey/config/targets/INST/cmd_tlm/inst_cmds.txt +121 -0
- data/autohotkey/config/targets/INST/cmd_tlm/inst_tlm.txt +247 -0
- data/autohotkey/config/targets/INST/cmd_tlm_server.txt +5 -0
- data/autohotkey/config/targets/INST/doc/README.txt +1 -0
- data/autohotkey/config/targets/INST/lib/example_limits_response.rb +30 -0
- data/autohotkey/config/targets/INST/lib/sim_inst.rb +294 -0
- data/autohotkey/config/targets/INST/screens/adcs.txt +46 -0
- data/autohotkey/config/targets/INST/screens/array.txt +7 -0
- data/autohotkey/config/targets/INST/screens/block.txt +8 -0
- data/autohotkey/config/targets/INST/screens/commanding.txt +30 -0
- data/autohotkey/config/targets/INST/screens/graphs.txt +14 -0
- data/autohotkey/config/targets/INST/screens/ground.txt +25 -0
- data/autohotkey/config/targets/INST/screens/health_status.txt +33 -0
- data/autohotkey/config/targets/INST/screens/hs.txt +49 -0
- data/autohotkey/config/targets/INST/screens/image.txt +21 -0
- data/autohotkey/config/targets/INST/screens/latest.txt +23 -0
- data/autohotkey/config/targets/INST/screens/mech.txt +25 -0
- data/autohotkey/config/targets/INST/screens/other.txt +25 -0
- data/autohotkey/config/targets/INST/screens/params.txt +25 -0
- data/autohotkey/config/targets/INST/screens/tabs.txt +68 -0
- data/autohotkey/config/targets/INST/target.txt +27 -0
- data/autohotkey/config/targets/META/cmd_tlm/meta_cmd.txt +10 -0
- data/autohotkey/config/targets/META/cmd_tlm/meta_tlm.txt +9 -0
- data/autohotkey/config/targets/SYSTEM/cmd_tlm/limits_groups.txt +7 -0
- data/autohotkey/config/targets/SYSTEM/screens/error.txt +11 -0
- data/autohotkey/config/tools/cmd_sender/cmd_sender.txt +1 -0
- data/autohotkey/config/tools/cmd_tlm_server/cmd_tlm_server.txt +22 -0
- data/autohotkey/config/tools/data_viewer/data_viewer.txt +11 -0
- data/autohotkey/config/tools/handbook_creator/default_toc.xsl +59 -0
- data/autohotkey/config/tools/handbook_creator/handbook_creator.txt +49 -0
- data/autohotkey/config/tools/handbook_creator/templates/command_packets.html.erb +86 -0
- data/autohotkey/config/tools/handbook_creator/templates/command_toc.html.erb +38 -0
- data/autohotkey/config/tools/handbook_creator/templates/footer.html.erb +9 -0
- data/autohotkey/config/tools/handbook_creator/templates/header.html.erb +25 -0
- data/autohotkey/config/tools/handbook_creator/templates/limits_groups.html.erb +13 -0
- data/autohotkey/config/tools/handbook_creator/templates/nav.html.erb +27 -0
- data/autohotkey/config/tools/handbook_creator/templates/overview.html.erb +1 -0
- data/autohotkey/config/tools/handbook_creator/templates/pdf_cover.html.erb +23 -0
- data/autohotkey/config/tools/handbook_creator/templates/pdf_footer.html.erb +33 -0
- data/autohotkey/config/tools/handbook_creator/templates/pdf_header.html.erb +41 -0
- data/autohotkey/config/tools/handbook_creator/templates/telemetry_packets.html.erb +80 -0
- data/autohotkey/config/tools/handbook_creator/templates/telemetry_toc.html.erb +38 -0
- data/autohotkey/config/tools/handbook_creator/templates/title.html.erb +1 -0
- data/autohotkey/config/tools/launcher/launcher.txt +38 -0
- data/autohotkey/config/tools/limits_monitor/README.txt +1 -0
- data/autohotkey/config/tools/opengl_builder/error.txt +1 -0
- data/autohotkey/config/tools/script_runner/script_runner.txt +3 -0
- data/autohotkey/config/tools/table_manager/ConfigTables_def.txt +8 -0
- data/autohotkey/config/tools/table_manager/OneDimensionalTable_def.txt +19 -0
- data/autohotkey/config/tools/table_manager/TwoDimensionalTable_def.txt +248 -0
- data/autohotkey/config/tools/test_runner/test_runner.txt +8 -0
- data/autohotkey/config/tools/test_runner/test_runner2.txt +11 -0
- data/autohotkey/config/tools/test_runner/test_runner3.txt +7 -0
- data/autohotkey/config/tools/test_runner/test_runner4.txt +1 -0
- data/autohotkey/config/tools/tlm_extractor/tlm_extractor.txt +14 -0
- data/autohotkey/config/tools/tlm_extractor/tlm_extractor2.txt +9 -0
- data/autohotkey/config/tools/tlm_grapher/README.txt +1 -0
- data/autohotkey/config/tools/tlm_grapher/bad.txt +50 -0
- data/autohotkey/config/tools/tlm_grapher/temp1-4.txt +51 -0
- data/autohotkey/config/tools/tlm_grapher/test2.txt +111 -0
- data/autohotkey/config/tools/tlm_viewer/tlm_viewer.txt +24 -0
- data/autohotkey/config/tools/tlm_viewer/tlm_viewer2.txt +4 -0
- data/autohotkey/config/tools/tlm_viewer/tlm_viewer3.txt +3 -0
- data/autohotkey/lib/example_background_task.rb +42 -0
- data/autohotkey/lib/user_version.rb +3 -0
- data/autohotkey/outputs/handbooks/assets/css/bootstrap-theme.css +397 -0
- data/autohotkey/outputs/handbooks/assets/css/bootstrap-theme.min.css +7 -0
- data/autohotkey/outputs/handbooks/assets/css/bootstrap.css +7118 -0
- data/autohotkey/outputs/handbooks/assets/css/bootstrap.min.css +7 -0
- data/autohotkey/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/autohotkey/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/autohotkey/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/autohotkey/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/autohotkey/outputs/handbooks/assets/js/bootstrap.js +2006 -0
- data/autohotkey/outputs/handbooks/assets/js/bootstrap.min.js +7 -0
- data/autohotkey/outputs/logs/bigtlm.bin +0 -0
- data/autohotkey/outputs/logs/cmd.bin +0 -0
- data/autohotkey/outputs/logs/tlm.bin +0 -0
- data/autohotkey/outputs/saved_config/README.txt +1 -0
- data/autohotkey/outputs/tables/README.txt +1 -0
- data/autohotkey/outputs/tmp/README.txt +1 -0
- data/autohotkey/procedures/clear_util.rb +7 -0
- data/autohotkey/procedures/collect.rb +18 -0
- data/autohotkey/procedures/collect_util.rb +14 -0
- data/autohotkey/procedures/example_test.rb +67 -0
- data/autohotkey/procedures/example_test2.rb +74 -0
- data/autohotkey/procedures/script_test.rb +17 -0
- data/autohotkey/procedures/syntax_error.rb +18 -0
- data/autohotkey/tools/CmdExtractorAHK +16 -0
- data/autohotkey/tools/CmdSender +14 -0
- data/autohotkey/tools/CmdSenderAHK +18 -0
- data/autohotkey/tools/CmdTlmServer +14 -0
- data/autohotkey/tools/CmdTlmServerAHK +28 -0
- data/autohotkey/tools/CmdTlmServerAHK2 +17 -0
- data/autohotkey/tools/DataViewer +14 -0
- data/autohotkey/tools/DataViewerAHK +17 -0
- data/autohotkey/tools/HandbookCreatorAHK +20 -0
- data/autohotkey/tools/LauncherAHK +17 -0
- data/autohotkey/tools/LimitsMonitorAHK +20 -0
- data/autohotkey/tools/OpenGLBuilderAHK +20 -0
- data/autohotkey/tools/PacketViewer +14 -0
- data/autohotkey/tools/PacketViewerAHK +18 -0
- data/autohotkey/tools/PacketViewerAHK2 +17 -0
- data/autohotkey/tools/Replay +14 -0
- data/autohotkey/tools/Replay.bat +59 -0
- data/autohotkey/tools/ReplayAHK +17 -0
- data/autohotkey/tools/ScriptRunner +14 -0
- data/autohotkey/tools/ScriptRunnerAHK +20 -0
- data/autohotkey/tools/ScriptRunnerAHK2 +17 -0
- data/autohotkey/tools/TableManager +14 -0
- data/autohotkey/tools/TableManagerAHK +30 -0
- data/autohotkey/tools/TestRunner +15 -0
- data/autohotkey/tools/TestRunnerAHK +17 -0
- data/autohotkey/tools/TestRunnerAHK2 +17 -0
- data/autohotkey/tools/TestRunnerAHK3 +17 -0
- data/autohotkey/tools/TestRunnerAHK4 +17 -0
- data/autohotkey/tools/TlmExtractor +15 -0
- data/autohotkey/tools/TlmExtractorAHK +19 -0
- data/autohotkey/tools/TlmExtractorAHK2 +16 -0
- data/autohotkey/tools/TlmExtractorAHK3 +16 -0
- data/autohotkey/tools/TlmGrapher +14 -0
- data/autohotkey/tools/TlmGrapherAHK +19 -0
- data/autohotkey/tools/TlmGrapherAHK2 +23 -0
- data/autohotkey/tools/TlmGrapherAHK3 +17 -0
- data/autohotkey/tools/TlmGrapherAHK4 +17 -0
- data/autohotkey/tools/TlmViewer +14 -0
- data/autohotkey/tools/TlmViewerAHK +28 -0
- data/autohotkey/tools/TlmViewerAHK2 +18 -0
- data/autohotkey/tools/TlmViewerAHK3 +18 -0
- data/autohotkey/tools/TlmViewerAHK4 +18 -0
- data/autohotkey/tools/TlmViewerAHK5 +18 -0
- data/autohotkey/tools/autohotkey.rb +37 -0
- data/autohotkey/tools/cmd_extractor.ahk +27 -0
- data/autohotkey/tools/cmd_sender.ahk +162 -0
- data/autohotkey/tools/cmd_tlm_server.ahk +89 -0
- data/autohotkey/tools/cmd_tlm_server2.ahk +45 -0
- data/autohotkey/tools/data_viewer.ahk +135 -0
- data/autohotkey/tools/handbook_creator.ahk +23 -0
- data/autohotkey/tools/launcher.ahk +41 -0
- data/autohotkey/tools/limits_monitor.ahk +70 -0
- data/autohotkey/tools/open_gl_builder.ahk +134 -0
- data/autohotkey/tools/packet_viewer.ahk +143 -0
- data/autohotkey/tools/packet_viewer2.ahk +9 -0
- data/autohotkey/tools/replay.ahk +98 -0
- data/autohotkey/tools/script_runner.ahk +589 -0
- data/autohotkey/tools/script_runner2.ahk +31 -0
- data/autohotkey/tools/table_manager.ahk +220 -0
- data/autohotkey/tools/test_runner.ahk +259 -0
- data/autohotkey/tools/test_runner2.ahk +52 -0
- data/autohotkey/tools/test_runner3.ahk +13 -0
- data/autohotkey/tools/tlm_extractor.ahk +272 -0
- data/autohotkey/tools/tlm_grapher.ahk +642 -0
- data/autohotkey/tools/tlm_grapher2.ahk +115 -0
- data/autohotkey/tools/tlm_grapher3.ahk +24 -0
- data/autohotkey/tools/tlm_viewer.ahk +133 -0
- data/autohotkey/tools/tlm_viewer2.ahk +49 -0
- data/autohotkey/tools/tlm_viewer4.ahk +4 -0
- data/autohotkey/tools/tlm_viewer5.ahk +20 -0
- data/autohotkey/userpath.txt +1 -0
- data/bin/cosmos +96 -0
- data/bin/cstol_converter +1166 -0
- data/bin/exchndl20.dll +0 -0
- data/bin/exchndl21.dll +0 -0
- data/bin/mgwhelp.dll +0 -0
- data/bin/rubysloc +85 -0
- data/cosmos.gemspec +98 -0
- data/data/COSMOS_64x64.bmp +0 -0
- data/data/COSMOS_64x64.ico +0 -0
- data/data/COSMOS_64x64.png +0 -0
- data/data/CheckBoxCheck.gif +0 -0
- data/data/CheckBoxEmpty.gif +0 -0
- data/data/Earthmap1024x512.gif +0 -0
- data/data/about.txt +4 -0
- data/data/add_database.png +0 -0
- data/data/add_plot.png +0 -0
- data/data/add_tab.png +0 -0
- data/data/blank.png +0 -0
- data/data/bug.png +0 -0
- data/data/checkmark.png +0 -0
- data/data/close.png +0 -0
- data/data/cmd_extractor.png +0 -0
- data/data/cmd_sender.png +0 -0
- data/data/copy.png +0 -0
- data/data/cosmos.xcf +0 -0
- data/data/cosmos_word.gif +0 -0
- data/data/crc.txt +305 -0
- data/data/cts.png +0 -0
- data/data/cut.png +0 -0
- data/data/data_viewer.png +0 -0
- data/data/delete_database.png +0 -0
- data/data/delete_plot.png +0 -0
- data/data/delete_tab.png +0 -0
- data/data/diamond.STL +58 -0
- data/data/disconnected.png +0 -0
- data/data/edit.png +0 -0
- data/data/edit_database.png +0 -0
- data/data/edit_plot.png +0 -0
- data/data/edit_tab.png +0 -0
- data/data/end-26.png +0 -0
- data/data/fast_forward-26.png +0 -0
- data/data/file.png +0 -0
- data/data/handbook_creator.png +0 -0
- data/data/help.png +0 -0
- data/data/html-32.png +0 -0
- data/data/launcher.png +0 -0
- data/data/legal.gif +0 -0
- data/data/legal.txt +9 -0
- data/data/limits_monitor.png +0 -0
- data/data/moonmap1k.gif +0 -0
- data/data/multi.png +0 -0
- data/data/open.png +0 -0
- data/data/open_in_browser-32.png +0 -0
- data/data/opengl_builder.png +0 -0
- data/data/packet_viewer.png +0 -0
- data/data/pdf-32.png +0 -0
- data/data/play-26.png +0 -0
- data/data/redo.png +0 -0
- data/data/replay.png +0 -0
- data/data/reverse-play-26.png +0 -0
- data/data/rewind-26.png +0 -0
- data/data/running.png +0 -0
- data/data/save.png +0 -0
- data/data/save_as.png +0 -0
- data/data/screenshot.png +0 -0
- data/data/script_runner.png +0 -0
- data/data/search-14.png +0 -0
- data/data/search.png +0 -0
- data/data/send_file.png +0 -0
- data/data/skip_to_start-26.png +0 -0
- data/data/spinner.gif +0 -0
- data/data/splash.gif +0 -0
- data/data/stop-26.png +0 -0
- data/data/table_manager.png +0 -0
- data/data/test_runner.png +0 -0
- data/data/tlm_extractor.png +0 -0
- data/data/tlm_grapher.png +0 -0
- data/data/tlm_viewer.png +0 -0
- data/data/undo.png +0 -0
- data/demo/Gemfile +5 -0
- data/demo/Launcher +15 -0
- data/demo/Launcher.bat +59 -0
- data/demo/Rakefile +61 -0
- data/demo/config/data/attitude.bin +0 -0
- data/demo/config/data/crc.txt +206 -0
- data/demo/config/data/diamond.STL +58 -0
- data/demo/config/data/groundoff.gif +0 -0
- data/demo/config/data/groundon.gif +0 -0
- data/demo/config/data/hselectoff.gif +0 -0
- data/demo/config/data/hselecton.gif +0 -0
- data/demo/config/data/hswitchoff.gif +0 -0
- data/demo/config/data/hswitchon.gif +0 -0
- data/demo/config/data/meta_init.txt +4 -0
- data/demo/config/data/position.bin +0 -0
- data/demo/config/data/poweroff.gif +0 -0
- data/demo/config/data/poweron.gif +0 -0
- data/demo/config/data/satellite.gif +0 -0
- data/demo/config/data/tada.wav +0 -0
- data/demo/config/data/vswitchoff.gif +0 -0
- data/demo/config/data/vswitchon.gif +0 -0
- data/demo/config/system/system.txt +34 -0
- data/demo/config/system/system2.txt +33 -0
- data/demo/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt +41 -0
- data/demo/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +15 -0
- data/demo/config/targets/COSMOS/cmd_tlm_server.txt +6 -0
- data/demo/config/targets/COSMOS/screens/limits_change.txt +20 -0
- data/demo/config/targets/COSMOS/screens/version.txt +19 -0
- data/demo/config/targets/COSMOS/target.txt +11 -0
- data/demo/config/targets/EXAMPLE/cmd_tlm/example_cmds.txt +2 -0
- data/demo/config/targets/EXAMPLE/cmd_tlm/example_tlm.txt +3 -0
- data/demo/config/targets/EXAMPLE/cmd_tlm_server.txt +6 -0
- data/demo/config/targets/EXAMPLE/lib/example_interface.rb +22 -0
- data/demo/config/targets/EXAMPLE/target.txt +7 -0
- data/demo/config/targets/INST/cmd_tlm/inst_cmds.txt +121 -0
- data/demo/config/targets/INST/cmd_tlm/inst_tlm.txt +247 -0
- data/demo/config/targets/INST/cmd_tlm_server.txt +5 -0
- data/demo/config/targets/INST/doc/README.txt +1 -0
- data/demo/config/targets/INST/lib/example_limits_response.rb +30 -0
- data/demo/config/targets/INST/lib/sim_inst.rb +294 -0
- data/demo/config/targets/INST/screens/adcs.txt +46 -0
- data/demo/config/targets/INST/screens/array.txt +15 -0
- data/demo/config/targets/INST/screens/block.txt +8 -0
- data/demo/config/targets/INST/screens/commanding.txt +30 -0
- data/demo/config/targets/INST/screens/graphs.txt +14 -0
- data/demo/config/targets/INST/screens/ground.txt +25 -0
- data/demo/config/targets/INST/screens/hs.txt +44 -0
- data/demo/config/targets/INST/screens/latest.txt +23 -0
- data/demo/config/targets/INST/screens/other.txt +29 -0
- data/demo/config/targets/INST/screens/tabs.txt +70 -0
- data/demo/config/targets/INST/target.txt +33 -0
- data/demo/config/targets/META/cmd_tlm/meta_cmd.txt +10 -0
- data/demo/config/targets/META/cmd_tlm/meta_tlm.txt +13 -0
- data/demo/config/targets/SYSTEM/cmd_tlm/limits_groups.txt +7 -0
- data/demo/config/targets/SYSTEM/cmd_tlm/override.txt +29 -0
- data/demo/config/targets/SYSTEM/screens/status.txt +12 -0
- data/demo/config/targets/TEMPLATED/cmd_tlm/templated_cmds.txt +12 -0
- data/demo/config/targets/TEMPLATED/cmd_tlm/templated_tlm.txt +3 -0
- data/demo/config/targets/TEMPLATED/cmd_tlm_server.txt +6 -0
- data/demo/config/targets/TEMPLATED/lib/templated_interface.rb +48 -0
- data/demo/config/targets/TEMPLATED/target.txt +6 -0
- data/demo/config/tools/cmd_tlm_server/cmd_tlm_server.txt +33 -0
- data/demo/config/tools/cmd_tlm_server/cmd_tlm_server2.txt +29 -0
- data/demo/config/tools/data_viewer/data_viewer.txt +11 -0
- data/demo/config/tools/handbook_creator/default_toc.xsl +59 -0
- data/demo/config/tools/handbook_creator/handbook_creator.txt +66 -0
- data/demo/config/tools/handbook_creator/templates/command_packets.html.erb +86 -0
- data/demo/config/tools/handbook_creator/templates/command_toc.html.erb +38 -0
- data/demo/config/tools/handbook_creator/templates/footer.html.erb +9 -0
- data/demo/config/tools/handbook_creator/templates/header.html.erb +25 -0
- data/demo/config/tools/handbook_creator/templates/limits_groups.html.erb +13 -0
- data/demo/config/tools/handbook_creator/templates/nav.html.erb +27 -0
- data/demo/config/tools/handbook_creator/templates/overview.html.erb +1 -0
- data/demo/config/tools/handbook_creator/templates/pdf_cover.html.erb +23 -0
- data/demo/config/tools/handbook_creator/templates/pdf_footer.html.erb +33 -0
- data/demo/config/tools/handbook_creator/templates/pdf_header.html.erb +41 -0
- data/demo/config/tools/handbook_creator/templates/telemetry_packets.html.erb +80 -0
- data/demo/config/tools/handbook_creator/templates/telemetry_toc.html.erb +38 -0
- data/demo/config/tools/handbook_creator/templates/title.html.erb +1 -0
- data/demo/config/tools/launcher/launcher.txt +45 -0
- data/demo/config/tools/launcher/launcher2.txt +45 -0
- data/demo/config/tools/limits_monitor/README.txt +1 -0
- data/demo/config/tools/opengl_builder/README.txt +1 -0
- data/demo/config/tools/script_runner/script_runner.txt +3 -0
- data/demo/config/tools/table_manager/ConfigTables_def.txt +8 -0
- data/demo/config/tools/table_manager/ExampleTableDefinition.txt +24 -0
- data/demo/config/tools/table_manager/MCConfigurationTable_fsw1_def.txt +25 -0
- data/demo/config/tools/table_manager/MCConfigurationTable_fsw2_def.txt +25 -0
- data/demo/config/tools/table_manager/PPSSelectionTable_def.txt +8 -0
- data/demo/config/tools/table_manager/TLMMonitoringTable_def.txt +248 -0
- data/demo/config/tools/test_runner/test_runner.txt +17 -0
- data/demo/config/tools/tlm_extractor/tlm_extractor.txt +13 -0
- data/demo/config/tools/tlm_extractor/tlm_extractor2.txt +2 -0
- data/demo/config/tools/tlm_extractor/tlm_extractor3.txt +2 -0
- data/demo/config/tools/tlm_extractor/tlm_extractor4.txt +2 -0
- data/demo/config/tools/tlm_grapher/README.txt +1 -0
- data/demo/config/tools/tlm_viewer/tlm_viewer.txt +41 -0
- data/demo/lib/example_background_task.rb +52 -0
- data/demo/lib/example_target.rb +108 -0
- data/demo/lib/scpi_target.rb +74 -0
- data/demo/lib/user_version.rb +3 -0
- data/demo/outputs/handbooks/assets/css/bootstrap-theme.css +397 -0
- data/demo/outputs/handbooks/assets/css/bootstrap-theme.min.css +7 -0
- data/demo/outputs/handbooks/assets/css/bootstrap.css +7118 -0
- data/demo/outputs/handbooks/assets/css/bootstrap.min.css +7 -0
- data/demo/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/demo/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/demo/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/demo/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/demo/outputs/handbooks/assets/img/ball_logo.bmp +0 -0
- data/demo/outputs/handbooks/assets/img/ball_logo.gif +0 -0
- data/demo/outputs/handbooks/assets/img/ball_logo.jpg +0 -0
- data/demo/outputs/handbooks/assets/js/bootstrap.js +2006 -0
- data/demo/outputs/handbooks/assets/js/bootstrap.min.js +7 -0
- data/demo/outputs/handbooks/assets/js/html5shiv.js +8 -0
- data/demo/outputs/handbooks/assets/js/jquery-1.10.2.min.js +6 -0
- data/demo/outputs/handbooks/assets/js/respond.min.js +6 -0
- data/demo/outputs/logs/README.txt +1 -0
- data/demo/outputs/saved_config/README.txt +1 -0
- data/demo/outputs/tables/README.txt +1 -0
- data/demo/outputs/tmp/README.txt +1 -0
- data/demo/procedures/checks.rb +11 -0
- data/demo/procedures/clear_util.rb +7 -0
- data/demo/procedures/collect.rb +18 -0
- data/demo/procedures/collect_util.rb +14 -0
- data/demo/procedures/cosmos_api_test.rb +293 -0
- data/demo/procedures/disconnect.rb +29 -0
- data/demo/procedures/example_test.rb +182 -0
- data/demo/procedures/plot_test.rb +8 -0
- data/demo/procedures/run_example_test.rb +3 -0
- data/demo/procedures/test.rb +51 -0
- data/demo/tools/CmdExtractor +15 -0
- data/demo/tools/CmdExtractor.bat +59 -0
- data/demo/tools/CmdSender +15 -0
- data/demo/tools/CmdSender.bat +59 -0
- data/demo/tools/CmdTlmServer +15 -0
- data/demo/tools/CmdTlmServer.bat +59 -0
- data/demo/tools/DataViewer +15 -0
- data/demo/tools/DataViewer.bat +59 -0
- data/demo/tools/ExampleTarget +15 -0
- data/demo/tools/ExampleTarget.bat +59 -0
- data/demo/tools/HandbookCreator +15 -0
- data/demo/tools/HandbookCreator.bat +61 -0
- data/demo/tools/Launcher +15 -0
- data/demo/tools/Launcher.bat +59 -0
- data/demo/tools/LimitsMonitor +15 -0
- data/demo/tools/LimitsMonitor.bat +59 -0
- data/demo/tools/OpenGLBuilder +15 -0
- data/demo/tools/OpenGLBuilder.bat +59 -0
- data/demo/tools/PacketViewer +15 -0
- data/demo/tools/PacketViewer.bat +59 -0
- data/demo/tools/Replay +15 -0
- data/demo/tools/Replay.bat +59 -0
- data/demo/tools/ScpiTarget +15 -0
- data/demo/tools/ScpiTarget.bat +59 -0
- data/demo/tools/ScriptRunner +15 -0
- data/demo/tools/ScriptRunner.bat +59 -0
- data/demo/tools/TableManager +15 -0
- data/demo/tools/TableManager.bat +59 -0
- data/demo/tools/TestRunner +15 -0
- data/demo/tools/TestRunner.bat +59 -0
- data/demo/tools/TlmExtractor +15 -0
- data/demo/tools/TlmExtractor.bat +59 -0
- data/demo/tools/TlmGrapher +15 -0
- data/demo/tools/TlmGrapher.bat +59 -0
- data/demo/tools/TlmViewer +15 -0
- data/demo/tools/TlmViewer.bat +59 -0
- data/demo/tools/mac/CmdExtractor.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/CmdExtractor.app/Contents/MacOS/CmdExtractor.rb +15 -0
- data/demo/tools/mac/CmdExtractor.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/CmdExtractor.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/CmdSender.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/CmdSender.app/Contents/MacOS/CmdSender.rb +15 -0
- data/demo/tools/mac/CmdSender.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/CmdSender.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/CmdTlmServer.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/CmdTlmServer.app/Contents/MacOS/CmdTlmServer.rb +15 -0
- data/demo/tools/mac/CmdTlmServer.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/CmdTlmServer.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/DataViewer.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/DataViewer.app/Contents/MacOS/DataViewer.rb +15 -0
- data/demo/tools/mac/DataViewer.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/DataViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/HandbookCreator.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/HandbookCreator.app/Contents/MacOS/HandbookCreator.rb +15 -0
- data/demo/tools/mac/HandbookCreator.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/HandbookCreator.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/Launcher.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/Launcher.app/Contents/MacOS/Launcher.rb +15 -0
- data/demo/tools/mac/Launcher.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/Launcher.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/LimitsMonitor.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/LimitsMonitor.app/Contents/MacOS/LimitsMonitor.rb +15 -0
- data/demo/tools/mac/LimitsMonitor.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/LimitsMonitor.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/OpenGLBuilder.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/OpenGLBuilder.app/Contents/MacOS/OpenGLBuilder.rb +15 -0
- data/demo/tools/mac/OpenGLBuilder.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/OpenGLBuilder.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/PacketViewer.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/PacketViewer.app/Contents/MacOS/PacketViewer.rb +15 -0
- data/demo/tools/mac/PacketViewer.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/PacketViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/Replay.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/Replay.app/Contents/MacOS/Replay.rb +15 -0
- data/demo/tools/mac/Replay.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/Replay.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/ScriptRunner.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/ScriptRunner.app/Contents/MacOS/ScriptRunner.rb +15 -0
- data/demo/tools/mac/ScriptRunner.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/ScriptRunner.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/TableManager.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/TableManager.app/Contents/MacOS/TableManager.rb +15 -0
- data/demo/tools/mac/TableManager.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/TableManager.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/TestRunner.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/TestRunner.app/Contents/MacOS/TestRunner.rb +15 -0
- data/demo/tools/mac/TestRunner.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/TestRunner.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/TlmExtractor.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/TlmExtractor.app/Contents/MacOS/TlmExtractor.rb +15 -0
- data/demo/tools/mac/TlmExtractor.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/TlmExtractor.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/TlmGrapher.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/TlmGrapher.app/Contents/MacOS/TlmGrapher.rb +15 -0
- data/demo/tools/mac/TlmGrapher.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/TlmGrapher.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/tools/mac/TlmViewer.app/Contents/Info.plist +38 -0
- data/demo/tools/mac/TlmViewer.app/Contents/MacOS/TlmViewer.rb +15 -0
- data/demo/tools/mac/TlmViewer.app/Contents/MacOS/main.sh +6 -0
- data/demo/tools/mac/TlmViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/demo/userpath.txt +1 -0
- data/ext/cosmos/ext/array/array.c +111 -0
- data/ext/cosmos/ext/array/extconf.rb +13 -0
- data/ext/cosmos/ext/buffered_file/buffered_file.c +167 -0
- data/ext/cosmos/ext/buffered_file/extconf.rb +13 -0
- data/ext/cosmos/ext/config_parser/config_parser.c +237 -0
- data/ext/cosmos/ext/config_parser/extconf.rb +13 -0
- data/ext/cosmos/ext/cosmos_io/cosmos_io.c +117 -0
- data/ext/cosmos/ext/cosmos_io/extconf.rb +13 -0
- data/ext/cosmos/ext/crc/crc.c +341 -0
- data/ext/cosmos/ext/crc/extconf.rb +13 -0
- data/ext/cosmos/ext/line_graph/extconf.rb +13 -0
- data/ext/cosmos/ext/line_graph/line_graph.c +501 -0
- data/ext/cosmos/ext/low_fragmentation_array/extconf.rb +13 -0
- data/ext/cosmos/ext/low_fragmentation_array/low_fragmentation_array.c +261 -0
- data/ext/cosmos/ext/packet/extconf.rb +13 -0
- data/ext/cosmos/ext/packet/packet.c +339 -0
- data/ext/cosmos/ext/platform/extconf.rb +13 -0
- data/ext/cosmos/ext/platform/platform.c +82 -0
- data/ext/cosmos/ext/polynomial_conversion/extconf.rb +13 -0
- data/ext/cosmos/ext/polynomial_conversion/polynomial_conversion.c +73 -0
- data/ext/cosmos/ext/string/extconf.rb +13 -0
- data/ext/cosmos/ext/string/string.c +49 -0
- data/ext/cosmos/ext/structure/structure.c +894 -0
- data/ext/cosmos/ext/tabbed_plots_config/extconf.rb +13 -0
- data/ext/cosmos/ext/tabbed_plots_config/tabbed_plots_config.c +51 -0
- data/ext/cosmos/ext/telemetry/extconf.rb +13 -0
- data/ext/cosmos/ext/telemetry/telemetry.c +306 -0
- data/install/Gemfile +5 -0
- data/install/Launcher +14 -0
- data/install/Launcher.bat +59 -0
- data/install/Rakefile +61 -0
- data/install/config/data/README.txt +1 -0
- data/install/config/data/crc.txt +133 -0
- data/install/config/system/system.txt +29 -0
- data/install/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt +41 -0
- data/install/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +15 -0
- data/install/config/targets/COSMOS/cmd_tlm_server.txt +6 -0
- data/install/config/targets/COSMOS/screens/limits_change.txt +20 -0
- data/install/config/targets/COSMOS/screens/version.txt +19 -0
- data/install/config/targets/COSMOS/target.txt +9 -0
- data/install/config/targets/SYSTEM/README.txt +1 -0
- data/install/config/tools/cmd_tlm_server/cmd_tlm_server.txt +2 -0
- data/install/config/tools/data_viewer/data_viewer.txt +4 -0
- data/install/config/tools/handbook_creator/default_toc.xsl +59 -0
- data/install/config/tools/handbook_creator/handbook_creator.txt +49 -0
- data/install/config/tools/handbook_creator/templates/command_packets.html.erb +86 -0
- data/install/config/tools/handbook_creator/templates/command_toc.html.erb +38 -0
- data/install/config/tools/handbook_creator/templates/footer.html.erb +9 -0
- data/install/config/tools/handbook_creator/templates/header.html.erb +25 -0
- data/install/config/tools/handbook_creator/templates/limits_groups.html.erb +13 -0
- data/install/config/tools/handbook_creator/templates/nav.html.erb +27 -0
- data/install/config/tools/handbook_creator/templates/overview.html.erb +1 -0
- data/install/config/tools/handbook_creator/templates/pdf_cover.html.erb +23 -0
- data/install/config/tools/handbook_creator/templates/pdf_footer.html.erb +33 -0
- data/install/config/tools/handbook_creator/templates/pdf_header.html.erb +41 -0
- data/install/config/tools/handbook_creator/templates/telemetry_packets.html.erb +80 -0
- data/install/config/tools/handbook_creator/templates/telemetry_toc.html.erb +38 -0
- data/install/config/tools/handbook_creator/templates/title.html.erb +1 -0
- data/install/config/tools/launcher/launcher.txt +39 -0
- data/install/config/tools/limits_monitor/README.txt +1 -0
- data/install/config/tools/opengl_builder/README.txt +1 -0
- data/install/config/tools/script_runner/script_runner.txt +3 -0
- data/install/config/tools/table_manager/README.txt +1 -0
- data/install/config/tools/test_runner/test_runner.txt +8 -0
- data/install/config/tools/tlm_extractor/README.txt +1 -0
- data/install/config/tools/tlm_grapher/README.txt +1 -0
- data/install/config/tools/tlm_viewer/tlm_viewer.txt +5 -0
- data/install/lib/user_version.rb +3 -0
- data/install/outputs/handbooks/assets/css/bootstrap-theme.css +397 -0
- data/install/outputs/handbooks/assets/css/bootstrap-theme.min.css +7 -0
- data/install/outputs/handbooks/assets/css/bootstrap.css +7118 -0
- data/install/outputs/handbooks/assets/css/bootstrap.min.css +7 -0
- data/install/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/install/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/install/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/install/outputs/handbooks/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/install/outputs/handbooks/assets/img/ball_logo.bmp +0 -0
- data/install/outputs/handbooks/assets/img/ball_logo.gif +0 -0
- data/install/outputs/handbooks/assets/img/ball_logo.jpg +0 -0
- data/install/outputs/handbooks/assets/js/bootstrap.js +2006 -0
- data/install/outputs/handbooks/assets/js/bootstrap.min.js +7 -0
- data/install/outputs/handbooks/assets/js/html5shiv.js +8 -0
- data/install/outputs/handbooks/assets/js/jquery-1.10.2.min.js +6 -0
- data/install/outputs/handbooks/assets/js/respond.min.js +6 -0
- data/install/outputs/logs/README.txt +1 -0
- data/install/outputs/saved_config/README.txt +1 -0
- data/install/outputs/tables/README.txt +1 -0
- data/install/outputs/tmp/README.txt +1 -0
- data/install/procedures/README.txt +1 -0
- data/install/tools/CmdExtractor +15 -0
- data/install/tools/CmdExtractor.bat +59 -0
- data/install/tools/CmdSender +15 -0
- data/install/tools/CmdSender.bat +59 -0
- data/install/tools/CmdTlmServer +15 -0
- data/install/tools/CmdTlmServer.bat +59 -0
- data/install/tools/DataViewer +15 -0
- data/install/tools/DataViewer.bat +59 -0
- data/install/tools/HandbookCreator +15 -0
- data/install/tools/HandbookCreator.bat +61 -0
- data/install/tools/Launcher +15 -0
- data/install/tools/Launcher.bat +59 -0
- data/install/tools/LimitsMonitor +15 -0
- data/install/tools/LimitsMonitor.bat +59 -0
- data/install/tools/OpenGLBuilder +15 -0
- data/install/tools/OpenGLBuilder.bat +59 -0
- data/install/tools/PacketViewer +15 -0
- data/install/tools/PacketViewer.bat +59 -0
- data/install/tools/Replay +15 -0
- data/install/tools/Replay.bat +59 -0
- data/install/tools/ScriptRunner +15 -0
- data/install/tools/ScriptRunner.bat +59 -0
- data/install/tools/TableManager +15 -0
- data/install/tools/TableManager.bat +59 -0
- data/install/tools/TestRunner +15 -0
- data/install/tools/TestRunner.bat +59 -0
- data/install/tools/TlmExtractor +15 -0
- data/install/tools/TlmExtractor.bat +59 -0
- data/install/tools/TlmGrapher +15 -0
- data/install/tools/TlmGrapher.bat +59 -0
- data/install/tools/TlmViewer +15 -0
- data/install/tools/TlmViewer.bat +59 -0
- data/install/tools/mac/CmdExtractor.app/Contents/Info.plist +38 -0
- data/install/tools/mac/CmdExtractor.app/Contents/MacOS/CmdExtractor.rb +15 -0
- data/install/tools/mac/CmdExtractor.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/CmdExtractor.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/CmdSender.app/Contents/Info.plist +38 -0
- data/install/tools/mac/CmdSender.app/Contents/MacOS/CmdSender.rb +15 -0
- data/install/tools/mac/CmdSender.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/CmdSender.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/CmdTlmServer.app/Contents/Info.plist +38 -0
- data/install/tools/mac/CmdTlmServer.app/Contents/MacOS/CmdTlmServer.rb +15 -0
- data/install/tools/mac/CmdTlmServer.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/CmdTlmServer.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/DataViewer.app/Contents/Info.plist +38 -0
- data/install/tools/mac/DataViewer.app/Contents/MacOS/DataViewer.rb +15 -0
- data/install/tools/mac/DataViewer.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/DataViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/HandbookCreator.app/Contents/Info.plist +38 -0
- data/install/tools/mac/HandbookCreator.app/Contents/MacOS/HandbookCreator.rb +15 -0
- data/install/tools/mac/HandbookCreator.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/HandbookCreator.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/Launcher.app/Contents/Info.plist +38 -0
- data/install/tools/mac/Launcher.app/Contents/MacOS/Launcher.rb +15 -0
- data/install/tools/mac/Launcher.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/Launcher.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/LimitsMonitor.app/Contents/Info.plist +38 -0
- data/install/tools/mac/LimitsMonitor.app/Contents/MacOS/LimitsMonitor.rb +15 -0
- data/install/tools/mac/LimitsMonitor.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/LimitsMonitor.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/OpenGLBuilder.app/Contents/Info.plist +38 -0
- data/install/tools/mac/OpenGLBuilder.app/Contents/MacOS/OpenGLBuilder.rb +15 -0
- data/install/tools/mac/OpenGLBuilder.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/OpenGLBuilder.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/PacketViewer.app/Contents/Info.plist +38 -0
- data/install/tools/mac/PacketViewer.app/Contents/MacOS/PacketViewer.rb +15 -0
- data/install/tools/mac/PacketViewer.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/PacketViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/Replay.app/Contents/Info.plist +38 -0
- data/install/tools/mac/Replay.app/Contents/MacOS/Replay.rb +15 -0
- data/install/tools/mac/Replay.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/Replay.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/ScriptRunner.app/Contents/Info.plist +38 -0
- data/install/tools/mac/ScriptRunner.app/Contents/MacOS/ScriptRunner.rb +15 -0
- data/install/tools/mac/ScriptRunner.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/ScriptRunner.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/TableManager.app/Contents/Info.plist +38 -0
- data/install/tools/mac/TableManager.app/Contents/MacOS/TableManager.rb +15 -0
- data/install/tools/mac/TableManager.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/TableManager.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/TestRunner.app/Contents/Info.plist +38 -0
- data/install/tools/mac/TestRunner.app/Contents/MacOS/TestRunner.rb +15 -0
- data/install/tools/mac/TestRunner.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/TestRunner.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/TlmExtractor.app/Contents/Info.plist +38 -0
- data/install/tools/mac/TlmExtractor.app/Contents/MacOS/TlmExtractor.rb +15 -0
- data/install/tools/mac/TlmExtractor.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/TlmExtractor.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/TlmGrapher.app/Contents/Info.plist +38 -0
- data/install/tools/mac/TlmGrapher.app/Contents/MacOS/TlmGrapher.rb +15 -0
- data/install/tools/mac/TlmGrapher.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/TlmGrapher.app/Contents/Resources/appIcon.icns +0 -0
- data/install/tools/mac/TlmViewer.app/Contents/Info.plist +38 -0
- data/install/tools/mac/TlmViewer.app/Contents/MacOS/TlmViewer.rb +15 -0
- data/install/tools/mac/TlmViewer.app/Contents/MacOS/main.sh +6 -0
- data/install/tools/mac/TlmViewer.app/Contents/Resources/appIcon.icns +0 -0
- data/install/userpath.txt +1 -0
- data/lib/cosmos/ccsds/ccsds_packet.rb +63 -0
- data/lib/cosmos/ccsds/ccsds_parser.rb +143 -0
- data/lib/cosmos/config/config_parser.rb +324 -0
- data/lib/cosmos/conversions/conversion.rb +47 -0
- data/lib/cosmos/conversions/generic_conversion.rb +55 -0
- data/lib/cosmos/conversions/new_packet_log_conversion.rb +45 -0
- data/lib/cosmos/conversions/polynomial_conversion.rb +57 -0
- data/lib/cosmos/conversions/processor_conversion.rb +46 -0
- data/lib/cosmos/conversions/received_count_conversion.rb +33 -0
- data/lib/cosmos/conversions/received_time_formatted_conversion.rb +37 -0
- data/lib/cosmos/conversions/received_time_seconds_conversion.rb +37 -0
- data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +128 -0
- data/lib/cosmos/conversions/unix_time_conversion.rb +50 -0
- data/lib/cosmos/conversions/unix_time_formatted_conversion.rb +44 -0
- data/lib/cosmos/conversions/unix_time_seconds_conversion.rb +44 -0
- data/lib/cosmos/conversions.rb +13 -0
- data/lib/cosmos/core_ext/array.rb +354 -0
- data/lib/cosmos/core_ext/class.rb +51 -0
- data/lib/cosmos/core_ext/cosmos_io.rb +29 -0
- data/lib/cosmos/core_ext/exception.rb +52 -0
- data/lib/cosmos/core_ext/file.rb +75 -0
- data/lib/cosmos/core_ext/hash.rb +28 -0
- data/lib/cosmos/core_ext/io.rb +75 -0
- data/lib/cosmos/core_ext/kernel.rb +38 -0
- data/lib/cosmos/core_ext/math.rb +119 -0
- data/lib/cosmos/core_ext/matrix.rb +146 -0
- data/lib/cosmos/core_ext/objectspace.rb +29 -0
- data/lib/cosmos/core_ext/range.rb +22 -0
- data/lib/cosmos/core_ext/socket.rb +32 -0
- data/lib/cosmos/core_ext/string.rb +310 -0
- data/lib/cosmos/core_ext/stringio.rb +24 -0
- data/lib/cosmos/core_ext/time.rb +446 -0
- data/lib/cosmos/core_ext.rb +18 -0
- data/lib/cosmos/ext/.keep +0 -0
- data/lib/cosmos/gui/choosers/combobox_chooser.rb +130 -0
- data/lib/cosmos/gui/choosers/file_chooser.rb +68 -0
- data/lib/cosmos/gui/choosers/float_chooser.rb +82 -0
- data/lib/cosmos/gui/choosers/integer_chooser.rb +80 -0
- data/lib/cosmos/gui/choosers/string_chooser.rb +53 -0
- data/lib/cosmos/gui/choosers/telemetry_chooser.rb +317 -0
- data/lib/cosmos/gui/dialogs/about_dialog.rb +128 -0
- data/lib/cosmos/gui/dialogs/calendar_dialog.rb +136 -0
- data/lib/cosmos/gui/dialogs/cmd_details_dialog.rb +52 -0
- data/lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb +149 -0
- data/lib/cosmos/gui/dialogs/details_dialog.rb +174 -0
- data/lib/cosmos/gui/dialogs/exception_dialog.rb +97 -0
- data/lib/cosmos/gui/dialogs/exception_list_dialog.rb +59 -0
- data/lib/cosmos/gui/dialogs/find_replace_dialog.rb +196 -0
- data/lib/cosmos/gui/dialogs/legal_dialog.rb +168 -0
- data/lib/cosmos/gui/dialogs/packet_log_dialog.rb +118 -0
- data/lib/cosmos/gui/dialogs/progress_dialog.rb +262 -0
- data/lib/cosmos/gui/dialogs/pry_dialog.rb +161 -0
- data/lib/cosmos/gui/dialogs/scroll_text_dialog.rb +37 -0
- data/lib/cosmos/gui/dialogs/select_dialog.rb +54 -0
- data/lib/cosmos/gui/dialogs/set_tlm_dialog.rb +131 -0
- data/lib/cosmos/gui/dialogs/splash.rb +113 -0
- data/lib/cosmos/gui/dialogs/tlm_details_dialog.rb +206 -0
- data/lib/cosmos/gui/dialogs/tlm_edit_dialog.rb +81 -0
- data/lib/cosmos/gui/line_graph/line_graph.rb +456 -0
- data/lib/cosmos/gui/line_graph/line_graph_dialog.rb +34 -0
- data/lib/cosmos/gui/line_graph/line_graph_drawing.rb +494 -0
- data/lib/cosmos/gui/line_graph/line_graph_popups.rb +116 -0
- data/lib/cosmos/gui/line_graph/line_graph_scaling.rb +460 -0
- data/lib/cosmos/gui/line_graph/line_graph_script.rb +26 -0
- data/lib/cosmos/gui/line_graph/lines.rb +290 -0
- data/lib/cosmos/gui/line_graph/overview_graph.rb +459 -0
- data/lib/cosmos/gui/opengl/earth_model.rb +22 -0
- data/lib/cosmos/gui/opengl/gl_bounds.rb +67 -0
- data/lib/cosmos/gui/opengl/gl_light.rb +39 -0
- data/lib/cosmos/gui/opengl/gl_material.rb +29 -0
- data/lib/cosmos/gui/opengl/gl_scene.rb +72 -0
- data/lib/cosmos/gui/opengl/gl_shape.rb +146 -0
- data/lib/cosmos/gui/opengl/gl_viewer.rb +712 -0
- data/lib/cosmos/gui/opengl/gl_viewport.rb +35 -0
- data/lib/cosmos/gui/opengl/moon_model.rb +22 -0
- data/lib/cosmos/gui/opengl/opengl.rb +8 -0
- data/lib/cosmos/gui/opengl/stl_reader.rb +211 -0
- data/lib/cosmos/gui/opengl/stl_shape.rb +124 -0
- data/lib/cosmos/gui/opengl/texture_mapped_sphere.rb +202 -0
- data/lib/cosmos/gui/qt.rb +786 -0
- data/lib/cosmos/gui/qt_tool.rb +373 -0
- data/lib/cosmos/gui/text/completion.rb +381 -0
- data/lib/cosmos/gui/text/completion_line_edit.rb +30 -0
- data/lib/cosmos/gui/text/completion_text_edit.rb +179 -0
- data/lib/cosmos/gui/text/ruby_editor.rb +395 -0
- data/lib/cosmos/gui/utilities/screenshot.rb +25 -0
- data/lib/cosmos/gui/utilities/script_module_gui.rb +203 -0
- data/lib/cosmos/gui/widgets/full_text_search_line_edit.rb +161 -0
- data/lib/cosmos/gui/widgets/packet_log_frame.rb +305 -0
- data/lib/cosmos/gui/widgets/realtime_button_bar.rb +98 -0
- data/lib/cosmos/interfaces/cmd_tlm_server_interface.rb +149 -0
- data/lib/cosmos/interfaces/interface.rb +213 -0
- data/lib/cosmos/interfaces/linc_interface.rb +360 -0
- data/lib/cosmos/interfaces/serial_interface.rb +76 -0
- data/lib/cosmos/interfaces/simulated_target_interface.rb +128 -0
- data/lib/cosmos/interfaces/stream_interface.rb +156 -0
- data/lib/cosmos/interfaces/tcpip_client_interface.rb +60 -0
- data/lib/cosmos/interfaces/tcpip_server_interface.rb +154 -0
- data/lib/cosmos/interfaces/udp_interface.rb +173 -0
- data/lib/cosmos/interfaces.rb +11 -0
- data/lib/cosmos/io/buffered_file.rb +11 -0
- data/lib/cosmos/io/cosmos_snmp.rb +50 -0
- data/lib/cosmos/io/io_multiplexer.rb +89 -0
- data/lib/cosmos/io/json_drb.rb +320 -0
- data/lib/cosmos/io/json_drb_object.rb +137 -0
- data/lib/cosmos/io/json_rpc.rb +365 -0
- data/lib/cosmos/io/posix_serial_driver.rb +145 -0
- data/lib/cosmos/io/raw_logger.rb +174 -0
- data/lib/cosmos/io/raw_logger_pair.rb +71 -0
- data/lib/cosmos/io/serial_driver.rb +85 -0
- data/lib/cosmos/io/stderr.rb +36 -0
- data/lib/cosmos/io/stdout.rb +36 -0
- data/lib/cosmos/io/tcpip_server.rb +532 -0
- data/lib/cosmos/io/udp_sockets.rb +152 -0
- data/lib/cosmos/io/win32_serial_driver.rb +147 -0
- data/lib/cosmos/packet_logs/meta_packet_log_writer.rb +107 -0
- data/lib/cosmos/packet_logs/packet_log_reader.rb +439 -0
- data/lib/cosmos/packet_logs/packet_log_writer.rb +309 -0
- data/lib/cosmos/packet_logs/packet_log_writer_pair.rb +30 -0
- data/lib/cosmos/packet_logs.rb +6 -0
- data/lib/cosmos/packets/binary_accessor.rb +921 -0
- data/lib/cosmos/packets/commands.rb +291 -0
- data/lib/cosmos/packets/limits.rb +263 -0
- data/lib/cosmos/packets/limits_response.rb +38 -0
- data/lib/cosmos/packets/packet.rb +699 -0
- data/lib/cosmos/packets/packet_config.rb +1034 -0
- data/lib/cosmos/packets/packet_item.rb +317 -0
- data/lib/cosmos/packets/packet_item_limits.rb +128 -0
- data/lib/cosmos/packets/structure.rb +386 -0
- data/lib/cosmos/packets/structure_item.rb +233 -0
- data/lib/cosmos/packets/telemetry.rb +317 -0
- data/lib/cosmos/processors/new_packet_log_processor.rb +34 -0
- data/lib/cosmos/processors/processor.rb +71 -0
- data/lib/cosmos/processors/statistics_processor.rb +65 -0
- data/lib/cosmos/processors/watermark_processor.rb +44 -0
- data/lib/cosmos/processors.rb +6 -0
- data/lib/cosmos/script/extract.rb +115 -0
- data/lib/cosmos/script/script.rb +1493 -0
- data/lib/cosmos/script.rb +9 -0
- data/lib/cosmos/streams/burst_stream_protocol.rb +25 -0
- data/lib/cosmos/streams/fixed_stream_protocol.rb +111 -0
- data/lib/cosmos/streams/length_stream_protocol.rb +140 -0
- data/lib/cosmos/streams/preidentified_stream_protocol.rb +118 -0
- data/lib/cosmos/streams/serial_stream.rb +143 -0
- data/lib/cosmos/streams/stream.rb +57 -0
- data/lib/cosmos/streams/stream_protocol.rb +369 -0
- data/lib/cosmos/streams/tcpip_client_stream.rb +77 -0
- data/lib/cosmos/streams/tcpip_socket_stream.rb +139 -0
- data/lib/cosmos/streams/template_stream_protocol.rb +140 -0
- data/lib/cosmos/streams/terminated_stream_protocol.rb +81 -0
- data/lib/cosmos/system/system.rb +558 -0
- data/lib/cosmos/system/target.rb +178 -0
- data/lib/cosmos/system.rb +4 -0
- data/lib/cosmos/tools/cmd_extractor/cmd_extractor.rb +253 -0
- data/lib/cosmos/tools/cmd_sender/cmd_sender.rb +716 -0
- data/lib/cosmos/tools/cmd_sender/cmd_sender_item_delegate.rb +77 -0
- data/lib/cosmos/tools/cmd_sender/cmd_sender_text_edit.rb +70 -0
- data/lib/cosmos/tools/cmd_tlm_server/api.rb +940 -0
- data/lib/cosmos/tools/cmd_tlm_server/background_task.rb +46 -0
- data/lib/cosmos/tools/cmd_tlm_server/background_tasks.rb +63 -0
- data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +496 -0
- data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +241 -0
- data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +1008 -0
- data/lib/cosmos/tools/cmd_tlm_server/commanding.rb +112 -0
- data/lib/cosmos/tools/cmd_tlm_server/connections.rb +176 -0
- data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +221 -0
- data/lib/cosmos/tools/cmd_tlm_server/interfaces.rb +127 -0
- data/lib/cosmos/tools/cmd_tlm_server/packet_logging.rb +132 -0
- data/lib/cosmos/tools/cmd_tlm_server/router_thread.rb +66 -0
- data/lib/cosmos/tools/cmd_tlm_server/routers.rb +97 -0
- data/lib/cosmos/tools/data_viewer/data_viewer.rb +600 -0
- data/lib/cosmos/tools/data_viewer/data_viewer_component.rb +167 -0
- data/lib/cosmos/tools/data_viewer/dump_component.rb +40 -0
- data/lib/cosmos/tools/handbook_creator/handbook_creator.rb +149 -0
- data/lib/cosmos/tools/handbook_creator/handbook_creator_config.rb +360 -0
- data/lib/cosmos/tools/launcher/launcher.rb +184 -0
- data/lib/cosmos/tools/launcher/launcher_config.rb +167 -0
- data/lib/cosmos/tools/launcher/launcher_multitool.rb +41 -0
- data/lib/cosmos/tools/launcher/launcher_tool.rb +104 -0
- data/lib/cosmos/tools/limits_monitor/limits_monitor.rb +768 -0
- data/lib/cosmos/tools/opengl_builder/opengl_builder.rb +416 -0
- data/lib/cosmos/tools/opengl_builder/scene_config.rb +118 -0
- data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +525 -0
- data/lib/cosmos/tools/replay/replay.rb +488 -0
- data/lib/cosmos/tools/replay/replay_server.rb +91 -0
- data/lib/cosmos/tools/script_runner/script_audit.rb +139 -0
- data/lib/cosmos/tools/script_runner/script_runner.rb +914 -0
- data/lib/cosmos/tools/script_runner/script_runner_config.rb +40 -0
- data/lib/cosmos/tools/script_runner/script_runner_frame.rb +1859 -0
- data/lib/cosmos/tools/table_manager/table.rb +70 -0
- data/lib/cosmos/tools/table_manager/table_config.rb +764 -0
- data/lib/cosmos/tools/table_manager/table_item.rb +74 -0
- data/lib/cosmos/tools/table_manager/table_manager.rb +1065 -0
- data/lib/cosmos/tools/table_manager/table_manager_core.rb +539 -0
- data/lib/cosmos/tools/test_runner/results_writer.rb +283 -0
- data/lib/cosmos/tools/test_runner/test.rb +480 -0
- data/lib/cosmos/tools/test_runner/test_runner.rb +1157 -0
- data/lib/cosmos/tools/test_runner/test_runner_chooser.rb +338 -0
- data/lib/cosmos/tools/tlm_extractor/text_item_chooser.rb +60 -0
- data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +1008 -0
- data/lib/cosmos/tools/tlm_extractor/tlm_extractor_config.rb +371 -0
- data/lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb +60 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_adders/housekeeping_data_object_adder.rb +75 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_adders/singlexy_data_object_adder.rb +44 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_adders/xy_data_object_adder.rb +94 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_editors/data_object_editor.rb +61 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_editors/housekeeping_data_object_editor.rb +180 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb +141 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_editors/singlexy_data_object_editor.rb +30 -0
- data/lib/cosmos/tools/tlm_grapher/data_object_editors/xy_data_object_editor.rb +173 -0
- data/lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb +177 -0
- data/lib/cosmos/tools/tlm_grapher/data_objects/housekeeping_data_object.rb +409 -0
- data/lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb +176 -0
- data/lib/cosmos/tools/tlm_grapher/data_objects/singlexy_data_object.rb +25 -0
- data/lib/cosmos/tools/tlm_grapher/data_objects/xy_data_object.rb +320 -0
- data/lib/cosmos/tools/tlm_grapher/plot_editors/linegraph_plot_editor.rb +181 -0
- data/lib/cosmos/tools/tlm_grapher/plot_editors/plot_editor.rb +28 -0
- data/lib/cosmos/tools/tlm_grapher/plot_editors/singlexy_plot_editor.rb +30 -0
- data/lib/cosmos/tools/tlm_grapher/plot_editors/xy_plot_editor.rb +59 -0
- data/lib/cosmos/tools/tlm_grapher/plot_gui_objects/linegraph_plot_gui_object.rb +172 -0
- data/lib/cosmos/tools/tlm_grapher/plot_gui_objects/singlexy_plot_gui_object.rb +27 -0
- data/lib/cosmos/tools/tlm_grapher/plot_gui_objects/xy_plot_gui_object.rb +74 -0
- data/lib/cosmos/tools/tlm_grapher/plots/linegraph_plot.rb +201 -0
- data/lib/cosmos/tools/tlm_grapher/plots/plot.rb +69 -0
- data/lib/cosmos/tools/tlm_grapher/plots/singlexy_plot.rb +20 -0
- data/lib/cosmos/tools/tlm_grapher/plots/xy_plot.rb +61 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots/overview_tabbed_plots.rb +1278 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_config.rb +430 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_data_object_editor.rb +107 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb +95 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_plot_editor.rb +101 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb +66 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_tab.rb +57 -0
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_tool.rb +1004 -0
- data/lib/cosmos/tools/tlm_grapher/tlm_grapher.rb +87 -0
- data/lib/cosmos/tools/tlm_viewer/screen.rb +458 -0
- data/lib/cosmos/tools/tlm_viewer/tlm_viewer.rb +544 -0
- data/lib/cosmos/tools/tlm_viewer/tlm_viewer_config.rb +287 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/aging_widget.rb +110 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/array_widget.rb +70 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/block_widget.rb +61 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/button_widget.rb +39 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvas_widget.rb +62 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvasimage_widget.rb +41 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvasimagevalue_widget.rb +57 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb +56 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvasline_widget.rb +55 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvaslinevalue_widget.rb +66 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/canvasvalue_widget.rb +124 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/checkbutton_widget.rb +31 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/combobox_widget.rb +30 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/formatfontvalue_widget.rb +36 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/formatvalue_widget.rb +35 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/horizontal_widget.rb +27 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/horizontalbox_widget.rb +31 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/horizontalline_widget.rb +26 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/label_widget.rb +29 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelformatvalue_widget.rb +39 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelprogressbar_widget.rb +38 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labeltrendlimitsbar_widget.rb +38 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelvalue_widget.rb +39 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluedesc_widget.rb +42 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluelimitsbar_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluerangebar_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/layout_widget.rb +34 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb +178 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/linegraph_widget.rb +54 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/matrixbycolumns_widget.rb +47 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/multi_widget.rb +116 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/progressbar_widget.rb +34 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/radiobutton_widget.rb +30 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/rangebar_widget.rb +57 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/screenshotbutton_widget.rb +34 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/scrollwindow_widget.rb +35 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/sectionheader_widget.rb +33 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/tabbook_widget.rb +26 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/tabitem_widget.rb +28 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/textbox_widget.rb +47 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/textfield_widget.rb +26 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/timegraph_widget.rb +88 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/title_widget.rb +27 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/trendbar_widget.rb +130 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/trendlimitsbar_widget.rb +46 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/value_widget.rb +43 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/valuelimitsbar_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/valuerangebar_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/vertical_widget.rb +35 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/verticalbox_widget.rb +37 -0
- data/lib/cosmos/tools/tlm_viewer/widgets/widget.rb +257 -0
- data/lib/cosmos/tools/tlm_viewer/widgets.rb +53 -0
- data/lib/cosmos/top_level.rb +596 -0
- data/lib/cosmos/utilities/crc.rb +166 -0
- data/lib/cosmos/utilities/csv.rb +83 -0
- data/lib/cosmos/utilities/logger.rb +137 -0
- data/lib/cosmos/utilities/low_fragmentation_array.rb +11 -0
- data/lib/cosmos/utilities/message_log.rb +74 -0
- data/lib/cosmos/utilities/quaternion.rb +258 -0
- data/lib/cosmos/utilities/ruby_lex_utils.rb +313 -0
- data/lib/cosmos/utilities/simulated_target.rb +99 -0
- data/lib/cosmos/utilities.rb +10 -0
- data/lib/cosmos/version.rb +12 -0
- data/lib/cosmos/win32/excel.rb +66 -0
- data/lib/cosmos/win32/win32.rb +387 -0
- data/lib/cosmos/win32/win32_main.rb +311 -0
- data/lib/cosmos.rb +63 -0
- data/roodi.yml +24 -0
- data/run_gui_tests.bat +32 -0
- data/spec/ccsds/ccsds_packet_spec.rb +67 -0
- data/spec/ccsds/ccsds_parser_spec.rb +148 -0
- data/spec/config/config_parser_spec.rb +322 -0
- data/spec/conversions/conversion_spec.rb +31 -0
- data/spec/conversions/generic_conversion_spec.rb +45 -0
- data/spec/conversions/new_packet_log_conversion_spec.rb +39 -0
- data/spec/conversions/polynomial_conversion_spec.rb +40 -0
- data/spec/conversions/processor_conversion_spec.rb +45 -0
- data/spec/conversions/received_count_conversion_spec.rb +43 -0
- data/spec/conversions/received_time_formatted_conversion_spec.rb +49 -0
- data/spec/conversions/received_time_seconds_conversion_spec.rb +50 -0
- data/spec/conversions/segmented_polynomial_conversion_spec.rb +51 -0
- data/spec/conversions/unix_time_formatted_conversion_spec.rb +74 -0
- data/spec/conversions/unix_time_seconds_conversion_spec.rb +76 -0
- data/spec/core_ext/array_spec.rb +186 -0
- data/spec/core_ext/class_spec.rb +36 -0
- data/spec/core_ext/cosmos_io_spec.rb +77 -0
- data/spec/core_ext/exception_spec.rb +91 -0
- data/spec/core_ext/file_spec.rb +72 -0
- data/spec/core_ext/hash_spec.rb +24 -0
- data/spec/core_ext/io_spec.rb +46 -0
- data/spec/core_ext/kernel_spec.rb +54 -0
- data/spec/core_ext/math_spec.rb +116 -0
- data/spec/core_ext/matrix_spec.rb +66 -0
- data/spec/core_ext/objectspace_spec.rb +29 -0
- data/spec/core_ext/range_spec.rb +21 -0
- data/spec/core_ext/socket_spec.rb +32 -0
- data/spec/core_ext/string_spec.rb +223 -0
- data/spec/core_ext/stringio_spec.rb +21 -0
- data/spec/core_ext/time_spec.rb +151 -0
- data/spec/gui/line_graph/line_clip_spec.rb +322 -0
- data/spec/install/config/system/system.txt +33 -0
- data/spec/install/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt +41 -0
- data/spec/install/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +15 -0
- data/spec/install/config/targets/COSMOS/cmd_tlm_server.txt +6 -0
- data/spec/install/config/targets/COSMOS/screens/limits_change.txt +20 -0
- data/spec/install/config/targets/COSMOS/screens/version.txt +19 -0
- data/spec/install/config/targets/COSMOS/target.txt +5 -0
- data/spec/install/config/targets/INST/cmd_tlm/inst_cmd_linc.txt +30 -0
- data/spec/install/config/targets/INST/cmd_tlm/inst_cmds.txt +111 -0
- data/spec/install/config/targets/INST/cmd_tlm/inst_tlm.txt +236 -0
- data/spec/install/config/targets/INST/cmd_tlm/inst_tlm_linc.txt +25 -0
- data/spec/install/config/targets/INST/cmd_tlm_server.txt +5 -0
- data/spec/install/config/targets/INST/lib/sim_inst.rb +294 -0
- data/spec/install/config/targets/INST/target.txt +10 -0
- data/spec/install/config/targets/META/cmd_tlm/meta_cmd.txt +4 -0
- data/spec/install/config/targets/META/cmd_tlm/meta_tlm.txt +4 -0
- data/spec/install/config/targets/SYSTEM/cmd_tlm/limits_groups.txt +7 -0
- data/spec/install/config/tools/cmd_tlm_server/cmd_tlm_server.txt +1 -0
- data/spec/install/lib/README.txt +1 -0
- data/spec/install/userpath.txt +1 -0
- data/spec/interfaces/cmd_tlm_server_interface_spec.rb +150 -0
- data/spec/interfaces/interface_spec.rb +128 -0
- data/spec/interfaces/linc_interface_spec.rb +199 -0
- data/spec/interfaces/serial_interface_spec.rb +56 -0
- data/spec/interfaces/simulated_target_interface_spec.rb +128 -0
- data/spec/interfaces/stream_interface_spec.rb +157 -0
- data/spec/interfaces/tcpip_client_interface_spec.rb +54 -0
- data/spec/interfaces/tcpip_server_interface_spec.rb +151 -0
- data/spec/interfaces/udp_interface_spec.rb +175 -0
- data/spec/io/buffered_file_spec.rb +113 -0
- data/spec/io/io_multiplexer_spec.rb +94 -0
- data/spec/io/json_drb_object_spec.rb +93 -0
- data/spec/io/json_drb_spec.rb +293 -0
- data/spec/io/json_rpc_spec.rb +264 -0
- data/spec/io/raw_logger_pair_spec.rb +76 -0
- data/spec/io/raw_logger_spec.rb +133 -0
- data/spec/io/serial_driver_spec.rb +61 -0
- data/spec/io/stderr_spec.rb +32 -0
- data/spec/io/stdout_spec.rb +32 -0
- data/spec/io/tcpip_server_spec.rb +322 -0
- data/spec/io/udp_sockets_spec.rb +94 -0
- data/spec/io/win32_serial_driver_spec.rb +88 -0
- data/spec/packet_logs/meta_packet_log_writer_spec.rb +170 -0
- data/spec/packet_logs/packet_log_reader_spec.rb +408 -0
- data/spec/packet_logs/packet_log_writer_pair_spec.rb +30 -0
- data/spec/packet_logs/packet_log_writer_spec.rb +209 -0
- data/spec/packets/binary_accessor_spec.rb +2073 -0
- data/spec/packets/commands_spec.rb +369 -0
- data/spec/packets/limits_response_spec.rb +25 -0
- data/spec/packets/limits_spec.rb +326 -0
- data/spec/packets/packet_config_spec.rb +1620 -0
- data/spec/packets/packet_item_limits_spec.rb +161 -0
- data/spec/packets/packet_item_spec.rb +386 -0
- data/spec/packets/packet_spec.rb +949 -0
- data/spec/packets/structure_item_spec.rb +195 -0
- data/spec/packets/structure_spec.rb +419 -0
- data/spec/packets/telemetry_spec.rb +535 -0
- data/spec/processors/new_packet_log_processor_spec.rb +39 -0
- data/spec/processors/processor_spec.rb +55 -0
- data/spec/processors/statistics_processor_spec.rb +60 -0
- data/spec/processors/watermark_processor_spec.rb +51 -0
- data/spec/script/script_spec.rb +650 -0
- data/spec/spec_helper.rb +138 -0
- data/spec/streams/burst_stream_protocol_spec.rb +32 -0
- data/spec/streams/fixed_stream_protocol_spec.rb +110 -0
- data/spec/streams/length_stream_protocol_spec.rb +297 -0
- data/spec/streams/preidentified_stream_protocol_spec.rb +118 -0
- data/spec/streams/serial_stream_spec.rb +105 -0
- data/spec/streams/stream_protocol_spec.rb +332 -0
- data/spec/streams/stream_spec.rb +29 -0
- data/spec/streams/tcpip_client_stream_spec.rb +54 -0
- data/spec/streams/tcpip_socket_stream_spec.rb +146 -0
- data/spec/streams/template_stream_protocol_spec.rb +151 -0
- data/spec/streams/terminated_stream_protocol_spec.rb +123 -0
- data/spec/system/system_spec.rb +645 -0
- data/spec/system/target_spec.rb +248 -0
- data/spec/tools/cmd_tlm_server/api_spec.rb +1090 -0
- data/spec/tools/cmd_tlm_server/background_task_spec.rb +32 -0
- data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +82 -0
- data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +406 -0
- data/spec/tools/cmd_tlm_server/cmd_tlm_server_spec.rb +418 -0
- data/spec/tools/cmd_tlm_server/commanding_spec.rb +123 -0
- data/spec/tools/cmd_tlm_server/connections_spec.rb +147 -0
- data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +317 -0
- data/spec/tools/cmd_tlm_server/interfaces_spec.rb +228 -0
- data/spec/tools/cmd_tlm_server/packet_logging_spec.rb +143 -0
- data/spec/tools/cmd_tlm_server/router_thread_spec.rb +104 -0
- data/spec/tools/cmd_tlm_server/routers_spec.rb +196 -0
- data/spec/top_level/top_level_spec.rb +320 -0
- data/spec/utilities/crc_spec.rb +45 -0
- data/spec/utilities/csv_spec.rb +97 -0
- data/spec/utilities/logger_spec.rb +102 -0
- data/spec/utilities/message_log_spec.rb +89 -0
- data/spec/utilities/quaternion_spec.rb +107 -0
- data/spec/utilities/ruby_lex_utils_spec.rb +86 -0
- data/tasks/manifest.rake +22 -0
- data/tasks/spec.rake +23 -0
- metadata +1566 -0
|
@@ -0,0 +1,2073 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2014 Ball Aerospace & Technologies Corp.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
10
|
+
|
|
11
|
+
require 'spec_helper'
|
|
12
|
+
require 'cosmos'
|
|
13
|
+
require 'cosmos/packets/binary_accessor'
|
|
14
|
+
|
|
15
|
+
module Cosmos
|
|
16
|
+
|
|
17
|
+
describe BinaryAccessor do
|
|
18
|
+
|
|
19
|
+
describe "read" do
|
|
20
|
+
|
|
21
|
+
before(:each) do
|
|
22
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should complain about unrecognized data types" do
|
|
26
|
+
lambda { BinaryAccessor.read(0, 32, :BLOB, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "data_type BLOB is not recognized")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should complain about bit_offsets before the beginning of the buffer" do
|
|
30
|
+
lambda { BinaryAccessor.read(-((@data.length * 8) + 8), 32, :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "#{@data.length} byte buffer insufficient to read STRING at bit_offset #{-((@data.length * 8) + 8)} with bit_size 32")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should complain about a negative bit_offset and zero bit_size" do
|
|
34
|
+
lambda { BinaryAccessor.read(-8, 0, :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "negative or zero bit_sizes (0) cannot be given with negative bit_offsets (-8)")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should complain about a negative bit_offset and negative bit_size" do
|
|
38
|
+
lambda { BinaryAccessor.read(-8, -8, :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "negative or zero bit_sizes (-8) cannot be given with negative bit_offsets (-8)")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should complain about negative bit_sizes larger than the size of the buffer" do
|
|
42
|
+
lambda { BinaryAccessor.read(0, -((@data.length * 8) + 8), :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "#{@data.length} byte buffer insufficient to read STRING at bit_offset 0 with bit_size #{-((@data.length * 8) + 8)}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should complain about negative or zero bit_sizes with data_types other than STRING and BLOCK" do
|
|
46
|
+
lambda { BinaryAccessor.read(0, -8, :INT, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
47
|
+
lambda { BinaryAccessor.read(0, -8, :UINT, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
48
|
+
lambda { BinaryAccessor.read(0, -8, :FLOAT, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should read aligned strings" do
|
|
52
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
53
|
+
if (bit_offset / 8) <= 7
|
|
54
|
+
BinaryAccessor.read(bit_offset, (@data.length * 8) - bit_offset, :STRING, @data, :BIG_ENDIAN).should eql(@data[(bit_offset / 8)..7])
|
|
55
|
+
elsif (bit_offset / 8) == 8
|
|
56
|
+
BinaryAccessor.read(bit_offset, (@data.length * 8) - bit_offset, :STRING, @data, :BIG_ENDIAN).should eql('')
|
|
57
|
+
else
|
|
58
|
+
BinaryAccessor.read(bit_offset, (@data.length * 8) - bit_offset, :STRING, @data, :BIG_ENDIAN).should eql(@data[(bit_offset / 8)..-1])
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should read variable length strings with a zero and negative bit_size" do
|
|
64
|
+
0.step(-(@data.length * 8), -8) do |bit_size|
|
|
65
|
+
if (bit_size / 8) >= -8
|
|
66
|
+
BinaryAccessor.read(0, bit_size, :STRING, @data, :BIG_ENDIAN).should eql(@data[0..7])
|
|
67
|
+
else
|
|
68
|
+
BinaryAccessor.read(0, bit_size, :STRING, @data, :BIG_ENDIAN).should eql(@data[0..((bit_size / 8) - 1)])
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should read strings with negative bit_offsets" do
|
|
74
|
+
BinaryAccessor.read(-16, 16, :STRING, @data, :BIG_ENDIAN).should eql(@data[-2..-1])
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should complain about unaligned strings" do
|
|
78
|
+
lambda { BinaryAccessor.read(1, 32, :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type STRING")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should read aligned blocks" do
|
|
82
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
83
|
+
BinaryAccessor.read(bit_offset, (@data.length * 8) - bit_offset, :BLOCK, @data, :BIG_ENDIAN).should eql(@data[(bit_offset / 8)..-1])
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should read variable length blocks with a zero and negative bit_size" do
|
|
88
|
+
0.step(-(@data.length * 8), -8) do |bit_size|
|
|
89
|
+
BinaryAccessor.read(0, bit_size, :BLOCK, @data, :BIG_ENDIAN).should eql(@data[0..((bit_size / 8) - 1)])
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should read blocks with negative bit_offsets" do
|
|
94
|
+
BinaryAccessor.read(-16, 16, :BLOCK, @data, :BIG_ENDIAN).should eql(@data[-2..-1])
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should complain about unaligned blocks" do
|
|
98
|
+
lambda { BinaryAccessor.read(7, 16, :BLOCK, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 7 is not byte aligned for data_type BLOCK")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should complain if read exceeds the size of the buffer" do
|
|
102
|
+
lambda { BinaryAccessor.read(8, 800, :STRING, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "16 byte buffer insufficient to read STRING at bit_offset 8 with bit_size 800")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should read aligned 8-bit unsigned integers" do
|
|
106
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
107
|
+
BinaryAccessor.read(bit_offset, 8, :UINT, @data, :BIG_ENDIAN).should eql(@data.getbyte(bit_offset / 8))
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should read aligned 8-bit signed integers" do
|
|
112
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
113
|
+
expected = @data.getbyte(bit_offset / 8)
|
|
114
|
+
expected = expected - 256 if expected >= 128
|
|
115
|
+
BinaryAccessor.read(bit_offset, 8, :INT, @data, :BIG_ENDIAN).should eql(expected)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "given big endian data" do
|
|
120
|
+
|
|
121
|
+
it "should read 1-bit unsigned integers" do
|
|
122
|
+
expected = [0x1, 0x0]
|
|
123
|
+
bit_size = 1
|
|
124
|
+
BinaryAccessor.read(8, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
125
|
+
BinaryAccessor.read(9, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "should read 1-bit signed integers" do
|
|
129
|
+
expected = [0x1, 0x0]
|
|
130
|
+
bit_size = 1
|
|
131
|
+
BinaryAccessor.read(8, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
132
|
+
BinaryAccessor.read(9, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should read 7-bit unsigned integers" do
|
|
136
|
+
expected = [0x40, 0x02]
|
|
137
|
+
bit_size = 7
|
|
138
|
+
BinaryAccessor.read(8, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
139
|
+
BinaryAccessor.read(3, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "should read 7-bit signed integers" do
|
|
143
|
+
expected = [0x40, 0x02]
|
|
144
|
+
bit_size = 7
|
|
145
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
146
|
+
BinaryAccessor.read(8, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
147
|
+
BinaryAccessor.read(3, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should read 13-bit unsigned integers" do
|
|
151
|
+
expected = [0x1C24, 0x20]
|
|
152
|
+
bit_size = 13
|
|
153
|
+
BinaryAccessor.read(30, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
154
|
+
BinaryAccessor.read(1, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "should read 13-bit signed integers" do
|
|
158
|
+
expected = [0x1C24, 0x20]
|
|
159
|
+
bit_size = 13
|
|
160
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
161
|
+
BinaryAccessor.read(30, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
162
|
+
BinaryAccessor.read(1, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "should read aligned 16-bit unsigned integers" do
|
|
166
|
+
expected_array = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
167
|
+
index = 0
|
|
168
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
169
|
+
BinaryAccessor.read(bit_offset, 16, :UINT, @data, :BIG_ENDIAN).should eql(expected_array[index])
|
|
170
|
+
index += 1
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should read aligned 16-bit signed integers" do
|
|
175
|
+
expected_array = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
176
|
+
index = 0
|
|
177
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
178
|
+
expected = expected_array[index]
|
|
179
|
+
expected = expected - 2**16 if expected >= 2**15
|
|
180
|
+
BinaryAccessor.read(bit_offset, 16, :INT, @data, :BIG_ENDIAN).should eql(expected)
|
|
181
|
+
index += 1
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "should read aligned 32-bit unsigned integers" do
|
|
186
|
+
expected_array = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
187
|
+
index = 0
|
|
188
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
189
|
+
BinaryAccessor.read(bit_offset, 32, :UINT, @data, :BIG_ENDIAN).should eql(expected_array[index])
|
|
190
|
+
index += 1
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "should read aligned 32-bit signed integers" do
|
|
195
|
+
expected_array = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
196
|
+
index = 0
|
|
197
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
198
|
+
expected = expected_array[index]
|
|
199
|
+
expected = expected - 2**32 if expected >= 2**31
|
|
200
|
+
BinaryAccessor.read(bit_offset, 32, :INT, @data, :BIG_ENDIAN).should eql(expected)
|
|
201
|
+
index += 1
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it "should read aligned 32-bit floats" do
|
|
206
|
+
expected_array = [-1.189360e-038, -3.139169e-036, 8.301067e-040, 1.086646e-031]
|
|
207
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-038).of(expected_array[0])
|
|
208
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-036).of(expected_array[1])
|
|
209
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-040).of(expected_array[2])
|
|
210
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-031).of(expected_array[3])
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "should read 37-bit unsigned integers" do
|
|
214
|
+
expected = [0x8182838485 >> 3, 0x00090A0B0C]
|
|
215
|
+
bit_size = 37
|
|
216
|
+
BinaryAccessor.read(8, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
217
|
+
BinaryAccessor.read(67, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should read 37-bit signed integers" do
|
|
221
|
+
expected = [0x8182838485 >> 3, 0x00090A0B0C]
|
|
222
|
+
bit_size = 37
|
|
223
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
224
|
+
BinaryAccessor.read(8, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
225
|
+
BinaryAccessor.read(67, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "should read 63-bit unsigned integers" do
|
|
229
|
+
expected = [0x8081828384858687 >> 1, 0x00090A0B0C0D0E0F]
|
|
230
|
+
bit_size = 63
|
|
231
|
+
BinaryAccessor.read(0, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
232
|
+
BinaryAccessor.read(65, bit_size, :UINT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it "should read 63-bit signed integers" do
|
|
236
|
+
expected = [0x8081828384858687 >> 1, 0x00090A0B0C0D0E0F]
|
|
237
|
+
bit_size = 63
|
|
238
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
239
|
+
BinaryAccessor.read(0, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[0])
|
|
240
|
+
BinaryAccessor.read(65, bit_size, :INT, @data, :BIG_ENDIAN).should eql(expected[1])
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it "should read aligned 64-bit unsigned integers" do
|
|
244
|
+
expected_array = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
245
|
+
index = 0
|
|
246
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
247
|
+
BinaryAccessor.read(bit_offset, 64, :UINT, @data, :BIG_ENDIAN).should eql(expected_array[index])
|
|
248
|
+
index += 1
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "should read aligned 64-bit signed integers" do
|
|
253
|
+
expected_array = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
254
|
+
index = 0
|
|
255
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
256
|
+
expected = expected_array[index]
|
|
257
|
+
expected = expected - 2**64 if expected >= 2**63
|
|
258
|
+
BinaryAccessor.read(bit_offset, 64, :INT, @data, :BIG_ENDIAN).should eql(expected)
|
|
259
|
+
index += 1
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "should read aligned 64-bit floats" do
|
|
264
|
+
expected_array = [-3.116851e-306, 1.257060e-308]
|
|
265
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-306).of(expected_array[0])
|
|
266
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-308).of(expected_array[1])
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
it "should complain about unaligned floats" do
|
|
270
|
+
lambda { BinaryAccessor.read(17, 32, :FLOAT, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 17 is not byte aligned for data_type FLOAT")
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "should complain about mis-sized floats" do
|
|
274
|
+
lambda { BinaryAccessor.read(0, 33, :FLOAT, @data, :BIG_ENDIAN) }.should raise_error(ArgumentError, "bit_size is 33 but must be 32 or 64 for data_type FLOAT")
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
end # given big endian data
|
|
278
|
+
|
|
279
|
+
describe "given little endian data" do
|
|
280
|
+
|
|
281
|
+
it "should complain about ill-defined little endian bitfields" do
|
|
282
|
+
lambda { BinaryAccessor.read(3, 7, :UINT, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "LITTLE_ENDIAN bitfield with bit_offset 3 and bit_size 7 is invalid")
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it "should read 1-bit unsigned integers" do
|
|
286
|
+
expected = [0x1, 0x0]
|
|
287
|
+
bit_size = 1
|
|
288
|
+
BinaryAccessor.read(8, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
289
|
+
BinaryAccessor.read(9, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "should read 1-bit signed integers" do
|
|
293
|
+
expected = [0x1, 0x0]
|
|
294
|
+
bit_size = 1
|
|
295
|
+
BinaryAccessor.read(8, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
296
|
+
BinaryAccessor.read(9, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it "should read 7-bit unsigned integers" do
|
|
300
|
+
expected = [0x40, 0x60]
|
|
301
|
+
bit_size = 7
|
|
302
|
+
BinaryAccessor.read(8, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
303
|
+
BinaryAccessor.read(15, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
it "should read 7-bit signed integers" do
|
|
307
|
+
expected = [0x40, 0x60]
|
|
308
|
+
bit_size = 7
|
|
309
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
310
|
+
BinaryAccessor.read(8, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
311
|
+
BinaryAccessor.read(15, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
it "should read 13-bit unsigned integers" do
|
|
315
|
+
expected = [0x038281 >> 5, 0x0180 >> 2]
|
|
316
|
+
bit_size = 13
|
|
317
|
+
BinaryAccessor.read(30, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
318
|
+
BinaryAccessor.read(9, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it "should read 13-bit signed integers" do
|
|
322
|
+
expected = [0x038281 >> 5, 0x0180 >> 2]
|
|
323
|
+
bit_size = 13
|
|
324
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
325
|
+
BinaryAccessor.read(30, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
326
|
+
BinaryAccessor.read(9, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
it "should read aligned 16-bit unsigned integers" do
|
|
330
|
+
expected_array = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
331
|
+
index = 0
|
|
332
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
333
|
+
BinaryAccessor.read(bit_offset, 16, :UINT, @data, :LITTLE_ENDIAN).should eql(expected_array[index])
|
|
334
|
+
index += 1
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it "should read aligned 16-bit signed integers" do
|
|
339
|
+
expected_array = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
340
|
+
index = 0
|
|
341
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
342
|
+
expected = expected_array[index]
|
|
343
|
+
expected = expected - 2**16 if expected >= 2**15
|
|
344
|
+
BinaryAccessor.read(bit_offset, 16, :INT, @data, :LITTLE_ENDIAN).should eql(expected)
|
|
345
|
+
index += 1
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it "should read aligned 32-bit unsigned integers" do
|
|
350
|
+
expected_array = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
351
|
+
index = 0
|
|
352
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
353
|
+
BinaryAccessor.read(bit_offset, 32, :UINT, @data, :LITTLE_ENDIAN).should eql(expected_array[index])
|
|
354
|
+
index += 1
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
it "should read aligned 32-bit signed integers" do
|
|
359
|
+
expected_array = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
360
|
+
index = 0
|
|
361
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
362
|
+
expected = expected_array[index]
|
|
363
|
+
expected = expected - 2**32 if expected >= 2**31
|
|
364
|
+
BinaryAccessor.read(bit_offset, 32, :INT, @data, :LITTLE_ENDIAN).should eql(expected)
|
|
365
|
+
index += 1
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
it "should read aligned 32-bit floats" do
|
|
370
|
+
expected_array = [-7.670445e-037, -2.024055e-034, 2.658460e-032, 7.003653e-030]
|
|
371
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-037).of(expected_array[0])
|
|
372
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-034).of(expected_array[1])
|
|
373
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-032).of(expected_array[2])
|
|
374
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-030).of(expected_array[3])
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it "should read 37-bit unsigned integers" do
|
|
378
|
+
expected = [0x8584838281 >> 3, 0x0F0E0D0C0B]
|
|
379
|
+
bit_size = 37
|
|
380
|
+
BinaryAccessor.read(40, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
381
|
+
BinaryAccessor.read(123, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
it "should read 37-bit signed integers" do
|
|
385
|
+
expected = [0x8584838281 >> 3, 0x0F0E0D0C0B]
|
|
386
|
+
bit_size = 37
|
|
387
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
388
|
+
BinaryAccessor.read(40, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
389
|
+
BinaryAccessor.read(123, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
it "should read 63-bit unsigned integers" do
|
|
393
|
+
expected = [0x0F0E0D0C0B0A0900 >> 1, 0x0786858483828180]
|
|
394
|
+
bit_size = 63
|
|
395
|
+
BinaryAccessor.read(120, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
396
|
+
BinaryAccessor.read(57, bit_size, :UINT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
it "should read 63-bit signed integers" do
|
|
400
|
+
expected = [0x0F0E0D0C0B0A0900 >> 1, 0x0786858483828180]
|
|
401
|
+
bit_size = 63
|
|
402
|
+
expected.each_with_index { |value, index| expected[index] = value - 2**bit_size if value >= 2**(bit_size - 1) }
|
|
403
|
+
BinaryAccessor.read(120, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[0])
|
|
404
|
+
BinaryAccessor.read(57, bit_size, :INT, @data, :LITTLE_ENDIAN).should eql(expected[1])
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
it "should read aligned 64-bit unsigned integers" do
|
|
408
|
+
expected_array = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
409
|
+
index = 0
|
|
410
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
411
|
+
BinaryAccessor.read(bit_offset, 64, :UINT, @data, :LITTLE_ENDIAN).should eql(expected_array[index])
|
|
412
|
+
index += 1
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it "should read aligned 64-bit signed integers" do
|
|
417
|
+
expected_array = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
418
|
+
index = 0
|
|
419
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
420
|
+
expected = expected_array[index]
|
|
421
|
+
expected = expected - 2**64 if expected >= 2**63
|
|
422
|
+
BinaryAccessor.read(bit_offset, 64, :INT, @data, :LITTLE_ENDIAN).should eql(expected)
|
|
423
|
+
index += 1
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
it "should read aligned 64-bit floats" do
|
|
428
|
+
expected_array = [-2.081577e-272, 3.691916e-236]
|
|
429
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-272).of(expected_array[0])
|
|
430
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-236).of(expected_array[1])
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
it "should complain about unaligned floats" do
|
|
434
|
+
lambda { BinaryAccessor.read(1, 32, :FLOAT, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type FLOAT")
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
it "should complain about mis-sized floats" do
|
|
438
|
+
lambda { BinaryAccessor.read(0, 65, :FLOAT, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "bit_size is 65 but must be 32 or 64 for data_type FLOAT")
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
end # little endian
|
|
442
|
+
end # describe 'read'
|
|
443
|
+
|
|
444
|
+
describe "read_array" do
|
|
445
|
+
|
|
446
|
+
before(:each) do
|
|
447
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
it "should complain with unknown data_type" do
|
|
451
|
+
expect { BinaryAccessor.read_array(0, 8, :BLAH, 0, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "data_type BLAH is not recognized")
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
describe "given little endian data" do
|
|
455
|
+
|
|
456
|
+
it "should complain about negative bit sizes" do
|
|
457
|
+
expect { BinaryAccessor.read_array(0, -8, :UINT, @data.length*8, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "bit_size -8 must be positive for arrays")
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
context "when positive or zero bit_offset" do
|
|
461
|
+
it "should read the given array_size amount of items" do
|
|
462
|
+
data = @data.unpack('C*')
|
|
463
|
+
BinaryAccessor.read_array(0, 8, :UINT, 32, @data, :LITTLE_ENDIAN).should eql(data[0..3])
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
it "should read the given array_size amount of items" do
|
|
467
|
+
data = @data.unpack('C*')
|
|
468
|
+
BinaryAccessor.read_array(32, 8, :UINT, 32, @data, :LITTLE_ENDIAN).should eql(data[4..7])
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
it "should read the total buffer given array_size = buffer size" do
|
|
472
|
+
data = @data.unpack('c*')
|
|
473
|
+
|
|
474
|
+
BinaryAccessor.read_array(0, 8, :INT, @data.length*8, @data, :LITTLE_ENDIAN).should eql(data)
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
it "should complain with an array_size not a multiple of bit_size" do
|
|
478
|
+
data = @data.unpack('C*')
|
|
479
|
+
expect { BinaryAccessor.read_array(0, 8, :UINT, 10, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "array_size 10 not a multiple of bit_size 8")
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it "should read as many items as possible with a zero array_size" do
|
|
483
|
+
data = @data.unpack('C*')
|
|
484
|
+
BinaryAccessor.read_array(0, 8, :UINT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
it "should exclude the remaining bits if array_size is negative" do
|
|
488
|
+
data = @data.unpack('C*')
|
|
489
|
+
BinaryAccessor.read_array(0, 8, :UINT, -32, @data, :LITTLE_ENDIAN).should eql(data[0..-5])
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
it "should return an empty array if the offset equals the negative array size" do
|
|
493
|
+
data = @data.unpack('C*')
|
|
494
|
+
BinaryAccessor.read_array(@data.length*8-32, 8, :UINT, -32, @data, :LITTLE_ENDIAN).should eql([])
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
it "should complain if the offset is greater than the negative array size" do
|
|
498
|
+
data = @data.unpack('C*')
|
|
499
|
+
offset = @data.length * 8 - 16
|
|
500
|
+
expect { BinaryAccessor.read_array(offset, 8, :UINT, -32, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "16 byte buffer insufficient to read UINT at bit_offset #{offset} with bit_size 8")
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
context "when negative bit_offset" do
|
|
505
|
+
it "should read an array of aligned 8 bit unsigned integers" do
|
|
506
|
+
data = @data.unpack('C*')
|
|
507
|
+
BinaryAccessor.read_array(-32, 8, :UINT, 32, @data, :LITTLE_ENDIAN).should eql(data[-4..-1])
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
it "should read an array if the negative offset is the size of the array" do
|
|
511
|
+
data = @data.unpack('C*')
|
|
512
|
+
BinaryAccessor.read_array(-(@data.length*8), 8, :UINT, @data.length*8, @data, :LITTLE_ENDIAN).should eql(data)
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
it "should complain if the offset is larger than the buffer" do
|
|
516
|
+
expect { BinaryAccessor.read_array(-(@data.length*8+1), 8, :UINT, @data.length*8, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "#{@data.length} byte buffer insufficient to read #{:UINT} at bit_offset -#{@data.length*8+1} with bit_size 8")
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
it "should complain with zero array_size" do
|
|
520
|
+
expect { BinaryAccessor.read_array(-32, 8, :UINT, 0, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "negative or zero array_size (0) cannot be given with negative bit_offset (-32)")
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
it "should complain with negative array_size" do
|
|
524
|
+
expect { BinaryAccessor.read_array(-32, 8, :UINT, -8, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "negative or zero array_size (-8) cannot be given with negative bit_offset (-32)")
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
it "should complain about accessing data from a buffer which is too small" do
|
|
529
|
+
expect { BinaryAccessor.read_array(0, 256, :STRING, 256, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "16 byte buffer insufficient to read STRING at bit_offset 0 with bit_size 256")
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
it "should return an empty array when passed a zero length buffer" do
|
|
533
|
+
BinaryAccessor.read_array(0, 8, :UINT, 32, "", :LITTLE_ENDIAN).should eql([])
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
it "should complain about unaligned strings" do
|
|
537
|
+
lambda { BinaryAccessor.read_array(1, 32, :STRING, 32, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type STRING")
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
it "should read a single STRING item" do
|
|
541
|
+
BinaryAccessor.read_array(0, 128, :STRING, 0, @data, :LITTLE_ENDIAN).should eql([@data[0..7]])
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
it "should read a single BLOCK item" do
|
|
545
|
+
BinaryAccessor.read_array(0, 128, :BLOCK, 0, @data, :LITTLE_ENDIAN).should eql([@data])
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
it "should read BLOCK items" do
|
|
549
|
+
data = BinaryAccessor.read_array(0, 8, :BLOCK, 0, @data, :LITTLE_ENDIAN)
|
|
550
|
+
data.each_with_index {|val, i| val.should eql(@data[i]) }
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
it "should read 1-bit integers" do
|
|
554
|
+
expected = [0x1, 0x0, 0x0, 0x0]
|
|
555
|
+
BinaryAccessor.read_array(0, 1, :INT, 4, @data, :LITTLE_ENDIAN).should eql(expected)
|
|
556
|
+
BinaryAccessor.read_array(0, 1, :INT, 2, @data, :LITTLE_ENDIAN).should eql(expected[0..1])
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
it "should complain about little endian bit-fields greater than 1-bit" do
|
|
560
|
+
expect { BinaryAccessor.read_array(8, 7, :UINT, 21, @data, :LITTLE_ENDIAN) }.to raise_error(ArgumentError, "read_array does not support little endian bit fields with bit_size greater than 1-bit")
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
it "should read 16 bit UINT items" do
|
|
564
|
+
data = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
565
|
+
BinaryAccessor.read_array(0, 16, :UINT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
it "should read 16 bit INT items" do
|
|
569
|
+
data = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
570
|
+
data.map! {|x| (x & ~(1 << 15)) - (x & (1 << 15)) } # convert to negative
|
|
571
|
+
BinaryAccessor.read_array(0, 16, :INT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
it "should read 32 bit UINT items" do
|
|
575
|
+
data = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
576
|
+
BinaryAccessor.read_array(0, 32, :UINT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
it "should read 32 bit INT items" do
|
|
580
|
+
data = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
581
|
+
data.map! {|x| (x & ~(1 << 31)) - (x & (1 << 31)) } # convert to negative
|
|
582
|
+
BinaryAccessor.read_array(0, 32, :INT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
it "should read 64 bit UINT items" do
|
|
586
|
+
data = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
587
|
+
BinaryAccessor.read_array(0, 64, :UINT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
it "should read 64 bit INT items" do
|
|
591
|
+
data = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
592
|
+
data.map! {|x| (x & ~(1 << 63)) - (x & (1 << 63)) } # convert to negative
|
|
593
|
+
BinaryAccessor.read_array(0, 64, :INT, 0, @data, :LITTLE_ENDIAN).should eql(data)
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
it "should read aligned 32-bit floats" do
|
|
597
|
+
expected_array = [-7.670445e-037, -2.024055e-034, 2.658460e-032, 7.003653e-030]
|
|
598
|
+
actual = BinaryAccessor.read_array(0, 32, :FLOAT, 0, @data, :LITTLE_ENDIAN)
|
|
599
|
+
actual.each_with_index do |val, index|
|
|
600
|
+
val.should be_within(1.0e-030).of(expected_array[index])
|
|
601
|
+
end
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
it "should read aligned 64-bit floats" do
|
|
605
|
+
expected_array = [-2.081577e-272, 3.691916e-236]
|
|
606
|
+
actual = BinaryAccessor.read_array(0, 64, :FLOAT, 0, @data, :LITTLE_ENDIAN)
|
|
607
|
+
actual.each_with_index do |val, index|
|
|
608
|
+
val.should be_within(1.0e-236).of(expected_array[index])
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
|
|
612
|
+
it "should complain about unaligned floats" do
|
|
613
|
+
lambda { BinaryAccessor.read_array(1, 32, :FLOAT, 32, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type FLOAT")
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
it "should complain about mis-sized floats" do
|
|
617
|
+
lambda { BinaryAccessor.read_array(0, 65, :FLOAT, 65, @data, :LITTLE_ENDIAN) }.should raise_error(ArgumentError, "bit_size is 65 but must be 32 or 64 for data_type FLOAT")
|
|
618
|
+
end
|
|
619
|
+
end # given little endian data
|
|
620
|
+
|
|
621
|
+
describe "given big endian data" do
|
|
622
|
+
|
|
623
|
+
it "should read 7-bit unsigned integers" do
|
|
624
|
+
expected = [0x40, 0x60, 0x50]
|
|
625
|
+
bit_size = 7
|
|
626
|
+
BinaryAccessor.read_array(8, bit_size, :UINT, 21, @data, :BIG_ENDIAN).should eql(expected)
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
it "should read 16 bit UINT items" do
|
|
630
|
+
data = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
631
|
+
BinaryAccessor.read_array(0, 16, :UINT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
it "should read 16 bit INT items" do
|
|
635
|
+
data = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
636
|
+
data.map! {|x| (x & ~(1 << 15)) - (x & (1 << 15)) } # convert to negative
|
|
637
|
+
BinaryAccessor.read_array(0, 16, :INT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
638
|
+
end
|
|
639
|
+
|
|
640
|
+
it "should read 32 bit UINT items" do
|
|
641
|
+
data = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
642
|
+
BinaryAccessor.read_array(0, 32, :UINT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
643
|
+
end
|
|
644
|
+
|
|
645
|
+
it "should read 32 bit INT items" do
|
|
646
|
+
data = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
647
|
+
data.map! {|x| (x & ~(1 << 31)) - (x & (1 << 31)) } # convert to negative
|
|
648
|
+
BinaryAccessor.read_array(0, 32, :INT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
it "should read 64 bit UINT items" do
|
|
652
|
+
data = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
653
|
+
BinaryAccessor.read_array(0, 64, :UINT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
it "should read 64 bit INT items" do
|
|
657
|
+
data = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
658
|
+
data.map! {|x| (x & ~(1 << 63)) - (x & (1 << 63)) } # convert to negative
|
|
659
|
+
BinaryAccessor.read_array(0, 64, :INT, 0, @data, :BIG_ENDIAN).should eql(data)
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
it "should read aligned 32-bit floats" do
|
|
663
|
+
expected_array = [-1.189360e-038, -3.139169e-036, 8.301067e-040, 1.086646e-031]
|
|
664
|
+
actual = BinaryAccessor.read_array(0, 32, :FLOAT, 0, @data, :BIG_ENDIAN)
|
|
665
|
+
actual.each_with_index do |val, index|
|
|
666
|
+
val.should be_within(1.0e-030).of(expected_array[index])
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
it "should read aligned 64-bit floats" do
|
|
671
|
+
expected_array = [-3.116851e-306, 1.257060e-308]
|
|
672
|
+
actual = BinaryAccessor.read_array(0, 64, :FLOAT, 0, @data, :BIG_ENDIAN)
|
|
673
|
+
actual.each_with_index do |val, index|
|
|
674
|
+
val.should be_within(1.0e-236).of(expected_array[index])
|
|
675
|
+
end
|
|
676
|
+
end
|
|
677
|
+
end # given big endian data
|
|
678
|
+
end # describe "read_array"
|
|
679
|
+
|
|
680
|
+
describe "write" do
|
|
681
|
+
|
|
682
|
+
before(:each) do
|
|
683
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
684
|
+
@baseline_data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
it "should complain about unrecognized data types" do
|
|
688
|
+
lambda { BinaryAccessor.write(0, 0, 32, :BLOB, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "data_type BLOB is not recognized")
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
it "should complain about bit_offsets before the beginning of the buffer" do
|
|
692
|
+
lambda { BinaryAccessor.write('', -((@data.length * 8) + 8), 32, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "#{@data.length} byte buffer insufficient to write STRING at bit_offset #{-((@data.length * 8) + 8)} with bit_size 32")
|
|
693
|
+
end
|
|
694
|
+
|
|
695
|
+
it "should complain about a negative bit_offset and zero bit_size" do
|
|
696
|
+
lambda { BinaryAccessor.write('', -8, 0, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "negative or zero bit_sizes (0) cannot be given with negative bit_offsets (-8)")
|
|
697
|
+
end
|
|
698
|
+
|
|
699
|
+
it "should complain about a negative bit_offset and negative bit_size" do
|
|
700
|
+
lambda { BinaryAccessor.write('', -8, -8, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "negative or zero bit_sizes (-8) cannot be given with negative bit_offsets (-8)")
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
it "should complain about negative or zero bit_sizes with data_types other than STRING and BLOCK" do
|
|
704
|
+
lambda { BinaryAccessor.write(0, 0, -8, :INT, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
705
|
+
lambda { BinaryAccessor.write(0, 0, -8, :UINT, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
706
|
+
lambda { BinaryAccessor.write(0, 0, -8, :FLOAT, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size -8 must be positive for data types other than :STRING and :BLOCK")
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
it "should write aligned strings" do
|
|
710
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
711
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
712
|
+
@expected_data = @baseline_data.clone
|
|
713
|
+
first_byte_index = bit_offset / 8
|
|
714
|
+
if first_byte_index > 0
|
|
715
|
+
@expected_data[0..(first_byte_index - 1)] = "\x00" * first_byte_index
|
|
716
|
+
end
|
|
717
|
+
BinaryAccessor.write(@baseline_data[first_byte_index..-1], bit_offset, (@data.length * 8) - bit_offset, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
718
|
+
@data.should eql(@expected_data)
|
|
719
|
+
end
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
it "should write variable length strings with a zero and negative bit_size" do
|
|
723
|
+
0.step(-(@baseline_data.length * 8), -8) do |bit_size|
|
|
724
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
725
|
+
@expected_data = @baseline_data.clone + ("\x00" * -(bit_size / 8))
|
|
726
|
+
BinaryAccessor.write(@baseline_data, 0, bit_size, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
727
|
+
@data.should eql(@expected_data)
|
|
728
|
+
end
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
it "should write strings with negative bit_offsets" do
|
|
732
|
+
BinaryAccessor.write(@baseline_data[14..15], -16, 16, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
733
|
+
@data.should eql(("\x00" * 14) + @baseline_data[14..15])
|
|
734
|
+
end
|
|
735
|
+
|
|
736
|
+
it "should complain about unaligned strings" do
|
|
737
|
+
lambda { BinaryAccessor.write('', 1, 32, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type STRING")
|
|
738
|
+
end
|
|
739
|
+
|
|
740
|
+
it "should write aligned blocks" do
|
|
741
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
742
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
743
|
+
@expected_data = @baseline_data.clone
|
|
744
|
+
first_byte_index = bit_offset / 8
|
|
745
|
+
if first_byte_index > 0
|
|
746
|
+
@expected_data[0..(first_byte_index - 1)] = "\x00" * first_byte_index
|
|
747
|
+
end
|
|
748
|
+
BinaryAccessor.write(@baseline_data[first_byte_index..-1], bit_offset, (@data.length * 8) - bit_offset, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
749
|
+
@data.should eql(@expected_data)
|
|
750
|
+
end
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
it "should write variable length blocks with a zero and negative bit_size" do
|
|
754
|
+
0.step(-(@data.length * 8), -8) do |bit_size|
|
|
755
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
756
|
+
@expected_data = @baseline_data.clone + ("\x00" * -(bit_size / 8))
|
|
757
|
+
BinaryAccessor.write(@baseline_data, 0, bit_size, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
758
|
+
@data.should eql(@expected_data)
|
|
759
|
+
end
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
it "should write blocks with negative bit_offsets" do
|
|
763
|
+
BinaryAccessor.write(@baseline_data[0..1], -16, 16, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
764
|
+
@data[-2..-1].should eql(@baseline_data[0..1])
|
|
765
|
+
end
|
|
766
|
+
|
|
767
|
+
it "should write a blank string with zero bit size" do
|
|
768
|
+
BinaryAccessor.write('', 0, 0, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
769
|
+
@data.should eql('')
|
|
770
|
+
end
|
|
771
|
+
|
|
772
|
+
it "should write a blank block with zero bit size" do
|
|
773
|
+
BinaryAccessor.write('', 0, 0, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
774
|
+
@data.should eql('')
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
it "should write a shorter string with zero bit size" do
|
|
778
|
+
BinaryAccessor.write("\x00\x00\x00\x00\x00\x00\x00\x00", 0, 0, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
779
|
+
@data.should eql("\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
it "should write a shorter block with zero bit size" do
|
|
783
|
+
BinaryAccessor.write("\x00\x00\x00\x00\x00\x00\x00\x00", 0, 0, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
784
|
+
@data.should eql("\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
it "should write a shorter string and zero fill to the given bit size" do
|
|
788
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
789
|
+
BinaryAccessor.write("\x01\x02\x03\x04\x05\x06\x07\x08", 0, 128, :STRING, @data, :BIG_ENDIAN, :ERROR)
|
|
790
|
+
@data.should eql("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
791
|
+
end
|
|
792
|
+
|
|
793
|
+
it "should write a shorter block and zero fill to the given bit size" do
|
|
794
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
795
|
+
BinaryAccessor.write("\x01\x02\x03\x04\x05\x06\x07\x08", 0, 128, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
|
|
796
|
+
@data.should eql("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
it "should complain about unaligned blocks" do
|
|
800
|
+
lambda { BinaryAccessor.write(@baseline_data, 7, 16, :BLOCK, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 7 is not byte aligned for data_type BLOCK")
|
|
801
|
+
end
|
|
802
|
+
|
|
803
|
+
it "should complain if write exceeds the size of the buffer" do
|
|
804
|
+
lambda { BinaryAccessor.write(@baseline_data, 8, 800, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "16 byte buffer insufficient to write STRING at bit_offset 8 with bit_size 800")
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
it "should write aligned 8-bit unsigned integers" do
|
|
808
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
809
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
810
|
+
byte_index = bit_offset / 8
|
|
811
|
+
BinaryAccessor.write(@baseline_data.getbyte(byte_index), bit_offset, 8, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
812
|
+
@data[byte_index..byte_index].should eq(@baseline_data[byte_index..byte_index])
|
|
813
|
+
end
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
it "should write aligned 8-bit signed integers" do
|
|
817
|
+
0.step((@data.length - 1) * 8, 8) do |bit_offset|
|
|
818
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
819
|
+
byte_index = bit_offset / 8
|
|
820
|
+
value = @baseline_data.getbyte(byte_index)
|
|
821
|
+
value = value - 256 if value >= 128
|
|
822
|
+
BinaryAccessor.write(value, bit_offset, 8, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
823
|
+
@data[byte_index..byte_index].should eql(@baseline_data[byte_index..byte_index])
|
|
824
|
+
end
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
describe "given big endian data" do
|
|
828
|
+
|
|
829
|
+
it "should write 1-bit unsigned integers" do
|
|
830
|
+
BinaryAccessor.write(0x1, 8, 1, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
831
|
+
BinaryAccessor.write(0x0, 9, 1, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
832
|
+
BinaryAccessor.write(0x1, 10, 1, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
833
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
834
|
+
end
|
|
835
|
+
|
|
836
|
+
it "should write 1-bit signed integers" do
|
|
837
|
+
BinaryAccessor.write(0x1, 8, 1, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
838
|
+
BinaryAccessor.write(0x0, 9, 1, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
839
|
+
BinaryAccessor.write(0x1, 10, 1, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
840
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
841
|
+
end
|
|
842
|
+
|
|
843
|
+
it "should write 7-bit unsigned integers" do
|
|
844
|
+
BinaryAccessor.write(0x40, 8, 7, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
845
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
846
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
847
|
+
BinaryAccessor.write(0x20, 3, 7, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
848
|
+
@data.should eql("\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
849
|
+
end
|
|
850
|
+
|
|
851
|
+
it "should write 7-bit signed integers" do
|
|
852
|
+
BinaryAccessor.write(-64, 8, 7, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
853
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
854
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
855
|
+
BinaryAccessor.write(32, 3, 7, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
856
|
+
@data.should eql("\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
it "should write 13-bit unsigned integers" do
|
|
860
|
+
BinaryAccessor.write(0x1C24, 30, 13, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
861
|
+
@data.should eql("\x00\x00\x00\x03\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
862
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
863
|
+
BinaryAccessor.write(0x0020, 1, 13, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
864
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
it "should write 13-bit signed integers" do
|
|
868
|
+
BinaryAccessor.write(-988, 30, 13, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
869
|
+
@data.should eql("\x00\x00\x00\x03\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
870
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
871
|
+
BinaryAccessor.write(32, 1, 13, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
872
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
it "should write aligned 16-bit unsigned integers" do
|
|
876
|
+
expected_array = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
877
|
+
index = 0
|
|
878
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
879
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 16, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
880
|
+
index += 1
|
|
881
|
+
end
|
|
882
|
+
@data.should eql(@baseline_data)
|
|
883
|
+
end
|
|
884
|
+
|
|
885
|
+
it "should write aligned 16-bit signed integers" do
|
|
886
|
+
expected_array = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
887
|
+
index = 0
|
|
888
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
889
|
+
expected = expected_array[index]
|
|
890
|
+
expected = expected - 2**16 if expected >= 2**15
|
|
891
|
+
BinaryAccessor.write(expected, bit_offset, 16, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
892
|
+
index += 1
|
|
893
|
+
end
|
|
894
|
+
@data.should eql(@baseline_data)
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
it "should write aligned 32-bit unsigned integers" do
|
|
898
|
+
expected_array = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
899
|
+
index = 0
|
|
900
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
901
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 32, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
902
|
+
index += 1
|
|
903
|
+
end
|
|
904
|
+
@data.should eql(@baseline_data)
|
|
905
|
+
end
|
|
906
|
+
|
|
907
|
+
it "should write aligned 32-bit signed integers" do
|
|
908
|
+
expected_array = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
909
|
+
index = 0
|
|
910
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
911
|
+
expected = expected_array[index]
|
|
912
|
+
expected = expected - 2**32 if expected >= 2**31
|
|
913
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 32, :INT, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
914
|
+
index += 1
|
|
915
|
+
end
|
|
916
|
+
@data.should eql(@baseline_data)
|
|
917
|
+
end
|
|
918
|
+
|
|
919
|
+
it "should write aligned 32-bit floats" do
|
|
920
|
+
expected_array = [-1.189360e-038, -3.139169e-036, 8.301067e-040, 1.086646e-031]
|
|
921
|
+
BinaryAccessor.write(expected_array[0], 0, 32, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
922
|
+
BinaryAccessor.write(expected_array[1], 32, 32, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
923
|
+
BinaryAccessor.write(expected_array[2], 64, 32, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
924
|
+
BinaryAccessor.write(expected_array[3], 96, 32, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
925
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-038).of(expected_array[0])
|
|
926
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-036).of(expected_array[1])
|
|
927
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-040).of(expected_array[2])
|
|
928
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-031).of(expected_array[3])
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
it "should write 37-bit unsigned integers" do
|
|
932
|
+
BinaryAccessor.write(0x8182838485 >> 3, 8, 37, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
933
|
+
BinaryAccessor.write(0x00090A0B0C, 67, 37, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
934
|
+
@data.should eql("\x00\x81\x82\x83\x84\x80\x00\x00\x00\x09\x0A\x0B\x0C\x00\x00\x00")
|
|
935
|
+
end
|
|
936
|
+
|
|
937
|
+
it "should write 37-bit signed integers" do
|
|
938
|
+
BinaryAccessor.write((0x8182838485 >> 3) - 2**37, 8, 37, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
939
|
+
BinaryAccessor.write(0x00090A0B0C, 67, 37, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
940
|
+
@data.should eql("\x00\x81\x82\x83\x84\x80\x00\x00\x00\x09\x0A\x0B\x0C\x00\x00\x00")
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
it "should write 63-bit unsigned integers" do
|
|
944
|
+
BinaryAccessor.write(0x8081828384858687 >> 1, 0, 63, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
945
|
+
BinaryAccessor.write(0x00090A0B0C0D0E0F, 65, 63, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
946
|
+
@data.should eql("\x80\x81\x82\x83\x84\x85\x86\x86\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F")
|
|
947
|
+
end
|
|
948
|
+
|
|
949
|
+
it "should write 63-bit signed integers" do
|
|
950
|
+
BinaryAccessor.write((0x8081828384858687 >> 1) - 2**63, 0, 63, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
951
|
+
BinaryAccessor.write(0x00090A0B0C0D0E0F, 65, 63, :INT, @data, :BIG_ENDIAN, :ERROR)
|
|
952
|
+
@data.should eql("\x80\x81\x82\x83\x84\x85\x86\x86\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F")
|
|
953
|
+
end
|
|
954
|
+
|
|
955
|
+
it "should write aligned 64-bit unsigned integers" do
|
|
956
|
+
expected_array = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
957
|
+
index = 0
|
|
958
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
959
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 64, :UINT, @data, :BIG_ENDIAN, :ERROR)
|
|
960
|
+
index += 1
|
|
961
|
+
end
|
|
962
|
+
@data.should eql(@baseline_data)
|
|
963
|
+
end
|
|
964
|
+
|
|
965
|
+
it "should write aligned 64-bit signed integers" do
|
|
966
|
+
expected_array = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
967
|
+
index = 0
|
|
968
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
969
|
+
expected = expected_array[index]
|
|
970
|
+
expected = expected - 2**64 if expected >= 2**63
|
|
971
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 64, :INT, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
972
|
+
index += 1
|
|
973
|
+
end
|
|
974
|
+
@data.should eql(@baseline_data)
|
|
975
|
+
end
|
|
976
|
+
|
|
977
|
+
it "should write aligned 64-bit floats" do
|
|
978
|
+
expected_array = [-3.116851e-306, 1.257060e-308]
|
|
979
|
+
BinaryAccessor.write(expected_array[0], 0, 64, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
980
|
+
BinaryAccessor.write(expected_array[1], 64, 64, :FLOAT, @data, :BIG_ENDIAN, :ERROR)
|
|
981
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-306).of(expected_array[0])
|
|
982
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-308).of(expected_array[1])
|
|
983
|
+
end
|
|
984
|
+
|
|
985
|
+
it "should complain about unaligned floats" do
|
|
986
|
+
lambda { BinaryAccessor.write(0.0, 17, 32, :FLOAT, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 17 is not byte aligned for data_type FLOAT")
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
it "should complain about mis-sized floats" do
|
|
990
|
+
lambda { BinaryAccessor.write(0.0, 0, 33, :FLOAT, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size is 33 but must be 32 or 64 for data_type FLOAT")
|
|
991
|
+
end
|
|
992
|
+
|
|
993
|
+
end # given big endian data
|
|
994
|
+
|
|
995
|
+
describe "given little endian data" do
|
|
996
|
+
|
|
997
|
+
it "should complain about ill-defined little endian bitfields" do
|
|
998
|
+
lambda { BinaryAccessor.write(0x1, 3, 7, :UINT, @data, :LITTLE_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "LITTLE_ENDIAN bitfield with bit_offset 3 and bit_size 7 is invalid")
|
|
999
|
+
end
|
|
1000
|
+
|
|
1001
|
+
it "should write 1-bit unsigned integers" do
|
|
1002
|
+
BinaryAccessor.write(0x1, 8, 1, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1003
|
+
BinaryAccessor.write(0x0, 9, 1, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1004
|
+
BinaryAccessor.write(0x1, 10, 1, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1005
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1006
|
+
end
|
|
1007
|
+
|
|
1008
|
+
it "should write 1-bit signed integers" do
|
|
1009
|
+
BinaryAccessor.write(0x1, 8, 1, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1010
|
+
BinaryAccessor.write(0x0, 9, 1, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1011
|
+
BinaryAccessor.write(0x1, 10, 1, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1012
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1013
|
+
end
|
|
1014
|
+
|
|
1015
|
+
it "should write 7-bit unsigned integers" do
|
|
1016
|
+
BinaryAccessor.write(0x40, 8, 7, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1017
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1018
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1019
|
+
BinaryAccessor.write(0x7F, 11, 7, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1020
|
+
@data.should eql("\xC0\x1F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1021
|
+
end
|
|
1022
|
+
|
|
1023
|
+
it "should write 7-bit signed integers" do
|
|
1024
|
+
BinaryAccessor.write(-64, 8, 7, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1025
|
+
@data.should eql("\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1026
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1027
|
+
BinaryAccessor.write(32, 11, 7, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1028
|
+
@data.should eql("\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1029
|
+
end
|
|
1030
|
+
|
|
1031
|
+
it "should write 13-bit unsigned integers" do
|
|
1032
|
+
BinaryAccessor.write(0x1C24, 30, 13, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1033
|
+
@data.should eql("\x00\x80\x84\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1034
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1035
|
+
BinaryAccessor.write(0x0020, 9, 13, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1036
|
+
@data.should eql("\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1037
|
+
end
|
|
1038
|
+
|
|
1039
|
+
it "should write 13-bit signed integers" do
|
|
1040
|
+
BinaryAccessor.write(-988, 30, 13, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1041
|
+
@data.should eql("\x00\x80\x84\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1042
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1043
|
+
BinaryAccessor.write(32, 9, 13, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1044
|
+
@data.should eql("\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1045
|
+
end
|
|
1046
|
+
|
|
1047
|
+
it "should write aligned 16-bit unsigned integers" do
|
|
1048
|
+
expected_array = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
1049
|
+
index = 0
|
|
1050
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
1051
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 16, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1052
|
+
index += 1
|
|
1053
|
+
end
|
|
1054
|
+
@data.should eql(@baseline_data)
|
|
1055
|
+
end
|
|
1056
|
+
|
|
1057
|
+
it "should write aligned 16-bit signed integers" do
|
|
1058
|
+
expected_array = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
1059
|
+
index = 0
|
|
1060
|
+
0.step((@data.length - 1) * 8, 16) do |bit_offset|
|
|
1061
|
+
expected = expected_array[index]
|
|
1062
|
+
expected = expected - 2**16 if expected >= 2**15
|
|
1063
|
+
BinaryAccessor.write(expected, bit_offset, 16, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1064
|
+
index += 1
|
|
1065
|
+
end
|
|
1066
|
+
@data.should eql(@baseline_data)
|
|
1067
|
+
end
|
|
1068
|
+
|
|
1069
|
+
it "should write aligned 32-bit unsigned integers" do
|
|
1070
|
+
expected_array = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
1071
|
+
index = 0
|
|
1072
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
1073
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 32, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1074
|
+
index += 1
|
|
1075
|
+
end
|
|
1076
|
+
@data.should eql(@baseline_data)
|
|
1077
|
+
end
|
|
1078
|
+
|
|
1079
|
+
it "should write aligned 32-bit signed integers" do
|
|
1080
|
+
expected_array = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
1081
|
+
index = 0
|
|
1082
|
+
0.step((@data.length - 1) * 8, 32) do |bit_offset|
|
|
1083
|
+
expected = expected_array[index]
|
|
1084
|
+
expected = expected - 2**32 if expected >= 2**31
|
|
1085
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 32, :INT, @data, :LITTLE_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1086
|
+
index += 1
|
|
1087
|
+
end
|
|
1088
|
+
@data.should eql(@baseline_data)
|
|
1089
|
+
end
|
|
1090
|
+
|
|
1091
|
+
it "should write aligned 32-bit floats" do
|
|
1092
|
+
expected_array = [-7.670445e-037, -2.024055e-034, 2.658460e-032, 7.003653e-030]
|
|
1093
|
+
BinaryAccessor.write(expected_array[0], 0, 32, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1094
|
+
BinaryAccessor.write(expected_array[1], 32, 32, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1095
|
+
BinaryAccessor.write(expected_array[2], 64, 32, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1096
|
+
BinaryAccessor.write(expected_array[3], 96, 32, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1097
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-037).of(expected_array[0])
|
|
1098
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-034).of(expected_array[1])
|
|
1099
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-032).of(expected_array[2])
|
|
1100
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-030).of(expected_array[3])
|
|
1101
|
+
end
|
|
1102
|
+
|
|
1103
|
+
it "should write 37-bit unsigned integers" do
|
|
1104
|
+
BinaryAccessor.write(0x1584838281, 43, 37, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1105
|
+
BinaryAccessor.write(0x0C0B0A0900 >> 3, 96, 37, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1106
|
+
@data.should eql("\x00\x81\x82\x83\x84\x15\x00\x00\x00\x09\x0A\x0B\x0C\x00\x00\x00")
|
|
1107
|
+
end
|
|
1108
|
+
|
|
1109
|
+
it "should write 37-bit signed integers" do
|
|
1110
|
+
BinaryAccessor.write(0x1584838281 - 2**37, 43, 37, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1111
|
+
BinaryAccessor.write(0x0C0B0A0900 >> 3, 96, 37, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1112
|
+
@data.should eql("\x00\x81\x82\x83\x84\x15\x00\x00\x00\x09\x0A\x0B\x0C\x00\x00\x00")
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
it "should write 63-bit unsigned integers" do
|
|
1116
|
+
BinaryAccessor.write(0x4786858483828180, 57, 63, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1117
|
+
BinaryAccessor.write(0x0F0E0D0C0B0A0900 >> 1, 120, 63, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1118
|
+
@data.should eql("\x80\x81\x82\x83\x84\x85\x86\x47\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F")
|
|
1119
|
+
end
|
|
1120
|
+
|
|
1121
|
+
it "should write 63-bit signed integers" do
|
|
1122
|
+
BinaryAccessor.write(0x4786858483828180 - 2**63, 57, 63, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1123
|
+
BinaryAccessor.write(0x0F0E0D0C0B0A0900 >> 1, 120, 63, :INT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1124
|
+
@data.should eql("\x80\x81\x82\x83\x84\x85\x86\x47\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F")
|
|
1125
|
+
end
|
|
1126
|
+
|
|
1127
|
+
it "should write aligned 64-bit unsigned integers" do
|
|
1128
|
+
expected_array = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
1129
|
+
index = 0
|
|
1130
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
1131
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 64, :UINT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1132
|
+
index += 1
|
|
1133
|
+
end
|
|
1134
|
+
@data.should eql(@baseline_data)
|
|
1135
|
+
end
|
|
1136
|
+
|
|
1137
|
+
it "should write aligned 64-bit signed integers" do
|
|
1138
|
+
expected_array = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
1139
|
+
index = 0
|
|
1140
|
+
0.step((@data.length - 1) * 8, 64) do |bit_offset|
|
|
1141
|
+
expected = expected_array[index]
|
|
1142
|
+
expected = expected - 2**64 if expected >= 2**63
|
|
1143
|
+
BinaryAccessor.write(expected_array[index], bit_offset, 64, :INT, @data, :LITTLE_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1144
|
+
index += 1
|
|
1145
|
+
end
|
|
1146
|
+
@data.should eql(@baseline_data)
|
|
1147
|
+
end
|
|
1148
|
+
|
|
1149
|
+
it "should write aligned 64-bit floats" do
|
|
1150
|
+
expected_array = [-2.081577e-272, 3.691916e-236]
|
|
1151
|
+
BinaryAccessor.write(expected_array[0], 0, 64, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1152
|
+
BinaryAccessor.write(expected_array[1], 64, 64, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1153
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-272).of(expected_array[0])
|
|
1154
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-236).of(expected_array[1])
|
|
1155
|
+
end
|
|
1156
|
+
|
|
1157
|
+
it "should complain about unaligned floats" do
|
|
1158
|
+
lambda { BinaryAccessor.write(0.0, 1, 32, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type FLOAT")
|
|
1159
|
+
end
|
|
1160
|
+
|
|
1161
|
+
it "should complain about mis-sized floats" do
|
|
1162
|
+
lambda { BinaryAccessor.write(0.0, 0, 65, :FLOAT, @data, :LITTLE_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size is 65 but must be 32 or 64 for data_type FLOAT")
|
|
1163
|
+
end
|
|
1164
|
+
|
|
1165
|
+
end # given little endian data
|
|
1166
|
+
|
|
1167
|
+
describe "should support overflow types" do
|
|
1168
|
+
before(:each) do
|
|
1169
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
it "should prevent overflow of STRING" do
|
|
1173
|
+
lambda { BinaryAccessor.write("abcde", 0, 32, :STRING, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of 5 bytes does not fit into 4 bytes for data_type STRING")
|
|
1174
|
+
end
|
|
1175
|
+
|
|
1176
|
+
it "should prevent overflow of BLOCK" do
|
|
1177
|
+
lambda { BinaryAccessor.write("abcde", 0, 32, :BLOCK, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of 5 bytes does not fit into 4 bytes for data_type BLOCK")
|
|
1178
|
+
end
|
|
1179
|
+
|
|
1180
|
+
it "should prevent overflow of 8-bit INT" do
|
|
1181
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1182
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1183
|
+
value = -(value + 1)
|
|
1184
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1185
|
+
end
|
|
1186
|
+
|
|
1187
|
+
it "should prevent overflow of 16-bit INT" do
|
|
1188
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1189
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1190
|
+
value = -(value + 1)
|
|
1191
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1192
|
+
end
|
|
1193
|
+
|
|
1194
|
+
it "should prevent overflow of 32-bit INT" do
|
|
1195
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1196
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1197
|
+
value = -(value + 1)
|
|
1198
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1199
|
+
end
|
|
1200
|
+
|
|
1201
|
+
it "should prevent overflow of 64-bit INT" do
|
|
1202
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1203
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1204
|
+
value = -(value + 1)
|
|
1205
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1206
|
+
end
|
|
1207
|
+
|
|
1208
|
+
it "should prevent overflow of 3-bit INT" do
|
|
1209
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1210
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1211
|
+
value = -(value + 1)
|
|
1212
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1213
|
+
end
|
|
1214
|
+
|
|
1215
|
+
it "should prevent overflow of 8-bit UINT" do
|
|
1216
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size
|
|
1217
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1218
|
+
value = -1
|
|
1219
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
it "should prevent overflow of 16-bit UINT" do
|
|
1223
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size
|
|
1224
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1225
|
+
value = -1
|
|
1226
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1227
|
+
end
|
|
1228
|
+
|
|
1229
|
+
it "should prevent overflow of 32-bit UINT" do
|
|
1230
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size
|
|
1231
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1232
|
+
value = -1
|
|
1233
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1234
|
+
end
|
|
1235
|
+
|
|
1236
|
+
it "should prevent overflow of 64-bit UINT" do
|
|
1237
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size
|
|
1238
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1239
|
+
value = -1
|
|
1240
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1241
|
+
end
|
|
1242
|
+
|
|
1243
|
+
it "should prevent overflow of 3-bit UINT" do
|
|
1244
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size
|
|
1245
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1246
|
+
value = -1
|
|
1247
|
+
lambda { BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1248
|
+
end
|
|
1249
|
+
|
|
1250
|
+
it "should truncate STRING" do
|
|
1251
|
+
BinaryAccessor.write("abcde", 0, 32, :STRING, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1252
|
+
@data[0..4].should eql "abcd\x00"
|
|
1253
|
+
end
|
|
1254
|
+
|
|
1255
|
+
it "should truncate BLOCK" do
|
|
1256
|
+
BinaryAccessor.write("abcde", 0, 32, :BLOCK, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1257
|
+
@data[0..4].should eql "abcd\x00"
|
|
1258
|
+
end
|
|
1259
|
+
|
|
1260
|
+
it "should truncate 8-bit INT" do
|
|
1261
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1262
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1263
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1266
|
+
it "should truncate 16-bit INT" do
|
|
1267
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1268
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1269
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1270
|
+
end
|
|
1271
|
+
|
|
1272
|
+
it "should truncate 32-bit INT" do
|
|
1273
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1274
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1275
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1276
|
+
end
|
|
1277
|
+
|
|
1278
|
+
it "should truncate 64-bit INT" do
|
|
1279
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1280
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1281
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1282
|
+
end
|
|
1283
|
+
|
|
1284
|
+
it "should truncate 3-bit INT" do
|
|
1285
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1286
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1287
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1288
|
+
end
|
|
1289
|
+
|
|
1290
|
+
it "should truncate 8-bit UINT" do
|
|
1291
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1292
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1293
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1294
|
+
end
|
|
1295
|
+
|
|
1296
|
+
it "should truncate 16-bit UINT" do
|
|
1297
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1298
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1299
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1300
|
+
end
|
|
1301
|
+
|
|
1302
|
+
it "should truncate 32-bit UINT" do
|
|
1303
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1304
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1305
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1306
|
+
end
|
|
1307
|
+
|
|
1308
|
+
it "should truncate 64-bit UINT" do
|
|
1309
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1310
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1311
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1312
|
+
end
|
|
1313
|
+
|
|
1314
|
+
it "should truncate 3-bit UINT" do
|
|
1315
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1316
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1317
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
it "should saturate 8-bit INT" do
|
|
1321
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1322
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1323
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1324
|
+
value = -(value + 1); saturated_value = value + 1
|
|
1325
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1326
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1327
|
+
end
|
|
1328
|
+
|
|
1329
|
+
it "should saturate 16-bit INT" do
|
|
1330
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1331
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1332
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1333
|
+
value = -(value + 1); saturated_value = value + 1
|
|
1334
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1335
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1336
|
+
end
|
|
1337
|
+
|
|
1338
|
+
it "should saturate 32-bit INT" do
|
|
1339
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1340
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1341
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1342
|
+
value = -(value + 1); saturated_value = value + 1
|
|
1343
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1344
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1345
|
+
end
|
|
1346
|
+
|
|
1347
|
+
it "should saturate 64-bit INT" do
|
|
1348
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1349
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1350
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1351
|
+
value = -(value + 1); saturated_value = value + 1
|
|
1352
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1353
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1354
|
+
end
|
|
1355
|
+
|
|
1356
|
+
it "should saturate 3-bit INT" do
|
|
1357
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1358
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1359
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1360
|
+
value = -(value + 1); saturated_value = value + 1
|
|
1361
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1362
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1363
|
+
end
|
|
1364
|
+
|
|
1365
|
+
it "should saturate 8-bit UINT" do
|
|
1366
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
1367
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1368
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1369
|
+
value = -1; saturated_value = 0
|
|
1370
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1371
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1372
|
+
end
|
|
1373
|
+
|
|
1374
|
+
it "should saturate 16-bit UINT" do
|
|
1375
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
1376
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1377
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1378
|
+
value = -1; saturated_value = 0
|
|
1379
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1380
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1381
|
+
end
|
|
1382
|
+
|
|
1383
|
+
it "should saturate 32-bit UINT" do
|
|
1384
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
1385
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1386
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1387
|
+
value = -1; saturated_value = 0
|
|
1388
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1389
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1390
|
+
end
|
|
1391
|
+
|
|
1392
|
+
it "should saturate 64-bit UINT" do
|
|
1393
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
1394
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1395
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1396
|
+
value = -1; saturated_value = 0
|
|
1397
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1398
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1399
|
+
end
|
|
1400
|
+
|
|
1401
|
+
it "should saturate 3-bit UINT" do
|
|
1402
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
1403
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1404
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1405
|
+
value = -1; saturated_value = 0
|
|
1406
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :SATURATE)
|
|
1407
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1408
|
+
end
|
|
1409
|
+
|
|
1410
|
+
it "should allow hex value entry of 8-bit INT" do
|
|
1411
|
+
bit_size = 8; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
1412
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1413
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
1414
|
+
end
|
|
1415
|
+
|
|
1416
|
+
it "should allow hex value entry of 16-bit INT" do
|
|
1417
|
+
bit_size = 16; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
1418
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1419
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
1420
|
+
end
|
|
1421
|
+
|
|
1422
|
+
it "should allow hex value entry of 32-bit INT" do
|
|
1423
|
+
bit_size = 32; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
1424
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1425
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
1426
|
+
end
|
|
1427
|
+
|
|
1428
|
+
it "should allow hex value entry of 64-bit INT" do
|
|
1429
|
+
bit_size = 64; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
1430
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1431
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
1432
|
+
end
|
|
1433
|
+
|
|
1434
|
+
it "should allow hex value entry of 3-bit INT" do
|
|
1435
|
+
bit_size = 3; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
1436
|
+
BinaryAccessor.write(value, 0, bit_size, data_type, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
1437
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
1438
|
+
end
|
|
1439
|
+
|
|
1440
|
+
end
|
|
1441
|
+
|
|
1442
|
+
end # describe "write"
|
|
1443
|
+
|
|
1444
|
+
describe "write_array" do
|
|
1445
|
+
before(:each) do
|
|
1446
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1447
|
+
@data_array = []
|
|
1448
|
+
@data.length.times {|i| @data_array << @data[i] }
|
|
1449
|
+
@baseline_data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
1450
|
+
@baseline_data_array = []
|
|
1451
|
+
@baseline_data.length.times {|i| @baseline_data_array << @baseline_data[i] }
|
|
1452
|
+
end
|
|
1453
|
+
|
|
1454
|
+
it "should complain about value other than Array" do
|
|
1455
|
+
lambda { BinaryAccessor.write_array("", 0, 32, :STRING, 0, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "values must be an Array type class is String")
|
|
1456
|
+
end
|
|
1457
|
+
|
|
1458
|
+
it "should complain about unrecognized data types" do
|
|
1459
|
+
lambda { BinaryAccessor.write_array([0], 0, 32, :BLOB, 0, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "data_type BLOB is not recognized")
|
|
1460
|
+
end
|
|
1461
|
+
|
|
1462
|
+
it "should complain about bit_offsets before the beginning of the buffer" do
|
|
1463
|
+
expect { BinaryAccessor.write_array([''], -((@data.length * 8) + 8), 32, :STRING, 0, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "#{@data.length} byte buffer insufficient to write STRING at bit_offset #{-((@data.length * 8) + 8)} with bit_size 32")
|
|
1464
|
+
end
|
|
1465
|
+
|
|
1466
|
+
it "should write if a negative bit_offset is equal to length of buffer" do
|
|
1467
|
+
BinaryAccessor.write_array(@baseline_data_array, -(@data.length * 8), 8, :BLOCK, @baseline_data_array.length*8, @data, :BIG_ENDIAN, :ERROR)
|
|
1468
|
+
@data.should eql @baseline_data
|
|
1469
|
+
end
|
|
1470
|
+
|
|
1471
|
+
it "should complain about a negative or zero bit_size" do
|
|
1472
|
+
expect { BinaryAccessor.write_array([''], 0, 0, :STRING, 0, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "bit_size 0 must be positive for arrays")
|
|
1473
|
+
expect { BinaryAccessor.write_array([''], 0, -8, :STRING, 0, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "bit_size -8 must be positive for arrays")
|
|
1474
|
+
end
|
|
1475
|
+
|
|
1476
|
+
it "should write aligned strings with fixed array_size" do
|
|
1477
|
+
data = @data.clone
|
|
1478
|
+
BinaryAccessor.write_array(@baseline_data_array, 0, 8, :STRING, @baseline_data_array.length*8, data, :BIG_ENDIAN, :ERROR)
|
|
1479
|
+
data.should eql(@baseline_data)
|
|
1480
|
+
end
|
|
1481
|
+
|
|
1482
|
+
it "should write aligned strings with zero array_size" do
|
|
1483
|
+
BinaryAccessor.write_array(@baseline_data_array, 0, 8, :STRING, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1484
|
+
@data.should eql(@baseline_data)
|
|
1485
|
+
end
|
|
1486
|
+
|
|
1487
|
+
it "should write strings with negative bit_offsets" do
|
|
1488
|
+
BinaryAccessor.write_array(@baseline_data_array[14..15], -16, 8, :STRING, 16, @data, :BIG_ENDIAN, :ERROR)
|
|
1489
|
+
@data.should eql(("\x00" * 14) + @baseline_data[14..15])
|
|
1490
|
+
end
|
|
1491
|
+
|
|
1492
|
+
it "should complain about unaligned strings" do
|
|
1493
|
+
expect { BinaryAccessor.write_array([], 1, 32, :STRING, 32, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type STRING")
|
|
1494
|
+
end
|
|
1495
|
+
|
|
1496
|
+
it "should complain if pass more values than the given array_size can hold" do
|
|
1497
|
+
expect { BinaryAccessor.write_array(@baseline_data_array, 0, 8, :BLOCK, 32, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "too many values #{@baseline_data_array.length} for given array_size 32 and bit_size 8")
|
|
1498
|
+
end
|
|
1499
|
+
|
|
1500
|
+
it "should write blocks with fixed array_size" do
|
|
1501
|
+
BinaryAccessor.write_array(@baseline_data_array, 0, 8, :BLOCK, @baseline_data_array.length*8, @data, :BIG_ENDIAN, :ERROR)
|
|
1502
|
+
@data.should eql(@baseline_data)
|
|
1503
|
+
end
|
|
1504
|
+
|
|
1505
|
+
it "should zero fill if array_size > number of values passed" do
|
|
1506
|
+
data = @baseline_data.clone
|
|
1507
|
+
BinaryAccessor.write_array(["\x01","\x02","\x03","\x04"], 0, 8, :BLOCK, 64, @baseline_data, :BIG_ENDIAN, :ERROR)
|
|
1508
|
+
@baseline_data.should eql("\x01\x02\x03\x04" + "\x00" * 4 + data[8..-1])
|
|
1509
|
+
end
|
|
1510
|
+
|
|
1511
|
+
it "should write blocks with fixed array_size at non zero offset" do
|
|
1512
|
+
BinaryAccessor.write_array(@baseline_data_array[0..-5], 32, 8, :BLOCK, @baseline_data_array.length*8-32, @data, :BIG_ENDIAN, :ERROR)
|
|
1513
|
+
@data.should eql(("\x00" * 4) + @baseline_data[0..-5])
|
|
1514
|
+
end
|
|
1515
|
+
|
|
1516
|
+
it "should write blocks with zero array_size" do
|
|
1517
|
+
BinaryAccessor.write_array(@baseline_data_array, 0, 8, :BLOCK, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1518
|
+
@data.should eql(@baseline_data)
|
|
1519
|
+
end
|
|
1520
|
+
|
|
1521
|
+
it "should write blocks with negative bit_offsets" do
|
|
1522
|
+
BinaryAccessor.write_array(["\x80\x81","\x82\x83"], -32, 16, :BLOCK, 32, @data, :BIG_ENDIAN, :ERROR)
|
|
1523
|
+
@data.should eql(("\x00" * 12) + @baseline_data[0..3])
|
|
1524
|
+
end
|
|
1525
|
+
|
|
1526
|
+
it "should complain with an array_size not a multiple of bit_size" do
|
|
1527
|
+
data = @data.unpack('C*')
|
|
1528
|
+
expect { BinaryAccessor.write_array([1,2], 0, 8, :UINT, 10, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "array_size 10 not a multiple of bit_size 8")
|
|
1529
|
+
end
|
|
1530
|
+
|
|
1531
|
+
it "should complain with an array_size not a multiple of bit_size" do
|
|
1532
|
+
data = @data.unpack('C*')
|
|
1533
|
+
expect { BinaryAccessor.write_array([1,2], 0, 8, :UINT, -10, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "array_size -10 not a multiple of bit_size 8")
|
|
1534
|
+
end
|
|
1535
|
+
|
|
1536
|
+
it "should exclude the remaining bits if array_size is negative" do
|
|
1537
|
+
data = @data.clone
|
|
1538
|
+
BinaryAccessor.write_array(@baseline_data_array[0..-5], 0, 8, :BLOCK, -32, @data, :BIG_ENDIAN, :ERROR)
|
|
1539
|
+
@data.should eql(@baseline_data[0..-5] + data[-4..-1])
|
|
1540
|
+
end
|
|
1541
|
+
|
|
1542
|
+
it "should not write if the offset equals the negative array size" do
|
|
1543
|
+
data = @data.clone
|
|
1544
|
+
BinaryAccessor.write_array([], @data.length*8-32, 8, :BLOCK, -32, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1545
|
+
@data.should eql(data)
|
|
1546
|
+
end
|
|
1547
|
+
|
|
1548
|
+
it "should expand the buffer to handle negative array size" do
|
|
1549
|
+
@data = "\x00\x01\x02\x00\x03"
|
|
1550
|
+
BinaryAccessor.write_array([1,2,3,4], 0, 32, :UINT, -8, @data, :BIG_ENDIAN, :ERROR)
|
|
1551
|
+
@data.should eql("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x03")
|
|
1552
|
+
end
|
|
1553
|
+
|
|
1554
|
+
it "should shrink the buffer when handling negative array size" do
|
|
1555
|
+
# Start with one array item
|
|
1556
|
+
@data = "\x00\x01\x02\x00\x03"
|
|
1557
|
+
# Goto 4 array items array item
|
|
1558
|
+
BinaryAccessor.write_array([1,2,3,4], 0, 32, :UINT, -8, @data, :BIG_ENDIAN, :ERROR)
|
|
1559
|
+
@data.should eql("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x03")
|
|
1560
|
+
# Goto 2 array items
|
|
1561
|
+
BinaryAccessor.write_array([1,2], 0, 32, :UINT, -8, @data, :BIG_ENDIAN, :ERROR)
|
|
1562
|
+
@data.should eql("\x00\x00\x00\x01\x00\x00\x00\x02\x03")
|
|
1563
|
+
# Goto 0 array items
|
|
1564
|
+
BinaryAccessor.write_array([], 0, 32, :UINT, -8, @data, :BIG_ENDIAN, :ERROR)
|
|
1565
|
+
@data.should eql("\x03")
|
|
1566
|
+
# Go back to 1 array items
|
|
1567
|
+
BinaryAccessor.write_array([1], 0, 32, :UINT, -8, @data, :BIG_ENDIAN, :ERROR)
|
|
1568
|
+
@data.should eql("\x00\x00\x00\x01\x03")
|
|
1569
|
+
end
|
|
1570
|
+
|
|
1571
|
+
it "complain when passed a zero length buffer" do
|
|
1572
|
+
expect { BinaryAccessor.write_array([1,2,3], 0, 8, :UINT, 32, "", :LITTLE_ENDIAN, :ERROR) }.to raise_error(ArgumentError)
|
|
1573
|
+
end
|
|
1574
|
+
|
|
1575
|
+
it "should expand the buffer if the offset is greater than the negative array size" do
|
|
1576
|
+
offset = @data.length * 8 - 16
|
|
1577
|
+
data = @data.clone
|
|
1578
|
+
BinaryAccessor.write_array([1,2], offset, 8, :UINT, -32, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1579
|
+
@data.should eql(data[0..-3] + "\x01\x02" + data[-4..-1])
|
|
1580
|
+
end
|
|
1581
|
+
|
|
1582
|
+
it "should complain with negative bit_offset and zero array_size" do
|
|
1583
|
+
expect { BinaryAccessor.write_array([1,2], -32, 8, :UINT, 0, @data, :LITTLE_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "negative or zero array_size (0) cannot be given with negative bit_offset (-32)")
|
|
1584
|
+
end
|
|
1585
|
+
|
|
1586
|
+
it "should complain with negative array_size" do
|
|
1587
|
+
expect { BinaryAccessor.write_array([1,2], -32, 8, :UINT, -8, @data, :LITTLE_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "negative or zero array_size (-8) cannot be given with negative bit_offset (-32)")
|
|
1588
|
+
end
|
|
1589
|
+
|
|
1590
|
+
it "should write a shorter string and zero fill to the given bit size" do
|
|
1591
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
1592
|
+
BinaryAccessor.write_array(["\x01\x02","\x01\x02","\x01\x02","\x01\x02"], 0, 32, :STRING, 128, @data, :BIG_ENDIAN, :ERROR)
|
|
1593
|
+
@data.should eql("\x01\x02\x00\x00\x01\x02\x00\x00\x01\x02\x00\x00\x01\x02\x00\x00")
|
|
1594
|
+
end
|
|
1595
|
+
|
|
1596
|
+
it "should write a shorter string and zero fill to the given bit size" do
|
|
1597
|
+
@data = "\x80\x81\x82\x83\x84\x85\x86\x87\x00\x09\x0A\x0B\x0C\x0D\x0E\x0F"
|
|
1598
|
+
BinaryAccessor.write_array(["\x01\x02","\x01\x02","\x01\x02","\x01\x02"], 0, 32, :BLOCK, 128, @data, :BIG_ENDIAN, :ERROR)
|
|
1599
|
+
@data.should eql("\x01\x02\x00\x00\x01\x02\x00\x00\x01\x02\x00\x00\x01\x02\x00\x00")
|
|
1600
|
+
end
|
|
1601
|
+
|
|
1602
|
+
it "should complain about unaligned blocks" do
|
|
1603
|
+
lambda { BinaryAccessor.write_array(@baseline_data_array[0..1], 7, 16, :BLOCK, 32, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 7 is not byte aligned for data_type BLOCK")
|
|
1604
|
+
end
|
|
1605
|
+
|
|
1606
|
+
it "should complain if write exceeds the size of the buffer" do
|
|
1607
|
+
lambda { BinaryAccessor.write_array([], 8, 800, :STRING, 800, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "16 byte buffer insufficient to write STRING at bit_offset 8 with bit_size 800")
|
|
1608
|
+
end
|
|
1609
|
+
|
|
1610
|
+
it "should write aligned 8-bit unsigned integers" do
|
|
1611
|
+
data = @data.clone
|
|
1612
|
+
BinaryAccessor.write_array([0,1,2,3,4,5,255,255], 0, 8, :UINT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1613
|
+
@data.should eql("\x00\x01\x02\x03\x04\x05\xFF\xFF")
|
|
1614
|
+
end
|
|
1615
|
+
|
|
1616
|
+
it "should write aligned 8-bit signed integers" do
|
|
1617
|
+
data = @data.clone
|
|
1618
|
+
BinaryAccessor.write_array([0,1,2,3,4,5,-1,127], 0, 8, :INT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1619
|
+
@data.should eql("\x00\x01\x02\x03\x04\x05\xFF\x7F")
|
|
1620
|
+
end
|
|
1621
|
+
|
|
1622
|
+
it "should complain about unaligned strings" do
|
|
1623
|
+
expect { BinaryAccessor.write_array(['X'], 1, 32, :STRING, 32, @data, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type STRING")
|
|
1624
|
+
end
|
|
1625
|
+
|
|
1626
|
+
it "should write STRING items" do
|
|
1627
|
+
data = @baseline_data.clone
|
|
1628
|
+
BinaryAccessor.write_array(['a'], 0, 64, :STRING, 0, @baseline_data, :BIG_ENDIAN, :ERROR)
|
|
1629
|
+
@baseline_data.should eql("a\x00\x00\x00\x00\x00\x00\x00")
|
|
1630
|
+
end
|
|
1631
|
+
|
|
1632
|
+
it "should write BLOCK items" do
|
|
1633
|
+
BinaryAccessor.write_array(["\x01","\x02","\x03","\x04"], 0, 32, :BLOCK, 0, @baseline_data, :BIG_ENDIAN, :ERROR)
|
|
1634
|
+
@baseline_data.should eql("\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00")
|
|
1635
|
+
end
|
|
1636
|
+
|
|
1637
|
+
it "should write variable length arrays with a zero and negative array_size" do
|
|
1638
|
+
baseline_data_array_uint8 = []
|
|
1639
|
+
@baseline_data.length.times {|i| baseline_data_array_uint8 << @baseline_data[i].ord }
|
|
1640
|
+
0.step(-(@baseline_data.length * 8), -8) do |array_size|
|
|
1641
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1642
|
+
@expected_data = @baseline_data.clone + ("\x00" * -(array_size / 8))
|
|
1643
|
+
BinaryAccessor.write_array(baseline_data_array_uint8, 0, 8, :UINT, array_size, @data, :BIG_ENDIAN, :ERROR)
|
|
1644
|
+
@data.should eql(@expected_data)
|
|
1645
|
+
end
|
|
1646
|
+
end
|
|
1647
|
+
|
|
1648
|
+
it "should write variable length arrays or 32-bit UINTS with a zero and negative array_size" do
|
|
1649
|
+
baseline_data = "\x01\x01\x01\x01\x02\x02\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04"
|
|
1650
|
+
data_array_uint32 = [0x01010101, 0x02020202, 0x03030303, 0x04040404]
|
|
1651
|
+
0.step(-(baseline_data.length * 8), -8) do |array_size|
|
|
1652
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1653
|
+
@expected_data = baseline_data.clone + ("\x00" * -(array_size / 8))
|
|
1654
|
+
BinaryAccessor.write_array(data_array_uint32, 0, 32, :UINT, array_size, @data, :BIG_ENDIAN, :ERROR)
|
|
1655
|
+
@data.should eql(@expected_data)
|
|
1656
|
+
end
|
|
1657
|
+
end
|
|
1658
|
+
|
|
1659
|
+
it "should write variable length arrays of 32-bit UINTS with a zero and negative array_size and non-zero bit offset" do
|
|
1660
|
+
baseline_data = "\x01\x01\x01\x01\x02\x02\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04"
|
|
1661
|
+
data_array_uint32 = [0x01010101, 0x02020202, 0x03030303, 0x04040404]
|
|
1662
|
+
0.step(-(baseline_data.length * 8), -8) do |array_size|
|
|
1663
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1664
|
+
@expected_data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + baseline_data.clone + ("\x00" * -(array_size / 8))
|
|
1665
|
+
BinaryAccessor.write_array(data_array_uint32, 128, 32, :UINT, array_size, @data, :BIG_ENDIAN, :ERROR)
|
|
1666
|
+
@data.should eql(@expected_data)
|
|
1667
|
+
end
|
|
1668
|
+
end
|
|
1669
|
+
|
|
1670
|
+
it "should write variable length arrays of 32-bit UINTS with a zero and negative array_size and non-zero bit offset and grow the buffer" do
|
|
1671
|
+
baseline_data = "\x01\x01\x01\x01\x02\x02\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04"
|
|
1672
|
+
data_array_uint32 = [0x01010101, 0x02020202, 0x03030303, 0x04040404]
|
|
1673
|
+
0.step(-(baseline_data.length * 8), -8) do |array_size|
|
|
1674
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1675
|
+
@expected_data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + baseline_data.clone + ("\x00" * -(array_size / 8))
|
|
1676
|
+
BinaryAccessor.write_array(data_array_uint32, 128, 32, :UINT, array_size, @data, :BIG_ENDIAN, :ERROR)
|
|
1677
|
+
@data.should eql(@expected_data)
|
|
1678
|
+
end
|
|
1679
|
+
end
|
|
1680
|
+
|
|
1681
|
+
describe "given big endian data" do
|
|
1682
|
+
|
|
1683
|
+
it "should write 1-bit unsigned integers" do
|
|
1684
|
+
BinaryAccessor.write_array([1,0,1], 8, 1, :UINT, 3, @data, :BIG_ENDIAN, :ERROR)
|
|
1685
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1686
|
+
end
|
|
1687
|
+
|
|
1688
|
+
it "should write 1-bit signed integers" do
|
|
1689
|
+
BinaryAccessor.write_array([1,0,1], 8, 1, :INT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1690
|
+
@data.should eql("\x00\xA0")
|
|
1691
|
+
end
|
|
1692
|
+
|
|
1693
|
+
it "should write 7-bit unsigned integers" do
|
|
1694
|
+
BinaryAccessor.write_array([0x40,0x60,0x50], 8, 7, :UINT, 21, @data, :BIG_ENDIAN, :ERROR)
|
|
1695
|
+
@data.should eql("\x00\x81\x82\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1696
|
+
end
|
|
1697
|
+
|
|
1698
|
+
it "should write aligned 16-bit unsigned integers" do
|
|
1699
|
+
data = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
1700
|
+
BinaryAccessor.write_array(data, 0, 16, :UINT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1701
|
+
@data.should eql(@baseline_data)
|
|
1702
|
+
end
|
|
1703
|
+
|
|
1704
|
+
it "should write aligned 16-bit signed integers" do
|
|
1705
|
+
data = [0x8081, 0x8283, 0x8485, 0x8687, 0x0009, 0x0A0B, 0x0C0D, 0x0E0F]
|
|
1706
|
+
data.map! {|x| (x & ~(1 << 15)) - (x & (1 << 15)) } # convert to negative
|
|
1707
|
+
BinaryAccessor.write_array(data, 0, 16, :INT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1708
|
+
@data.should eql(@baseline_data)
|
|
1709
|
+
end
|
|
1710
|
+
|
|
1711
|
+
it "should write aligned 32-bit unsigned integers" do
|
|
1712
|
+
data = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
1713
|
+
BinaryAccessor.write_array(data, 0, 32, :UINT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1714
|
+
@data.should eql(@baseline_data)
|
|
1715
|
+
end
|
|
1716
|
+
|
|
1717
|
+
it "should write aligned 32-bit signed integers" do
|
|
1718
|
+
data = [0x80818283, 0x84858687, 0x00090A0B, 0x0C0D0E0F]
|
|
1719
|
+
data.map! {|x| (x & ~(1 << 31)) - (x & (1 << 31)) } # convert to negative
|
|
1720
|
+
BinaryAccessor.write_array(data, 0, 32, :INT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1721
|
+
@data.should eql(@baseline_data)
|
|
1722
|
+
end
|
|
1723
|
+
|
|
1724
|
+
it "should write aligned 32-bit floats" do
|
|
1725
|
+
data = [-1.189360e-038, -3.139169e-036, 8.301067e-040, 1.086646e-031]
|
|
1726
|
+
BinaryAccessor.write_array(data, 0, 32, :FLOAT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1727
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-038).of(data[0])
|
|
1728
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-036).of(data[1])
|
|
1729
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-040).of(data[2])
|
|
1730
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-031).of(data[3])
|
|
1731
|
+
end
|
|
1732
|
+
|
|
1733
|
+
it "should write aligned 64-bit unsigned integers" do
|
|
1734
|
+
data = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
1735
|
+
BinaryAccessor.write_array(data, 0, 64, :UINT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1736
|
+
@data.should eql(@baseline_data)
|
|
1737
|
+
end
|
|
1738
|
+
|
|
1739
|
+
it "should write aligned 64-bit signed integers" do
|
|
1740
|
+
data = [0x8081828384858687, 0x00090A0B0C0D0E0F]
|
|
1741
|
+
data.map! {|x| (x & ~(1 << 63)) - (x & (1 << 63)) } # convert to negative
|
|
1742
|
+
BinaryAccessor.write_array(data, 0, 64, :INT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1743
|
+
@data.should eql(@baseline_data)
|
|
1744
|
+
end
|
|
1745
|
+
|
|
1746
|
+
it "should write aligned 64-bit floats" do
|
|
1747
|
+
data = [-3.116851e-306, 1.257060e-308]
|
|
1748
|
+
BinaryAccessor.write_array(data, 0, 64, :FLOAT, 0, @data, :BIG_ENDIAN, :ERROR)
|
|
1749
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-306).of(data[0])
|
|
1750
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :BIG_ENDIAN).should be_within(1.0e-308).of(data[1])
|
|
1751
|
+
end
|
|
1752
|
+
|
|
1753
|
+
it "should complain about unaligned floats" do
|
|
1754
|
+
lambda { BinaryAccessor.write_array([0.0], 17, 32, :FLOAT, 32, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 17 is not byte aligned for data_type FLOAT")
|
|
1755
|
+
end
|
|
1756
|
+
|
|
1757
|
+
it "should complain about mis-sized floats" do
|
|
1758
|
+
lambda { BinaryAccessor.write_array([0.0], 0, 33, :FLOAT, 33, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size is 33 but must be 32 or 64 for data_type FLOAT")
|
|
1759
|
+
end
|
|
1760
|
+
|
|
1761
|
+
end # given big endian data
|
|
1762
|
+
|
|
1763
|
+
describe "given little endian data" do
|
|
1764
|
+
|
|
1765
|
+
it "should write 1-bit unsigned integers" do
|
|
1766
|
+
BinaryAccessor.write_array([1,0,1], 8, 1, :UINT, 3, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1767
|
+
@data.should eql("\x00\xA0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
1768
|
+
end
|
|
1769
|
+
|
|
1770
|
+
it "should write 1-bit signed integers" do
|
|
1771
|
+
BinaryAccessor.write_array([1,0,1], 8, 1, :INT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1772
|
+
@data.should eql("\x00\xA0")
|
|
1773
|
+
end
|
|
1774
|
+
|
|
1775
|
+
it "should complain about little endian bit-fields greater than 1-bit" do
|
|
1776
|
+
expect { BinaryAccessor.write_array([0x40,0x60,0x50], 8, 7, :UINT, 21, @data, :LITTLE_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "write_array does not support little endian bit fields with bit_size greater than 1-bit")
|
|
1777
|
+
end
|
|
1778
|
+
|
|
1779
|
+
it "should write aligned 16-bit unsigned integers" do
|
|
1780
|
+
data = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
1781
|
+
BinaryAccessor.write_array(data, 0, 16, :UINT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1782
|
+
@data.should eql(@baseline_data)
|
|
1783
|
+
end
|
|
1784
|
+
|
|
1785
|
+
it "should write aligned 16-bit signed integers" do
|
|
1786
|
+
data = [0x8180, 0x8382, 0x8584, 0x8786, 0x0900, 0x0B0A, 0x0D0C, 0x0F0E]
|
|
1787
|
+
data.map! {|x| (x & ~(1 << 15)) - (x & (1 << 15)) } # convert to negative
|
|
1788
|
+
BinaryAccessor.write_array(data, 0, 16, :INT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1789
|
+
@data.should eql(@baseline_data)
|
|
1790
|
+
end
|
|
1791
|
+
|
|
1792
|
+
it "should write aligned 32-bit unsigned integers" do
|
|
1793
|
+
data = [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
1794
|
+
BinaryAccessor.write_array(data, 0, 32, :UINT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1795
|
+
@data.should eql(@baseline_data)
|
|
1796
|
+
end
|
|
1797
|
+
|
|
1798
|
+
it "should write aligned 32-bit signed integers" do
|
|
1799
|
+
data= [0x83828180, 0x87868584, 0x0B0A0900, 0x0F0E0D0C]
|
|
1800
|
+
data.map! {|x| (x & ~(1 << 31)) - (x & (1 << 31)) } # convert to negative
|
|
1801
|
+
BinaryAccessor.write_array(data, 0, 32, :INT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1802
|
+
@data.should eql(@baseline_data)
|
|
1803
|
+
end
|
|
1804
|
+
|
|
1805
|
+
it "should write aligned 32-bit floats" do
|
|
1806
|
+
data = [-7.670445e-037, -2.024055e-034, 2.658460e-032, 7.003653e-030]
|
|
1807
|
+
BinaryAccessor.write_array(data, 0, 32, :FLOAT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1808
|
+
BinaryAccessor.read(0, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-037).of(data[0])
|
|
1809
|
+
BinaryAccessor.read(32, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-034).of(data[1])
|
|
1810
|
+
BinaryAccessor.read(64, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-032).of(data[2])
|
|
1811
|
+
BinaryAccessor.read(96, 32, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-030).of(data[3])
|
|
1812
|
+
end
|
|
1813
|
+
|
|
1814
|
+
it "should write aligned 64-bit unsigned integers" do
|
|
1815
|
+
data = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
1816
|
+
BinaryAccessor.write_array(data, 0, 64, :UINT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1817
|
+
@data.should eql(@baseline_data)
|
|
1818
|
+
end
|
|
1819
|
+
|
|
1820
|
+
it "should write aligned 64-bit signed integers" do
|
|
1821
|
+
data = [0x8786858483828180, 0x0F0E0D0C0B0A0900]
|
|
1822
|
+
data.map! {|x| (x & ~(1 << 63)) - (x & (1 << 63)) } # convert to negative
|
|
1823
|
+
BinaryAccessor.write_array(data, 0, 64, :INT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1824
|
+
@data.should eql(@baseline_data)
|
|
1825
|
+
end
|
|
1826
|
+
|
|
1827
|
+
it "should write aligned 64-bit floats" do
|
|
1828
|
+
data = [-2.081577e-272, 3.691916e-236]
|
|
1829
|
+
BinaryAccessor.write_array(data, 0, 64, :FLOAT, 0, @data, :LITTLE_ENDIAN, :ERROR)
|
|
1830
|
+
BinaryAccessor.read(0, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-272).of(data[0])
|
|
1831
|
+
BinaryAccessor.read(64, 64, :FLOAT, @data, :LITTLE_ENDIAN).should be_within(1.0e-236).of(data[1])
|
|
1832
|
+
end
|
|
1833
|
+
|
|
1834
|
+
it "should complain about unaligned floats" do
|
|
1835
|
+
lambda { BinaryAccessor.write_array([0.0], 1, 32, :FLOAT, 32, @data, :LITTLE_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_offset 1 is not byte aligned for data_type FLOAT")
|
|
1836
|
+
end
|
|
1837
|
+
|
|
1838
|
+
it "should complain about mis-sized floats" do
|
|
1839
|
+
lambda { BinaryAccessor.write_array([0.0], 0, 65, :FLOAT, 65, @data, :LITTLE_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "bit_size is 65 but must be 32 or 64 for data_type FLOAT")
|
|
1840
|
+
end
|
|
1841
|
+
|
|
1842
|
+
end # given little endian data
|
|
1843
|
+
|
|
1844
|
+
describe "should support overflow types" do
|
|
1845
|
+
before(:each) do
|
|
1846
|
+
@data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
1847
|
+
end
|
|
1848
|
+
|
|
1849
|
+
it "should prevent overflow of STRING" do
|
|
1850
|
+
lambda { BinaryAccessor.write_array(["abcde"], 0, 32, :STRING, 32, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of 5 bytes does not fit into 4 bytes for data_type STRING")
|
|
1851
|
+
end
|
|
1852
|
+
|
|
1853
|
+
it "should prevent overflow of BLOCK" do
|
|
1854
|
+
lambda { BinaryAccessor.write_array(["abcde"], 0, 32, :BLOCK, 32, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of 5 bytes does not fit into 4 bytes for data_type BLOCK")
|
|
1855
|
+
end
|
|
1856
|
+
|
|
1857
|
+
it "should prevent overflow of 8-bit INT" do
|
|
1858
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1859
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1860
|
+
end
|
|
1861
|
+
|
|
1862
|
+
it "should prevent overflow of 16-bit INT" do
|
|
1863
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1864
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1865
|
+
end
|
|
1866
|
+
|
|
1867
|
+
it "should prevent overflow of 32-bit INT" do
|
|
1868
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1869
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1870
|
+
end
|
|
1871
|
+
|
|
1872
|
+
it "should prevent overflow of 64-bit INT" do
|
|
1873
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1874
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1875
|
+
end
|
|
1876
|
+
|
|
1877
|
+
it "should prevent overflow of 3-bit INT" do
|
|
1878
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1)
|
|
1879
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1880
|
+
end
|
|
1881
|
+
|
|
1882
|
+
it "should prevent overflow of 8-bit UINT" do
|
|
1883
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size
|
|
1884
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1885
|
+
end
|
|
1886
|
+
|
|
1887
|
+
it "should prevent overflow of 16-bit UINT" do
|
|
1888
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size
|
|
1889
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1890
|
+
end
|
|
1891
|
+
|
|
1892
|
+
it "should prevent overflow of 32-bit UINT" do
|
|
1893
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size
|
|
1894
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1895
|
+
end
|
|
1896
|
+
|
|
1897
|
+
it "should prevent overflow of 64-bit UINT" do
|
|
1898
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size
|
|
1899
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1900
|
+
end
|
|
1901
|
+
|
|
1902
|
+
it "should prevent overflow of 3-bit UINT" do
|
|
1903
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size
|
|
1904
|
+
lambda { BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR) }.should raise_error(ArgumentError, "value of #{value} invalid for #{bit_size}-bit #{data_type}")
|
|
1905
|
+
end
|
|
1906
|
+
|
|
1907
|
+
it "should truncate STRING" do
|
|
1908
|
+
BinaryAccessor.write_array(["abcde"], 0, 32, :STRING, 32, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1909
|
+
@data[0..4].should eql "abcd\x00"
|
|
1910
|
+
end
|
|
1911
|
+
|
|
1912
|
+
it "should truncate BLOCK" do
|
|
1913
|
+
BinaryAccessor.write_array(["abcde"], 0, 32, :BLOCK, 32, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1914
|
+
@data[0..4].should eql "abcd\x00"
|
|
1915
|
+
end
|
|
1916
|
+
|
|
1917
|
+
it "should truncate 8-bit INT" do
|
|
1918
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1919
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1920
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1921
|
+
end
|
|
1922
|
+
|
|
1923
|
+
it "should truncate 16-bit INT" do
|
|
1924
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1925
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1926
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1927
|
+
end
|
|
1928
|
+
|
|
1929
|
+
it "should truncate 32-bit INT" do
|
|
1930
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1931
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1932
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1933
|
+
end
|
|
1934
|
+
|
|
1935
|
+
it "should truncate 64-bit INT" do
|
|
1936
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1937
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1938
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1939
|
+
end
|
|
1940
|
+
|
|
1941
|
+
it "should truncate 3-bit INT" do
|
|
1942
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1); truncated_value = -value
|
|
1943
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1944
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1945
|
+
end
|
|
1946
|
+
|
|
1947
|
+
it "should truncate 8-bit UINT" do
|
|
1948
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1949
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1950
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1951
|
+
end
|
|
1952
|
+
|
|
1953
|
+
it "should truncate 16-bit UINT" do
|
|
1954
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1955
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1956
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1957
|
+
end
|
|
1958
|
+
|
|
1959
|
+
it "should truncate 32-bit UINT" do
|
|
1960
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1961
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1962
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1963
|
+
end
|
|
1964
|
+
|
|
1965
|
+
it "should truncate 64-bit UINT" do
|
|
1966
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1967
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1968
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1969
|
+
end
|
|
1970
|
+
|
|
1971
|
+
it "should truncate 3-bit UINT" do
|
|
1972
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size + 1; truncated_value = 1
|
|
1973
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :TRUNCATE)
|
|
1974
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql truncated_value
|
|
1975
|
+
end
|
|
1976
|
+
|
|
1977
|
+
it "should saturate 8-bit INT" do
|
|
1978
|
+
bit_size = 8; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1979
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
1980
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1981
|
+
end
|
|
1982
|
+
|
|
1983
|
+
it "should saturate 16-bit INT" do
|
|
1984
|
+
bit_size = 16; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1985
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
1986
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1987
|
+
end
|
|
1988
|
+
|
|
1989
|
+
it "should saturate 32-bit INT" do
|
|
1990
|
+
bit_size = 32; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1991
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
1992
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1993
|
+
end
|
|
1994
|
+
|
|
1995
|
+
it "should saturate 64-bit INT" do
|
|
1996
|
+
bit_size = 64; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
1997
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
1998
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
1999
|
+
end
|
|
2000
|
+
|
|
2001
|
+
it "should saturate 3-bit INT" do
|
|
2002
|
+
bit_size = 3; data_type = :INT; value = 2 ** (bit_size - 1); saturated_value = value - 1
|
|
2003
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2004
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2005
|
+
end
|
|
2006
|
+
|
|
2007
|
+
it "should saturate 8-bit UINT" do
|
|
2008
|
+
bit_size = 8; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
2009
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2010
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2011
|
+
end
|
|
2012
|
+
|
|
2013
|
+
it "should saturate 16-bit UINT" do
|
|
2014
|
+
bit_size = 16; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
2015
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2016
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2017
|
+
end
|
|
2018
|
+
|
|
2019
|
+
it "should saturate 32-bit UINT" do
|
|
2020
|
+
bit_size = 32; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
2021
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2022
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2023
|
+
end
|
|
2024
|
+
|
|
2025
|
+
it "should saturate 64-bit UINT" do
|
|
2026
|
+
bit_size = 64; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
2027
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2028
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2029
|
+
end
|
|
2030
|
+
|
|
2031
|
+
it "should saturate 3-bit UINT" do
|
|
2032
|
+
bit_size = 3; data_type = :UINT; value = 2 ** bit_size; saturated_value = value - 1
|
|
2033
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :SATURATE)
|
|
2034
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql saturated_value
|
|
2035
|
+
end
|
|
2036
|
+
|
|
2037
|
+
it "should allow hex value entry of 8-bit INT" do
|
|
2038
|
+
bit_size = 8; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
2039
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
2040
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
2041
|
+
end
|
|
2042
|
+
|
|
2043
|
+
it "should allow hex value entry of 16-bit INT" do
|
|
2044
|
+
bit_size = 16; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
2045
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
2046
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
2047
|
+
end
|
|
2048
|
+
|
|
2049
|
+
it "should allow hex value entry of 32-bit INT" do
|
|
2050
|
+
bit_size = 32; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
2051
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
2052
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
2053
|
+
end
|
|
2054
|
+
|
|
2055
|
+
it "should allow hex value entry of 64-bit INT" do
|
|
2056
|
+
bit_size = 64; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
2057
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
2058
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
2059
|
+
end
|
|
2060
|
+
|
|
2061
|
+
it "should allow hex value entry of 3-bit INT" do
|
|
2062
|
+
bit_size = 3; data_type = :INT; value = 2 ** bit_size - 1; allowed_value = -1
|
|
2063
|
+
BinaryAccessor.write_array([value], 0, bit_size, data_type, bit_size, @data, :BIG_ENDIAN, :ERROR_ALLOW_HEX)
|
|
2064
|
+
BinaryAccessor.read(0, bit_size, data_type, @data, :BIG_ENDIAN).should eql allowed_value
|
|
2065
|
+
end
|
|
2066
|
+
|
|
2067
|
+
end
|
|
2068
|
+
|
|
2069
|
+
end # describe "write_array"
|
|
2070
|
+
|
|
2071
|
+
end # describe BinaryAccessor
|
|
2072
|
+
|
|
2073
|
+
end # module Cosmos
|