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

Service Example Code (SDP) 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.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtAOTA.ApplicationUpdateNotification;
import com.fca.uconnect.global.GlobalUconnectExtAOTA.InitiateDiscrepancyCheck;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForAOTA {
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.  

public SDPExampleForAOTA() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtAOTA.discrepancyCheck);
	extRegistry.add(GlobalUconnectExtAOTA.updateStatusNotification);
}
//Disconnects MQTT 
public void disconnect(){
	try {
		mqttClient.disconnect();
	} catch (AWSIotException e) {
		e.printStackTrace();
	}
}
public UconnectMessage getInitiateDescMsg(){
	messageId++;
	InitiateDiscrepancyCheck descCheckmsg = InitiateDiscrepancyCheck.newBuilder()
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtAOTA.initiateDiscrepancyCheck, descCheckmsg))
			.build();

		return msg;		
}
public UconnectMessage getAppUpdateNotifyMsg(String appId,String description,long expireTime,
			int size,String version,String checkSum,String url) {
	messageId++;
	
	ApplicationUpdateNotification updateNotifyMsg = ApplicationUpdateNotification.newBuilder()
			.setAppId(appId)
			.setDescription(description)
			.setExpireDate(expireTime)
			.setPackageSize(size)
			.setChecksum(checkSum)
			.setVersion(version)
			.setUrl(url)
			.build();

	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtAOTA.applicationUpdateNotification, updateNotifyMsg))
		.build();

	return msg;		
}

public void process() {
	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/AOTA/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtAOTA.discrepancyCheck)){
		//Receive Discrepancy Check Message
		//send app update
		long expireTime = System.currentTimeMillis()+1000000;
		sendMessage(getAppUpdateNotifyMsg("APPID","DESCRPTION",expireTime,32,"VERSION","CHECKSUM","URL"));
    }
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing AOTA.");
}
}
};
mqttClient.subscribe(iotTopic);
sendMessage(getInitiateDescMsg());

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

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

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

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

Download Service Example Code here

Service Example Code (SDP) for Activation:

      
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;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtActivation.ActivationResponse;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningPush;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForActivation {
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 boolean termsAndConditions;// flag to check whether User agreed or not for Terms and Condition.  
private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.

public SDPExampleForActivation() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtActivation.activationRequest);
	extRegistry.add(GlobalUconnectExtActivation.activationResponse);
	extRegistry.add(GlobalUconnectExtProvision.provisioningPush);
}
public static void main(String[] args) {
	SDPExampleForActivation m = new SDPExampleForActivation();
	m.process();
}
public UconnectMessage getActivationRespMsg(int correlationId,boolean isFromException) {
	messageId++;

	GlobalUconnectExtActivation.ActivationResponse.ResponseEnum resp = null;
	  
	  if(termsAndConditions){
		   resp = GlobalUconnectExtActivation.ActivationResponse.ResponseEnum.ACTIVATED;
	  }else if(!isFromException){
		  resp = GlobalUconnectExtActivation.ActivationResponse.ResponseEnum.FAILURE;
	  }else{
		  resp = GlobalUconnectExtActivation.ActivationResponse.ResponseEnum.RETRY_ABLE_FAILURE;
	  }
	ActivationResponse aresp = ActivationResponse.newBuilder()
			.setResponseEnum(resp)
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtActivation.activationResponse, aresp))
		.build();

	return msg;		
}
public void disconnect(){
	try {
		mqttClient.disconnect();
	} catch (AWSIotException e) {
		e.printStackTrace();
	}
}
public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/UACT/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	
	GlobalUconnectExtActivation.ActivationRequest activationReqMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtActivation.activationRequest);
	if (activationReqMsg.getVehicleId()!=null && activationReqMsg.getVehicleId().trim().length()>0  
	  &&activationReqMsg.getEmailAddress()!=null &&
		activationReqMsg.getEmailAddress().trim().length()>0 && validateEmail(activationReqMsg.getEmailAddress())) {
		correlationId=msgIn.getMessageId();
		if(activationReqMsg.getTcIndicator().equals(GlobalUconnectExtActivation.ActivationRequest.TCIndicatorEnum.AGREE))
			termsAndConditions=true;
		else
			termsAndConditions=false;
		sendMessage(getActivationRespMsg(correlationId,false));
	}
		try {
			Thread.sleep(1000);//simulating a delay between the login response message and pushing an updated provisioning message to the vehicle.  The delay represents additional processing time to lookup the services for the use.
		} catch (InterruptedException e) {
		}
		sendMessage(getProvisionPushMsg( sessionId));
	
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing Activation.");
	 sendMessage(getActivationRespMsg(correlationId,true));
}
}
};

mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
	e.printStackTrace();
}
}
public boolean validateEmail(String emailAddress){
	// this needs to be implemented with the appropriate logic to meet the requirements documented in the SFS.
	return true;
}
public UconnectMessage getProvisionPushMsg(ByteString sessionId) {
	messageId++;
	ByteString drmFile = ByteString.copyFrom(new byte[18]);
	DRM drm = DRM.newBuilder()
			.setDrmFile(drmFile)
			.build();
		 ProvisioningPush provisioningPush = ProvisioningPush.newBuilder()
				 .setDrm(drm)
				 .build();
UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		setExtension(GlobalUconnectExtProvision.provisioningPush, provisioningPush))					
		.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+"/UACT/", AWSIotQos.QOS1, msgOut);
} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
				e.printStackTrace();
			}		    	
	    }
	    
	}).start();
}	
}
      
      

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

Download Service Example Code here

Service Example Code (SDP) 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.DRM;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtAuth.LoginResponse;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningPush;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForAuthorization {
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 int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
private boolean messageReceived = false; // flag to wait for the message as part of this example.
 

public SDPExampleForAuthorization() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtAuth.loginRequest);
	extRegistry.add(GlobalUconnectExtAuth.loginResponse);
	extRegistry.add(GlobalUconnectExtProvision.provisioningPush);
}

public UconnectMessage getLoginRespMsg(int correlationId,boolean loginSuccessful) {
	messageId++;

	GlobalUconnectExtAuth.LoginResponse.ResponseEnum resp = null;  
	if(loginSuccessful)
	resp = GlobalUconnectExtAuth.LoginResponse.ResponseEnum.SUCCESS;
	else
		resp = GlobalUconnectExtAuth.LoginResponse.ResponseEnum.NOT_AUTHORIZED;
	LoginResponse loginResp = LoginResponse.newBuilder()
			.setResponse(resp)
			.build();
	sessionId = ByteString.copyFrom(new byte[18]);
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setSessionId(sessionId)
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtAuth.loginResponse, loginResp))
		.build();

	return msg;		
}

public void process() {

mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/ULIO/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);								
	GlobalUconnectExtAuth.LoginRequest loginReqMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtAuth.loginRequest);
	if (loginReqMsg.getCredentials()!=null && loginReqMsg.getIdentifier().trim().length()>0) {
		correlationId=msgIn.getMessageId();
		sendMessage(getLoginRespMsg(correlationId,true));
		try {
			Thread.sleep(1000);//simulating a delay between the login response message and pushing an updated provisioning message to the vehicle.  The delay represents additional processing time to lookup the services for the use.
		} catch (InterruptedException e) {
		}
		sendMessage(getProvisionPushMsg( sessionId));
	}
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing Login/Logout.");
}
}
};

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 getProvisionPushMsg(ByteString sessionId) {
	messageId++;
	ByteString drmFile = ByteString.copyFrom(new byte[18]);
	DRM drm = DRM.newBuilder()
			.setDrmFile(drmFile)
			.build();
		 ProvisioningPush provisioningPush = ProvisioningPush.newBuilder()
				 .setDrm(drm)
				 .build();
 

UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		setExtension(GlobalUconnectExtProvision.provisioningPush, provisioningPush))					
		.build();
	return msg;		
}
public void disconnect(){
	try {
		mqttClient.disconnect();
	} catch (AWSIotException e) {
		e.printStackTrace();
	}
}
public void sendMessage(UconnectMessage msg) {
final byte[] msgOut = msg.toByteArray();
new Thread(new Runnable() {

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

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

Download Service Example Code here

Service Example Code (SDP) 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.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallCarDataRequest;
import com.fca.uconnect.global.GlobalUconnectExtECall.ECallStatusUpdate.ECallStatusEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForECall {
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 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 SDPExampleForECall() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtECall.ecallDataUpload);
	extRegistry.add(GlobalUconnectExtECall.ecallStatusUpdate);
	extRegistry.add(GlobalUconnectExtECall.ecallCarDataResponse);
	this.semaphore = new Semaphore();
}
public static void main(String[] args) {
	SDPExampleForECall m = new SDPExampleForECall();
	m.process();
}
public UconnectMessage getECallCarDataRequestMsg() {
	messageId++;

	ECallCarDataRequest carDataReq = ECallCarDataRequest.newBuilder()
			.build();
	sessionId = ByteString.copyFrom(new byte[18]);
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setSessionId(sessionId)
		
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtECall.ecallCarDataRequest, carDataReq))
		.build();

	return msg;		
}

