UAVReplacementCharger.java 3.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM 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
 * any later version.
 * 
 * PeerfactSim.KOM 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 PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.energy;


import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
25
26
27

import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
28
29
30
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
31
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
32
33

/**
34
35
 * Ground-based charger for UAVs. Replaces the battery completely, i.e., 
 * sets battery capacity to full levels, but requires some time to do so.
36
37
38
39
40
 * 
 * 
 * @author Julian Zobel
 * @version 1.0, 21.09.2018
 */
41
public class UAVReplacementCharger implements HostComponent {
42
43
44
45
	
	private Host host;
	private long replacementDuration;
	
46
	public UAVReplacementCharger(Host host, long replacementDuration) {
47
		this.host = host;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
		this.replacementDuration = replacementDuration;		
	}
	
	/**
	 * Charge a UAV by replacing the battery (i.e. reset to full battery levels). Replacement takes some time.
	 * The UAV is informed about the full replacement when it is finished by a callback.
	 * 
	 * @param uav
	 * @param cb
	 */
	public void charge(UAVTopologyComponent uav, BatteryReplacementCallback cb) {
		
		Event.scheduleWithDelay(replacementDuration, new EventHandler() {
			@Override
			public void eventOccurred(Object content, int type) {
				replacementComplete(uav, cb);
			}
		}, null, 0);			
	}
	
	/**
	 * When this is called (after the replacement duration) the UAV's battery is set 
	 * to full level/max capacity.
	 * 
	 * @param uav
	 * @param cb
	 */
	protected void replacementComplete(UAVTopologyComponent uav, BatteryReplacementCallback cb) {		
		uav.getBattery().setToMaximumLoad();
		cb.rechargeComplete();
78
79
80
81
	}
	
	@Override
	public void initialize() {
82
		// TODO Auto-generated method stub		
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
	}

	@Override
	public void shutdown() {
		throw new UnsupportedOperationException("Charger shutdown not supported!");
	}

	@Override
	public Host getHost() {
		return host;
	}

	
	public static class Factory implements HostComponentFactory {

		private long replacementDuration;
99
100
101
102
103
				
		/**
		 * Duration of the battery replacement in SECONDS
		 * @param replacementDuration
		 */
104
105
106
107
108
109
		public void setReplacementDuration(long replacementDuration) {
			this.replacementDuration = replacementDuration;
		}	
		
		@Override
		public HostComponent createComponent(Host host) {
110
			return new UAVReplacementCharger(host, replacementDuration);
111
112
113
114
		}
	
	}
}