live_f1-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.autotest +23 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +65 -0
  6. data/Guardfile +11 -0
  7. data/README.rdoc +62 -0
  8. data/Rakefile +11 -0
  9. data/bin/live_f1_example +74 -0
  10. data/features/fixtures/sessions/2012.03.china.qualifying/7136/keyframes.yaml +32722 -0
  11. data/features/fixtures/sessions/2012.03.china.qualifying/7136/session.key +1 -0
  12. data/features/fixtures/sessions/2012.03.china.qualifying/session.bin +0 -0
  13. data/features/fixtures/sessions/2012.04.bahrain.practice.2/7164/keyframes.yaml +22403 -0
  14. data/features/fixtures/sessions/2012.04.bahrain.practice.2/7164/session.key +1 -0
  15. data/features/fixtures/sessions/2012.04.bahrain.practice.2/session.bin +0 -0
  16. data/features/fixtures/sessions/2012.05.bahrain.race.post/7167/keyframes.yaml +1204 -0
  17. data/features/fixtures/sessions/2012.05.bahrain.race.post/7167/session.key +1 -0
  18. data/features/fixtures/sessions/2012.05.bahrain.race.post/session.bin +0 -0
  19. data/features/live_f1.feature +14 -0
  20. data/features/step_definitions/live_f1_steps.rb +69 -0
  21. data/features/support/env.rb +9 -0
  22. data/lib/live_f1/debug.rb +6 -0
  23. data/lib/live_f1/enum.rb +9 -0
  24. data/lib/live_f1/event.rb +23 -0
  25. data/lib/live_f1/packet/car/best_lap_time.rb +10 -0
  26. data/lib/live_f1/packet/car/driver.rb +14 -0
  27. data/lib/live_f1/packet/car/gap.rb +10 -0
  28. data/lib/live_f1/packet/car/interval.rb +10 -0
  29. data/lib/live_f1/packet/car/lap_count.rb +10 -0
  30. data/lib/live_f1/packet/car/lap_time.rb +10 -0
  31. data/lib/live_f1/packet/car/num_pits.rb +10 -0
  32. data/lib/live_f1/packet/car/number.rb +14 -0
  33. data/lib/live_f1/packet/car/period_1.rb +11 -0
  34. data/lib/live_f1/packet/car/period_2.rb +11 -0
  35. data/lib/live_f1/packet/car/period_3.rb +11 -0
  36. data/lib/live_f1/packet/car/pit_count.rb +18 -0
  37. data/lib/live_f1/packet/car/pit_lap_1.rb +10 -0
  38. data/lib/live_f1/packet/car/pit_lap_2.rb +10 -0
  39. data/lib/live_f1/packet/car/pit_lap_3.rb +10 -0
  40. data/lib/live_f1/packet/car/position.rb +14 -0
  41. data/lib/live_f1/packet/car/position_history.rb +14 -0
  42. data/lib/live_f1/packet/car/position_update.rb +13 -0
  43. data/lib/live_f1/packet/car/sector_1.rb +11 -0
  44. data/lib/live_f1/packet/car/sector_2.rb +11 -0
  45. data/lib/live_f1/packet/car/sector_3.rb +11 -0
  46. data/lib/live_f1/packet/car.rb +13 -0
  47. data/lib/live_f1/packet/decryptable.rb +22 -0
  48. data/lib/live_f1/packet/header.rb +127 -0
  49. data/lib/live_f1/packet/sector_time.rb +28 -0
  50. data/lib/live_f1/packet/sys/commentary.rb +33 -0
  51. data/lib/live_f1/packet/sys/copyright.rb +9 -0
  52. data/lib/live_f1/packet/sys/key_frame.rb +17 -0
  53. data/lib/live_f1/packet/sys/notice.rb +10 -0
  54. data/lib/live_f1/packet/sys/reset.rb +9 -0
  55. data/lib/live_f1/packet/sys/session_start.rb +25 -0
  56. data/lib/live_f1/packet/sys/speed.rb +29 -0
  57. data/lib/live_f1/packet/sys/timestamp.rb +23 -0
  58. data/lib/live_f1/packet/sys/track_status.rb +18 -0
  59. data/lib/live_f1/packet/sys/weather.rb +33 -0
  60. data/lib/live_f1/packet/sys.rb +10 -0
  61. data/lib/live_f1/packet.rb +129 -0
  62. data/lib/live_f1/source/keyframe.rb +30 -0
  63. data/lib/live_f1/source/live.rb +163 -0
  64. data/lib/live_f1/source/log.rb +29 -0
  65. data/lib/live_f1/source/session.rb +41 -0
  66. data/lib/live_f1/source.rb +83 -0
  67. data/lib/live_f1/version.rb +3 -0
  68. data/lib/live_f1.rb +32 -0
  69. data/live_f1-core.gemspec +26 -0
  70. data/spec/live_f1/event_spec.rb +5 -0
  71. data/spec/live_f1/packet/car/best_lap_time_spec.rb +19 -0
  72. data/spec/live_f1/packet/car/driver_spec.rb +20 -0
  73. data/spec/live_f1/packet/car/gap_spec.rb +20 -0
  74. data/spec/live_f1/packet/car/interval_spec.rb +20 -0
  75. data/spec/live_f1/packet/car/lap_count_spec.rb +20 -0
  76. data/spec/live_f1/packet/car/lap_time_spec.rb +20 -0
  77. data/spec/live_f1/packet/car/number_spec.rb +20 -0
  78. data/spec/live_f1/packet/car/period_1_spec.rb +21 -0
  79. data/spec/live_f1/packet/car/period_2_spec.rb +21 -0
  80. data/spec/live_f1/packet/car/period_3_spec.rb +21 -0
  81. data/spec/live_f1/packet/car/pit_count_spec.rb +20 -0
  82. data/spec/live_f1/packet/car/pit_lap_1_spec.rb +20 -0
  83. data/spec/live_f1/packet/car/pit_lap_2_spec.rb +20 -0
  84. data/spec/live_f1/packet/car/pit_lap_3_spec.rb +20 -0
  85. data/spec/live_f1/packet/car/position_history_spec.rb +20 -0
  86. data/spec/live_f1/packet/car/position_spec.rb +20 -0
  87. data/spec/live_f1/packet/car/position_update_spec.rb +19 -0
  88. data/spec/live_f1/packet/car/sector_1_spec.rb +21 -0
  89. data/spec/live_f1/packet/car/sector_2_spec.rb +21 -0
  90. data/spec/live_f1/packet/car/sector_3_spec.rb +21 -0
  91. data/spec/live_f1/packet/header_spec.rb +148 -0
  92. data/spec/live_f1/packet/sys/commentary_spec.rb +45 -0
  93. data/spec/live_f1/packet/sys/copyright_spec.rb +19 -0
  94. data/spec/live_f1/packet/sys/key_frame_spec.rb +39 -0
  95. data/spec/live_f1/packet/sys/notice_spec.rb +20 -0
  96. data/spec/live_f1/packet/sys/reset_spec.rb +26 -0
  97. data/spec/live_f1/packet/sys/session_start_spec.rb +31 -0
  98. data/spec/live_f1/packet/sys/speed_spec.rb +20 -0
  99. data/spec/live_f1/packet/sys/timestamp_spec.rb +34 -0
  100. data/spec/live_f1/packet/sys/track_status_spec.rb +20 -0
  101. data/spec/live_f1/packet/sys/weather_spec.rb +20 -0
  102. data/spec/live_f1/packet_spec.rb +112 -0
  103. data/spec/live_f1/source/keyframe_spec.rb +56 -0
  104. data/spec/live_f1/source/live_spec.rb +106 -0
  105. data/spec/live_f1/source/session_spec.rb +39 -0
  106. data/spec/live_f1/source_spec.rb +140 -0
  107. data/spec/spec_helper.rb +10 -0
  108. data/spec/support/packet_type_examples.rb +122 -0
  109. metadata +337 -0
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/live_f1/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gareth Adams"]
6
+ gem.email = ["g@rethada.ms"]
7
+ gem.description = %q{Parses raw events from the Formula1.com live timing stream}
8
+ gem.summary = %q{LiveF1 provides an API to receive data from the official live timing servers. It uses the same data that's streamed to the live timing applet at www.formula1.com/live_timing - and needs you to have a corresponding account to decrypt the stream - but enables you to have a more fine-grained access to the numbers}
9
+ gem.homepage = "https://github.com/gareth/live_f1-core"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "live_f1-core"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = LiveF1::VERSION
17
+
18
+ gem.add_development_dependency "hpricot"
19
+ gem.add_development_dependency "rspec"
20
+ gem.add_development_dependency "cucumber"
21
+ gem.add_development_dependency "guard-rspec"
22
+ gem.add_development_dependency "guard-cucumber"
23
+ gem.add_development_dependency "growl"
24
+ gem.add_development_dependency "fakeweb"
25
+ gem.add_development_dependency "rb-fsevent"
26
+ end
@@ -0,0 +1,5 @@
1
+ require 'live_f1/event'
2
+
3
+ describe LiveF1::Event do
4
+
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::BestLapTime do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+
9
+ subject { packet }
10
+
11
+ let(:source) { mock(:source) }
12
+ let(:header) { mock(:header) }
13
+ let(:data) { "" }
14
+ let(:packet) do
15
+ packet = described_class.new(source, header)
16
+ packet.send :set_data, data
17
+ packet
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Driver do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Gap do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Interval do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::LapCount do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::LapTime do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Number do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Period1 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Period2 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Period3 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PitCount do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PitLap1 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PitLap2 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PitLap3 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PositionHistory do
7
+ it_behaves_like LiveF1::Packet::Type::Long
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Position do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::PositionUpdate do
7
+ it_behaves_like LiveF1::Packet::Type::Special
8
+
9
+ subject { packet }
10
+
11
+ let(:source) { mock(:source) }
12
+ let(:header) { mock(:header) }
13
+ let(:data) { "" }
14
+ let(:packet) do
15
+ packet = described_class.new(source, header)
16
+ packet.send :set_data, data
17
+ packet
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Sector1 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Sector2 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Car::Sector3 do
7
+ it_behaves_like LiveF1::Packet::Type::Short
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+ it_behaves_like LiveF1::Packet::SectorTime
10
+
11
+ subject { packet }
12
+
13
+ let(:source) { mock(:source) }
14
+ let(:header) { mock(:header) }
15
+ let(:data) { "" }
16
+ let(:packet) do
17
+ packet = described_class.new(source, header)
18
+ packet.send :set_data, data
19
+ packet
20
+ end
21
+ end
@@ -0,0 +1,148 @@
1
+ require 'live_f1/packet'
2
+ require 'live_f1/event'
3
+
4
+ describe LiveF1::Packet::Header do
5
+ describe "::from_source" do
6
+ let(:source) { mock("source") }
7
+ let(:event_type) { 13 }
8
+
9
+ it "reads 2 bytes from the source" do
10
+ described_class.stub(:new)
11
+
12
+ source.should_receive(:read_bytes).with(2) { " " }
13
+
14
+ described_class.from_source(source, nil)
15
+ end
16
+
17
+ it "generates a Header with the correct attributes" do
18
+ # Header data is packed into 2 bytes, little-endian (bytes reversed)
19
+ # MASK: bbbcccccaaaaaaab/bbb
20
+ # a: 0000001 = 1
21
+ # b: 0/011 = 3 (wrapped)
22
+ # c: 00111 = 7
23
+ bits = "0110011100000010"
24
+ source.stub(:read_bytes) { [bits].pack("B*") }
25
+
26
+ described_class.should_receive(:new).with(1, 3, 7, event_type) { stub("header") }
27
+
28
+ described_class.from_source(source, event_type)
29
+ end
30
+ end
31
+
32
+ describe "(constructor)" do
33
+ let(:header) { described_class.new(1, 2, 3, 4) }
34
+
35
+ it "assigns the data parameter" do
36
+ header.data.should == 1
37
+ end
38
+
39
+ it "assigns the packet type parameter" do
40
+ header.packet_type.should == 2
41
+ end
42
+
43
+ it "assigns the car parameter" do
44
+ header.car.should == 3
45
+ end
46
+
47
+ it "assigns the event type parameter" do
48
+ header.event_type.should == 4
49
+ end
50
+ end
51
+
52
+ describe "(instance_methods)" do
53
+ let(:data) { 1 }
54
+ let(:packet_type) { 2 }
55
+ let(:car) { 0 }
56
+ let(:instance) { described_class.new(data, packet_type, car) }
57
+
58
+ describe "#car?" do
59
+ it "is false when the car number is zero" do
60
+ described_class.new(data, packet_type, 0).car?.should == false
61
+ end
62
+
63
+ it "is true when the car number is nonzero" do
64
+ described_class.new(data, packet_type, 10).car?.should == true
65
+ end
66
+ end
67
+
68
+ describe "#packet_klass" do
69
+ context "for system packets" do
70
+ it "returns the class described by the header" do
71
+ described_class.new(data, 0, 0).packet_klass.should == LiveF1::Packet::Unknown
72
+ described_class.new(data, 1, 0).packet_klass.should == LiveF1::Packet::Sys::SessionStart
73
+ described_class.new(data, 2, 0).packet_klass.should == LiveF1::Packet::Sys::KeyFrame
74
+ described_class.new(data, 3, 0).packet_klass.should == LiveF1::Packet::Unknown
75
+ described_class.new(data, 4, 0).packet_klass.should == LiveF1::Packet::Sys::Commentary
76
+ described_class.new(data, 5, 0).packet_klass.should == LiveF1::Packet::Unknown
77
+ described_class.new(data, 6, 0).packet_klass.should == LiveF1::Packet::Sys::Notice
78
+ described_class.new(data, 7, 0).packet_klass.should == LiveF1::Packet::Sys::Timestamp
79
+ # described_class.new(data, 8, 0).packet_klass.should == LiveF1::Packet::Unknown
80
+ described_class.new(data, 9, 0).packet_klass.should == LiveF1::Packet::Sys::Weather
81
+ described_class.new(data, 10, 0).packet_klass.should == LiveF1::Packet::Sys::Speed
82
+ described_class.new(data, 11, 0).packet_klass.should == LiveF1::Packet::Sys::TrackStatus
83
+ described_class.new(data, 12, 0).packet_klass.should == LiveF1::Packet::Sys::Copyright
84
+ # described_class.new(data, 13, 0).packet_klass.should == LiveF1::Packet::Unknown
85
+ # described_class.new(data, 14, 0).packet_klass.should == LiveF1::Packet::Unknown
86
+ # described_class.new(data, 15, 0).packet_klass.should == LiveF1::Packet::Unknown
87
+ end
88
+ end
89
+
90
+ context "for car packets" do
91
+ it "raises an error if no event type is available" do
92
+ lambda { described_class.new(data, 0, 1).packet_klass }.should raise_error
93
+ end
94
+
95
+ it "returns the class described by the header" do
96
+ described_class.new(data, 0, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::PositionUpdate
97
+ described_class.new(data, 1, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Position
98
+ described_class.new(data, 2, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Number
99
+ described_class.new(data, 3, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Driver
100
+ described_class.new(data, 4, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Gap
101
+ described_class.new(data, 5, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Interval
102
+ described_class.new(data, 6, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::LapTime
103
+ described_class.new(data, 7, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Sector1
104
+ described_class.new(data, 8, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::PitLap1
105
+ described_class.new(data, 9, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Sector2
106
+ described_class.new(data, 10, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::PitLap2
107
+ described_class.new(data, 11, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::Sector3
108
+ described_class.new(data, 12, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::PitLap3
109
+ described_class.new(data, 13, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::NumPits
110
+ described_class.new(data, 15, 1, LiveF1::Event::RACE).packet_klass.should == LiveF1::Packet::Car::PositionHistory
111
+
112
+ described_class.new(data, 0, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::PositionUpdate
113
+ described_class.new(data, 1, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Position
114
+ described_class.new(data, 2, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Number
115
+ described_class.new(data, 3, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Driver
116
+ described_class.new(data, 4, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::BestLapTime
117
+ described_class.new(data, 5, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Gap
118
+ described_class.new(data, 6, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Sector1
119
+ described_class.new(data, 7, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Sector2
120
+ described_class.new(data, 8, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::Sector3
121
+ described_class.new(data, 9, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::LapCount
122
+
123
+ described_class.new(data, 0, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::PositionUpdate
124
+ described_class.new(data, 1, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Position
125
+ described_class.new(data, 2, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Number
126
+ described_class.new(data, 3, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Driver
127
+ described_class.new(data, 4, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Period1
128
+ described_class.new(data, 5, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Period2
129
+ described_class.new(data, 6, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Period3
130
+ described_class.new(data, 7, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Sector1
131
+ described_class.new(data, 8, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Sector2
132
+ described_class.new(data, 9, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::Sector3
133
+
134
+ pending "remaining packets" do
135
+ described_class.new(data, 15, 1, LiveF1::Event::PRACTICE).packet_klass.should == LiveF1::Packet::Car::PositionHistory
136
+
137
+ described_class.new(data, 10, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::LapCount
138
+ described_class.new(data, 15, 1, LiveF1::Event::QUALIFYING).packet_klass.should == LiveF1::Packet::Car::PositionHistory
139
+ end
140
+ end
141
+ end
142
+
143
+ it "raises an exception for an unexpected packet" do
144
+ expect { described_class.new(data, 16, car).packet_klass }.to raise_error(LiveF1::Packet::Header::UnexpectedPacket)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,45 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Sys::Commentary do
7
+ it_behaves_like LiveF1::Packet::Type::Long
8
+ it_behaves_like LiveF1::Packet::Decryptable
9
+
10
+ subject { packet }
11
+
12
+ let(:source) { mock(:source) }
13
+ let(:header) { mock(:header) }
14
+ let(:data) { "" }
15
+ let(:packet) do
16
+ packet = described_class.new(source, header)
17
+ packet.send :set_data, data
18
+ packet
19
+ end
20
+
21
+ describe "#terminal?" do
22
+ context "when the data contains a byte indicating terminality" do
23
+ let(:data) { "\x01\x01A commentary line without a subsequent line" }
24
+
25
+ it "marks the packet as terminal" do
26
+ subject.should be_terminal
27
+ end
28
+ end
29
+
30
+ context "when the data contains a byte indicating non-terminality" do
31
+ let(:data) { "\x01\x00A commentary line with a subsequent line" }
32
+
33
+ it "marks the packet as non-terminal" do
34
+ subject.should_not be_terminal
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#line" do
40
+ let(:data) { "\x01\x01A commentary line without a subsequent line" }
41
+ it "returns the data without the initial flags" do
42
+ subject.line.should == "A commentary line without a subsequent line"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'live_f1/packet'
2
+ require 'spec_helper'
3
+
4
+ extend PacketTypeExamples
5
+
6
+ describe LiveF1::Packet::Sys::Copyright do
7
+ it_behaves_like LiveF1::Packet::Type::Long
8
+
9
+ subject { packet }
10
+
11
+ let(:source) { mock(:source) }
12
+ let(:header) { mock(:header) }
13
+ let(:data) { "" }
14
+ let(:packet) do
15
+ packet = described_class.new(source, header)
16
+ packet.send :set_data, data
17
+ packet
18
+ end
19
+ end