From d8f0b7e37768bacc51c1c76f10caf3fa9863da7b Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Thu, 9 Mar 2023 14:21:51 +0100
Subject: [PATCH] Initial import

---
 acsboard104.pro     |  12 +++++
 src/acsboard104.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++
 src/acsboard104.h   |  50 ++++++++++++++++++
 src/acsboard104.ui  | 123 ++++++++++++++++++++++++++++++++++++++++++++
 src/main.cpp        |  41 +++++++++++++++
 5 files changed, 347 insertions(+)
 create mode 100644 acsboard104.pro
 create mode 100644 src/acsboard104.cpp
 create mode 100644 src/acsboard104.h
 create mode 100644 src/acsboard104.ui
 create mode 100644 src/main.cpp

diff --git a/acsboard104.pro b/acsboard104.pro
new file mode 100644
index 0000000..d400f3c
--- /dev/null
+++ b/acsboard104.pro
@@ -0,0 +1,12 @@
+include(/usr/local/qtango/include/qtango6/qtango.pri)
+# include(/runtime/elettra/include/qtango4/qtango.pri)
+# include(../../../../utils/qmake.custom.3)
+
+SOURCES += src/acsboard104.cpp \
+           src/main.cpp
+
+HEADERS += src/acsboard104.h
+
+FORMS    = src/acsboard104.ui
+
+TARGET   = ../acs/bin/acsboard104
diff --git a/src/acsboard104.cpp b/src/acsboard104.cpp
new file mode 100644
index 0000000..0055c8a
--- /dev/null
+++ b/src/acsboard104.cpp
@@ -0,0 +1,121 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by    *
+ *      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+
+#include "acsboard104.h"
+#include <qtango.h>
+
+	char tmBuffer[80];
+/*
+  timestamp() 
+  send a timestamp to standard output
+*/
+void timestamp() 
+{
+	struct tm *mytime;
+	time_t myTime_t;
+	myTime_t = time(NULL);
+	mytime = localtime(&myTime_t);
+	strftime(tmBuffer, 79, "%Y-%m-%d %H:%M:%S ", mytime);
+	return;
+}
+
+acsboard104::acsboard104(QWidget *parent) : QWidget(parent)
+{
+	// setup User Interface
+	try {
+		ui.setupUi(this);
+	}
+	catch (const Tango::DevFailed &e) {
+		timestamp();
+		cout << tmBuffer << "cannot setup UI" << endl;
+	}
+	catch (...) {
+		timestamp();
+		cout << tmBuffer << "default exception, cannot setup UI" << endl;
+	}
+	// connect to control access server
+	try {
+		// plc_server = new Tango::DeviceProxy("ken/plcaccess/0");
+		plc_server = new Tango::DeviceProxy("sr/accessi/pss");
+	}
+	catch (const Tango::DevFailed &e) {
+		timestamp();
+		cout << tmBuffer << "Fatal Error: Access Control Device Server not responding, the application will be terminated immediately" << endl;
+		exit(1);
+	}
+	catch (...) {
+		timestamp();
+		cout << tmBuffer << "Fatal Error: Access Control Device Server not responding, the application will be terminated immediately" << endl;
+		exit(1);
+	}
+	refresh();
+	// init timer
+	try {
+		timer = new QTimer(this);
+		timer->setInterval(1000);
+		timer->setSingleShot(false);
+		connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
+		timer->start();
+	}
+	catch (const Tango::DevFailed &e) {
+		timestamp();
+		cout << tmBuffer << "cannot connect UI" << endl;
+	}
+	catch (...) {
+		timestamp();
+		cout << tmBuffer << "default exception, cannot setup UI" << endl;
+	}
+}
+
+acsboard104::~acsboard104()
+{
+}    
+
+int acsboard104::myReadAttribute(const char *attrName)
+{
+	try {
+		myAttribute = plc_server->read_attribute(attrName);
+		return 1;
+	}
+	catch (const Tango::DevFailed &e) {
+		timestamp();
+		cout << "error reading attribute: " << attrName << endl;
+	}
+	catch (...) {
+		timestamp();
+		cout << tmBuffer << "default exception reading attribute: " << attrName << endl;
+	}
+	return 0;
+}
+
+void acsboard104::refresh()
+{
+	vector<bool> stat;
+	if (myReadAttribute("Disabled_board_104")) {
+		try {
+			myAttribute >> stat;
+		}
+		catch (const Tango::DevFailed &e) {
+		}
+		ui.checkBox_0->setCheckState(stat[0]? Qt::Checked: Qt::Unchecked);
+		ui.checkBox_1->setCheckState(stat[1]? Qt::Checked: Qt::Unchecked);
+	}
+}
diff --git a/src/acsboard104.h b/src/acsboard104.h
new file mode 100644
index 0000000..765e1c6
--- /dev/null
+++ b/src/acsboard104.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by    *
+ *      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+
+#ifndef acsboard104_H
+#define acsboard104_H
+
+#include "ui_acsboard104.h"
+#include <tango.h>
+#include <QProcess>
+
+class acsboard104: public QWidget
+{
+    Q_OBJECT
+
+public:
+    acsboard104(QWidget * =NULL);
+    ~acsboard104();
+
+public slots:
+    void refresh();
+
+private:
+    Ui::acsboard104 ui;
+    QTimer *timer;
+    Tango::DeviceAttribute myAttribute;
+    Tango::DeviceProxy 	*plc_server;
+    int myReadAttribute(const char *);
+
+};
+
+
+#endif
diff --git a/src/acsboard104.ui b/src/acsboard104.ui
new file mode 100644
index 0000000..0cd055e
--- /dev/null
+++ b/src/acsboard104.ui
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>acsboard104</class>
+ <widget class="QWidget" name="acsboard104">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>460</width>
+    <height>30</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>460</width>
+    <height>30</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>460</width>
+    <height>30</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>BOARD 104 - ingressi</string>
+  </property>
+  <widget class="QLabel" name="label_1">
+   <property name="geometry">
+    <rect>
+     <x>5</x>
+     <y>63</y>
+     <width>420</width>
+     <height>18</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="text">
+    <string>key_RFs_fail: chiave RF service failure</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>5</x>
+     <y>6</y>
+     <width>420</width>
+     <height>18</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="text">
+    <string>key_1a_ABI_fail: chiave 1a abilitazione failure</string>
+   </property>
+  </widget>
+  <widget class="Line" name="line_4">
+   <property name="geometry">
+    <rect>
+     <x>430</x>
+     <y>0</y>
+     <width>2</width>
+     <height>361</height>
+    </rect>
+   </property>
+   <property name="orientation">
+    <enum>Qt::Vertical</enum>
+   </property>
+  </widget>
+  <widget class="Line" name="line_14">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>83</y>
+     <width>780</width>
+     <height>2</height>
+    </rect>
+   </property>
+   <property name="orientation">
+    <enum>Qt::Horizontal</enum>
+   </property>
+  </widget>
+  <widget class="QCheckBox" name="checkBox_0">
+   <property name="geometry">
+    <rect>
+     <x>440</x>
+     <y>60</y>
+     <width>16</width>
+     <height>21</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string/>
+   </property>
+  </widget>
+  <widget class="QCheckBox" name="checkBox_1">
+   <property name="geometry">
+    <rect>
+     <x>440</x>
+     <y>3</y>
+     <width>16</width>
+     <height>21</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string/>
+   </property>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..e56003d
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by    *
+ *      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+
+#include <QApplication>
+#include "acsboard104.h"
+#include <X11/Xlib.h>
+#include <QX11Info>
+#define CVSVERSION "$Name:  $"
+
+int main( int argc, char ** argv ) {
+
+    QApplication a( argc, argv );
+    a.setApplicationVersion(CVSVERSION);
+    acsboard104 mw;
+    mw.show();
+
+    /* register to window manager */
+    Display *disp = QX11Info::display();
+    Window root_win = (Window) mw.winId();
+    XSetCommand(disp, root_win, argv, argc);
+	
+    return a.exec();
+}
-- 
GitLab