Example code for Building UconnectMessage:

       
/**********************************************************************************************
 * This example code is provided for illustrative purposes only and provided 'AS IS' without 
 * warranty of any kind.
 * 
 * Copyright ©2014 Chrysler Group LLC.  All Rights Reserved.  All information contained herein is,
 * and remains the property of Chrysler Group LLC and its suppliers, if any.  The intellectual and
 * technical concepts contained herein are proprietary to Chrysler Group LLC and its suppliers
 * and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade
 * secret or copyright law. Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Chrysler Group LLC.
 *
 * Chrysler, Jeep, Dodge, Ram, SRT, Mopar and the Pentastar logo are registered trademarks of
 * Chrysler Group LLC. FIAT is a registered trademark of Fiat group Marketing & Corporate
 * Communication S.p.A. used under license by Chrysler Group LLC.
 *********************************************************************************************/
		
	ActivationRequest activationReq = ActivationRequest.newBuilder()
			.setVehicleId(vehicleId)
			.setEmailAddress(emailAddress)
			.setFirstName(firstName)
			.setLastName(lastName)
			.setTcIndicator(indicatorEnum)
			.build();
    		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder()
			.setExtension(GlobalUconnectExtActivation.activationRequest, 
			 activationReq))
			.build();
      
      

The example code demonstrates how to build Uconnect message and add Activation Request message to it, Similarly you can add other messages

Client Example Code (HU/TBM) for AOTA:

       
package com.fca.uconnect.global;


