summaryrefslogtreecommitdiffstats
path: root/test/afb-test/fixtures/mapi_low-can.lua
blob: b88fc2ffd6c86c0165edb75884b20cbc8b722395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--[[
    Copyright (C) 2018 "IoT.bzh"
    Author Romain Forlot <romain.forlot@iot.bzh>

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


    NOTE: strict mode: every global variables should be prefixed by '_'
--]]

function _subscribe(source, args)
  AFB:success(source)
end

function _unsubscribe(source, args)
  AFB:success(source)
end

function _evtpush(source, context, val)
  local event = val[0]
  return AFB:evtpush(source, _evtHandles[event], val[1])
end

function _get(source, args)
  _evtHandles = {}
  _messageHandles = {}

  _evtHandles['messages_engine_speed'] = nil
  _evtHandles['messages_vehicle_speed'] = nil

  _messageHandles['messages_engine_speed'] = 1234
  _messageHandles['messages_vehicle_speed'] = 5678

  for k,v in pairs(_messageHandles) do
    if type(_evtHandles[k]) ~= "userdata" then
      _evt = AFB:evtmake(source, k)
      _evtHandles[k] = _evt
    end
    if type(_evtHandles[k]) == "userdata" then
      AFB:subscribe(source, _evtHandles[k])
      AFB:timerset(source, {uid="evtpush_"..k, delay=1, count=1}, "_evtpush", {k, v})
    end
  end

  AFB:success(source)

end

function _list(source, args)
  AFB:success(source)
end

function _auth(source, args)
  AFB:success(source)
end

function _write(source, args)
  AFB:success(source)
end