Commit 67f6d3cc authored by Gino Tosti's avatar Gino Tosti
Browse files

incuded ful support for integer and renuced the number of generated logs

parent cd58ba2a
Loading
Loading
Loading
Loading
+94 −32
Original line number Diff line number Diff line
@@ -121,6 +121,36 @@ public class baciHelper {
		private String name;
		private String type;
		private Object prop;
		private Double d_val;
		private Boolean b_val;
		private Integer i_val;
		private Float f_val;
		
		
		public Double getD_val() {
			return d_val;
		}
		public void setD_val(Double d_val) {
			this.d_val = d_val;
		}
		public Boolean getB_val() {
			return b_val;
		}
		public void setB_val(Boolean b_val) {
			this.b_val = b_val;
		}
		public Integer getI_val() {
			return i_val;
		}
		public void setI_val(Integer i_val) {
			this.i_val = i_val;
		}
		public Float getF_val() {
			return f_val;
		}
		public void setF_val(Float f_val) {
			this.f_val = f_val;
		}
		public bclass(String name,String type, Object prop) {
			super();
			this.name=name;
@@ -155,7 +185,7 @@ public class baciHelper {
    private boolean isConnected=false;
    private String opc_url=null;
   // private myValueListener myL=null; // = new myDoubleListener(); 
    private UaSubscriptionListener myNL; //= new myNotificationListener();
    private UaSubscriptionListener myNL =null; //= new myNotificationListener();
    private PropErrorListener myEL=null;
    protected ConnectionListener commL=null;
    boolean notify=false;
@@ -187,48 +217,59 @@ public class baciHelper {
	}
	
    public class myNotificationListener implements UaSubscriptionListener{

    	private long Count=0;
		@Override
		public void onAlive() {
			if (Count>10000L) {
				m_logger.info("Server OPC-UA alive");
			commL.notify(opc_url, ConnectionStatus.ALIVE);
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.ALIVE);
				Count=0L;
			}
			Count++;
		}

		@Override
		public void onBufferOverflow(long arg0) {
			m_logger.warning("onBufferOverflow(): " + arg0);
			commL.notify(opc_url, ConnectionStatus.BUFFEROVERFLOW);
//			m_logger.warning("onBufferOverflow(): " + arg0);
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.BUFFEROVERFLOW);
		}

		@Override
		public void onError(Exception arg0) {
			m_logger.severe("Server OPC-UA onError(): " + arg0.getMessage());;
			if (commL!=null)
				commL.notify(opc_url, ConnectionStatus.ERROR);
		}

		@Override
		public void onMissingData(long arg0, long arg1) {
			m_logger.warning("onMissingData(): " + arg0 + ", " + arg1);	
			commL.notify(opc_url, ConnectionStatus.MISSINGDATA);
			//m_logger.warning("onMissingData(): " + arg0 + ", " + arg1);	
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.MISSINGDATA);
		}

		@Override
		public void onTimeout() {
			m_logger.warning("onTimeout()");
			commL.notify(opc_url, ConnectionStatus.TIMEOUT);
			//m_logger.warning("onTimeout()");
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.TIMEOUT);
		}

		@Override
		public void onAfterCreate() {
			m_logger.info("onAfterCreate()");
			commL.notify(opc_url, ConnectionStatus.CREATED);
			//m_logger.info("onAfterCreate()");
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.CREATED);
			
		}

		@Override
		public void onLifetimeTimeout() {
			m_logger.warning("onLifetimeTimeout()");
			commL.notify(opc_url, ConnectionStatus.LIFETIMETIMEOUT);
			//m_logger.warning("onLifetimeTimeout()");
//			if (commL!=null)
//				commL.notify(opc_url, ConnectionStatus.LIFETIMETIMEOUT);
			
		}
    	
@@ -241,9 +282,25 @@ public class baciHelper {
				UaDataSupport ap=(UaDataSupport) source;
				bclass  prop= nodes.get(ap.getNodeIdRefsAsStr());
				checkAlarm(prop.getName(), prop.getProp(),newValue);
				if (newValue instanceof Double ) {
					Double nvalue = (Double) newValue;
					prop.setD_val(nvalue);
					String t = UTCUtility.getUTCDate(System.currentTimeMillis());
					m_logger.fine("Received <"+t+">:"+prop.getName()+":"+prop.getType()+":"+nvalue.toString());
				}else if (newValue instanceof Boolean ) {
					Boolean nvalue = (Boolean) newValue;
					prop.setB_val(nvalue);
					String t = UTCUtility.getUTCDate(System.currentTimeMillis());
					m_logger.fine("Received <"+t+">:"+prop.getName()+":"+prop.getType()+":"+nvalue.toString());
				}else if (newValue instanceof Integer ) {
					Integer nvalue = (Integer) newValue;
					prop.setI_val(nvalue);
					String t = UTCUtility.getUTCDate(System.currentTimeMillis());
				m_logger.info("Received <"+t+">:"+prop.getName()+":"+prop.getType()+":"+nvalue.toString());
					m_logger.fine("Received <"+t+">:"+prop.getName()+":"+prop.getType()+":"+nvalue.toString());
				}else {
					String t = UTCUtility.getUTCDate(System.currentTimeMillis());
					m_logger.fine("Received <"+t+">:Unsupported data type");
				}
			}		
			//m_logger.info("Value Changed");
		} 	