public void process() {
	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
	
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/ECAL/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtECall.ecallDataUpload)){
	//receive Vehicle Data
	GlobalUconnectExtECall.ECallDataUpload ecallDataUploadMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtECall.ecallDataUpload);
	}else{
	//Wait for Call
	GlobalUconnectExtECall.ECallStatusUpdate ecallStatusUpdateMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtECall.ecallStatusUpdate);
	if(!ecallStatusUpdateMsg.getEcallStatusEnum().equals(ECallStatusEnum.CANCEL)){//User did not cancel call
		//if needed query for Vehicle data continuously
	 int counter = 0;
	 while(counter<5){
		sendMessage(getECallCarDataRequestMsg());
		try {
			Thread.sleep(1000);//wait and Request vehicle data
		} catch (InterruptedException e) {
		}
		counter++;
	 }
    }
	semaphore.unlock();// Releasing the lock 
   }
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing ECALL.");
	 
}
}
};
mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
	e.printStackTrace();
}
try {
	this.semaphore.lock();
} catch (InterruptedException e) {

}
}

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

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

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

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

Download Service Example Code here

Service Example Code (SDP) for FOTA:

      
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.GlobalUconnectExtFOTA.FirmwareUpdateNotification;
import com.fca.uconnect.global.GlobalUconnectExtFOTA.FirmwareUpdateNotification.FirmwareDescriptor;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForFOTA {
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;

public SDPExampleForFOTA() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtFOTA.firmwareUpdateResponse);
}
//Disconnects MQTT 
public void disconnect(){
	try {
		mqttClient.disconnect();
	} catch (AWSIotException e) {
		e.printStackTrace();
	}
}

public UconnectMessage getFirmwareNotifyMsg(String taskId,List firmwareDescriptors) {
	messageId++;
	
	FirmwareUpdateNotification updateNotifyMsg = FirmwareUpdateNotification.newBuilder()
			.setFotaTaskId(taskId)
			.addAllFirmwareDescriptor(firmwareDescriptors)
			.build();

	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtFOTA.firmwareUpdateNotification, updateNotifyMsg))
		.build();

	return msg;		
}
public List getFOTADataMsg(){
	while(messages.isEmpty()){
		try {
			Thread.currentThread().sleep(3000);
		} catch (InterruptedException e) {
		}
	}
	return messages;
}
public void process() {
	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/FOTA/#",AWSIotQos.QOS0){
	public void onMessage(AWSIotMessage msg) {
try {
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtFOTA.firmwareUpdateResponse)){
		//Receive Firmware update response
    }
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing FOTA.");
}
}
};
mqttClient.subscribe(iotTopic);
FirmwareDescriptor firmwareDescriptor = FirmwareDescriptor.newBuilder()
.setChecksum("CE114E4501D2F4E2DCEA3E17B546F339")
.setDescription("Update for ABC")
.setEcuAddress(956488)
.setExpireDate(456899)
.setPackageSize(10000)
.setFirmwareVersion("2.0")
.setUrl("https://abc.com")
.build();
List descriptors = new ArrayList<>();
descriptors.add(firmwareDescriptor);
sendMessage(getFirmwareNotifyMsg("AXCSEA1234",descriptors));
} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
	e.printStackTrace();
}
}

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

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

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

Download Service Example Code here

Service Example Code (SDP) for PC:

      
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.GlobalUconnectExtPC.PCUpdateConfigRequest;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCUpdateConfigRequest.ConfigTypeVehicle;
import com.fca.uconnect.global.GlobalUconnectExtPC.PCUpdateConfigRequest.ConfigTypeVehicle.SpeedAlertConfig;
import com.fca.uconnect.global.util.MessageUtil;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForPC {
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;


public SDPExampleForPC() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtPC.pcUpdateConfigResponse);
}
public UconnectMessage getPCConfigReqMsg() {
	messageId++;
	List activeDays = new ArrayList();
	activeDays.add(1);
	activeDays.add(2);
	SpeedAlertConfig speedAlertMsg =SpeedAlertConfig.newBuilder()
			.setBeginTime(1000)
			.setEndTime(10000)
			.setThresholdAbovePostedSpeed(60)
			.setThresholdAbsolute(70)
			.setThresholdPostedSpeedAbsent(80)
			.addAllActiveDaysOfWeek(activeDays)
			.build();
	ConfigTypeVehicle configTypeVehicle = ConfigTypeVehicle.newBuilder()
			.setUpdateSpeedAlertConfig(true)
			.addSpeedAlerts(speedAlertMsg)
			.build();
	PCUpdateConfigRequest pcUpdateConfigReq = PCUpdateConfigRequest.newBuilder()
			.setConfigTypeVehicle(configTypeVehicle)
			.build();
	
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtPC.pcUpdateConfigRequest,pcUpdateConfigReq ))
		.build();

	return msg;		
}
/**
 * This method demonstrates connecting to the AWS IoT mqtt broker and Subscribing  an Parental Control message to the PC topic.
 */
