// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemClient.java
// public interface GsmModemClient extends Closeable {
// 	void setSMSTextMode() throws IOException, GsmModemException;
// 
// 	void sendSms(String gsmNumber, String sms) throws IOException, GsmModemException;
// 
// 	void sendCommand(String command) throws IOException, GsmModemException;
// }
// 
// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemException.java
// public class GsmModemException extends Exception {
// 	private static final long serialVersionUID = 1L;
// 
// 	public GsmModemException() {
// 		super();
// 	}
// 
// 	public GsmModemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public GsmModemException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public GsmModemException(String message) {
// 		super(message);
// 	}
// 
// 	public GsmModemException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: gsm-modem-client-jserialcomm/src/main/java/fr/romainmoreau/gsmmodem/client/jserialcomm/JSerialCommGsmModemClient.java
// public class JSerialCommGsmModemClient extends AbstractUARTGsmModemClient implements SerialPortDataListener {
// 	private final SerialPort serialPort;
// 
// 	private SerialEventExceptionListener serialEventExceptionListener;
// 
// 	public JSerialCommGsmModemClient(String portName, long timeout) throws IOException {
// 		super(timeout);
// 		serialPort = SerialPort.getCommPort(portName);
// 		serialPort.setBaudRate(115200);
// 		serialPort.setNumDataBits(8);
// 		serialPort.setNumStopBits(ONE_STOP_BIT);
// 		serialPort.setParity(NO_PARITY);
// 		serialPort.addDataListener(this);
// 		if (!serialPort.openPort()) {
// 			throw new IOException("Port not opened");
// 		}
// 	}
// 
// 	@Override
// 	public int getListeningEvents() {
// 		return LISTENING_EVENT_DATA_AVAILABLE;
// 	}
// 
// 	@Override
// 	public void serialEvent(SerialPortEvent event) {
// 		try {
// 			byte[] readBytes = readBytes();
// 			if (readBytes != null) {
// 				for (byte readByte : readBytes) {
// 					onReadByte(readByte);
// 				}
// 			}
// 		} catch (Exception e) {
// 			if (serialEventExceptionListener != null) {
// 				serialEventExceptionListener.onException(e);
// 			}
// 		}
// 	}
// 
// 	@Override
// 	public synchronized void close() throws IOException {
// 		if (!serialPort.closePort()) {
// 			throw new IOException("Port not closed");
// 		}
// 	}
// 
// 	@Override
// 	protected void sendString(String string) throws IOException {
// 		byte[] bytes = string.getBytes();
// 		int bytesWritten = serialPort.writeBytes(bytes, bytes.length);
// 		if (bytesWritten != bytes.length) {
// 			throw new IOException("Error writing bytes");
// 		}
// 	}
// 
// 	private byte[] readBytes() {
// 		int bytesAvailable = serialPort.bytesAvailable();
// 		if (bytesAvailable == 0) {
// 			return null;
// 		} else if (bytesAvailable > 0) {
// 			byte[] bytes = new byte[bytesAvailable];
// 			if (serialPort.readBytes(bytes, bytes.length) == bytes.length) {
// 				return bytes;
// 			} else {
// 				throw new RuntimeException("Error reading bytes");
// 			}
// 		} else {
// 			throw new RuntimeException("Port not opened");
// 		}
// 	}
// 
// 	public void setSerialEventExceptionListener(SerialEventExceptionListener serialEventExceptionListener) {
// 		this.serialEventExceptionListener = serialEventExceptionListener;
// 	}
// }


import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import fr.romainmoreau.gsmmodem.client.api.GsmModemClient;
import fr.romainmoreau.gsmmodem.client.api.GsmModemException;
import fr.romainmoreau.gsmmodem.client.jserialcomm.JSerialCommGsmModemClient;
package fr.romainmoreau.gsmmodem.web;




@EnableAsync
@EnableWebSocketMessageBroker
@SpringBootApplication(scanBasePackages = "fr.romainmoreau.gsmmodem.web")
@ConfigurationPropertiesScan
public class WebGsmModemApplication implements WebSocketMessageBrokerConfigurer {
	private static final Logger LOGGER = LoggerFactory.getLogger(WebGsmModemApplication.class);

	@Autowired
	private GsmModemProperties gsmModemProperties;

	@Autowired
	private WebGsmEventListener webGsmEventListener;

	@Autowired
	private SimpMessagingTemplate simpMessagingTemplate;

