Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김유현
2020-11-19 12:56:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8842bc3fb4adfd59b8ce17f0460c7852944b6e36
8842bc3f
1 parent
0dbcf4b4
Modify
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
api/migrations/0002_adddevice.py
api/views.py
process/doorlock.py
api/migrations/0002_adddevice.py
0 → 100644
View file @
8842bc3
# Generated by Django 3.1.2 on 2020-11-18 19:55
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'AddDevice'
,
fields
=
[
(
'id'
,
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
)),
(
'add'
,
models
.
BooleanField
(
default
=
False
)),
],
),
]
api/views.py
View file @
8842bc3
...
...
@@ -7,8 +7,8 @@ from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist
from
django.shortcuts
import
render
from
api.videorecord
import
record
from
api.models
import
Video
,
Device
,
RemoteHistory
,
Lock
,
Record
,
Door
from
api.serializers
import
VideoSerializer
,
DeviceSerializer
,
RemoteHistorySerializer
,
RecordSerializer
,
LockSerializer
from
api.models
import
Video
,
Device
,
RemoteHistory
,
Lock
,
Record
,
Door
,
AddDevice
from
api.serializers
import
VideoSerializer
,
DeviceSerializer
,
RemoteHistorySerializer
,
RecordSerializer
,
LockSerializer
,
AddDeviceSerializer
from
rest_framework
import
status
...
...
@@ -68,6 +68,13 @@ class Devices(APIView) :
try
:
print
(
request
.
body
)
data
=
json
.
loads
(
request
.
body
)
target
=
AddDevice
.
objects
.
get
(
id
=
1
)
serializer
=
AddDeviceSerializer
(
target
,
many
=
False
)
state
=
serializer
.
data
[
'state'
]
if
state
==
False
:
print
(
">> 기기추가 요청이 들어옴"
)
target
.
state
=
True
target
.
save
()
rfid_id
=
data
.
get
(
'rfid_id'
,
None
)
res
=
{
'rfid_id'
:
rfid_id
...
...
process/doorlock.py
View file @
8842bc3
...
...
@@ -81,9 +81,10 @@ def RFIDProcess(signalQueue):
if
response
.
status_code
==
200
:
deviceList
=
(
response
.
json
()[
'deviceList'
])
# state = getFromIPC(원격 잠금해제 여부)
target
=
Lock
.
objects
.
get
(
id
=
1
)
# 장고 모델에서 잠금 상태 모델(Lock) 객체 가져옴
serializer
=
LockSerializer
(
target
,
many
=
False
)
# python 데이터타입으로 변환
# state = getFromIPC(기기추가여부)
target
=
AddDevice
.
objects
.
get
(
id
=
1
)
# 장고 모델에서 잠금 상태 모델(Lock) 객체 가져옴
serializer
=
AddDeviceSerializer
(
target
,
many
=
False
)
# python 데이터타입으로 변환
state
=
serializer
.
data
[
'state'
]
# state에 저장(boolean)
findDevice
=
False
# 기기 등록 여부
...
...
@@ -91,7 +92,7 @@ def RFIDProcess(signalQueue):
if
deviceId
in
i
[
"rfid"
]:
findDevice
=
True
if
state
==
False
:
# if state == 원격 잠금해제
:
if
state
==
True
:
# if state == 기기추가
:
try
:
if
findDevice
:
# if devices.find(deviceId):
print
(
"이미 등록된 RFID 장치"
)
# raise
...
...
@@ -104,10 +105,10 @@ def RFIDProcess(signalQueue):
except
:
print
(
"경고음 삑 -!"
)
pass
finally
:
# setToIPC(
원격 잠금해제 여부, 원격 잠금해제
아님)
target
.
state
=
Tru
e
finally
:
# setToIPC(
기기 추가 여부, 기기 추가
아님)
target
.
state
=
Fals
e
target
.
save
()
else
:
#
원격 잠금해제
상태가 아님 = 도어락 해제 프로세스
else
:
#
기기 추가
상태가 아님 = 도어락 해제 프로세스
try
:
if
not
findDevice
:
# if not devices.find(deviceId)
print
(
"등록되지 않은 RFID 장치"
)
# raise
...
...
Please
register
or
login
to post a comment