diff --git a/volumes/sirm/apps/main/management/commands/restart_pedestal.py b/volumes/sirm/apps/main/management/commands/restart_pedestal.py index 414bfd3..77977ac 100644 --- a/volumes/sirm/apps/main/management/commands/restart_pedestal.py +++ b/volumes/sirm/apps/main/management/commands/restart_pedestal.py @@ -39,6 +39,18 @@ def pedestal_start(self, id_exp): exp.pedestal.start_device(name_experiment=name) self.stdout.write(f'"{exp.name}" experiment: Pedestal acquisition was restarted') +def pedestal_reset(self, id_exp): + all_status = Experiment.objects.filter(status=2) + check_id = False + + if len(all_status) > 0: + check_id = all_status[0].pk + + if check_id and check_id == id_exp: + exp = get_object_or_404(Experiment, pk=id_exp) + exp.pedestal.reset_device() + self.stdout.write(f'"{exp.name}" experiment: Pedestal acquisition is resetting') + def pedestal_stop(self, id_exp): all_status = Experiment.objects.filter(status=2) check_id = False @@ -49,7 +61,7 @@ def pedestal_stop(self, id_exp): if check_id and check_id == id_exp: exp = get_object_or_404(Experiment, pk=id_exp) exp.pedestal.stop_device() - self.stdout.write(f'"{exp.name}" experiment: Pedestal acquisition "{exp.name}" was stopped') + self.stdout.write(f'"{exp.name}" experiment: Pedestal acquisition was stopped') def hdf5_list_content(get_file): table_records = np.array(get_file).tolist() @@ -180,8 +192,6 @@ def restart_pedestal(self): pedestal_stop(self, id_exp) time.sleep(14) - #pedestal_reset(self, id_exp) - #time.sleep(2) pedestal_start(self, id_exp) else: @@ -190,10 +200,10 @@ def restart_pedestal(self): else: self.stdout.write(f'No file increment, retry') + pedestal_reset(self, id_exp) + time.sleep(14) pedestal_stop(self, id_exp) time.sleep(14) - #pedestal_reset(self, id_exp) - #time.sleep(2) pedestal_start(self, id_exp) else: diff --git a/volumes/sirm/apps/main/management/commands/restart_reception.py b/volumes/sirm/apps/main/management/commands/restart_reception.py index ec1c75b..d6594a9 100644 --- a/volumes/sirm/apps/main/management/commands/restart_reception.py +++ b/volumes/sirm/apps/main/management/commands/restart_reception.py @@ -37,11 +37,15 @@ def acquisition_start(self, id_exp): name = '{}-R@{}'.format(exp.name, datetime.now().strftime('%Y-%m-%dT%H-%M-%S')) exp.reception_rx.start_device(name_experiment = name, restart = True) self.stdout.write(f'"{exp.name}" experiment: Data acquisition was restarted') + self.stdout.write(f'Restarting schain...') + datadir_exp = exp.reception_rx.datadir + datadir_exp = datadir_exp.replace(os.environ.get('EXPOSE_NAS', '/DATA_RM/DATA') + '/', '') + datadir_exp = datadir_exp.replace('/rawdata', '') r = requests.get('http://'+os.environ.get('SCHAIN_SITE', 'sophy-schain')+'/stop') time.sleep(1) - r = requests.post('http://'+os.environ.get('SCHAIN_SITE', 'sophy-schain')+'/start', json={'name': exp.name}) + r = requests.post('http://'+os.environ.get('SCHAIN_SITE', 'sophy-schain')+'/start', json={'name': datadir_exp}) def acquisition_stop(self, id_exp): all_status = Experiment.objects.filter(status=2) diff --git a/volumes/sirm/apps/main/models.py b/volumes/sirm/apps/main/models.py index 53de5fb..4ae5eba 100644 --- a/volumes/sirm/apps/main/models.py +++ b/volumes/sirm/apps/main/models.py @@ -342,6 +342,8 @@ class Experiment(PolymorphicModel): time.sleep(0.1) self.reception_rx.stop_device() time.sleep(0.1) + self.pedestal.reset_device() + time.sleep(14) self.pedestal.stop_device() time.sleep(0.1) proc_url = 'http://'+os.environ['PROC_SITE']+'/stop' diff --git a/volumes/sirm/apps/pedestal/models.py b/volumes/sirm/apps/pedestal/models.py index 7a2c733..9d71f67 100644 --- a/volumes/sirm/apps/pedestal/models.py +++ b/volumes/sirm/apps/pedestal/models.py @@ -118,7 +118,25 @@ class PedestalConfiguration(Configuration): self.device.save() return True - def reset_device(self, axi, angle): + def reset_device(self): + + try: + r = requests.get(self.device.url() + 'reset') + + if r: + #self.device.status = 3 + #self.device.save() + self.message = 'Pedestal restarted' + else: + return False + + except Exception as e: + self.message = "Pedestal can't restarted: {}".format(str(e)) + return False + + return True + + def initial_device(self, axi, angle): try: url = self.device.url() + "position?params=" @@ -153,12 +171,12 @@ class PedestalConfiguration(Configuration): if r: self.device.status = 3 self.device.save() - self.message = 'Pedestal reset' + self.message = 'Pedestal - initial position' else: return False except Exception as e: - self.message = 'Pedestal reset: {}'.format(str(e)) + self.message = 'Pedestal - initial position: {}'.format(str(e)) return False return True @@ -173,7 +191,7 @@ class PedestalConfiguration(Configuration): AX = {'az':'azimuth', 'el':'elevation'} axis = [AX[x.lower().strip()] for x in self.axis.split(',')] list_of_floats = [float(x.strip()) for x in self.angle.split(",")] - self.reset_device(axis[0], list_of_floats[0]) + self.initial_device(axis[0], list_of_floats[0]) if r: self.device.status = 4 @@ -293,4 +311,7 @@ class PedestalConfiguration(Configuration): return payload def get_absolute_url_import(self): - return reverse('url_import_pedestal_conf', args=[str(self.id)]) \ No newline at end of file + return reverse('url_import_pedestal_conf', args=[str(self.id)]) + + def get_absolute_url_reset(self): + return reverse('url_reset_pedestal_conf', args=[str(self.id)]) \ No newline at end of file diff --git a/volumes/sirm/apps/pedestal/templates/pedestal_conf.html b/volumes/sirm/apps/pedestal/templates/pedestal_conf.html index 2218f63..945ec69 100644 --- a/volumes/sirm/apps/pedestal/templates/pedestal_conf.html +++ b/volumes/sirm/apps/pedestal/templates/pedestal_conf.html @@ -3,6 +3,10 @@ {% load bootstrap4 %} {% load main_tags %} +{% block extra-menu-actions %} +
  • Reset
  • +{% endblock %} + {% block content-detail %}

    Pedestal

    diff --git a/volumes/sirm/apps/pedestal/urls.py b/volumes/sirm/apps/pedestal/urls.py index ef42daa..69d452f 100644 --- a/volumes/sirm/apps/pedestal/urls.py +++ b/volumes/sirm/apps/pedestal/urls.py @@ -6,6 +6,7 @@ urlpatterns = ( path('/', views.conf, name='url_pedestal_conf'), path('/import/', views.import_file, name='url_import_pedestal_conf'), path('/edit/', views.conf_edit, name='url_edit_pedestal_conf'), + path('/reset/', views.conf_reset, name='url_reset_pedestal_conf'), #url(r'^(?P-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_pedestal_conf'), #url(r'^(?P-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_pedestal_conf'), ) diff --git a/volumes/sirm/apps/pedestal/views.py b/volumes/sirm/apps/pedestal/views.py index d25de12..320081f 100644 --- a/volumes/sirm/apps/pedestal/views.py +++ b/volumes/sirm/apps/pedestal/views.py @@ -114,6 +114,18 @@ def import_file(request, conf_id): return render(request, 'pedestal_import.html', kwargs) +@login_required +def conf_reset(request, conf_id): + + conf = get_object_or_404(PedestalConfiguration, pk=conf_id) + + if conf.reset_device(): + messages.success(request, conf.message) + else: + messages.error(request, conf.message) + + return redirect(conf.get_absolute_url()) + def conf_raw(request, conf_id): conf = get_object_or_404(PedestalConfiguration, pk=conf_id) raw = conf.write_device(raw=True)