summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--date.txt3
-rw-r--r--map_machine_ids.txt4
-rw-r--r--new.csv9
-rw-r--r--sbhs_server/settings.py2
-rw-r--r--sbhs_server/tables/management/commands/initialize_machines.py182
5 files changed, 153 insertions, 47 deletions
diff --git a/date.txt b/date.txt
index d808b62..24cf74c 100644
--- a/date.txt
+++ b/date.txt
@@ -1 +1,2 @@
-Tue Jun 6 18:04:57 IST 2017
+
+Fri Jun 9 15:02:01 IST 2017 \ No newline at end of file
diff --git a/map_machine_ids.txt b/map_machine_ids.txt
index 659395e..2cbad2a 100644
--- a/map_machine_ids.txt
+++ b/map_machine_ids.txt
@@ -1,2 +1,2 @@
-15=/dev/ttyUSB1
-7=/dev/ttyUSB0
+4=/dev/ttyUSB2
+3=/dev/ttyUSB1
diff --git a/new.csv b/new.csv
index 9118476..15f8027 100644
--- a/new.csv
+++ b/new.csv
@@ -4697,7 +4697,8 @@
2017-05-26 00:00:46.763190 False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True
2017-05-26 14:55:45.419017 True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True True
2017-05-26 14:56:51.481469 False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True
-2017-06-05 17:00:13.997532 False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True
-2017-06-05 17:02:05.408243 False True True True False False True True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False
-2017-06-06 15:22:19.386157 False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False
-2017-06-06 18:04:57.054912 False False False False False False True False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False
+2017-06-08 15:20:43.936289 True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True
+2017-06-08 15:22:26.446962 True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True
+2017-06-08 15:30:18.130241 False False True True False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False
+2017-06-09 14:43:28.646527 False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False
+2017-06-09 15:02:01.132038 False False True True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False \ No newline at end of file
diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py
index 82c95d7..7c03dfa 100644
--- a/sbhs_server/settings.py
+++ b/sbhs_server/settings.py
@@ -276,7 +276,7 @@ online_mids = [int(i) for i in boards.keys()]
print "No of machines online : ", len(online_mids)
import sys
-print >>sys.stderr, online_mids[1:33] #srikant
+print >>sys.stderr, online_mids[:] #srikant
#srikant
#f = open(os.path.join(BASE_DIR, 'maintenance/online_mids.txt'), 'w')
#f.write(online_mids)
diff --git a/sbhs_server/tables/management/commands/initialize_machines.py b/sbhs_server/tables/management/commands/initialize_machines.py
index 1987a27..b39e4e6 100644
--- a/sbhs_server/tables/management/commands/initialize_machines.py
+++ b/sbhs_server/tables/management/commands/initialize_machines.py
@@ -2,44 +2,148 @@ from django.core.management.base import BaseCommand, CommandError
from sbhs_server import settings
from sbhs_server.tables.models import Board
from sbhs_server import helpers
+import serial,time
class Command(BaseCommand):
- args = ''
- help = 'Initializes the SBHS board data in the database'
-
- def handle(self, *args, **options):
- previous_onlines = Board.objects.only("mid").filter(online=True)
- previous_onlines = [p.mid for p in previous_onlines]
- for o in settings.online_mids:
- try:
- Board.objects.get_or_create(mid=o)
- except:
- pass
-
- new_offlines = []
- for p in previous_onlines:
- if p not in settings.online_mids:
- new_offlines.append(p)
-
- message = "SBHS Administrator,\n\n"
- message += "Following issue requires immidiate attention.\n\n"
- message += "SBHS could not be connected\n"
- for n in new_offlines:
- message += ("MID: %d\n" % n)
- message += "\nYou can check the SBHS status on http://vlabs.iitb.ac.in/sbhs/admin/."
- message += " Possible correction actions are:\n"
- message += "1. Run this command without brackets -> ( cd $SBHS_SERVER_ROOT; ./cron_job.sh )\n"
- message += "2. If same machine comes offline multiple times, replacement of the machine is advised.\n\n\n"
- message += "Regards,\nSBHS Vlabs Server Code"
-
- print "New offline board mids", new_offlines
- subject = "SBHS Vlabs: Notice - SBHS not connected"
-
- if len(new_offlines) > 0:
- for admin in settings.SBHS_ADMINS:
- helpers.mailer.email(admin[2], subject, message)
-
- Board.objects.filter(mid__in=settings.online_mids).update(online=True)
- Board.objects.exclude(mid__in=settings.online_mids).update(online=False)
-
- self.stdout.write('Boards loaded')
+ args = ''
+ help = 'Initializes the SBHS board data in the database'
+
+
+
+ def handle(self, *args, **options):
+ """
+ This function executes as a part of cron job . It monitors the condition of the SBHS devices.
+ To be specific it does the following checks :
+ 1.It tries to connect to the devices whose path exists in map_machine_id.txt
+ 2.It checks the status of fan ,heater, sensor on SBHS by performing a series of variations on them and analysing
+ the result
+ At the end it updates the Boards database with the device status.
+ It mails the admin if any fault occurs.The mail comprises of machine Id of faulty board and probable cause.
+
+
+
+ This function is invoked from command line as following
+ python manage.py initialize_machines
+
+ """
+ previous_onlines = Board.objects.only("mid").filter(online=True)
+ previous_onlines = [p.mid for p in previous_onlines]
+ current_onlines = settings.online_mids
+ current_connections = settings.boards
+
+
+ MINIMUM_DELTA = 1
+
+ def write_to_sbhs(conn,command,value):
+ conn.write(chr(command))
+ conn.write(chr(value))
+
+ def read_from_sbhs(conn,command):
+ conn.write(chr(command))
+ result=-1
+ if command==255:
+ result=ord(conn.read(1))+0.1*ord(conn.read(1))
+ else:
+ result=ord(conn.read(1))
+
+ return result
+
+
+
+
+ first_reading,second_reading,final_reading={},{},{}
+
+
+ for key,value in current_connections.iteritems():
+ first_reading[key]=read_from_sbhs(value['board'].boardcon,255)
+ write_to_sbhs(value['board'].boardcon,253,0)
+ write_to_sbhs(value['board'].boardcon,254,50)
+
+ time.sleep(40)
+
+ for key,value in current_connections.iteritems():
+ second_reading[key] = read_from_sbhs(value['board'].boardcon,255)
+ write_to_sbhs(value['board'].boardcon,253,100)
+
+ time.sleep(40)
+
+ for key,value in current_connections.iteritems():
+ final_reading[key] = read_from_sbhs(value['board'].boardcon,255)
+
+
+ for key,value in current_connections.iteritems():
+ write_to_sbhs(value['board'].boardcon,253,100)
+ write_to_sbhs(value['board'].boardcon,254,0)
+
+
+ print first_reading
+ print second_reading
+ print final_reading
+
+
+
+ delta1,delta2={},{}
+
+ faulty_boards = {}
+
+ for key in current_connections:
+ delta1[key]=second_reading[key]-first_reading[key]
+ delta2[key]=final_reading[key]-second_reading[key]
+
+ for key in current_connections:
+ if delta1[key] > MINIMUM_DELTA and delta2[key] < -MINIMUM_DELTA:
+ pass
+ elif delta1[key] > MINIMUM_DELTA and delta2[key] > MINIMUM_DELTA:
+ #fans not working
+ faulty_boards[key]="Probably Fan is not working"
+ elif delta1[key] < MINIMUM_DELTA and delta2[key] < -MINIMUM_DELTA:
+ #heaters not working
+ faulty_boards[key]="Probably Heater is not working"
+ else:
+ #sensors not working
+ faulty_boards[key]="Probably Sensor is not working"
+
+ for o in current_onlines:
+ try:
+ Board.objects.get_or_create(mid=o)
+ except:
+ pass
+
+ new_offlines = []
+ for p in previous_onlines:
+ if p not in current_onlines:
+ new_offlines.append(p)
+
+
+ message = "SBHS Administrator,\n\n"
+ message += "Following issue requires immidiate attention.\n\n"
+ if len(new_offlines)>0:
+ message += "SBHS could not be connected\n"
+ for n in new_offlines:
+ message += ("MID: %d\n" % n)
+ if bool(faulty_boards):
+ message += "Following devices are suspected to be faulty.\n\n"
+ for key in faulty_boards:
+ message += "MID : {} Cause : {}\n" .format(key,faulty_boards[key])
+ message += "\nYou can check the SBHS status on http://vlabs.iitb.ac.in/sbhs/admin/."
+ message += " Possible correction actions are:\n"
+ message += "1. Run this command without brackets -> ( cd $SBHS_SERVER_ROOT; ./cron_job.sh )\n"
+ message += "2. If same machine comes offline multiple times, replacement of the machine is advised.\n\n\n"
+ message += "Regards,\nSBHS Vlabs Server Code"
+
+ print "New offline board mids", new_offlines
+ subject = "SBHS Vlabs: Notice - SBHS not connected"
+
+
+ print message
+
+ print len(new_offlines) > 0 or len(faulty_boards)>0
+
+ if len(new_offlines) > 0 or len(faulty_boards)>0:
+ for admin in settings.SBHS_ADMINS:
+ helpers.mailer.email(admin[2], subject, message)
+
+ Board.objects.filter(mid__in=current_onlines).update(online=True)
+ Board.objects.exclude(mid__in=current_onlines).update(online=False)
+
+ self.stdout.write('Boards loaded')