	@Bean
	public GsmModemClient gsmModemClient() throws IOException, GsmModemException {
		LOGGER.info("Creating jSerialComm gsm-modem client using port name {} and timeout {}",
				gsmModemProperties.getPortName(), gsmModemProperties.getTimeout());
// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemClient.java
// public interface GsmModemClient extends Closeable {
// 	void setSMSTextMode() throws IOException, GsmModemException;
// 
// 	void sendSms(String gsmNumber, String sms) throws IOException, GsmModemException;
// 
// 	void sendCommand(String command) throws IOException, GsmModemException;
// }
// 
// Path: gsm-modem-client-api/src/main/java/fr/romainmoreau/gsmmodem/client/api/GsmModemException.java
// public class GsmModemException extends Exception {
// 	private static final long serialVersionUID = 1L;
// 
// 	public GsmModemException() {
// 		super();
// 	}
// 
// 	public GsmModemException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public GsmModemException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public GsmModemException(String message) {
// 		super(message);
// 	}
// 
// 	public GsmModemException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: gsm-modem-client-jserialcomm/src/main/java/fr/romainmoreau/gsmmodem/client/jserialcomm/JSerialCommGsmModemClient.java
// public class JSerialCommGsmModemClient extends AbstractUARTGsmModemClient implements SerialPortDataListener {
// 	private final SerialPort serialPort;
// 
// 	private SerialEventExceptionListener serialEventExceptionListener;
// 
// 	public JSerialCommGsmModemClient(String portName, long timeout) throws IOException {
// 		super(timeout);
// 		serialPort = SerialPort.getCommPort(portName);
// 		serialPort.setBaudRate(115200);
// 		serialPort.setNumDataBits(8);
// 		serialPort.setNumStopBits(ONE_STOP_BIT);
// 		serialPort.setParity(NO_PARITY);
// 		serialPort.addDataListener(this);
// 		if (!serialPort.openPort()) {
// 			throw new IOException("Port not opened");
// 		}
// 	}
// 
// 	@Override
// 	public int getListeningEvents() {
// 		return LISTENING_EVENT_DATA_AVAILABLE;
// 	}
// 
// 	@Override
// 	public void serialEvent(SerialPortEvent event) {
// 		try {
// 			byte[] readBytes = readBytes();
// 			if (readBytes != null) {
// 				for (byte readByte : readBytes) {
// 					onReadByte(readByte);
// 				}
// 			}
// 		} catch (Exception e) {
// 			if (serialEventExceptionListener != null) {
// 				serialEventExceptionListener.onException(e);
// 			}
// 		}
// 	}
// 
// 	@Override
// 	public synchronized void close() throws IOException {
// 		if (!serialPort.closePort()) {
// 			throw new IOException("Port not closed");
// 		}
// 	}
// 
// 	@Override
// 	protected void sendString(String string) throws IOException {
// 		byte[] bytes = string.getBytes();
// 		int bytesWritten = serialPort.writeBytes(bytes, bytes.length);
// 		if (bytesWritten != bytes.length) {
// 			throw new IOException("Error writing bytes");
// 		}
// 	}
// 
// 	private byte[] readBytes() {
// 		int bytesAvailable = serialPort.bytesAvailable();
// 		if (bytesAvailable == 0) {
// 			return null;
// 		} else if (bytesAvailable > 0) {
// 			byte[] bytes = new byte[bytesAvailable];
// 			if (serialPort.readBytes(bytes, bytes.length) == bytes.length) {
// 				return bytes;
// 			} else {
// 				throw new RuntimeException("Error reading bytes");
// 			}
// 		} else {
// 			throw new RuntimeException("Port not opened");
// 		}
// 	}
// 
// 	public void setSerialEventExceptionListener(SerialEventExceptionListener serialEventExceptionListener) {
// 		this.serialEventExceptionListener = serialEventExceptionListener;
// 	}
// }


// Path: gsm-modem-web/src/main/java/fr/romainmoreau/gsmmodem/web/WebGsmModemApplication.java
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import fr.romainmoreau.gsmmodem.client.api.GsmModemClient;
import fr.romainmoreau.gsmmodem.client.api.GsmModemException;
import fr.romainmoreau.gsmmodem.client.jserialcomm.JSerialCommGsmModemClient;

package fr.romainmoreau.gsmmodem.web;




@EnableAsync
@EnableWebSocketMessageBroker
@SpringBootApplication(scanBasePackages = "fr.romainmoreau.gsmmodem.web")
@ConfigurationPropertiesScan
public class WebGsmModemApplication implements WebSocketMessageBrokerConfigurer {
	private static final Logger LOGGER = LoggerFactory.getLogger(WebGsmModemApplication.class);

	@Autowired
	private GsmModemProperties gsmModemProperties;

	@Autowired
	private WebGsmEventListener webGsmEventListener;

	@Autowired
	private SimpMessagingTemplate simpMessagingTemplate;

	@Bean
	public GsmModemClient gsmModemClient() throws IOException, GsmModemException {
		LOGGER.info("Creating jSerialComm gsm-modem client using port name {} and timeout {}",
				gsmModemProperties.getPortName(), gsmModemProperties.getTimeout());
		JSerialCommGsmModemClient jSerialCommGsmModemClient = new JSerialCommGsmModemClient(