Skip to content

Commit

Permalink
Merge branch 'master' into bflb-iot-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
shchen-Lab authored Sep 28, 2023
2 parents 7dc0854 + d1fa6ee commit 2cb2aa1
Show file tree
Hide file tree
Showing 68 changed files with 15,871 additions and 474 deletions.
92 changes: 89 additions & 3 deletions .github/.wordlist.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ tv-app/**/README
:maxdepth: 1
tv-casting-app/**/README
tv-casting-app/APIs.md
```

## Window example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.google.chip.chiptool.setuppayloadscanner.BarcodeFragment
import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceDetailsFragment
import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceInfo
import com.google.chip.chiptool.setuppayloadscanner.CHIPLedgerDetailsFragment
import com.google.chip.chiptool.util.DeviceIdUtil
import org.json.JSONObject

class CHIPToolActivity :
Expand Down Expand Up @@ -94,11 +95,12 @@ class CHIPToolActivity :
}
}

override fun onCommissioningComplete(code: Int) {
override fun onCommissioningComplete(code: Int, nodeId: Long) {
runOnUiThread {
Toast.makeText(this, getString(R.string.commissioning_completed, code), Toast.LENGTH_SHORT)
.show()
}
DeviceIdUtil.setCommissionedNodeId(this, nodeId)
ChipClient.getDeviceController(this).close()
showFragment(SelectActionFragment.newInstance(), false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.chip.chiptool.attestation.AttestationTestFragment
import com.google.chip.chiptool.clusterclient.*
import com.google.chip.chiptool.clusterclient.GroupSettingFragment
import com.google.chip.chiptool.clusterclient.clusterinteraction.ClusterInteractionFragment
import com.google.chip.chiptool.databinding.SelectActionFragmentBinding
import com.google.chip.chiptool.provisioning.ProvisionNetworkType
Expand Down Expand Up @@ -71,6 +72,7 @@ class SelectActionFragment : Fragment() {
binding.provisionCustomFlowBtn.setOnClickListener { handleProvisionCustomFlowClicked() }
binding.wildcardBtn.setOnClickListener { handleWildcardClicked() }
binding.unpairDeviceBtn.setOnClickListener { handleUnpairDeviceClicked() }
binding.groupSettingBtn.setOnClickListener { handleGroupSettingClicked() }

return binding.root
}
Expand Down Expand Up @@ -233,6 +235,10 @@ class SelectActionFragment : Fragment() {
showFragment(BarcodeFragment.newInstance(), false)
}

private fun handleGroupSettingClicked() {
showFragment(GroupSettingFragment.newInstance())
}

companion object {

@JvmStatic fun newInstance() = SelectActionFragment()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.google.chip.chiptool.clusterclient

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import chip.devicecontroller.ChipDeviceController
import com.google.chip.chiptool.ChipClient
Expand Down Expand Up @@ -41,13 +45,70 @@ class AddressUpdateFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

val compressedFabricId = deviceController.compressedFabricId
binding.fabricIdEd.setText(compressedFabricId.toULong().toString(16).padStart(16, '0'))
binding.deviceIdEd.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString())
binding.fabricIdEd.setText(compressedFabricId.toULong().toString().padStart(16, '0'))
binding.deviceIdEd.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString(16))
binding.epIdEd.setText(endpointId.toString())

updateDeviceIdSpinner()
}

fun updateDeviceIdSpinner() {
val deviceIdList = DeviceIdUtil.getCommissionedNodeId(requireContext())
binding.deviceIdSpinner.adapter =
ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, deviceIdList)
binding.deviceIdSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
binding.deviceIdEd.setText(deviceIdList[position].toULong(16).toString())
}

override fun onNothingSelected(parent: AdapterView<*>?) {
Log.d(TAG, "onNothingSelected")
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

suspend fun getDevicePointer(context: Context): Long {
return if (isGroupId()) {
deviceController.getGroupDevicePointer(getGroupId().toInt())
} else {
ChipClient.getConnectedDevicePointer(context, getNodeId().toLong())
}
}

fun isGroupId(): Boolean {
return isGroupNodeId(getNodeId())
}

fun getGroupId(): UInt {
return getGroupIdFromNodeId(getNodeId())
}

fun getNodeId(): ULong {
return binding.deviceIdEd.text.toString().toULong()
}

companion object {
private const val TAG = "AddressUpdateFragment"
// Refer from NodeId.h (src/lib/core/NodeId.h)
private const val MIN_GROUP_NODE_ID = 0xFFFF_FFFF_FFFF_0000UL
private const val MASK_GROUP_ID = 0x0000_0000_0000_FFFFUL

fun isGroupNodeId(nodeId: ULong): Boolean {
return nodeId >= MIN_GROUP_NODE_ID
}

fun getNodeIdFromGroupId(groupId: UInt): ULong {
return groupId.toULong() or MIN_GROUP_NODE_ID
}

fun getGroupIdFromNodeId(nodeId: ULong): UInt {
return (nodeId and MASK_GROUP_ID).toUInt()
}
}
}
Loading

0 comments on commit 2cb2aa1

Please sign in to comment.