public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/PC/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtPC.pcUpdateConfigResponse)){
		GlobalUconnectExtPC.PCUpdateConfigResponse pcConfigResp = msgIn.getMessages(0).getExtension(GlobalUconnectExtPC.pcUpdateConfigResponse);
		if(messages==null)
			messages = new ArrayList();
		messages.add(msgIn.getMessages(0));
	}
} catch( Exception ex) {
	ex.printStackTrace();
}
}
};
sendMessage(getPCConfigReqMsg());
mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught 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(clientId+"/PC/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here

Here's an example of how Service Connects to AWS IOT MQTT for Provisioning topics and process Provisioning Request and send Provision Push.

Service Example Code (SDP):

      
  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.DRM;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningPush;
import com.fca.uconnect.global.GlobalUconnectExtProvision.ProvisioningResponse;
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;

public class SDPExampleForProvisioning {
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 int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.

public SDPExampleForProvisioning() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtProvision.provisioningRequest);
	extRegistry.add(GlobalUconnectExtProvision.provisioningResponse);
	extRegistry.add(GlobalUconnectExtProvision.provisioningPush);
}

public UconnectMessage getProvisioningRespMsg(int correlationId) {
	messageId++;

	GlobalUconnectExtProvision.ProvisioningResponse.ResponseEnum resp = 
			GlobalUconnectExtProvision.ProvisioningResponse.ResponseEnum.SUCCESS;	
	ProvisioningResponse presp = ProvisioningResponse.newBuilder()
			.setResponseEnum(resp)
			.build();
	sessionId = ByteString.copyFrom(new byte[18]);
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setSessionId(sessionId)
		
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtProvision.provisioningResponse, presp))
		.build();

	return msg;		
}

public void process() {

mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/PRVI/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);								
	GlobalUconnectExtProvision.ProvisioningRequest provisioningReqMsg = 
			msgIn.getMessages(0).getExtension(GlobalUconnectExtProvision.provisioningRequest);
	if (provisioningReqMsg.getVehicleId()!=null 
			&& provisioningReqMsg.getVehicleId().trim().length()>0) {
		correlationId=msgIn.getMessageId();
		sendMessage(getProvisioningRespMsg(correlationId));
		try {
			Thread.sleep(1000);//wait and send provisionpush
		} catch (InterruptedException e) {
		}
		sendMessage(getProvisionPushMsg( sessionId));
	}
	
} 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();
}

}
public UconnectMessage getProvisionPushMsg(ByteString sessionId) {
	messageId++;
	ByteString drmFile = ByteString.copyFrom(new byte[18]);
DRM drm = DRM.newBuilder()
	.setDrmFile(drmFile)
	.build();
 ProvisioningPush provisioningPush = ProvisioningPush.newBuilder()
		 .setDrm(drm)
		 .build();
 

UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		setExtension(GlobalUconnectExtProvision.provisioningPush, provisioningPush))					
		.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(clientId+"/PRVI/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here

Service Example Code (SDP) for Remote Operation:

      
package com.fca.uconnect.global;

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.GlobalUconnectExtRemoteOp.RemoteDoorRequest;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteDoorRequest.CommandEnum;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest.ActionEnum;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationResponse;
import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

public class SDPExampleForRemoteOp {
	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 AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	public SDPExampleForRemoteOp() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationResponse);
		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationSubscribeResponse);
		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationStatus);
	}
	public void process() {

		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
 		if (mqttClient == null) {
 			System.out.println("Error init mqtt client.");
 			System.exit(0);
 		}
		try {			
			mqttClient.connect();						
			iotTopic = new AWSIotTopic("/RO/#",AWSIotQos.QOS1){
				public void onMessage(AWSIotMessage msg) {
					UconnectMessage msgIn = null;
					try {
						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
					} catch (InvalidProtocolBufferException e) {					
					}
					//  sync response
				 	//Acknowledging Remote OperationRequest
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse)) {							
						RemoteOperationResponse roAckMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse);
			
					// async status response after SUBSCRIBE Remote operation request
					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus)) {							
						RemoteOperationStatus roStatusmsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus);
					}	
				}	
			}};
			mqttClient.subscribe(iotTopic);
		} catch (AWSIotException e) {
			System.out.println("Caught Exception "+e);
			e.printStackTrace();
		}
		try {
			sendMessage(getRemoteDoorsMsg(ActionEnum.SUBSCRIBE, CommandEnum.UNLOCK_DRIVER, 0));
		} catch (AWSIotException e) {
			e.printStackTrace();
		}
	}
