Skip to content

Commit

Permalink
Merge branch 'master' into make-python-attribute-cache-faster
Browse files Browse the repository at this point in the history
  • Loading branch information
agners authored May 25, 2023
2 parents 6e6b201 + 5728039 commit a1632ca
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_UBSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-asan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-err.log >&2)
# -enableThreadSanitizer instruments the code in Matter.framework,
# but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_TSAN=YES
xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2)
#xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2)
working-directory: src/darwin/Framework
- name: Uploading log files
uses: actions/upload-artifact@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import chip.devicecontroller.ChipDeviceController
import chip.devicecontroller.ClusterIDMapping
import chip.devicecontroller.ClusterIDMapping.AdministratorCommissioning
import chip.devicecontroller.InvokeCallback
import chip.devicecontroller.OpenCommissioningCallback
import chip.devicecontroller.ReportCallback
import chip.devicecontroller.model.ChipAttributePath
import chip.devicecontroller.model.ChipEventPath
import chip.devicecontroller.model.InvokeElement
import chip.devicecontroller.model.NodeState
import chip.tlv.AnonymousTag
import chip.tlv.TlvWriter
import com.google.chip.chiptool.ChipClient
Expand Down Expand Up @@ -47,6 +51,9 @@ class MultiAdminClientFragment : Fragment() {
binding.basicCommissioningMethodBtn.setOnClickListener { scope.launch { sendBasicCommissioningCommandClick() } }
binding.enhancedCommissioningMethodBtn.setOnClickListener { scope.launch { sendEnhancedCommissioningCommandClick() } }
binding.revokeBtn.setOnClickListener { scope.launch { sendRevokeCommandClick() } }
binding.readWindowStatusBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.WindowStatus) } }
binding.readAdminFabricIndexBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.AdminFabricIndex) } }
binding.readAdminVendorIdBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.AdminVendorId) } }

return binding.root
}
Expand Down Expand Up @@ -137,9 +144,9 @@ class MultiAdminClientFragment : Fragment() {
val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
tlvWriter.endStructure()
val invokeElement = InvokeElement.newInstance(0
, ClusterIDMapping.AdministratorCommissioning.ID
, ClusterIDMapping.AdministratorCommissioning.Command.RevokeCommissioning.id
val invokeElement = InvokeElement.newInstance(ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID
, AdministratorCommissioning.ID
, AdministratorCommissioning.Command.RevokeCommissioning.id
, tlvWriter.getEncoded(), null)

deviceController.invoke(object: InvokeCallback {
Expand All @@ -156,6 +163,25 @@ class MultiAdminClientFragment : Fragment() {
}, getConnectedDevicePointer(), invokeElement, timedInvokeTimeout, 0)
}

private suspend fun readAdministratorCommissioningClusterAttributeClick(attribute: AdministratorCommissioning.Attribute) {
val endpointId = ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID
val clusterId = AdministratorCommissioning.ID
val attributeId = attribute.id
val attributeName = attribute.name
val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
deviceController.readAttributePath(object: ReportCallback {
override fun onReport(nodeState: NodeState?) {
val value = nodeState?.getEndpointState(endpointId)?.getClusterState(clusterId)?.getAttributeState(attributeId)?.value ?: "null"
Log.i(TAG,"read $attributeName: $value")
showMessage("read $attributeName: $value")
}

override fun onError(attributePath: ChipAttributePath?, eventPath: ChipEventPath?, e: Exception) {
showMessage("read $attributeName - error : ${e?.message}")
}
}, getConnectedDevicePointer(), listOf(attributePath), 0)
}

private suspend fun getConnectedDevicePointer(): Long {
return ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId)
}
Expand All @@ -168,6 +194,7 @@ class MultiAdminClientFragment : Fragment() {

companion object {
private const val TAG = "MultiAdminClientFragment"
private const val ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID = 0
fun newInstance(): MultiAdminClientFragment = MultiAdminClientFragment()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ import com.google.chip.chiptool.databinding.OpCredClientFragmentBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

import chip.devicecontroller.ClusterIDMapping.*
import chip.devicecontroller.ClusterIDMapping.OperationalCredentials
import chip.devicecontroller.InvokeCallback
import chip.devicecontroller.ReportCallback
import chip.devicecontroller.model.ChipAttributePath
import chip.devicecontroller.model.ChipEventPath
import chip.devicecontroller.model.InvokeElement
import chip.devicecontroller.model.NodeState
import chip.tlv.AnonymousTag
import chip.tlv.ContextSpecificTag
import chip.tlv.TlvWriter

class OpCredClientFragment : Fragment() {
private val deviceController: ChipDeviceController
Expand Down Expand Up @@ -47,6 +52,8 @@ class OpCredClientFragment : Fragment() {

binding.readSupportedFabricBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.SupportedFabrics) } }
binding.readCommissionedFabricBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.CommissionedFabrics) } }
binding.readFabricsBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.Fabrics) } }
binding.removeFabricsBtn.setOnClickListener { scope.launch { sendRemoveFabricsBtnClick(binding.fabricIndexEd.text.toString().toUInt()) } }

