flok 0.0.87 → 0.0.88

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efe6aff1ca42440bbac2069214724add409de0e8
4
- data.tar.gz: 9a0fd374f5b7787f71c6926e1502e287be3b96a6
3
+ metadata.gz: 7f7c1d58d114b65944fe9b7c0b93cf3f1add02ab
4
+ data.tar.gz: 3b56e5c4a6e7e99fbb8a6dc08100890141cbe934
5
5
  SHA512:
6
- metadata.gz: 0cda7f2305edd0b418dd09bd3b36bfd4ecfd69cec19a5a023ae5e0f84163d3dde95f1fe7b6ca8e78ad614e098cedacb7f29fc232ad431dd4a80d2daac3dbbb19
7
- data.tar.gz: bce8a88f827beb44dd3921d13c541c56fa1be3fa3230aaab9f79817336fa8efa8cc0095aba94f3285dd2c156f9916758f116f707418d4736f25b39c8b3c5b841
6
+ metadata.gz: f8df5aa50fea837620349c56c9910bd63b12bf66a823a7fbf80c24b8a71371c34c681effb071971d7ba421b1f11d28475a8665222f1c40b8491dc337835c1b56
7
+ data.tar.gz: 28957c4505e8e45fb166c0e1975c299e2469cdb18d5c07daff402f411b3cc63343bea482e5f8e1c3f82dfc93c539f4a525bd94fa03ebdb6f07257c702ac2266a
@@ -10,6 +10,7 @@ DEBUG:
10
10
  - sockio
11
11
  - persist
12
12
  - timer
13
+ - rtc
13
14
  defines:
14
15
  - mem_pager
15
16
  - sockio_pager
@@ -23,6 +24,7 @@ RELEASE:
23
24
  - sockio
24
25
  - persist
25
26
  - timer
27
+ - rtc
26
28
  defines:
27
29
  - mem_pager
28
30
  - sockio_pager
@@ -0,0 +1,9 @@
1
+ function rtc_callback() {
2
+ //Call timer interrupt
3
+ int_dispatch([0, "int_rtc", Math.floor(new Date() / 1000)]);
4
+ }
5
+
6
+ function if_rtc_init(tps) {
7
+ //Call timer 1 time per second
8
+ setInterval(rtc_callback, 1000.0);
9
+ }
@@ -1,6 +1,6 @@
1
1
  function timer_callback() {
2
2
  //Call timer interrupt
3
- int_dispatch([0, "int_timer"]);
3
+ int_dispatch([0, "int_timer"])
4
4
  }
5
5
 