public UconnectMessage getRemoteDoorsMsg( RemoteOperationRequest.ActionEnum action, RemoteDoorRequest.CommandEnum command, int delay) {
	messageId++;
	RemoteOperationRequest ro = RemoteOperationRequest.newBuilder()
			.setAction(action)
			.setRemoteDoorRequest(
			 RemoteDoorRequest.newBuilder()
			 .setCommand(command)
			 .setDelay(delay))
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest,ro))
			.build();
	return msg;		
}

	private void sendMessage(Object msgIn) throws AWSIotException {
		UconnectMessage msg = (UconnectMessage)msgIn;
		final byte[] msgOut =  msg.toByteArray(); 
			new Thread(new Runnable() {
			    @Override
			public void run() {
			try {						
				AWSIotMessage message = new 
						MessagePublisherListener(clientId+"/RO/",AWSIotQos.QOS1,msgOut);
				mqttClient.publish(message);

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

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

Download Service Example Code here

Service Example Code (SDP) for RoadSideAssist:

      
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;

public class SDPExampleForRSA {
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.


public SDPExampleForRSA() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtRoadSideAssist.rsaDataUpload);
}
public static void main(String[] args) {
	SDPExampleForRSA m = new SDPExampleForRSA();
	m.process();
}
/**
 * This method demonstrates connecting to the AWS IoT mqtt broker and Subscribing  an RSADataUpload message to the RSA topic.
 */
public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/RSA/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	
	GlobalUconnectExtRoadSideAssist.RSADataUpload rsaDataMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtRoadSideAssist.rsaDataUpload);
	//Receive Car data for RoadSide Assistance.
	
} catch( Exception ex) {
	ex.printStackTrace();
}
}
};

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

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

Download Service Example Code here

Service Example Code (SDP) for SQDF:

      
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.GlobalUconnectExtSQDF.SQDFRequest;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFRequest.PolicySubscriptionScope;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFRequest.SQDFCommand;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForSQDF {
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.
 

public SDPExampleForSQDF() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtSQDF.sqdfResponse);
	
}
public static void main(String[] args) {
	SDPExampleForSQDF m = new SDPExampleForSQDF();
	m.process();
}
public UconnectMessage getSQDFRequestMsg() {
	messageId++;

	SQDFRequest sreq = SQDFRequest.newBuilder()
			.setCommand(SQDFCommand.SendData)
			.setPolicySubscriptionScope(PolicySubscriptionScope.GenericData)
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtSQDF.sqdfRequest, sreq))
		.build();
	return msg;		
}

public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/SQDF/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	GlobalUconnectExtSQDF.SQDFResponse SQDFRespMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtSQDF.sqdfResponse);
	if (SQDFRespMsg!=null) {
		//receive sqdfresponse.
		
	}
} catch( Exception ex) {
	ex.printStackTrace();
}
}
};

mqttClient.subscribe(iotTopic);
sendMessage(getSQDFRequestMsg());
} catch (AWSIotException e) {
	System.out.println("Caught Exception "+e);
	e.printStackTrace();
}

}


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

new Thread(new Runnable() {

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

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

Download Service Example Code here

Example Code (SDP):

      
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.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.GlobalUconnectExtSendAndGo.DestinationPush;
import com.fca.uconnect.global.GlobalUconnectExtSendAndGo.DestinationPush.MapDataBaseVariant;
import com.fca.uconnect.global.GlobalUconnectExtSendAndGo.DestinationPush.MapDataBaseVariant.NavTypeEnum;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForSendDesttoCar {
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=10; // 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.


public SDPExampleForSendDesttoCar() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtSendAndGo.destinationPush);
}
/**
 * This method generates a Protocol Buffer Uconnect Message given the required inputs for DestinationPush.
 * @param mapDBVariant
 * @param dest
 * @param isImmediateNavigation
 * @return
 */
public UconnectMessage getDestinationPushMsg(MapDataBaseVariant mapDBVariant,Destination dest,boolean isImmediateNavigation) {
	this.messageId++;
	sessionId = ByteString.copyFrom(new byte[18]);
	
	DestinationPush destPushMsg = DestinationPush.newBuilder()
			.setIsImmediateNavigation(false)
			.setMapDataBaseVariant(mapDBVariant)
			.addDestinationList(dest)
			.build();
		
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setSessionId(sessionId)
		
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtSendAndGo.destinationPush,destPushMsg))
		.build();
	return msg;		
}

