-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.erl
74 lines (59 loc) · 1.61 KB
/
receiver.erl
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
70
71
72
73
74
%% Author: anton
%% Created: 08.01.2013
%% Description: TODO: Add description to receiver
-module(receiver).
-behaviour(gen_server).
-import(util,[timestamp/0]).
%%
%% Include files
%%
%%
%% Exported Functions
%%
%% callbacks f�r gen_server
-export([init/1,
handle_call/3,
handle_cast/2,
handle_info/2,
terminate/2,
code_change/3]).
-compile([export_all]).
-record(state, {coordinatorPID, socket,station}).
%%
%% API Functions
%%
start(CoordinatorPID,Socket,Station) ->
%log("[~p]Receiver start",[Station]),
gen_server:start(?MODULE,[CoordinatorPID, Socket,Station],[]).
init([CoordinatorPID,Socket,Station]) ->
%log("[~p]Receiver init",[Station]),
{ok, #state{coordinatorPID=CoordinatorPID, socket=Socket, station=Station}}.
terminate(normal, State) ->
%log("TERMINATING!"),
gen_udp:close(State#state.socket).
%log("Receiver wurde beendet").
handle_info({udp, _Socket, _IP, _Port, Packet}, State) ->
%log("[~p]Paket angekommen",[State#state.station]),
Timestamp = util:timestamp(),
gen_server:cast(State#state.coordinatorPID,{recieved, Timestamp, Packet}),
{noreply, State};
handle_info(_Info, State) ->
%log("Unknown Info"),
{noreply, State}.
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(Any, State) ->
%log("Unbekannte Nachricht: ~p",[Any]),
{noreply, State}.
%%
%% Local Functions
%%
log(Message) ->
util:log("Receiver.log",Message).
log(Message, Data) ->
util:log("Receiver.log",Message, Data).
%% durch gen_server vorgegeben
handle_call(_Request, _From, State) ->
{reply, ok, State}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.