From 9adcb32af31d22a046881f5d690d068e232be773 Mon Sep 17 00:00:00 2001
From: Joe Zhao <ztuowen@gmail.com>
Date: Mon, 9 Jun 2014 20:24:43 +0800
Subject: Comments & maintenance

---
 devicemon.erl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'devicemon.erl')

diff --git a/devicemon.erl b/devicemon.erl
index 703dca5..d56043b 100644
--- a/devicemon.erl
+++ b/devicemon.erl
@@ -18,7 +18,10 @@
 %% API
 %% -export([]).
 
+%% @todo This module is not fault-safe, abrupt death will halt all operations
+
 -define(QTOUT,100).
+-define(STNULL,[0,255,0,0,0]).
 
 cleanloop() ->
 %% Cleanup the message queue -> Don't call it
@@ -56,8 +59,10 @@ deviceloop(Devices) ->
       Pid ! {self(),comm,orddict:fold(fun(Key,Val,Acc) -> [Key,Val#device.type]++Val#device.state++Acc end, [],Devices)},
       deviceloop(Devices);
     {Pid,comm,[0,Addr]} -> % Specific query, this also shouldn't happen.
-      Dev=orddict:fetch(Addr,Devices),
-      Pid ! {self(),comm,[Dev#device.type]++Dev#device.state},
+      case orddict:find(Addr,Devices) of
+        error -> Pid ! {self(),comm,[Addr]++?STNULL};
+        {ok,Value} -> Pid ! {self(),comm,[Addr,Value#device.type]++Value#device.state}
+      end,
       deviceloop(Devices);
 
     %% Messages received from rsbus
-- 
cgit v1.2.3-70-g09d2