import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.DRM.AppDrm;
import com.fca.uconnect.global.GlobalUconnectControl.DRM.AppDrm.DRMContent;
import com.fca.uconnect.global.GlobalUconnectControl.DRM.AppDrm.DRMRegistration;
import com.fca.uconnect.global.GlobalUconnectControl.DRM.AppDrm.DRMRegistration.OperationEnum;
import com.fca.uconnect.global.GlobalUconnectControl.DRM.AppDrm.DRMRegistration.RegistrationStatusEnum;
import com.fca.uconnect.global.GlobalUconnectControl.DRMService;
import com.fca.uconnect.global.GlobalUconnectControl.DRM;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtAOTA.DiscrepancyCheck;
import com.fca.uconnect.global.GlobalUconnectExtAOTA.UpdateStatusNotification;
import com.fca.uconnect.global.GlobalUconnectExtAOTA.UpdateStatusNotification.StatusEnum;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect AOTA message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForAOTA {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForAOTA() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtAOTA.applicationUpdateNotification);
		extRegistry.add(GlobalUconnectExtAOTA.initiateDiscrepancyCheck);
	}
	public void disconnect(){
		try {
			mqttClient.disconnect();
		} catch (AWSIotException e) {
			e.printStackTrace();
		}
	}
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for AOTA Response.
	 *
	 * @return
	 */
	public UconnectMessage getAOTARespMsg(StatusEnum repsonse){
			messageId++;
			UpdateStatusNotification respMsg = UpdateStatusNotification.newBuilder()
					.setStatus(repsonse)
					.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtAOTA.updateStatusNotification, respMsg))
			.build();

		return msg;		
	}
	
	public UconnectMessage getDescCheckMsg(){
		messageId++;
		DRMRegistration regiMsg = DRMRegistration.newBuilder()
				.setOperation(OperationEnum.RESET)
				.setRegistrationStatus(RegistrationStatusEnum.BASIC_STAGE)
				.build();
		//Only few fields added in this example
				DRMService drmService = DRMService.newBuilder()
						.setAppIdentifier("APPIDENTIFIER")
						.setEmailId("EMAILID")
						.setFileName("FILENAME")
						.setInstallerType("INSTALLER TYPE")
						.build();
		DRMContent drmContent = DRMContent.newBuilder()
				.setDrmService(0, drmService)
				.setApplicationType("APPTYPE")
				.setMsisdn("MSISDN")
				.build();
		AppDrm appDrm = AppDrm.newBuilder()
				.setDrmRegistration(regiMsg)
				.setAmsDRM(drmContent)
				.build();
		DRM drm = DRM.newBuilder()
				.setAppDrm(appDrm)
				.build();
		DiscrepancyCheck descCheckMsg = DiscrepancyCheck.newBuilder()
				.setDrm(drm)
				.build();
		
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtAOTA.discrepancyCheck, descCheckMsg))
		.build();
	return msg;		
}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an AOTA message to the AOTA topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/AOTA/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {
						e.printStackTrace();
					}			
					if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtAOTA.initiateDiscrepancyCheck)){
						//receive Initiate  and send DRM to SDP
						correlationId=msgIn.getMessageId();
						sendMessage(getDescCheckMsg());
					}else if ((msgIn.getMessages(0).hasExtension(GlobalUconnectExtAOTA.applicationUpdateNotification))){
						
						correlationId=msgIn.getMessageId();
						sendMessage(getAOTARespMsg(StatusEnum.SUCCESS));
					}
				}	
			};
			mqttClient.subscribe(iotTopic);
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} 
	}
	/**
	 * This method publishes the message to AOTA topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {						
			mqttClient.publish("/AOTA/"+clientId, AWSIotQos.QOS1, msgOut);
		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}		
	/**
	 * Example main to launch example.
	 * 
	 */
	public static void main(String[] args) {
		TBMExampleForAOTA example = new TBMExampleForAOTA();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for Activation:

       
package com.fca.uconnect.global;

import java.util.ArrayList;
import java.util.List;
import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtActivation.ActivationRequest;
import com.fca.uconnect.global.GlobalUconnectExtActivation.ActivationResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect Activation message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForActivation {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private Semaphore semaphore;//The semaphore objects is used to wait for a response.
	List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForActivation() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtActivation.activationResponse);
		extRegistry.add(GlobalUconnectExtProvision.provisioningPush);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for Activation.
	 * 
	 * @param vehicleId
	 * @param firstName
	 * @param lastName
	 * @param emailAddress
	 * @param acceptTandC
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getActivationReqMsg(String vehicleId,String firstName,String lastName,
		String emailAddress, boolean acceptTandC) {
		this.messageId++;
		sessionId = ByteString.copyFrom(new byte[18]);
		GlobalUconnectExtActivation.ActivationRequest.TCIndicatorEnum indicatorEnum;
		
		if (acceptTandC) {
			indicatorEnum = GlobalUconnectExtActivation.ActivationRequest.TCIndicatorEnum.AGREE;
		}
		else {
			indicatorEnum = GlobalUconnectExtActivation.ActivationRequest.TCIndicatorEnum.DISAGREE;			
		}
	
		ActivationRequest activationReq = ActivationRequest.newBuilder()
			.setVehicleId(vehicleId)
			.setEmailAddress(emailAddress)
			.setFirstName(firstName)
			.setLastName(lastName)
			.setTcIndicator(indicatorEnum)
			.build();
    		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtActivation.activationRequest, activationReq))
			.build();

		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Activation message to the UACT topic.
	 */
	public List process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/UACT/", AWSIotQos.QOS1) {
				//this code will be executed upon receiving an ActivationRespose message.
				public void onMessage(AWSIotMessage msg) {
					try{
					UconnectMessage msgIn;
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					if (msgIn.getCorrelationId()==messageId && msgIn.getMessages(0).hasExtension(GlobalUconnectExtActivation.activationResponse)) {
						if(messages==null)
							messages = new ArrayList();
						messages.add(msgIn.getMessages(0));
						ActivationResponse activationMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtActivation.activationResponse);
						semaphore.unlock();// Releasing the lock as it received response
					}else if(messages!=null && messages.size()>0){
						receivedResponse=true;
						messages.add(msgIn.getMessages(0));
					}
				
			} catch( Exception ex) {
				ex.printStackTrace();
				System.out.println("Err processing message: "+ex+", try parsing Activation.");
			}
			}
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getActivationReqMsg("562X4423AE122","fname","lname","flname@google.com",true);
			AWSIotMessage message = new MessagePublisherListener("/UACT/"+clientId,AWSIotQos.QOS1,msg.toByteArray());
			mqttClient.publish(message);
			//This is just to simulate a delay between sending Activation request and receiving Activation response and its just a place holder ,The onMessage method Handles callback
			this.semaphore.lock();		
			
			if(messages!=null)
				return messages;
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForActivation example = new TBMExampleForActivation();
		example.process();vc
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for AUTH:

       
package com.fca.uconnect.global;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtAuth.LoginRequest;
import com.fca.uconnect.global.GlobalUconnectExtAuth.LoginResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect Login/Logout message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForAuthorization {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForAuthorization() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtAuth.loginResponse);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for Login.
	 * @param userId
	 * @param credentials
	 * @return
	 */
	public UconnectMessage getLoginReqMsg(String userId,String credentials) {
		this.messageId++;
	
		LoginRequest lr = LoginRequest.newBuilder()
				.setIdentifier(userId)
				.setCredentials(credentials)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtAuth.loginRequest, lr))
			.build();

		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Login message to the ULIO topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/ULIO/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {

					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtAuth.loginResponse)) {
						LoginResponse loginMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtAuth.loginResponse);
						semaphore.unlock();// Releasing the lock as it received response
					}
				}	
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getLoginReqMsg("userId","password");

			AWSIotMessage message = new 
					MessagePublisherListener("/ULIO/"+clientId,AWSIotQos.QOS1,msg.toByteArray());
			mqttClient.publish(message);
			this.semaphore.lock();	//Wait for response, lock thread
			
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForAuthorization example = new TBMExampleForAuthorization();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for ECALL:

       
package com.fca.uconnect.global;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallDataUpload;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallDataUpload.AirBagStatus;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallDataUpload.EngineStatusEnum;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallDataUpload.TirePressure;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallStatusUpdate;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallStatusUpdate.ECallStatusEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect Ecall message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForECall {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForECall() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtECall.ecallDataUpload);		
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for ECALLDATAUPLOAD.
	 *
	 * @param vehicleId
	 * @param numberOfPassengers
	 * @param vehicleSpeed
	 * @param tirePressure
	 * @param isPositionTrusted
	 * @param carLocation
	 * @param airBagStatus
	 * @return
	 */
	public UconnectMessage getECallDataUploadReqMsg(String vehicleId,int numberOfPassengers,float vehicleSpeed,
			TirePressure tirePressure,boolean isPositionTrusted,Location carLocation,AirBagStatus airBagStatus){
						 
		this.messageId++;
		sessionId = ByteString.copyFrom(new byte[18]);
    	ECallDataUpload cardata = ECallDataUpload.newBuilder()
    			.setVehicleId(vehicleId)
    			.setNumberOfPassengers(numberOfPassengers)
    			.setVehicleSpeed(vehicleSpeed)
    			.setTimeStamp(System.currentTimeMillis())
    			.setTirePressure(tirePressure)
    			.setEngineStatusEnum(EngineStatusEnum.STOP)
    			.setIsPositionTrusted(isPositionTrusted)
    			.setVehicleLocation(carLocation)
    			.setAirBagStatus(airBagStatus)
    			.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setSessionId(sessionId)
			
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtECall.ecallDataUpload, cardata))
			.build();

		return msg;		
	}
	
	public UconnectMessage getECallStatusUpdateMsg(){
		ECallStatusUpdate ecallStatusUpdate = ECallStatusUpdate.newBuilder().
				setEcallStatusEnum(ECallStatusEnum.DIAL).build();
		
		UconnectMessage msg = UconnectMessage.newBuilder()
				.setTimestamp(System.currentTimeMillis())
				.setSessionId(sessionId)
				
				.setMessageId(messageId)
				.addMessages(UconnectAny.newBuilder().
				 setExtension(GlobalUconnectExtECall.ecallStatusUpdate, ecallStatusUpdate))
				.build();

			return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an ECALL message to the ECAL topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/ECAL/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
				}	
			};
			mqttClient.subscribe(iotTopic);
			AirBagStatus airBagStatus = AirBagStatus.newBuilder()
					.setIsDriver(false)
					.setIsDriverKnee(false)
					.setIsLeftSeat(false)
					.setIsRightSeat(false)
					.setIsPassenger(false)
					.setIsPassengerKnee(false)
					.setIsLeftSideCurtain(false)
					.build();
			Location vehicleLocation = Location.newBuilder()
					.setPositionLongitude(43.9999f)
					.setPositionLatitude(-84.54635343f)
					.build();
				TirePressure tirePressureMsg = TirePressure.newBuilder()
						.setFlTirePressure(35)
						.setFrTirePressure(34)
						.setRlTirePressure(36)
						.setRrTirePressure(35)
						.build();
			UconnectMessage msg = getECallDataUploadReqMsg("1234AXFGFGHGH4566",1,75,tirePressureMsg,true,vehicleLocation,airBagStatus);
			sendMessage(msg);
			Thread.sleep(5000);
			UconnectMessage eCallMsg = getECallStatusUpdateMsg();
			sendMessage(eCallMsg);
			
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} catch (InterruptedException e) {
		} 
	}
	/**
	 * This method publishes the message to ECAL topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {		
			AWSIotMessage message = new 
					MessagePublisherListener("/ECAL/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);
		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}
		
	/**
	 * Example main to launch example.
	 * 
	 */
	public static void main(String[] args) {
		TBMExampleForECall example = new TBMExampleForECall();
		example.process();
	}
}
   
      

Download Client Example Code here

Client Example Code (HU/TBM) for FOTA:

       

package com.fca.uconnect.global;


