ArduinoSignalDataType.java
/*******************************************************************************
* jArduino: Arduino C++ Code Generation From Java
* Copyright 2020 Tony Washer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package net.sourceforge.jarduino.message;
import net.sourceforge.jarduino.message.ArduinoParser.ArduinoParserException;
/**
* Arduino Signal DataType.
*/
public enum ArduinoSignalDataType {
/**
* littleEndianSigned.
*/
LESIGNED("1-"),
/**
* littleEndianUnsSigned.
*/
LEUNSIGNED("1+"),
/**
* bigEndianSigned.
*/
BESIGNED("0-"),
/**
* bigEndianUnsigned.
*/
BEUNSIGNED("0+");
/**
* The definition.
*/
private final String theDef;
/**
* littleEndian.
*/
private final boolean littleEndian;
/**
* Signed.
*/
private final boolean isSigned;
/**
* Constructor.
* @param pDef the definition
*/
ArduinoSignalDataType(final String pDef) {
theDef = pDef;
littleEndian = pDef.charAt(0) == '1';
isSigned = pDef.charAt(1) == '-';
}
/**
* Obtain the definition.
* @return the definition
*/
public String getDefinition() {
return theDef;
}
/**
* Is littleEndian?
* @return true/false
*/
public boolean isLittleEndian() {
return littleEndian;
}
/**
* Is Signed?
* @return true/false
*/
public boolean isSigned() {
return isSigned;
}
/**
* Parse dataType.
* @param pDataType the dataType representation
* @return the dataType
* @throws ArduinoParserException on error
*/
static ArduinoSignalDataType parseDataType(final String pDataType) throws ArduinoParserException {
/* Loop through the values */
for (ArduinoSignalDataType myType : values()) {
if (pDataType.equals(myType.theDef)) {
return myType;
}
}
throw new ArduinoParserException("Invalid DataType", pDataType);
}
@Override
public String toString() {
return theDef;
}
}