[chronojump-server] Implemented rfid detection when creating player
- From: Max Ros i Morejon <maxros src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Implemented rfid detection when creating player
- Date: Fri, 15 Feb 2019 14:12:43 +0000 (UTC)
commit 15a95b8de4ee59c4fdbae59555f76f6141564999
Author: Max Ros i Morejon <mros33 gmail com>
Date: Fri Feb 15 15:11:37 2019 +0100
Implemented rfid detection when creating player
.../chronojump_networks/organizations/api/views.py | 47 +++++++++++++---------
.../chronojump_networks/organizations/models.py | 14 +++++++
.../players/add_edit_player_form.html | 42 ++++++++++++++++++-
.../organizations/players/players_list.html | 20 ++++++++-
chronojumpserver/rfid-csharp/RFID.cs | 11 +++++
5 files changed, 113 insertions(+), 21 deletions(-)
---
diff --git a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
index acedd9c..3847018 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/api/views.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/api/views.py
@@ -1,5 +1,6 @@
import os
-from ..models import Player, GroupPlayer, Group, Station, Gym, Exercise
+import subprocess
+from ..models import Player, GroupPlayer, Group, Station, Gym, Exercise, RFIDHistory
from ..decorators import check_user_organization
from .serializers import PlayerSerializer, StationSerializer, ExerciseSerializer, GymStationsSerializer
@@ -116,29 +117,36 @@ class PlayerListView(ListCreateAPIView):
def register_rfid(request):
"""Call an external program to read rfid and return the value read."""
+ print("register_rfid")
status_code = 200
msg = ""
# From original crhonojump-flask source read RFID
rfidFile = '/tmp/chronojump_rfid.txt'
# Check if we are in development, to read directly the value pass manually
# instead of the mono executable
- if not 'MONO_PATH' in os.environ:
- no_mono = 1
- else:
- no_mono = 0
+ rfidscriptpath = "/home/max/chronojump-server/chronojumpserver/rfid-csharp"
+ #if not 'MONO_PATH' in os.environ:
+ #if not 'MONO_PATH' in os.environ:
+
+ #no_mono = 1
+ #else:
+ #no_mono = 0
+
#print "DEBUG: NO_MONO = %d" % int(no_mono)
- if no_mono == 1:
- sleep(4)
- else:
- if os.access(rfidFile, os.W_OK):
- os.remove(rfidFile)
- # Call Mono program to read from RFID Reader
- mono_path = os.path.join(os.environ['MONO_PATH'], 'RFID.exe')
- rfidReadedStatus = subprocess.call(
- "mono %s" % mono_path, shell=True)
- # Debug: Print output status
- #print rfidReadedStatus
+ #if no_mono == 1:
+ #sleep(4)
+ #else:
+ if os.access(rfidFile, os.W_OK):
+ os.remove(rfidFile)
+ # Call Mono program to read from RFID Reader
+ #mono_path = os.path.join(os.environ['MONO_PATH'], 'RFID.exe')
+ rfidscript = os.path.join(rfidscriptpath, 'RFID.exe')
+
+ rfidReadedStatus = subprocess.call(
+ "mono %s" % rfidscript, shell=True)
+ # Debug: Print output status
+ #print rfidReadedStatus
# Read the RFID read
try:
@@ -147,17 +155,18 @@ def register_rfid(request):
except Exception, e:
print "ERROR: %s" % str(e)
rfid = ""
-
if rfid:
"""Check if the RFID exists."""
- p = RFIDHistory.query.filter(RFIDHistory.rfid == rfid).first()
- if p:
+ p = RFIDHistory.objects.filter(rfid = rfid)
+ if p is None:
# Aquest RFID ja ha estat registrada amb anterioritat.
status_code = 404
msg = "El RFID %s ja ha estat registrat amb anterioritat." % rfid
else:
status_code = 404
msg = "ERROR: No s'ha pogut llegir cap RFID en el temps assignat."
+
response = JsonResponse({"rfid":rfid, "msg":msg})
response.status_code = status_code
+ print response
return response
diff --git a/chronojumpserver-django/chronojump_networks/organizations/models.py
b/chronojumpserver-django/chronojump_networks/organizations/models.py
index 1122046..02150b5 100644
--- a/chronojumpserver-django/chronojump_networks/organizations/models.py
+++ b/chronojumpserver-django/chronojump_networks/organizations/models.py
@@ -278,3 +278,17 @@ class GroupPlayer(models.Model):
on_delete=models.CASCADE,
related_name="players",
db_column='groupId')
+
+class RFIDHistory(models.Model):
+ """RFIDHistory class to control rfid history."""
+
+ class Meta:
+ db_table = 'rfidHistory'
+
+ #rfid = Column(String(23), primary_key=True)
+ #person_id = Column(Integer, nullable=False)
+
+ rfid = models.CharField(max_length=23,primary_key=True)
+ player = models.ForeignKey(Player,
+ on_delete=models.CASCADE,
+ db_column='playerId')
diff --git
a/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
index 7fe41b6..34cf671 100644
--- a/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/players/add_edit_player_form.html
@@ -11,6 +11,9 @@
</button>
</div>
<div class="modal-body">
+
+ <!--input type="hidden" id="personId" />-->
+
<form>
<div class="row">
<div class="col-sm-4">
@@ -20,7 +23,7 @@
</div>
</div>
<div class="col-sm-8">
- <div class="form-group">
+ <div class="form-group">
<label for="fullname">{% trans 'Fullname' %}</label>
<input name="fullname" class="form-control"
id="fullname" type="text">
</div>
@@ -34,6 +37,19 @@
<input name="weight" class="form-control"
id="weight" type="number" min="0" step="1">
</div>
</div>
+ <div class="form-group">
+ <label for="rfid">{% trans 'Rfid' %}</label>
+ <div class="form-row">
+ <div class="col-sm-10">
+ <input name="rfid" class="form-control" id="input_rfid" type="text"
aria-describedby="btn_read_rfid" readonly>
+ </div>
+ <div class="col-sm-2">
+ <div class="input-group-prepend">
+ <button class="btn btn-outline-secondary" type="button"
id="btn_read_rfid">Register</button>
+ </div>
+ </div>
+ </div>
+ </div>
</div>
</div>
@@ -50,3 +66,27 @@
</div>
<!-- /.modal-dialog -->
</div>
+
+
+<!--
+<script>
+
+$(document).ready(function() {
+ $('#btn_read_rfid').click(function() {
+ $.ajax({
+ 'url': "{% url 'api_organizations:register_rfid' %}",
+ 'method': 'GET',
+ success: function(data) {
+ console.log(data);
+ $('#input_rfid').val(data.rfid);
+ },
+ error: function (request, status, error) {
+ alert(request.msg);
+ }
+
+ })
+ })
+
+}) //end of document ready
+
+</script>-->
diff --git a/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
b/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
index 0503d25..7ac1a40 100644
--- a/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
+++ b/chronojumpserver-django/chronojump_networks/templates/organizations/players/players_list.html
@@ -122,7 +122,7 @@
],
initComplete: function() {
// Enable the remove player selection the first time data is loaded
- enablePlayersTableFunctionality();
+ //enablePlayersTableFunctionality(); TODO: CHECK if this is needed and implemented
},
"language": {
"lengthMenu": "{% trans 'Showing _MENU_ players per page' %}",
@@ -141,6 +141,24 @@
"search": "{% trans 'Search:' %}"
}
});
+
+ $('#btn_read_rfid').click(function() {
+ console.log('crida script')
+ $.ajax({
+ 'url': "{% url 'api_organizations:register_rfid' %}",
+ 'method': 'GET',
+ success: function(data) {
+ console.log('success');
+ $('#input_rfid').val(data.rfid);
+ },
+ error: function(request, status, error) {
+ console.log('error');
+ alert(request.msg);
+ }
+
+ })
+ })
+
});
</script>
{% endblock %}
diff --git a/chronojumpserver/rfid-csharp/RFID.cs b/chronojumpserver/rfid-csharp/RFID.cs
index b7a63b8..3b462bf 100755
--- a/chronojumpserver/rfid-csharp/RFID.cs
+++ b/chronojumpserver/rfid-csharp/RFID.cs
@@ -28,6 +28,17 @@ public class RFIDMain
public static void Main()
{
+ //debug starts
+ /*string str = "Called RFIDMain. Writing at /tmp/rfidcalled.txt";
+ Console.WriteLine(str);
+
+ TextWriter writer = File.CreateText("/tmp/rfidcalled.txt");
+ writer.Write(str);
+ writer.Flush();
+ writer.Close();
+ ((IDisposable)writer).Dispose();*/
+ //debug ends
+
removeFile();
RFID rfid = new RFID();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]