import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtFOTA.FirmwareUpdateResponse;
import com.fca.uconnect.global.GlobalUconnectExtFOTA.FirmwareUpdateResponse.ResponseEnum;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect FOTA message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForFOTA {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private List messages;// This can be used for JUNIT tests.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForFOTA() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtFOTA.firmwareUpdateNotification);
		
	}
	public void disconnect(){
		try {
			mqttClient.disconnect();
		} catch (AWSIotException e) {
			e.printStackTrace();
		}
	}
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for FOTA Response.
	 *
	 * @return
	 */
	public UconnectMessage getFOTARespMsg(ResponseEnum repsonse){
			messageId++;
			FirmwareUpdateResponse respMsg = FirmwareUpdateResponse.newBuilder()
					.setResponseEnum(repsonse)
					.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtFOTA.firmwareUpdateResponse, respMsg))
			.build();

		return msg;		
	}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an FOTA message to the FOTA topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/FOTA/", AWSIotQos.QOS0) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {
						e.printStackTrace();
					}			
					if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtFOTA.firmwareUpdateNotification)){
						//receive notify and update firmware and send response to SDP
						correlationId=msgIn.getMessageId();
						sendMessage(getFOTARespMsg(ResponseEnum.SUCCESS));
						
					}
				}	
			};
			mqttClient.subscribe(iotTopic);
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} 
	}
	/**
	 * This method publishes the message to FOTA topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {						
			mqttClient.publish("/FOTA/"+clientId, AWSIotQos.QOS0, msgOut);
		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}
		
	/**
	 * Example main to launch example.
	 * 
	 */
	public static void main(String[] args) {
		TBMExampleForFOTA example = new TBMExampleForFOTA();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for PC:

       

package com.fca.uconnect.global;
import java.util.List;
import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCNotificationPublish;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCNotificationPublish.NotificationType;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCNotificationPublish.SignalSource;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCNotificationPublish.VehiclePosition;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCUpdateConfigResponse;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCUpdateConfigResponse.ResponseEnum;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.EngineStatusEnum;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.ErrorTellTale;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.TirePressure;
import com.fca.uconnect.global.util.MessageUtil;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect RoadSideAsistance message with Data to the SDP .   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForPC {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForPC() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtPC.pcUpdateConfigRequest);
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for Parental Control Response
	 * @param ResponseEnum
	 * @return
	 */
	public UconnectMessage getPCConfigRespMsg(ResponseEnum respEnum) {
		this.messageId++;
		PCUpdateConfigResponse pcConfigResp = PCUpdateConfigResponse.newBuilder()
				.setResponseEnum(respEnum)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtPC.pcUpdateConfigResponse, pcConfigResp))
			.build();
		return msg;		
	}
	public UconnectMessage getPCNotifyPubMsg() {
		this.messageId++;
		Location vehicleLocation = Location.newBuilder()
				.setPositionLongitude(43.9999f)
				.setPositionLatitude(-84.54635343f)
				.build();
		VehiclePosition vehPosition = VehiclePosition.newBuilder()
			.setPositionEncrypted(false)
			.setGpsTimestamp((int)System.currentTimeMillis())
			.setVehicleDirection(32)
			.setVehiclePosition(vehicleLocation)
			.build();
		PCNotificationPublish notify = PCNotificationPublish.newBuilder()
				.setAcceleration(35)
				.setNotificatonType(NotificationType.SUDDEN_CORNERING)
				.setSpeed(75)
				.setSteeringWheelRotationRate(15.5f)
				.setVehiclePosition(vehPosition)
				.setSpeedSource(SignalSource.TBM_ACCELEROMETER)
				.setAccelerationSource(SignalSource.TBM_ACCELEROMETER)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtPC.pcNotificationPublish, notify))
			.build();
		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an RSADataUpload message to the RSA topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
			iotTopic = new AWSIotTopic(clientId+"/PC/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtPC.pcUpdateConfigRequest)){
						GlobalUconnectExtPC.PCUpdateConfigRequest pcConfigReq = msgIn.getMessages(0).getExtension(GlobalUconnectExtPC.pcUpdateConfigRequest);
					UconnectMessage respMsg = getPCConfigRespMsg(ResponseEnum.SUCCESS);
					sendMessage(respMsg);
					sendMessage(getPCNotifyPubMsg());
				}
			}};
			mqttClient.subscribe(iotTopic);
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * This method publishes the message to PC topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {
			AWSIotMessage message = new 
					MessagePublisherListener("/PC/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);
		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}

	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForPC example = new TBMExampleForPC();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for PHEV:

       

package com.fca.uconnect.global;

import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtPHEV.PHEVData;
import com.fca.uconnect.global.GlobalUconnectExtPHEV.PHEVData.CommandMarkEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect PHEVDATA message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForPHEV {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.

	private List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForPHEV() {
		extRegistry = ExtensionRegistry.newInstance();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for PHEVData.
	 * 
	 * 
	 */
	public UconnectMessage getPHEVDataMsg() {
		this.messageId++;
		ByteString phevData = ByteString.copyFrom(new byte[18]);
		
		PHEVData phevDataMsg = PHEVData.newBuilder()
				.setData(phevData)
				.setCommandMark(CommandMarkEnum.VEHICLE_LOGIN)
				.setDataCollectionTimestamp(System.currentTimeMillis())
				.build();
    		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtPHEV.phevData,phevDataMsg))
			.build();
		return msg;		
	}
	public void disconnect(){
		try {
			mqttClient.disconnect();
		} catch (AWSIotException e) {
			e.printStackTrace();
		}
	}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an PHEVData message to the PHEV topic.
	 */
	public List process() {
		
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/PHEV/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					try{
					UconnectMessage msgIn;
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
			} catch( Exception ex) {
				ex.printStackTrace();
				System.out.println("Err processing message: "+ex+", try parsing PHEV.");
			}
			}
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getPHEVDataMsg();
			mqttClient.publish("/PHEV/"+clientId, AWSIotQos.QOS1, msg.toByteArray());

			if(messages!=null)
				return messages;
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForPHEV example = new TBMExampleForPHEV();
		example.process();
	}
}
     
      

The example code demonstrates how to connect with AWS IoT for publishing and subscribing to the PHEV topic.

Download Client Example Code here

Client Example Code (HU/TBM) for Provisioning:

       

package com.fca.uconnect.global;

import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Device;
import com.fca.uconnect.global.GlobalUconnectControl.Device.DeviceType;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningRequest;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect Provisioning message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForProvisioning {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	private List messages;
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForProvisioning() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtProvision.provisioningResponse);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for Provisioning.
	 * 
	 * @param vehicleId
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getProvisioningReqMsg(String vehicleId) {
		this.messageId++;
		Device device = Device.newBuilder()
				.setDeviceType(DeviceType.VP4)
				.setHuSerialNum("HUSerialNbr")
				.setHuFirmwareVersion("HUVersion")
				.setTbmFirmwareVersion("TBM Version")
				.setTbmSerialNum("TBMSerial Nbr")
				.setIccid("ICCID")
				.setImei("IMEI")
				.setMsisdn("MSDISDN")
				.build();
		ProvisioningRequest pr = ProvisioningRequest.newBuilder()
				.setVehicleId(vehicleId)
				.setDevice(device)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtProvision.provisioningRequest, pr))
			.build();

		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Provisioning message to the PRVI topic.
	 */
	public List process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/PRVI/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {

					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtProvision.provisioningResponse)) {
						ProvisioningResponse provisioningMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtProvision.provisioningResponse);
						semaphore.unlock();// Releasing the lock as it received response
						if(messages==null)
							messages = new ArrayList();
						messages.add(msgIn.getMessages(0));
					}
					
				}	
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getProvisioningReqMsg("562X4423AE122");

			AWSIotMessage message = new 
					MessagePublisherListener("/PRVI/"+clientId,AWSIotQos.QOS1,msg.toByteArray());
			mqttClient.publish(message);
			this.semaphore.lock();	//Wait for response, lock thread
			
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return messages;
	}
	public void disconnect(){
		try {
			mqttClient.disconnect();
		} catch (AWSIotException e) {
			e.printStackTrace();
		}
	}
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForProvisioning example = new TBMExampleForProvisioning();
		example.process();
	}
}
      
      

