r360 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-application/src/main/java/fr/ulr/sammoa/application/device sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps sammoa-application/src/main/java/gnu/io sammoa-application/src/main/resources/i18n sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing
Author: fdesbois Date: 2012-08-07 17:48:54 +0200 (Tue, 07 Aug 2012) New Revision: 360 Url: http://forge.codelutin.com/repositories/revision/sammoa/360 Log: refs #1378 : Clean listeners and create package device Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java Removed: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/ Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java 2012-08-07 15:48:54 UTC (rev 360) @@ -1,80 +0,0 @@ -package fr.ulr.sammoa.application; -/* - * #%L - * SAMMOA :: Application - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import java.util.Set; - -/** - * Created: 06/08/12 - * - * @author fdesbois <florian.desbois@codelutin.com> - */ -public interface DeviceManager<L extends DeviceUpdateListener> { - - /** - * Open the device - * - * @throws DeviceTechnicalException for errors on open - */ - void open() throws DeviceTechnicalException; - - /** - * Start the device session (recording, reading, ...) and try opening it if necessary. The open - * could be tried several times to permit a proper start. - */ - void start(); - - /** - * Stop the device session - */ - void stop(); - - /** - * Close the device and stop it if necessary - * - * @throws DeviceTechnicalException for errors on close - */ - void close() throws DeviceTechnicalException; - - /** - * @return the DeviceState - */ - DeviceState getState(); - - /** - * @param listener DeviceUpdateListener to add - */ - void addUpdateListener(L listener); - - /** - * @param listener DeviceUpdateListener to remove - */ - void removeUpdateListener(L listener); - - /** - * @return all the listeners - */ - Set<L> getUpdateListeners(); - -} Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java 2012-08-07 15:48:54 UTC (rev 360) @@ -1,41 +0,0 @@ -/* - * #%L - * SAMMOA :: Application - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.application; - -/** - * Enumeration to represent device (gps, audio) state. - * - * @author echatellier - */ -public enum DeviceState { - /** voyant gris : pas de peripherique */ - NO_DEVICE, - /** voyant bleu : peripherique prêt */ - READY, - /** voyant vert : reception de données */ - RECORDING, - /** voyant rouge clignotant : périphirique prêt mais aucune données */ - NO_DATA -} Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java 2012-08-07 15:48:54 UTC (rev 360) @@ -1,49 +0,0 @@ -/* - * #%L - * SAMMOA :: Application - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.application; - -/** - * @author fdesbois <fdesbois@codelutin.com> - */ -public class DeviceTechnicalException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - protected DeviceManager source; - - public DeviceTechnicalException(DeviceManager source, String message) { - super(message); - this.source = source; - } - - public DeviceTechnicalException(DeviceManager source, String message, Throwable cause) { - super(message, cause); - this.source = source; - } - - public DeviceManager getSource() { - return source; - } -} Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java 2012-08-07 15:48:54 UTC (rev 360) @@ -1,56 +0,0 @@ -package fr.ulr.sammoa.application; -/* - * #%L - * SAMMOA :: Application - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -/** - * Created: 06/08/12 - * - * @author fdesbois <florian.desbois@codelutin.com> - */ -public class DeviceUpdateEvent<T> { - - protected DeviceManager source; - - protected T oldValue; - - protected T newValue; - - public DeviceUpdateEvent(DeviceManager source, T oldValue, T newValue) { - this.source = source; - this.oldValue = oldValue; - this.newValue = newValue; - } - - public DeviceManager getSource() { - return source; - } - - public T getOldValue() { - return oldValue; - } - - public T getNewValue() { - return newValue; - } -} \ No newline at end of file Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java 2012-08-07 15:48:54 UTC (rev 360) @@ -1,39 +0,0 @@ -package fr.ulr.sammoa.application; -/* - * #%L - * SAMMOA :: Application - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -/** - * Created: 06/08/12 - * - * @author fdesbois <florian.desbois@codelutin.com> - */ -public interface DeviceUpdateListener { - - /** - * Update device state. - * - * @param event new event - */ - void onStateChanged(DeviceUpdateEvent<DeviceState> event); -} Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 15:48:54 UTC (rev 360) @@ -23,10 +23,11 @@ * #L% */ -import fr.ulr.sammoa.application.audio.AudioRecorder; -import fr.ulr.sammoa.application.audio.AudioRecorderDefault; -import fr.ulr.sammoa.application.gps.GpsConfig; -import fr.ulr.sammoa.application.gps.GpsHandler; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.application.device.audio.AudioRecorder; +import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault; +import fr.ulr.sammoa.application.device.gps.GpsConfig; +import fr.ulr.sammoa.application.device.gps.GpsHandler; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.ObservationStatus; @@ -66,7 +67,7 @@ /** * @param config GpsConfig to initialize the Gps - * @exception DeviceTechnicalException if the gps device can't be opened properly + * @exception fr.ulr.sammoa.application.device.DeviceTechnicalException if the gps device can't be opened properly */ void openGpsDevice(GpsConfig config) throws DeviceTechnicalException; Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 15:48:54 UTC (rev 360) @@ -28,11 +28,15 @@ import com.google.common.base.Supplier; import com.google.common.base.Throwables; import com.google.common.collect.Sets; -import fr.ulr.sammoa.application.audio.AudioRecorder; -import fr.ulr.sammoa.application.audio.AudioRecorderDefault; -import fr.ulr.sammoa.application.gps.GpsConfig; -import fr.ulr.sammoa.application.gps.GpsHandler; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; +import fr.ulr.sammoa.application.device.DeviceManager; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.application.device.audio.AudioRecorder; +import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault; +import fr.ulr.sammoa.application.device.gps.GpsConfig; +import fr.ulr.sammoa.application.device.gps.GpsHandler; +import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; +import fr.ulr.sammoa.application.device.gps.GpsLocationListener; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.persistence.FlightDAO; import fr.ulr.sammoa.persistence.GeoPoint; @@ -66,7 +70,7 @@ * * @author fdesbois <desbois@codelutin.com> */ -public class FlightControllerDefault implements GpsUpdateListener, FlightController { +public class FlightControllerDefault implements GpsLocationListener, FlightController { private static final Logger logger = LoggerFactory.getLogger(FlightControllerDefault.class); @@ -148,6 +152,19 @@ @Override public void openGpsDevice(final GpsConfig config) throws DeviceTechnicalException { + Set<GpsLocationListener> locationListeners; + if (gpsHandler != null) { + + // Remove all existing listeners and keep them for the new instance + locationListeners = Sets.newHashSet(gpsHandler.getGpsLocationListeners()); + for (GpsLocationListener listener : locationListeners) { + gpsHandler.removeGpsLocationListener(listener); + } + + } else { + locationListeners = Sets.newHashSet(); + } + gpsHandler = newDeviceManager(gpsHandler, new Supplier<GpsHandler>() { @Override @@ -161,7 +178,7 @@ gpsHandlerClass.getConstructor(GpsConfig.class); GpsHandler result = constructor.newInstance(config); - result.addUpdateListener(FlightControllerDefault.this); + result.addGpsLocationListener(FlightControllerDefault.this); return result; } catch (InstantiationException e) { @@ -176,6 +193,10 @@ } }); + for (GpsLocationListener listener : locationListeners) { + gpsHandler.addGpsLocationListener(listener); + } + if (initialized && isRunning()) { gpsHandler.start(); } else { @@ -821,33 +842,33 @@ protected <T extends DeviceManager> T newDeviceManager(T oldInstance, Supplier<T> supplier) throws DeviceTechnicalException { - Set<DeviceUpdateListener> updateListeners; + Set<DeviceStateListener> stateListeners; if (oldInstance != null) { // Remove all existing listeners and keep them for the new instance - updateListeners = Sets.newHashSet(oldInstance.getUpdateListeners()); - for (DeviceUpdateListener listener : updateListeners) { - oldInstance.removeUpdateListener(listener); + stateListeners = Sets.newHashSet(oldInstance.getDeviceStateListeners()); + for (DeviceStateListener listener : stateListeners) { + oldInstance.removeDeviceStateListener(listener); } oldInstance.close(); } else { - updateListeners = Sets.newHashSet(); + stateListeners = Sets.newHashSet(); } T result = supplier.get(); // Attach all updateListener - for (DeviceUpdateListener listener : updateListeners) { - result.addUpdateListener(listener); + for (DeviceStateListener listener : stateListeners) { + result.addDeviceStateListener(listener); } return result; } @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { + public void locationChanged(GpsLocationEvent event) { GeoPoint newLocation = event.getNewValue(); if (newLocation != null/* && newLocation.getTopiaId() == null*/) { newLocation.setFlight(flight); @@ -855,9 +876,4 @@ } } - @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { - // nothing to do - } - } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-07 15:48:54 UTC (rev 360) @@ -26,7 +26,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Throwables; -import fr.ulr.sammoa.application.gps.GpsConfig; +import fr.ulr.sammoa.application.device.gps.GpsConfig; import fr.ulr.sammoa.persistence.AutoSaveListener; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.nuiton.util.ApplicationConfig; Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,80 @@ +package fr.ulr.sammoa.application.device; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import java.util.Set; + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public interface DeviceManager { + + /** + * Open the device + * + * @throws DeviceTechnicalException for errors on open + */ + void open() throws DeviceTechnicalException; + + /** + * Start the device session (recording, reading, ...) and try opening it if necessary. The open + * could be tried several times to permit a proper start. + */ + void start(); + + /** + * Stop the device session + */ + void stop(); + + /** + * Close the device and stop it if necessary + * + * @throws DeviceTechnicalException for errors on close + */ + void close() throws DeviceTechnicalException; + + /** + * @return the DeviceState + */ + DeviceState getState(); + + /** + * @param listener DeviceStateListener to add + */ + void addDeviceStateListener(DeviceStateListener listener); + + /** + * @param listener DeviceStateListener to remove + */ + void removeDeviceStateListener(DeviceStateListener listener); + + /** + * @return all the listeners + */ + Set<DeviceStateListener> getDeviceStateListeners(); + +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,41 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device; + +/** + * Enumeration to represent device (gps, audio) state. + * + * @author echatellier + */ +public enum DeviceState { + /** voyant gris : pas de peripherique */ + NO_DEVICE, + /** voyant bleu : peripherique prêt */ + READY, + /** voyant vert : reception de données */ + RECORDING, + /** voyant rouge clignotant : périphirique prêt mais aucune données */ + NO_DATA +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,56 @@ +package fr.ulr.sammoa.application.device; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class DeviceStateEvent { + + protected DeviceManager source; + + protected DeviceState oldValue; + + protected DeviceState newValue; + + public DeviceStateEvent(DeviceManager source, DeviceState oldValue, DeviceState newValue) { + this.source = source; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public DeviceManager getSource() { + return source; + } + + public DeviceState getOldValue() { + return oldValue; + } + + public DeviceState getNewValue() { + return newValue; + } +} \ No newline at end of file Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,39 @@ +package fr.ulr.sammoa.application.device; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public interface DeviceStateListener { + + /** + * Update device state. + * + * @param event new event + */ + void stateChanged(DeviceStateEvent event); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,49 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device; + +/** + * @author fdesbois <fdesbois@codelutin.com> + */ +public class DeviceTechnicalException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + protected DeviceManager source; + + public DeviceTechnicalException(DeviceManager source, String message) { + super(message); + this.source = source; + } + + public DeviceTechnicalException(DeviceManager source, String message, Throwable cause) { + super(message, cause); + this.source = source; + } + + public DeviceManager getSource() { + return source; + } +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,64 @@ +package fr.ulr.sammoa.application.device.audio; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.application.device.DeviceManager; + +import javax.sound.sampled.AudioFileFormat; +import java.io.File; +import java.io.IOException; + +/** + * Recorder of audio files. Two recorder are used and a delay between recording + * could be customized. + * <p/> + * Created: 12/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public interface AudioRecorder extends DeviceManager { + + /** + * @return the {@link AudioFileFormat.Type} used (default is WAV) + */ + AudioFileFormat.Type getOutputType(); + + /** + * Record the audio line and save the data in given {@code outputFile}. The + * previous recording will be stopped in {@code delaySeconds}. The delay is + * useful to avoid recording lost or too quick between two files. + * + * @param outputFile File to record + * @param delaySeconds Delay for previous recording + * @throws IOException for recording issues on the file + */ + void record(File outputFile, long delaySeconds) throws IOException; + + /** + * Stop the current recording after {@code delaySeconds}. + * + * @param delaySeconds Delay for current recording + */ + void stopRecord(long delaySeconds); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,516 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device.audio; + +import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sound.sampled.AudioFileFormat; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.TargetDataLine; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Created: 16/05/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class AudioRecorderDefault implements AudioRecorder { + + private static final Logger logger = LoggerFactory.getLogger(AudioRecorderDefault.class); + + private static final AudioFormat.Encoding DEFAULT_ENCODING = AudioFormat.Encoding.PCM_SIGNED; + + private static final float DEFAULT_SAMPLE_RATE = 44100.0F; + + private static final int DEFAULT_SAMPLE_SIZE_IN_BITS = 16; + + private static final int DEFAULT_CHANNELS = 2; + + private static final int DEFAULT_FRAME_SIZE = 4; + + private static final float DEFAULT_FRAME_RATE = 44100.0F; + + private static final boolean DEFAULT_BIG_ENDIAN = false; + + private static final AudioFileFormat.Type DEFAULT_OUTPUT_TYPE = AudioFileFormat.Type.WAVE; + + protected AudioFormat audioFormat; + + protected AudioFileFormat.Type outputType; + + protected TargetDataLine dataLine; + + protected DataLineReader lineReader; + + private Recorder recorder1; + + private Recorder recorder2; + + protected Recorder currentRecorder; + +// // For debug purpose +// private int count; + + protected DeviceState state; + + protected Set<DeviceStateListener> listeners; + + public AudioRecorderDefault() { + this(new AudioFormat( + DEFAULT_ENCODING, + DEFAULT_SAMPLE_RATE, + DEFAULT_SAMPLE_SIZE_IN_BITS, + DEFAULT_CHANNELS, + DEFAULT_FRAME_SIZE, + DEFAULT_FRAME_RATE, + DEFAULT_BIG_ENDIAN + + ), DEFAULT_OUTPUT_TYPE); + } + + public AudioRecorderDefault(AudioFormat audioFormat, + AudioFileFormat.Type outputType) { + + this.audioFormat = audioFormat; + this.outputType = outputType; + this.listeners = Sets.newHashSet(); + this.state = DeviceState.NO_DEVICE; + } + + @Override + public DeviceState getState() { + return state; + } + + protected void setState(DeviceState state) { + DeviceState oldValue = getState(); + this.state = state; + + // Fire on listeners + for (DeviceStateListener listener : listeners) { + listener.stateChanged(new DeviceStateEvent(this, oldValue, state)); + } + } + + @Override + public AudioFileFormat.Type getOutputType() { + return outputType; + } + + @Override + public void addDeviceStateListener(DeviceStateListener listener) { + listeners.add(listener); + } + + @Override + public void removeDeviceStateListener(DeviceStateListener listener) { + listeners.remove(listener); + } + + @Override + public Set<DeviceStateListener> getDeviceStateListeners() { + return listeners; + } + + @Override + public void open() throws DeviceTechnicalException { + + if (logger.isInfoEnabled()) { + logger.info("Open the audio line"); + } + + DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); + try { + dataLine = (TargetDataLine) AudioSystem.getLine(info); + dataLine.open(audioFormat); + + // Start using the line for recording + dataLine.start(); + + setState(DeviceState.READY); + + if (logger.isInfoEnabled()) { + logger.info("Audio line is ready"); + } + + } catch (IllegalArgumentException e) { + setState(DeviceState.NO_DEVICE); + throw new DeviceTechnicalException(this, "Can't open audio device", e); + + } catch (IllegalStateException e) { + setState(DeviceState.NO_DEVICE); + throw new DeviceTechnicalException(this, "Can't open audio device", e); + + } catch (SecurityException e) { + setState(DeviceState.NO_DEVICE); + throw new DeviceTechnicalException(this, "Can't open audio device", e); + + } catch (LineUnavailableException e) { + setState(DeviceState.NO_DEVICE); + throw new DeviceTechnicalException(this, "Can't open audio device", e); + } + } + + @Override + public void start() { + + if (getState() == DeviceState.READY) { + + // Stop previous recording + stop(); + + logger.info("Start reading audio line"); + + lineReader = new DataLineReader(); + lineReader.start(); + } + } + + @Override + public void record(File outputFile, long delaySeconds) throws IOException { + + if (DeviceState.NO_DATA == state) { + if (logger.isWarnEnabled()) { + logger.warn("Can't record " + outputFile.getAbsolutePath() + ", no available dataLine"); + } + + // XXX-fdesbois-2012-08-03 : try to start the line again ? + + return; + } + + Preconditions.checkArgument(outputFile != null); + Preconditions.checkState(dataLine != null, + "You must start the AudioRecorder to initialize " + + "the audio line before call record method"); + + + // Start recorder1 + if (currentRecorder == null) { + recorder1 = new Recorder(outputFile, audioFormat, outputType, lineReader); + currentRecorder = recorder1; + + // Stop recorder1 if recording and start recorder2 + } else if (currentRecorder == recorder1) { + + if (recorder1.isRecording()) { + recorder1.stop(delaySeconds); + } + + if (recorder2 != null && recorder2.isRecording()) { + recorder2.stop(); + } + recorder2 = new Recorder(outputFile, audioFormat, outputType, lineReader); + currentRecorder = recorder2; + + // Stop recorder2 if recording and start recorder1 + } else if (currentRecorder == recorder2) { + + if (recorder2.isRecording()) { + recorder2.stop(delaySeconds); + } + + if (recorder1.isRecording()) { + recorder1.stop(); + } + recorder1 = new Recorder(outputFile, audioFormat, outputType, lineReader); + currentRecorder = recorder1; + } + } + + @Override + public void stopRecord(long delaySeconds) { + if (currentRecorder != null) { + currentRecorder.stop(delaySeconds); + } + } + + @Override + public void stop() { + + if (getState() != DeviceState.NO_DEVICE) { + + // Destroy the thread + if (lineReader != null) { + lineReader.interrupt(); + } + lineReader = null; + } + } + + @Override + public void close() throws DeviceTechnicalException { + + stop(); + + if (dataLine != null && dataLine.isRunning()) { + + logger.info("Close the audio line"); + + dataLine.stop(); + dataLine.drain(); + dataLine.close(); + dataLine = null; + + setState(DeviceState.NO_DEVICE); + } + } + + protected class DataLineReader extends Thread { + + private List<Recorder> recorders = Collections.synchronizedList(Lists.<Recorder>newArrayList()); + + public void addRecorder(Recorder recorder) { + recorders.add(recorder); + } + + public void removeRecorder(Recorder recorder) { + recorders.remove(recorder); + } + + @Override + public void run() { + + int frameSize = audioFormat.getFrameSize(); + int bufferLengthInFrames = dataLine.getBufferSize() / 8; + int bufferSize = bufferLengthInFrames * frameSize; + byte[] buffer = new byte[bufferSize]; + + // Start reading the line + int numBytesRead; + while (lineReader != null) { + + if (!recorders.isEmpty()) { + + setState(DeviceState.RECORDING); + + numBytesRead = dataLine.read(buffer, 0, bufferSize); + synchronized (recorders) { + for (Recorder recorder : recorders) { + recorder.write(buffer, 0, numBytesRead); + } + } + + } else { + setState(DeviceState.READY); + } + } + + logger.debug("Stop all recorders (" + recorders.size() + ")"); + + List<Recorder> list; + synchronized (recorders) { + list = Lists.newArrayList(recorders); + } + for (Recorder recorder : list) { + recorder.stop(); + } + } + } + + protected static class Recorder { + + protected AudioFormat audioFormat; + + protected AudioFileFormat.Type outputType; + + protected ByteArrayOutputStream bufferStream; + + protected String outputFilePath; + + protected OutputStream outputStream; + + protected DataLineReader lineReader; + + protected boolean stop; + + protected boolean stopScheduled; + + protected TimerTask saveTask = new SaveTask(); + + protected TimerTask stopRecording = new StopTask(); + + protected class SaveTask extends TimerTask { + + @Override + public void run() { + save(); + } + } + + protected class StopTask extends TimerTask { + + @Override + public void run() { + doStop(); + } + } + + public Recorder(File outputFile, + AudioFormat audioFormat, + AudioFileFormat.Type outputType, + DataLineReader lineReader) throws IOException { + + this.outputFilePath = outputFile.getAbsolutePath(); + boolean newFile = outputFile.createNewFile(); + if (newFile) { + logger.info("Record a new audio file '{}'", outputFilePath); + } else { + logger.info("Use existing file '{}' to continue recording", outputFilePath); + } + this.bufferStream = new ByteArrayOutputStream(); + this.outputStream = new BufferedOutputStream(new FileOutputStream(outputFile, true)); + this.audioFormat = audioFormat; + this.outputType = outputType; + this.lineReader = lineReader; + this.lineReader.addRecorder(this); + + // Save the audio file every 3 seconds + new Timer().schedule(saveTask, 0, 3000); + } + + public boolean isRecording() { + return !stop; + } + + public void write(byte[] buffer, int offset, int length) { + + if (stop) { + logger.debug("File is already saved ({})", outputFilePath); + return; + } + synchronized (bufferStream) { + bufferStream.write(buffer, offset, length); + } + } + + public void stop(long delay) { + + if (stop) { + logger.debug("File is already saved ({})", outputFilePath); + return; + } + + if (stopScheduled) { + logger.debug("Stop is already scheduled ({})", outputFilePath); + return; + } + long delayMilliseconds = delay * 1000; + logger.debug("Call stop recording ({}) with delay = {} ms", outputFilePath, delayMilliseconds); + new Timer().schedule(stopRecording, delayMilliseconds); + stopScheduled = true; + } + + public void stop() { + + if (stop) { + logger.debug("File is already saved ({})", outputFilePath); + return; + } + + stopRecording.cancel(); + doStop(); + } + + protected void doStop() { + + logger.debug("Stop recording ({})", outputFilePath); + lineReader.removeRecorder(this); + saveTask.cancel(); + save(); + stop = true; + try { + + bufferStream.flush(); + bufferStream.close(); + + } catch (IOException e) { + Throwables.propagate(e); + + } finally { + IOUtils.closeQuietly(bufferStream); + } + } + + protected void save() { + + // reset the buffer stream + byte[] bytes; + synchronized (bufferStream) { + bytes = bufferStream.toByteArray(); + bufferStream.reset(); + } + + // prepare AudioStream + AudioInputStream audioStream = new AudioInputStream( + new ByteArrayInputStream(bytes), + audioFormat, + bytes.length / audioFormat.getFrameSize() + ); + + try { + logger.debug("Save in file {}", outputFilePath); + + AudioSystem.write(audioStream, outputType, outputStream); + + } catch (IOException e) { + logger.error("Can't record file {}", outputFilePath, e); + + } finally { + try { + audioStream.close(); + } catch (IOException e) { + logger.error("Can't close file {}", outputFilePath, e); + } + } + } + } + +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,99 @@ +package fr.ulr.sammoa.application.device.audio; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Sets; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; + +import javax.sound.sampled.AudioFileFormat; +import java.io.File; +import java.io.IOException; +import java.util.Set; + +/** + * Mock for {@link AudioRecorder} that record nothing. + * <p/> + * Created: 12/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class AudioRecorderMock implements AudioRecorder { + + @Override + public DeviceState getState() { + return DeviceState.NO_DEVICE; + } + + @Override + public AudioFileFormat.Type getOutputType() { + return AudioFileFormat.Type.WAVE; + } + + @Override + public void open() throws DeviceTechnicalException { + // do nothing + } + + @Override + public void start() { + // do nothing + } + + @Override + public void record(File outputFile, long delaySeconds) throws IOException { + // do nothing + } + + @Override + public void stopRecord(long delaySeconds) { + // do nothing + } + + @Override + public void stop() { + // do nothing + } + + @Override + public void close() throws DeviceTechnicalException { + // do nothing + } + + @Override + public void addDeviceStateListener(DeviceStateListener listener) { + // do nothing + } + + @Override + public void removeDeviceStateListener(DeviceStateListener listener) { + // do nothing + } + + @Override + public Set<DeviceStateListener> getDeviceStateListeners() { + return Sets.newHashSet(); + } +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,224 @@ +/* + * #%L + * SAMMOA :: Application + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device.gps; + +import com.google.common.collect.Sets; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.persistence.GeoPoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Base class for {@link GpsHandler} interface. This class contains common behaviour + * for automatic check on a given {@code period}. For that, this class contains + * a {@link TimerTask} scheduled from {@link #start()}. The {@link #open()} method + * will be called on start if state is still {@link DeviceState#NO_DEVICE}. + * The method {@link #getCurrentLocation()} must return null if the location doesn't + * change or the GPS is down. + * + * Created: 02/07/12 + * + * @author fdesbois <desbois@codelutin.com> + * @since 0.2 + * @see FakeGpsHandler + * @see GpsHandlerGpsylon + */ +public abstract class BaseGpsHandler implements GpsHandler { + + private static final Logger logger = LoggerFactory.getLogger(BaseGpsHandler.class); + + protected Set<DeviceStateListener> deviceStateListeners; + protected Set<GpsLocationListener> gpsLocationListeners; + + /** To test if connection to device is effective. */ + protected DeviceState state; + + protected GpsConfig config; + + protected Timer timer; + + /** + * Value to check the number of timer update failures before the DeviceState + * becomes {@link DeviceState#NO_DATA} + */ + protected int nbFailuresMax; + + public BaseGpsHandler(GpsConfig config) { + this.config = config; + this.state = DeviceState.NO_DEVICE; + this.gpsLocationListeners = Sets.newHashSet(); + this.nbFailuresMax = + (int) Math.ceil(config.getTimeout() / config.getCheckPeriod()); + + if (logger.isDebugEnabled()) { + logger.debug("GPS NbFailuresMax = " + nbFailuresMax); + } + } + + public GpsConfig getConfig() { + return config; + } + + @Override + public DeviceState getState() { + return state; + } + + @Override + public void start() throws DeviceTechnicalException { + + long periodMilliseconds = config.getCheckPeriod() * 1000; + + if (getState() == DeviceState.READY) { + + if (logger.isDebugEnabled()) { + logger.debug("Start scheduling GpsHandler every " + + periodMilliseconds + " milliseconds"); + } + + timer = new Timer(); + timer.schedule(recordTask, 0, periodMilliseconds); + + } else { + + timer = new Timer(); + timer.schedule(openTask, 0, periodMilliseconds); + } + } + + @Override + public void stop() { + timer.cancel(); + timer = null; + } + + @Override + public void addDeviceStateListener(DeviceStateListener deviceStateListener) { + deviceStateListeners.add(deviceStateListener); + } + + @Override + public void removeDeviceStateListener(DeviceStateListener deviceStateListener) { + deviceStateListeners.remove(deviceStateListener); + } + + @Override + public Set<DeviceStateListener> getDeviceStateListeners() { + return deviceStateListeners; + } + + @Override + public void addGpsLocationListener(GpsLocationListener gpsLocationListener) { + gpsLocationListeners.add(gpsLocationListener); + } + + @Override + public void removeGpsLocationListener(GpsLocationListener gpsLocationListener) { + gpsLocationListeners.remove(gpsLocationListener); + } + + @Override + public Set<GpsLocationListener> getGpsLocationListeners() { + return gpsLocationListeners; + } + + protected void setState(DeviceState state) { + DeviceState oldValue = getState(); + this.state = state; + + for (DeviceStateListener listener : deviceStateListeners) { + listener.stateChanged(new DeviceStateEvent(this, oldValue, state)); + } + } + + protected TimerTask openTask = new TimerTask() { + + @Override + public void run() { + try { + + open(); + + timer.cancel(); + timer = null; + + start(); + + } catch (DeviceTechnicalException ex) { + + // We use NO_DATA, because this task is during start + setState(DeviceState.NO_DATA); + + if (logger.isErrorEnabled()) { + logger.error("Can't open GPS device. Try again in " + + this.scheduledExecutionTime() + " milliseconds", ex); + } + } + } + }; + + protected TimerTask recordTask = new TimerTask() { + + protected GeoPoint location; + + protected int nbFailures; + + @Override + public void run() { + + GeoPoint lastLocation = location; + + location = getCurrentLocation(); + + // reset nbFailures if currentLocation is defined + if (location != null) { + nbFailures = 0; + } else { + nbFailures++; + } + + // Data is unavailable + if (location == null && nbFailures >= nbFailuresMax) { + setState(DeviceState.NO_DATA); + + // GPS is recording + } else { + + setState(DeviceState.RECORDING); + + // Fire events for location change + for (GpsLocationListener listener : gpsLocationListeners) { + listener.locationChanged(new GpsLocationEvent(BaseGpsHandler.this, lastLocation, location)); + } + } + } + }; +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,168 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device.gps; + +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPointImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.Random; + +/** + * Un Fake pour {@link GpsHandler}, il simule un déplacement toute les secondes + * à partir du point 0, 0. + */ +public class FakeGpsHandler extends BaseGpsHandler { + + private static final Logger logger = LoggerFactory.getLogger(FakeGpsHandler.class); + + public static final int MAX_POINTS = 100; + + protected GeoPoint startingPoint; + + protected GeoPoint currentLocation; + + protected Thread thread; + + public FakeGpsHandler(GpsConfig config) { + this(config, new GeoPointImpl(46.164139,-1.150503)); + } + + public FakeGpsHandler(GpsConfig config, GeoPoint origin) { + super(config); + + startingPoint = new GeoPointImpl(origin.getLatitude(), origin.getLongitude()); +// +// // add new thread to simulate gps state change +// Timer timer = new Timer(); +// timer.schedule(new TimerTask() { +// protected Random r = new Random(); +// protected DeviceState currentState = DeviceState.NO_DEVICE; +// +// @Override +// public void run() { +// DeviceState newState = currentState; +// if (r.nextInt(32) > 25) { +// newState = DeviceState.NO_DEVICE; +// } else { +// if (started) { +// if (r.nextInt(32) > 25) { +// newState = DeviceState.NO_DATA; +// } else { +// newState = DeviceState.RECORDING; +// } +// } else { +// newState = DeviceState.READY; +// } +// } +// +// if (!newState.equals(currentState)) { +// currentState = newState; +// for (GpsLocationListener locationUpdateListener : gpsLocationListeners) { +// locationUpdateListener.stateChanged(currentState); +// } +// } +// } +// }, 10000, 10000); + } + + @Override + public void open() throws DeviceTechnicalException { + // nothing to do + } + + @Override + public void start() { + if (thread == null) { + thread = new Thread(new GpsPointGenerator()); + thread.start(); + } + super.start(); + } + + @Override + public void close() throws DeviceTechnicalException { + // nothing to do + } + + @Override + protected void finalize() throws Throwable { + + if (thread != null) { + thread.interrupt(); + thread = null; + } + + super.finalize(); + } + + @Override + public GeoPoint getCurrentLocation() { + GeoPoint result; + // Location already saved, return null (i.e. no new location) + if (currentLocation == null || currentLocation.getTopiaId() != null) { + result = null; + + } else { + result = currentLocation; + } + return result; + } + + protected class GpsPointGenerator implements Runnable { + + @Override + public void run() { + + double latitude = startingPoint.getLatitude(); + double longitude = startingPoint.getLongitude(); + + Random random = new Random(1337); + + int count = MAX_POINTS; + + while (true && count != 0) { + + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + logger.debug("Interrupt sleeping, thread will be destroy", e); + } + + latitude += random.nextDouble() - 0.5; + longitude += random.nextDouble() - 0.5; + + currentLocation = new GeoPointImpl(latitude, longitude); + currentLocation.setRecordTime(new Date()); + + count--; + } + } + } + +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsConfig.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,205 @@ +package fr.ulr.sammoa.application.device.gps; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + + +import com.google.common.base.Preconditions; +import org.nuiton.util.ApplicationConfig; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Created: 18/06/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class GpsConfig { + + protected ApplicationConfig applicationConfig; + + public GpsConfig(ApplicationConfig applicationConfig) { + this.applicationConfig = applicationConfig; + this.applicationConfig.loadDefaultOptions(GpsConfigOption.values()); + } + + /** + * @return {@link GpsConfigOption#GPS_HANDLER} value + */ + public Class<? extends GpsHandler> getGpsHandlerClass() { + Class<?> result = applicationConfig.getOptionAsClass(GpsConfigOption.GPS_HANDLER.key); + Preconditions.checkArgument(GpsHandler.class.isAssignableFrom(result), + "The class " + result.getSimpleName() + " is not a GpsHandler implementation"); + return (Class<? extends GpsHandler>) result; + } + + /** + * @return {@link GpsConfigOption#GPS_CHECK_PERIOD} value + */ + public int getCheckPeriod() { + int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_CHECK_PERIOD.key); + return result; + } + + /** + * @return {@link GpsConfigOption#GPS_TIMEOUT} value + */ + public int getTimeout() { + int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_TIMEOUT.key); + return result; + } + + /** + * @return {@link GpsConfigOption#GPS_DEVICE} value + */ + public String getDevice() { + String result = applicationConfig.getOption(GpsConfigOption.GPS_DEVICE.key); + return result; + } + + /** + * @return {@link GpsConfigOption#GPS_SPEED} value + */ + public int getSpeed() { + int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_SPEED.key); + return result; + } + + public enum GpsConfigOption implements ApplicationConfig.OptionDef { + + /** Implementation class for GpsHandler */ + GPS_HANDLER("gps.handler", + n_("sammoa.config.gps.handler"), + "fr.ulr.sammoa.application.device.gps.GpsHandlerGpsylon", + Class.class + ), + /** Period time in seconds for each check of the gps to update location */ + GPS_CHECK_PERIOD("gps.check.period", + n_("sammoa.config.gps.check.period"), + "2", + Integer.class + ), + /** Time in seconds before timeout (NO_DATA, NO_DEVICE) */ + GPS_TIMEOUT("gps.timeout", + n_("sammoa.config.gps.timeout"), + "10", + Integer.class + ), + /** GPS Device name ex: /dev/ttyUSB0 or /dev/ttyS1 or COM5 */ + GPS_DEVICE("gps.device", + n_("sammoa.config.gps.device"), + "COM1", + String.class + ), + /** GPS data speed */ + GPS_SPEED("gps.speed", + n_("sammoa.config.gps.speed"), + "4800", + Integer.class + ); + + /** Configuration key. */ + private final String key; + + /** I18n key of option description */ + private final String description; + + /** Type of option */ + private final Class<?> type; + + /** Default value of option. */ + private String defaultValue; + + /** Flag to not keep option value on disk */ + private boolean isTransient; + + /** Flag to not allow option value modification */ + private boolean isFinal; + + GpsConfigOption(String key, + String description, + String defaultValue, + Class<?> type, + boolean isTransient, + boolean isFinal) { + this.key = key; + this.description = description; + this.defaultValue = defaultValue; + this.type = type; + this.isTransient = isTransient; + this.isFinal = isFinal; + } + + GpsConfigOption(String key, + String description, + String defaultValue, + Class<?> type) { + this(key, description, defaultValue, type, false, false); + } + + @Override + public String getKey() { + return key; + } + + @Override + public Class<?> getType() { + return type; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getDefaultValue() { + return defaultValue; + } + + @Override + public boolean isTransient() { + return isTransient; + } + + @Override + public boolean isFinal() { + return isFinal; + } + + @Override + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + public void setTransient(boolean newValue) { + // not used + } + + @Override + public void setFinal(boolean newValue) { + // not used + } + } +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,59 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device.gps; + +import fr.ulr.sammoa.application.device.DeviceManager; +import fr.ulr.sammoa.persistence.GeoPoint; + +import java.util.Set; + +/** + * Représente l'accès à un périphérique GPS. + */ +public interface GpsHandler extends DeviceManager { + + /** + * Retourne la position courante du GPS. + * + * @return la position courante selon le GPS ou {@code null} si elle ne peut + * pas être obtenue + */ + GeoPoint getCurrentLocation(); + + /** + * @param gpsLocationListener GpsLocationListener to add + */ + void addGpsLocationListener(GpsLocationListener gpsLocationListener); + + /** + * @param gpsLocationListener GpsLocationListener to remove + */ + void removeGpsLocationListener(GpsLocationListener gpsLocationListener); + + /** + * @return all GpsLocationListener + */ + Set<GpsLocationListener> getGpsLocationListeners(); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,236 @@ +/* + * #%L + * SAMMOA :: Application + * * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ulr.sammoa.application.device.gps; + +import com.google.common.base.Objects; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPointImpl; +import gnu.io.CommPortIdentifier; +import org.dinopolis.gpstool.gpsinput.GPSDataProcessor; +import org.dinopolis.gpstool.gpsinput.GPSDevice; +import org.dinopolis.gpstool.gpsinput.GPSException; +import org.dinopolis.gpstool.gpsinput.GPSPosition; +import org.dinopolis.gpstool.gpsinput.GPSSerialDevice; +import org.dinopolis.gpstool.gpsinput.nmea.GPSNmeaDataProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Date; +import java.util.Enumeration; +import java.util.Hashtable; + +/** + * Implementation de la gestion du GPS sur GPSylon. + * + * @author echatellier + */ +public class GpsHandlerGpsylon extends BaseGpsHandler { + + private static final Logger logger = LoggerFactory.getLogger(GpsHandlerGpsylon.class); + + protected GPSDataProcessor gpsDataProcessor; + + protected GPSDevice gpsDevice; + + protected GPSPosition lastPosition; + + protected GPSPosition lastSendPosition; + + protected float lastAltitude; + + protected float lastSpeed; + + protected boolean deviceInitialized; + + public GpsHandlerGpsylon(GpsConfig config) { + super(config); + } + + @Override + public void open() throws DeviceTechnicalException { + + if (getState() == DeviceState.READY) { + if (logger.isWarnEnabled()) { + logger.warn("GPS already opened"); + } + return; + } + + try { + + if (!deviceInitialized) { + + gpsDataProcessor = new GPSNmeaDataProcessor(); + + gpsDevice = new SammoaGPSSerialDevice(); + + Hashtable<String, Object> options = new Hashtable<String, Object>(); + options.put(GPSSerialDevice.PORT_NAME_KEY, getConfig().getDevice()); + options.put(GPSSerialDevice.PORT_SPEED_KEY, getConfig().getSpeed()); + + if (logger.isDebugEnabled()) { + logger.debug("GPS options: " + options); + } + + gpsDevice.init(options); + gpsDataProcessor.setGPSDevice(gpsDevice); + + deviceInitialized = true; + } + + if (logger.isTraceEnabled()) { + Enumeration portList = CommPortIdentifier.getPortIdentifiers(); + + while (portList.hasMoreElements()) { + CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); + if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { + logger.trace("Available SERIAL port : " + portId.getName()); + } + } + } + + gpsDataProcessor.open(); + + gpsDataProcessor.addGPSDataChangeListener( + GPSDataProcessor.LOCATION, gpsDataProcessorListener); + gpsDataProcessor.addGPSDataChangeListener( + GPSDataProcessor.ALTITUDE, gpsDataProcessorListener); + gpsDataProcessor.addGPSDataChangeListener( + GPSDataProcessor.SPEED, gpsDataProcessorListener); + + logger.info("Connected to GPS device"); + + setState(DeviceState.READY); + + } catch (GPSException ex) { + + setState(DeviceState.NO_DEVICE); + + throw new DeviceTechnicalException(this, "Can't open GPS device", ex); + } + } + + @Override + public void close() { + + stop(); + + if (gpsDataProcessor != null && getState() != DeviceState.NO_DEVICE) { + + logger.info("Closing GPS device..."); + try { + + gpsDataProcessor.removeGPSDataChangeListener( + GPSDataProcessor.LOCATION, gpsDataProcessorListener); + gpsDataProcessor.removeGPSDataChangeListener( + GPSDataProcessor.ALTITUDE, gpsDataProcessorListener); + gpsDataProcessor.removeGPSDataChangeListener( + GPSDataProcessor.SPEED, gpsDataProcessorListener); + + gpsDataProcessor.close(); + + logger.info("GPS device is closed"); + + setState(DeviceState.NO_DEVICE); + + } catch (GPSException e) { + throw new DeviceTechnicalException(this, "Can't close GPS device", e); + } + } + } + + @Override + public GeoPoint getCurrentLocation() { + + GeoPoint result = null; + + logger.trace("Ask lastPosition = {}", lastPosition); + + if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) { + + result = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude()); + result.setAltitude(lastAltitude); + result.setSpeed(lastSpeed); + // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp + result.setRecordTime(new Date()); + + lastSendPosition = lastPosition; + } + return result; + } + + @Override + protected void finalize() throws Throwable { + close(); + super.finalize(); + } + + /** + * Si l'on recoit des evenements, c'est que le gps fonctionne. + * Il sont envoyé par le traitement des flux NMEA et propagé par le + * {@code GPSDataChangeListener}. + * + * Properties available: + * <ul> + * <li>LOCATION: the value is a GPSPosition object + * <li>HEADING: the value is a Float + * <li>SPEED: the value is a Float and is in kilometers per hour + * <li>NUMBER_SATELLITES: the value is a Integer + * <li>ALTITUDE: the value is a Float and is in meters + * <li>SATELLITE_INFO: the value is a SatelliteInfo object. + * <li>DEPTH: the value is a Float and is in meters. + * <li>EPE: estimated position error, the value is a GPSPositionError object. + * <li>IDS_SATELLITES: An array of Integers holding the number of visible satellites. + * <li>PDOP: a Float indicating the quality of the gps signal. + * <li>HDOP: a Float indicating the quality of the gps signal in horizontal direction. + * <li>VDOP: a Float indicating the quality of the gps signal in vertical direction. + * </ul> + */ + protected PropertyChangeListener gpsDataProcessorListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + String property = evt.getPropertyName(); + + logger.trace("Gps data received {} {}", property, evt.getNewValue()); + + if (GPSDataProcessor.LOCATION.equals(property)) { + lastPosition = (GPSPosition) evt.getNewValue(); + + } else if (GPSDataProcessor.ALTITUDE.equals(property)) { + lastAltitude = (Float) evt.getNewValue(); + + } else if (GPSDataProcessor.SPEED.equals(property)) { + lastSpeed = (Float) evt.getNewValue(); + } + } + }; +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,58 @@ +package fr.ulr.sammoa.application.device.gps; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.persistence.GeoPoint; + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class GpsLocationEvent { + + protected GpsHandler source; + + protected GeoPoint oldValue; + + protected GeoPoint newValue; + + public GpsLocationEvent(GpsHandler source, GeoPoint oldValue, GeoPoint newValue) { + this.source = source; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public GpsHandler getSource() { + return source; + } + + public GeoPoint getOldValue() { + return oldValue; + } + + public GeoPoint getNewValue() { + return newValue; + } +} \ No newline at end of file Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,38 @@ +/* + * #%L + * SAMMOA :: Application + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.application.device.gps; + +/** + * DP Observateur. + */ +public interface GpsLocationListener { + + /** + * Update GPS location. + * + * @param event new event + */ + void locationChanged(GpsLocationEvent event); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java 2012-08-07 15:48:54 UTC (rev 360) @@ -0,0 +1,67 @@ +package fr.ulr.sammoa.application.device.gps; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import gnu.io.RXTXHack; +import gnu.io.RXTXPort; +import org.dinopolis.gpstool.gpsinput.GPSException; +import org.dinopolis.gpstool.gpsinput.GPSSerialDevice; + +/** + * There is an issue with closing on {@link gnu.io.SerialPort}. See + * <a href="https://forums.oracle.com/forums/thread.jspa?threadID=1292323"> + * https://forums.oracle.com/forums/thread.jspa?threadID=1292323 + * </a> + * + * Note that only the {@link RXTXHack} works... Maybe the upgrade of rxtx.jar could + * works (not in maven repo). + * <p/> + * The issue is probably from {@link org.dinopolis.gpstool.gpsinput.nmea.GPSNmeaDataProcessor} + * that creates a daemon thread to read the serialPort InputStream. There is + * no way to kill properly this thread before closing serialPort. + * + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class SammoaGPSSerialDevice extends GPSSerialDevice { + + @Override + public void close() throws GPSException { + if (serial_port_ != null) { + +// serial_port_.removeEventListener(); +// try { +// serial_port_.getOutputStream().flush(); +// serial_port_.getOutputStream().close(); +// serial_port_.getInputStream().close(); +// } catch (IOException e) { +// throw Throwables.propagate(e); +// } +// serial_port_.close(); + + RXTXHack.closeRxtxPort((RXTXPort) serial_port_); + } + } +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java =================================================================== --- trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java 2012-08-07 15:48:54 UTC (rev 360) @@ -27,7 +27,7 @@ * Created: 06/08/12 * * @author fdesbois <florian.desbois@codelutin.com> - * @see fr.ulr.sammoa.application.gps.SammoaGPSSerialDevice for usage + * @see fr.ulr.sammoa.application.device.gps.SammoaGPSSerialDevice for usage */ public final class RXTXHack { Modified: trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties =================================================================== --- trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties 2012-08-07 15:48:54 UTC (rev 360) @@ -10,7 +10,7 @@ sammoa.config.fly.mode= sammoa.config.gps.check.period=Time in seconds between each GPS capture sammoa.config.gps.device=GPS device port -sammoa.config.gps.handler=GpsHandler class \: fr.ulr.sammoa.application.gps.GpsHandlerGpylon or fr.ulr.sammoa.application.gps.FakeGpsHandler +sammoa.config.gps.handler=GpsHandler class \: fr.ulr.sammoa.application.device.gps.GpsHandlerGpylon or fr.ulr.sammoa.application.device.gps.FakeGpsHandler sammoa.config.gps.speed=GPS speed for capture sammoa.config.gps.timeout=Time in seconds before GPS going to timeout (always the same data is received for this laps of time) and return error sammoa.config.log.file=Path for application log file Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -24,11 +24,11 @@ */ package fr.ulr.sammoa.ui.swing; -import fr.ulr.sammoa.application.DeviceTechnicalException; import fr.ulr.sammoa.application.FlightState; import fr.ulr.sammoa.application.SammoaConfig; import fr.ulr.sammoa.application.SammoaContext; -import fr.ulr.sammoa.application.gps.GpsConfig; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.application.device.gps.GpsConfig; import fr.ulr.sammoa.persistence.Campaign; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.ui.swing.campaign.CampaignUI; Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-07 15:48:54 UTC (rev 360) @@ -24,11 +24,9 @@ */ package fr.ulr.sammoa.ui.swing.flight; -import fr.ulr.sammoa.application.DeviceState; -import fr.ulr.sammoa.application.DeviceUpdateEvent; -import fr.ulr.sammoa.application.DeviceUpdateListener; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; -import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; import org.nuiton.util.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +47,7 @@ * * @author chatellier */ -public class DeviceStateLED extends JLabel implements DeviceUpdateListener, GpsUpdateListener { +public class DeviceStateLED extends JLabel implements DeviceStateListener { /** serialVersionUID. */ private static final long serialVersionUID = 1L; @@ -59,7 +57,7 @@ protected DeviceState state; public DeviceStateLED() { -// onStateChanged(DeviceState.NO_DEVICE); +// stateChanged(DeviceState.NO_DEVICE); } protected static final ImageIcon NO_DEVICE_ICON = Resource.getIcon("/icons/device/nodevice.png"); @@ -68,7 +66,7 @@ protected static final ImageIcon NO_DATA_ICON = Resource.getIcon("/icons/device/nodata.gif"); @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { + public void stateChanged(DeviceStateEvent event) { DeviceState oldValue = getState(); this.state = event.getNewValue(); @@ -97,9 +95,4 @@ public DeviceState getState() { return state; } - - @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { - // nothing to do - } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -53,9 +53,9 @@ public void init() { getFlightUIModel().addPropertyChangeListener(this); - getFlightController().getAudioRecorder().addUpdateListener(view.getAudioLED()); - getFlightController().getGpsHandler().addUpdateListener(view.getGpsLED()); - getFlightController().getGpsHandler().addUpdateListener(getModel()); + getFlightController().getAudioRecorder().addDeviceStateListener(view.getAudioLED()); + getFlightController().getGpsHandler().addDeviceStateListener(view.getGpsLED()); + getFlightController().getGpsHandler().addGpsLocationListener(getModel()); } @Override Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-07 15:48:54 UTC (rev 360) @@ -24,9 +24,8 @@ */ package fr.ulr.sammoa.ui.swing.flight; -import fr.ulr.sammoa.application.DeviceState; -import fr.ulr.sammoa.application.DeviceUpdateEvent; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; +import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; +import fr.ulr.sammoa.application.device.gps.GpsLocationListener; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.ui.swing.BaseModel; @@ -37,7 +36,7 @@ /** * @author sletellier <letellier@codelutin.com> */ -public class FlightBarModel extends BaseModel implements GpsUpdateListener { +public class FlightBarModel extends BaseModel implements GpsLocationListener { private static final long serialVersionUID = 1L; @@ -82,16 +81,11 @@ } @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { + public void locationChanged(GpsLocationEvent event) { GeoPoint newLocation = event.getNewValue(); if (newLocation != null) { setSpeed((float) newLocation.getSpeed()); setAlt((float) newLocation.getAltitude()); } } - - @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { - // nothing to do - } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -46,9 +46,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; -import fr.ulr.sammoa.application.DeviceState; -import fr.ulr.sammoa.application.DeviceTechnicalException; -import fr.ulr.sammoa.application.DeviceUpdateEvent; import fr.ulr.sammoa.application.FlightController; import fr.ulr.sammoa.application.FlightControllerDefault; import fr.ulr.sammoa.application.FlightControllerUpdateListener; @@ -57,7 +54,9 @@ import fr.ulr.sammoa.application.ReferentialService; import fr.ulr.sammoa.application.SammoaConfig; import fr.ulr.sammoa.application.SammoaContext; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; +import fr.ulr.sammoa.application.device.gps.GpsLocationListener; import fr.ulr.sammoa.persistence.Campaign; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.persistence.GeoPoint; @@ -381,11 +380,11 @@ initMapHandler(); - getFlightController().getGpsHandler().addUpdateListener( - new GpsUpdateListener() { + getFlightController().getGpsHandler().addGpsLocationListener( + new GpsLocationListener() { @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { + public void locationChanged(GpsLocationEvent event) { GeoPoint newLocation = event.getNewValue(); if (newLocation != null && getModel().isMapFollow()) { MapBean mapBean = getOverlayMapPanel().getMapBean(); @@ -393,11 +392,6 @@ newLocation.getLongitude())); } } - - @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { - // nothing to do - } }); timeLog.log(startTime, "afterInitUI", "map is initialized"); @@ -749,7 +743,7 @@ // Ajout d'un layer pour représenter les points relevés par le GPS GpsTracingLayer gpsTracingLayer = new GpsTracingLayer(); - getFlightController().getGpsHandler().addUpdateListener(gpsTracingLayer); + getFlightController().getGpsHandler().addGpsLocationListener(gpsTracingLayer); mapHandler.add(gpsTracingLayer); InformationDelegator informationDelegator = new InformationDelegator(); Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-07 15:48:54 UTC (rev 360) @@ -29,9 +29,8 @@ import com.bbn.openmap.omGraphics.OMGraphicConstants; import com.bbn.openmap.omGraphics.OMGraphicList; import com.bbn.openmap.omGraphics.OMLine; -import fr.ulr.sammoa.application.DeviceState; -import fr.ulr.sammoa.application.DeviceUpdateEvent; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; +import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; +import fr.ulr.sammoa.application.device.gps.GpsLocationListener; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.ui.swing.SammoaColors; @@ -39,7 +38,7 @@ /** * Un layer OpenMap qui affiche les points envoyés par le GPS. */ -public class GpsTracingLayer extends OMGraphicHandlerLayer implements GpsUpdateListener { +public class GpsTracingLayer extends OMGraphicHandlerLayer implements GpsLocationListener { // private static final Logger logger = LoggerFactory.getLogger(GpsTracingLayer.class); @@ -52,7 +51,7 @@ } @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { + public void locationChanged(GpsLocationEvent event) { // OMGraphic point = new OMPoint(newLocation.getLatitude(), newLocation.getLongitude()); GeoPoint newLocation = event.getNewValue(); @@ -88,9 +87,4 @@ currentLocation = new GeoPointImpl(newLocation.getLatitude(), newLocation.getLongitude()); } } - - @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { - // nothing to do - } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 15:48:54 UTC (rev 360) @@ -23,13 +23,11 @@ * #L% */ -import fr.ulr.sammoa.application.DeviceState; -import fr.ulr.sammoa.application.DeviceUpdateEvent; -import fr.ulr.sammoa.application.DeviceUpdateListener; import fr.ulr.sammoa.application.FlightController; import fr.ulr.sammoa.application.FlightService; -import fr.ulr.sammoa.application.gps.GpsUpdateListener; -import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.ObservationStatus; import fr.ulr.sammoa.persistence.Observations; @@ -97,7 +95,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.4 */ -public class EffortPanelHandler implements DeviceUpdateListener, GpsUpdateListener { +public class EffortPanelHandler implements DeviceStateListener { private static final Logger logger = LoggerFactory.getLogger(EffortPanelHandler.class); @@ -275,8 +273,8 @@ SammoaUIContext.getUIContext().getFlightUIHandler().getFlightController(); if (flightController != null) { - flightController.getGpsHandler().addUpdateListener(this); - flightController.getAudioRecorder().addUpdateListener(this); + flightController.getGpsHandler().addDeviceStateListener(this); + flightController.getAudioRecorder().addDeviceStateListener(this); } @@ -552,7 +550,7 @@ } @Override - public void onStateChanged(DeviceUpdateEvent<DeviceState> event) { + public void stateChanged(DeviceStateEvent event) { DeviceState state = event.getNewValue(); if (DeviceState.NO_DATA == state) { ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR); @@ -562,11 +560,6 @@ } } - @Override - public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) { - // nothing to do - } - public DecoratorProvider getDecoratorProvider() { return SammoaUIContext.getUIContext().getDecoratorProvider(); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-07 07:52:19 UTC (rev 359) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-07 15:48:54 UTC (rev 360) @@ -26,7 +26,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Throwables; -import fr.ulr.sammoa.application.DeviceTechnicalException; +import fr.ulr.sammoa.application.device.DeviceTechnicalException; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.beanutils.NestedNullException; @@ -38,10 +38,7 @@ import org.slf4j.LoggerFactory; import javax.swing.*; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; +import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File;
participants (1)
-
fdesbois@users.forge.codelutin.com