Skip to content

Commit

Permalink
Update Android CHIPTool network commissioning code
Browse files Browse the repository at this point in the history
  • Loading branch information
austinh0 committed Dec 10, 2021
1 parent 175ae1c commit 0af7788
Showing 1 changed file with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class EnterNetworkFragment : Fragment() {

val cluster = createNetworkCommissioningCluster()
val enableNetworkCallback = object :
NetworkCommissioningCluster.EnableNetworkResponseCallback {
override fun onSuccess(errorCode: Int, debugText: String) {
NetworkCommissioningCluster.ConnectNetworkResponseCallback {
override fun onSuccess(networkingStatus: Int, debugText: String, errorValue: Long) {
Log.v(TAG, "EnableNetwork for $ssid succeeded, proceeding to OnOff")

requireActivity().runOnUiThread {
Expand All @@ -124,15 +124,14 @@ class EnterNetworkFragment : Fragment() {
}
}

cluster.addWiFiNetwork(object :
NetworkCommissioningCluster.AddWiFiNetworkResponseCallback {
override fun onSuccess(errorCode: Int, debugText: String) {
cluster.addOrUpdateWiFiNetwork(object :
NetworkCommissioningCluster.NetworkConfigResponseCallback {
override fun onSuccess(networkingStatus: Int, debugText: String) {
Log.v(TAG, "AddWifiNetwork for $ssid succeeded")
cluster.enableNetwork(
cluster.connectNetwork(
enableNetworkCallback,
ssidBytes,
/* breadcrumb = */ 0L,
ENABLE_NETWORK_TIMEOUT
)
}

Expand All @@ -143,7 +142,7 @@ class EnterNetworkFragment : Fragment() {
DeviceProvisioningFragment.Callback::class.java
)?.onCommissioningComplete(-1)
}
}, ssidBytes, pwdBytes, /* breadcrumb = */ 0L, ADD_NETWORK_TIMEOUT)
}, ssidBytes, pwdBytes, /* breadcrumb = */ 0L)
}

private fun saveThreadNetwork() {
Expand Down Expand Up @@ -192,8 +191,8 @@ class EnterNetworkFragment : Fragment() {
)

val enableNetworkCallback = object :
NetworkCommissioningCluster.EnableNetworkResponseCallback {
override fun onSuccess(errorCode: Int, debugText: String) {
NetworkCommissioningCluster.ConnectNetworkResponseCallback {
override fun onSuccess(networkingStatus: Int, debugText: String, errorValue: Long) {
Log.v(TAG, "EnableNetwork for $panIdStr succeeded, proceeding to OnOff")

requireActivity().runOnUiThread {
Expand All @@ -220,19 +219,14 @@ class EnterNetworkFragment : Fragment() {
}
}

cluster.addThreadNetwork(object :
NetworkCommissioningCluster.AddThreadNetworkResponseCallback {
override fun onSuccess(errorCode: Int, debugText: String) {
cluster.addOrUpdateThreadNetwork(object :
NetworkCommissioningCluster.NetworkConfigResponseCallback {
override fun onSuccess(networkingStatus: Int, debugText: String) {
Log.v(TAG, "AddThreadNetwork for $panIdStr succeeded")
println(xpanIdStr.toByteArray())
for( b in xpanIdStr.toByteArray()) {
println("> $b")
}
cluster.enableNetwork(
cluster.connectNetwork(
enableNetworkCallback,
xpanIdStr.hexToByteArray(),
/* breadcrumb = */ 0L,
ENABLE_NETWORK_TIMEOUT
/* breadcrumb = */ 0L
)
}

Expand All @@ -243,7 +237,7 @@ class EnterNetworkFragment : Fragment() {
DeviceProvisioningFragment.Callback::class.java
)?.onCommissioningComplete(-1)
}
}, operationalDataset, /* breadcrumb = */ 0L, ADD_NETWORK_TIMEOUT)
}, operationalDataset, /* breadcrumb = */ 0L)
}

private fun makeThreadOperationalDataset(
Expand Down Expand Up @@ -296,8 +290,6 @@ class EnterNetworkFragment : Fragment() {
private const val USE_HARDCODED_WIFI = false
private const val HARDCODED_WIFI_SSID = ""
private const val HARDCODED_WIFI_PASSWORD = ""
private const val ADD_NETWORK_TIMEOUT = 10000L
private const val ENABLE_NETWORK_TIMEOUT = 10000L

private const val NUM_CHANNEL_BYTES = 3
private const val NUM_PANID_BYTES = 2
Expand Down

0 comments on commit 0af7788

Please sign in to comment.