summaryrefslogtreecommitdiff
path: root/cmdiface.erl
blob: 8249a99849c94ea6435bcaae045bacdf6896a30b (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
%%%-------------------------------------------------------------------
%%% @author Joe Zhao
%%% @copyright (C) 2014, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 10. May 2014 下午9:20
%%%-------------------------------------------------------------------
-module(cmdiface).
-author("Joe Zhao").

-compile([debug_info,export_all]).

%% API
%%-export([]).

reg_feedbackOps(Addr,Name,T,MsgReq,MsgRes,To) ->
  io:format("Logging new command: ~p ~n",[Name]),
  Init=fun () -> rsbusserv ! {devicemon,comm,Addr,MsgReq} end,
  Exit=
    fun () ->
      rsbusserv ! {devicemon,comm,Addr,[]}
    end,
  Pid = spawn(?MODULE,res_manip,[Init,Exit,To,[0,Addr,MsgReq]]),
  Call =
    fun (_PPid) ->
      Pid ! rsbusserv:rsbusreq(Addr,MsgRes)
    end,
  eventserv:reg_future(Call,T).

invoke_cmd(Addr,Name,MsgReq) ->
  io:format("Command: ~p ~n",[Name]),
  rsbusserv! {devicemon,comm,Addr,MsgReq}.

res_manip(Init,Exit,To,Pre) ->
  Init(),
  receive
    {stat,Type,Msg} -> To ! {self(),comm,Pre++[Type]++Msg};
    {error,_Reason} -> ok
  end,
  Exit().