The example code demonstrates how to connect with AWS IoT for publishing and subscribing to the Provisioning topic.

Download Client Example Code here

Client Example Code (HU/TBM) for Remote Operation:

       
package com.fca.uconnect.global;

import java.util.UUID;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteDoorRequest.CommandEnum;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest.ActionEnum;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationResponse;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect RemoteOperations message to the Client and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForRemoteOp  {


	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId ;// The messageId is a sequential number incremented and assigned to each message sent from the Service.
	private AWSIotMqttClient mqttClient;// The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.


	public TBMExampleForRemoteOp() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationRequest);
		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationSubscribeResponse);
		this.semaphore = new Semaphore();
	}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Login message to the RO topic.
	 */
	public void process() {

		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
	try {			
	mqttClient.connect();						
	iotTopic = new AWSIotTopic(clientId+"/RO/",AWSIotQos.QOS1){
		public void onMessage(AWSIotMessage msg) {
	try {
		
		UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);								
		if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest)) {
				boolean validRemoteOperation = false;
				GlobalUconnectExtRemoteOp.RemoteOperationRequest ro = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest);
				if (ro.hasRemoteDoorRequest()) {
					if (ro.getRemoteDoorRequest().getCommand() == CommandEnum.UNLOCK_DRIVER) {
						correlationId = msgIn.getMessageId();
						validRemoteOperation = true;
						semaphore.unlock();
						sendMessage(getRemoteOpRespMsg(correlationId,GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum.SUCCESS));
						//Publish Remote operation Status if User subscribing
						if(ro.getAction().equals(ActionEnum.SUBSCRIBE)){
						GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum statusEnum=GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.REQUESTED;
						UUID serviceId =UUID.randomUUID();
						for(int i=0;i<4;i++){
							Thread.sleep(1000);//wait and send remote operation status
							if(i==1)
								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.DELIVERED;
							else if (i==2)
								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.IN_PROGRESS;
							else if (i==3)
								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.COMPLETE;
						  sendMessage(getRemoteOpPubMsg(correlationId,serviceId,statusEnum));
						 }
						}
					}else{
						sendMessage(getRemoteOpRespMsg(correlationId,GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum.NOT_AUTHORIZED));
					}
				}
			}
		
	} catch( Exception ex) {
		ex.printStackTrace();
		System.out.println("Err processing message: "+ex+", try parsing Provisioning.");
	  }
	 }
	};
	mqttClient.subscribe(iotTopic);

	} catch (AWSIotException e) {
		System.out.println("Caught Exception "+e);
		e.printStackTrace();
	}
	try {
		semaphore.lock();
	} catch (InterruptedException e) {
		
	}
	}
	public UconnectMessage getRemoteOpPubMsg(int correlationId, UUID serviceRequestId, StatusEnum status) {
		messageId++;
		RemoteOperationStatus ros = RemoteOperationStatus.newBuilder()
				.setStatus(status)
				.build();
		
		UconnectMessage msg = UconnectMessage.newBuilder()
				.setTimestamp(System.currentTimeMillis())
				.setMessageId(messageId)
				
				
				.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus, ros))
				.build();
		return msg;		
	}
	public UconnectMessage getRemoteOpRespMsg(int correlationId, GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum response) {
		messageId++;
		RemoteOperationResponse ro = RemoteOperationResponse.newBuilder()
				.setResponse(response)
				.build();
		
		UconnectMessage msg = UconnectMessage.newBuilder()
				.setTimestamp(System.currentTimeMillis())
				.setSessionId(sessionId)
				.setMessageId(messageId)
				.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse, ro))
				.build();
		return msg;		
	}
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {	
			AWSIotMessage message = new 
					MessagePublisherListener("/RO/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);

		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			    
			}).start();
}
	
	public static void main(String[] args) {
		TBMExampleForRemoteOp service = new TBMExampleForRemoteOp();
		service.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM):

       
/**********************************************************************************************
 * This example code is provided for illustrative purposes only and provided 'AS IS' without 
 * warranty of any kind.
 * 
 * Copyright ©2014 Chrysler Group LLC.  All Rights Reserved.  All information contained herein is,
 * and remains the property of Chrysler Group LLC and its suppliers, if any.  The intellectual and
 * technical concepts contained herein are proprietary to Chrysler Group LLC and its suppliers
 * and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade
 * secret or copyright law. Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Chrysler Group LLC.
 *
 * Chrysler, Jeep, Dodge, Ram, SRT, Mopar and the Pentastar logo are registered trademarks of
 * Chrysler Group LLC. FIAT is a registered trademark of Fiat group Marketing & Corporate
 * Communication S.p.A. used under license by Chrysler Group LLC.
 *********************************************************************************************/
package com.fca.uconnect.global;

import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.EngineStatusEnum;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.ErrorTellTale;
import com.fca.uconnect.global.GlobalUconnectExtRoadSideAssist.RSADataUpload.TirePressure;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect RoadSideAsistance message with Data to the SDP .   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForRSA {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	
	List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForRSA() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtRoadSideAssist.rsaDataUpload);
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for RoadSideAssistance Data upload
	 * @param location
	 * @param tirePressure
	 * @param errorTellTale
	 * @param statusEnum
	 * @param fuelLevel
	 * @return
	 */
	public UconnectMessage getRSADataMsg(Location location,TirePressure tirePressure,ErrorTellTale errorTellTale , EngineStatusEnum statusEnum,float fuelLevel) {
		this.messageId++;
		sessionId = ByteString.copyFrom(new byte[18]);
		RSADataUpload rsaData = RSADataUpload.newBuilder()
				.setErrorTellTale(errorTellTale)
				.setFuelLevel(fuelLevel)
				.setTirePressure(tirePressure)
				.setVehicleLocation(location)
				.setEngineStatusEnum(statusEnum)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtRoadSideAssist.rsaDataUpload, rsaData))
			.build();
		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an RSADataUpload message to the RSA topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/RSA/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					// You can receive messages if SDP sends any 
				}
			};
			mqttClient.subscribe(iotTopic);
			Location carLocation = Location.newBuilder()
					.setPositionLongitude(43.9999)
					.setPositionLatitude(-84.54635343f)
					.build();
			TirePressure tirePressureMsg = TirePressure.newBuilder()
					.setFlTirePressure(35)
					.setFrTirePressure(34)
					.setRlTirePressure(36)
					.setRrTirePressure(35)
					.build();
			ErrorTellTale tellTaleMsg = ErrorTellTale.newBuilder()
					.setIsOilPressure(true)
					.build();
			EngineStatusEnum engineStatus = EngineStatusEnum.REQUESTSTART;
			UconnectMessage msg = getRSADataMsg(carLocation,tirePressureMsg,tellTaleMsg,engineStatus,20f);
			mqttClient.publish("/RSA/"+clientId, AWSIotQos.QOS1, msg.toByteArray());

		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForRSA example = new TBMExampleForRSA();
		example.process();
	}
}
   
      