/**
 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an SendDestinationToCar messages to the SDTC topic.
 */
public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/SDTC/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
}
};
mqttClient.subscribe(iotTopic);
MapDataBaseVariant mapDBVariant =MapDataBaseVariant.newBuilder()
.setNavTypeEnum(NavTypeEnum.AUTO)
.setVersion("1.0")
.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();
sendMessage(getDestinationPushMsg(mapDBVariant,dest,true));
} catch (AWSIotException e) {
	System.out.println("Caught 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(clientId+"/SDTC/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

public static void main(String[] args) {
	SDPExampleForSendDesttoCar m = new SDPExampleForSendDesttoCar();
	m.process();
}
}
      
      

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

Download Service Example Code here

Example Code (SDP):

      
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.GlobalUconnectExtStolenVehAssist.StolenModeChangeRequest;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenModeChangeRequest.StolenModeCommand;
import com.fca.uconnect.global.GlobalUconnectExtStolenVehAssist.StolenVehicleControlRequest;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForStolenVehAssist {
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=10; // 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 stolenVehicleControlmessageId;// This is to store message Id that sent with stolenVehicleControlRequest.
private boolean vehControlReqSent=false;//This is to check whether SDP received Vehicle Notification.

public SDPExampleForStolenVehAssist() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenModeChangeRequest);
	extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenModeChangeResponse);
	extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleInfoNotification);
	extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleControlResponse);
	extRegistry.add(GlobalUconnectExtStolenVehAssist.stolenVehicleControlRequest);
}

public UconnectMessage getStolenVehicleControlReqMsg(boolean isIgnoreAccelerate,boolean isBlockIgnition){
	messageId++;
	stolenVehicleControlmessageId =messageId;
	StolenVehicleControlRequest sControlReqMsg = StolenVehicleControlRequest.newBuilder()
			.setIsIgnoreAccelerate(true)
			.setIsBlockIgnition(true)
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		
		
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtStolenVehAssist.stolenVehicleControlRequest,sControlReqMsg))
		.build();
	return msg;
	
}
public UconnectMessage getStolenModeChgReqMsg(boolean isActiveWhenKeyOff,int locationUpdateInterval,
		StolenModeCommand stolenModeCommand,int stolenModeDuration) {
	messageId++;
	StolenModeChangeRequest sreq = StolenModeChangeRequest.newBuilder()
			.setIsActiveWhenKeyOff(isActiveWhenKeyOff)
			.setLocationUpdateInterval(locationUpdateInterval)
			.setStolenModeCommand(stolenModeCommand)
			.setStolenModeDuration(stolenModeDuration)
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		
		
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtStolenVehAssist.stolenModeChangeRequest,sreq))
		.build();

	return msg;		
}

public void process() {
	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/SVAS/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	int msgId = msgIn.getMessageId();
		if(msgIn.getMessages(0).hasExtension(
		  GlobalUconnectExtStolenVehAssist.stolenVehicleInfoNotification)){
		//Receive Vehicle Information from TBM		
			
		if(!vehControlReqSent){
			vehControlReqSent=true;
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
			}
			sendMessage(getStolenVehicleControlReqMsg(true,true));//send Stolen Vehicle control Request	
		}
	}else if (msgIn.getMessages(0).hasExtension(
			GlobalUconnectExtStolenVehAssist.stolenModeChangeResponse) && 
			msgIn.getCorrelationId() ==messageId){
		//receive response from TBM
	}else if (msgIn.getMessages(0).hasExtension(
			GlobalUconnectExtStolenVehAssist.stolenVehicleControlResponse) && 
			msgIn.getCorrelationId()==stolenVehicleControlmessageId){
		//Receive Stolen VehicleControl Response
	}
		
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing Stolen Vehicle Assistance.");
	
}
}
};

sendMessage(getStolenModeChgReqMsg(false, 100000, StolenModeCommand.ENTER, 1000000));
mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught 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(clientId+"/SVAS/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here

Service Example Code (SDP):

      
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;

public class SDPExampleForTheftAlarm {
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.


public SDPExampleForTheftAlarm() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtTheftAlarmNotify.theftAlarmNotification);
	this.semaphore = new Semaphore();
}

