summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazanski <sergiusz@q3k.org>2011-11-09 18:16:36 +0100
committerSergiusz Bazanski <sergiusz@q3k.org>2011-11-09 18:16:36 +0100
commit0515af97b752151127dfecbc15b8b612b479f206 (patch)
tree79bdcce799284b94f64ba04ca77927ace910c4a7
parent44057288e77eca8dcfae9e6a906ae0428f37e228 (diff)
parent8bf4441ebae76f7aaba89521e84fc53ca74d451f (diff)
downloaddoorman-0515af97b752151127dfecbc15b8b612b479f206.tar.gz
doorman-0515af97b752151127dfecbc15b8b612b479f206.tar.bz2
doorman-0515af97b752151127dfecbc15b8b612b479f206.tar.xz
doorman-0515af97b752151127dfecbc15b8b612b479f206.zip
Merge branch 'minefield'
-rw-r--r--admin/cards.csv0
-rw-r--r--admin/lib/csvstore.py12
-rw-r--r--admin/lib/storage.py2
-rw-r--r--arduino/arduino.pde (renamed from arduino/hspace_lock.pde)56
4 files changed, 55 insertions, 15 deletions
diff --git a/admin/cards.csv b/admin/cards.csv
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin/cards.csv
diff --git a/admin/lib/csvstore.py b/admin/lib/csvstore.py
index c4c882c..317d6e2 100644
--- a/admin/lib/csvstore.py
+++ b/admin/lib/csvstore.py
@@ -1,20 +1,20 @@
-import StringIO
from UserDict import IterableUserDict
+from StringIO import StringIO
import csv
class Storage(IterableUserDict):
- def __init__(self, file):
+ def __init__(self, encapsulation):
self.encapsulation = encapsulation
self.encapsulation.begin_transaction()
try:
stored = {x[0]: [x[1], x[2]]
- for x in csv.reader([self.encapsulation.data])}
+ for x in csv.reader(StringIO(self.encapsulation.data))}
except IOError:
stored = {}
IterableUserDict.__init__(self, stored)
def sync(self):
- f = StringIO.StringIO()
+ f = StringIO()
csv.writer(f).writerows(
[c, u, name] for c, (u, name) in self.data.iteritems())
@@ -24,7 +24,9 @@ class Storage(IterableUserDict):
self.encapsulation.begin_transaction()
def __del__(self):
- self.sync()
+ #TODO: fix this shit
+ #self.sync()
+ pass
def __setitem__(self, k, v):
IterableUserDict.__setitem__(self, k, v)
self.sync()
diff --git a/admin/lib/storage.py b/admin/lib/storage.py
index 5627ff7..1d5b992 100644
--- a/admin/lib/storage.py
+++ b/admin/lib/storage.py
@@ -5,7 +5,7 @@ import jsonstore
import options
import storage_encapsulation
-if options.storage_encrypt == True
+if options.storage_encrypt == True:
encapsulation_class = storage_encapsulation.DESFileEncapsulation
else:
encapsulation_class = storage_encapsulation.RawFileEncapsulation
diff --git a/arduino/hspace_lock.pde b/arduino/arduino.pde
index 0a7c41a..d12d2d7 100644
--- a/arduino/hspace_lock.pde
+++ b/arduino/arduino.pde
@@ -60,16 +60,26 @@ void setup() {
/** Main loop. */
void loop(){
//Communication with mifare reader.
- rf_comm();
+ unsigned long rfid;
+ unsigned int id;
+ if (rf_comm(&rfid,&id)){
+ unsigned int pin;
+ //User rfid is authorized, read pin here!
+ if (emem_check_pin(id,pin)) {
+ //Open door
+ } else {
+ //Wrong pin
+ }
+ }
//Communication with PC (optional).
pc_comm();
}
/**
* Function reads record with given id from EEPROM.
- * @param adr Address of record to read.
- * @param data Pointer to space for data.
- * @param id Pointer to space for id.
+ * @param adr Address of record to read, or NULL.
+ * @param data Pointer to space for data, or NULL.
+ * @param id Pointer to space for id, or NULL.
* @return Function returns true when data was red, false otherwise.
*/
boolean emem_get_record(unsigned int adr,unsigned long * data,unsigned int * id,unsigned int * pin){
@@ -81,9 +91,15 @@ boolean emem_get_record(unsigned int adr,unsigned long * data,unsigned int * id,
for (int ii=0;ii<EMEM_RECORD_SIZE;ii++){
rec[ii] = EEPROM.read(adr*EMEM_RECORD_SIZE+ii);
}
- (*id)=rec[0];
- (*data)=(long(rec[1])<<24)|(long(rec[2])<<16)|(long(rec[3])<<8)|(long(rec[4]));
- (*pin)=(rec[5]<<8)|(rec[6]);
+ if (id != NULL){
+ (*id)=rec[0];
+ }
+ if (data != NULL){
+ (*data)=(long(rec[1])<<24)|(long(rec[2])<<16)|(long(rec[3])<<8)|(long(rec[4]));
+ }
+ if (pin != NULL){
+ (*pin)=(rec[5]<<8)|(rec[6]);
+ }
return true;
}
@@ -104,6 +120,18 @@ boolean emem_del_record(unsigned int adr){
}
/**
+ * Checks if pin is correct.
+ * @param if User id.
+ * @param pin Pin code.
+ * @return True if pin is correct, false otherwise.
+ */
+boolean emem_check_pin(unsigned int id, unsigned int pin){
+ unsigned int epin;
+ emem_get_record(id,NULL,NULL,&pin);
+ return (epin==pin);
+}
+
+/**
* Finds record with given ID.
* @param id Record id.
* @return Address of found record or EMEM_INV_ADR.
@@ -426,10 +454,13 @@ boolean pc_parse(){
/**
* Handles communication with rfid reader.
+ * @return Returns true when authorized user rfid was red, false otherwise.
*/
-void rf_comm() {
+boolean rf_comm(unsigned long * p_rfid,unsigned int * p_id) {
static unsigned long last_millis = 0;
static unsigned long new_millis = 0;
+ (*p_id) = EMEM_INV_ADR;
+ (*p_rfid) = 0;
new_millis = millis();
if (new_millis<last_millis){
last_millis=new_millis;
@@ -446,10 +477,17 @@ void rf_comm() {
if (pc_send_flag){
pc_send_flag=false;
pc_print('S',data,id);
-
+
+ }
+ if (id!=EMEM_INV_ADR){
+ //User is authorized
+ (*p_id) = id;
+ (*p_rfid) = data;
+ return true;
}
}
}
+ return false;
}
/**