Permalink
Browse files

first commit

  • Loading branch information...
tonyrog committed Feb 24, 2014
0 parents commit 0e78e6991f1e586ca92f6bd934adcaa765b61435
Showing with 476 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. 0 README.md
  3. +2 −0 ebin/.gitignore
  4. +10 −0 rebar.config
  5. +8 −0 rebar.config.script
  6. +13 −0 src/hex_gpio.app.src
  7. +114 −0 src/hex_gpio.erl
  8. +16 −0 src/hex_gpio_app.erl
  9. +287 −0 src/hex_gpio_server.erl
  10. +25 −0 src/hex_gpio_sup.erl
@@ -0,0 +1 @@
+*~
No changes.
@@ -0,0 +1,2 @@
+*.beam
+*.app
@@ -0,0 +1,10 @@
+%% -*- erlang -*-
+%% Config file for hex plugin hex_gpio application.
+%%
+{erl_opts, [debug_info]}.
+
+{deps, [ {hex, ".*", {git, "git@github.com:tonyrog/hex.git"}},
+ {gpio, ".*", {git, "git@github.com:tonyrog/gpio.git"}},
+ {lager, ".*", {git, "git://github.com/Feuerlabs/lager.git",
+ "1.0.0.fl.2"}}
+ ]}.
@@ -0,0 +1,8 @@
+%% -*- erlang -*-
+%% Config script file for uart-application
+case os:getenv("REBAR_DEPS") of
+ false -> CONFIG; % env var not defined
+ [] -> CONFIG; % env var set to empty string
+ Dir ->
+ lists:keystore(deps_dir, 1, CONFIG, {deps_dir, Dir})
+end.
@@ -0,0 +1,13 @@
+{application, hex_gpio,
+ [
+ {description, "hex GPIO plugin"},
+ {vsn, git},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ gpio
+ ]},
+ {mod, { hex_gpio_app, []}},
+ {env, []}
+ ]}.
@@ -0,0 +1,114 @@
+%%%-------------------------------------------------------------------
+%%% @author Tony Rogvall <tony@rogvall.se>
+%%% @copyright (C) 2014, Tony Rogvall
+%%% @doc
+%%% Hex GPIO plugin
+%%% @end
+%%% Created : 24 Feb 2014 by Tony Rogvall <tony@rogvall.se>
+%%%-------------------------------------------------------------------
+-module(hex_gpio).
+
+-behaviour(hex_plugin).
+
+-export([add_event/2, del_event/1, output/2]).
+-export([validate_flags/2]).
+
+%%
+%% add_event(Flags::[{atom(),term()}, Signal::signal()) ->
+%% {ok, Ref:reference()} | {error, Reason}
+%%
+add_event(Flags, Signal) ->
+ hex_gpio_server:add_event(Flags, Signal).
+
+%%
+%% del_event(Ref::reference()) ->
+%% ok.
+del_event(Ref) ->
+ hex_gpio_server:del_event(Ref).
+%%
+%% output(Flags::[{atom(),term()}], Env::[{atom(),term()}]) ->
+%% ok.
+%%
+output(Flags, _Env) ->
+ Body = proplists:get_value(body, Flags, ""),
+ {Fs,_} = proplists:split(Flags, [smsc,rp,udhi,udh,srr,mref,
+ vpf,vp,addr,pid,dcs,type,class,
+ alphabet,compression,store,wait_type,
+ notify,ref]),
+ Opts = lists:append(Fs),
+ gsms:send(Opts, Body).
+
+%%
+%% validate_flags(in | out, Flags::[{atom(),term()}])
+%%
+validate_flags(_Dir, []) ->
+ ok;
+validate_flags(Dir, [{Key,Value}|Kvs]) ->
+ case Key of
+ smsc when is_list(Value) ->
+ %% FIXME: validate msisdn
+ validate_flags(Dir, Kvs);
+ rp when is_boolean(Value) ->
+ validate_flags(Dir, Kvs);
+ udhi when is_boolean(Value) ->
+ validate_flags(Dir, Kvs);
+ udh when Value =:= [] ->
+ validate_flags(Dir, Kvs);
+ udh when is_list(Value) ->
+ %% FIXME: validate udh codings
+ validate_flags(Dir, Kvs);
+ srr when is_boolean(Value) ->
+ validate_flags(Dir, Kvs);
+ mref when is_integer(Value), Value>=0, Value=< 255 ->
+ validate_flags(Dir, Kvs);
+ vpf when Value =:= none;
+ Value =:= relative;
+ Value =:= enhanced;
+ Value =:= absolute ->
+ validate_flags(Dir, Kvs);
+ vp ->
+ case Value of
+ none ->
+ validate_flags(Dir, Kvs);
+ {relative, Seconds} when is_integer(Seconds), Seconds>=0 ->
+ validate_flags(Dir, Kvs);
+ {absolute,DateTimeTz} ->
+ case gsms_codec:is_valid_scts(DateTimeTz) of
+ true ->
+ validate_flags(Dir, Kvs);
+ false ->
+ {error, badarg}
+ end;
+ {enhanced,_} ->
+ {error, not_supported} %% yet
+ end;
+ addr when is_list(Value) ->
+ %% FIXME: validate msisdn
+ validate_flags(Dir, Kvs);
+ pid when is_integer(Value), Value>=0, Value=<255 ->
+ validate_flags(Dir, Kvs);
+ dcs when is_integer(Value) ->
+ _Dcs = gsms_codec:decode_dcs(Value),
+ validate_flags(Dir, Kvs);
+ type -> %% fixme test
+ validate_flags(Dir, Kvs);
+ class -> %% fixme test
+ validate_flags(Dir, Kvs);
+ alphabet -> %% fixme test
+ validate_flags(Dir, Kvs);
+ compression -> %% fixme test
+ validate_flags(Dir, Kvs);
+ store -> %% fixme test
+ validate_flags(Dir, Kvs);
+ wait_type -> %% fixme test
+ validate_flags(Dir, Kvs);
+ %% recognized options, but not for pdu
+ notify -> %% fixme test?
+ validate_flags(Dir, Kvs);
+ ref -> %% fixme test?
+ validate_flags(Dir, Kvs);
+ _ ->
+ lager:debug("validate_flags: unknown pdu option ~p",
+ [{Key,Value}]),
+ {error, badarg}
+ end.
@@ -0,0 +1,16 @@
+-module(hex_gpio_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ hex_gpio_sup:start_link().
+
+stop(_State) ->
+ ok.
Oops, something went wrong.

0 comments on commit 0e78e69

Please sign in to comment.