@@ -254,6 +311,7 @@ public class baciHelper {
		this.m_logger=log;
		this.m_comp=comp;
		this.device=m_comp.name();
		this.myNL =new myNotificationListener();
		
	}
	public void setOPCUAurl(String url) {
@@ -312,13 +370,13 @@ public class baciHelper {
		if (prop instanceof ROdouble) {
			ROdouble tmp =(ROdouble)prop;
			Double val = (Double) value;
			if (val > tmp.alarm_high_on()) {
			if (val.doubleValue() > tmp.alarm_high_on()) {
				send_hi_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_HI);
				}
			}
			if (val < tmp.alarm_low_on()) {
			if (val.doubleValue() < tmp.alarm_low_on()) {
				send_low_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_LOW);
@@ -330,13 +388,13 @@ public class baciHelper {
		}else if (prop instanceof ROlong) {
			ROlong tmp =(ROlong)prop;
			Integer val = (Integer) value;
			if (val > tmp.alarm_high_on()) {
			if (val.intValue() > tmp.alarm_high_on()) {
				send_hi_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_HI);
				}
			}
			if (val < tmp.alarm_low_on()) {
			if (val.intValue() < tmp.alarm_low_on()) {
				send_low_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_LOW);
@@ -349,13 +407,13 @@ public class baciHelper {
		else if (prop instanceof ROlongLong) {
			ROlongLong tmp =(ROlongLong)prop;
			Long val = (Long) value;
			if (val > tmp.alarm_high_on()) {
			if (val.longValue() > tmp.alarm_high_on()) {
				send_hi_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_HI);
				}
			}
			if (val < tmp.alarm_low_on()) {
			if (val.longValue() < tmp.alarm_low_on()) {
				send_low_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_LOW);
@@ -368,13 +426,13 @@ public class baciHelper {
		else if (prop instanceof ROfloat) {
			ROfloat tmp =(ROfloat)prop;
			Float val = (Float) value;
			if (val > tmp.alarm_high_on()) {
			if (val.floatValue() > tmp.alarm_high_on()) {
				send_hi_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_HI);
				}
			}
			if (val < tmp.alarm_low_on()) {
			if (val.floatValue() < tmp.alarm_low_on()) {
				send_low_Alarm(name, true);
				if(notify) {
					myEL.onError(name,AlarmState.ALARM_LOW);
@@ -469,11 +527,6 @@ public class baciHelper {
		//addValueListener(name);
		return prop;
    }
	public RWuLongLong createRWuLongLongProp(String name, String Node) throws PropertyInitializationFailed {
		dataAccess.put(name, new UaDataSupport(opc_url,Node));    
		RWuLongLongImpl impl = new RWuLongLongImpl(name, m_comp, dataAccess.get(name));
        return RWuLongLongHelper.narrow(m_comp.registerProperty(impl, new RWuLongLongPOATie(impl)));
        }
	public ROboolean createRObooleanProp(String name, String Node) throws PropertyInitializationFailed {
		dataAccess.put(name, new UaDataSupport(opc_url,Node));
		RObooleanImpl impl = new RObooleanImpl(name, m_comp, dataAccess.get(name));
@@ -526,6 +579,11 @@ public class baciHelper {
		RWbooleanImpl impl = new RWbooleanImpl(name, m_comp, dataAccess.get(name));
		return RWbooleanHelper.narrow(m_comp.registerProperty(impl, new RWbooleanPOATie(impl)));
	}
	public RWuLongLong createRWuLongLongProp(String name, String Node) throws PropertyInitializationFailed {
		dataAccess.put(name, new UaDataSupport(opc_url,Node));    
		RWuLongLongImpl impl = new RWuLongLongImpl(name, m_comp, dataAccess.get(name));
        return RWuLongLongHelper.narrow(m_comp.registerProperty(impl, new RWuLongLongPOATie(impl)));
        }
	public ROlongSeq createROlongSeqProp(String name, String Node) throws PropertyInitializationFailed {
		UaDataSupport uas= new UaDataSupport(opc_url,Node);
		uas.setConversionToPrimitiveArrayEnabled(true);
@@ -612,6 +670,7 @@ public class baciHelper {
			if (checkCompletion(c, name,arg0)) {
				m_logger.info("read property "+ name+":"+val+" at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
			}else {
				m_logger.severe("error in reading "+ name+": at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}
				
@@ -639,6 +698,7 @@ public class baciHelper {
			if (checkCompletion(c, name,arg0)) {
				m_logger.info("read property "+ name+":"+val.toString()+" at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
			}else {
				m_logger.severe("error in reading "+ name+": at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}
				
@@ -669,6 +729,7 @@ public class baciHelper {
				m_logger.info("read property "+ name+":"+val.toString()+" at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}else {
				m_logger.severe("error in reading "+ name+": at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}
		}else{
@@ -696,6 +757,7 @@ public class baciHelper {
				m_logger.info("read property "+ name+":"+val+" at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}else {
				m_logger.severe("error in reading "+ name+": at t="+ UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(arg0.value)));
				return val;
			}
		}else{