public void process() {
mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
	
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/TANF/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtTheftAlarmNotify.theftAlarmNotification)){
		semaphore.unlock();
     }
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing Theft Alarm Notification.");
}
}
};
mqttClient.subscribe(iotTopic);

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

try {
	this.semaphore.lock();// lock thread
} catch (InterruptedException e) {
	
}	
}

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

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

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

Download Service Example Code here

Service Example Code (SDP):

      
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;
import com.fca.uconnect.global.GlobalUconnectExtVehDataAcquisition.VehicleDataAcquisitionPolicyPublish.PolicySubscription;
import com.google.protobuf.ExtensionRegistry;

public class ServiceExampleForADA {
	public ServiceExampleForADA() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPolicyPublish);
	}

	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.  	
	
	 

	public void process(){
		
		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
		try {			
		mqttClient.connect();						
		 iotTopic = new AWSIotTopic("/ADA/#",AWSIotQos.QOS0){
			public void onMessage(AWSIotMessage msg) {
		try {
				sendMessage(getADAPolicyMsg());
		} 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();
		}
	}
	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 UconnectMessage getADAPolicyMsg() {
		messageId++;
		UUID policySubId = UUID.randomUUID();
		PolicySubscription policySub = PolicySubscription.newBuilder()
				.setExpirationDate(policySubId.getLeastSignificantBits())
				.setPolicySubscriptionIdLSB(policySubId.getMostSignificantBits())
				.build();
		VehicleDataAcquisitionPolicyPublish vehiclePolicy = VehicleDataAcquisitionPolicyPublish.newBuilder()
				.setPolicySubscription(0, policySub).build();
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtVehDataAcquisition.vehicleDataAcquisitionPolicyPublish, vehiclePolicy))
			.build();

		return msg;		
	}

	public static void main(String[] args){
		ServiceExampleForADA serviceExampleForADA = new ServiceExampleForADA();
		serviceExampleForADA.process();
	}

}


      
      

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

Download Service Example Code here

Service Example Code (SDP):

      
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.GlobalUconnectExtVehSync.VehicleConfigRequest;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForVehSync {
private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
private int messageId=10; // 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.

public SDPExampleForVehSync() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtVehSync.vehicleConfigPublish);
	extRegistry.add(GlobalUconnectExtVehSync.vehicleConfigRequest);
}

public UconnectMessage getVehicleConfigReqMsg() {
	messageId++;
	VehicleConfigRequest vehReqMsg = VehicleConfigRequest.newBuilder()
			.setConfigSetVersion(1)
			.build();
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		
		
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtVehSync.vehicleConfigRequest, vehReqMsg))
		.build();

	return msg;		
}

public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/VCSC/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	if (correlationId==msgIn.getMessageId() &&msgIn.getMessages(0).hasExtension(GlobalUconnectExtVehSync.vehicleConfigPublish) ) {
		GlobalUconnectExtVehSync.VehicleConfigPublish vehPubMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtVehSync.vehicleConfigPublish);
	// Receive Vehicle Config
	}
	
} catch( Exception ex) {
	ex.printStackTrace();
	System.out.println("Err processing message: "+ex+", try parsing Vehicle Sync.");
}
}
};

mqttClient.subscribe(iotTopic);
sendMessage(getVehicleConfigReqMsg());
} catch (AWSIotException e) {
	System.out.println("Caught 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(clientId+"/VCSC/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here

Service Example Code (SDP):

      
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.GlobalUconnectExtVehicleMessaging.VehicleMessagePublish;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessagePublish.LanguageString;
import com.fca.uconnect.global.GlobalUconnectExtVehicleMessaging.VehicleMessagePublish.MessageType;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForVehMessaging {
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;//This is for Junit Tests.


public SDPExampleForVehMessaging() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtVehicleMessaging.vehicleMessageAck);
	extRegistry.add(GlobalUconnectExtVehicleMessaging.vehicleMessageDispositionPublish);
}
public UconnectMessage getVehicleMessagingPubMsg(String vin,MessageType messageType,LanguageString lang) {
	messageId++;
	VehicleMessagePublish pubMsg = VehicleMessagePublish.newBuilder()
			.setVin(vin)
			.setMessageType(messageType)
			.addMessage(lang)
			.build();
	
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setMessageId(messageId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtVehicleMessaging.vehicleMessagePublish,pubMsg))
		.build();

	return msg;		
}

/**
 * This method demonstrates connecting to the AWS IoT mqtt broker and Subscribing  an Parental Control message to the VehicleMessaging topic.
 */