6
6
  function if_timer_init(tps) {
@@ -0,0 +1,5 @@
1
+ __epoch__ = -1;
2
+
3
+ function int_rtc(epoch) {
4
+ __epoch__ = epoch;
5
+ }
data/app/kern/time.js ADDED
@@ -0,0 +1,4 @@
1
+ function time() {
2
+ //Usually defined in rtc
3
+ return __epoch__;
4
+ }
data/docs/kernel_api.md CHANGED
@@ -42,6 +42,9 @@ instead.
42
42
  ##Timers
43
43
  * See [./callout.md](Callout) for how to register a timer
44
44
 
45
+ ##Time
46
+ * `time()` - Returns the time in seconds since 1970 (unix epoch). Must have a compatible module, [`rtc`]
47
+
45
48
  ##Things that are compiled into the kernel from user given data
46
49
  `MODS` - A list of modules that was specified in `./app/drivers/$PLATFORM/config.yml`
47
50
  `PLATFORM` - The platform that this kernel was compiled with
data/docs/mod/rtc.md ADDED
@@ -0,0 +1,10 @@
1
+ #Real Time Clock (rtc.js)
2
+
3
+ ###Driver
4
+ `if_rtc_init()` - Initialize the RTC module.
5
+
6
+ ###Interrupts
7
+ `int_rtc(epoch)` - Called every second to indicate that a second has passed.
8
+
9
+ ###Helper functions
10
+ `time()` - Retrieves the time as an integer based on the unix epoch (Seconds since 1970)
data/docs/mod/speech.md CHANGED
@@ -9,4 +9,4 @@ There is a software-simulation of the `speech` module. To enable it, put `speech
9
9
  `int_speech_cancelled()` - The speech was cancelled
10
10
  `int_speech_finished()` - The speech completed succesfully
11
11
  `int_speech_started()` - The speech has started
12
- `int_will_speak_range(offset, count)` - The speech is in the process of talking over a range of the text
12
+ `int_will_speak_range(offset, count)` - The speech is in the process of talking over a range of the text
data/docs/mod/timer.md CHANGED
@@ -4,7 +4,8 @@
4
4
  `if_timer_init(tps)` - Initiate a timer that calls `int_timer` N `tps` (ticsk per second). This is always called via the cpu scheduling class (3)
5
5
 
6
6
  ###Interrupts
7
- `int_timer` - Called by the device at the rate described in `tps`. This function lives inside the `timer` service's initialization portion.
7
+ `int_timer()` - Called by the device at the rate described in `tps`. This function lives inside the `timer` service's initialization portion.
8
+ A. Requires the timer module.
8
9
 
9
10
  ###Callout
10
11
  The kernel's `int_timer` function gets sent to `callout_wakeup()` located in `callout.js`.
data/lib/flok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.87"
2
+ VERSION = "0.0.88"
3
3
  end
@@ -0,0 +1,45 @@
1
+ Dir.chdir File.join File.dirname(__FILE__), '../../../'
2
+ require './spec/env/iface.rb'
3
+ require './spec/lib/helpers.rb'
4
+ require './spec/lib/io_extensions.rb'
5
+ require './spec/lib/rspec_extensions.rb'
6
+
7
+ RSpec.describe "iface:driver:rtc" do
8
+ module_dep "rtc"
9
+ include_context "iface:driver"
10
+
11
+ it "Does update epoch every second" do
12
+ #Wait for response
13
+ @pipe.puts [[0, 0, "ping"]].to_json; @pipe.readline_timeout
14
+
15
+ @pipe.puts [[0, 1, "if_rtc_init"]].to_json
16
+
17
+ #Wait to start until after the 1st event fires to make sure timer started up
18
+ @pipe.readline
19
+ expect(@pipe).to readline_and_equal_json_x_within_y_seconds([0, "int_rtc", Fixnum], 5.seconds)
20
+ start_time = Time.now.to_i
21
+ 5.times do
22
+ expect(@pipe).to readline_and_equal_json_x_within_y_seconds([0, "int_rtc", Fixnum], 2.seconds)
23
+ end
24
+ end_time = Time.now.to_i
25
+
26
+ #Just leave some room for connection latency, etc.
27
+ expect(end_time - start_time).to be < 7
28
+ expect(end_time - start_time).to be > 4
29
+
30
+ #Now let's compare one-to-three 'ticks'
31
+ a = JSON.parse(@pipe.readline_timeout)
32
+ sleep 1
33
+ b = JSON.parse(@pipe.readline_timeout)
34
+
35
+ #They should be at least 1 second apart and not more than 3
36
+ a_timestamp = a[2]
37
+ b_timestamp = b[2]
38
+ expect(b_timestamp - a_timestamp).to be > 0
39
+ expect(b_timestamp - a_timestamp).to be < 4
40
+
41
+ #Should match the current epoch within 1 minute
42
+ current_epoch = Time.now.to_i
43
+ expect((b_timestamp - current_epoch).abs).to be < 60
44
+ end
45
+ end
@@ -5,7 +5,7 @@ require './spec/lib/io_extensions.rb'
5
5
  require './spec/lib/rspec_extensions.rb'
6
6
 
7
7
  RSpec.describe "iface:driver:timer" do
8
- module_dep "net"
8
+ module_dep "timer"
9
9
  include_context "iface:driver"
10
10
 
11
11
  it "Can call initiate a timer" do
@@ -0,0 +1,26 @@
1
+ Dir.chdir File.join File.dirname(__FILE__), '../../'
2
+ require './spec/env/kern.rb'
3
+ require './spec/lib/helpers.rb'
4
+ require './spec/lib/io_extensions.rb'
5
+ require './spec/lib/rspec_extensions.rb'
6
+
7
+ RSpec.describe "kern:rtc_spec" do
8
+ include_context "kern"
9
+
10
+ it "Does update the epoch when receiving the int_rtc message" do
11
+ #Compile the controller
12
+ ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
13
+
14
+ @driver.int("int_rtc", [555])
15
+ dump = ctx.evald %{
16
+ dump.time = time()
17
+ }
18
+ expect(dump["time"]).to eq(555)
19
+
20
+ @driver.int("int_rtc", [556])
21
+ dump = ctx.evald %{
22
+ dump.time = time()
23
+ }
24
+ expect(dump["time"]).to eq(556)
25
+ end
26
+ end
@@ -97,7 +97,21 @@ RSpec::Matchers.define :readline_and_equal_json_x_within_y_seconds do |json, sec
97
97
  begin
98
98
  Timeout::timeout(seconds) do
99
99
  @res = JSON.parse(pipe.readline.strip)
100
- return true if @res == json
100
+
101
+ if json.class != Array
102
+ return true if @res == json
103
+ else
104
+ expect(@res.length).to eq(json.length)
105
+ @res.each_with_index do |r, i|
106
+ if json[i] == Fixnum
107
+ expect(r.class).to eq(Fixnum)
108
+ else
109
+ expect(r).to eq(json[i])
110
+ end
111
+ end
112
+ return true
113
+ end
114
+
101
115
  end
102
116
  rescue Timeout::Error #Time out
103
117
  rescue EOFError #Couldn't read pipe
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.87
4
+ version: 0.0.88
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
@@ -285,6 +285,7 @@ files:
285
285
  - app/drivers/chrome/src/helpers.js
286
286
  - app/drivers/chrome/src/net.js
287
287
  - app/drivers/chrome/src/persist.js
288
+ - app/drivers/chrome/src/rtc.js
288
289
  - app/drivers/chrome/src/segue.js
289
290
  - app/drivers/chrome/src/sockio.js
290
291
  - app/drivers/chrome/src/timer.js
@@ -304,6 +305,7 @@ files:
304
305
  - app/kern/mod/event.js
305
306
  - app/kern/mod/net.js
306
307
  - app/kern/mod/persist.js
308
+ - app/kern/mod/rtc.js
307
309
  - app/kern/mod/segue.js
308
310
  - app/kern/mod/sockio.js
309
311
  - app/kern/mod/timer.js
@@ -319,6 +321,7 @@ files:
319
321
  - app/kern/services/vm.rb
320
322
  - app/kern/spec_helper.js
321
323
  - app/kern/tel.js
324
+ - app/kern/time.js
322
325
  - bin/flok
323
326
  - docs/architecture.md
324
327
  - docs/branches.md
@@ -345,6 +348,7 @@ files:
345
348
  - docs/mod/intercept.md
346
349
  - docs/mod/net.md
347
350
  - docs/mod/persist.md
351
+ - docs/mod/rtc.md
348
352
  - docs/mod/sockio.md
349
353
  - docs/mod/speech.md
350
354
  - docs/mod/timer.md
@@ -1130,6 +1134,7 @@ files:
1130
1134
  - spec/iface/driver/persist_spec.rb
1131
1135
  - spec/iface/driver/ping_spec.rb
1132
1136
  - spec/iface/driver/pipe_spec.rb
1137
+ - spec/iface/driver/rtc_spec.rb
1133
1138
  - spec/iface/driver/sockio_spec.rb
1134
1139
  - spec/iface/driver/timer_spec.rb
1135
1140
  - spec/iface/driver/ui_spec.rb
@@ -1303,6 +1308,7 @@ files:
1303
1308
  - spec/kern/functions_spec.rb
1304
1309
  - spec/kern/global_functions_spec.rb
1305
1310
  - spec/kern/rest_service_spec.rb
1311
+ - spec/kern/rtc_spec.rb
1306
1312
  - spec/kern/service_controller_spec.rb
1307
1313
  - spec/kern/test_service_spec.rb
1308
1314
  - spec/kern/vm_service_functional_spec.rb
@@ -2086,6 +2092,7 @@ test_files:
2086
2092
  - spec/iface/driver/persist_spec.rb
2087
2093
  - spec/iface/driver/ping_spec.rb
2088
2094
  - spec/iface/driver/pipe_spec.rb
2095
+ - spec/iface/driver/rtc_spec.rb
2089
2096
  - spec/iface/driver/sockio_spec.rb
2090
2097
  - spec/iface/driver/timer_spec.rb
2091
2098
  - spec/iface/driver/ui_spec.rb
@@ -2259,6 +2266,7 @@ test_files:
2259
2266
  - spec/kern/functions_spec.rb
2260
2267
  - spec/kern/global_functions_spec.rb
2261
2268
  - spec/kern/rest_service_spec.rb
2269
+ - spec/kern/rtc_spec.rb
2262
2270
  - spec/kern/service_controller_spec.rb
2263
2271
  - spec/kern/test_service_spec.rb
2264
2272
  - spec/kern/vm_service_functional_spec.rb