Download Client Example Code here

Client Example Code (HU/TBM) for SQDF:

       
package com.fca.uconnect.global;

import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData.ECUDataPoint;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData.ECUDataPoint.CanType;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData.QuickScan;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFPublish;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect SQDF message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForSQDF {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	List messages ;
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForSQDF() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtSQDF.sqdfRequest);
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for SQDFPublish.
	 * 
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getSQDFPubMsg() {
		this.messageId++;
		ECUDataPoint dataPoint = ECUDataPoint.newBuilder()
		.setResponseID(12345)
		.setType(CanType.BHCAN_OR_I_CAN)
		.setCanFrame(ByteString.copyFrom(new byte[18]))
		.build();
		QuickScan scan = QuickScan.newBuilder()
				.setODO(60)
				.setGpsLatitude(12.34)
				.setGpsLongitude(12.34)
				.addQuickscanDataPoints(dataPoint)
				.setGpsAltitude(12.34)
				.setGpsTimestamp(System.currentTimeMillis())
				.setVIN(122)
				.build();
		SQDFData data = SQDFData.newBuilder()
				.setQuickScan(scan)
				.build();
		SQDFPublish pubMsg = SQDFPublish.newBuilder()
				.setData(data)
				.build();
				
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtSQDF.sqdfPublish, pubMsg))
			.build();

		return msg;		
	}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an SQDF message to the SQDF topic.
	 */
	public List process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
		iotTopic = new AWSIotTopic(clientId+"/SQDF/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					try{
					UconnectMessage msgIn;
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtSQDF.sqdfRequest)) {
						if(messages==null)
							messages = new ArrayList();
						messages.add(msgIn.getMessages(0));
					}
				
			} catch( Exception ex) {
				ex.printStackTrace();
				System.out.println("Err processing message: "+ex+", try parsing SQDF.");
			}
			}
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getSQDFPubMsg();
			mqttClient.publish("/SQDF/"+clientId, AWSIotQos.QOS1, msg.toByteArray());
			
			if(messages!=null)
				return messages;
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForSQDF example = new TBMExampleForSQDF();
		example.process();
	}
}
      
      

Download Client Example Code here

Example Code (HU/TBM) for SendAndGo:

       

package com.fca.uconnect.global;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to receive a Uconnect SendDestinationtoCar messages from the SDP    
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForSendDesttoCar {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	

	
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForSendDesttoCar() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtSendAndGo.destinationPush);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing and subscribing  SendDestoVehicle messages to the SDTC topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
			iotTopic = new AWSIotTopic(clientId+"/SDTC/", AWSIotQos.QOS1) {
			 public void onMessage(AWSIotMessage msg) {
				 try {
			 UconnectMessage msgIn;
				msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
				if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtSendAndGo.destinationPush)) {
					semaphore.unlock();// Releasing the lock 
				} 

			} catch (InvalidProtocolBufferException e) {
			}
			 }};
				
			mqttClient.subscribe(iotTopic);
			this.semaphore.lock();	//Wait for response, lock thread
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForSendDesttoCar example = new TBMExampleForSendDesttoCar();
		example.process();
	}
}
   
      

Download Client Example Code here

Example Code (HU/TBM):

       
/**********************************************************************************************
 * This example code is provided for illustrative purposes only and provided 'AS IS' without 
 * warranty of any kind.
 * 
 * Copyright ©2014 Chrysler Group LLC.  All Rights Reserved.  All information contained herein is,
 * and remains the property of Chrysler Group LLC and its suppliers, if any.  The intellectual and
 * technical concepts contained herein are proprietary to Chrysler Group LLC and its suppliers
 * and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade
 * secret or copyright law. Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Chrysler Group LLC.
 *
 * Chrysler, Jeep, Dodge, Ram, SRT, Mopar and the Pentastar logo are registered trademarks of
 * Chrysler Group LLC. FIAT is a registered trademark of Fiat group Marketing & Corporate
 * Communication S.p.A. used under license by Chrysler Group LLC.
 *********************************************************************************************/
package com.fca.uconnect.global;

import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenModeChangeRequest;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenModeChangeRequest.StolenModeCommand;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenModeChangeResponse;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenVehicleControlResponse;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenVehicleControlResponse.StolenVehControlResponseEnum;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenVehicleInfoNotification;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send/receive a Uconnect StolenVehicleAssistance messages to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForStolenVehAssist {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForStolenVehAssist() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenModeChangeRequest);
		extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenModeChangeResponse);
		extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleInfoNotification);
		extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleControlRequest);
		extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleControlResponse);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for StolenModeChangeResponse.
	 * 
	 * @param isStolenModeActive
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getStolenModeChangeRespMsg(boolean isStolenModeActive) {
		this.messageId++;
		sessionId = ByteString.copyFrom(new byte[18]);
		StolenModeChangeResponse stolenModeChgResp = StolenModeChangeResponse.newBuilder()
			.setIsStolenModeActive(isStolenModeActive)
			.build();
    		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
			setExtension(GlobalUconnectExtStolenVehAssist.stolenModeChangeResponse, stolenModeChgResp))
			.build();
		return msg;		
	}
	public UconnectMessage getStolenVehNotificationMsg(Location vehicleLocation,boolean isBlockIgnitionActive,
					boolean isIgnoreAccelerateActive){
		messageId++;
		StolenVehicleInfoNotification notifyMsg =StolenVehicleInfoNotification.newBuilder()
				.setIsBlockIgnitionActive(isBlockIgnitionActive)
				.setIsIgnoreAccelerateActive(isIgnoreAccelerateActive)
				.setVehicleLocation(vehicleLocation)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
				.setTimestamp(System.currentTimeMillis())
				.setMessageId(messageId)
				.addMessages(UconnectAny.newBuilder().
				setExtension(GlobalUconnectExtStolenVehAssist.stolenVehicleInfoNotification, notifyMsg))
				.build();
			return msg;		
	}
