forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68d69cb
commit 26db8c5
Showing
15 changed files
with
489 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
...ool/app/src/main/java/com/google/chip/chiptool/clusterclient/OtaProviderClientFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.google.chip.chiptool.clusterclient | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.lifecycleScope | ||
import chip.devicecontroller.ChipDeviceController | ||
import chip.devicecontroller.ClusterIDMapping | ||
import chip.devicecontroller.InvokeCallback | ||
import chip.devicecontroller.OTAProviderDelegate | ||
import chip.devicecontroller.model.InvokeElement | ||
import chip.tlv.AnonymousTag | ||
import chip.tlv.ContextSpecificTag | ||
import chip.tlv.TlvWriter | ||
import com.google.chip.chiptool.ChipClient | ||
import com.google.chip.chiptool.GenericChipDeviceListener | ||
import com.google.chip.chiptool.R | ||
import com.google.chip.chiptool.databinding.OtaProviderClientFragmentBinding | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
class OtaProviderClientFragment : Fragment() { | ||
private val deviceController: ChipDeviceController | ||
get() = ChipClient.getDeviceController(requireContext()) | ||
|
||
private lateinit var scope: CoroutineScope | ||
|
||
private lateinit var addressUpdateFragment: AddressUpdateFragment | ||
|
||
private var _binding: OtaProviderClientFragmentBinding? = null | ||
private val binding | ||
get() = _binding!! | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = OtaProviderClientFragmentBinding.inflate(inflater, container, false) | ||
scope = viewLifecycleOwner.lifecycleScope | ||
|
||
deviceController.setCompletionListener(ChipControllerCallback()) | ||
|
||
addressUpdateFragment = | ||
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment | ||
|
||
binding.announceOTAProviderBtn.setOnClickListener { scope.launch { sendAnnounceOTAProviderBtnClick() } } | ||
|
||
deviceController.setOTAProviderDelegate(object: OTAProviderDelegate { | ||
override fun handleQueryImage() { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun handleApplyUpdateRequest() { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun handleNotifyUpdateApplied() { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun handleBDXTransferSessionBegin(nodeId: Long, fileDesignator: String?, offset: Int) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun handleBDXTransferSessionEnd(nodeId: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun setOTAFilePath(path: String?) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun selectOTACandidate(requestorVendorID: Int, requestorProductID: Int, requestorSoftwareVersion: Int): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
}) | ||
return binding.root | ||
} | ||
|
||
private suspend fun sendAnnounceOTAProviderBtnClick() { | ||
val endpointId = 0 | ||
val clusterId = ClusterIDMapping.OtaSoftwareUpdateRequestor.ID | ||
val commandId = ClusterIDMapping.OtaSoftwareUpdateRequestor.Command.AnnounceOTAProvider | ||
|
||
val tlvWriter = TlvWriter().apply { | ||
startStructure(AnonymousTag) | ||
put(ContextSpecificTag(ClusterIDMapping.OtaSoftwareUpdateRequestor.AnnounceOTAProviderCommandField.ProviderNodeID.id), deviceController.controllerNodeId.toULong()) | ||
put(ContextSpecificTag(ClusterIDMapping.OtaSoftwareUpdateRequestor.AnnounceOTAProviderCommandField.VendorID.id), ChipClient.VENDOR_ID.toUInt()) | ||
put(ContextSpecificTag(ClusterIDMapping.OtaSoftwareUpdateRequestor.AnnounceOTAProviderCommandField.AnnouncementReason.id), 0U) | ||
put(ContextSpecificTag(ClusterIDMapping.OtaSoftwareUpdateRequestor.AnnounceOTAProviderCommandField.Endpoint.id), 0U) | ||
endStructure() | ||
} | ||
|
||
val invokeElement = InvokeElement.newInstance(endpointId, clusterId, commandId.id, tlvWriter.getEncoded(), null) | ||
|
||
deviceController.invoke( | ||
object : InvokeCallback { | ||
override fun onError(ex: Exception?) { | ||
showMessage("${commandId.name} command failure $ex") | ||
Log.e(TAG, "${commandId.name} command failure", ex) | ||
} | ||
|
||
override fun onResponse(invokeElement: InvokeElement?, successCode: Long) { | ||
Log.d(TAG, "onResponse : $invokeElement, Code : $successCode") | ||
showMessage("${commandId.name} command success") | ||
} | ||
}, | ||
getConnectedDevicePointer(), | ||
invokeElement, | ||
0, | ||
0 | ||
) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
inner class ChipControllerCallback : GenericChipDeviceListener() { | ||
override fun onConnectDeviceComplete() {} | ||
|
||
override fun onCommissioningComplete(nodeId: Long, errorCode: Int) { | ||
Log.d(TAG, "onCommissioningComplete for nodeId $nodeId: $errorCode") | ||
showMessage("Address update complete for nodeId $nodeId with code $errorCode") | ||
} | ||
|
||
override fun onNotifyChipConnectionClosed() { | ||
Log.d(TAG, "onNotifyChipConnectionClosed") | ||
} | ||
|
||
override fun onCloseBleComplete() { | ||
Log.d(TAG, "onCloseBleComplete") | ||
} | ||
|
||
override fun onError(error: Throwable?) { | ||
Log.d(TAG, "onError: $error") | ||
} | ||
} | ||
|
||
private suspend fun getConnectedDevicePointer(): Long { | ||
return ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId) | ||
} | ||
|
||
private fun showMessage(msg: String) { | ||
requireActivity().runOnUiThread { binding.commandStatusTv.text = msg } | ||
} | ||
|
||
private fun showReportMessage(msg: String) { | ||
requireActivity().runOnUiThread { binding.reportStatusTv.text = msg } | ||
} | ||
|
||
companion object { | ||
private const val TAG = "OtaProviderClientFragment" | ||
|
||
fun newInstance(): OtaProviderClientFragment = OtaProviderClientFragment() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/android/CHIPTool/app/src/main/res/layout/ota_provider_client_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/addressUpdateFragment" | ||
android:name="com.google.chip.chiptool.clusterclient.AddressUpdateFragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentTop="true" /> | ||
|
||
<GridLayout | ||
android:id="@+id/buttonGrid" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/addressUpdateFragment" | ||
android:columnCount="3" | ||
android:rowCount="2"> | ||
<TextView | ||
android:id="@+id/announceOTAProviderBtn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="16dp" | ||
android:layout_margin="8dp" | ||
android:layout_gravity="center" | ||
android:layout_columnWeight="1" | ||
android:layout_column="0" | ||
android:layout_row="0" | ||
android:background="@android:color/darker_gray" | ||
android:text="@string/ota_provider_announce_ota_provider_text" | ||
android:textSize="16sp"/> | ||
|
||
</GridLayout> | ||
<TextView | ||
android:id="@+id/commandStatusTv" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/buttonGrid" | ||
android:padding="16dp" | ||
android:minLines="4" | ||
android:singleLine="false" | ||
android:textSize="20sp" /> | ||
|
||
<TextView | ||
android:id="@+id/reportStatusTv" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/commandStatusTv" | ||
android:padding="16dp" | ||
android:minLines="4" | ||
android:singleLine="false" | ||
android:textSize="20sp" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.