import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.util.HexUtils;
import org.slf4j.Logger;
*
* @return the current power status
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public SonyProjectorStatusPower getStatusPower() throws SonyProjectorException {
return SonyProjectorStatusPower.getFromDataCode(getSetting(SonyProjectorItem.STATUS_POWER));
/**
* Power ON the projector
*
- * @throws SonyProjectorException - In case the projector is not ready for a power ON command or any other problem
+ * @throws SonyProjectorException in case the projector is not ready for a power ON command or any other problem
*/
public void powerOn() throws SonyProjectorException {
SonyProjectorStatusPower status = null;
/**
* Power OFF the projector
*
- * @throws SonyProjectorException - In case the projector is not ready for a power OFF command or any other problem
+ * @throws SonyProjectorException in case the projector is not ready for a power OFF command or any other problem
*/
public void powerOff() throws SonyProjectorException {
SonyProjectorStatusPower status = null;
*
* @return the current calibration preset
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getCalibrationPreset() throws SonyProjectorException {
return model.getCalibrPresetNameFromDataCode(getSetting(SonyProjectorItem.CALIBRATION_PRESET));
*
* @param value the calibration preset to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setCalibrationPreset(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.CALIBRATION_PRESET, model.getCalibrPresetDataCodeFromName(value));
*
* @return the current video input
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getInput() throws SonyProjectorException {
return model.getInputNameFromDataCode(getSetting(SonyProjectorItem.INPUT));
*
* @param value the video input to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setInput(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.INPUT, model.getInputDataCodeFromName(value));
*
* @return the current contrast value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getContrast() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.CONTRAST));
*
* @param value the contrast value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setContrast(int value) throws SonyProjectorException {
setSetting(SonyProjectorItem.CONTRAST, convertIntToData(value));
*
* @return the current brightness value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getBrightness() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.BRIGHTNESS));
*
* @param value the brightness value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setBrightness(int value) throws SonyProjectorException {
setSetting(SonyProjectorItem.BRIGHTNESS, convertIntToData(value));
*
* @return the current color value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getColor() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.COLOR));
*
* @param value the color value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setColor(int value) throws SonyProjectorException {
setSetting(SonyProjectorItem.COLOR, convertIntToData(value));
*
* @return the current hue value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getHue() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.HUE));
*
* @param value the hue value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setHue(int value) throws SonyProjectorException {
setSetting(SonyProjectorItem.HUE, convertIntToData(value));
*
* @return the current sharpness value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getSharpness() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.SHARPNESS));
*
* @param value the sharpness value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setSharpness(int value) throws SonyProjectorException {
setSetting(SonyProjectorItem.SHARPNESS, convertIntToData(value));
*
* @return the current contrast enhancer mode
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getContrastEnhancer() throws SonyProjectorException {
return model.getContrastEnhancerNameFromDataCode(getSetting(SonyProjectorItem.CONTRAST_ENHANCER));
*
* @param value the contrast enhancer mode to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setContrastEnhancer(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.CONTRAST_ENHANCER, model.getContrastEnhancerDataCodeFromName(value));
*
* @return the current film mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getFilmMode() throws SonyProjectorException {
if (!model.isFilmModeAvailable()) {
*
* @param value the film mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setFilmMode(String value) throws SonyProjectorException {
if (!model.isFilmModeAvailable()) {
*
* @return the lamp use time
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public int getLampUseTime() throws SonyProjectorException {
return convertDataToInt(getSetting(SonyProjectorItem.LAMP_USE_TIME));
*
* @return the current mode for the lamp control setting
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getLampControl() throws SonyProjectorException {
if (!model.isLampControlAvailable()) {
*
* @param value the mode to set for the lamp control setting
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setLampControl(String value) throws SonyProjectorException {
if (!model.isLampControlAvailable()) {
*
* @return OnOffType.ON if the picture is muted, OnOffType.OFF if not
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public OnOffType getPictureMuting() throws SonyProjectorException {
return Arrays.equals(getSetting(SonyProjectorItem.PICTURE_MUTING), PICTURE_ON) ? OnOffType.ON : OnOffType.OFF;
/**
* Request the projector to mute the picture
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void mutePicture() throws SonyProjectorException {
setSetting(SonyProjectorItem.PICTURE_MUTING, PICTURE_ON);
/**
* Request the projector to unmute the picture
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void unmutePicture() throws SonyProjectorException {
setSetting(SonyProjectorItem.PICTURE_MUTING, PICTURE_OFF);
*
* @return the current mode for the picture position setting
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getPicturePosition() throws SonyProjectorException {
if (!model.isPicturePositionAvailable()) {
*
* @param value the mode to set for the picture position setting
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setPicturePosition(String value) throws SonyProjectorException {
if (!model.isPicturePositionAvailable()) {
*
* @return OnOffType.ON if the overscan is enabled, OnOffType.OFF if not
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public OnOffType getOverscan() throws SonyProjectorException {
if (!model.isOverscanAvailable()) {
/**
* Request the projector to enable the overscan
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void enableOverscan() throws SonyProjectorException {
if (!model.isOverscanAvailable()) {
/**
* Request the projector to disable the overscan
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void disableOverscan() throws SonyProjectorException {
if (!model.isOverscanAvailable()) {
*
* @return the current current aspect ratio mode
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getAspect() throws SonyProjectorException {
return model.getAspectNameFromDataCode(getSetting(SonyProjectorItem.ASPECT));
*
* @param value the aspect ratio mode to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setAspect(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.ASPECT, model.getAspectCodeFromName(value));
*
* @return the current color temperature value
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getColorTemperature() throws SonyProjectorException {
return model.getColorTempNameFromDataCode(getSetting(SonyProjectorItem.COLOR_TEMP));
*
* @param value the color temperature value to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setColorTemperature(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.COLOR_TEMP, model.getColorTempCodeFromName(value));
*
* @return the current iris mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getIrisMode() throws SonyProjectorException {
if (!model.isIrisModeAvailable()) {
*
* @param value the iris mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setIrisMode(String value) throws SonyProjectorException {
if (!model.isIrisModeAvailable()) {
*
* @return the current value for the iris manual setting
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public int getIrisManual() throws SonyProjectorException {
if (!model.isIrisManualAvailable()) {
*
* @param value the iris manual value to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setIrisManual(int value) throws SonyProjectorException {
if (!model.isIrisManualAvailable()) {
*
* @return the current iris sensitivity
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getIrisSensitivity() throws SonyProjectorException {
if (!model.isIrisSensitivityAvailable()) {
*
* @param value the iris sensitivity to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setIrisSensitivity(String value) throws SonyProjectorException {
if (!model.isIrisSensitivityAvailable()) {
*
* @return the current film projection mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getFilmProjection() throws SonyProjectorException {
if (!model.isFilmProjectionAvailable()) {
*
* @param value the film projection mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setFilmProjection(String value) throws SonyProjectorException {
if (!model.isFilmProjectionAvailable()) {
*
* @return the current motion enhancer mode
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getMotionEnhancer() throws SonyProjectorException {
if (!model.isMotionEnhancerAvailable()) {
*
* @param value the motion enhancer mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setMotionEnhancer(String value) throws SonyProjectorException {
if (!model.isMotionEnhancerAvailable()) {
*
* @return the current gamma correction
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getGammaCorrection() throws SonyProjectorException {
return model.getGammaCorrectionNameFromDataCode(getSetting(SonyProjectorItem.GAMMA_CORRECTION));
*
* @param value the gamma correction to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setGammaCorrection(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.GAMMA_CORRECTION, model.getGammaCorrectionCodeFromName(value));
*
* @return the current color space
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getColorSpace() throws SonyProjectorException {
return model.getColorSpaceNameFromDataCode(getSetting(SonyProjectorItem.COLOR_SPACE));
*
* @param value the color space to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setColorSpace(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.COLOR_SPACE, model.getColorSpaceCodeFromName(value));
*
* @return the current noise reduction mode
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getNr() throws SonyProjectorException {
return model.getNrNameFromDataCode(getSetting(SonyProjectorItem.NR));
*
* @param value the noise reduction mode to set
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public void setNr(String value) throws SonyProjectorException {
setSetting(SonyProjectorItem.NR, model.getNrCodeFromName(value));
*
* @return the current block noise reduction mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getBlockNr() throws SonyProjectorException {
if (!model.isBlockNrAvailable()) {
*
* @param value the block noise reduction mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setBlockNr(String value) throws SonyProjectorException {
if (!model.isBlockNrAvailable()) {
*
* @return the current mosquito noise reduction mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getMosquitoNr() throws SonyProjectorException {
if (!model.isMosquitoNrAvailable()) {
*
* @param value the mosquito noise reduction mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setMosquitoNr(String value) throws SonyProjectorException {
if (!model.isMosquitoNrAvailable()) {
*
* @return the current MPEG noise reduction mode
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public String getMpegNr() throws SonyProjectorException {
if (!model.isMpegNrAvailable()) {
*
* @param value the MPEG noise reduction mode to set
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void setMpegNr(String value) throws SonyProjectorException {
if (!model.isMpegNrAvailable()) {
*
* @return the current value for xvColor
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public OnOffType getXvColor() throws SonyProjectorException {
if (!model.isXvColorAvailable()) {
/**
* Request the projector to set xvColor to ON
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void enableXvColor() throws SonyProjectorException {
if (!model.isXvColorAvailable()) {
/**
* Request the projector to set xvColor to OFF
*
- * @throws SonyProjectorException - In case this setting is not available for the projector or any other problem
+ * @throws SonyProjectorException in case this setting is not available for the projector or any other problem
*/
public void disableXvColor() throws SonyProjectorException {
if (!model.isXvColorAvailable()) {
*
* @return the current value for the setting
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
protected byte[] getSetting(SonyProjectorItem item) throws SonyProjectorException {
logger.debug("Get setting {}", item.getName());
logger.debug("Get setting {} succeeded: result data: {}", item.getName(), HexUtils.bytesToHex(result));
return result;
- } catch (SonyProjectorException e) {
- logger.debug("Get setting {} failed: {}", item.getName(), e.getMessage());
- throw new SonyProjectorException("Get setting " + item.getName() + " failed: " + e.getMessage());
+ } catch (CommunicationException e) {
+ throw new SonyProjectorException("Get setting " + item.getName() + " failed", e);
}
}
* @param item the projector setting to set
* @param data the value to set for the setting
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
private void setSetting(SonyProjectorItem item, byte[] data) throws SonyProjectorException {
logger.debug("Set setting {} data {}", item.getName(), HexUtils.bytesToHex(data));
try {
executeCommand(item, false, data);
- } catch (SonyProjectorException e) {
- logger.debug("Set setting {} failed: {}", item.getName(), e.getMessage());
- throw new SonyProjectorException("Set setting " + item.getName() + " failed: " + e.getMessage());
+ } catch (CommunicationException e) {
+ throw new SonyProjectorException("Set setting " + item.getName() + " failed", e);
}
logger.debug("Set setting {} succeeded", item.getName());
*
* @param item the IR information to send
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
private synchronized void sendIR(SonyProjectorItem item) throws SonyProjectorException {
logger.debug("Send IR {}", item.getName());
if (!runningSession) {
close();
}
- } catch (SonyProjectorException e) {
- logger.debug("Send IR {} failed: {}", item.getName(), e.getMessage());
- throw new SonyProjectorException("Send IR " + item.getName() + " failed: " + e.getMessage());
+ } catch (CommunicationException e) {
+ throw new SonyProjectorException("Send IR " + item.getName() + " failed", e);
} catch (InterruptedException e) {
- logger.debug("Send IR {} interrupted: {}", item.getName(), e.getMessage());
Thread.currentThread().interrupt();
- throw new SonyProjectorException("Send IR " + item.getName() + " interrupted: " + e.getMessage());
+ throw new SonyProjectorException("Send IR " + item.getName() + " interrupted", e);
}
logger.debug("Send IR {} succeeded", item.getName());
*
* @return the buffer containing the returned message
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws ConnectionException in case of any connection problem
+ * @throws CommunicationException in case of any communication problem
*/
private synchronized byte[] executeCommand(SonyProjectorItem item, boolean getCommand, byte[] data)
- throws SonyProjectorException {
- try {
- boolean runningSession = connected;
+ throws ConnectionException, CommunicationException {
+ boolean runningSession = connected;
- open();
+ open();
- // Build the message and send it
- writeCommand(buildMessage(item, getCommand, data));
+ // Build the message and send it
+ writeCommand(buildMessage(item, getCommand, data));
- // Read the response
- byte[] responseMessage = readResponse();
+ // Read the response
+ byte[] responseMessage = readResponse();
- if (!runningSession) {
- close();
- }
+ if (!runningSession) {
+ close();
+ }
- // Validate the content of the response
- validateResponse(responseMessage, item);
+ // Validate the content of the response
+ validateResponse(responseMessage, item);
- return responseMessage;
- } catch (SonyProjectorException e) {
- throw new SonyProjectorException(e.getMessage());
- }
+ return responseMessage;
}
/**
* Open the connection with the projector if not yet opened
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws ConnectionException in case of any problem
*/
- public abstract void open() throws SonyProjectorException;
+ public abstract void open() throws ConnectionException;
/**
* Close the connection with the projector
* @param dataBuffer the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the
* stream has been reached.
- * @throws SonyProjectorException - If the input stream is null, if the first byte cannot be read for any reason
+ * @throws CommunicationException if the input stream is null, if the first byte cannot be read for any reason
* other than the end of the file, if the input stream has been closed, or if some other I/O error
* occurs.
*/
- protected int readInput(byte[] dataBuffer) throws SonyProjectorException {
+ protected int readInput(byte[] dataBuffer) throws CommunicationException {
if (simu) {
- throw new SonyProjectorException("readInput failed: should not be called in simu mode");
+ throw new CommunicationException("readInput failed: should not be called in simu mode");
}
InputStream dataIn = this.dataIn;
if (dataIn == null) {
- throw new SonyProjectorException("readInput failed: input stream is null");
+ throw new CommunicationException("readInput failed: input stream is null");
}
try {
return dataIn.read(dataBuffer);
} catch (IOException e) {
logger.debug("readInput failed: {}", e.getMessage());
- throw new SonyProjectorException("readInput failed: " + e.getMessage());
+ throw new CommunicationException("readInput failed", e);
}
}
*
* @param message the buffer containing the message to be sent
*
- * @throws SonyProjectorException - In case of any communication problem
+ * @throws CommunicationException in case of any communication problem
*/
- protected void writeCommand(byte[] message) throws SonyProjectorException {
+ protected void writeCommand(byte[] message) throws CommunicationException {
logger.debug("writeCommand: {}", HexUtils.bytesToHex(message));
if (simu) {
return;
}
OutputStream dataOut = this.dataOut;
if (dataOut == null) {
- throw new SonyProjectorException("writeCommand failed: output stream is null");
+ throw new CommunicationException("writeCommand failed: output stream is null");
}
try {
dataOut.write(message);
dataOut.flush();
} catch (IOException e) {
logger.debug("writeCommand failed: {}", e.getMessage());
- throw new SonyProjectorException("writeCommand failed: " + e.getMessage());
+ throw new CommunicationException("writeCommand failed", e);
}
}
*
* @return the buffer containing the returned message
*
- * @throws SonyProjectorException - In case of any communication problem
+ * @throws CommunicationException in case of any communication problem
*/
- protected abstract byte[] readResponse() throws SonyProjectorException;
+ protected abstract byte[] readResponse() throws CommunicationException;
/**
* Validate the content of a returned message
* @param responseMessage the buffer containing the returned message
* @param the projector setting to get or set
*
- * @throws SonyProjectorException - If the message has unexpected content
+ * @throws CommunicationException if the message has unexpected content
*/
protected abstract void validateResponse(byte[] responseMessage, SonyProjectorItem item)
- throws SonyProjectorException;
+ throws CommunicationException;
/**
* Extract the value from the returned message
import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorConnector;
import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
import org.openhab.core.util.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- public synchronized void open() throws SonyProjectorException {
+ public synchronized void open() throws ConnectionException {
if (!connected) {
logger.debug("Opening SDCP connection IP {} port {}", this.address, this.port);
try {
logger.debug("SDCP connection opened");
} catch (IOException | SecurityException | IllegalArgumentException e) {
- logger.debug("Opening SDCP connection failed: {}", e.getMessage());
- throw new SonyProjectorException("Opening SDCP connection failed: " + e.getMessage());
+ throw new ConnectionException("@text/exception.opening-sdcp-connection-failed", e);
}
}
}
* @param dataBuffer the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the
* stream has been reached.
- * @throws SonyProjectorException - If the input stream is null, if the first byte cannot be read for any reason
+ * @throws CommunicationException if the input stream is null, if the first byte cannot be read for any reason
* other than the end of the file, if the input stream has been closed, or if some other I/O error
* occurs.
*/
@Override
- protected int readInput(byte[] dataBuffer) throws SonyProjectorException {
+ protected int readInput(byte[] dataBuffer) throws CommunicationException {
InputStream dataIn = this.dataIn;
if (dataIn == null) {
- throw new SonyProjectorException("readInput failed: input stream is null");
+ throw new CommunicationException("readInput failed: input stream is null");
}
try {
return dataIn.read(dataBuffer);
return 0;
} catch (IOException e) {
logger.debug("readInput failed: {}", e.getMessage());
- throw new SonyProjectorException("readInput failed: " + e.getMessage());
+ throw new CommunicationException("readInput failed", e);
}
}
@Override
- protected synchronized byte[] readResponse() throws SonyProjectorException {
+ protected synchronized byte[] readResponse() throws CommunicationException {
logger.debug("readResponse (timeout = {} ms)...", READ_TIMEOUT_MS);
byte[] message = new byte[MSG_MAX_SIZE];
boolean timeout = false;
}
if ((count < MSG_MIN_SIZE) && timeout) {
logger.debug("readResponse timeout: only {} bytes read after {} ms", count, READ_TIMEOUT_MS);
- throw new SonyProjectorException("readResponse failed: timeout");
+ throw new CommunicationException("readResponse failed: timeout");
}
logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
if (count < MSG_MIN_SIZE) {
logger.debug("readResponse: unexpected response data length: {}", count);
- throw new SonyProjectorException("Unexpected response data length");
+ throw new CommunicationException("Unexpected response data length");
}
return message;
}
@Override
- protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws SonyProjectorException {
+ protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws CommunicationException {
// Check response size
if (responseMessage.length < MSG_MIN_SIZE) {
logger.debug("Unexpected response data length: {}", responseMessage.length);
- throw new SonyProjectorException("Unexpected response data length");
+ throw new CommunicationException("Unexpected response data length");
}
// Header should be a sony projector header
if (!Arrays.equals(headerMsg, HEADER)) {
logger.debug("Unexpected HEADER in response: {} rather than {}", HexUtils.bytesToHex(headerMsg),
HexUtils.bytesToHex(HEADER));
- throw new SonyProjectorException("Unexpected HEADER in response");
+ throw new CommunicationException("Unexpected HEADER in response");
}
// Community should be the same as used for sending
if (!Arrays.equals(communityResponseMsg, community.getBytes())) {
logger.debug("Unexpected community in response: {} rather than {}",
HexUtils.bytesToHex(communityResponseMsg), HexUtils.bytesToHex(community.getBytes()));
- throw new SonyProjectorException("Unexpected community in response");
+ throw new CommunicationException("Unexpected community in response");
}
// Item number should be the same as used for sending
if (!Arrays.equals(itemResponseMsg, item.getCode())) {
logger.debug("Unexpected item number in response: {} rather than {}", HexUtils.bytesToHex(itemResponseMsg),
HexUtils.bytesToHex(item.getCode()));
- throw new SonyProjectorException("Unexpected item number in response");
+ throw new CommunicationException("Unexpected item number in response");
}
// Check response size
int dataLength = responseMessage[9] & 0x000000FF;
if (responseMessage.length < (10 + dataLength)) {
logger.debug("Unexpected response data length: {}", dataLength);
- throw new SonyProjectorException("Unexpected response data length");
+ throw new CommunicationException("Unexpected response data length");
}
// byte 7 is expected to be 1, which indicates that the request was successful
try {
SonyProjectorSdcpError error = SonyProjectorSdcpError.getFromDataCode(errorCode);
msg = error.getMessage();
- } catch (SonyProjectorException e) {
+ } catch (CommunicationException e) {
}
}
logger.debug("{} received in response", msg);
- throw new SonyProjectorException(msg + " received in response");
+ throw new CommunicationException(msg + " received in response");
}
}
*
* @return the model name
*
- * @throws SonyProjectorException - In case of any problem
+ * @throws SonyProjectorException in case of any problem
*/
public String getModelName() throws SonyProjectorException {
return new String(getSetting(SonyProjectorItem.MODEL_NAME), StandardCharsets.UTF_8);
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.TooManyListenersException;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorConnector;
import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
+import org.openhab.core.i18n.CommunicationException;
+import org.openhab.core.i18n.ConnectionException;
import org.openhab.core.io.transport.serial.PortInUseException;
import org.openhab.core.io.transport.serial.SerialPort;
import org.openhab.core.io.transport.serial.SerialPortEvent;
}
@Override
- public synchronized void open() throws SonyProjectorException {
+ public synchronized void open() throws ConnectionException {
if (!connected) {
logger.debug("Opening serial connection on port {}", serialPortName);
try {
SerialPortIdentifier portIdentifier = serialPortManager.getIdentifier(serialPortName);
if (portIdentifier == null) {
- logger.debug("Opening serial connection failed: No Such Port: {}", serialPortName);
- throw new SonyProjectorException("Opening serial connection failed: No Such Port");
+ throw new ConnectionException("@text/exception.invalid-serial-port", serialPortName);
}
SerialPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
connected = true;
logger.debug("Serial connection opened");
- } catch (PortInUseException e) {
- logger.debug("Opening serial connection failed: Port in Use Exception: {}", e.getMessage(), e);
- throw new SonyProjectorException("Opening serial connection failed: Port in Use Exception");
- } catch (UnsupportedCommOperationException e) {
- logger.debug("Opening serial connection failed: Unsupported Comm Operation Exception: {}",
- e.getMessage(), e);
- throw new SonyProjectorException(
- "Opening serial connection failed: Unsupported Comm Operation Exception");
- } catch (UnsupportedEncodingException e) {
- logger.debug("Opening serial connection failed: Unsupported Encoding Exception: {}", e.getMessage(), e);
- throw new SonyProjectorException("Opening serial connection failed: Unsupported Encoding Exception");
- } catch (IOException e) {
- logger.debug("Opening serial connection failed: IO Exception: {}", e.getMessage(), e);
- throw new SonyProjectorException("Opening serial connection failed: IO Exception");
+ } catch (PortInUseException | UnsupportedCommOperationException | IOException e) {
+ throw new ConnectionException("@text/exception.opening-serial-connection-failed", e);
}
}
}
}
@Override
- protected synchronized byte[] readResponse() throws SonyProjectorException {
+ protected synchronized byte[] readResponse() throws CommunicationException {
logger.debug("readResponse (timeout = {} ms)...", READ_TIMEOUT_MS);
byte[] message = new byte[8];
boolean startCodeReached = false;
}
if (!endCodeReached && timeout) {
logger.debug("readResponse timeout: only {} bytes read after {} ms", index, READ_TIMEOUT_MS);
- throw new SonyProjectorException("readResponse failed: timeout");
+ throw new CommunicationException("readResponse failed: timeout");
}
logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
}
@Override
- protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws SonyProjectorException {
+ protected void validateResponse(byte[] responseMessage, SonyProjectorItem item) throws CommunicationException {
if (responseMessage.length != 8) {
logger.debug("Unexpected response data length: {}", responseMessage.length);
- throw new SonyProjectorException("Unexpected response data length");
+ throw new CommunicationException("Unexpected response data length");
}
// Check START CODE
if (responseMessage[0] != START_CODE) {
logger.debug("Unexpected message START CODE in response: {} rather than {}",
Integer.toHexString(responseMessage[0] & 0x000000FF), Integer.toHexString(START_CODE & 0x000000FF));
- throw new SonyProjectorException("Unexpected message START CODE in response");
+ throw new CommunicationException("Unexpected message START CODE in response");
}
// Check END CODE
if (responseMessage[7] != END_CODE) {
logger.debug("Unexpected message END CODE in response: {} rather than {}",
Integer.toHexString(responseMessage[7] & 0x000000FF), Integer.toHexString(END_CODE & 0x000000FF));
- throw new SonyProjectorException("Unexpected message END CODE in response");
+ throw new CommunicationException("Unexpected message END CODE in response");
}
byte checksum = computeCheckSum(responseMessage);
if (responseMessage[6] != checksum) {
logger.debug("Invalid check sum in response: {} rather than {}",
Integer.toHexString(responseMessage[6] & 0x000000FF), Integer.toHexString(checksum & 0x000000FF));
- throw new SonyProjectorException("Invalid check sum in response");
+ throw new CommunicationException("Invalid check sum in response");
}
if (responseMessage[3] == TYPE_ITEM) {
if (!Arrays.equals(itemResponseMsg, item.getCode())) {
logger.debug("Unexpected item number in response: {} rather than {}",
HexUtils.bytesToHex(itemResponseMsg), HexUtils.bytesToHex(item.getCode()));
- throw new SonyProjectorException("Unexpected item number in response");
+ throw new CommunicationException("Unexpected item number in response");
}
} else if (responseMessage[3] == TYPE_ACK) {
// ACK
try {
SonyProjectorSerialError error = SonyProjectorSerialError.getFromDataCode(errorCode);
msg = error.getMessage();
- } catch (SonyProjectorException e) {
+ } catch (CommunicationException e) {
}
logger.debug("{} received in response", msg);
- throw new SonyProjectorException(msg + " received in response");
+ throw new CommunicationException(msg + " received in response");
}
} else {
logger.debug("Unexpected TYPE in response: {}", Integer.toHexString(responseMessage[3] & 0x000000FF));
- throw new SonyProjectorException("Unexpected TYPE in response");
+ throw new CommunicationException("Unexpected TYPE in response");
}
}