public class HpDataValidator {
public boolean validate(DataMessage data) throws SerialServerException {
if (data.getFrequency() < 0.0001) {
throw new SerialServerException(5, "frequency out of range");
}
if (data.getAmplitude() < 0.05 ||
data.getAmplitude() > 10 ) {
throw new SerialServerException(4, "amplitude out of range");
}
if (data.getWaveShape().equals(WaveShape.DC)) {
}
else if (data.getWaveShape().equals(WaveShape.NOISE)) {
}
else if (data.getWaveShape().equals(WaveShape.RAMP)) {
if (data.getFrequency() > 100000) {
throw new SerialServerException(5, "frequency out of range");
}
}
else if (data.getWaveShape().equals(WaveShape.SINE)) {
if (data.getFrequency() > 15000000) {
throw new SerialServerException(5, "frequency out of range");
}
}
else if (data.getWaveShape().equals(WaveShape.SQUARE)) {
if (data.getFrequency() > 15000000) {
throw new SerialServerException(5, "frequency out of range");
}
}
else if (data.getWaveShape().equals(WaveShape.TRIANGLE)) {
if (data.getFrequency() > 100000) {
throw new SerialServerException(5, "frequency out of range");
}
}
if (! ( (Math.abs(data.getOffset()) + (data.getAmplitude()/2)) < 10
&&
Math.abs(data.getOffset()) <= 2* data.getAmplitude()
) ) {
throw new SerialServerException(3, "offset out of range");
}
return true;