AWS IoT FleetWise 使用 Kotlin 开发工具包的示例 - AWS SDK 代码示例

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS IoT FleetWise 使用 Kotlin 开发工具包的示例

以下代码示例向您展示了如何使用适用于 Kotlin 的 AWS SDK 来执行操作和实现常见场景。 AWS IoT FleetWise

基础知识是向您展示如何在服务中执行基本操作的代码示例。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

开始使用

以下代码示例展示了如何开始使用 AWS IoT FleetWise。

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** Before running this Kotlin code example, set up your development environment, including your credentials. For more information, see the following documentation topic: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html */ suspend fun main() { listSignalCatalogs() } /** * Lists the AWS FleetWise Signal Catalogs associated with the current AWS account. */ suspend fun listSignalCatalogs() { val request = ListSignalCatalogsRequest { maxResults = 10 } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.listSignalCatalogs(request) val summaries = response.summaries if (summaries.isNullOrEmpty()) { println("No AWS FleetWise Signal Catalogs were found.") } else { summaries.forEach { summary -> with(summary) { println("Catalog Name: $name") println("ARN: $arn") println("Created: $creationTime") println("Last Modified: $lastModificationTime") println("---------------") } } } } }

基本功能

以下代码示例展示了如何:

  • 创建标准化信号的集合。

  • 创建代表一组车辆的车队。

  • 创建模型清单。

  • 创建解码器清单。

  • 检查模型清单的状态。

  • 检查解码器的状态。

  • 创建物联网事物。

  • 创建一辆车。

  • 显示车辆详情。

  • 删除资 AWS IoT FleetWise 产。

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

运行演示 AWS IoT SiteWise 功能的交互式场景。