public UconnectMessage getStolenVehicleControlRespMsg(StolenVehControlResponseEnum respEnum){
messageId++;
StolenVehicleControlResponse respMsg =StolenVehicleControlResponse.newBuilder()
		.setStolenVehControlResponseEnum(respEnum)
		.build();
UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		setExtension(GlobalUconnectExtStolenVehAssist.stolenVehicleControlResponse, respMsg))
		.build();
	return msg;		
}
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an StolenVehAsist messages to the SVAS topic.
	 */
	public void process() {
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
			iotTopic = new AWSIotTopic(clientId+"/SVAS/", AWSIotQos.QOS1) {
	public void onMessage(AWSIotMessage msg) {
		try{
		UconnectMessage msgIn;
			msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
			correlationId=msgIn.getMessageId();
	if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtStolenVehAssist.stolenModeChangeRequest)) {
		semaphore.unlock();// Releasing the lock 
		StolenModeChangeRequest stolenModelChgReqMsg = msgIn.getMessages(0).getExtension(
				GlobalUconnectExtStolenVehAssist.stolenModeChangeRequest);
		boolean isStolenModeActive=false;
	if(stolenModelChgReqMsg.getStolenModeCommand().equals(StolenModeCommand.ENTER))
			isStolenModeActive=true;
		UconnectMessage respMsg = getStolenModeChangeRespMsg(isStolenModeActive);
		sendMessage(respMsg);
		//For Every interval send Vehicle Notification to SDP with location and Mode
		int i=1;
		while(isStolenModeActive){
			Location vehicleLocation = Location.newBuilder()
					.setPositionLatitude(42.480201F+(i*0.0001F))
					.setPositionLongitude(-83.671875F+(i*0.0001F))
					.build();
			boolean isBlockIgnitionActive=false;
			boolean isIgnoreAccelerateActive=false;
			Thread.sleep(stolenModelChgReqMsg.getLocationUpdateInterval());
			sendMessage(getStolenVehNotificationMsg(vehicleLocation, 
					isBlockIgnitionActive, isIgnoreAccelerateActive));
			i++;
		}
	}else if(msgIn.getMessages(0).hasExtension(
			GlobalUconnectExtStolenVehAssist.stolenVehicleControlRequest)){
		correlationId=msgIn.getMessageId();
		sendMessage(getStolenVehicleControlRespMsg(StolenVehControlResponseEnum.SUCCESS));
	}
	} catch( Exception ex) {
		ex.printStackTrace();
		System.out.println("Err processing message: "+ex+", try parsing StolenVehAssistance messages.");
	}
 }
};
			mqttClient.subscribe(iotTopic);
			this.semaphore.lock();	// lock thread

		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {
		    @Override
		public void run() {
		try {						
			AWSIotMessage message = new 
					MessagePublisherListener("/SVAS/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);

		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForStolenVehAssist example = new TBMExampleForStolenVehAssist();
		example.process();
	}
}
   
      

Download Client Example Code here

Client Example Code (HU/TBM):

       
/**********************************************************************************************
 * This example code is provided for illustrative purposes only and provided 'AS IS' without 
 * warranty of any kind.
 * 
 * Copyright ©2014 Chrysler Group LLC.  All Rights Reserved.  All information contained herein is,
 * and remains the property of Chrysler Group LLC and its suppliers, if any.  The intellectual and
 * technical concepts contained herein are proprietary to Chrysler Group LLC and its suppliers
 * and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade
 * secret or copyright law. Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Chrysler Group LLC.
 *
 * Chrysler, Jeep, Dodge, Ram, SRT, Mopar and the Pentastar logo are registered trademarks of
 * Chrysler Group LLC. FIAT is a registered trademark of Fiat group Marketing & Corporate
 * Communication S.p.A. used under license by Chrysler Group LLC.
 *********************************************************************************************/
package com.fca.uconnect.global;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtTheftAlarmNotify.TheftAlarmNotification;
import com.fca.uconnect.global.GlobalUconnectExtTheftAlarmNotify.TheftAlarmNotification.AlarmCause;
import com.fca.uconnect.global.GlobalUconnectExtTheftAlarmNotify.TheftAlarmNotification.AlarmStatusEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect TheftAlarmNotification message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForTheftAlarm {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private boolean receivedResponse = false; // flag to wait for the response as part of this example.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForTheftAlarm() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtTheftAlarmNotify.theftAlarmNotificationResponse);
		extRegistry.add(GlobalUconnectExtTheftAlarmNotify.theftAlarmNotification);
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for TheftAlarmNotification.
	 * @param alarmCause
	 * @param vehicleLocation
	 * @param alarmStatus
	 * @return
	 */
	public UconnectMessage getTheftAlarmNotifyMsg(AlarmCause alarmCause,Location vehicleLocation,AlarmStatusEnum alarmStatus){
						 
		this.messageId++;
		sessionId = ByteString.copyFrom(new byte[18]);
		TheftAlarmNotification theftAlarmMsg = TheftAlarmNotification.newBuilder()
				.setAlarmCause(alarmCause)
				.setAlarmStatusEnum(alarmStatus)
				.setVehicleLocation(vehicleLocation)
				.setTimeStamp(System.currentTimeMillis())
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtTheftAlarmNotify.theftAlarmNotification, theftAlarmMsg))
			.build();

		return msg;		
	}
	
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an TheftAlarmNotification message to the TANF topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/TANF/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {
						e.printStackTrace();
					}			
				}	
			};
			mqttClient.subscribe(iotTopic);
			AlarmCause alarmCause = AlarmCause.newBuilder()
					.setIsFLDoorBreached(true)
					.setIsVehiclePositionChanged(true)
					.build();
			Location vehicleLocation = Location.newBuilder()
					.setPositionLongitude(43.9999f)
					.setPositionLatitude(-84.54635343f)
					.build();
			
			UconnectMessage msg = getTheftAlarmNotifyMsg(alarmCause,vehicleLocation,AlarmStatusEnum.ACTIVE);
			sendMessage(msg);
			
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} 
	}
	/**
	 * This method publishes the message to TANF topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {						
			AWSIotMessage message = new 
					MessagePublisherListener("/TANF/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);

		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}
		
	/**
	 * Example main to launch example.
	 * 
	 */
	public static void main(String[] args) {
		TBMExampleForTheftAlarm example = new TBMExampleForTheftAlarm();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM):

       

package com.fca.uconnect.global;

import java.util.UUID;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPolicyPublish.DataSetSignal;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPublish;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPublish.DataSet;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPublish.DataSubscription;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPublish.SignalValue;
import com.google.protobuf.ExtensionRegistry;

public class ClientExampleForADA {
private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
private UUID sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.  
private boolean messageReceived = false; // flag to wait for the message as part of this example.
 

public ClientExampleForADA() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPolicyPublish);
	extRegistry.add(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPublish);
}

private void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/ADA/#",AWSIotQos.QOS0){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);								
	GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPolicyPublish vehicleDataAcquisitionPolicyPublishMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPolicyPublish);
	if (vehicleDataAcquisitionPolicyPublishMsg.getPolicySubscriptionList()!=null &&vehicleDataAcquisitionPolicyPublishMsg.getPolicySubscriptionList().size()>0) {
		while(true){
		 Thread.sleep(1000);//wait and send Vehicle Data
		 sendMessage(getVehicleDataPublishMsg());
		}
	}
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing ADA.");
	 
}
}
};

mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
	e.printStackTrace();
}

