/**********************************************************************************************
* 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.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();
}
}
Here's an example of how SDP Connects to AWS IOT MQTT for PC topics.
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.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 Client Example Code here
Download Service Example Code here