/** Before running this Kotlin code example, set up your development environment, including your credentials. For more information, see the following documentation topic: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html */ var scanner = Scanner(System.`in`) val DASHES = String(CharArray(80)).replace("\u0000", "-") suspend fun main(args: Array<String>) { val usage = """ Usage: <signalCatalogName> <manifestName> <fleetId> <vecName> <decName> Where: signalCatalogName - The name of the Signal Catalog to create (eg, catalog30). manifestName - The name of the Vehicle Model (Model Manifest) to create (eg, manifest30). fleetId - The ID of the Fleet to create (eg, fleet30). vecName - The name of the Vehicle to create (eg, vehicle30). decName - The name of the Decoder Manifest to create (eg, decManifest30). """.trimIndent() if (args.size != 5) { println(usage) return } val signalCatalogName = args[0] val manifestName = args[1] val fleetId = args[2] val vecName = args[3] val decName = args[4] println( """ AWS IoT FleetWise is a managed service that simplifies the process of collecting, organizing, and transmitting vehicle data to the cloud in near real-time. Designed for automakers and fleet operators, it allows you to define vehicle models, specify the exact data you want to collect (such as engine temperature, speed, or battery status), and send this data to AWS for analysis. By using intelligent data collection techniques, IoT FleetWise reduces the volume of data transmitted by filtering and transforming it at the edge, helping to minimize bandwidth usage and costs. At its core, AWS IoT FleetWise helps organizations build scalable systems for vehicle data management and analytics, supporting a wide variety of vehicles and sensor configurations. You can define signal catalogs and decoder manifests that describe how raw CAN bus signals are translated into readable data, making the platform highly flexible and extensible. This allows manufacturers to optimize vehicle performance, improve safety, and reduce maintenance costs by gaining real-time visibility into fleet operations. """.trimIndent(), ) waitForInputToContinue(scanner) println(DASHES) runScenario(signalCatalogName, fleetId, manifestName, decName, vecName) } suspend fun runScenario(signalCatalogName: String, fleetIdVal: String, manifestName: String, decName: String, vecName: String) { println(DASHES) println("1. Creates a collection of standardized signals that can be reused to create vehicle models") waitForInputToContinue(scanner) val signalCatalogArn = createbranchVehicle(signalCatalogName) println("The collection ARN is $signalCatalogArn") waitForInputToContinue(scanner) println(DASHES) println(DASHES) println("2. Create a fleet that represents a group of vehicles") println( """ Creating an IoT FleetWise fleet allows you to efficiently collect, organize, and transfer vehicle data to the cloud, enabling real-time insights into vehicle performance and health. It helps reduce data costs by allowing you to filter and prioritize only the most relevant vehicle signals, supporting advanced analytics and predictive maintenance use cases. """.trimIndent(), ) waitForInputToContinue(scanner) val fleetid = createFleet(signalCatalogArn, fleetIdVal) println("The fleet Id is $fleetid") waitForInputToContinue(scanner) val nodeList = listSignalCatalogNode(signalCatalogName) println(DASHES) println(DASHES) println("3. Create a model manifest") println( """ An AWS IoT FleetWise manifest defines the structure and relationships of vehicle data. The model manifest specifies which signals to collect and how they relate to vehicle systems, while the decoder manifest defines how to decode raw vehicle data into meaningful signals. """.trimIndent(), ) waitForInputToContinue(scanner) val nodes = listSignalCatalogNode(signalCatalogName) val manifestArn = nodes?.let { createModelManifest(manifestName, signalCatalogArn, it) } println("The manifest ARN is $manifestArn") println(DASHES) println(DASHES) println("4. Create a decoder manifest") println( """ A decoder manifest in AWS IoT FleetWise defines how raw vehicle data (such as CAN signals) should be interpreted and decoded into meaningful signals. It acts as a translation layer that maps vehicle-specific protocols to standardized data formats using decoding rules. This is crucial for extracting usable data from different vehicle models, even when their data formats vary. """.trimIndent(), ) waitForInputToContinue(scanner) val decArn = createDecoderManifest(decName, manifestArn) println("The decoder manifest ARN is $decArn") waitForInputToContinue(scanner) println(DASHES) println(DASHES) println("5. Check the status of the model manifest") println( """ The model manifest must be in an ACTIVE state before it can be used to create or update a vehicle. """.trimIndent(), ) waitForInputToContinue(scanner) updateModelManifest(manifestName) waitForModelManifestActive(manifestName) waitForInputToContinue(scanner) println(DASHES) println(DASHES) println("6. Check the status of the decoder") println( """ The decoder manifest must be in an ACTIVE state before it can be used to create or update a vehicle. """.trimIndent(), ) waitForInputToContinue(scanner) updateDecoderManifest(decName) waitForDecoderManifestActive(decName) waitForInputToContinue(scanner) println(DASHES) println(DASHES) println("7. Create an IoT Thing") println( """ AWS IoT FleetWise expects an existing AWS IoT Thing with the same name as the vehicle name you are passing to createVehicle method. Before calling createVehicle(), you must create an AWS IoT Thing with the same name using the AWS IoT Core service. """.trimIndent(), ) waitForInputToContinue(scanner) createThingIfNotExist(vecName) println(DASHES) println(DASHES) println("8. Create a vehicle") println( """ Creating a vehicle in AWS IoT FleetWise allows you to digitally represent and manage a physical vehicle within the AWS ecosystem. This enables efficient ingestion, transformation, and transmission of vehicle telemetry data to the cloud for analysis. """.trimIndent(), ) waitForInputToContinue(scanner) createVehicle(vecName, manifestArn, decArn) println(DASHES) println(DASHES) println("9. Display vehicle details") waitForInputToContinue(scanner) getVehicleDetails(vecName) waitForInputToContinue(scanner) println(DASHES) println(DASHES) println("10. Delete the AWS IoT Fleetwise Assets") println("Would you like to delete the IoT Fleetwise Assets? (y/n)") val delAns = scanner.nextLine().trim() if (delAns.equals("y", ignoreCase = true)) { deleteVehicle(vecName) deleteDecoderManifest(decName) deleteModelManifest(manifestName) deleteFleet(fleetid) deleteSignalCatalog(signalCatalogName) } println(DASHES) println( """ Thank you for checking out the AWS IoT Fleetwise Service Use demo. We hope you learned something new, or got some inspiration for your own apps today. For more AWS code examples, have a look at: https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html """.trimIndent(), ) println(DASHES) } suspend fun deleteVehicle(vecName: String) { val request = DeleteVehicleRequest { vehicleName = vecName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteVehicle(request) println("Vehicle $vecName was deleted successfully.") } } suspend fun getVehicleDetails(vehicleNameVal: String) { val request = GetVehicleRequest { vehicleName = vehicleNameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.getVehicle(request) val details = mapOf( "vehicleName" to response.vehicleName, "arn" to response.arn, "modelManifestArn" to response.modelManifestArn, "decoderManifestArn" to response.decoderManifestArn, "attributes" to response.attributes.toString(), "creationTime" to response.creationTime.toString(), "lastModificationTime" to response.lastModificationTime.toString(), ) println("Vehicle Details:") for ((key, value) in details) { println("• %-20s : %s".format(key, value)) } } } suspend fun createVehicle(vecName: String, manifestArn: String?, decArn: String) { val request = CreateVehicleRequest { vehicleName = vecName modelManifestArn = manifestArn decoderManifestArn = decArn } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.createVehicle(request) println("Vehicle $vecName was created successfully.") } } /** * Creates an IoT Thing if it does not already exist. * * @param vecName the name of the IoT Thing to create */ suspend fun createThingIfNotExist(vecName: String) { val request = CreateThingRequest { thingName = vecName } IotClient { region = "us-east-1" }.use { client -> client.createThing(request) println("The $vecName IoT Thing was successfully created") } } suspend fun updateDecoderManifest(nameVal: String) { val request = UpdateDecoderManifestRequest { name = nameVal status = ManifestStatus.Active } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.updateDecoderManifest(request) println("$nameVal was successfully updated") } } /** * Waits for the specified model manifest to become active. * * @param decNameVal the name of the model manifest to wait for */ suspend fun waitForDecoderManifestActive(decNameVal: String) { var elapsedSeconds = 0 var lastStatus: ManifestStatus = ManifestStatus.Draft print("⏳ Elapsed: 0s | Status: DRAFT") IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> while (true) { delay(1000) elapsedSeconds++ if (elapsedSeconds % 5 == 0) { val request = GetDecoderManifestRequest { name = decNameVal } val response = fleetwiseClient.getDecoderManifest(request) lastStatus = response.status ?: ManifestStatus.Draft when (lastStatus) { ManifestStatus.Active -> { print("\rElapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") return } ManifestStatus.Invalid -> { print("\rElapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") throw RuntimeException("Model manifest became INVALID. Cannot proceed.") } else -> { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } else { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } } /** * Waits for the specified model manifest to become active. * * @param manifestName the name of the model manifest to wait for */ suspend fun waitForModelManifestActive(manifestNameVal: String) { var elapsedSeconds = 0 var lastStatus: ManifestStatus = ManifestStatus.Draft print("⏳ Elapsed: 0s | Status: DRAFT") IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> while (true) { delay(1000) elapsedSeconds++ if (elapsedSeconds % 5 == 0) { val request = GetModelManifestRequest { name = manifestNameVal } val response = fleetwiseClient.getModelManifest(request) lastStatus = response.status ?: ManifestStatus.Draft when (lastStatus) { ManifestStatus.Active -> { print("\r Elapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") return } ManifestStatus.Invalid -> { print("\r Elapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") throw RuntimeException("Model manifest became INVALID. Cannot proceed.") } else -> { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } else { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } } /** * Updates the model manifest. * * @param nameVal the name of the model manifest to update */ suspend fun updateModelManifest(nameVal: String) { val request = UpdateModelManifestRequest { name = nameVal status = ManifestStatus.Active } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.updateModelManifest(request) println("$nameVal was successfully updated") } } suspend fun deleteDecoderManifest(nameVal: String) { val request = DeleteDecoderManifestRequest { name = nameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteDecoderManifest(request) println("$nameVal was successfully deleted") } } /** * Creates a new decoder manifest. * * @param decName the name of the decoder manifest * @param modelManifestArnVal the ARN of the model manifest * @return the ARN of the decoder manifest */ suspend fun createDecoderManifest(decName: String, modelManifestArnVal: String?): String { val interfaceIdVal = "can0" val canInter = CanInterface { name = "canInterface0" protocolName = "CAN" protocolVersion = "1.0" } val networkInterface = NetworkInterface { interfaceId = interfaceIdVal type = NetworkInterfaceType.CanInterface canInterface = canInter } val carRpmSig = CanSignal { messageId = 100 isBigEndian = false isSigned = false startBit = 16 length = 16 factor = 1.0 offset = 0.0 } val carSpeedSig = CanSignal { messageId = 101 isBigEndian = false isSigned = false startBit = 0 length = 16 factor = 1.0 offset = 0.0 } val engineRpmDecoder = SignalDecoder { fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" interfaceId = interfaceIdVal type = SignalDecoderType.CanSignal canSignal = carRpmSig } val vehicleSpeedDecoder = SignalDecoder { fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" interfaceId = interfaceIdVal type = SignalDecoderType.CanSignal canSignal = carSpeedSig } val request = CreateDecoderManifestRequest { name = decName modelManifestArn = modelManifestArnVal networkInterfaces = listOf(networkInterface) signalDecoders = listOf(engineRpmDecoder, vehicleSpeedDecoder) } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createDecoderManifest(request) return response.arn } } /** * Deletes a signal catalog. * * @param name the name of the signal catalog to delete */ suspend fun deleteSignalCatalog(catName: String) { val request = DeleteSignalCatalogRequest { name = catName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteSignalCatalog(request) println(" $catName was successfully deleted") } } /** * Deletes a fleet based on the provided fleet ID. * * @param fleetId the ID of the fleet to be deleted */ suspend fun deleteFleet(fleetIdVal: String) { val request = DeleteFleetRequest { fleetId = fleetIdVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteFleet(request) println(" $fleetIdVal was successfully deleted") } } /** * Deletes a model manifest. * * @param nameVal the name of the model manifest to delete */ suspend fun deleteModelManifest(nameVal: String) { val request = DeleteModelManifestRequest { name = nameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteModelManifest(request) println(" $nameVal was successfully deleted") } } /** * Creates a model manifest. * * @param name the name of the model manifest to create * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog * @param nodes a list of nodes to include in the model manifest * @return a {@link CompletableFuture} that completes with the ARN of the created model manifest */ suspend fun createModelManifest(nameVal: String, signalCatalogArnVal: String, nodesList: List<Node>): String { val fqnList: List<String> = nodesList.map { node -> when (node) { is Node.Sensor -> node.asSensor().fullyQualifiedName is Node.Branch -> node.asBranch().fullyQualifiedName else -> throw RuntimeException("Unsupported node type") } } val request = CreateModelManifestRequest { name = nameVal signalCatalogArn = signalCatalogArnVal nodes = fqnList } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createModelManifest(request) return response.arn } } /** * Lists the signal catalog nodes asynchronously. * * @param signalCatalogName the name of the signal catalog * @return a CompletableFuture that, when completed, contains a list of nodes in the specified signal catalog * @throws CompletionException if an exception occurs during the asynchronous operation */ suspend fun listSignalCatalogNode(signalCatalogName: String): List<Node>? { val request = ListSignalCatalogNodesRequest { name = signalCatalogName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.listSignalCatalogNodes(request) return response.nodes } } /** * Creates a new fleet. * * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet * @param fleetId the unique identifier for the fleet * @return the ID of the created fleet */ suspend fun createFleet(catARN: String, fleetIdVal: String): String { val fleetRequest = CreateFleetRequest { fleetId = fleetIdVal signalCatalogArn = catARN description = "Built using the AWS For Kotlin" } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createFleet(fleetRequest) return response.id } } /** * Creates a signal catalog. * * @param signalCatalogName the name of the signal catalog to create the branch vehicle in * @return the ARN (Amazon Resource Name) of the created signal catalog */ suspend fun createbranchVehicle(signalCatalogName: String): String { delay(2000) // Wait for 2 seconds val branchVehicle = Branch { fullyQualifiedName = "Vehicle" description = "Root branch" } val branchPowertrain = Branch { fullyQualifiedName = "Vehicle.Powertrain" description = "Powertrain branch" } val sensorRPM = Sensor { fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" description = "Engine RPM" dataType = NodeDataType.Double unit = "rpm" } val sensorKM = Sensor { fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" description = "Vehicle Speed" dataType = NodeDataType.Double unit = "km/h" } // Wrap each specific node type (Branch and Sensor) into the sealed Node class // so they can be included in the CreateSignalCatalogRequest. val myNodes = listOf( Node.Branch(branchVehicle), Node.Branch(branchPowertrain), Node.Sensor(sensorRPM), Node.Sensor(sensorKM), ) val request = CreateSignalCatalogRequest { name = signalCatalogName nodes = myNodes } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createSignalCatalog(request) return response.arn } } private fun waitForInputToContinue(scanner: Scanner) { while (true) { println("") println("Enter 'c' followed by <ENTER> to continue:") val input = scanner.nextLine() if (input.trim { it <= ' ' }.equals("c", ignoreCase = true)) { println("Continuing with the program...") println("") break } else { println("Invalid input. Please try again.") } } }

操作

以下代码示例演示了如何使用 createDecoderManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Creates a new decoder manifest. * * @param decName the name of the decoder manifest * @param modelManifestArnVal the ARN of the model manifest * @return the ARN of the decoder manifest */ suspend fun createDecoderManifest(decName: String, modelManifestArnVal: String?): String { val interfaceIdVal = "can0" val canInter = CanInterface { name = "canInterface0" protocolName = "CAN" protocolVersion = "1.0" } val networkInterface = NetworkInterface { interfaceId = interfaceIdVal type = NetworkInterfaceType.CanInterface canInterface = canInter } val carRpmSig = CanSignal { messageId = 100 isBigEndian = false isSigned = false startBit = 16 length = 16 factor = 1.0 offset = 0.0 } val carSpeedSig = CanSignal { messageId = 101 isBigEndian = false isSigned = false startBit = 0 length = 16 factor = 1.0 offset = 0.0 } val engineRpmDecoder = SignalDecoder { fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" interfaceId = interfaceIdVal type = SignalDecoderType.CanSignal canSignal = carRpmSig } val vehicleSpeedDecoder = SignalDecoder { fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" interfaceId = interfaceIdVal type = SignalDecoderType.CanSignal canSignal = carSpeedSig } val request = CreateDecoderManifestRequest { name = decName modelManifestArn = modelManifestArnVal networkInterfaces = listOf(networkInterface) signalDecoders = listOf(engineRpmDecoder, vehicleSpeedDecoder) } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createDecoderManifest(request) return response.arn } }

以下代码示例演示了如何使用 createFleet

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Creates a new fleet. * * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet * @param fleetId the unique identifier for the fleet * @return the ID of the created fleet */ suspend fun createFleet(catARN: String, fleetIdVal: String): String { val fleetRequest = CreateFleetRequest { fleetId = fleetIdVal signalCatalogArn = catARN description = "Built using the AWS For Kotlin" } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createFleet(fleetRequest) return response.id } }
  • 有关 API 的详细信息,请参阅适用于 K otlin 的AWS SDK 中的 CreateFleet API 参考。

以下代码示例演示了如何使用 createModelManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Creates a model manifest. * * @param name the name of the model manifest to create * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog * @param nodes a list of nodes to include in the model manifest * @return a {@link CompletableFuture} that completes with the ARN of the created model manifest */ suspend fun createModelManifest(nameVal: String, signalCatalogArnVal: String, nodesList: List<Node>): String { val fqnList: List<String> = nodesList.map { node -> when (node) { is Node.Sensor -> node.asSensor().fullyQualifiedName is Node.Branch -> node.asBranch().fullyQualifiedName else -> throw RuntimeException("Unsupported node type") } } val request = CreateModelManifestRequest { name = nameVal signalCatalogArn = signalCatalogArnVal nodes = fqnList } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createModelManifest(request) return response.arn } }
  • 有关 API 的详细信息,请参阅适用createModelManifest于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 createSignalCatalog

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Creates a signal catalog. * * @param signalCatalogName the name of the signal catalog to create the branch vehicle in * @return the ARN (Amazon Resource Name) of the created signal catalog */ suspend fun createbranchVehicle(signalCatalogName: String): String { delay(2000) // Wait for 2 seconds val branchVehicle = Branch { fullyQualifiedName = "Vehicle" description = "Root branch" } val branchPowertrain = Branch { fullyQualifiedName = "Vehicle.Powertrain" description = "Powertrain branch" } val sensorRPM = Sensor { fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" description = "Engine RPM" dataType = NodeDataType.Double unit = "rpm" } val sensorKM = Sensor { fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" description = "Vehicle Speed" dataType = NodeDataType.Double unit = "km/h" } // Wrap each specific node type (Branch and Sensor) into the sealed Node class // so they can be included in the CreateSignalCatalogRequest. val myNodes = listOf( Node.Branch(branchVehicle), Node.Branch(branchPowertrain), Node.Sensor(sensorRPM), Node.Sensor(sensorKM), ) val request = CreateSignalCatalogRequest { name = signalCatalogName nodes = myNodes } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.createSignalCatalog(request) return response.arn } }
  • 有关 API 的详细信息,请参阅适用createSignalCatalog于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 createVehicle

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun createVehicle(vecName: String, manifestArn: String?, decArn: String) { val request = CreateVehicleRequest { vehicleName = vecName modelManifestArn = manifestArn decoderManifestArn = decArn } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.createVehicle(request) println("Vehicle $vecName was created successfully.") } }
  • 有关 API 的详细信息,请参阅 K otlin 版AWS SDK 中的 Create Vehicle API 参考。

