use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class VMStatDataSourceRT method readParts.
private void readParts(String[] parts) {
TranslatableMessage error = null;
long time = System.currentTimeMillis();
pointListChangeLock.readLock().lock();
try {
for (DataPointRT dp : dataPoints) {
VMStatPointLocatorVO locator = ((VMStatPointLocatorRT) dp.getPointLocator()).getVo();
Integer position = attributePositions.get(locator.getAttributeId());
if (position == null) {
if (error != null)
error = new TranslatableMessage("event.vmstat.attributeNotFound", locator.getConfigurationDescription());
} else {
try {
String data = parts[position];
Double value = new Double(data);
dp.updatePointValue(new PointValueTime(value, time));
} catch (NumberFormatException e) {
log.error("Weird. We couldn't parse the value " + parts[position] + " into a double. attribute=" + locator.getAttributeId());
} catch (ArrayIndexOutOfBoundsException e) {
log.error("Weird. We need element " + position + " but the vmstat data is only " + parts.length + " elements long. The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output.");
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.vmstat.process", "The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output."));
}
}
}
} finally {
pointListChangeLock.readLock().unlock();
}
if (error == null)
returnToNormal(PARSE_EXCEPTION_EVENT, time);
else
raiseEvent(PARSE_EXCEPTION_EVENT, time, true, error);
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class SerialDataSourceRT method setPointValueImpl.
@Override
public void setPointValueImpl(DataPointRT dataPoint, PointValueTime valueTime, SetPointSource source) {
// Are we connected?
if (this.port == null && !connect()) {
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailedPortNotSetup"));
return;
}
try {
setPointValueImplTransport(dataPoint, valueTime);
returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (IOException e) {
if (vo.getRetries() == 0)
LOG.error("Failed setting serial point " + dataPoint.getVO().getExtendedName() + ": " + e.getMessage(), e);
// Try and reset the connection
Exception ex = e;
int retries = vo.getRetries();
while (retries > 0) {
try {
retries -= 1;
if (this.port != null)
Common.serialPortManager.close(this.port);
if (this.connect()) {
setPointValueImplTransport(dataPoint, valueTime);
returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis());
return;
}
} catch (Exception e2) {
ex = e2;
}
}
if (ex != null) {
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailed", e.getMessage()));
LOG.error("Error re-connecting to serial port.", ex);
}
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class SerialDataSourceRT method setPointValueImplTransport.
private void setPointValueImplTransport(DataPointRT dataPoint, PointValueTime valueTime) throws IOException {
OutputStream os = this.port.getOutputStream();
if (os == null)
throw new IOException("Port is closed.");
// Create Message from Message Start
SerialPointLocatorRT pl = dataPoint.getPointLocator();
byte[] data;
if (this.vo.isHex()) {
// Convert to Hex
try {
switch(dataPoint.getDataTypeId()) {
case DataTypes.ALPHANUMERIC:
data = convertToHex(valueTime.getStringValue());
break;
case DataTypes.BINARY:
if (valueTime.getBooleanValue())
data = convertToHex("00");
else
data = convertToHex("01");
break;
case DataTypes.MULTISTATE:
String intValue = Integer.toString(valueTime.getIntegerValue());
if (intValue.length() % 2 != 0)
intValue = "0" + intValue;
data = convertToHex(intValue);
break;
case DataTypes.NUMERIC:
String numValue = Integer.toString(valueTime.getIntegerValue());
if (numValue.length() % 2 != 0)
numValue = "0" + numValue;
data = convertToHex(numValue);
break;
default:
throw new ShouldNeverHappenException("Unsupported data type" + dataPoint.getDataTypeId());
}
if (this.vo.isLogIO())
this.ioLog.log(false, data);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.notHex"));
return;
}
} else {
// Pin the terminator on the end
String messageTerminator = ((SerialDataSourceVO) this.getVo()).getMessageTerminator();
// Do we need to or is it already on the end?
String identifier = pl.getVo().getPointIdentifier();
String fullMsg = identifier + valueTime.getStringValue();
if (!fullMsg.endsWith(messageTerminator)) {
fullMsg += messageTerminator;
}
// String output = newValue.getStringValue();
data = fullMsg.getBytes();
if (vo.isLogIO())
this.ioLog.log("O: " + fullMsg);
}
for (byte b : data) {
os.write(b);
}
os.flush();
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.
the class BaseDwr method prepareBasePointState.
/**
* Base method for preparing information in a state object and returning a
* point value.
*
* @param componentId
* a unique id for the browser side component. Required for set
* point snippets.
* @param state
* @param point
* @param status
* @param model
* @return
*/
protected static PointValueTime prepareBasePointState(String componentId, BasePointState state, DataPointVO pointVO, DataPointRT point, Map<String, Object> model) {
model.clear();
model.put("componentId", componentId);
model.put("point", pointVO);
model.put("pointRT", point);
model.put(MODEL_ATTR_TRANSLATIONS, getTranslations());
PointValueTime pointValue = null;
if (point == null)
model.put("disabled", "true");
else {
pointValue = point.getPointValue();
if (pointValue != null)
model.put("pointValue", pointValue);
}
return pointValue;
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.
the class DataPointDetailsDwr method getPointData.
public static PointDetailsState getPointData() {
// Get the point from the user's session. It should have been set by the controller.
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
User user = Common.getUser(request);
DataPointVO pointVO = user.getEditPoint();
// Create the watch list state.
Map<String, Object> model = new HashMap<String, Object>();
// Get the data point status from the data image.
DataPointRT pointRT = Common.runtimeManager.getDataPoint(pointVO.getId());
PointDetailsState state = new PointDetailsState();
state.setId(Integer.toString(pointVO.getId()));
PointValueTime pointValue = prepareBasePointState(Integer.toString(pointVO.getId()), state, pointVO, pointRT, model);
setPrettyText(request, state, pointVO, model, pointValue);
setChange(pointVO, state, pointRT, request, model, user);
setEvents(pointVO, user, model, pointEventsLimit);
setMessages(state, request, "dataPointMessages.jsp", model);
return state;
}
Aggregations