Development

» MR-Pa: Smart Parking Example

In this example the Smart Parking board is turned on and calibrated, then a measurement is taken every second approximately showing the magnetic field values read and the estimated status through the USB port.

Required Materials

1 x Waspmote
1 x Battery
1 x Smart Parking board

Notes

* Do not move the Smart Parking board once calibration has started or an "occupied" value will be output no matter the status of the board.
* To simulate the change of status a magnet or a ferromagnetic piece of metal may be used.
* A complete example of an application, along with the details of the board, may be found in the Smart Parking Technical Guide.
* Logger, Common and Parking assemblies must be loaded in the mote.
* Please, note that the output is in hexadecimal.
* Please, note that Float.toLong() method has been used with a precission of 2 decimals. For example, a 3413 output in decimal base means 34.13. For more information of Float class, see http://localhost:5000/gac/saguaro-system-11.3.htm?fqn=r:com.ibm.saguaro.system.Float
* To compile this example: mrc --assembly=park-1.0 --system=waspmote --ref=logger-#.# --ref=/common-1.0 --ref=/parking-1.0 ParkingExample.java

Code

/**
 *  Copyright (C) 2013 Libelium Comunicaciones Distribuidas S.L.
 * http://www.libelium.com
 *
 * This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 3.0 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 *
 *  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/>.
 * 
 * Design: David Gascón
 * 
 * @version 0.1
 * @author Anartz Nuin Jiménez, Diego López Pérez and Ignacio Ruiz Martín
 */

package com.libelium.examples.parking;

import com.ibm.saguaro.logger.Logger;
import com.ibm.saguaro.system.Float;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.Time;
import com.ibm.saguaro.system.Timer;
import com.ibm.saguaro.system.TimerEvent;
import com.ibm.saguaro.system.csr;
import com.libelium.common.Constants;
import com.libelium.parking.Parking;

public class ParkingExample {
	static Timer timer;
	static Parking park = new Parking();
	
	static{
		//park.loadReference();
		park.ON();
		park.calibration();
		
		Logger.appendString(csr.s2b("Initial Values:"));
		Logger.flush(Mote.INFO);
		Logger.appendString(csr.s2b("X-Field:"));
		Logger.appendHexLong(Float.toLong(park.initialX, (byte)0));
		Logger.flush(Mote.INFO);
		Logger.appendString(csr.s2b("Y-Field:"));
		Logger.appendHexLong(Float.toLong(park.initialY, (byte)0));
		Logger.flush(Mote.INFO);
		Logger.appendString(csr.s2b("Z-Field:"));
		Logger.appendHexLong(Float.toLong(park.initialZ, (byte)0));
		Logger.flush(Mote.INFO);
		
		
		
		timer = new Timer();
		
		timer.setCallback(new TimerEvent(null){
        		public void invoke(byte param, long time){
        			ParkingTest.timeCallback(param,time);
        		}
        	});
	
        long INTERVAL = Time.toTickSpan(Time.MILLISECS,2000);
    	timer.setAlarmBySpan(INTERVAL);
	}
	
	protected static void timeCallback(byte param, long time) {
		park.readParkingSetReset();
		int temperature = park.readTemperature();
		
		park.calculateReference(temperature);
		
		boolean status = park.estimateState();
		
		Logger.appendString(csr.s2b("X-Field:"));
		Logger.appendHexInt(park.valueX);
		Logger.flush(Mote.INFO);
		Logger.appendString(csr.s2b("Y-Field:"));
		Logger.appendHexInt(park.valueY);
		Logger.flush(Mote.INFO);
		Logger.appendString(csr.s2b("Z-Field:"));
		Logger.appendHexInt(park.valueZ);
		Logger.flush(Mote.INFO);
		
		if(status==Constants.PARKING_OCCUPIED){
			Logger.appendString(csr.s2b(" OCCUPIED"));
			Logger.flush(Mote.INFO);
		}else{
			Logger.appendString(csr.s2b(" EMPTY"));
			Logger.flush(Mote.INFO);
		}
		
		long INTERVAL = Time.toTickSpan(Time.MILLISECS,2000);
		timer.setAlarmBySpan(INTERVAL);
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Initial Values:

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: X-Field: 0731

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Y-Field: 0641

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Z-Field: 0684

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: X-Field: 0304

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Y-Field: 0582

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Z-Field: 036

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: OCCUPIED

Quick Publish:

This site uses cookies. By clicking the “Accept” button you are agreeing to our use of cookies. Read More