以下代码示例演示了如何使用 deleteDecoderManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun deleteDecoderManifest(nameVal: String) { val request = DeleteDecoderManifestRequest { name = nameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteDecoderManifest(request) println("$nameVal was successfully deleted") } }

以下代码示例演示了如何使用 deleteFleet

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Deletes a fleet based on the provided fleet ID. * * @param fleetId the ID of the fleet to be deleted */ suspend fun deleteFleet(fleetIdVal: String) { val request = DeleteFleetRequest { fleetId = fleetIdVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteFleet(request) println(" $fleetIdVal was successfully deleted") } }
  • 有关 API 的详细信息,请参阅适用于 K otlin 的AWS SDK 中的 D eleteFleet API 参考。

以下代码示例演示了如何使用 deleteModelManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Deletes a model manifest. * * @param nameVal the name of the model manifest to delete */ suspend fun deleteModelManifest(nameVal: String) { val request = DeleteModelManifestRequest { name = nameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteModelManifest(request) println(" $nameVal was successfully deleted") } }
  • 有关 API 的详细信息,请参阅适用deleteModelManifest于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 deleteSignalCatalog

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Deletes a signal catalog. * * @param name the name of the signal catalog to delete */ suspend fun deleteSignalCatalog(catName: String) { val request = DeleteSignalCatalogRequest { name = catName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteSignalCatalog(request) println(" $catName was successfully deleted") } }
  • 有关 API 的详细信息,请参阅适用deleteSignalCatalog于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 deleteVehicle

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun deleteVehicle(vecName: String) { val request = DeleteVehicleRequest { vehicleName = vecName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.deleteVehicle(request) println("Vehicle $vecName was deleted successfully.") } }
  • 有关 API 的详细信息,请参阅适用于 K otlin 的AWS SDK 中的 D elete Vehic le API 参考。