while(!messageReceived) {
 try {
        Thread.sleep(1000);
    } catch (InterruptedException e){
    }
 }

}
public UconnectMessage getVehicleDataPublishMsg() {
	messageId++;
	VehicleDataAcquisitionPublish.DataSet.Builder dataSetBuilder = VehicleDataAcquisitionPublish.DataSet.newBuilder();
	dataSetBuilder.setDataSetId(1);
	
	VehicleDataAcquisitionPublish.DataRow.Builder dataRowBuilder = VehicleDataAcquisitionPublish.DataRow.newBuilder();
	dataRowBuilder.setTimestamp(System.currentTimeMillis());
	

		SignalValue.Builder svb1 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				svb1.setStringValue("123456");	//VehicleId
				dataRowBuilder.addSignalValue(svb1);
		SignalValue.Builder svb2 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				svb2.setStringValue("4.0");	//SWRelease
				dataRowBuilder.addSignalValue(svb2);
		SignalValue.Builder svb3 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				svb3.setStringValue("12AESCXFSDSDS2344");//HU Serial nbr
				dataRowBuilder.addSignalValue(svb3);
				SignalValue.Builder svb4 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setDoubleValue(48.543434343434);//Latitude
				    dataRowBuilder.addSignalValue(svb4);
				    SignalValue.Builder svb5 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setDoubleValue(48.543434343434);//Longitude
				    dataRowBuilder.addSignalValue(svb5);
				    SignalValue.Builder svb6 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(4.434343434f);//HorizontalAccuracy
				    dataRowBuilder.addSignalValue(svb6);
				    SignalValue.Builder svb7 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(4.434343434f);//VerticalAccuracy
				    dataRowBuilder.addSignalValue(svb7);
				    SignalValue.Builder svb8 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(4.434343434f);//Course
				    dataRowBuilder.addSignalValue(svb8);
				    SignalValue.Builder svb9 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(4.434343434f);//Azimuth
				    dataRowBuilder.addSignalValue(svb9);
				    SignalValue.Builder svb10 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(65f);//Speed
				    dataRowBuilder.addSignalValue(svb10);
				    SignalValue.Builder svb11 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setInt64Value(System.currentTimeMillis());//Timestamp
				    dataRowBuilder.addSignalValue(svb11);
				    SignalValue.Builder svb12 = VehicleDataAcquisitionPublish.SignalValue.newBuilder();
				    svb4.setFloatValue(4.434343434f);//Altitude
				    dataRowBuilder.addSignalValue(svb12);
	dataSetBuilder.addDataRow(dataRowBuilder);
	DataSet ds = dataSetBuilder.build();
	
	VehicleDataAcquisitionPublish.DataSubscription.Builder dataSubBuilder = VehicleDataAcquisitionPublish.DataSubscription.newBuilder();
	UUID policyId = UUID.randomUUID();
	dataSubBuilder.setPolicySubscriptionIdLSB(policyId.getLeastSignificantBits());
	dataSubBuilder.setPolicySubscriptionIdMSB(policyId.getMostSignificantBits());
	dataSubBuilder.addDataSet(ds);
	VehicleDataAcquisitionPublish.Builder publishBuilder = VehicleDataAcquisitionPublish.newBuilder();
	publishBuilder.addDataSubscription(dataSubBuilder);
		
	UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
		
			.addMessages(UconnectAny.newBuilder().
			setExtension(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPublish, publishBuilder.build()))					
			.build();
	return msg;		
}

public void sendMessage(UconnectMessage msg) {
final byte[] msgOut = msg.toByteArray();
new Thread(new Runnable() {

    @Override
public void run() {
try {						
	mqttClient.publish(clientId+"/ADA/", AWSIotQos.QOS0, msgOut);
	
} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
				e.printStackTrace();
			}		    	
	    }
	    
	}).start();
}
public static void main(String[] args) {
	ServiceExampleForADA service = new ServiceExampleForADA();
	service.process();
}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for Vehicle Sync:

       
       
package com.fca.uconnect.global;
import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.Address;
import com.fca.uconnect.global.GlobalUconnectControl.Destination;
import com.fca.uconnect.global.GlobalUconnectControl.Destination.OriginalSource;
import com.fca.uconnect.global.GlobalUconnectControl.Destination.RoutePreference;
import com.fca.uconnect.global.GlobalUconnectControl.Location;
import com.fca.uconnect.global.GlobalUconnectControl.PointOfInterest;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.InfotainmentPreference;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.MusicFavourite;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.NavigationPreference;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.RadioPreset;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.RadioPreset.RadioStation;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.PersonalAccount.RadioPreset.RadioStation.StationType;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.VehSyncModel;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.VehicleConfigPublish;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.WifiSetting;
import com.fca.uconnect.global.GlobalUconnectExtVehSync.WifiSetting.EncryptionEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect VehSync message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForVehSync {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	List messages ;

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForVehSync() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtVehSync.vehicleConfigPublish);
		extRegistry.add(GlobalUconnectExtVehSync.vehicleConfigRequest);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for VehicleConfigPublish.
	 * 
	 */
	public UconnectMessage getVehConfigPubMsg() {
		this.messageId++;
		WifiSetting wifiSetting = WifiSetting.newBuilder()
				 .setEncryption(EncryptionEnum.WEP)
				 .setSsid("FCA")
				 .setPassword("FCAPWD")
				 .build();
		RadioStation radioStation = RadioStation.newBuilder()
				.setStationFrequency(91)
				.setStationName("Michigan Radio")
				.setStationType(StationType.FM)
				.build();
		RadioPreset radioPreset = RadioPreset.newBuilder()
				.addStations(radioStation)
				.build();
		MusicFavourite musicFavourite = MusicFavourite.newBuilder()
				.addBandNames("Green Day")
				.addSongNames("Wake Me Up When September")
				.addSongNames("Boulevard of Broken Dreams")
				.build();
		InfotainmentPreference infotainmentPreference = InfotainmentPreference.newBuilder()
				.setMusicFavorite(musicFavourite)
				.setRadioPreset(radioPreset)
				.build();
		Location destLocation = Location.newBuilder()
				.setPositionLatitude(42.480201)
				.setPositionLongitude(-83.671875F)
				.build();
				Address address = Address.newBuilder()
				.setHouseNumber("1000")
				.setStreetName("Chrystler Drive")
				.setCityName("Auburn Hills")
				.setProvinceName("Michigan")
				.setCountryName("USA")
				.build();
				Address poiAddress = Address.newBuilder()
				.setHouseNumber("2000")
				.setStreetName("abc drive")
				.setCityName("Auburn Hills")
				.setProvinceName("Michigan")
				.setCountryName("USA")
				.build();
				PointOfInterest poi  = PointOfInterest.newBuilder()
				.setCategory("Restaurant")
				.setDescription("favorite")
				.setName("ABCD Restaurant")
				.setId(123)
				.setPhoneNumber("123 456 7890")
				.setLocation(destLocation)
				.setUrl("www.abcrestaurant.com")
				.setAddress(poiAddress)
				.build();
				Destination dest = Destination.newBuilder()
				.setDestinationDescription("fav restaurant")
				.setRoutePreference(RoutePreference.Fast)
				.setOrignalSource(OriginalSource.SDP)
				.setCreateTimestamp(System.currentTimeMillis())
				.setLocation(destLocation)
				.setDestinationPoi(poi)
				.setDestinationAddress(address)
				.build();
		NavigationPreference navigationPreference = NavigationPreference.newBuilder()
				.addFavoriteLocations(dest)
				.build();
		
		PersonalAccount personalAccount = PersonalAccount.newBuilder()
				.setInfotainmentPreference(infotainmentPreference)
				.setNavigationPreference(navigationPreference)
				.build();
		VehSyncModel vehSyncModel = VehSyncModel.newBuilder()
				.setPersonalAccountData(personalAccount)
				.setWifiConfigSet(wifiSetting)
				.build();
		VehicleConfigPublish vehicleConfigPublish = VehicleConfigPublish.newBuilder()
				.setConfigSetVersion(1)
				.setIsChangesOnly(false)
				.setModelData(vehSyncModel)
				.build();
		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
					 setExtension(GlobalUconnectExtVehSync.vehicleConfigPublish,vehicleConfigPublish))
			.build();
		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Activation message to the UACT topic.
	 */
	public List process() {
		
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/VCSC/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					try{
					UconnectMessage msgIn;
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					
					if ( msgIn.getMessages(0).hasExtension(GlobalUconnectExtVehSync.vehicleConfigRequest)) {
						correlationId=msgIn.getMessageId();
						sendMessage(getVehConfigPubMsg());
						semaphore.unlock();// Releasing the lock 
					}
				
			} catch( Exception ex) {
				ex.printStackTrace();
				System.out.println("Err processing message: "+ex+", try parsing Vehicle Sync.");
			}
			}
			};
			mqttClient.subscribe(iotTopic);
			this.semaphore.lock();	// lock thread
			if(messages!=null)
				return messages;
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {	
			AWSIotMessage message = new 
					MessagePublisherListener("/VCSC/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);

		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			    
			}).start();
		}

	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForVehSync example = new TBMExampleForVehSync();
		example.process();
	}
}
      
      