return binding.root
}
Expand Down Expand Up @@ -99,6 +106,32 @@ class OpCredClientFragment : Fragment() {
}, devicePtr, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), null, false, 0 /* imTimeoutMs */)
}

private suspend fun sendRemoveFabricsBtnClick(fabricIndex: UInt) {
val devicePtr = ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId)
// TODO : Need to be implement poj-to-tlv
val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
tlvWriter.put(ContextSpecificTag(OperationalCredentials.RemoveFabricCommandField.FabricIndex.id), fabricIndex)
tlvWriter.endStructure()
val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId
, OperationalCredentials.ID
, OperationalCredentials.Command.RemoveFabric.id
, tlvWriter.getEncoded(), null)

deviceController.invoke(object: InvokeCallback {
override fun onError(ex: Exception?) {
showMessage("RemoveFabric failure $ex")
Log.e(TAG, "RemoveFabric failure", ex)
}

override fun onResponse(invokeElement: InvokeElement?, successCode: Long) {
Log.e(TAG, "onResponse : $invokeElement, Code : $successCode")
showMessage("RemoveFabric success")
}

}, devicePtr, invokeElement, 0, 0)
}

private fun showMessage(msg: String) {
requireActivity().runOnUiThread {
binding.opCredClusterCommandStatus.text = msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,45 @@
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/revoke_btn_text" />

<Button
android:id="@+id/readWindowStatusBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="10dp"
app:layout_constraintTop_toBottomOf="@id/revokeBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/readAdminFabricIndexBtn"
android:text="@string/read_window_status_btn_text" />

<Button
android:id="@+id/readAdminFabricIndexBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="10dp"
app:layout_constraintTop_toBottomOf="@id/revokeBtn"
app:layout_constraintEnd_toStartOf="@id/readAdminVendorIdBtn"
app:layout_constraintStart_toEndOf="@id/readWindowStatusBtn"
android:text="@string/read_admin_fabric_index_btn_text" />

<Button
android:id="@+id/readAdminVendorIdBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="10dp"
app:layout_constraintTop_toBottomOf="@id/revokeBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/readAdminFabricIndexBtn"
android:text="@string/read_admin_vendor_id_btn_text" />

<TextView
android:id="@+id/multiAdminClusterCommandStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
app:layout_constraintTop_toBottomOf="@id/revokeBtn"
app:layout_constraintTop_toBottomOf="@id/readWindowStatusBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:singleLine="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,50 @@
android:layout_marginBottom="10dp"
android:text="@string/op_cred_client_read_commissioned_fabric_btn_text" />

<Button
android:id="@+id/readFabricsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/readCommissionedFabricBtn"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:text="@string/op_cred_client_read_fabrics_btn_text" />

<Button
android:id="@+id/removeFabricsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/readFabricsBtn"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:text="@string/op_cred_client_remove_fabrics_btn_text" />

<EditText
android:id="@+id/fabricIndexEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/readFabricsBtn"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_toEndOf="@+id/removeFabricsBtn"
android:text="1"
android:hint="@string/op_cred_client_fabric_index_hint_text"
android:inputType="number"
android:textSize="20sp" />

<TextView
android:id="@+id/opCredClusterCommandStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/readCommissionedFabricBtn"
android:layout_below="@id/removeFabricsBtn"
android:minLines="4"
android:padding="16dp"
android:singleLine="false"
Expand Down
6 changes: 6 additions & 0 deletions examples/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@
<string name="enter_setup_pin_code_hint_text">Enter Setup PIN Code</string>
<string name="enhanced_commissioning_method_btn_text">Enhanced Commissioning Method</string>
<string name="revoke_btn_text">Revoke</string>
<string name="read_window_status_btn_text">Read Window Status</string>
<string name="read_admin_fabric_index_btn_text">Read Admin FabricIndex</string>
<string name="read_admin_vendor_id_btn_text">Read Admin VID</string>

<string name="op_cred_client_btn_text">Operational Credentials cluster</string>
<string name="op_cred_client_read_supported_fabric_btn_text">Read Supported Fabric count</string>
<string name="op_cred_client_read_commissioned_fabric_btn_text">Read Commissioned Fabric count</string>
<string name="op_cred_client_read_fabrics_btn_text">Read Fabrics</string>
<string name="op_cred_client_remove_fabrics_btn_text">Remove Fabrics</string>
<string name="op_cred_client_fabric_index_hint_text">FabricIndex</string>

<string name="basic_cluster_btn_text">Basic cluster</string>
<string name="basic_cluster_write_btn_text">Write</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PairOnNetworkLongImSubscribeCommand(
}

private inner class InternalResubscriptionAttemptCallback : ResubscriptionAttemptCallback {
override fun onResubscriptionAttempt(terminationCause: Int, nextResubscribeIntervalMsec: Int) {
override fun onResubscriptionAttempt(terminationCause: Long, nextResubscribeIntervalMsec: Long) {
logger.log(Level.INFO, "ResubscriptionAttemptCallback");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import java.util.Objects;

public class MatterError {
private int errorCode;
private long errorCode;
private String errorMessage;

public static final MatterError DISCOVERY_SERVICE_LOST =
new MatterError(4, "Discovery service was lost.");
new MatterError(4L, "Discovery service was lost.");

public static final MatterError NO_ERROR = new MatterError(0, null);

public MatterError(int errorCode, String errorMessage) {
public MatterError(long errorCode, String errorMessage) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
Expand All @@ -37,7 +37,7 @@ public boolean isNoError() {
return this.equals(NO_ERROR);
}

public int getErrorCode() {
public long getErrorCode() {
return errorCode;
}

Expand Down
23 changes: 20 additions & 3 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def __init__(self, zap_config, template, output_dir=None):
else:
self.output_dir = None

@property
def is_matter_idl_generation(self):
return (self.output_dir is None)

def distinct_output(self):
if not self.template and not self.output_dir:
# Matter IDL templates have no template/output dir as they go with the
Expand Down Expand Up @@ -463,9 +467,22 @@ def main():
if args.parallel:
# Ensure each zap run is independent
os.environ['ZAP_TEMPSTATE'] = '1'
with multiprocessing.Pool() as pool:
for timing in pool.imap_unordered(_ParallelGenerateOne, targets):
timings.append(timing)

# There is a sequencing here:
# - ZAP will generate ".matter" files
# - various codegen may generate from ".matter" files (like java)
# We split codegen into two generations to not be racy
first, second = [], []
for target in targets:
if isinstance(target, ZAPGenerateTarget) and target.is_matter_idl_generation:
first.append(target)
else:
second.append(target)

for items in [first, second]:
with multiprocessing.Pool() as pool:
for timing in pool.imap_unordered(_ParallelGenerateOne, items):
timings.append(timing)
else:
for target in targets:
timings.append(target.generate())
Expand Down
Loading

0 comments on commit a1632ca

Please sign in to comment.