以下代码示例演示了如何使用 getDecoderManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Waits for the specified model manifest to become active. * * @param decNameVal the name of the model manifest to wait for */ suspend fun waitForDecoderManifestActive(decNameVal: String) { var elapsedSeconds = 0 var lastStatus: ManifestStatus = ManifestStatus.Draft print("⏳ Elapsed: 0s | Status: DRAFT") IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> while (true) { delay(1000) elapsedSeconds++ if (elapsedSeconds % 5 == 0) { val request = GetDecoderManifestRequest { name = decNameVal } val response = fleetwiseClient.getDecoderManifest(request) lastStatus = response.status ?: ManifestStatus.Draft when (lastStatus) { ManifestStatus.Active -> { print("\rElapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") return } ManifestStatus.Invalid -> { print("\rElapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") throw RuntimeException("Model manifest became INVALID. Cannot proceed.") } else -> { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } else { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } }
  • 有关 API 的详细信息,请参阅适用getDecoderManifest于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 getModelManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Waits for the specified model manifest to become active. * * @param manifestName the name of the model manifest to wait for */ suspend fun waitForModelManifestActive(manifestNameVal: String) { var elapsedSeconds = 0 var lastStatus: ManifestStatus = ManifestStatus.Draft print("⏳ Elapsed: 0s | Status: DRAFT") IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> while (true) { delay(1000) elapsedSeconds++ if (elapsedSeconds % 5 == 0) { val request = GetModelManifestRequest { name = manifestNameVal } val response = fleetwiseClient.getModelManifest(request) lastStatus = response.status ?: ManifestStatus.Draft when (lastStatus) { ManifestStatus.Active -> { print("\r Elapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") return } ManifestStatus.Invalid -> { print("\r Elapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") throw RuntimeException("Model manifest became INVALID. Cannot proceed.") } else -> { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } else { print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") } } } }
  • 有关 API 的详细信息,请参阅适用getModelManifest于 K otlin 的AWS SDK API 参考

以下代码示例演示了如何使用 getVehicle

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun getVehicleDetails(vehicleNameVal: String) { val request = GetVehicleRequest { vehicleName = vehicleNameVal } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.getVehicle(request) val details = mapOf( "vehicleName" to response.vehicleName, "arn" to response.arn, "modelManifestArn" to response.modelManifestArn, "decoderManifestArn" to response.decoderManifestArn, "attributes" to response.attributes.toString(), "creationTime" to response.creationTime.toString(), "lastModificationTime" to response.lastModificationTime.toString(), ) println("Vehicle Details:") for ((key, value) in details) { println("• %-20s : %s".format(key, value)) } } }
  • 有关 API 的详细信息,请参阅适用于 K otlin 的AWS SDK 中的 getVe hicle API 参考。

以下代码示例演示了如何使用 listSignalCatalogNodes

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Lists the signal catalog nodes asynchronously. * * @param signalCatalogName the name of the signal catalog * @return a CompletableFuture that, when completed, contains a list of nodes in the specified signal catalog * @throws CompletionException if an exception occurs during the asynchronous operation */ suspend fun listSignalCatalogNode(signalCatalogName: String): List<Node>? { val request = ListSignalCatalogNodesRequest { name = signalCatalogName } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> val response = fleetwiseClient.listSignalCatalogNodes(request) return response.nodes } }

以下代码示例演示了如何使用 updateDecoderManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun updateDecoderManifest(nameVal: String) { val request = UpdateDecoderManifestRequest { name = nameVal status = ManifestStatus.Active } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.updateDecoderManifest(request) println("$nameVal was successfully updated") } }

以下代码示例演示了如何使用 updateModelManifest

适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Updates the model manifest. * * @param nameVal the name of the model manifest to update */ suspend fun updateModelManifest(nameVal: String) { val request = UpdateModelManifestRequest { name = nameVal status = ManifestStatus.Active } IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> fleetwiseClient.updateModelManifest(request) println("$nameVal was successfully updated") } }
  • 有关 API 的详细信息,请参阅适用updateModelManifest于 K otlin 的AWS SDK API 参考