Download Client Example Code here

       

package com.fca.uconnect.global;

import java.util.List;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessageAck;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessageAck.ResponseEnum;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessageDispositionPublish;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessageDispositionPublish.MessageDispositionEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect In Vehicle message Acknowledgement to the SDP .   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForVehMessaging {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
	List messages ;//This is for Junit Tests.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.

	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForVehMessaging() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtVehicleMessaging.vehicleMessagePublish);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for VehicleMessage Ack
	 * @param response
	 * @param vehMsgId
	 * @return
	 */
	public UconnectMessage getVehicleMessagingAckMsg(ResponseEnum response,ByteString vehMsgId) {
		this.messageId++;
		VehicleMessageAck ackMsg = VehicleMessageAck.newBuilder()
				.setStatus(response)
				.setVehicleMessageID(vehMsgId)
				.setMessageReceiptTimestamp(System.currentTimeMillis())
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtVehicleMessaging.vehicleMessageAck,ackMsg))
			.build();
		return msg;		
	}
	public UconnectMessage getVehicleMessagingDispPubMsg(long messageDisplayTimestamp,
			long messageHMIDispositionEventTimestamp,ByteString vehicleMessageID,MessageDispositionEnum dispEnum) {
		this.messageId++;
		VehicleMessageDispositionPublish vehDispPubMsg = VehicleMessageDispositionPublish.newBuilder()
				.setMessageDisplayTimestamp(messageDisplayTimestamp)
				.setMessageHMIDispositionEventTimestamp(messageHMIDispositionEventTimestamp)
				.setVehicleMessageID(vehicleMessageID)
				.setDisposition(dispEnum)
				.build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.setCorrelationId(correlationId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtVehicleMessaging.vehicleMessageDispositionPublish, vehDispPubMsg))
			.build();
		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Vehicle message Ack to the In Vehicle Message topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
			mqttClient.connect();						
			iotTopic = new AWSIotTopic(clientId+"/IVM/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtVehicleMessaging.vehicleMessagePublish)){
						semaphore.unlock();// Releasing the lock
						GlobalUconnectExtVehicleMessaging.VehicleMessagePublish msgToDisplay = msgIn.getMessages(0).getExtension(GlobalUconnectExtVehicleMessaging.vehicleMessagePublish);
						correlationId = msgIn.getMessageId();
						ByteString vehMsgId = ByteString.copyFrom(new byte[18]);//This is just an example
						sendMessage(getVehicleMessagingAckMsg(ResponseEnum.MESSAGE_STAGED_FOR_DISPLAY,vehMsgId));
						long dispTime = System.currentTimeMillis();
						
						try {
							Thread.sleep(10000);
						} catch (InterruptedException e) {
						}
						long dispositionTime = System.currentTimeMillis();
						sendMessage(getVehicleMessagingDispPubMsg(dispTime,
						dispositionTime,vehMsgId,MessageDispositionEnum.MESSAGE_DISPLAY_CANCELLED));
				}
			}};
			mqttClient.subscribe(iotTopic);
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		}  catch (Exception e) {
			e.printStackTrace();
		}
		try {
			this.semaphore.lock();// lock thread
		} catch (InterruptedException e) {
		}	
	}
	/**
	 * This method publishes the message to VehicleMessaging topic
	 */
	public void sendMessage(UconnectMessage msg) {
		final byte[] msgOut = msg.toByteArray();
		new Thread(new Runnable() {

		    @Override
		public void run() {
		try {						
			AWSIotMessage message = new 
					MessagePublisherListener("/IVM/"+clientId,AWSIotQos.QOS1,msgOut);
			mqttClient.publish(message);

		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
						e.printStackTrace();
					}		    	
			    }
			}).start();
		}

	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForVehMessaging example = new TBMExampleForVehMessaging();
		example.process();
	}
}
      
      

Download Client Example Code here

Client Example Code (HU/TBM) for WIFIHotSpot:

       

package com.fca.uconnect.global;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtWIFIHotSpot.DataPackageStatusRequest;
import com.fca.uconnect.global.GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect DataPackageStatus message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForWifiHotSpot {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library. 
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	private Semaphore semaphore;//The semaphore object is used to wait for a response.
	
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForWifiHotSpot() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse);
		this.semaphore = new Semaphore();
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the empty message for Wifi.
	 *
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getWifiReqMsg() {
		this.messageId++;
		DataPackageStatusRequest dataReq = DataPackageStatusRequest.newBuilder()
			.build();
    		
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusRequest, dataReq))
			.build();

		return msg;		
	}
	
	/**
	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an DataPackageStatus message to the WIFI topic.
	 */
	public void process() {
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		
		try {			
			mqttClient.connect();						
						
			iotTopic = new AWSIotTopic(clientId+"/WIFI/", AWSIotQos.QOS1) {
				public void onMessage(AWSIotMessage msg) {

					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse)) {
						DataPackageStatusResponse dataRespMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse);
						semaphore.unlock();// Releasing the lock as it received response
					}
				}	
			};
			mqttClient.subscribe(iotTopic);
			UconnectMessage msg = getWifiReqMsg();
			AWSIotMessage message = new 
					MessagePublisherListener("/WIFI/"+clientId,AWSIotQos.QOS1,msg.toByteArray());
			mqttClient.publish(message);
			this.semaphore.lock();	//Wait for response, lock thread
			
		} catch (AWSIotException ex) {
			System.out.println("Caught AWS Exception "+ex);
			ex.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForWifiHotSpot example = new TBMExampleForWifiHotSpot();
		example.process();
	}
}
      
      

Download Client Example Code here