public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/IVM/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);			
	if(msgIn.getMessages(0).hasExtension(GlobalUconnectExtVehicleMessaging.vehicleMessageAck)){
		GlobalUconnectExtVehicleMessaging.VehicleMessageAck acknowledgement= msgIn.getMessages(0).getExtension(GlobalUconnectExtVehicleMessaging.vehicleMessageAck);
		if(messages==null)
			messages = new ArrayList();
		messages.add(msgIn.getMessages(0));
	}
} catch( Exception ex) {
	ex.printStackTrace();
}
}
};
LanguageString lang = LanguageString.newBuilder()
.setLanguage("ENGLISH")
.setMessageText("Your Vehicle is Due for Service")
.build();

sendMessage(getVehicleMessagingPubMsg("1HGCM82633A004352",MessageType.SERVICE_NOTICE,lang));
mqttClient.subscribe(iotTopic);

} catch (AWSIotException e) {
	System.out.println("Caught 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(clientId+"/IVM/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here

Service Example Code (SDP):

      
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.DataPackageStatusResponse;
import com.fca.uconnect.global.GlobalUconnectExtWIFIHotSpot.WifiPackageDataStatus;
import com.google.protobuf.ByteString;
import com.google.protobuf.ExtensionRegistry;

public class SDPExampleForWifiHotSpot {
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 int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
private boolean messageReceived = false; // flag to wait for the message as part of this example. 

public SDPExampleForWifiHotSpot() {
	extRegistry = ExtensionRegistry.newInstance();
	extRegistry.add(GlobalUconnectExtWIFIHotSpot.dataPackageStatusRequest);
	extRegistry.add(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse);
	extRegistry.add(GlobalUconnectExtWIFIHotSpot.wifiPackageDataStatus);
}

public UconnectMessage getWifiRespMsg(int correlationId,boolean isFromException) {
	messageId++;

	GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum resp = null;
	  if(isFromException)
		   resp = GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum.FAILURE;
	  else
		   resp = GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum.SUCCESS;
		   WifiPackageDataStatus wifiPackageDataStatus = WifiPackageDataStatus.newBuilder()
				   .setIsLowAlertFlag(false)
				   .setTotalVolume(1000000) //this is in KB
				   .setUsedVolume(500000)
				   .setUsedTiming(20)   //days
				   .setTotalTiming(30)
				   .build();
	DataPackageStatusResponse dataPackageStatusResponse = DataPackageStatusResponse.newBuilder()
			.setResponseEnum(resp)
			.setPackageStatus(wifiPackageDataStatus)
			.build();
	
	UconnectMessage msg = UconnectMessage.newBuilder()
		.setTimestamp(System.currentTimeMillis())
		.setSessionId(sessionId)
		
		.setMessageId(messageId)
		.setCorrelationId(correlationId)
		.addMessages(UconnectAny.newBuilder().
		 setExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse, dataPackageStatusResponse))
		.build();

	return msg;		
}

public void process() {

	mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");

try {			
mqttClient.connect();						
 iotTopic = new AWSIotTopic("/WIFI/#",AWSIotQos.QOS1){
	public void onMessage(AWSIotMessage msg) {
try {
	
	UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);								
	GlobalUconnectExtWIFIHotSpot.DataPackageStatusRequest wifiReqMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusRequest);
		correlationId=msgIn.getMessageId();
		sendMessage(getWifiRespMsg(correlationId,false));
  	
		try {
			Thread.sleep(1000);//wait and send WifiDataPush
		} catch (InterruptedException e) {
		}
		sendMessage(getWifiLowAlertPushMsg(sessionId));
	
	
} catch( Exception ex) {
	System.out.println("Err processing message: "+ex+", try parsing Activation.");
	 sendMessage(getWifiRespMsg(correlationId,true));
}
}
};

mqttClient.subscribe(iotTopic);

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


}
public UconnectMessage getWifiLowAlertPushMsg(ByteString sessionId) {
	messageId++;
	
	WifiPackageDataStatus packagStatus = WifiPackageDataStatus.newBuilder()
			   .setIsLowAlertFlag(true)
			   .setTotalVolume(1000000) //this is in KB
			   .setUsedVolume(900000)
			   .setUsedTiming(20)
			   .setTotalTiming(30)
			   .build();
	  
		
		UconnectMessage msg = UconnectMessage.newBuilder()
				.setTimestamp(System.currentTimeMillis())
				.setMessageId(messageId)
				.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtWIFIHotSpot.wifiPackageDataStatus, packagStatus))
				.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(clientId+"/WIFI/",AWSIotQos.QOS1,msgOut);
	mqttClient.publish(message);

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

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

Download Service Example Code here