Skip to content

Commit

Permalink
Implement android generic im
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed May 22, 2023
1 parent 28b3fcd commit bc4608b
Show file tree
Hide file tree
Showing 8 changed files with 6,214 additions and 2,156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class BasicClientFragment : Fragment() {
showMessage("[Read Success] $attributeName: $value")
}

}, devicePtr, listOf(ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)), null, false, 0 /* imTimeoutMs */)
}, devicePtr, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), null, false, 0 /* imTimeoutMs */)
}

private fun makeAttributeList() {
Expand All @@ -160,7 +160,7 @@ class BasicClientFragment : Fragment() {
showMessage("Write ${attribute.name} success")
}

}, devicePtr, listOf(AttributeWriteRequest.newInstance(addressUpdateFragment.endpointId.toLong(), clusterId, attribute.id, tlv, Optional.empty())), 0, 0)
}, devicePtr, listOf(AttributeWriteRequest.newInstance(addressUpdateFragment.endpointId, clusterId, attribute.id, tlv, Optional.empty())), 0, 0)
}

private fun showMessage(msg: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OnOffClientFragment : Fragment() {
val clusterId = OnOff.ID
val attributeId = OnOff.Attribute.OnOff.id

val attributePath = ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)
val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)

ChipClient.getDeviceController(requireContext()).readPath(object: ReportCallback {
override fun onError(attributePath: ChipAttributePath?, eventPath: ChipEventPath?, ex: java.lang.Exception) {
Expand Down Expand Up @@ -140,7 +140,7 @@ class OnOffClientFragment : Fragment() {
val clusterId = OnOff.ID
val attributeId = OnOff.Attribute.OnOff.id

val attributePath = ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)
val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)

val subscriptionEstablishedCallback =
SubscriptionEstablishedCallback {
Expand Down Expand Up @@ -209,13 +209,13 @@ class OnOffClientFragment : Fragment() {
// TODO : Need to be implement poj-to-tlv
val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
tlvWriter.put(ContextSpecificTag(0), binding.levelBar.progress.toUInt())
tlvWriter.put(ContextSpecificTag(1), 0u)
tlvWriter.put(ContextSpecificTag(2), 0u)
tlvWriter.put(ContextSpecificTag(3), 0u)
tlvWriter.put(ContextSpecificTag(LevelControl.MoveToLevelCommandField.Level.id), binding.levelBar.progress.toUInt())
tlvWriter.put(ContextSpecificTag(LevelControl.MoveToLevelCommandField.OptionsMask.id), 0u)
tlvWriter.put(ContextSpecificTag(LevelControl.MoveToLevelCommandField.OptionsOverride.id), 0u)
tlvWriter.put(ContextSpecificTag(LevelControl.MoveToLevelCommandField.TransitionTime.id), 0u)
tlvWriter.endStructure()

val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId.toLong()
val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId
, LevelControl.ID
, LevelControl.Command.MoveToLevel.id
, tlvWriter.getEncoded(), null)
Expand All @@ -239,7 +239,7 @@ class OnOffClientFragment : Fragment() {
val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
tlvWriter.endStructure()
val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId.toLong()
val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId
, OnOff.ID
, commandId.id
, tlvWriter.getEncoded(), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class OpCredClientFragment : Fragment() {
showMessage("OpCred $attributeName value: $value")
}

}, devicePtr, listOf(ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)), null, false, 0 /* imTimeoutMs */)
}, devicePtr, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), null, false, 0 /* imTimeoutMs */)
}

private fun showMessage(msg: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class SensorClientFragment : Fragment() {
val device = ChipClient.getConnectedDevicePointer(requireContext(), deviceId)
val callback = makeReadCallback(clusterName, false)

deviceController.readAttributePath(callback, device, listOf(ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)), 0)
deviceController.readAttributePath(callback, device, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), 0)
} catch (ex: Exception) {
Log.d(TAG, "Failed to read the sensor : ", ex)
showMessage(R.string.sensor_client_read_error_text, ex.toString())
Expand All @@ -170,7 +170,7 @@ class SensorClientFragment : Fragment() {
val device = ChipClient.getConnectedDevicePointer(requireContext(), deviceId)
val callback = makeReadCallback(clusterName, true)

deviceController.subscribeToAttributePath({ Log.d(TAG, "onSubscriptionEstablished") }, callback, device, listOf(ChipAttributePath.newInstance(endpointId.toLong(), clusterId, attributeId)), MIN_REFRESH_PERIOD_S, MAX_REFRESH_PERIOD_S, 0)
deviceController.subscribeToAttributePath({ Log.d(TAG, "onSubscriptionEstablished") }, callback, device, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), MIN_REFRESH_PERIOD_S, MAX_REFRESH_PERIOD_S, 0)
subscribedDevicePtr = device
} catch (ex: Exception) {
Log.d(TAG, "Failed to subscribe", ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ object TlvParseUtil {

fun encode(input: ByteArray): ByteArray {
val tlvWriter = TlvWriter()
val inputByteStringValue = ByteString.copyFrom(input);
tlvWriter.put(AnonymousTag, inputByteStringValue)
tlvWriter.put(AnonymousTag, input)
return tlvWriter.getEncoded();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ public class ClusterIDMapping {
}
}

{%- for command in cluster.commands | sort(attribute='code') %}
{%- if command.input_param -%}
public enum {{command.name | upfirst}}CommandField {
{%- for field in (cluster.structs | named(command.input_param)).fields -%} {{field.name | upfirst}}({{field.code}}), {%- endfor -%};
private final int id;
{{command.name | upfirst}}CommandField(int id) {
this.id = id;
}

public int getID() {
return id;
}
public static {{command.name | upfirst}}CommandField value(int id) throws NoSuchFieldError {
for ({{command.name | upfirst}}CommandField field : {{command.name | upfirst}}CommandField.values()) {
if (field.getID() == id) {
return field;
}
}
throw new NoSuchFieldError();
}
}
{%- endif -%}
{%- endfor -%}

@Override
public String getAttributeName(long id) throws NoSuchFieldError {
return Attribute.value(id).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public static Command value(long id) throws NoSuchFieldError {
}
throw new NoSuchFieldError();
}
}

@Override
}@Override
public String getAttributeName(long id) throws NoSuchFieldError {
return Attribute.value(id).toString();
}
Expand Down Expand Up @@ -200,9 +198,7 @@ public static Command value(long id) throws NoSuchFieldError {
}
throw new NoSuchFieldError();
}
}

@Override
}@Override
public String getAttributeName(long id) throws NoSuchFieldError {
return Attribute.value(id).toString();
}
Expand Down Expand Up @@ -298,9 +294,7 @@ public static Command value(long id) throws NoSuchFieldError {
}
throw new NoSuchFieldError();
}
}

@Override
}@Override
public String getAttributeName(long id) throws NoSuchFieldError {
return Attribute.value(id).toString();
}
Expand Down
Loading

0 comments on commit bc4608b

Please sign in to comment.