[31] | 1 | /************************************************************************************ |
---|
| 2 | * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University |
---|
| 3 | * All rights reserved. |
---|
| 4 | * Refer to LICENSE for terms and conditions of use. |
---|
| 5 | ***********************************************************************************/ |
---|
| 6 | package vnsim.network.dsrc; |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | import java.io.ByteArrayOutputStream; |
---|
| 10 | import java.io.IOException; |
---|
| 11 | import java.io.Serializable; |
---|
| 12 | |
---|
| 13 | import vnsim.applications.vitp.CarRunningVITP; |
---|
| 14 | import vnsim.core.*; |
---|
| 15 | import vnsim.map.object.Globals; |
---|
| 16 | import vnsim.network.scft.MesageSCFT; |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | public class CarRunningDSRC extends CarRunningVITP |
---|
| 23 | { |
---|
| 24 | private WirelessPhy physicalLayer; |
---|
| 25 | |
---|
| 26 | private MAC80211 macLayer; |
---|
| 27 | |
---|
| 28 | private Application appLayer; |
---|
| 29 | |
---|
| 30 | public CarRunningDSRC(int vehicleId, byte lane, double speed, |
---|
| 31 | short roadIdx, short pointIdx, byte direction, double offset) |
---|
| 32 | { |
---|
| 33 | super(vehicleId, lane, speed, roadIdx, pointIdx, direction, offset); |
---|
| 34 | |
---|
| 35 | this.physicalLayer=new WirelessPhy(0); |
---|
| 36 | |
---|
| 37 | this.macLayer=new MAC80211(0); |
---|
| 38 | |
---|
| 39 | this.appLayer=new Application(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | public void onReceive(byte[] bytesReceived, Serializable m, Communicator sender) |
---|
| 44 | { |
---|
| 45 | if (!isEquipped || bytesReceived == null) |
---|
| 46 | return; |
---|
| 47 | //System.out.println("on receive:"+bytesReceived[0]); |
---|
| 48 | byte header = bytesReceived[0]; |
---|
| 49 | byte[] message = null; |
---|
| 50 | |
---|
| 51 | switch(header) |
---|
| 52 | { |
---|
| 53 | case Globals.PROT_EMERGENCY: |
---|
| 54 | this.appLayer.EmergencyVehicleWarning(bytesReceived,((CarInfo)this)); |
---|
| 55 | break; |
---|
| 56 | |
---|
| 57 | default:super.onReceive(bytesReceived, m, sender); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public byte[] prepareMessage(int messageType) |
---|
| 62 | { |
---|
| 63 | if (!isEquipped) |
---|
| 64 | return null; |
---|
| 65 | byte[] bytesToSend=null; |
---|
| 66 | //System.out.println("prepare:"+messageType); |
---|
| 67 | if(messageType==-1) |
---|
| 68 | { |
---|
| 69 | byte[] localinfo = toBytes(); |
---|
| 70 | ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); |
---|
| 71 | outBytes.write(Globals.PROT_EMERGENCY); |
---|
| 72 | outBytes.write(CRTDIR); |
---|
| 73 | try{ |
---|
| 74 | outBytes.write(localinfo); |
---|
| 75 | }catch(IOException e){ |
---|
| 76 | } |
---|
| 77 | bytesToSend = outBytes.toByteArray(); |
---|
| 78 | |
---|
| 79 | return bytesToSend; |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | return super.prepareMessage(messageType); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | public WirelessPhy getPhysical() |
---|
| 88 | { |
---|
| 89 | return this.physicalLayer; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | public MAC80211 getMac() |
---|
| 93 | { |
---|
| 94 | return this.macLayer; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | public Application getAppLayer() |
---|
| 98 | { |
---|
| 99 | return this.appLayer; |
---|
| 100 | } |
---|
| 101 | } |
---|