/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.network.dsrc; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.Serializable; import vnsim.applications.vitp.CarRunningVITP; import vnsim.core.*; import vnsim.map.object.Globals; import vnsim.network.scft.MesageSCFT; public class CarRunningDSRC extends CarRunningVITP { private WirelessPhy physicalLayer; private MAC80211 macLayer; private Application appLayer; public CarRunningDSRC(int vehicleId, byte lane, double speed, short roadIdx, short pointIdx, byte direction, double offset) { super(vehicleId, lane, speed, roadIdx, pointIdx, direction, offset); this.physicalLayer=new WirelessPhy(0); this.macLayer=new MAC80211(0); this.appLayer=new Application(); } public void onReceive(byte[] bytesReceived, Serializable m, Communicator sender) { if (!isEquipped || bytesReceived == null) return; //System.out.println("on receive:"+bytesReceived[0]); byte header = bytesReceived[0]; byte[] message = null; switch(header) { case Globals.PROT_EMERGENCY: this.appLayer.EmergencyVehicleWarning(bytesReceived,((CarInfo)this)); break; default:super.onReceive(bytesReceived, m, sender); } } public byte[] prepareMessage(int messageType) { if (!isEquipped) return null; byte[] bytesToSend=null; //System.out.println("prepare:"+messageType); if(messageType==-1) { byte[] localinfo = toBytes(); ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); outBytes.write(Globals.PROT_EMERGENCY); outBytes.write(CRTDIR); try{ outBytes.write(localinfo); }catch(IOException e){ } bytesToSend = outBytes.toByteArray(); return bytesToSend; } else { return super.prepareMessage(messageType); } } public WirelessPhy getPhysical() { return this.physicalLayer; } public MAC80211 getMac() { return this.macLayer; } public Application getAppLayer() { return this.appLayer; } }