diff options
146 files changed, 6641 insertions, 3592 deletions
diff --git a/Manifest.pdf b/Manifest.pdf index eca850e..eca850e 100644..100755 --- a/Manifest.pdf +++ b/Manifest.pdf | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/.classpath b/client/AndroidClients/LightingController/.classpath index a4763d1..ce3da48 100644..100755 --- a/client/AndroidClients/LightingController/.classpath +++ b/client/AndroidClients/LightingController/.classpath | |||
@@ -1,8 +1,9 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <classpath> | 2 | <classpath> |
3 | <classpathentry kind="src" path="src"/> | 3 | <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> |
4 | <classpathentry kind="src" path="gen"/> | 4 | <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> |
5 | <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | 5 | <classpathentry kind="src" path="src"/> |
6 | <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> | 6 | <classpathentry kind="src" path="gen"/> |
7 | <classpathentry kind="output" path="bin/classes"/> | 7 | <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> |
8 | </classpath> | 8 | <classpathentry kind="output" path="bin/classes"/> |
9 | </classpath> | ||
diff --git a/client/AndroidClients/LightingController/.project b/client/AndroidClients/LightingController/.project index bb70ac8..bb70ac8 100644..100755 --- a/client/AndroidClients/LightingController/.project +++ b/client/AndroidClients/LightingController/.project | |||
diff --git a/client/AndroidClients/LightingController/.settings/org.eclipse.jdt.core.prefs b/client/AndroidClients/LightingController/.settings/org.eclipse.jdt.core.prefs index 543e7e6..543e7e6 100644..100755 --- a/client/AndroidClients/LightingController/.settings/org.eclipse.jdt.core.prefs +++ b/client/AndroidClients/LightingController/.settings/org.eclipse.jdt.core.prefs | |||
diff --git a/client/AndroidClients/LightingController/AndroidManifest.xml b/client/AndroidClients/LightingController/AndroidManifest.xml index 45fb8cd..45fb8cd 100644..100755 --- a/client/AndroidClients/LightingController/AndroidManifest.xml +++ b/client/AndroidClients/LightingController/AndroidManifest.xml | |||
diff --git a/client/AndroidClients/LightingController/bin/AndroidManifest.xml b/client/AndroidClients/LightingController/bin/AndroidManifest.xml index 45fb8cd..45fb8cd 100644..100755 --- a/client/AndroidClients/LightingController/bin/AndroidManifest.xml +++ b/client/AndroidClients/LightingController/bin/AndroidManifest.xml | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/BuildConfig.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/BuildConfig.class index 94c5e5d..94c5e5d 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/BuildConfig.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/BuildConfig.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class index baa30fb..1d3a710 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class index fe1d34f..60b14a1 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask$1.class index 2a6a499..2a6a499 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class index 05ccbad..0f34055 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class index 9cdb686..aa4167b 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$anim.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$anim.class index 7c82094..7c82094 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$anim.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$anim.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$array.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$array.class index b2d465c..b2d465c 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$array.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$array.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$attr.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$attr.class index 7b620b3..7b620b3 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$attr.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$attr.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class index a692e54..8e6dc24 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class index 9e9ccb6..db57ba3 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class index 4d0f706..6353fb4 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class index 568ef69..c1801d9 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class index 6e491a1..d7e130e 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R.class index 2762b70..2762b70 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class index dcefaa8..832b485 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class index 94bd22b..a687013 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeGroup.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeGroup.class index 8383b43..8383b43 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeGroup.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeGroup.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class index 03d1817..bea7621 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class index 57b7301..35eed7d 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class index 08bcf8e..2b3b1e6 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class index 5728e2a..0987c98 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$5.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$5.class new file mode 100755 index 0000000..6a7610f --- /dev/null +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$5.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$6.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$6.class new file mode 100755 index 0000000..37ef8db --- /dev/null +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$6.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$7.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$7.class new file mode 100755 index 0000000..84bd686 --- /dev/null +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$7.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class index 17a40db..923a406 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeScene.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeScene.class index 270063d..270063d 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeScene.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeScene.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class index 294d077..c3e85eb 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class index 6b1a6bd..0d5cb62 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$1.class index 3fac38e..3fac38e 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$2.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$2.class index ea283e7..ea283e7 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$2.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$2.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$3.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$3.class index daae256..daae256 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$3.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$3.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$4.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$4.class index bdf92dd..bdf92dd 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$4.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$4.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class index 13c417c..a41989a 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class index 1e5b0ef..882dada 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class index 953fcd2..87de90d 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class index e5da882..4d427dc 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class index 3ee9217..012da77 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class index a284f8f..880bfb7 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class index b3a3b27..94a3e65 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class index 8e54580..bd8ce1d 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/optionsMenu.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/optionsMenu.class index ee6acd3..ee6acd3 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/optionsMenu.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/optionsMenu.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class index b94c549..794d8ff 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class index 67a9bf5..c9b509b 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class index 9c9591b..8a66c1c 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class index 1def5cd..49f39ca 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class index b2270eb..861ee15 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class index 35a0da8..9b8d0f8 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class index ed819a7..fc3af5a 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class index c79b064..620f2d2 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class index 4a45b81..ac26807 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class index 55eb520..6c88c01 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class index 6c06c87..c2bf6ed 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask$1.class new file mode 100755 index 0000000..edcc641 --- /dev/null +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask.class new file mode 100755 index 0000000..d462643 --- /dev/null +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class index be8981b..4071416 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class index 12496d8..eff697c 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class index 1f0dfad..ab55b41 100644..100755 --- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class +++ b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/default.properties b/client/AndroidClients/LightingController/default.properties index f049142..f049142 100644..100755 --- a/client/AndroidClients/LightingController/default.properties +++ b/client/AndroidClients/LightingController/default.properties | |||
diff --git a/client/AndroidClients/LightingController/gen/com/lightingcontroller/BuildConfig.java b/client/AndroidClients/LightingController/gen/com/lightingcontroller/BuildConfig.java index 90eed7d..90eed7d 100644..100755 --- a/client/AndroidClients/LightingController/gen/com/lightingcontroller/BuildConfig.java +++ b/client/AndroidClients/LightingController/gen/com/lightingcontroller/BuildConfig.java | |||
diff --git a/client/AndroidClients/LightingController/gen/com/lightingcontroller/R.java b/client/AndroidClients/LightingController/gen/com/lightingcontroller/R.java index 9a7c7b9..9e0e0d6 100644..100755 --- a/client/AndroidClients/LightingController/gen/com/lightingcontroller/R.java +++ b/client/AndroidClients/LightingController/gen/com/lightingcontroller/R.java | |||
@@ -1,149 +1,151 @@ | |||
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. | 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. |
2 | * | 2 | * |
3 | * This class was automatically generated by the | 3 | * This class was automatically generated by the |
4 | * aapt tool from the resource data it found. It | 4 | * aapt tool from the resource data it found. It |
5 | * should not be modified by hand. | 5 | * should not be modified by hand. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | package com.lightingcontroller; | 8 | package com.lightingcontroller; |
9 | 9 | ||
10 | public final class R { | 10 | public final class R { |
11 | public static final class anim { | 11 | public static final class anim { |
12 | public static final int animation_enter_l=0x7f040000; | 12 | public static final int animation_enter_l=0x7f040000; |
13 | public static final int animation_enter_r=0x7f040001; | 13 | public static final int animation_enter_r=0x7f040001; |
14 | public static final int animation_leave_l=0x7f040002; | 14 | public static final int animation_leave_l=0x7f040002; |
15 | public static final int animation_leave_r=0x7f040003; | 15 | public static final int animation_leave_r=0x7f040003; |
16 | public static final int popup_in=0x7f040004; | 16 | public static final int popup_in=0x7f040004; |
17 | public static final int popup_out=0x7f040005; | 17 | public static final int popup_out=0x7f040005; |
18 | } | 18 | } |
19 | public static final class array { | 19 | public static final class array { |
20 | public static final int BUAD_Rate=0x7f060001; | 20 | public static final int BUAD_Rate=0x7f060001; |
21 | public static final int OSC=0x7f060000; | 21 | public static final int OSC=0x7f060000; |
22 | public static final int Parity_Check=0x7f060002; | 22 | public static final int Parity_Check=0x7f060002; |
23 | } | 23 | } |
24 | public static final class attr { | 24 | public static final class attr { |
25 | } | 25 | } |
26 | public static final class drawable { | 26 | public static final class drawable { |
27 | public static final int background=0x7f020000; | 27 | public static final int background=0x7f020000; |
28 | public static final int butt_down=0x7f020001; | 28 | public static final int butt_down=0x7f020001; |
29 | public static final int butt_high=0x7f020002; | 29 | public static final int butt_high=0x7f020002; |
30 | public static final int butt_norm=0x7f020003; | 30 | public static final int butt_norm=0x7f020003; |
31 | public static final int button9=0x7f020004; | 31 | public static final int button9=0x7f020004; |
32 | public static final int ic_menu_bind=0x7f020005; | 32 | public static final int ic_menu_add=0x7f020005; |
33 | public static final int ic_menu_group=0x7f020006; | 33 | public static final int ic_menu_bind=0x7f020006; |
34 | public static final int ic_menu_list_devices=0x7f020007; | 34 | public static final int ic_menu_group=0x7f020007; |
35 | public static final int ic_menu_scene=0x7f020008; | 35 | public static final int ic_menu_list_devices=0x7f020008; |
36 | public static final int layoutborder=0x7f020009; | 36 | public static final int ic_menu_scene=0x7f020009; |
37 | public static final int popup=0x7f02000a; | 37 | public static final int layoutborder=0x7f02000a; |
38 | public static final int tilogo=0x7f02000b; | 38 | public static final int popup=0x7f02000b; |
39 | public static final int tizllicon=0x7f02000c; | 39 | public static final int tilogo=0x7f02000c; |
40 | } | 40 | public static final int tizllicon=0x7f02000d; |
41 | public static final class id { | 41 | } |
42 | public static final int FrameLable03=0x7f080033; | 42 | public static final class id { |
43 | public static final int FrameLable04=0x7f080028; | 43 | public static final int FrameLable03=0x7f080034; |
44 | public static final int FrameLable06=0x7f08000c; | 44 | public static final int FrameLable04=0x7f080029; |
45 | public static final int IdControlledToggle=0x7f080009; | 45 | public static final int FrameLable06=0x7f08000c; |
46 | public static final int IdControlledToggleText=0x7f08000a; | 46 | public static final int IdControlledToggle=0x7f080009; |
47 | public static final int IdControllingToggle=0x7f080006; | 47 | public static final int IdControlledToggleText=0x7f08000a; |
48 | public static final int IdControllingToggleText=0x7f080007; | 48 | public static final int IdControllingToggle=0x7f080006; |
49 | public static final int IdGroupToggle=0x7f080018; | 49 | public static final int IdControllingToggleText=0x7f080007; |
50 | public static final int IdGroupToggleText=0x7f080019; | 50 | public static final int IdGroupToggle=0x7f080018; |
51 | public static final int IdLightToggle=0x7f080016; | 51 | public static final int IdGroupToggleText=0x7f080019; |
52 | public static final int IdLightToggleText=0x7f080017; | 52 | public static final int IdLightToggle=0x7f080016; |
53 | public static final int addToGroupRadio=0x7f080013; | 53 | public static final int IdLightToggleText=0x7f080017; |
54 | public static final int bindRadio=0x7f08000b; | 54 | public static final int addToGroupRadio=0x7f080013; |
55 | public static final int colourPick=0x7f08002e; | 55 | public static final int bindRadio=0x7f08000b; |
56 | public static final int controlFrame=0x7f08002c; | 56 | public static final int colourPick=0x7f08002f; |
57 | public static final int controlledDeviceSpinner=0x7f080004; | 57 | public static final int controlFrame=0x7f08002d; |
58 | public static final int controllingDeviceSpinner=0x7f080002; | 58 | public static final int controlledDeviceSpinner=0x7f080004; |
59 | public static final int deviceChangeNameButton=0x7f08000f; | 59 | public static final int controllingDeviceSpinner=0x7f080002; |
60 | public static final int deviceFrame=0x7f08002a; | 60 | public static final int deviceChangeNameButton=0x7f08000f; |
61 | public static final int deviceIdLayout=0x7f080005; | 61 | public static final int deviceFrame=0x7f08002b; |
62 | public static final int deviceSpinner=0x7f08000e; | 62 | public static final int deviceIdLayout=0x7f080005; |
63 | public static final int groupIdLayout=0x7f080008; | 63 | public static final int deviceSpinner=0x7f08000e; |
64 | public static final int groupSpinner=0x7f080011; | 64 | public static final int groupIdLayout=0x7f080008; |
65 | public static final int image=0x7f08001f; | 65 | public static final int groupSpinner=0x7f080011; |
66 | public static final int lightIdLayout=0x7f080015; | 66 | public static final int image=0x7f080020; |
67 | public static final int linearLayout1=0x7f08002d; | 67 | public static final int lightIdLayout=0x7f080015; |
68 | public static final int linearLayout1a=0x7f08002f; | 68 | public static final int linearLayout1=0x7f08002e; |
69 | public static final int linearLayout3=0x7f08002b; | 69 | public static final int linearLayout1a=0x7f080030; |
70 | public static final int linearLayout4=0x7f080021; | 70 | public static final int linearLayout3=0x7f08002c; |
71 | public static final int linearLayout6=0x7f080000; | 71 | public static final int linearLayout4=0x7f080022; |
72 | public static final int newGroupRadio=0x7f080012; | 72 | public static final int linearLayout6=0x7f080000; |
73 | public static final int newSceneRadio=0x7f080025; | 73 | public static final int newGroupRadio=0x7f080012; |
74 | public static final int offButton=0x7f080030; | 74 | public static final int newSceneRadio=0x7f080026; |
75 | public static final int onButton=0x7f080032; | 75 | public static final int offButton=0x7f080031; |
76 | public static final int optionMenuBinding=0x7f08001c; | 76 | public static final int onButton=0x7f080033; |
77 | public static final int optionMenuGroups=0x7f08001a; | 77 | public static final int optionMenuAddDevice=0x7f08001a; |
78 | public static final int optionMenuListDevices=0x7f08001d; | 78 | public static final int optionMenuBinding=0x7f08001d; |
79 | public static final int optionMenuScenes=0x7f08001b; | 79 | public static final int optionMenuGroups=0x7f08001b; |
80 | public static final int popup_text_box=0x7f080020; | 80 | public static final int optionMenuListDevices=0x7f08001e; |
81 | public static final int radioGroup2=0x7f080024; | 81 | public static final int optionMenuScenes=0x7f08001c; |
82 | public static final int sceneRadio0=0x7f080014; | 82 | public static final int popup_text_box=0x7f080021; |
83 | public static final int sceneRestoreRadio=0x7f080027; | 83 | public static final int radioGroup2=0x7f080025; |
84 | public static final int sceneSelectSpinner=0x7f080023; | 84 | public static final int sceneRadio0=0x7f080014; |
85 | public static final int sceneStoreRadio=0x7f080026; | 85 | public static final int sceneRestoreRadio=0x7f080028; |
86 | public static final int seekBarLevel=0x7f080031; | 86 | public static final int sceneSelectSpinner=0x7f080024; |
87 | public static final int textViewControl=0x7f080001; | 87 | public static final int sceneStoreRadio=0x7f080027; |
88 | public static final int textViewControlled=0x7f080003; | 88 | public static final int seekBarLevel=0x7f080032; |
89 | public static final int textViewDev=0x7f08000d; | 89 | public static final int textViewControl=0x7f080001; |
90 | public static final int textViewGroup=0x7f080010; | 90 | public static final int textViewControlled=0x7f080003; |
91 | public static final int textViewScene=0x7f080022; | 91 | public static final int textViewDev=0x7f08000d; |
92 | public static final int toast_layout_root=0x7f08001e; | 92 | public static final int textViewGroup=0x7f080010; |
93 | public static final int zllMainLayout=0x7f080029; | 93 | public static final int textViewScene=0x7f080023; |
94 | } | 94 | public static final int toast_layout_root=0x7f08001f; |
95 | public static final class layout { | 95 | public static final int zllMainLayout=0x7f08002a; |
96 | public static final int bindview=0x7f030000; | 96 | } |
97 | public static final int groupview=0x7f030001; | 97 | public static final class layout { |
98 | public static final int main=0x7f030002; | 98 | public static final int bindview=0x7f030000; |
99 | public static final int optionmenu=0x7f030003; | 99 | public static final int groupview=0x7f030001; |
100 | public static final int popup=0x7f030004; | 100 | public static final int main=0x7f030002; |
101 | public static final int sceneview=0x7f030005; | 101 | public static final int optionmenu=0x7f030003; |
102 | public static final int zllmain=0x7f030006; | 102 | public static final int popup=0x7f030004; |
103 | public static final int zllmainportraite=0x7f030007; | 103 | public static final int sceneview=0x7f030005; |
104 | } | 104 | public static final int zllmain=0x7f030006; |
105 | public static final class string { | 105 | public static final int zllmainportraite=0x7f030007; |
106 | public static final int SelectDevice=0x7f050018; | 106 | } |
107 | public static final int SelectGroup=0x7f050019; | 107 | public static final class string { |
108 | public static final int app_name=0x7f050001; | 108 | public static final int SelectDevice=0x7f050018; |
109 | public static final int bt_ConfigInitial=0x7f05000d; | 109 | public static final int SelectGroup=0x7f050019; |
110 | public static final int bt_startrecv=0x7f05000e; | 110 | public static final int app_name=0x7f050001; |
111 | public static final int bt_startsend=0x7f050010; | 111 | public static final int bt_ConfigInitial=0x7f05000d; |
112 | public static final int bt_stoprecv=0x7f05000f; | 112 | public static final int bt_startrecv=0x7f05000e; |
113 | public static final int bt_stopsend=0x7f050011; | 113 | public static final int bt_startsend=0x7f050010; |
114 | public static final int groupAdd=0x7f05001a; | 114 | public static final int bt_stoprecv=0x7f05000f; |
115 | public static final int hello=0x7f050000; | 115 | public static final int bt_stopsend=0x7f050011; |
116 | public static final int lb_BaudRate=0x7f050004; | 116 | public static final int groupAdd=0x7f05001a; |
117 | public static final int lb_SendData=0x7f050003; | 117 | public static final int hello=0x7f050000; |
118 | public static final int lb_osc=0x7f050005; | 118 | public static final int lb_BaudRate=0x7f050004; |
119 | public static final int lb_paritycheck=0x7f050006; | 119 | public static final int lb_SendData=0x7f050003; |
120 | public static final int m_about=0x7f05000b; | 120 | public static final int lb_osc=0x7f050005; |
121 | public static final int m_clear=0x7f05000a; | 121 | public static final int lb_paritycheck=0x7f050006; |
122 | public static final int m_configinitial=0x7f050007; | 122 | public static final int m_about=0x7f05000b; |
123 | public static final int m_quit=0x7f05000c; | 123 | public static final int m_clear=0x7f05000a; |
124 | public static final int m_recvdata=0x7f050009; | 124 | public static final int m_configinitial=0x7f050007; |
125 | public static final int m_senddata=0x7f050008; | 125 | public static final int m_quit=0x7f05000c; |
126 | public static final int optionMenuGroupsTitle=0x7f05001c; | 126 | public static final int m_recvdata=0x7f050009; |
127 | public static final int optionMenuTitle=0x7f05001b; | 127 | public static final int m_senddata=0x7f050008; |
128 | public static final int optionMuneBindingTitle=0x7f05001d; | 128 | public static final int optionMenuGroupsTitle=0x7f05001c; |
129 | public static final int optionMuneListDevicesTitle=0x7f05001e; | 129 | public static final int optionMenuTitle=0x7f05001b; |
130 | public static final int rbt_0=0x7f050012; | 130 | public static final int optionMuneBindingTitle=0x7f05001d; |
131 | public static final int rbt_1=0x7f050013; | 131 | public static final int optionMuneListDevicesTitle=0x7f05001e; |
132 | public static final int rbt_2=0x7f050014; | 132 | public static final int rbt_0=0x7f050012; |
133 | public static final int rbt_3=0x7f050015; | 133 | public static final int rbt_1=0x7f050013; |
134 | public static final int rbt_4=0x7f050016; | 134 | public static final int rbt_2=0x7f050014; |
135 | public static final int str_sendtext=0x7f050017; | 135 | public static final int rbt_3=0x7f050015; |
136 | public static final int textviewMSG=0x7f050002; | 136 | public static final int rbt_4=0x7f050016; |
137 | } | 137 | public static final int str_sendtext=0x7f050017; |
138 | public static final class style { | 138 | public static final int textviewMSG=0x7f050002; |
139 | public static final int Animation_Popup=0x7f070008; | 139 | } |
140 | public static final int ApplicationTheme=0x7f070000; | 140 | public static final class style { |
141 | public static final int DialogMenuText=0x7f070007; | 141 | public static final int Animation_Popup=0x7f070008; |
142 | public static final int SideMenuText=0x7f070006; | 142 | public static final int ApplicationTheme=0x7f070000; |
143 | public static final int StdButton=0x7f070001; | 143 | public static final int DialogMenuText=0x7f070007; |
144 | public static final int StdButtonIcon=0x7f070002; | 144 | public static final int SideMenuText=0x7f070006; |
145 | public static final int StdButtonText=0x7f070003; | 145 | public static final int StdButton=0x7f070001; |
146 | public static final int StdScreen=0x7f070005; | 146 | public static final int StdButtonIcon=0x7f070002; |
147 | public static final int TitleText=0x7f070004; | 147 | public static final int StdButtonText=0x7f070003; |
148 | } | 148 | public static final int StdScreen=0x7f070005; |
149 | } | 149 | public static final int TitleText=0x7f070004; |
150 | } | ||
151 | } | ||
diff --git a/client/AndroidClients/LightingController/lint.xml b/client/AndroidClients/LightingController/lint.xml index ee0eead..ee0eead 100644..100755 --- a/client/AndroidClients/LightingController/lint.xml +++ b/client/AndroidClients/LightingController/lint.xml | |||
diff --git a/client/AndroidClients/LightingController/proguard.cfg b/client/AndroidClients/LightingController/proguard.cfg index b1cdf17..b1cdf17 100644..100755 --- a/client/AndroidClients/LightingController/proguard.cfg +++ b/client/AndroidClients/LightingController/proguard.cfg | |||
diff --git a/client/AndroidClients/LightingController/project.properties b/client/AndroidClients/LightingController/project.properties index f049142..c4f09d2 100644..100755 --- a/client/AndroidClients/LightingController/project.properties +++ b/client/AndroidClients/LightingController/project.properties | |||
@@ -8,4 +8,4 @@ | |||
8 | # project structure. | 8 | # project structure. |
9 | 9 | ||
10 | # Project target. | 10 | # Project target. |
11 | target=android-10 | 11 | target=android-17 |
diff --git a/client/AndroidClients/LightingController/res/anim/animation_enter_l.xml b/client/AndroidClients/LightingController/res/anim/animation_enter_l.xml index 2ae2e85..2ae2e85 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/animation_enter_l.xml +++ b/client/AndroidClients/LightingController/res/anim/animation_enter_l.xml | |||
diff --git a/client/AndroidClients/LightingController/res/anim/animation_enter_r.xml b/client/AndroidClients/LightingController/res/anim/animation_enter_r.xml index 3135e3f..3135e3f 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/animation_enter_r.xml +++ b/client/AndroidClients/LightingController/res/anim/animation_enter_r.xml | |||
diff --git a/client/AndroidClients/LightingController/res/anim/animation_leave_l.xml b/client/AndroidClients/LightingController/res/anim/animation_leave_l.xml index 43fc169..43fc169 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/animation_leave_l.xml +++ b/client/AndroidClients/LightingController/res/anim/animation_leave_l.xml | |||
diff --git a/client/AndroidClients/LightingController/res/anim/animation_leave_r.xml b/client/AndroidClients/LightingController/res/anim/animation_leave_r.xml index 2ea3679..2ea3679 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/animation_leave_r.xml +++ b/client/AndroidClients/LightingController/res/anim/animation_leave_r.xml | |||
diff --git a/client/AndroidClients/LightingController/res/anim/popup_in.xml b/client/AndroidClients/LightingController/res/anim/popup_in.xml index e4a81a7..e4a81a7 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/popup_in.xml +++ b/client/AndroidClients/LightingController/res/anim/popup_in.xml | |||
diff --git a/client/AndroidClients/LightingController/res/anim/popup_out.xml b/client/AndroidClients/LightingController/res/anim/popup_out.xml index c836a1d..c836a1d 100644..100755 --- a/client/AndroidClients/LightingController/res/anim/popup_out.xml +++ b/client/AndroidClients/LightingController/res/anim/popup_out.xml | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_add.png b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_add.png new file mode 100755 index 0000000..3fa5552 --- /dev/null +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_add.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_bind.png b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_bind.png index 26f8634..26f8634 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_bind.png +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_bind.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_group.png b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_group.png index 8a09995..8a09995 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_group.png +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_group.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_list_devices.png b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_list_devices.png index c028b9b..c028b9b 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_list_devices.png +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_list_devices.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_scene.png b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_scene.png index 24680db..24680db 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_scene.png +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_scene.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/layoutborder.xml b/client/AndroidClients/LightingController/res/drawable-hdpi/layoutborder.xml index c6f17c0..c6f17c0 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/layoutborder.xml +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/layoutborder.xml | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-hdpi/tizllicon.bmp b/client/AndroidClients/LightingController/res/drawable-hdpi/tizllicon.bmp index 4865c01..4865c01 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-hdpi/tizllicon.bmp +++ b/client/AndroidClients/LightingController/res/drawable-hdpi/tizllicon.bmp | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-ldpi/layoutborder.xml b/client/AndroidClients/LightingController/res/drawable-ldpi/layoutborder.xml index 5ccef86..5ccef86 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-ldpi/layoutborder.xml +++ b/client/AndroidClients/LightingController/res/drawable-ldpi/layoutborder.xml | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-ldpi/tizllicon.bmp b/client/AndroidClients/LightingController/res/drawable-ldpi/tizllicon.bmp index 4865c01..4865c01 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-ldpi/tizllicon.bmp +++ b/client/AndroidClients/LightingController/res/drawable-ldpi/tizllicon.bmp | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/background.png b/client/AndroidClients/LightingController/res/drawable-mdpi/background.png index 6ab5e01..6ab5e01 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/background.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/background.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_down.9.png b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_down.9.png index c9047bb..c9047bb 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_down.9.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_down.9.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_high.9.png b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_high.9.png index ba40527..ba40527 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_high.9.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_high.9.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_norm.9.png b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_norm.9.png index 3e42a60..3e42a60 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/butt_norm.9.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/butt_norm.9.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/button9.xml b/client/AndroidClients/LightingController/res/drawable-mdpi/button9.xml index efc7c1e..efc7c1e 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/button9.xml +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/button9.xml | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/popup.9.png b/client/AndroidClients/LightingController/res/drawable-mdpi/popup.9.png index 5f6e24d..5f6e24d 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/popup.9.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/popup.9.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/tilogo.png b/client/AndroidClients/LightingController/res/drawable-mdpi/tilogo.png index 1da4b85..1da4b85 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/tilogo.png +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/tilogo.png | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/drawable-mdpi/tizllicon.bmp b/client/AndroidClients/LightingController/res/drawable-mdpi/tizllicon.bmp index 4865c01..4865c01 100644..100755 --- a/client/AndroidClients/LightingController/res/drawable-mdpi/tizllicon.bmp +++ b/client/AndroidClients/LightingController/res/drawable-mdpi/tizllicon.bmp | |||
Binary files differ | |||
diff --git a/client/AndroidClients/LightingController/res/layout/bindview.xml b/client/AndroidClients/LightingController/res/layout/bindview.xml index 382791d..382791d 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/bindview.xml +++ b/client/AndroidClients/LightingController/res/layout/bindview.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/groupview.xml b/client/AndroidClients/LightingController/res/layout/groupview.xml index 73c93c0..73c93c0 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/groupview.xml +++ b/client/AndroidClients/LightingController/res/layout/groupview.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/main.xml b/client/AndroidClients/LightingController/res/layout/main.xml index df10bf5..df10bf5 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/main.xml +++ b/client/AndroidClients/LightingController/res/layout/main.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/optionmenu.xml b/client/AndroidClients/LightingController/res/layout/optionmenu.xml index 3a9f65b..29973bf 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/optionmenu.xml +++ b/client/AndroidClients/LightingController/res/layout/optionmenu.xml | |||
@@ -4,6 +4,8 @@ | |||
4 | android:layout_height="wrap_content" | 4 | android:layout_height="wrap_content" |
5 | android:maxRows="1" | 5 | android:maxRows="1" |
6 | android:maxItemsPerRow="6" > | 6 | android:maxItemsPerRow="6" > |
7 | <item android:id="@+id/optionMenuAddDevice" | ||
8 | android:icon="@drawable/ic_menu_add" /> | ||
7 | <item android:id="@+id/optionMenuGroups" | 9 | <item android:id="@+id/optionMenuGroups" |
8 | android:icon="@drawable/ic_menu_group" /> | 10 | android:icon="@drawable/ic_menu_group" /> |
9 | <item android:id="@+id/optionMenuScenes" | 11 | <item android:id="@+id/optionMenuScenes" |
@@ -11,5 +13,5 @@ | |||
11 | <item android:id="@+id/optionMenuBinding" | 13 | <item android:id="@+id/optionMenuBinding" |
12 | android:icon="@drawable/ic_menu_bind" /> | 14 | android:icon="@drawable/ic_menu_bind" /> |
13 | <item android:id="@+id/optionMenuListDevices" | 15 | <item android:id="@+id/optionMenuListDevices" |
14 | android:icon="@drawable/ic_menu_list_devices" /> | 16 | android:icon="@drawable/ic_menu_list_devices" /> |
15 | </menu> | 17 | </menu> |
diff --git a/client/AndroidClients/LightingController/res/layout/popup.xml b/client/AndroidClients/LightingController/res/layout/popup.xml index 0ac1cdb..0ac1cdb 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/popup.xml +++ b/client/AndroidClients/LightingController/res/layout/popup.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/sceneview.xml b/client/AndroidClients/LightingController/res/layout/sceneview.xml index 55c3ac5..55c3ac5 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/sceneview.xml +++ b/client/AndroidClients/LightingController/res/layout/sceneview.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/zllmain.xml b/client/AndroidClients/LightingController/res/layout/zllmain.xml index 819e783..819e783 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/zllmain.xml +++ b/client/AndroidClients/LightingController/res/layout/zllmain.xml | |||
diff --git a/client/AndroidClients/LightingController/res/layout/zllmainportraite.xml b/client/AndroidClients/LightingController/res/layout/zllmainportraite.xml index f2038fc..f2038fc 100644..100755 --- a/client/AndroidClients/LightingController/res/layout/zllmainportraite.xml +++ b/client/AndroidClients/LightingController/res/layout/zllmainportraite.xml | |||
diff --git a/client/AndroidClients/LightingController/res/values/strings.xml b/client/AndroidClients/LightingController/res/values/strings.xml index 4a3186b..4a3186b 100644..100755 --- a/client/AndroidClients/LightingController/res/values/strings.xml +++ b/client/AndroidClients/LightingController/res/values/strings.xml | |||
diff --git a/client/AndroidClients/LightingController/res/values/styles.xml b/client/AndroidClients/LightingController/res/values/styles.xml index 37cae65..37cae65 100644..100755 --- a/client/AndroidClients/LightingController/res/values/styles.xml +++ b/client/AndroidClients/LightingController/res/values/styles.xml | |||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/ColourPicker.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/ColourPicker.java index b6bbb30..b6bbb30 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/ColourPicker.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/ColourPicker.java | |||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/LightingController.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/LightingController.java index 8c787fd..4ee66fd 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/LightingController.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/LightingController.java | |||
@@ -145,7 +145,7 @@ public class LightingController extends Activity{ | |||
145 | ZigbeeSrpcClient.discoverGroups(); | 145 | ZigbeeSrpcClient.discoverGroups(); |
146 | ZigbeeSrpcClient.discoverScenes(); | 146 | ZigbeeSrpcClient.discoverScenes(); |
147 | //wait for responses | 147 | //wait for responses |
148 | try { TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException e) {e.printStackTrace();} | 148 | try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) {e.printStackTrace();} |
149 | 149 | ||
150 | startActivity(new Intent(LightingController.this, zllMain.class)); | 150 | startActivity(new Intent(LightingController.this, zllMain.class)); |
151 | } | 151 | } |
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeAssistant.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeAssistant.java index bfe52aa..29aed19 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeAssistant.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeAssistant.java | |||
@@ -41,7 +41,7 @@ | |||
41 | package com.lightingcontroller.Zigbee; | 41 | package com.lightingcontroller.Zigbee; |
42 | 42 | ||
43 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
44 | import java.util.Calendar; | 44 | import java.util.Arrays; |
45 | import java.util.HashMap; | 45 | import java.util.HashMap; |
46 | import java.util.List; | 46 | import java.util.List; |
47 | 47 | ||
@@ -54,15 +54,11 @@ import android.widget.Toast; | |||
54 | 54 | ||
55 | public class ZigbeeAssistant implements Runnable { | 55 | public class ZigbeeAssistant implements Runnable { |
56 | 56 | ||
57 | //public static final boolean USE_JNI = true; | ||
58 | public static final boolean USE_JNI = false; | ||
59 | |||
60 | public static boolean gateWayConnected = false; | 57 | public static boolean gateWayConnected = false; |
61 | public static boolean initializing = true; | 58 | public static boolean initializing = true; |
62 | 59 | ||
63 | private static String TAG = "ZigbeeAssistant"; | 60 | private static String TAG = "ZigbeeAssistant"; |
64 | public static ZigbeeSrpcClient zigbeeSrpcClient; | 61 | public static ZigbeeSrpcClient zigbeeSrpcClient; |
65 | public static String ZigbeeSrpcClientGatewayIp = "192.168.1.220"; | ||
66 | 62 | ||
67 | static Thread thread; | 63 | static Thread thread; |
68 | static Activity mainAct; | 64 | static Activity mainAct; |
@@ -73,15 +69,9 @@ public class ZigbeeAssistant implements Runnable { | |||
73 | 69 | ||
74 | private static int LightDeviceIdx = 0; | 70 | private static int LightDeviceIdx = 0; |
75 | 71 | ||
76 | static public int lastTempReading = 65535; | ||
77 | static public List<Integer> powerReadings = new ArrayList<Integer>(); | ||
78 | static public List<Long> powerReadingsTimes = new ArrayList<Long>(); | ||
79 | static public HashMap<Short,Long> nwrkToIEEE = new HashMap<Short,Long>(); | 72 | static public HashMap<Short,Long> nwrkToIEEE = new HashMap<Short,Long>(); |
80 | 73 | ||
81 | public static native int runMain(); | 74 | public static native int runMain(); |
82 | public static native boolean isRunning(); | ||
83 | public static native short requestThermostatReading(short networkaddr, char end); // Get ThermostatReading | ||
84 | public static native short requestPowerReading(short networkaddr, char end); // Get ThermostatReading | ||
85 | public static native void setDeviceState(short networkaddr, char end, boolean state); // Set device state on/off | 75 | public static native void setDeviceState(short networkaddr, char end, boolean state); // Set device state on/off |
86 | public static native void setDeviceLevel(short networkaddr, char end, char level, short transitionTime); // Set device level/dim | 76 | public static native void setDeviceLevel(short networkaddr, char end, char level, short transitionTime); // Set device level/dim |
87 | public static native void setDeviceColour(short networkaddr, char end, char hue, char saturation, short transitionTime); // Set device Color | 77 | public static native void setDeviceColour(short networkaddr, char end, char hue, char saturation, short transitionTime); // Set device Color |
@@ -90,19 +80,17 @@ public class ZigbeeAssistant implements Runnable { | |||
90 | short network_b, char end_b, int ieel_b, int ieeh_b, | 80 | short network_b, char end_b, int ieel_b, int ieeh_b, |
91 | short clusterId); // Bind Devices | 81 | short clusterId); // Bind Devices |
92 | 82 | ||
83 | static final byte EP_INFO_TYPE_EXISTING = 0; | ||
84 | static final byte EP_INFO_TYPE_NEW = 1; | ||
85 | static final byte EP_INFO_TYPE_UPDATED = 2; | ||
86 | static final byte EP_INFO_TYPE_REMOVED = 4; | ||
93 | 87 | ||
88 | static int cnt = 0; | ||
94 | 89 | ||
95 | static | 90 | public static void enableNotify(Activity activity, int timeOut) |
96 | { | 91 | { |
97 | if(USE_JNI) | 92 | ZigbeeNotification.init(activity); |
98 | System.loadLibrary("zigbee_assistant_jni"); //Loading native library | 93 | } |
99 | |||
100 | } | ||
101 | |||
102 | public static void notifyUser(String s) | ||
103 | { | ||
104 | ZigbeeNotification.showNotification(s); | ||
105 | } | ||
106 | 94 | ||
107 | public static List<ZigbeeDevice> getDevices() | 95 | public static List<ZigbeeDevice> getDevices() |
108 | { | 96 | { |
@@ -111,9 +99,6 @@ public class ZigbeeAssistant implements Runnable { | |||
111 | 99 | ||
112 | public static void addGroup(ZigbeeDevice d, String groupName ) | 100 | public static void addGroup(ZigbeeDevice d, String groupName ) |
113 | { | 101 | { |
114 | //ZigbeeGroup newGroup = new ZigbeeGroup(groupName); | ||
115 | //ourGroups.add(newGroup); | ||
116 | |||
117 | ZigbeeSrpcClient.addGroup((short) d.NetworkAddr,d.EndPoint, groupName); | 102 | ZigbeeSrpcClient.addGroup((short) d.NetworkAddr,d.EndPoint, groupName); |
118 | } | 103 | } |
119 | 104 | ||
@@ -142,60 +127,48 @@ public class ZigbeeAssistant implements Runnable { | |||
142 | return ourScenes; | 127 | return ourScenes; |
143 | } | 128 | } |
144 | 129 | ||
145 | public static void deviceAnnounce(int nwrk, long ieee1) | 130 | public static void newDevice(int ProfileId, int DeviceId, int NetworkAddr, char EndPoint, byte ieee[], String deviceName, byte newDevFlag) |
146 | { | ||
147 | // TODO Auto-generated method stub | ||
148 | |||
149 | if (nwrkToIEEE.containsKey(nwrk)) | ||
150 | nwrkToIEEE.remove(nwrk); | ||
151 | nwrkToIEEE.put((short)nwrk, ieee1); | ||
152 | } | ||
153 | |||
154 | |||
155 | public static void deviceAnnounce(int nwrk, int ieee1, int ieee2) | ||
156 | { | 131 | { |
157 | long t2; | 132 | //find old device |
158 | long t = (((long)ieee2))<<32; | 133 | ZigbeeDevice device = getDevice(ieee, EndPoint); |
159 | 134 | ||
160 | if(ieee1 < 0) | 135 | if(newDevFlag != EP_INFO_TYPE_REMOVED) |
161 | { | 136 | { |
162 | long t3 = 2147483647; | 137 | if(device != null) |
163 | t3 = t3 + 2147483647; | 138 | { |
164 | t3 = t3 + 2; | 139 | ZigbeeDevice newDevice = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint, ieee, deviceName, LightDeviceIdx++); |
165 | t2 = (((long)ieee1)); | 140 | device.updateDevice(newDevice); |
166 | t2 = t2+t3; | 141 | } |
142 | else | ||
143 | { | ||
144 | device = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint, ieee, deviceName, LightDeviceIdx++); | ||
145 | ourDevices.add(device); | ||
146 | } | ||
167 | } | 147 | } |
168 | else | 148 | else |
169 | { | 149 | { |
170 | t2 = ieee1; | 150 | if(device != null) |
171 | } | 151 | { |
172 | t = t | t2; | 152 | ourDevices.remove(device); |
173 | if (nwrkToIEEE.containsKey(nwrk)) | 153 | if(device.hasColourable || device.hasSwitchable || device.hasDimmable) |
174 | nwrkToIEEE.remove(nwrk); | 154 | { |
175 | nwrkToIEEE.put((short)nwrk, t); | 155 | ZigbeeNotification.showRemoveDeviceNotification(device.Name, 5000); |
176 | } | 156 | } |
177 | 157 | } | |
178 | public static void newDevice(int ProfileId, int DeviceId, int NetworkAddr, char EndPoint, byte ieee[], String deviceName) | ||
179 | { | ||
180 | ZigbeeDevice oldD = ifDeviceExists(NetworkAddr,EndPoint); | ||
181 | if (oldD != null) | ||
182 | { | ||
183 | if (oldD.ProfileId == ProfileId) | ||
184 | return; | ||
185 | oldD = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint, ieee, deviceName, LightDeviceIdx++); | ||
186 | return; | ||
187 | } | 158 | } |
188 | ZigbeeDevice newDevice = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint, ieee, deviceName, LightDeviceIdx++); | 159 | |
189 | ourDevices.add(newDevice); | 160 | if( (newDevFlag == EP_INFO_TYPE_NEW) && (device.hasColourable || device.hasSwitchable || device.hasDimmable)) |
161 | { | ||
162 | ZigbeeNotification.showNewDeviceNotification(device); | ||
163 | } | ||
190 | } | 164 | } |
191 | 165 | ||
192 | public static void newGroup( String groupName ) | 166 | public static void newGroup( String groupName ) |
193 | { | 167 | { |
194 | ZigbeeGroup newGroup = new ZigbeeGroup(groupName); | 168 | ZigbeeGroup newGroup = new ZigbeeGroup(groupName); |
195 | ourGroups.add(newGroup); | 169 | ourGroups.add(newGroup); |
196 | 170 | ||
197 | //Create new group on gateway (with invalid nwkAddr so not device is added to the group) | 171 | //Group will not be created on the GW until a device is added |
198 | ZigbeeSrpcClient.addGroup((short) 0xFFFF, (char) 0xFF, groupName); | ||
199 | } | 172 | } |
200 | 173 | ||
201 | public static void newGroup(String groupName, int groupId, int status) | 174 | public static void newGroup(String groupName, int groupId, int status) |
@@ -253,9 +226,8 @@ public class ZigbeeAssistant implements Runnable { | |||
253 | if(ourScenes.contains(newScene) == false) | 226 | if(ourScenes.contains(newScene) == false) |
254 | { | 227 | { |
255 | ourScenes.add(newScene); | 228 | ourScenes.add(newScene); |
256 | } | 229 | } |
257 | 230 | //Scene will not be created on the GW until scene is stored | |
258 | ZigbeeSrpcClient.storeScene( sceneName, groupId ); | ||
259 | } | 231 | } |
260 | 232 | ||
261 | public static boolean bindDevicesOnOff(ZigbeeDevice a, ZigbeeDevice b) | 233 | public static boolean bindDevicesOnOff(ZigbeeDevice a, ZigbeeDevice b) |
@@ -301,6 +273,11 @@ public class ZigbeeAssistant implements Runnable { | |||
301 | ZigbeeSrpcClient.changeDeviceName(d, newName); | 273 | ZigbeeSrpcClient.changeDeviceName(d, newName); |
302 | } | 274 | } |
303 | } | 275 | } |
276 | |||
277 | public static void openNetwork(byte duration) | ||
278 | { | ||
279 | ZigbeeSrpcClient.openNetwork(duration); | ||
280 | } | ||
304 | 281 | ||
305 | public static ZigbeeDevice ifDeviceExists(int NetworkAddr, char EndPoint) | 282 | public static ZigbeeDevice ifDeviceExists(int NetworkAddr, char EndPoint) |
306 | { | 283 | { |
@@ -319,6 +296,23 @@ public class ZigbeeAssistant implements Runnable { | |||
319 | return ret; | 296 | return ret; |
320 | } | 297 | } |
321 | 298 | ||
299 | public static ZigbeeDevice getDevice(byte ieee[], char EndPoint) | ||
300 | { | ||
301 | int last = ourDevices.size()-1; | ||
302 | int i = last; | ||
303 | ZigbeeDevice ret = null; | ||
304 | for (i = last ; i >= 0 ; i--) | ||
305 | { | ||
306 | ret = ourDevices.get(i); | ||
307 | if( (Arrays.equals(ret.Ieee, ieee)) && (ret.EndPoint == EndPoint)) | ||
308 | break; | ||
309 | } | ||
310 | if (i < 0) | ||
311 | return null; | ||
312 | else | ||
313 | return ret; | ||
314 | } | ||
315 | |||
322 | public static boolean hasAnySwitchers() | 316 | public static boolean hasAnySwitchers() |
323 | { | 317 | { |
324 | for (int i = 0 ; i < ourDevices.size() ; i++) | 318 | for (int i = 0 ; i < ourDevices.size() ; i++) |
@@ -330,18 +324,6 @@ public class ZigbeeAssistant implements Runnable { | |||
330 | return false; | 324 | return false; |
331 | } | 325 | } |
332 | 326 | ||
333 | public static void newDeviceCluster(int NetworkAddr, char EndPoint, boolean in, int ClusterId) | ||
334 | { | ||
335 | ZigbeeDevice toAddto = ifDeviceExists(NetworkAddr, EndPoint); | ||
336 | if (toAddto == null) | ||
337 | { | ||
338 | Log.w(TAG, "Couldn't find Device"); | ||
339 | return; | ||
340 | } | ||
341 | |||
342 | toAddto.addCluster(in, ClusterId); | ||
343 | } | ||
344 | |||
345 | public ZigbeeAssistant() | 327 | public ZigbeeAssistant() |
346 | { | 328 | { |
347 | ourDevices.clear(); | 329 | ourDevices.clear(); |
@@ -363,11 +345,7 @@ public class ZigbeeAssistant implements Runnable { | |||
363 | if (d.hasDimmable) | 345 | if (d.hasDimmable) |
364 | s+="\t: Dimmable\n"; | 346 | s+="\t: Dimmable\n"; |
365 | if (d.hasColourable) | 347 | if (d.hasColourable) |
366 | s+="\t: Colourable\n"; | 348 | s+="\t: Colourable\n"; |
367 | if (d.hasThermometer) | ||
368 | s+="\t: Measures Temperature\n"; | ||
369 | if (d.hasPowerUsage) | ||
370 | s+="\t: Measures Power Usage\n"; | ||
371 | if (d.hasOutSwitch) | 349 | if (d.hasOutSwitch) |
372 | s+="\t: Switches Others\n"; | 350 | s+="\t: Switches Others\n"; |
373 | if (d.hasOutLeveL) | 351 | if (d.hasOutLeveL) |
@@ -406,17 +384,20 @@ public class ZigbeeAssistant implements Runnable { | |||
406 | return s; | 384 | return s; |
407 | } | 385 | } |
408 | 386 | ||
409 | public static void haveTemperature(int NetworkAddr, char EndPoint, int data) | 387 | public static void IdentifyDevice(ZigbeeDevice d, short identifyTime) |
388 | { | ||
389 | ZigbeeSrpcClient.IdentifyDevice((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, identifyTime); | ||
390 | } | ||
391 | |||
392 | public static void IdentifyGroup(ZigbeeGroup g, short identifyTime) | ||
410 | { | 393 | { |
411 | lastTempReading = data; | 394 | ZigbeeSrpcClient.IdentifyDevice((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char)0xFF, identifyTime); |
412 | } | 395 | } |
413 | 396 | ||
414 | public static void setDeviceState(ZigbeeDevice d, boolean state) | 397 | public static void setDeviceState(ZigbeeDevice d, boolean state) |
415 | { | 398 | { |
416 | if(USE_JNI) | 399 | |
417 | setDeviceState((short) d.NetworkAddr,d.EndPoint,state); | 400 | ZigbeeSrpcClient.setDeviceState((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,state); |
418 | else | ||
419 | ZigbeeSrpcClient.setDeviceState((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,state); | ||
420 | } | 401 | } |
421 | 402 | ||
422 | public static void setDeviceState(ZigbeeGroup g, boolean state) | 403 | public static void setDeviceState(ZigbeeGroup g, boolean state) |
@@ -428,23 +409,17 @@ public class ZigbeeAssistant implements Runnable { | |||
428 | { | 409 | { |
429 | float[] hsv = new float[3]; | 410 | float[] hsv = new float[3]; |
430 | Color.colorToHSV(colour, hsv); | 411 | Color.colorToHSV(colour, hsv); |
431 | if (USE_JNI) | 412 | ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10); |
432 | setDeviceColour((short) d.NetworkAddr,d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10); | ||
433 | else | ||
434 | ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10); | ||
435 | } | 413 | } |
436 | 414 | ||
437 | public static void setDeviceHueSat(ZigbeeDevice d, byte hue, byte sat) | 415 | public static void setDeviceHueSat(ZigbeeDevice d, byte hue, byte sat) |
438 | { | 416 | { |
439 | if (USE_JNI) | 417 | ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, (char) hue, (char) sat,(short)10); |
440 | setDeviceColour((short) d.NetworkAddr,d.EndPoint,(char) hue, (char) sat,(short)10); | ||
441 | else | ||
442 | ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, (char) hue, (char) sat,(short)10); | ||
443 | } | 418 | } |
444 | 419 | ||
445 | public static void setDeviceHueSat(ZigbeeGroup g, byte hue, byte sat) | 420 | public static void setDeviceHueSat(ZigbeeGroup g, byte hue, byte sat) |
446 | { | 421 | { |
447 | ZigbeeSrpcClient.setDeviceColor((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF, (char) hue, (char) sat,(short)10); | 422 | ZigbeeSrpcClient.setDeviceColor((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF, (char) hue, (char) sat,(short)10); |
448 | } | 423 | } |
449 | 424 | ||
450 | public static void setDeviceLevel(ZigbeeDevice d, int colour) | 425 | public static void setDeviceLevel(ZigbeeDevice d, int colour) |
@@ -456,15 +431,12 @@ public class ZigbeeAssistant implements Runnable { | |||
456 | 431 | ||
457 | public static void setDeviceLevel(ZigbeeDevice d, char level) | 432 | public static void setDeviceLevel(ZigbeeDevice d, char level) |
458 | { | 433 | { |
459 | if(USE_JNI) | 434 | ZigbeeSrpcClient.setDeviceLevel((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,level,(short)10); |
460 | setDeviceLevel((short) d.NetworkAddr,d.EndPoint,level,(short)10); | ||
461 | else | ||
462 | ZigbeeSrpcClient.setDeviceLevel((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,level,(short)10); | ||
463 | } | 435 | } |
464 | 436 | ||
465 | public static void setDeviceLevel(ZigbeeGroup g, char level) | 437 | public static void setDeviceLevel(ZigbeeGroup g, char level) |
466 | { | 438 | { |
467 | ZigbeeSrpcClient.setDeviceLevel((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF,level,(short)10); | 439 | ZigbeeSrpcClient.setDeviceLevel((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF,level,(short)10); |
468 | } | 440 | } |
469 | 441 | ||
470 | public static void getDeviceState(ZigbeeDevice d) | 442 | public static void getDeviceState(ZigbeeDevice d) |
@@ -488,20 +460,7 @@ public class ZigbeeAssistant implements Runnable { | |||
488 | } | 460 | } |
489 | 461 | ||
490 | public void run() { | 462 | public void run() { |
491 | if(USE_JNI) | 463 | Log.d(TAG, "Begin Zigbee"); |
492 | { | 464 | zigbeeSrpcClient = new ZigbeeSrpcClient(); |
493 | Log.d(TAG, "Begin Zigbee"); | ||
494 | final int returnvalue = runMain(); | ||
495 | mainAct.runOnUiThread(new Runnable() { | ||
496 | public void run() { | ||
497 | Toast.makeText(mainAct, "Zigbee has failed ("+returnvalue+") \n - Is the dongle connected and chmodded?", Toast.LENGTH_LONG).show(); | ||
498 | } | ||
499 | }); | ||
500 | } | ||
501 | else | ||
502 | { | ||
503 | Log.d(TAG, "Begin Zigbee"); | ||
504 | zigbeeSrpcClient = new ZigbeeSrpcClient(); | ||
505 | } | ||
506 | } | 465 | } |
507 | } | 466 | } |
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeDevice.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeDevice.java index 4ff3119..8076bca 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeDevice.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeDevice.java | |||
@@ -62,8 +62,6 @@ public class ZigbeeDevice { | |||
62 | public boolean hasColourable = false; | 62 | public boolean hasColourable = false; |
63 | public boolean hasDimmable = false; | 63 | public boolean hasDimmable = false; |
64 | public boolean hasSwitchable = false; | 64 | public boolean hasSwitchable = false; |
65 | public boolean hasThermometer = false; | ||
66 | public boolean hasPowerUsage = false; | ||
67 | public boolean hasOutSwitch = false; | 65 | public boolean hasOutSwitch = false; |
68 | public boolean hasOutLeveL = false; | 66 | public boolean hasOutLeveL = false; |
69 | public boolean hasOutColor = false; | 67 | public boolean hasOutColor = false; |
@@ -374,22 +372,37 @@ public class ZigbeeDevice { | |||
374 | default: Type = "Unknown Device"; Name="Unknown"; | 372 | default: Type = "Unknown Device"; Name="Unknown"; |
375 | } | 373 | } |
376 | } | 374 | } |
377 | 375 | ||
378 | //String notification = "New "+Type+" connected!"; | 376 | if(!_deviceName.isEmpty()) |
379 | //ZigbeeNotification.showNotification(notification); | 377 | { |
378 | Name = _deviceName; | ||
379 | } | ||
380 | } | 380 | } |
381 | 381 | ||
382 | public void updateDevice(ZigbeeDevice device) | ||
383 | { | ||
384 | Name = device.Name; | ||
385 | Type = device.Type; | ||
386 | ProfileId = device.ProfileId; | ||
387 | DeviceId = device.DeviceId; | ||
388 | NetworkAddr = device.NetworkAddr; | ||
389 | hasColourable = device.hasColourable; | ||
390 | hasDimmable = device.hasDimmable; | ||
391 | hasSwitchable = device.hasSwitchable; | ||
392 | hasOutLeveL = device.hasOutLeveL; | ||
393 | hasOutScene = device.hasOutScene; | ||
394 | hasOutGroup = device.hasOutGroup; | ||
395 | } | ||
396 | |||
382 | public void addCluster(boolean in, int ClusterId) | 397 | public void addCluster(boolean in, int ClusterId) |
383 | { | 398 | { |
384 | if (in) | 399 | if (in) |
385 | { | 400 | { |
386 | switch (ClusterId) | 401 | switch (ClusterId) |
387 | { | 402 | { |
388 | case (0x0402): hasThermometer = true; break; | ||
389 | case (0x0006): hasSwitchable = true; break; | 403 | case (0x0006): hasSwitchable = true; break; |
390 | case (0x0008): hasDimmable = true; break; | 404 | case (0x0008): hasDimmable = true; break; |
391 | case (0x0300): hasColourable = true; break; | 405 | case (0x0300): hasColourable = true; break; |
392 | case (0x0702): hasPowerUsage = true; break; | ||
393 | } | 406 | } |
394 | } else | 407 | } else |
395 | { | 408 | { |
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeGroup.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeGroup.java index cb87ac6..cb87ac6 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeGroup.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeGroup.java | |||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeNotification.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeNotification.java index 88a7c33..57bf439 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeNotification.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeNotification.java | |||
@@ -1,197 +1,278 @@ | |||
1 | /************************************************************************************************** | 1 | /************************************************************************************************** |
2 | Filename: ZigBeeNotification.java | 2 | Filename: ZigBeeNotification.java |
3 | Revised: $$ | 3 | Revised: $$ |
4 | Revision: $$ | 4 | Revision: $$ |
5 | 5 | ||
6 | Description: ZigBee Notification Class | 6 | Description: ZigBee Notification Class |
7 | 7 | ||
8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ | 8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ |
9 | 9 | ||
10 | 10 | ||
11 | Redistribution and use in source and binary forms, with or without | 11 | Redistribution and use in source and binary forms, with or without |
12 | modification, are permitted provided that the following conditions | 12 | modification, are permitted provided that the following conditions |
13 | are met: | 13 | are met: |
14 | 14 | ||
15 | Redistributions of source code must retain the above copyright | 15 | Redistributions of source code must retain the above copyright |
16 | notice, this list of conditions and the following disclaimer. | 16 | notice, this list of conditions and the following disclaimer. |
17 | 17 | ||
18 | Redistributions in binary form must reproduce the above copyright | 18 | Redistributions in binary form must reproduce the above copyright |
19 | notice, this list of conditions and the following disclaimer in the | 19 | notice, this list of conditions and the following disclaimer in the |
20 | documentation and/or other materials provided with the | 20 | documentation and/or other materials provided with the |
21 | distribution. | 21 | distribution. |
22 | 22 | ||
23 | Neither the name of Texas Instruments Incorporated nor the names of | 23 | Neither the name of Texas Instruments Incorporated nor the names of |
24 | its contributors may be used to endorse or promote products derived | 24 | its contributors may be used to endorse or promote products derived |
25 | from this software without specific prior written permission. | 25 | from this software without specific prior written permission. |
26 | 26 | ||
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | 38 | ||
39 | **************************************************************************************************/ | 39 | **************************************************************************************************/ |
40 | 40 | ||
41 | package com.lightingcontroller.Zigbee; | 41 | package com.lightingcontroller.Zigbee; |
42 | 42 | ||
43 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
44 | 44 | import java.util.List; | |
45 | import com.lightingcontroller.R; | 45 | |
46 | 46 | import com.lightingcontroller.R; | |
47 | import android.app.Activity; | 47 | import com.lightingcontroller.zllMain; |
48 | import android.app.AlertDialog; | 48 | |
49 | import android.content.DialogInterface; | 49 | import android.app.Activity; |
50 | import android.graphics.Color; | 50 | import android.app.AlertDialog; |
51 | import android.graphics.drawable.BitmapDrawable; | 51 | import android.app.AlertDialog.Builder; |
52 | import android.os.Handler; | 52 | import android.app.Dialog; |
53 | import android.util.AttributeSet; | 53 | import android.content.DialogInterface; |
54 | import android.view.Gravity; | 54 | import android.content.Intent; |
55 | import android.view.LayoutInflater; | 55 | import android.graphics.Color; |
56 | import android.view.MotionEvent; | 56 | import android.graphics.drawable.BitmapDrawable; |
57 | import android.view.View; | 57 | import android.os.Handler; |
58 | import android.view.View.OnClickListener; | 58 | import android.view.Gravity; |
59 | import android.view.View.OnTouchListener; | 59 | import android.view.LayoutInflater; |
60 | import android.view.ViewGroup; | 60 | import android.view.MotionEvent; |
61 | import android.widget.ImageView; | 61 | import android.view.View; |
62 | import android.widget.LinearLayout; | 62 | import android.view.View.OnTouchListener; |
63 | import android.widget.PopupWindow; | 63 | import android.view.ViewGroup; |
64 | import android.widget.TextView; | 64 | import android.widget.EditText; |
65 | import android.widget.Toast; | 65 | import android.widget.LinearLayout; |
66 | 66 | import android.widget.PopupWindow; | |
67 | public class ZigbeeNotification { | 67 | import android.widget.TextView; |
68 | 68 | ||
69 | static Activity acty; | 69 | public class ZigbeeNotification { |
70 | static Handler handle = new Handler(); | 70 | |
71 | static boolean alive; | 71 | private static Activity acty = null; |
72 | static PopupWindow popwindow = null; | 72 | private static Dialog notificationDialog = null; |
73 | 73 | private static boolean deviceRemove = false; | |
74 | static ArrayList<String> notices = new ArrayList<String>(); | 74 | |
75 | 75 | static ArrayList<ZigbeeDevice> newDevNotifications = new ArrayList<ZigbeeDevice>(); | |
76 | static int timeout = 5000; | 76 | |
77 | 77 | static int timeout = 5000; | |
78 | public static void init(Activity a, int time_out) | 78 | static int cnt = 0; |
79 | { | 79 | |
80 | init(a); | 80 | public static void init(Activity a) { |
81 | timeout = time_out; | 81 | acty = a; |
82 | } | 82 | } |
83 | 83 | ||
84 | public static void init(Activity a) | 84 | public static void closing() { |
85 | { | 85 | closeDialog(); |
86 | acty = a; | 86 | acty = null; |
87 | if (notices.size() > 0) | 87 | } |
88 | { | 88 | |
89 | for (int i = 0 ; i < notices.size() ; i++) | 89 | public static void showNewDeviceNotification(final ZigbeeDevice device) { |
90 | { | 90 | cnt++; |
91 | showNotificationOnScreen(notices.get(i)); | 91 | if(cnt > 1) |
92 | } | 92 | cnt = 0; |
93 | for (int i = 0 ; i < notices.size() ; i++) | 93 | |
94 | { | 94 | if (acty != null) { |
95 | notices.remove(i); | 95 | if(notificationDialog != null) |
96 | } | 96 | { |
97 | } | 97 | newDevNotifications.add(device); |
98 | } | 98 | } |
99 | 99 | else | |
100 | public static void closing() | 100 | { |
101 | { | 101 | showNewDeviceNotificationDialog(device); |
102 | if (popwindow != null) | 102 | } |
103 | { | 103 | } |
104 | popwindow.dismiss(); | 104 | else |
105 | handle.removeCallbacks(closePopupTask); | 105 | { |
106 | } | 106 | |
107 | popwindow = null; | 107 | } |
108 | acty = null; | 108 | |
109 | } | 109 | while (!newDevNotifications.isEmpty()) { |
110 | 110 | if (acty != null) { | |
111 | public static void showNotification(String text) | 111 | if(notificationDialog == null) |
112 | { | 112 | { |
113 | if (acty == null) | 113 | ZigbeeDevice notifyDevice = newDevNotifications.remove(0); |
114 | { | 114 | showNewDeviceNotificationDialog(notifyDevice); |
115 | notices.add(text); | 115 | } |
116 | } | 116 | } |
117 | else | 117 | } |
118 | { | 118 | |
119 | showNotificationOnScreen(text); | 119 | /* |
120 | } | 120 | // restart activity to update device drop down |
121 | } | 121 | Intent intent = new Intent(); |
122 | 122 | intent.setClass(acty, acty.getClass()); | |
123 | public static void showNotificationOnScreen(final String text) | 123 | acty.finish(); |
124 | { | 124 | acty.startActivity(intent); |
125 | final TextView text1 = new TextView(acty); | 125 | */ |
126 | text1.setText(text); | 126 | } |
127 | text1.setTextColor(Color.WHITE); | 127 | |
128 | text1.setTextSize(18); | 128 | public static void showNewDeviceNotificationDialog( |
129 | text1.setGravity(Gravity.CENTER); | 129 | final ZigbeeDevice device) { |
130 | 130 | // close any existing notification | |
131 | if (popwindow == null) | 131 | closeDialog(); |
132 | { | 132 | |
133 | LayoutInflater inflater = (LayoutInflater) acty.getLayoutInflater(); | 133 | //put device into identify |
134 | View layout = inflater.inflate(R.layout.popup, | 134 | ZigbeeAssistant.setDeviceState(device,true); |
135 | (ViewGroup) acty.findViewById(R.id.toast_layout_root)); | 135 | ZigbeeAssistant.setDeviceLevel(device,0xFF); |
136 | 136 | ZigbeeAssistant.IdentifyDevice(device,(short) 600); | |
137 | ((LinearLayout) layout.findViewById(R.id.popup_text_box)).addView(text1); | 137 | |
138 | 138 | String Title = "New Device Found"; | |
139 | popwindow = new PopupWindow(layout,400,100,false); | 139 | String Msg = "Please Enter the name of the device"; |
140 | popwindow.setAnimationStyle(R.style.Animation_Popup); | 140 | final EditText t = new EditText(acty); |
141 | popwindow.setBackgroundDrawable(new BitmapDrawable()); | 141 | t.setText(device.Name); |
142 | popwindow.setOutsideTouchable(false); | 142 | |
143 | popwindow.setTouchable(true); | 143 | final AlertDialog.Builder builder = new AlertDialog.Builder(acty); |
144 | popwindow.setTouchInterceptor(new OnTouchListener() { | 144 | builder.setTitle(Title) |
145 | public boolean onTouch(View v, MotionEvent event) { | 145 | .setMessage(Msg) |
146 | handle.removeCallbacks(closePopupTask); | 146 | .setView(t) |
147 | handle.post(closePopupTask); | 147 | .setPositiveButton("OK", |
148 | return false; | 148 | new DialogInterface.OnClickListener() |
149 | } | 149 | { |
150 | }); | 150 | public void onClick(DialogInterface dialoginterface,int i){ |
151 | try{ | 151 | ZigbeeAssistant.setDeviceName(device.Name, t.getText().toString()); |
152 | acty.runOnUiThread (new Runnable(){ | 152 | zllMain.setCurrentDevice(device); |
153 | public void run() { | 153 | closeDialog(); |
154 | // if (acty!=null && acty.findViewById(R.id.MainMenu_lay)!=null) | 154 | //stop device identifying |
155 | // popwindow.showAtLocation(acty.findViewById(R.id.MainMenu_lay), Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 0); | 155 | ZigbeeAssistant.IdentifyDevice(device,(short) 0); |
156 | // else | 156 | } |
157 | // notices.add(text); | 157 | }); |
158 | } | 158 | |
159 | }); | 159 | |
160 | } catch (Exception e) | 160 | try { |
161 | { | 161 | acty.runOnUiThread(new Runnable() { |
162 | // Dagnabbit. | 162 | public void run() { |
163 | popwindow = null; | 163 | if (acty != null) { |
164 | } | 164 | // if(acty.hasWindowFocus()) |
165 | } | 165 | // { |
166 | else | 166 | notificationDialog = builder.create(); |
167 | { | 167 | notificationDialog.show(); |
168 | 168 | // } | |
169 | acty.runOnUiThread (new Runnable(){ | 169 | } |
170 | public void run() { | 170 | } |
171 | LinearLayout l = (LinearLayout)popwindow.getContentView().findViewById(R.id.popup_text_box); | 171 | }); |
172 | if (l.getChildCount()>2) | 172 | } catch (Exception e) { |
173 | l.removeViewAt(0); | 173 | |
174 | l.addView(text1); | 174 | } |
175 | popwindow.update(); | 175 | } |
176 | } | 176 | |
177 | }); | 177 | public static void showRemoveDeviceNotification(String deviceStr, |
178 | } | 178 | final int timeout) { |
179 | 179 | if (acty != null) { | |
180 | handle.removeCallbacks(closePopupTask); | 180 | // close any existing notification |
181 | handle.postDelayed(closePopupTask, timeout); | 181 | closeDialog(); |
182 | //SoundManager.playSound(SoundManager.NOTIFY, 1); | 182 | |
183 | } | 183 | final AlertDialog.Builder builder = new AlertDialog.Builder(acty); |
184 | 184 | builder.setTitle("ZigBee Notification") | |
185 | 185 | .setCancelable(false) | |
186 | private static Runnable closePopupTask = new Runnable() { | 186 | .setMessage("Device Removed: " + deviceStr) |
187 | public void run() { | 187 | .setPositiveButton("Ok", |
188 | if (popwindow!=null) | 188 | new DialogInterface.OnClickListener() { |
189 | { | 189 | public void onClick(DialogInterface dialog, |
190 | popwindow.dismiss(); | 190 | int id) { |
191 | popwindow = null; | 191 | // restart activity to update device drop |
192 | } | 192 | // down |
193 | } | 193 | Intent intent = new Intent(); |
194 | }; | 194 | intent.setClass(acty, acty.getClass()); |
195 | 195 | acty.finish(); | |
196 | 196 | acty.startActivity(intent); | |
197 | } | 197 | closeDialog(); |
198 | } | ||
199 | }); | ||
200 | |||
201 | try { | ||
202 | acty.runOnUiThread(new Runnable() { | ||
203 | public void run() { | ||
204 | if (acty != null) { | ||
205 | // if(acty.hasWindowFocus()) | ||
206 | // { | ||
207 | notificationDialog = builder.create(); | ||
208 | notificationDialog.show(); | ||
209 | // } | ||
210 | } | ||
211 | } | ||
212 | }); | ||
213 | } catch (Exception e) { | ||
214 | |||
215 | } | ||
216 | |||
217 | new Thread(new Runnable() { | ||
218 | public void run() { | ||
219 | try { | ||
220 | Thread.sleep(timeout); | ||
221 | } catch (InterruptedException e) { | ||
222 | // TODO Auto-generated catch block | ||
223 | e.printStackTrace(); | ||
224 | } | ||
225 | closeDialog(); | ||
226 | } | ||
227 | }).start(); | ||
228 | |||
229 | } | ||
230 | } | ||
231 | |||
232 | public static void showGeneralNotification(String notification, | ||
233 | final int timeout) { | ||
234 | if (acty != null) { | ||
235 | // close any existing notification | ||
236 | closeDialog(); | ||
237 | |||
238 | final AlertDialog.Builder builder = new AlertDialog.Builder(acty); | ||
239 | builder.setTitle("ZigBee Notification").setCancelable(false) | ||
240 | .setMessage(notification); | ||
241 | |||
242 | try { | ||
243 | acty.runOnUiThread(new Runnable() { | ||
244 | public void run() { | ||
245 | if (acty != null) { | ||
246 | // if(acty.hasWindowFocus()) | ||
247 | // { | ||
248 | notificationDialog = builder.create(); | ||
249 | notificationDialog.show(); | ||
250 | // } | ||
251 | } | ||
252 | } | ||
253 | }); | ||
254 | } catch (Exception e) { | ||
255 | |||
256 | } | ||
257 | |||
258 | new Thread(new Runnable() { | ||
259 | public void run() { | ||
260 | try { | ||
261 | Thread.sleep(timeout); | ||
262 | } catch (InterruptedException e) { | ||
263 | // TODO Auto-generated catch block | ||
264 | e.printStackTrace(); | ||
265 | } | ||
266 | closeDialog(); | ||
267 | } | ||
268 | }).start(); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | private static void closeDialog() { | ||
273 | if (notificationDialog != null) { | ||
274 | notificationDialog.cancel(); | ||
275 | } | ||
276 | notificationDialog = null; | ||
277 | } | ||
278 | } | ||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeScene.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeScene.java index 80016c6..80016c6 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeScene.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeScene.java | |||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.java index 812aafb..cb70a9f 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.java | |||
@@ -91,45 +91,49 @@ public class ZigbeeSrpcClient { | |||
91 | 91 | ||
92 | //SRPC CMD ID's | 92 | //SRPC CMD ID's |
93 | //define the outgoing RPSC command ID's | 93 | //define the outgoing RPSC command ID's |
94 | private static final byte RPCS_NEW_ZLL_DEVICE = (byte) 0x0001; | 94 | private static final byte SRPC_NEW_DEVICE = (byte) 0x0001; |
95 | private static final byte RPCS_DEV_ANNCE = (byte) 0x0002; | 95 | private static final byte SRPC_RESERVED_1 = (byte) 0x0002; |
96 | private static final byte RPCS_SIMPLE_DESC = (byte) 0x0003; | 96 | private static final byte SRPC_RESERVED_2 = (byte) 0x0003; |
97 | private static final byte RPCS_TEMP_READING = (byte) 0x0004; | 97 | private static final byte SRPC_RESERVED_3 = (byte) 0x0004; |
98 | private static final byte RPCS_POWER_READING = (byte) 0x0005; | 98 | private static final byte SRPC_RESERVED_4 = (byte) 0x0005; |
99 | private static final byte RPCS_PING = (byte) 0x0006; | 99 | private static final byte SRPC_RESERVED_5 = (byte) 0x0006; |
100 | private static final byte RPCS_GET_DEV_STATE_RSP = (byte) 0x0007; | 100 | private static final byte SRPC_GET_DEV_STATE_RSP = (byte) 0x0007; |
101 | private static final byte RPCS_GET_DEV_LEVEL_RSP = (byte) 0x0008; | 101 | private static final byte SRPC_GET_DEV_LEVEL_RSP = (byte) 0x0008; |
102 | private static final byte RPCS_GET_DEV_HUE_RSP = (byte) 0x0009; | 102 | private static final byte SRPC_GET_DEV_HUE_RSP = (byte) 0x0009; |
103 | private static final byte RPCS_GET_DEV_SAT_RSP = (byte) 0x000a; | 103 | private static final byte SRPC_GET_DEV_SAT_RSP = (byte) 0x000a; |
104 | private static final byte RPCS_ADD_GROUP_RSP = (byte) 0x000b; | 104 | private static final byte SRPC_ADD_GROUP_RSP = (byte) 0x000b; |
105 | private static final byte RPCS_GET_GROUP_RSP = (byte) 0x000c; | 105 | private static final byte SRPC_GET_GROUP_RSP = (byte) 0x000c; |
106 | private static final byte RPCS_ADD_SCENE_RSP = (byte) 0x000d; | 106 | private static final byte SRPC_ADD_SCENE_RSP = (byte) 0x000d; |
107 | private static final byte RPCS_GET_SCENE_RSP = (byte) 0x000e; | 107 | private static final byte SRPC_GET_SCENE_RSP = (byte) 0x000e; |
108 | 108 | ||
109 | 109 | ||
110 | //define incoming RPCS command ID's | 110 | //define incoming SRPC command ID's |
111 | private static final byte RPCS_CLOSE = (byte) 0x80; | 111 | private static final byte SRPC_CLOSE = (byte) 0x80; |
112 | private static final byte RPCS_GET_DEVICES = (byte) 0x81; | 112 | private static final byte SRPC_GET_DEVICES = (byte) 0x81; |
113 | private static final byte RPCS_SET_DEV_STATE = (byte) 0x82; | 113 | private static final byte SRPC_SET_DEV_STATE = (byte) 0x82; |
114 | private static final byte RPCS_SET_DEV_LEVEL = (byte) 0x83; | 114 | private static final byte SRPC_SET_DEV_LEVEL = (byte) 0x83; |
115 | private static final byte RPCS_SET_DEV_COLOR = (byte) 0x84; | 115 | private static final byte SRPC_SET_DEV_COLOR = (byte) 0x84; |
116 | private static final byte RPCS_GET_DEV_STATE = (byte) 0x85; | 116 | private static final byte SRPC_GET_DEV_STATE = (byte) 0x85; |
117 | private static final byte RPCS_GET_DEV_LEVEL = (byte) 0x86; | 117 | private static final byte SRPC_GET_DEV_LEVEL = (byte) 0x86; |
118 | private static final byte RPCS_GET_DEV_HUE = (byte) 0x87; | 118 | private static final byte SRPC_GET_DEV_HUE = (byte) 0x87; |
119 | private static final byte RPCS_GET_DEV_SAT = (byte) 0x88; | 119 | private static final byte SRPC_GET_DEV_SAT = (byte) 0x88; |
120 | private static final byte RPCS_BIND_DEVICES = (byte) 0x89; | 120 | private static final byte SRPC_BIND_DEVICES = (byte) 0x89; |
121 | private static final byte RPCS_GET_THERM_READING = (byte) 0x8a; | 121 | private static final byte SRPC_RESERVED_6 = (byte) 0x8a; |
122 | private static final byte RPCS_GET_POWER_READING = (byte) 0x8b; | 122 | private static final byte SRPC_RESERVED_7 = (byte) 0x8b; |
123 | private static final byte RPCS_DISCOVER_DEVICES = (byte) 0x8c; | 123 | private static final byte SRPC_RESERVED_8 = (byte) 0x8c; |
124 | private static final byte RPCS_SEND_ZCL = (byte) 0x8d; | 124 | private static final byte SRPC_RESERVED_9 = (byte) 0x8d; |
125 | private static final byte RPCS_GET_GROUPS = (byte) 0x8e; | 125 | private static final byte SRPC_GET_GROUPS = (byte) 0x8e; |
126 | private static final byte RPCS_ADD_GROUP = (byte) 0x8f; | 126 | private static final byte SRPC_ADD_GROUP = (byte) 0x8f; |
127 | private static final byte RPCS_GET_SCENES = (byte) 0x90; | 127 | private static final byte SRPC_GET_SCENES = (byte) 0x90; |
128 | private static final byte RPCS_STORE_SCENE = (byte) 0x91; | 128 | private static final byte SRPC_STORE_SCENE = (byte) 0x91; |
129 | private static final byte RPCS_RECALL_SCENE = (byte) 0x92; | 129 | private static final byte SRPC_RECALL_SCENE = (byte) 0x92; |
130 | private static final byte RPCS_IDENTIFY_DEVICE = (byte) 0x93; | 130 | private static final byte SRPC_IDENTIFY_DEVICE = (byte) 0x93; |
131 | private static final byte RPCS_CHANGE_DEVICE_NAME = (byte) 0x94; | 131 | private static final byte SRPC_CHANGE_DEVICE_NAME = (byte) 0x94; |
132 | 132 | private static final byte SRPC_REMOVE_DEVICE = (byte) 0x95; | |
133 | private static final byte SRPC_OPEN_NETWORK = (byte) 0x9c; | ||
134 | |||
135 | private static final short JOIN_AUTH_NUM = (short) 0xebd4; | ||
136 | |||
133 | //SRPC AfAddr Addr modes ID's | 137 | //SRPC AfAddr Addr modes ID's |
134 | public static final byte AddrNotPresent = 0; | 138 | public static final byte AddrNotPresent = 0; |
135 | public static final byte AddrGroup = 1; | 139 | public static final byte AddrGroup = 1; |
@@ -150,12 +154,13 @@ public class ZigbeeSrpcClient { | |||
150 | switch (msg[msgPtr + SRPC_CMD_ID_POS]) | 154 | switch (msg[msgPtr + SRPC_CMD_ID_POS]) |
151 | { | 155 | { |
152 | 156 | ||
153 | case RPCS_NEW_ZLL_DEVICE: | 157 | case SRPC_NEW_DEVICE: |
154 | { | 158 | { |
155 | int profileId=0, deviceId=0, nwkAddr=0; | 159 | int profileId=0, deviceId=0, nwkAddr=0; |
156 | char endPoint; | 160 | char endPoint; |
157 | String deviceName = ""; | 161 | String deviceName = ""; |
158 | byte[] ieee = new byte[8]; | 162 | byte[] ieee = new byte[8]; |
163 | byte newDevFlag; | ||
159 | 164 | ||
160 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; | 165 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; |
161 | //index passed len and cmd ID | 166 | //index passed len and cmd ID |
@@ -190,14 +195,12 @@ public class ZigbeeSrpcClient { | |||
190 | 195 | ||
191 | //index passed version | 196 | //index passed version |
192 | msgPtr++; | 197 | msgPtr++; |
193 | 198 | ||
194 | //index passed device name | ||
195 | int nameSize = msg[msgPtr++]; | 199 | int nameSize = msg[msgPtr++]; |
196 | for(int i = 0; i < nameSize; i++) | 200 | for(int i = 0; i < nameSize; i++) |
197 | { | 201 | { |
198 | deviceName += (char) msg[msgPtr++]; | 202 | deviceName += (char) msg[msgPtr++]; |
199 | } | 203 | } |
200 | msgPtr += nameSize; | ||
201 | 204 | ||
202 | //index passed status | 205 | //index passed status |
203 | msgPtr++; | 206 | msgPtr++; |
@@ -208,11 +211,13 @@ public class ZigbeeSrpcClient { | |||
208 | ieee[i] = msg[msgPtr++]; | 211 | ieee[i] = msg[msgPtr++]; |
209 | } | 212 | } |
210 | 213 | ||
211 | ZigbeeAssistant.newDevice(profileId, deviceId, nwkAddr, endPoint, ieee, deviceName); | 214 | newDevFlag = (byte) msg[msgPtr++]; |
212 | 215 | ||
216 | ZigbeeAssistant.newDevice(profileId, deviceId, nwkAddr, endPoint, ieee, deviceName, newDevFlag); | ||
217 | |||
213 | break; | 218 | break; |
214 | } | 219 | } |
215 | case RPCS_ADD_GROUP_RSP: | 220 | case SRPC_ADD_GROUP_RSP: |
216 | { | 221 | { |
217 | short groupId = 0; | 222 | short groupId = 0; |
218 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; | 223 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; |
@@ -244,9 +249,10 @@ public class ZigbeeSrpcClient { | |||
244 | break; | 249 | break; |
245 | } | 250 | } |
246 | 251 | ||
247 | case RPCS_GET_GROUP_RSP: | 252 | case SRPC_GET_GROUP_RSP: |
248 | { | 253 | { |
249 | short groupId = 0; | 254 | short groupId = 0; |
255 | String groupName = ""; | ||
250 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; | 256 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; |
251 | 257 | ||
252 | //index passed len and cmd ID | 258 | //index passed len and cmd ID |
@@ -259,15 +265,19 @@ public class ZigbeeSrpcClient { | |||
259 | int groupIdTemp = (msg[msgPtr] & 0xff); | 265 | int groupIdTemp = (msg[msgPtr] & 0xff); |
260 | groupId += (groupIdTemp << (8 * i)); | 266 | groupId += (groupIdTemp << (8 * i)); |
261 | } | 267 | } |
268 | |||
269 | int nameSize = msg[msgPtr++]; | ||
270 | for(int i = 0; i < nameSize; i++) | ||
271 | { | ||
272 | groupName += (char) msg[msgPtr++]; | ||
273 | } | ||
262 | 274 | ||
263 | String groupNameStr = new String(msg, msgPtr+1, msg[msgPtr], Charset.defaultCharset()); | 275 | ZigbeeAssistant.newGroup(groupName, groupId, ZigbeeGroup.groupStatusActive); |
264 | |||
265 | ZigbeeAssistant.newGroup(groupNameStr, groupId, ZigbeeGroup.groupStatusActive); | ||
266 | 276 | ||
267 | break; | 277 | break; |
268 | } | 278 | } |
269 | 279 | ||
270 | case RPCS_ADD_SCENE_RSP: | 280 | case SRPC_ADD_SCENE_RSP: |
271 | { | 281 | { |
272 | short groupId = 0; | 282 | short groupId = 0; |
273 | byte sceneId = 0; | 283 | byte sceneId = 0; |
@@ -303,10 +313,11 @@ public class ZigbeeSrpcClient { | |||
303 | break; | 313 | break; |
304 | } | 314 | } |
305 | 315 | ||
306 | case RPCS_GET_SCENE_RSP: | 316 | case SRPC_GET_SCENE_RSP: |
307 | { | 317 | { |
308 | short groupId = 0; | 318 | short groupId = 0; |
309 | byte sceneId = 0; | 319 | byte sceneId = 0; |
320 | String sceneName = ""; | ||
310 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; | 321 | msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2; |
311 | 322 | ||
312 | //index passed len and cmd ID | 323 | //index passed len and cmd ID |
@@ -322,14 +333,18 @@ public class ZigbeeSrpcClient { | |||
322 | 333 | ||
323 | //Get the sceneId | 334 | //Get the sceneId |
324 | sceneId = (byte) msg[msgPtr++]; | 335 | sceneId = (byte) msg[msgPtr++]; |
336 | |||
337 | int nameSize = msg[msgPtr++]; | ||
338 | for(int i = 0; i < nameSize; i++) | ||
339 | { | ||
340 | sceneName += (char) msg[msgPtr++]; | ||
341 | } | ||
325 | 342 | ||
326 | String sceneNameStr = new String(msg, msgPtr+1, msg[msgPtr], Charset.defaultCharset()); | 343 | ZigbeeAssistant.newScene(sceneName, groupId, sceneId, ZigbeeScene.sceneStatusActive); |
327 | |||
328 | ZigbeeAssistant.newScene(sceneNameStr, groupId, sceneId, ZigbeeScene.sceneStatusActive); | ||
329 | 344 | ||
330 | break; | 345 | break; |
331 | } | 346 | } |
332 | case RPCS_GET_DEV_STATE_RSP: | 347 | case SRPC_GET_DEV_STATE_RSP: |
333 | { | 348 | { |
334 | short nwkAddr = 0; | 349 | short nwkAddr = 0; |
335 | byte endPoint = 0; | 350 | byte endPoint = 0; |
@@ -366,7 +381,7 @@ public class ZigbeeSrpcClient { | |||
366 | } | 381 | } |
367 | break; | 382 | break; |
368 | } | 383 | } |
369 | case RPCS_GET_DEV_LEVEL_RSP: | 384 | case SRPC_GET_DEV_LEVEL_RSP: |
370 | { | 385 | { |
371 | short nwkAddr = 0; | 386 | short nwkAddr = 0; |
372 | byte endPoint = 0; | 387 | byte endPoint = 0; |
@@ -403,7 +418,7 @@ public class ZigbeeSrpcClient { | |||
403 | } | 418 | } |
404 | break; | 419 | break; |
405 | } | 420 | } |
406 | case RPCS_GET_DEV_HUE_RSP: | 421 | case SRPC_GET_DEV_HUE_RSP: |
407 | { | 422 | { |
408 | short nwkAddr = 0; | 423 | short nwkAddr = 0; |
409 | byte endPoint = 0; | 424 | byte endPoint = 0; |
@@ -440,7 +455,7 @@ public class ZigbeeSrpcClient { | |||
440 | } | 455 | } |
441 | break; | 456 | break; |
442 | } | 457 | } |
443 | case RPCS_GET_DEV_SAT_RSP: | 458 | case SRPC_GET_DEV_SAT_RSP: |
444 | { | 459 | { |
445 | short nwkAddr = 0; | 460 | short nwkAddr = 0; |
446 | byte endPoint = 0; | 461 | byte endPoint = 0; |
@@ -493,7 +508,7 @@ public class ZigbeeSrpcClient { | |||
493 | byte msgIdx; | 508 | byte msgIdx; |
494 | 509 | ||
495 | //set SRPC len and CMD ID | 510 | //set SRPC len and CMD ID |
496 | msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_STATE; | 511 | msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_STATE; |
497 | msg[SRPC_CMD_LEN_POS] = 13; | 512 | msg[SRPC_CMD_LEN_POS] = 13; |
498 | 513 | ||
499 | //set ptr to point to data | 514 | //set ptr to point to data |
@@ -531,7 +546,7 @@ public class ZigbeeSrpcClient { | |||
531 | byte msgIdx; | 546 | byte msgIdx; |
532 | 547 | ||
533 | //set SRPC len and CMD ID | 548 | //set SRPC len and CMD ID |
534 | msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_LEVEL; | 549 | msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_LEVEL; |
535 | msg[SRPC_CMD_LEN_POS] = 15; | 550 | msg[SRPC_CMD_LEN_POS] = 15; |
536 | 551 | ||
537 | //set ptr to point to data | 552 | //set ptr to point to data |
@@ -564,7 +579,7 @@ public class ZigbeeSrpcClient { | |||
564 | byte msgIdx; | 579 | byte msgIdx; |
565 | 580 | ||
566 | //set SRPC len and CMD ID | 581 | //set SRPC len and CMD ID |
567 | msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_COLOR; | 582 | msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_COLOR; |
568 | msg[SRPC_CMD_LEN_POS] = 16; | 583 | msg[SRPC_CMD_LEN_POS] = 16; |
569 | 584 | ||
570 | //set ptr to point to data | 585 | //set ptr to point to data |
@@ -600,7 +615,7 @@ public class ZigbeeSrpcClient { | |||
600 | byte msgIdx; | 615 | byte msgIdx; |
601 | 616 | ||
602 | //set SRPC len and CMD ID | 617 | //set SRPC len and CMD ID |
603 | msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_STATE; | 618 | msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_STATE; |
604 | msg[SRPC_CMD_LEN_POS] = 13; | 619 | msg[SRPC_CMD_LEN_POS] = 13; |
605 | 620 | ||
606 | //set ptr to point to data | 621 | //set ptr to point to data |
@@ -627,7 +642,7 @@ public class ZigbeeSrpcClient { | |||
627 | byte msgIdx; | 642 | byte msgIdx; |
628 | 643 | ||
629 | //set SRPC len and CMD ID | 644 | //set SRPC len and CMD ID |
630 | msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_LEVEL; | 645 | msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_LEVEL; |
631 | msg[SRPC_CMD_LEN_POS] = 13; | 646 | msg[SRPC_CMD_LEN_POS] = 13; |
632 | 647 | ||
633 | //set ptr to point to data | 648 | //set ptr to point to data |
@@ -654,7 +669,7 @@ public class ZigbeeSrpcClient { | |||
654 | byte msgIdx; | 669 | byte msgIdx; |
655 | 670 | ||
656 | //set SRPC len and CMD ID | 671 | //set SRPC len and CMD ID |
657 | msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_HUE; | 672 | msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_HUE; |
658 | msg[SRPC_CMD_LEN_POS] = 13; | 673 | msg[SRPC_CMD_LEN_POS] = 13; |
659 | 674 | ||
660 | //set ptr to point to data | 675 | //set ptr to point to data |
@@ -681,7 +696,7 @@ public class ZigbeeSrpcClient { | |||
681 | byte msgIdx; | 696 | byte msgIdx; |
682 | 697 | ||
683 | //set SRPC len and CMD ID | 698 | //set SRPC len and CMD ID |
684 | msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_SAT; | 699 | msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_SAT; |
685 | msg[SRPC_CMD_LEN_POS] = 13; | 700 | msg[SRPC_CMD_LEN_POS] = 13; |
686 | 701 | ||
687 | //set ptr to point to data | 702 | //set ptr to point to data |
@@ -708,7 +723,7 @@ public class ZigbeeSrpcClient { | |||
708 | byte msgIdx; | 723 | byte msgIdx; |
709 | 724 | ||
710 | //set SRPC len and CMD ID | 725 | //set SRPC len and CMD ID |
711 | msg[SRPC_CMD_ID_POS] = RPCS_BIND_DEVICES; | 726 | msg[SRPC_CMD_ID_POS] = SRPC_BIND_DEVICES; |
712 | msg[SRPC_CMD_LEN_POS] = 22; | 727 | msg[SRPC_CMD_LEN_POS] = 22; |
713 | 728 | ||
714 | //set ptr to point to data | 729 | //set ptr to point to data |
@@ -758,7 +773,7 @@ public class ZigbeeSrpcClient { | |||
758 | byte[] msg = new byte[2]; | 773 | byte[] msg = new byte[2]; |
759 | 774 | ||
760 | //set SRPC len and CMD ID | 775 | //set SRPC len and CMD ID |
761 | msg[SRPC_CMD_ID_POS] = RPCS_GET_DEVICES; | 776 | msg[SRPC_CMD_ID_POS] = SRPC_GET_DEVICES; |
762 | msg[SRPC_CMD_LEN_POS] = 0; | 777 | msg[SRPC_CMD_LEN_POS] = 0; |
763 | 778 | ||
764 | sendSrpc(msg); | 779 | sendSrpc(msg); |
@@ -769,7 +784,7 @@ public class ZigbeeSrpcClient { | |||
769 | byte[] msg = new byte[2]; | 784 | byte[] msg = new byte[2]; |
770 | 785 | ||
771 | //set SRPC len and CMD ID | 786 | //set SRPC len and CMD ID |
772 | msg[SRPC_CMD_ID_POS] = RPCS_GET_GROUPS; | 787 | msg[SRPC_CMD_ID_POS] = SRPC_GET_GROUPS; |
773 | msg[SRPC_CMD_LEN_POS] = 0; | 788 | msg[SRPC_CMD_LEN_POS] = 0; |
774 | 789 | ||
775 | sendSrpc(msg); | 790 | sendSrpc(msg); |
@@ -780,7 +795,7 @@ public class ZigbeeSrpcClient { | |||
780 | byte[] msg = new byte[2]; | 795 | byte[] msg = new byte[2]; |
781 | 796 | ||
782 | //set SRPC len and CMD ID | 797 | //set SRPC len and CMD ID |
783 | msg[SRPC_CMD_ID_POS] = RPCS_GET_SCENES; | 798 | msg[SRPC_CMD_ID_POS] = SRPC_GET_SCENES; |
784 | msg[SRPC_CMD_LEN_POS] = 0; | 799 | msg[SRPC_CMD_LEN_POS] = 0; |
785 | 800 | ||
786 | sendSrpc(msg); | 801 | sendSrpc(msg); |
@@ -792,7 +807,7 @@ public class ZigbeeSrpcClient { | |||
792 | byte msgIdx; | 807 | byte msgIdx; |
793 | 808 | ||
794 | //set SRPC len and CMD ID | 809 | //set SRPC len and CMD ID |
795 | msg[SRPC_CMD_ID_POS] = RPCS_ADD_GROUP; | 810 | msg[SRPC_CMD_ID_POS] = SRPC_ADD_GROUP; |
796 | msg[SRPC_CMD_LEN_POS] = (byte) (12 + groupName.length() + 1); | 811 | msg[SRPC_CMD_LEN_POS] = (byte) (12 + groupName.length() + 1); |
797 | 812 | ||
798 | //set ptr to point to data | 813 | //set ptr to point to data |
@@ -825,7 +840,7 @@ public class ZigbeeSrpcClient { | |||
825 | byte msgIdx; | 840 | byte msgIdx; |
826 | 841 | ||
827 | //set SRPC len and CMD ID | 842 | //set SRPC len and CMD ID |
828 | msg[SRPC_CMD_ID_POS] = RPCS_STORE_SCENE; | 843 | msg[SRPC_CMD_ID_POS] = SRPC_STORE_SCENE; |
829 | msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length()); | 844 | msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length()); |
830 | 845 | ||
831 | //set ptr to point to data | 846 | //set ptr to point to data |
@@ -861,7 +876,7 @@ public class ZigbeeSrpcClient { | |||
861 | byte msgIdx; | 876 | byte msgIdx; |
862 | 877 | ||
863 | //set SRPC len and CMD ID | 878 | //set SRPC len and CMD ID |
864 | msg[SRPC_CMD_ID_POS] = RPCS_RECALL_SCENE; | 879 | msg[SRPC_CMD_ID_POS] = SRPC_RECALL_SCENE; |
865 | msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length()); | 880 | msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length()); |
866 | 881 | ||
867 | //set ptr to point to data | 882 | //set ptr to point to data |
@@ -899,7 +914,7 @@ public class ZigbeeSrpcClient { | |||
899 | byte msgIdx; | 914 | byte msgIdx; |
900 | 915 | ||
901 | //set SRPC len and CMD ID | 916 | //set SRPC len and CMD ID |
902 | msg[SRPC_CMD_ID_POS] = RPCS_IDENTIFY_DEVICE; | 917 | msg[SRPC_CMD_ID_POS] = SRPC_IDENTIFY_DEVICE; |
903 | msg[SRPC_CMD_LEN_POS] = 14; | 918 | msg[SRPC_CMD_LEN_POS] = 14; |
904 | 919 | ||
905 | //set ptr to point to data | 920 | //set ptr to point to data |
@@ -917,20 +932,21 @@ public class ZigbeeSrpcClient { | |||
917 | //pad out pan ID | 932 | //pad out pan ID |
918 | msgIdx+=2; | 933 | msgIdx+=2; |
919 | 934 | ||
920 | //set transitionTime | 935 | //set transitionTime |
921 | msg[msgIdx++] = (byte) identifyTime; | 936 | msg[msgIdx++] = (byte) (identifyTime & 0xFF); |
937 | msg[msgIdx++] = (byte) ((identifyTime & 0xFF00)>>8); | ||
922 | 938 | ||
923 | sendSrpc(msg); | 939 | sendSrpc(msg); |
924 | } | 940 | } |
925 | 941 | ||
926 | public static void changeDeviceName(ZigbeeDevice device, String deviceName) | 942 | public static void changeDeviceName(ZigbeeDevice device, String deviceName) |
927 | { | 943 | { |
928 | byte[] msg = new byte[4 + deviceName.length()]; | 944 | byte[] msg = new byte[6 + deviceName.length()]; |
929 | byte msgIdx; | 945 | byte msgIdx; |
930 | 946 | ||
931 | //set SRPC len and CMD ID | 947 | //set SRPC len and CMD ID |
932 | msg[SRPC_CMD_ID_POS] = RPCS_CHANGE_DEVICE_NAME; | 948 | msg[SRPC_CMD_ID_POS] = SRPC_CHANGE_DEVICE_NAME; |
933 | msg[SRPC_CMD_LEN_POS] = (byte) (2 + deviceName.length()); | 949 | msg[SRPC_CMD_LEN_POS] = (byte) (4 + deviceName.length()); |
934 | 950 | ||
935 | //set ptr to point to data | 951 | //set ptr to point to data |
936 | msgIdx=2; | 952 | msgIdx=2; |
@@ -938,6 +954,9 @@ public class ZigbeeSrpcClient { | |||
938 | //set afAddrMode_t nwk address | 954 | //set afAddrMode_t nwk address |
939 | msg[msgIdx++] = (byte) (device.NetworkAddr & 0xFF); | 955 | msg[msgIdx++] = (byte) (device.NetworkAddr & 0xFF); |
940 | msg[msgIdx++] = (byte) ((device.NetworkAddr & 0xFF00)>>8); | 956 | msg[msgIdx++] = (byte) ((device.NetworkAddr & 0xFF00)>>8); |
957 | |||
958 | //set EP | ||
959 | msg[msgIdx++] = (byte) (device.EndPoint); | ||
941 | 960 | ||
942 | msg[msgIdx++] = (byte) deviceName.length(); | 961 | msg[msgIdx++] = (byte) deviceName.length(); |
943 | for(int i = 0; i < deviceName.length(); i++) | 962 | for(int i = 0; i < deviceName.length(); i++) |
@@ -948,6 +967,29 @@ public class ZigbeeSrpcClient { | |||
948 | sendSrpc(msg); | 967 | sendSrpc(msg); |
949 | } | 968 | } |
950 | 969 | ||
970 | |||
971 | public static void openNetwork(byte duration) | ||
972 | { | ||
973 | byte[] msg = new byte[5]; | ||
974 | byte msgIdx; | ||
975 | |||
976 | //set SRPC len and CMD ID | ||
977 | msg[SRPC_CMD_ID_POS] = SRPC_OPEN_NETWORK; | ||
978 | msg[SRPC_CMD_LEN_POS] = (byte) (3); | ||
979 | |||
980 | //set ptr to point to data | ||
981 | msgIdx=2; | ||
982 | |||
983 | //set duration | ||
984 | msg[msgIdx++] = duration; | ||
985 | |||
986 | //set join auth | ||
987 | msg[msgIdx++] = (byte) (JOIN_AUTH_NUM & 0xFF); | ||
988 | msg[msgIdx++] = (byte) ((JOIN_AUTH_NUM & 0xFF00)>>8); | ||
989 | |||
990 | sendSrpc(msg); | ||
991 | } | ||
992 | |||
951 | public static int clientConnect( ) | 993 | public static int clientConnect( ) |
952 | { | 994 | { |
953 | int Port; | 995 | int Port; |
@@ -1001,7 +1043,12 @@ public class ZigbeeSrpcClient { | |||
1001 | new Thread(new Runnable() | 1043 | new Thread(new Runnable() |
1002 | { | 1044 | { |
1003 | public void run() { | 1045 | public void run() { |
1004 | Listen(); | 1046 | try { |
1047 | Listen(); | ||
1048 | } catch (IOException e) { | ||
1049 | // TODO Auto-generated catch block | ||
1050 | e.printStackTrace(); | ||
1051 | } | ||
1005 | } | 1052 | } |
1006 | }).start(); | 1053 | }).start(); |
1007 | 1054 | ||
@@ -1028,15 +1075,36 @@ public class ZigbeeSrpcClient { | |||
1028 | 1075 | ||
1029 | public static void sendSrpc(byte[] msg) | 1076 | public static void sendSrpc(byte[] msg) |
1030 | { | 1077 | { |
1031 | |||
1032 | try{ | 1078 | try{ |
1033 | outStream.write( msg ); | 1079 | outStream.write( msg ); |
1034 | } catch (Exception e){} | 1080 | } catch (Exception e){} |
1035 | } | 1081 | } |
1036 | 1082 | ||
1037 | private static void Listen() { | 1083 | private static void Listen() throws IOException { |
1038 | //listen for Packets | 1084 | //listen for Packets |
1039 | while(true) | 1085 | while(true) |
1086 | { | ||
1087 | byte[] RxBuffer = new byte[1024]; | ||
1088 | int bytesRead = ReadMessage(inStream, RxBuffer); | ||
1089 | |||
1090 | Log.i("Process Message:", "[" + bytesRead + "]: RPC CMD: " + RxBuffer[0] + ", RPC LEN: " + RxBuffer[1]); | ||
1091 | |||
1092 | if(bytesRead == -1) | ||
1093 | { | ||
1094 | //error | ||
1095 | } | ||
1096 | else | ||
1097 | { | ||
1098 | int bytesProcessed; | ||
1099 | bytesProcessed = rpcsProcessIncoming(RxBuffer, 0); | ||
1100 | if ( bytesRead > bytesProcessed ) | ||
1101 | { | ||
1102 | //error did not process full buffer | ||
1103 | } | ||
1104 | } | ||
1105 | } | ||
1106 | /* | ||
1107 | while(true) | ||
1040 | { | 1108 | { |
1041 | byte[] RxBuffer = new byte[1024]; | 1109 | byte[] RxBuffer = new byte[1024]; |
1042 | try { | 1110 | try { |
@@ -1051,7 +1119,40 @@ public class ZigbeeSrpcClient { | |||
1051 | e.printStackTrace(); | 1119 | e.printStackTrace(); |
1052 | } | 1120 | } |
1053 | } | 1121 | } |
1122 | */ | ||
1054 | } | 1123 | } |
1124 | |||
1125 | private static int ReadMessage(InputStream is, byte[] bytes) throws IOException { | ||
1126 | byte[] rpcHeader = new byte[2]; | ||
1127 | int offset, len; | ||
1128 | int read; | ||
1129 | |||
1130 | read = is.read(rpcHeader, 0, 2); | ||
1131 | len = rpcHeader[1] + 2; | ||
1132 | |||
1133 | bytes[0] = rpcHeader[0]; | ||
1134 | bytes[1] = rpcHeader[1]; | ||
1135 | |||
1136 | if (read == -1) { return -1;} | ||
1137 | |||
1138 | Log.i("ReadMessage", "RPC CMD: " + rpcHeader[0] + ", RPC LEN: " + rpcHeader[1]); | ||
1139 | |||
1140 | offset = 2; | ||
1141 | while (offset < len) { | ||
1142 | read = is.read(bytes, offset, len - offset); | ||
1143 | if (read == -1) { | ||
1144 | /* if ( offset == 0 ) { | ||
1145 | return -1; | ||
1146 | } else { | ||
1147 | return offset; | ||
1148 | }*/ | ||
1149 | } else { | ||
1150 | offset += read; | ||
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | return len; | ||
1155 | } | ||
1055 | 1156 | ||
1056 | public static String getGatewayIp() { | 1157 | public static String getGatewayIp() { |
1057 | return gatewayIp; | 1158 | return gatewayIp; |
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/bindSelect.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/bindSelect.java index 6709d54..6bd647e 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/bindSelect.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/bindSelect.java | |||
@@ -164,11 +164,11 @@ public class bindSelect extends Activity { | |||
164 | ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControllingToggle); | 164 | ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControllingToggle); |
165 | if ( (idDeviceButton.isChecked()) && (currControllingDevice != null)) | 165 | if ( (idDeviceButton.isChecked()) && (currControllingDevice != null)) |
166 | { | 166 | { |
167 | //ZigbeeAssistant.Identify(currControllingDevice, (short) 0x80); | 167 | ZigbeeAssistant.IdentifyDevice(currControllingDevice, (short) 0x80); |
168 | } | 168 | } |
169 | else if(currControllingDevice != null) | 169 | else if(currControllingDevice != null) |
170 | { | 170 | { |
171 | //ZigbeeAssistant.Identify(currControllingDevice, (short) 0); | 171 | ZigbeeAssistant.IdentifyDevice(currControllingDevice, (short) 0); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
@@ -176,11 +176,11 @@ public class bindSelect extends Activity { | |||
176 | ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControlledToggle); | 176 | ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControlledToggle); |
177 | if ( (idDeviceButton.isChecked()) && (currControlledDevice != null)) | 177 | if ( (idDeviceButton.isChecked()) && (currControlledDevice != null)) |
178 | { | 178 | { |
179 | //ZigbeeAssistant.Identify(currControlledDevice, (short) 0x80); | 179 | ZigbeeAssistant.IdentifyDevice(currControlledDevice, (short) 0x80); |
180 | } | 180 | } |
181 | else if(currControlledDevice != null) | 181 | else if(currControlledDevice != null) |
182 | { | 182 | { |
183 | //ZigbeeAssistant.Identify(currControlledDevice, (short) 0); | 183 | ZigbeeAssistant.IdentifyDevice(currControlledDevice, (short) 0); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/groupSelect.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/groupSelect.java index baa6120..97248ac 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/groupSelect.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/groupSelect.java | |||
@@ -205,8 +205,7 @@ public class groupSelect extends Activity { | |||
205 | public void onClick(DialogInterface dialoginterface,int i){ | 205 | public void onClick(DialogInterface dialoginterface,int i){ |
206 | ZigbeeAssistant.newGroup(t.getText().toString() ); | 206 | ZigbeeAssistant.newGroup(t.getText().toString() ); |
207 | //set selection to the new group, which will be last as this is a new one | 207 | //set selection to the new group, which will be last as this is a new one |
208 | currGroup = groupSpinnerAdapter.getCount(); | 208 | currGroup = groupSpinnerAdapter.getCount(); |
209 | new waitRspTask().execute("Create Group"); | ||
210 | groupSpinner.setSelection(currGroup); | 209 | groupSpinner.setSelection(currGroup); |
211 | //update the spinner | 210 | //update the spinner |
212 | addItemsOnGroupSpinner(); | 211 | addItemsOnGroupSpinner(); |
@@ -214,75 +213,7 @@ public class groupSelect extends Activity { | |||
214 | }) | 213 | }) |
215 | .setNegativeButton("Cancel", null) | 214 | .setNegativeButton("Cancel", null) |
216 | .show(); | 215 | .show(); |
217 | } | 216 | } |
218 | |||
219 | |||
220 | |||
221 | class waitRspTask extends AsyncTask<String , Integer, Void> | ||
222 | { | ||
223 | private boolean rspSuccess; | ||
224 | String param; | ||
225 | @Override | ||
226 | protected void onPreExecute() | ||
227 | { | ||
228 | bar = new ProgressDialog(groupSelect.this); | ||
229 | bar.setMessage("Processing.."); | ||
230 | bar.setIndeterminate(true); | ||
231 | bar.show(); | ||
232 | } | ||
233 | @Override | ||
234 | protected Void doInBackground(String... params) | ||
235 | { | ||
236 | param = params[0]; | ||
237 | List<ZigbeeGroup> groupList = ZigbeeAssistant.getGroups(); | ||
238 | //currGroup = 0; | ||
239 | for(int i=0;i<10;i++) | ||
240 | { | ||
241 | if(currGroup < groupList.size()) | ||
242 | { | ||
243 | //check if group response updated the groupId | ||
244 | if (groupList.get(currGroup).getStatus() == ZigbeeGroup.groupStatusActive) | ||
245 | { | ||
246 | rspSuccess = true; | ||
247 | return null; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | try | ||
252 | { | ||
253 | Thread.sleep(500); | ||
254 | } | ||
255 | catch(Exception e) | ||
256 | { | ||
257 | System.out.println(e); | ||
258 | } | ||
259 | |||
260 | } | ||
261 | |||
262 | rspSuccess = false; | ||
263 | return null; | ||
264 | } | ||
265 | @Override | ||
266 | protected void onPostExecute(Void result) | ||
267 | { | ||
268 | bar.dismiss(); | ||
269 | |||
270 | if (rspSuccess == false) | ||
271 | { | ||
272 | AlertDialog show = new AlertDialog.Builder(groupSelect.this) | ||
273 | .setTitle(param) | ||
274 | .setMessage("No response from gateway. " + param + " failed.") | ||
275 | .setPositiveButton("OK", | ||
276 | new DialogInterface.OnClickListener() | ||
277 | { | ||
278 | public void onClick(DialogInterface dialoginterface,int i){ | ||
279 | } | ||
280 | }) | ||
281 | .show(); | ||
282 | } | ||
283 | |||
284 | } | ||
285 | } | ||
286 | 217 | ||
287 | 218 | ||
288 | public void addToGroupCmdButton(View view) { | 219 | public void addToGroupCmdButton(View view) { |
@@ -326,11 +257,11 @@ public class groupSelect extends Activity { | |||
326 | ToggleButton idLightButton = (ToggleButton) findViewById(R.id.IdLightToggle); | 257 | ToggleButton idLightButton = (ToggleButton) findViewById(R.id.IdLightToggle); |
327 | if (idLightButton.isChecked()) | 258 | if (idLightButton.isChecked()) |
328 | { | 259 | { |
329 | //ZigbeeAssistant.Identify(currDevice, (short) 0x80); | 260 | ZigbeeAssistant.IdentifyDevice(currDevice, (short) 0x80); |
330 | } | 261 | } |
331 | else | 262 | else |
332 | { | 263 | { |
333 | //ZigbeeAssistant.Identify(currDevice, (short) 0); | 264 | ZigbeeAssistant.IdentifyDevice(currDevice, (short) 0); |
334 | } | 265 | } |
335 | } | 266 | } |
336 | 267 | ||
@@ -341,11 +272,11 @@ public class groupSelect extends Activity { | |||
341 | 272 | ||
342 | if (idGroupButton.isChecked()) | 273 | if (idGroupButton.isChecked()) |
343 | { | 274 | { |
344 | //ZigbeeAssistant.Identify(group, (short) 0xFFFF); | 275 | ZigbeeAssistant.IdentifyGroup(group, (short) 0xFFFF); |
345 | } | 276 | } |
346 | else | 277 | else |
347 | { | 278 | { |
348 | //ZigbeeAssistant.Identify(group, (short) 0); | 279 | ZigbeeAssistant.IdentifyGroup(group, (short) 0); |
349 | } | 280 | } |
350 | } | 281 | } |
351 | 282 | ||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/optionsMenu.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/optionsMenu.java index 74277d5..4424ec5 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/optionsMenu.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/optionsMenu.java | |||
@@ -49,6 +49,4 @@ public class optionsMenu extends Activity { | |||
49 | super.onCreate(savedInstanceState); | 49 | super.onCreate(savedInstanceState); |
50 | setContentView(R.layout.optionmenu); | 50 | setContentView(R.layout.optionmenu); |
51 | } | 51 | } |
52 | |||
53 | |||
54 | } \ No newline at end of file | 52 | } \ No newline at end of file |
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/sceneSelect.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/sceneSelect.java index 4b6b2b4..25295d5 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/sceneSelect.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/sceneSelect.java | |||
@@ -186,8 +186,7 @@ public class sceneSelect extends Activity { | |||
186 | List<ZigbeeGroup> groupList = ZigbeeAssistant.getGroups(); | 186 | List<ZigbeeGroup> groupList = ZigbeeAssistant.getGroups(); |
187 | ZigbeeAssistant.newScene(t.getText().toString(), groupList.get(currGroup).getGroupId() ); | 187 | ZigbeeAssistant.newScene(t.getText().toString(), groupList.get(currGroup).getGroupId() ); |
188 | //set selection to the new group, which will be last as this is a new one | 188 | //set selection to the new group, which will be last as this is a new one |
189 | currScene = sceneSpinnerAdapter.getCount(); | 189 | currScene = sceneSpinnerAdapter.getCount(); |
190 | new waitRspTask().execute("Create Scene"); | ||
191 | sceneSpinner.setSelection(currScene); | 190 | sceneSpinner.setSelection(currScene); |
192 | //update the spinner | 191 | //update the spinner |
193 | addItemsOnSceneSpinner(); | 192 | addItemsOnSceneSpinner(); |
@@ -195,76 +194,7 @@ public class sceneSelect extends Activity { | |||
195 | }) | 194 | }) |
196 | .setNegativeButton("Cancel", null) | 195 | .setNegativeButton("Cancel", null) |
197 | .show(); | 196 | .show(); |
198 | } | 197 | } |
199 | |||
200 | |||
201 | |||
202 | class waitRspTask extends AsyncTask<String , Integer, Void> | ||
203 | { | ||
204 | private boolean rspSuccess; | ||
205 | String param; | ||
206 | @Override | ||
207 | protected void onPreExecute() | ||
208 | { | ||
209 | bar = new ProgressDialog(sceneSelect.this); | ||
210 | bar.setMessage("Processing.."); | ||
211 | bar.setIndeterminate(true); | ||
212 | bar.show(); | ||
213 | } | ||
214 | @Override | ||
215 | protected Void doInBackground(String... params) | ||
216 | { | ||
217 | param = params[0]; | ||
218 | List<ZigbeeScene> sceneList = ZigbeeAssistant.getScenes(); | ||
219 | //currGroup = 0; | ||
220 | for(int i=0;i<10;i++) | ||
221 | { | ||
222 | if(currScene < sceneList.size()) | ||
223 | { | ||
224 | //check if group response updated the groupId | ||
225 | if (sceneList.get(currScene).getStatus() == ZigbeeScene.sceneStatusActive) | ||
226 | { | ||
227 | rspSuccess = true; | ||
228 | return null; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | try | ||
233 | { | ||
234 | Thread.sleep(500); | ||
235 | } | ||
236 | catch(Exception e) | ||
237 | { | ||
238 | System.out.println(e); | ||
239 | } | ||
240 | |||
241 | } | ||
242 | |||
243 | rspSuccess = false; | ||
244 | return null; | ||
245 | } | ||
246 | @Override | ||
247 | protected void onPostExecute(Void result) | ||
248 | { | ||
249 | bar.dismiss(); | ||
250 | |||
251 | if (rspSuccess == false) | ||
252 | { | ||
253 | AlertDialog show = new AlertDialog.Builder(sceneSelect.this) | ||
254 | .setTitle(param) | ||
255 | .setMessage("No response from gateway. " + param + " failed.") | ||
256 | .setPositiveButton("OK", | ||
257 | new DialogInterface.OnClickListener() | ||
258 | { | ||
259 | public void onClick(DialogInterface dialoginterface,int i){ | ||
260 | } | ||
261 | }) | ||
262 | .show(); | ||
263 | } | ||
264 | |||
265 | } | ||
266 | } | ||
267 | |||
268 | 198 | ||
269 | public void sceneStoreButton(View view) { | 199 | public void sceneStoreButton(View view) { |
270 | 200 | ||
diff --git a/client/AndroidClients/LightingController/src/com/lightingcontroller/zllMain.java b/client/AndroidClients/LightingController/src/com/lightingcontroller/zllMain.java index 79e050f..adfcc12 100644..100755 --- a/client/AndroidClients/LightingController/src/com/lightingcontroller/zllMain.java +++ b/client/AndroidClients/LightingController/src/com/lightingcontroller/zllMain.java | |||
@@ -44,6 +44,7 @@ import android.app.ProgressDialog; | |||
44 | import android.os.AsyncTask; | 44 | import android.os.AsyncTask; |
45 | import android.os.Bundle; | 45 | import android.os.Bundle; |
46 | import android.util.DisplayMetrics; | 46 | import android.util.DisplayMetrics; |
47 | import android.util.Log; | ||
47 | import android.view.Menu; | 48 | import android.view.Menu; |
48 | import android.view.MenuInflater; | 49 | import android.view.MenuInflater; |
49 | import android.view.MenuItem; | 50 | import android.view.MenuItem; |
@@ -72,6 +73,7 @@ import java.util.concurrent.TimeUnit; | |||
72 | import com.lightingcontroller.Zigbee.ZigbeeAssistant; | 73 | import com.lightingcontroller.Zigbee.ZigbeeAssistant; |
73 | import com.lightingcontroller.Zigbee.ZigbeeDevice; | 74 | import com.lightingcontroller.Zigbee.ZigbeeDevice; |
74 | import com.lightingcontroller.Zigbee.ZigbeeGroup; | 75 | import com.lightingcontroller.Zigbee.ZigbeeGroup; |
76 | import com.lightingcontroller.Zigbee.ZigbeeNotification; | ||
75 | import com.lightingcontroller.ColourPicker; | 77 | import com.lightingcontroller.ColourPicker; |
76 | 78 | ||
77 | public class zllMain extends Activity { | 79 | public class zllMain extends Activity { |
@@ -80,9 +82,9 @@ public class zllMain extends Activity { | |||
80 | 82 | ||
81 | public static ColourPicker colourPicker; | 83 | public static ColourPicker colourPicker; |
82 | private static ZigbeeGroup currGroup; | 84 | private static ZigbeeGroup currGroup; |
83 | private static ZigbeeDevice currDevice; | 85 | private static ZigbeeDevice currDevice = null; |
84 | private Spinner deviceSpinner; | 86 | private Spinner deviceSpinner; |
85 | private ArrayAdapter<String> deviceSpinnerAdapter; | 87 | private static ArrayAdapter<String> deviceSpinnerAdapter; |
86 | private int currentDeviceSpinnerSelection=0; | 88 | private int currentDeviceSpinnerSelection=0; |
87 | 89 | ||
88 | ProgressDialog bar; | 90 | ProgressDialog bar; |
@@ -147,6 +149,8 @@ public class zllMain extends Activity { | |||
147 | 149 | ||
148 | addItemsOnDeviceSpinner(); | 150 | addItemsOnDeviceSpinner(); |
149 | addListenerOnDeviceSpinnerItemSelection(); | 151 | addListenerOnDeviceSpinnerItemSelection(); |
152 | |||
153 | ZigbeeNotification.init(this); | ||
150 | } | 154 | } |
151 | 155 | ||
152 | // add items into spinner dynamically | 156 | // add items into spinner dynamically |
@@ -165,6 +169,11 @@ public class zllMain extends Activity { | |||
165 | { | 169 | { |
166 | deviceSpinnerAdapter.add("group: " + groupList.get(i).getGroupName()); | 170 | deviceSpinnerAdapter.add("group: " + groupList.get(i).getGroupName()); |
167 | } | 171 | } |
172 | |||
173 | if( (currDevice == null) && (devList.size() > 0) ) | ||
174 | { | ||
175 | currDevice = devList.get(0); | ||
176 | } | ||
168 | } | 177 | } |
169 | 178 | ||
170 | public void addListenerOnDeviceSpinnerItemSelection() { | 179 | public void addListenerOnDeviceSpinnerItemSelection() { |
@@ -187,7 +196,7 @@ public class zllMain extends Activity { | |||
187 | ZigbeeAssistant.getDeviceLevel(currDevice); | 196 | ZigbeeAssistant.getDeviceLevel(currDevice); |
188 | ZigbeeAssistant.getDeviceHue(currDevice); | 197 | ZigbeeAssistant.getDeviceHue(currDevice); |
189 | ZigbeeAssistant.getDeviceSat(currDevice); | 198 | ZigbeeAssistant.getDeviceSat(currDevice); |
190 | //new waitRspTask().execute("Device Select"); | 199 | new waitRspTask().execute("Device Select"); |
191 | 200 | ||
192 | currGroup = null; | 201 | currGroup = null; |
193 | } | 202 | } |
@@ -243,18 +252,22 @@ public class zllMain extends Activity { | |||
243 | if( !currDevice.getCurrentStateUpdated() ) | 252 | if( !currDevice.getCurrentStateUpdated() ) |
244 | { | 253 | { |
245 | ZigbeeAssistant.getDeviceState(currDevice); | 254 | ZigbeeAssistant.getDeviceState(currDevice); |
255 | try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();} | ||
246 | } | 256 | } |
247 | if( !currDevice.getCurrentLevelUpdated() ) | 257 | if( !currDevice.getCurrentLevelUpdated() ) |
248 | { | 258 | { |
249 | ZigbeeAssistant.getDeviceLevel(currDevice); | 259 | ZigbeeAssistant.getDeviceLevel(currDevice); |
260 | try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();} | ||
250 | } | 261 | } |
251 | if( !currDevice.getCurrentHueUpdated() ) | 262 | if( !currDevice.getCurrentHueUpdated() ) |
252 | { | 263 | { |
253 | ZigbeeAssistant.getDeviceHue(currDevice); | 264 | ZigbeeAssistant.getDeviceHue(currDevice); |
265 | try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();} | ||
254 | } | 266 | } |
255 | if( !currDevice.getCurrentSatUpdated() ) | 267 | if( !currDevice.getCurrentSatUpdated() ) |
256 | { | 268 | { |
257 | ZigbeeAssistant.getDeviceSat(currDevice); | 269 | ZigbeeAssistant.getDeviceSat(currDevice); |
270 | try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();} | ||
258 | } | 271 | } |
259 | } | 272 | } |
260 | 273 | ||
@@ -383,6 +396,11 @@ public class zllMain extends Activity { | |||
383 | 396 | ||
384 | public boolean onOptionsItemSelected(MenuItem item) { | 397 | public boolean onOptionsItemSelected(MenuItem item) { |
385 | switch (item.getItemId()) { | 398 | switch (item.getItemId()) { |
399 | case R.id.optionMenuAddDevice: | ||
400 | { | ||
401 | new addDeviceTask().execute("Add Device"); | ||
402 | } | ||
403 | break; | ||
386 | case R.id.optionMenuGroups: | 404 | case R.id.optionMenuGroups: |
387 | startActivity(new Intent(zllMain.this, groupSelect.class)); | 405 | startActivity(new Intent(zllMain.this, groupSelect.class)); |
388 | break; | 406 | break; |
@@ -408,12 +426,17 @@ public class zllMain extends Activity { | |||
408 | alert = builder.create(); | 426 | alert = builder.create(); |
409 | alert.show(); | 427 | alert.show(); |
410 | } | 428 | } |
411 | break; | 429 | break; |
412 | } | 430 | } |
413 | return true; | 431 | return true; |
414 | } | 432 | } |
415 | 433 | ||
416 | public void deviceChangeNameButton(View view) | 434 | public void deviceChangeNameButton(View view) |
435 | { | ||
436 | deviceChangeName(); | ||
437 | } | ||
438 | |||
439 | public void deviceChangeName() | ||
417 | { | 440 | { |
418 | String Title = "Set Name"; | 441 | String Title = "Set Name"; |
419 | String Msg = "Please Enter the name of the device"; | 442 | String Msg = "Please Enter the name of the device"; |
@@ -498,4 +521,84 @@ public class zllMain extends Activity { | |||
498 | ZigbeeAssistant.setDeviceLevel(currGroup, (char) level); | 521 | ZigbeeAssistant.setDeviceLevel(currGroup, (char) level); |
499 | } | 522 | } |
500 | } | 523 | } |
524 | |||
525 | class addDeviceTask extends AsyncTask<String , Integer, Void> | ||
526 | { | ||
527 | private boolean rspSuccess; | ||
528 | int numCurrentDevices; | ||
529 | int timeoutCnt; | ||
530 | String param; | ||
531 | @Override | ||
532 | protected void onPreExecute() | ||
533 | { | ||
534 | bar = new ProgressDialog(zllMain.this); | ||
535 | bar.setMessage("Searching For New Device"); | ||
536 | bar.setIndeterminate(true); | ||
537 | bar.show(); | ||
538 | |||
539 | //count number of devices | ||
540 | numCurrentDevices = ZigbeeAssistant.getDevices().size(); | ||
541 | |||
542 | //open network | ||
543 | ZigbeeAssistant.openNetwork((byte)60); | ||
544 | |||
545 | } | ||
546 | @Override | ||
547 | protected Void doInBackground(String... params) | ||
548 | { | ||
549 | param = params[0]; | ||
550 | |||
551 | //30s time out | ||
552 | for(timeoutCnt = 0; timeoutCnt < 60; timeoutCnt++) | ||
553 | { | ||
554 | try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) {e.printStackTrace();} | ||
555 | |||
556 | if( ZigbeeAssistant.getDevices().size() > numCurrentDevices) | ||
557 | { | ||
558 | rspSuccess = true; | ||
559 | return null; | ||
560 | } | ||
561 | } | ||
562 | |||
563 | rspSuccess = false; | ||
564 | return null; | ||
565 | } | ||
566 | @Override | ||
567 | protected void onPostExecute(Void result) | ||
568 | { | ||
569 | bar.dismiss(); | ||
570 | |||
571 | if (rspSuccess == false) | ||
572 | { | ||
573 | AlertDialog show = new AlertDialog.Builder(zllMain.this) | ||
574 | .setTitle(param) | ||
575 | .setMessage("No new devices found\n") | ||
576 | .setPositiveButton("OK", | ||
577 | new DialogInterface.OnClickListener() | ||
578 | { | ||
579 | public void onClick(DialogInterface dialoginterface,int i){ | ||
580 | } | ||
581 | }) | ||
582 | .show(); | ||
583 | } | ||
584 | else | ||
585 | { | ||
586 | //Let notification change the name | ||
587 | } | ||
588 | } | ||
589 | } | ||
590 | |||
591 | public static void setCurrentDevice(ZigbeeDevice device) | ||
592 | { | ||
593 | currDevice = device; | ||
594 | deviceSpinnerAdapter.clear(); | ||
595 | List<ZigbeeDevice> tList = ZigbeeAssistant.getDevices(); | ||
596 | for (int j = 0 ; j < tList.size() ; j++) | ||
597 | { | ||
598 | if (tList.get(j).hasColourable || tList.get(j).hasSwitchable || tList.get(j).hasDimmable) | ||
599 | { | ||
600 | deviceSpinnerAdapter.add(tList.get(j).Name); | ||
601 | } | ||
602 | } | ||
603 | } | ||
501 | } \ No newline at end of file | 604 | } \ No newline at end of file |
diff --git a/client/CClients/Source/socket_client.c b/client/CClients/Source/socket_client.c index 7e6241c..7e6241c 100644..100755 --- a/client/CClients/Source/socket_client.c +++ b/client/CClients/Source/socket_client.c | |||
diff --git a/client/CClients/Source/socket_client.h b/client/CClients/Source/socket_client.h index e8baae8..e8baae8 100644..100755 --- a/client/CClients/Source/socket_client.h +++ b/client/CClients/Source/socket_client.h | |||
diff --git a/client/CClients/lightFlashCmdLine/Source/flashled.c b/client/CClients/lightFlashCmdLine/Source/flashled.c index 9273277..12e6228 100644..100755 --- a/client/CClients/lightFlashCmdLine/Source/flashled.c +++ b/client/CClients/lightFlashCmdLine/Source/flashled.c | |||
@@ -3,7 +3,7 @@ | |||
3 | Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $ | 3 | Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $ |
4 | Revision: $Revision: 246 $ | 4 | Revision: $Revision: 246 $ |
5 | 5 | ||
6 | Description: This file contains an example client for the zllGateway sever | 6 | Description: This file contains an example client for the zbGateway sever |
7 | 7 | ||
8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ | 8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ |
9 | 9 | ||
@@ -59,11 +59,11 @@ int keyFd; | |||
59 | #define CONSOLEDEVICE "/dev/console" | 59 | #define CONSOLEDEVICE "/dev/console" |
60 | 60 | ||
61 | void sendLightState(uint16_t addr, uint16_t addrMode, uint16_t ep, uint8_t state); | 61 | void sendLightState(uint16_t addr, uint16_t addrMode, uint16_t ep, uint8_t state); |
62 | void socketClientZllCb( msgData_t *msg ); | 62 | void socketClientCb( msgData_t *msg ); |
63 | 63 | ||
64 | typedef uint8_t (*rpcsProcessMsg_t)(msgData_t *msg); | 64 | typedef uint8_t (*srpcProcessMsg_t)(msgData_t *msg); |
65 | 65 | ||
66 | rpcsProcessMsg_t rpcsProcessSeIncoming[] = | 66 | srpcProcessMsg_t rpcsProcessSeIncoming[] = |
67 | { | 67 | { |
68 | }; | 68 | }; |
69 | 69 | ||
@@ -77,8 +77,9 @@ int main(int argc, char *argv[]) | |||
77 | { | 77 | { |
78 | uint16_t addr, period, loops; | 78 | uint16_t addr, period, loops; |
79 | uint8_t addrMode, ep, cnt=0; | 79 | uint8_t addrMode, ep, cnt=0; |
80 | uint32 start_with = 0; | ||
80 | 81 | ||
81 | if(argc != 6) | 82 | if(argc < 6) |
82 | { | 83 | { |
83 | printf("Expected 4 and got %d params Usage: %s <device/group addr> <addr mode> <ep> <periodms> <loops>\n", argc, argv[0] ); | 84 | printf("Expected 4 and got %d params Usage: %s <device/group addr> <addr mode> <ep> <periodms> <loops>\n", argc, argv[0] ); |
84 | printf("Example - Unicast command of nwk addr 0xb85a ep 0xb every 1s: %s 0xb85a 2 0xb 1000 0\n", argv[0] ); | 85 | printf("Example - Unicast command of nwk addr 0xb85a ep 0xb every 1s: %s 0xb85a 2 0xb 1000 0\n", argv[0] ); |
@@ -101,9 +102,15 @@ int main(int argc, char *argv[]) | |||
101 | 102 | ||
102 | sscanf(argv[5], "%d", &tmpInt); | 103 | sscanf(argv[5], "%d", &tmpInt); |
103 | loops = (uint16_t) tmpInt; | 104 | loops = (uint16_t) tmpInt; |
105 | |||
106 | if (argc > 6) | ||
107 | { | ||
108 | start_with = atoi(argv[6]); | ||
109 | } | ||
110 | |||
104 | } | 111 | } |
105 | 112 | ||
106 | socketClientInit("127.0.0.1:11235", socketClientZllCb); | 113 | socketClientInit("127.0.0.1:11235", socketClientCb); |
107 | 114 | ||
108 | if(loops != 0) | 115 | if(loops != 0) |
109 | loops+=2; | 116 | loops+=2; |
@@ -112,13 +119,13 @@ int main(int argc, char *argv[]) | |||
112 | while(loops != 2) | 119 | while(loops != 2) |
113 | { | 120 | { |
114 | printf("Toggling Light %x:%x - %d\n", addr, ep, cnt++ ); | 121 | printf("Toggling Light %x:%x - %d\n", addr, ep, cnt++ ); |
115 | if((loops % 2) ==0) | 122 | if((loops % 2) == start_with) |
116 | { | 123 | { |
117 | sendLightState(addr, addrMode, ep, 0); | 124 | sendLightState(addr, addrMode, ep, 1); |
118 | } | 125 | } |
119 | else | 126 | else |
120 | { | 127 | { |
121 | sendLightState(addr, addrMode, ep, 1); | 128 | sendLightState(addr, addrMode, ep, 0); |
122 | } | 129 | } |
123 | 130 | ||
124 | usleep(period * 1000); | 131 | usleep(period * 1000); |
@@ -135,7 +142,7 @@ int main(int argc, char *argv[]) | |||
135 | } | 142 | } |
136 | 143 | ||
137 | //Process the message from HA-Interface | 144 | //Process the message from HA-Interface |
138 | void socketClientZllCb( msgData_t *msg ) | 145 | void socketClientCb( msgData_t *msg ) |
139 | { | 146 | { |
140 | //for now we are not interested in messages from HA server | 147 | //for now we are not interested in messages from HA server |
141 | } | 148 | } |
@@ -145,7 +152,7 @@ void sendLightState(uint16_t addr, uint16_t addrMode, uint16_t ep, uint8_t state | |||
145 | msgData_t msg; | 152 | msgData_t msg; |
146 | uint8_t* pRpcCmd = msg.pData; | 153 | uint8_t* pRpcCmd = msg.pData; |
147 | 154 | ||
148 | msg.cmdId = RPCS_SET_DEV_STATE; | 155 | msg.cmdId = SRPC_SET_DEV_STATE; |
149 | msg.len = 15; | 156 | msg.len = 15; |
150 | //Addr Mode | 157 | //Addr Mode |
151 | *pRpcCmd++ = (afAddrMode_t)addrMode; | 158 | *pRpcCmd++ = (afAddrMode_t)addrMode; |
diff --git a/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile b/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile index 8d799d3..8d799d3 100644..100755 --- a/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile +++ b/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile | |||
diff --git a/client/CClients/listDevsCmdLine/Source/listdevs.c b/client/CClients/listDevsCmdLine/Source/listdevs.c index 6128911..27b0afd 100644..100755 --- a/client/CClients/listDevsCmdLine/Source/listdevs.c +++ b/client/CClients/listDevsCmdLine/Source/listdevs.c | |||
@@ -1,42 +1,42 @@ | |||
1 | /************************************************************************************************** | 1 | /************************************************************************************************** |
2 | Filename: flashled.c | 2 | Filename: flashled.c |
3 | Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $ | 3 | Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $ |
4 | Revision: $Revision: 246 $ | 4 | Revision: $Revision: 246 $ |
5 | 5 | ||
6 | Description: This file contains an example client for the zllGateway sever | 6 | Description: This file contains an example client for the zbGateway sever |
7 | 7 | ||
8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ | 8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ |
9 | 9 | ||
10 | 10 | ||
11 | Redistribution and use in source and binary forms, with or without | 11 | Redistribution and use in source and binary forms, with or without |
12 | modification, are permitted provided that the following conditions | 12 | modification, are permitted provided that the following conditions |
13 | are met: | 13 | are met: |
14 | 14 | ||
15 | Redistributions of source code must retain the above copyright | 15 | Redistributions of source code must retain the above copyright |
16 | notice, this list of conditions and the following disclaimer. | 16 | notice, this list of conditions and the following disclaimer. |
17 | 17 | ||
18 | Redistributions in binary form must reproduce the above copyright | 18 | Redistributions in binary form must reproduce the above copyright |
19 | notice, this list of conditions and the following disclaimer in the | 19 | notice, this list of conditions and the following disclaimer in the |
20 | documentation and/or other materials provided with the | 20 | documentation and/or other materials provided with the |
21 | distribution. | 21 | distribution. |
22 | 22 | ||
23 | Neither the name of Texas Instruments Incorporated nor the names of | 23 | Neither the name of Texas Instruments Incorporated nor the names of |
24 | its contributors may be used to endorse or promote products derived | 24 | its contributors may be used to endorse or promote products derived |
25 | from this software without specific prior written permission. | 25 | from this software without specific prior written permission. |
26 | 26 | ||
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | 38 | ||
39 | **************************************************************************************************/ | 39 | **************************************************************************************************/ |
40 | 40 | ||
41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
42 | #include <termios.h> | 42 | #include <termios.h> |
@@ -51,93 +51,187 @@ | |||
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <poll.h> | 52 | #include <poll.h> |
53 | 53 | ||
54 | |||
55 | #include "socket_client.h" | 54 | #include "socket_client.h" |
56 | #include "interface_srpcserver.h" | 55 | #include "interface_srpcserver.h" |
57 | #include "hal_defs.h" | 56 | #include "hal_defs.h" |
58 | |||
59 | int keyFd; | ||
60 | 57 | ||
61 | #define CONSOLEDEVICE "/dev/console" | 58 | #define CONSOLEDEVICE "/dev/console" |
62 | 59 | ||
63 | void socketClientZllCb( msgData_t *msg ); | 60 | void socketClientCb(msgData_t *msg); |
64 | uint8_t RPSC_ZLL_NewDevice(uint8_t *msg); | 61 | uint8_t SRPC_NewDevice(uint8_t *msg); |
65 | static void srpcSendGetDevices( void ); | 62 | static void srpcSendGetDevices(void); |
66 | 63 | ||
67 | typedef uint8_t (*rpcsProcessMsg_t)(uint8_t *msg); | 64 | typedef uint8_t (*srpcProcessMsg_t)(uint8_t *msg); |
68 | 65 | ||
69 | rpcsProcessMsg_t rpcsProcessZllIncoming[] = | 66 | typedef struct { |
67 | char * str; | ||
68 | uint16_t id; | ||
69 | } device_id_strings_t; | ||
70 | |||
71 | device_id_strings_t device_id_strings[] = | ||
70 | { | 72 | { |
71 | NULL, | 73 | { "On/Off Switch", 0x0000 }, |
72 | RPSC_ZLL_NewDevice, | 74 | { "Level Control Switch", 0x0001 }, |
73 | }; | 75 | { "On/Off Output", 0x0002 }, |
76 | { "Level Controllable Output", 0x0003 }, | ||
77 | { "Scene Selector", 0x0004 }, | ||
78 | { "Configuration Tool", 0x0005 }, | ||
79 | { "Remote Control", 0x0006 }, | ||
80 | { "Combined Interface", 0x0007 }, | ||
81 | { "Range Extender", 0x0008 }, | ||
82 | { "Mains Power Outlet", 0x0009 }, | ||
83 | { "Door Lock", 0x000A }, | ||
84 | { "Door Lock Controller", 0x000B }, | ||
85 | { "Simple Sensor", 0x000C }, | ||
86 | { "On/Off Light", 0x0100 }, | ||
87 | { "Dimmable Light", 0x0101 }, | ||
88 | { "Color Dimmable Light", 0x0102 }, | ||
89 | { "On/Off Light Switch", 0x0103 }, | ||
90 | { "Dimmer Switch", 0x0104 }, | ||
91 | { "Color Dimmer Switch", 0x0105 }, | ||
92 | { "Light Sensor", 0x0106 }, | ||
93 | { "Occupancy Sensor", 0x0107 }, | ||
94 | { "Shade", 0x0200 }, | ||
95 | { "Shade Controller", 0x0201 }, | ||
96 | { "Window Covering Device", 0x0202 }, | ||
97 | { "Window Covering Controller", 0x0203 }, | ||
98 | { "Heating/Cooling Unit", 0x0300 }, | ||
99 | { "Thermostat", 0x0301 }, | ||
100 | { "Temperature Sensor", 0x0302 }, | ||
101 | { "Pump", 0x0303 }, | ||
102 | { "Pump Controller", 0x0304 }, | ||
103 | { "Pressure Sensor", 0x0305 }, | ||
104 | { "Flow Sensor", 0x0306 }, | ||
105 | { "IAS Control and Indicating Equipment", 0x0400 }, | ||
106 | { "IAS Ancillary Control Equipment", 0x0401 }, | ||
107 | { "IAS Zone", 0x0402 }, | ||
108 | { "IAS Warning Device", 0x0403 }, }; | ||
109 | |||
110 | srpcProcessMsg_t srpcProcessIncoming[] = | ||
111 | { NULL, SRPC_NewDevice, }; | ||
74 | 112 | ||
113 | int keyFd; | ||
75 | 114 | ||
115 | /********************************************************************* | ||
116 | * @fn main | ||
117 | * | ||
118 | * @brief | ||
119 | * | ||
120 | * @param | ||
121 | * | ||
122 | * @return | ||
123 | */ | ||
76 | int main(int argc, char *argv[]) | 124 | int main(int argc, char *argv[]) |
77 | { | 125 | { |
78 | int ret; | 126 | int ret; |
79 | 127 | ||
80 | socketClientInit("127.0.0.1:11235", socketClientZllCb); | 128 | socketClientInit("127.0.0.1:11235", socketClientCb); |
81 | 129 | ||
82 | //send get devices command | 130 | printf( |
83 | srpcSendGetDevices(); | 131 | "--- List of devices ----------------------------------------------------\n"); |
84 | 132 | printf( | |
85 | while(1) | 133 | "addr ep profID devID IEEEAddr deviceIdString\n"); |
86 | { | 134 | printf( |
87 | struct pollfd pollFds[1]; | 135 | "------ ---- ------ ------ ----------------------- ----------------------\n"); |
88 | 136 | ||
89 | pollFds[0].fd = keyFd; | 137 | //send get devices command |
90 | pollFds[0].events = POLLIN; | 138 | srpcSendGetDevices(); |
91 | 139 | ||
92 | ret = poll(pollFds, 1, -1); | 140 | while (1) |
93 | 141 | { | |
94 | if (ret > 0) | 142 | struct pollfd pollFds[1]; |
95 | { | 143 | |
96 | if( ((pollFds[0].revents) & POLLIN) ) | 144 | pollFds[0].fd = keyFd; |
97 | { | 145 | pollFds[0].events = POLLIN; |
98 | //Any key ppress will exit | 146 | |
99 | socketClientClose(); | 147 | ret = poll(pollFds, 1, -1); |
100 | exit(0); | 148 | |
101 | } | 149 | if (ret > 0) |
102 | } | 150 | { |
103 | } | 151 | if (((pollFds[0].revents) & POLLIN)) |
104 | 152 | { | |
105 | socketClientClose(); | 153 | //Any key ppress will exit |
106 | 154 | socketClientClose(); | |
107 | return 0; | 155 | exit(0); |
156 | } | ||
157 | } | ||
158 | } | ||
159 | |||
160 | socketClientClose(); | ||
161 | |||
162 | return 0; | ||
108 | } | 163 | } |
109 | 164 | ||
110 | //Process the message from SE-Interface | 165 | /********************************************************************* |
111 | void socketClientZllCb( msgData_t *msg ) | 166 | * @fn socketClientCb |
167 | * | ||
168 | * @brief | ||
169 | * | ||
170 | * @param | ||
171 | * | ||
172 | * @return | ||
173 | */ | ||
174 | void socketClientCb(msgData_t *msg) | ||
112 | { | 175 | { |
113 | rpcsProcessMsg_t func; | 176 | srpcProcessMsg_t func; |
114 | 177 | ||
115 | func = rpcsProcessZllIncoming[(msg->cmdId)]; | 178 | func = srpcProcessIncoming[(msg->cmdId)]; |
116 | if (func) | 179 | if (func) |
117 | { | 180 | { |
118 | (*func)(msg->pData); | 181 | (*func)(msg->pData); |
119 | } | 182 | } |
120 | else | ||
121 | { | ||
122 | printf("Error: no processing function for CMD 0x%x\n", msg->cmdId); | ||
123 | } | ||
124 | |||
125 | } | 183 | } |
126 | 184 | ||
127 | static void srpcSendGetDevices( void ) | 185 | /********************************************************************* |
128 | { | 186 | * @fn srpcSendGetDevices |
129 | msgData_t srpcCmd; | 187 | * |
130 | 188 | * @brief | |
131 | srpcCmd.cmdId = RPCS_GET_DEVICES; | 189 | * |
132 | srpcCmd.len = 0; | 190 | * @param |
133 | 191 | * | |
134 | socketClientSendData (&srpcCmd); | 192 | * @return |
135 | 193 | */ | |
136 | return; | 194 | static void srpcSendGetDevices(void) |
195 | { | ||
196 | msgData_t srpcCmd; | ||
197 | |||
198 | srpcCmd.cmdId = SRPC_GET_DEVICES; | ||
199 | srpcCmd.len = 0; | ||
200 | |||
201 | socketClientSendData(&srpcCmd); | ||
202 | |||
203 | return; | ||
137 | } | 204 | } |
138 | 205 | ||
139 | /********************************************************************* | 206 | /********************************************************************* |
140 | * @fn RPSC_ZLL_NewDevice | 207 | * @fn get_device_id_string |
208 | * | ||
209 | * @brief | ||
210 | * | ||
211 | * @param | ||
212 | * | ||
213 | * @return | ||
214 | */ | ||
215 | char * get_device_id_string(uint16_t id) | ||
216 | { | ||
217 | char * device_id_string = "Unknown device"; | ||
218 | int x; | ||
219 | |||
220 | for (x = 0; x < (sizeof(device_id_strings) / sizeof(device_id_strings[0])); | ||
221 | x++) | ||
222 | { | ||
223 | if (id == device_id_strings[x].id) | ||
224 | { | ||
225 | device_id_string = device_id_strings[x].str; | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | return device_id_string; | ||
231 | } | ||
232 | |||
233 | /********************************************************************* | ||
234 | * @fn SRPC_NewDevice | ||
141 | * | 235 | * |
142 | * @brief This function proccesses the NewDevice message from the ZLL Gateway. | 236 | * @brief This function proccesses the NewDevice message from the ZLL Gateway. |
143 | * | 237 | * |
@@ -145,46 +239,51 @@ static void srpcSendGetDevices( void ) | |||
145 | * | 239 | * |
146 | * @return afStatus_t | 240 | * @return afStatus_t |
147 | */ | 241 | */ |
148 | uint8_t RPSC_ZLL_NewDevice(uint8_t *pMsg) | 242 | uint8_t SRPC_NewDevice(uint8_t *pMsg) |
149 | { | 243 | { |
150 | epInfo_t epInfo; | 244 | epInfo_t epInfo; |
151 | uint8_t devNameStrLen; | 245 | uint8_t devNameStrLen; |
152 | static int i=0; | 246 | int i; |
153 | uint8_t* pTmpMsg; | 247 | char * devNameStr; |
154 | 248 | ||
155 | printf("RPSC_ZLL_NewDevice++\n"); | 249 | epInfo.nwkAddr = BUILD_UINT16(pMsg[0], pMsg[1]); |
156 | 250 | pMsg += 2; | |
157 | pTmpMsg = pMsg; | 251 | |
158 | 252 | epInfo.endpoint = *pMsg++; | |
159 | epInfo.nwkAddr = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]); | 253 | |
160 | pTmpMsg+=2; | 254 | epInfo.profileID = BUILD_UINT16(pMsg[0], pMsg[1]); |
161 | 255 | pMsg += 2; | |
162 | epInfo.endpoint = *pTmpMsg++; | 256 | |
163 | 257 | epInfo.deviceID = BUILD_UINT16(pMsg[0], pMsg[1]); | |
164 | epInfo.profileID = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]); | 258 | pMsg += 2; |
165 | pTmpMsg+=2; | 259 | |
166 | 260 | epInfo.version = *pMsg++; | |
167 | epInfo.deviceID = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]); | 261 | |
168 | pTmpMsg+=2; | 262 | //skip name for now |
169 | 263 | devNameStrLen = *pMsg++; | |
170 | epInfo.version = *pTmpMsg++; | 264 | devNameStr = (char *) pMsg; |
171 | 265 | pMsg += devNameStrLen; | |
172 | //skip name for now | 266 | |
173 | devNameStrLen = *pTmpMsg; | 267 | epInfo.status = *pMsg++; |
174 | pTmpMsg += devNameStrLen + 1; | 268 | |
175 | 269 | for (i = 0; i < 8; i++) | |
176 | epInfo.status = *pTmpMsg++; | 270 | { |
177 | 271 | //printf("srpcParseEpInfp: IEEEAddr[%d] = %x\n", i, epInfo->IEEEAddr[i]); | |
178 | epInfo.IEEEAddr[0] = *pTmpMsg++; | 272 | epInfo.IEEEAddr[i] = *pMsg++; |
179 | epInfo.IEEEAddr[1] = *pTmpMsg++; | 273 | } |
180 | epInfo.IEEEAddr[2] = *pTmpMsg++; | 274 | |
181 | epInfo.IEEEAddr[3] = *pTmpMsg++; | 275 | printf(" 0x%04X 0x%02X 0x%04X 0x%04X ", epInfo.nwkAddr, epInfo.endpoint, |
182 | epInfo.IEEEAddr[4] = *pTmpMsg++; | 276 | epInfo.profileID, epInfo.deviceID); |
183 | epInfo.IEEEAddr[5] = *pTmpMsg++; | 277 | |
184 | epInfo.IEEEAddr[6] = *pTmpMsg++; | 278 | for (i = 0; i < 8; i++) |
185 | epInfo.IEEEAddr[7] = *pTmpMsg++; | 279 | { |
186 | 280 | printf("%s%02X", i > 0 ? ":" : "", epInfo.IEEEAddr[7 - i]); | |
187 | printf("RPSC_ZLL_NewDevice[%d]: %x:%x\n", i++, epInfo.nwkAddr, epInfo.endpoint); | 281 | } |
188 | 282 | ||
189 | return 0; | 283 | printf("------"); |
284 | |||
285 | printf(" %-*s \"%.*s\"\n", 36, get_device_id_string(epInfo.deviceID), | ||
286 | devNameStrLen, devNameStr); | ||
287 | |||
288 | return 0; | ||
190 | } | 289 | } |
diff --git a/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile b/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile index 5d05687..5d05687 100644..100755 --- a/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile +++ b/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile | |||
diff --git a/client/CClients/openNetwork/Source/openNetwork.c b/client/CClients/openNetwork/Source/openNetwork.c new file mode 100755 index 0000000..589493d --- /dev/null +++ b/client/CClients/openNetwork/Source/openNetwork.c | |||
@@ -0,0 +1,161 @@ | |||
1 | /************************************************************************************************** | ||
2 | Filename: addGroup.c | ||
3 | Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $ | ||
4 | Revision: $Revision: 246 $ | ||
5 | |||
6 | Description: This file contains an example client for the zbGateway sever | ||
7 | |||
8 | Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/ | ||
9 | |||
10 | |||
11 | Redistribution and use in source and binary forms, with or without | ||
12 | modification, are permitted provided that the following conditions | ||
13 | are met: | ||
14 | |||
15 | Redistributions of source code must retain the above copyright | ||
16 | notice, this list of conditions and the following disclaimer. | ||
17 | |||
18 | Redistributions in binary form must reproduce the above copyright | ||
19 | notice, this list of conditions and the following disclaimer in the | ||
20 | documentation and/or other materials provided with the | ||
21 | distribution. | ||
22 | |||
23 | Neither the name of Texas Instruments Incorporated nor the names of | ||
24 | its contributors may be used to endorse or promote products derived | ||
25 | from this software without specific prior written permission. | ||
26 | |||
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
38 | |||
39 | **************************************************************************************************/ | ||
40 | #include <fcntl.h> | ||
41 | #include <termios.h> | ||
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <unistd.h> | ||
45 | #include <errno.h> | ||
46 | #include <string.h> | ||
47 | #include <netdb.h> | ||
48 | #include <sys/types.h> | ||
49 | #include <netinet/in.h> | ||
50 | #include <sys/socket.h> | ||
51 | #include <poll.h> | ||
52 | |||
53 | #include "socket_client.h" | ||
54 | #include "interface_srpcserver.h" | ||
55 | #include "hal_defs.h" | ||
56 | |||
57 | int keyFd; | ||
58 | uint8 waitRsp = 1; | ||
59 | |||
60 | #define CONSOLEDEVICE "/dev/console" | ||
61 | |||
62 | void sendOpenNetwork(uint8_t duration); | ||
63 | void socketClientCb(msgData_t *msg); | ||
64 | |||
65 | typedef uint8_t (*srpcProcessMsg_t)(uint8_t *msg); | ||
66 | |||
67 | srpcProcessMsg_t srpcProcessIncoming[] = | ||
68 | { | ||
69 | NULL, //0 | ||
70 | NULL, //SRPC_NEW_ZLL_DEVICE 0x0001 | ||
71 | NULL, //SRPC_RESERVED_1 0x0002 | ||
72 | NULL, //SRPC_RESERVED_2 0x0003 | ||
73 | NULL, //SRPC_RESERVED_3 0x0004 | ||
74 | NULL, //SRPC_RESERVED_4 0x0005 | ||
75 | NULL, //SRPC_RESERVED_5 0x0006 | ||
76 | NULL, //SRPC_GET_DEV_STATE_RSP 0x0007 | ||
77 | NULL, //SRPC_GET_DEV_LEVEL_RSP 0x0008 | ||
78 | NULL, //SRPC_GET_DEV_HUE_RSP 0x0009 | ||
79 | NULL, //SRPC_GET_DEV_SAT_RSP 0x000a | ||
80 | NULL, //SRPC_ADD_GROUP_RSP 0x000b | ||
81 | NULL, //SRPC_GET_GROUP_RSP 0x000c | ||
82 | NULL, //SRPC_ADD_SCENE_RSP 0x000d | ||
83 | NULL, //SRPC_GET_SCENE_RSP 0x000e | ||
84 | }; | ||
85 | |||
86 | void keyInit(void) | ||
87 | { | ||
88 | keyFd = open(CONSOLEDEVICE, O_RDONLY | O_NOCTTY | O_NONBLOCK); | ||
89 | tcflush(keyFd, TCIFLUSH); | ||
90 | } | ||
91 | |||
92 | int main(int argc, char *argv[]) | ||
93 | { | ||
94 | uint8_t duration; | ||
95 | |||
96 | if (argc < 2) | ||
97 | { | ||
98 | printf( | ||
99 | "Expected 1 and got %d params Usage: %s <duration> <addr mode> <ep> <group name>\n", | ||
100 | argc, argv[0]); | ||
101 | printf( | ||
102 | "Example - open network for 60s: %s 60\n", | ||
103 | argv[0]); | ||
104 | exit(0); | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | uint32_t tmpInt; | ||
109 | |||
110 | sscanf(argv[1], "%d", &tmpInt); | ||
111 | duration = (uint8_t) tmpInt; | ||
112 | } | ||
113 | |||
114 | socketClientInit("127.0.0.1:11235", socketClientCb); | ||
115 | |||
116 | sendOpenNetwork(duration); | ||
117 | |||
118 | sleep(1); | ||
119 | |||
120 | socketClientClose(); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | /********************************************************************* | ||
126 | * @fn socketClientCb | ||
127 | * | ||
128 | * @brief | ||
129 | * | ||
130 | * @param | ||
131 | * | ||
132 | * @return | ||
133 | */ | ||
134 | void socketClientCb(msgData_t *msg) | ||
135 | { | ||
136 | srpcProcessMsg_t func; | ||
137 | |||
138 | printf("socketClientCb: cmdId:%x\n",(msg->cmdId)); | ||
139 | |||
140 | func = srpcProcessIncoming[(msg->cmdId)]; | ||
141 | if (func) | ||
142 | { | ||
143 | (*func)(msg->pData); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | void sendOpenNetwork(uint8_t duration) | ||
148 | { | ||
149 | msgData_t msg; | ||
150 | uint8_t* pRpcCmd = msg.pData; | ||
151 | |||
152 | printf("sendOpenNetwork++: duration=%d\n", duration); | ||
153 | |||
154 | msg.cmdId = SRPC_OPEN_NETWORK; | ||
155 | msg.len = 3; | ||
156 | |||
157 | //duration | ||
158 | *pRpcCmd++ = duration; | ||
159 | |||
160 | socketClientSendData(&msg); | ||
161 | } | ||
diff --git a/client/CClients/openNetwork/i486-linux-gnu/makefile b/client/CClients/openNetwork/i486-linux-gnu/makefile new file mode 100755 index 0000000..1ea0e57 --- /dev/null +++ b/client/CClients/openNetwork/i486-linux-gnu/makefile | |||
@@ -0,0 +1,34 @@ | |||
1 | DEVICE = COORDINATOR | ||
2 | #DEVICE = ROUTER | ||
3 | #DEVICE = ENDDEV | ||
4 | |||
5 | #Relative project path | ||
6 | PROJ_DIR = | ||
7 | |||
8 | INCLUDE = -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source | ||
9 | LIBS = -lpthread | ||
10 | |||
11 | #CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc | ||
12 | CC= gcc | ||
13 | #CC=arm-angstrom-linux-gnueabi-gcc | ||
14 | #CC=arm-none-linux-gnueabi-gcc | ||
15 | #CC=/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc | ||
16 | |||
17 | CFLAGS= -c -Wall -g -std=gnu99 | ||
18 | |||
19 | all: openNetwork.bin | ||
20 | |||
21 | openNetwork.bin: openNetwork.o socket_client.o | ||
22 | $(CC) openNetwork.o socket_client.o $(LIBS) -o openNetwork.bin | ||
23 | |||
24 | # rule for file "openNetwork.o". | ||
25 | openNetwork.o: ../Source/openNetwork.c | ||
26 | $(CC) $(CFLAGS) $(INCLUDE) $(DEFS) $(PROJ_DIR)../Source/openNetwork.c | ||
27 | |||
28 | # rule for file "socket_client.o". | ||
29 | socket_client.o: $(PROJ_DIR)../../Source/socket_client.h $(PROJ_DIR)../../Source/socket_client.c | ||
30 | $(CC) $(CFLAGS) $(INCLUDE) $(DEFS) $(PROJ_DIR)../../Source/socket_client.c | ||
31 | |||
32 | # rule for cleaning files generated during compilations. | ||
33 | clean: | ||
34 | /bin/rm -f openNetwork.bin *.o | ||
diff --git a/getFwModel/getFwModel.c b/getFwModel/getFwModel.c new file mode 100755 index 0000000..094edfb --- /dev/null +++ b/getFwModel/getFwModel.c | |||
@@ -0,0 +1,178 @@ | |||
1 | /************************************************************************************************** | ||
2 | * Filename: fwGetModel.c | ||
3 | * Description: This file contains the interface to the UART. | ||
4 | * | ||
5 | * | ||
6 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ | ||
7 | * | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
22 | * its contributors may be used to endorse or promote products derived | ||
23 | * from this software without specific prior written permission. | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
36 | * | ||
37 | */ | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <poll.h> | ||
43 | |||
44 | #include "zbSocCmd.h" | ||
45 | |||
46 | uint8_t tlIndicationCb(epInfo_t *epInfo); | ||
47 | uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr, | ||
48 | uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState); | ||
49 | uint8_t zclGetModelCb(uint8_t *ModelId); | ||
50 | |||
51 | static zbSocCallbacks_t zbSocCbs = | ||
52 | { tlIndicationCb, // pfnTlIndicationCb - TouchLink Indication callback | ||
53 | NULL, // pfnNewDevIndicationCb - New Device Indication callback | ||
54 | NULL, //pfnZclGetStateCb - ZCL response callback for get State | ||
55 | NULL, //pfnZclGetLevelCb_t - ZCL response callback for get Level | ||
56 | NULL, // pfnZclGetHueCb - ZCL response callback for get Hue | ||
57 | NULL, //pfnZclGetSatCb - ZCL response callback for get Sat | ||
58 | NULL, //pfnzdoSimpleDescRspCb - ZDO simple desc rsp | ||
59 | NULL, // pfnZdoLeaveIndCb - ZDO Leave indication | ||
60 | utilGetDevInfoRspCb, //pfnUtilGetDevInfoRspCb | ||
61 | zclGetModelCb //pfnZclGetModelCb | ||
62 | }; | ||
63 | |||
64 | void usage(char* exeName) | ||
65 | { | ||
66 | printf("Usage: ./%s <port>\n", exeName); | ||
67 | printf("Eample: ./%s /dev/ttyACM0\n", exeName); | ||
68 | } | ||
69 | |||
70 | int main(int argc, char* argv[]) | ||
71 | { | ||
72 | int retval = 0; | ||
73 | int zbSoc_fd; | ||
74 | |||
75 | //printf("%s -- %s %s\n", argv[0], __DATE__, __TIME__); | ||
76 | |||
77 | |||
78 | // accept only 1 | ||
79 | if (argc != 2) | ||
80 | { | ||
81 | usage(argv[0]); | ||
82 | //printf("attempting to use /dev/ttyACM0\n"); | ||
83 | zbSoc_fd = zbSocOpen("/dev/ttyO4"); | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | zbSoc_fd = zbSocOpen(argv[1]); | ||
88 | } | ||
89 | |||
90 | if (zbSoc_fd == -1) | ||
91 | { | ||
92 | exit(-1); | ||
93 | } | ||
94 | |||
95 | zbSocRegisterCallbacks(zbSocCbs); | ||
96 | |||
97 | zbSocGetInfo(); | ||
98 | |||
99 | while (1) | ||
100 | { | ||
101 | struct pollfd pollFd; | ||
102 | |||
103 | //set the zllSoC serial port FD in the poll file descriptors | ||
104 | pollFd.fd = zbSoc_fd; | ||
105 | pollFd.events = POLLIN; | ||
106 | |||
107 | //printf("%s: waiting for poll()\n", argv[1]); | ||
108 | |||
109 | poll(&pollFd, 1, 500); | ||
110 | |||
111 | //printf("%s: got poll()\n", argv[1]); | ||
112 | |||
113 | //did the poll unblock because of the zllSoC serial? | ||
114 | if (pollFd.revents) | ||
115 | { | ||
116 | //printf("%s: Message from ZB SoC\n", argv[1]); | ||
117 | zbSocProcessRpc(); | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | //printf("timeout\n"); | ||
122 | static int timeoutCnt = 0; | ||
123 | timeoutCnt++; | ||
124 | if(timeoutCnt > 5) | ||
125 | { | ||
126 | printf("Unknown model\n"); | ||
127 | zbSocClose(); | ||
128 | exit(0); | ||
129 | } | ||
130 | else if(timeoutCnt > 3) | ||
131 | { | ||
132 | //maybe MT_UTIL is not define, assume coord (nwkAddr=0x0) and try to get model ID | ||
133 | zbSocGetModel(0x0000, 0xff, afAddr16Bit); | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | zbSocGetInfo(); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
142 | return retval; | ||
143 | } | ||
144 | |||
145 | uint8_t tlIndicationCb(epInfo_t *epInfo) | ||
146 | { | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr, | ||
152 | uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState) | ||
153 | { | ||
154 | //printf("processRpcUtilGetDevInfoRsp: status:%x devState:%x, nwkAddr:%x ieeeIdx:%x:%x:%x:%x:%x:%x:%x:%x\n", status, devState, nwkAddr, | ||
155 | //ieeeAddr[7], ieeeAddr[6], ieeeAddr[5], ieeeAddr[4], ieeeAddr[3], ieeeAddr[2], ieeeAddr[1], ieeeAddr[0]); | ||
156 | |||
157 | zbSocGetModel(nwkAddr, 0xff, afAddr16Bit); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | uint8_t zclGetModelCb(uint8_t *ModelId) | ||
163 | { | ||
164 | uint8_t strIdx; | ||
165 | printf("Model ID:"); | ||
166 | |||
167 | for(strIdx = 0; strIdx < ModelId[0]; strIdx++) | ||
168 | { | ||
169 | printf("%c", ModelId[strIdx+1]); | ||
170 | } | ||
171 | printf("\n"); | ||
172 | |||
173 | zbSocClose(); | ||
174 | exit(0); | ||
175 | |||
176 | return 0; | ||
177 | } | ||
178 | |||
diff --git a/getFwModel/makefile b/getFwModel/makefile new file mode 100755 index 0000000..f3530a1 --- /dev/null +++ b/getFwModel/makefile | |||
@@ -0,0 +1,26 @@ | |||
1 | |||
2 | SBU_REV= "0.1" | ||
3 | |||
4 | |||
5 | GCC = gcc | ||
6 | |||
7 | CFLAGS = -Wall -DVERSION_NUMBER=${SBU_REV} | ||
8 | OBJECTS = getFwModel.o ../zbSocDriver/zbSocCmd.o | ||
9 | INCLUDE = -I../zbSocDriver/ | ||
10 | DEFS = | ||
11 | |||
12 | APP_NAME=getFwModel.bin | ||
13 | |||
14 | .PHONY: all, clean | ||
15 | |||
16 | ${APP_NAME}: ${OBJECTS} | ||
17 | $(GCC) $(CFLAGS) $(OBJECTS) -o ${APP_NAME} | ||
18 | |||
19 | %.o: %.c | ||
20 | ${GCC} ${CFLAGS} ${INCLUDE} ${DEFS} -c -o $@ $< | ||
21 | |||
22 | all: ${APP_NAME} | ||
23 | |||
24 | clean: | ||
25 | rm -rf *.o ${APP_NAME} | ||
26 | rm -rf ../zbSocDriver/*.o ${APP_NAME} | ||
diff --git a/server/Source/SimpleDB.c b/server/Source/SimpleDB.c new file mode 100755 index 0000000..bc486fe --- /dev/null +++ b/server/Source/SimpleDB.c | |||
@@ -0,0 +1,611 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <errno.h> | ||
5 | #include <stdint.h> | ||
6 | #include "hal_types.h" | ||
7 | #include "SimpleDB.h" | ||
8 | |||
9 | #define TEMP_FILENAME_EXTENTION_LENGTH 4 | ||
10 | |||
11 | int sdbErrno; | ||
12 | |||
13 | typedef struct { | ||
14 | char name[MAX_SUPPORTED_FILENAME + TEMP_FILENAME_EXTENTION_LENGTH + 1]; | ||
15 | FILE * file; | ||
16 | long last_accessed_record_start_file_pointer; | ||
17 | uint32_t last_accessed_record_size; | ||
18 | get_record_size_f get_record_size; | ||
19 | check_deleted_f check_deleted; | ||
20 | check_ignore_f check_ignore; | ||
21 | mark_deleted_f mark_deleted; | ||
22 | consolidation_processing_f consolidation_processing; | ||
23 | uint8_t type; | ||
24 | uint32_t bin_header_size; | ||
25 | } _db_descriptor; | ||
26 | |||
27 | db_descriptor * sdb_init_db(char * name, get_record_size_f get_record_size, | ||
28 | check_deleted_f check_deleted, check_ignore_f check_ignore, | ||
29 | mark_deleted_f mark_deleted, | ||
30 | consolidation_processing_f consolidation_processing, uint8_t db_type, | ||
31 | uint32_t db_bin_header_size) | ||
32 | { | ||
33 | _db_descriptor * db; | ||
34 | int abort = FALSE; | ||
35 | |||
36 | db = malloc(sizeof(_db_descriptor)); | ||
37 | |||
38 | if (db != NULL) | ||
39 | { | ||
40 | if (strlen(name) > MAX_SUPPORTED_FILENAME) | ||
41 | { | ||
42 | abort = TRUE; | ||
43 | } | ||
44 | else | ||
45 | { | ||
46 | strcpy(db->name, name); | ||
47 | |||
48 | db->file = fopen(name, (db_type == SDB_TYPE_TEXT) ? "r+t" : "r+b"); | ||
49 | if ((db->file == NULL) && (errno == ENOENT)) | ||
50 | { | ||
51 | db->file = fopen(name, (db_type == SDB_TYPE_TEXT) ? "w+t" : "w+b"); | ||
52 | } | ||
53 | |||
54 | if (db->file == NULL) | ||
55 | { | ||
56 | abort = TRUE; | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | db->last_accessed_record_start_file_pointer = 0; | ||
61 | db->last_accessed_record_size = 0; | ||
62 | db->get_record_size = get_record_size; | ||
63 | db->check_deleted = check_deleted; | ||
64 | db->check_ignore = check_ignore; | ||
65 | db->mark_deleted = mark_deleted; | ||
66 | db->consolidation_processing = consolidation_processing; | ||
67 | db->type = db_type; | ||
68 | db->bin_header_size = db_bin_header_size; //used only for binary-type databases. | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | if (abort) | ||
74 | { | ||
75 | free(db); | ||
76 | db = NULL; | ||
77 | } | ||
78 | |||
79 | return (db_descriptor *) db; | ||
80 | } | ||
81 | |||
82 | bool sdb_release_db(db_descriptor ** _db) | ||
83 | { | ||
84 | _db_descriptor * db = *_db; | ||
85 | |||
86 | if (db != NULL) | ||
87 | { | ||
88 | fclose(db->file); | ||
89 | free(db); | ||
90 | *_db = NULL; | ||
91 | return TRUE; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | return FALSE; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void sdb_flush_db(db_descriptor * db) | ||
100 | { | ||
101 | // do nothing. | ||
102 | // In the current implementation, flushing is done automatically after every change | ||
103 | } | ||
104 | |||
105 | bool sdb_release_record(void ** record) | ||
106 | { | ||
107 | // In the current implementation, the retrieved record is statically allocated, so no need to release it. | ||
108 | *record = NULL; | ||
109 | return TRUE; | ||
110 | } | ||
111 | |||
112 | bool sdb_add_record(db_descriptor * _db, void * rec) | ||
113 | { | ||
114 | _db_descriptor * db = _db; | ||
115 | |||
116 | if (fseek(db->file, 0, SEEK_END) != 0) | ||
117 | { | ||
118 | return FALSE; | ||
119 | } | ||
120 | |||
121 | db->last_accessed_record_start_file_pointer = ftell(db->file); | ||
122 | db->last_accessed_record_size = db->get_record_size(rec); | ||
123 | |||
124 | return ((fwrite(rec, db->get_record_size(rec), 1, db->file) == 1) | ||
125 | && (fflush(db->file) == 0)); | ||
126 | } | ||
127 | |||
128 | bool sdb_modify_last_accessed_record(db_descriptor * _db, void * record) | ||
129 | { | ||
130 | _db_descriptor * db = _db; | ||
131 | |||
132 | if ((db->get_record_size(record) != db->last_accessed_record_size) | ||
133 | || ((fseek(db->file, db->last_accessed_record_start_file_pointer, | ||
134 | SEEK_SET) != 0) | ||
135 | || (fwrite(record, db->last_accessed_record_size, 1, db->file) != 1) | ||
136 | || (fflush(db->file) != 0))) | ||
137 | { | ||
138 | return FALSE; | ||
139 | } | ||
140 | |||
141 | return TRUE; | ||
142 | } | ||
143 | |||
144 | void * sdb_delete_record(db_descriptor * _db, void * key, check_key_f check_key) | ||
145 | { | ||
146 | _db_descriptor * db = _db; | ||
147 | void * rec; | ||
148 | uint32_t size; | ||
149 | |||
150 | sdbErrno = 0; | ||
151 | |||
152 | rec = sdb_get_record(db, key, check_key, NULL); | ||
153 | |||
154 | if (rec != NULL) | ||
155 | { | ||
156 | |||
157 | size = db->get_record_size(rec); | ||
158 | db->mark_deleted(rec); | ||
159 | |||
160 | if (!sdb_modify_last_accessed_record(db, rec)) | ||
161 | { | ||
162 | sdbErrno = 1; | ||
163 | rec = NULL; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | return rec; | ||
168 | } | ||
169 | |||
170 | bool sdb_rename_db(db_descriptor * _db, char * newName) | ||
171 | { | ||
172 | _db_descriptor * db = _db; | ||
173 | int rc; | ||
174 | |||
175 | fclose(db->file); | ||
176 | |||
177 | rc = rename(db->name, newName); | ||
178 | if (rc != 0) | ||
179 | { | ||
180 | return FALSE; | ||
181 | } | ||
182 | |||
183 | strcpy(db->name, newName); | ||
184 | |||
185 | db->file = fopen(db->name, (db->type == SDB_TYPE_TEXT) ? "r+t" : "r+b"); | ||
186 | |||
187 | if (db->file == NULL) | ||
188 | { | ||
189 | return FALSE; | ||
190 | } | ||
191 | |||
192 | return TRUE; | ||
193 | } | ||
194 | |||
195 | bool sdb_consolidate_db(db_descriptor ** _db) | ||
196 | { | ||
197 | _db_descriptor * db = *_db; | ||
198 | _db_descriptor * tempDb; | ||
199 | void * rec; | ||
200 | uint32_t context; | ||
201 | int rc; | ||
202 | |||
203 | char tempfilename[MAX_SUPPORTED_FILENAME + TEMP_FILENAME_EXTENTION_LENGTH + 1]; | ||
204 | |||
205 | strcpy(tempfilename, db->name); | ||
206 | strcat(tempfilename, ".tmp"); | ||
207 | |||
208 | rc = remove(tempfilename); | ||
209 | if ((rc != 0) && (errno != ENOENT)) | ||
210 | { | ||
211 | return FALSE; | ||
212 | } | ||
213 | |||
214 | tempDb = sdb_init_db(tempfilename, db->get_record_size, db->check_deleted, | ||
215 | db->check_ignore, db->mark_deleted, db->consolidation_processing, | ||
216 | db->type, db->bin_header_size); | ||
217 | |||
218 | if (tempDb == NULL) | ||
219 | { | ||
220 | return FALSE; | ||
221 | } | ||
222 | |||
223 | db->check_ignore = NULL; //only deleted lines should be removed. Ignored lines should stay. | ||
224 | |||
225 | rec = SDB_GET_FIRST_RECORD(db, &context); | ||
226 | rc = TRUE; | ||
227 | while ((rec != NULL) && (rc == TRUE)) | ||
228 | { | ||
229 | |||
230 | if (db->consolidation_processing != NULL) | ||
231 | { | ||
232 | rc = db->consolidation_processing(tempDb, rec); | ||
233 | // devListErrorComment(tempDb, rec); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | rc = sdb_add_record(tempDb, rec); | ||
238 | } | ||
239 | |||
240 | rec = SDB_GET_NEXT_RECORD(db, &context); | ||
241 | } | ||
242 | |||
243 | strcpy(tempfilename, db->name); | ||
244 | |||
245 | sdb_release_db(_db); | ||
246 | (*_db) = tempDb; | ||
247 | |||
248 | rc = remove(tempfilename); | ||
249 | |||
250 | if (rc != 0) | ||
251 | { | ||
252 | return FALSE; | ||
253 | } | ||
254 | |||
255 | rc = sdb_rename_db(*_db, tempfilename); | ||
256 | |||
257 | return rc; | ||
258 | } | ||
259 | |||
260 | void * sdb_get_record(db_descriptor * _db, void * key, check_key_f check_key, | ||
261 | uint32_t * context) | ||
262 | { | ||
263 | _db_descriptor * db = _db; | ||
264 | static char rec[MAX_SUPPORTED_RECORD_SIZE]; | ||
265 | bool found = FALSE; | ||
266 | uint32_t _context; | ||
267 | |||
268 | if (context != NULL) | ||
269 | { | ||
270 | _context = *context; | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | _context = 0; | ||
275 | } | ||
276 | |||
277 | int curPos = ftell(db->file); | ||
278 | fseek(db->file, 0, SEEK_END); | ||
279 | fseek(db->file, curPos, SEEK_SET); | ||
280 | |||
281 | if (ftell(db->file) != _context) | ||
282 | { | ||
283 | fseek(db->file, _context, SEEK_SET); | ||
284 | } | ||
285 | |||
286 | if (db->type == SDB_TYPE_TEXT) | ||
287 | { | ||
288 | while ((!found) && (fgets(rec, sizeof(rec), db->file) != NULL)) //order matters!!! | ||
289 | { | ||
290 | db->last_accessed_record_start_file_pointer = _context; | ||
291 | db->last_accessed_record_size = db->get_record_size(rec); | ||
292 | _context = ftell(db->file); | ||
293 | |||
294 | if (rec[strlen(rec) - 1] != '\n') | ||
295 | { | ||
296 | //todo: set errno: record too long | ||
297 | return NULL; | ||
298 | } | ||
299 | |||
300 | if ((!(db->check_deleted(rec))) | ||
301 | && ((db->check_ignore == NULL) || (!(db->check_ignore(rec)))) | ||
302 | && ((check_key == NULL) | ||
303 | || (check_key(rec, key) == SDB_CHECK_KEY_EQUAL))) | ||
304 | { | ||
305 | found = TRUE; | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | else //db->type == SDB_TYPE_BINARY | ||
310 | { | ||
311 | //todo | ||
312 | } | ||
313 | |||
314 | if (!found) | ||
315 | { | ||
316 | return NULL; | ||
317 | } | ||
318 | |||
319 | if (context != NULL) | ||
320 | { | ||
321 | *context = _context; | ||
322 | } | ||
323 | |||
324 | return rec; | ||
325 | } | ||
326 | |||
327 | /***** USAGE EXAMPLE *************************************************************** | ||
328 | |||
329 | uint32_t text_db_get_record_size(void * record) | ||
330 | { | ||
331 | return strlen(record); | ||
332 | } | ||
333 | |||
334 | uint32_t text_db_check_deleted(void * record) | ||
335 | { | ||
336 | return (((char *)record)[0] == ';'); | ||
337 | } | ||
338 | |||
339 | void text_db_mark_deleted(void * record) | ||
340 | { | ||
341 | ((char *)record)[0] = ';'; | ||
342 | } | ||
343 | |||
344 | bool text_db_check_key_test(void * record, void * key) | ||
345 | { | ||
346 | return memcmp(((char *)record) + 2, key, 4); | ||
347 | } | ||
348 | |||
349 | void main(void) | ||
350 | { | ||
351 | char * rec; | ||
352 | uint32_t context = 0; | ||
353 | |||
354 | _db_descriptor * db; | ||
355 | db = sdb_init_db("c:\\temp\\testdb.txt", text_db_get_record_size, text_db_check_deleted, text_db_mark_deleted, SDB_TYPE_TEXT, 0); | ||
356 | sdb_add_record(db, "Hello world!\n"); | ||
357 | sdb_add_record(db, "Hello world2!\n"); | ||
358 | sdb_add_record(db, "This is line #2...\n"); | ||
359 | sdb_add_record(db, "Hello world3!\n"); | ||
360 | sdb_add_record(db, "And this is the third one.\n"); | ||
361 | sdb_add_record(db, "Hello world4!\n"); | ||
362 | sdb_add_record(db, "Hello world5!\n"); | ||
363 | sdb_delete_record(db,"llo ", text_db_check_key_test); | ||
364 | |||
365 | while ((rec = sdb_get_record(db,"llo ", text_db_check_key_test, &context)) != NULL) | ||
366 | { | ||
367 | printf("-->%s", rec); | ||
368 | } | ||
369 | |||
370 | rec = SDB_GET_FIRST_RECORD(db, &context); | ||
371 | while (rec != NULL) | ||
372 | { | ||
373 | printf("=->%s", rec); | ||
374 | rec = SDB_GET_NEXT_RECORD(db, &context); | ||
375 | } | ||
376 | |||
377 | sdb_consolidate_db(&db); | ||
378 | |||
379 | rec = SDB_GET_FIRST_RECORD(db, &context); | ||
380 | while (rec != NULL) | ||
381 | { | ||
382 | printf("=->%s", rec); | ||
383 | rec = SDB_GET_NEXT_RECORD(db, &context); | ||
384 | } | ||
385 | |||
386 | sdb_release_db(&db); | ||
387 | } | ||
388 | */ | ||
389 | |||
390 | const char * parsingErrorStrings[] = | ||
391 | { "SDB_TXT_PARSER_RESULT_OK", "SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD", | ||
392 | "SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG", | ||
393 | "SDB_TXT_PARSER_RESULT_FIELD_MISSING", | ||
394 | "SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT", | ||
395 | "SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE", | ||
396 | "SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE", | ||
397 | "SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE", | ||
398 | "SDB_TXT_PARSER_RESULT_STRING_TOO_LONG", }; | ||
399 | |||
400 | void sdb_txt_parser_move_to_next_field(char ** pBuf, parsingResult_t * result) | ||
401 | { | ||
402 | while ((result->code == SDB_TXT_PARSER_RESULT_OK) && (**pBuf != ',') | ||
403 | && (**pBuf != '\0')) | ||
404 | { | ||
405 | if ((**pBuf != ' ') && (**pBuf != '\t') && (**pBuf != '\n') | ||
406 | && (**pBuf != '\r')) | ||
407 | { | ||
408 | result->code = SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG; | ||
409 | //printf("char is %d\n", **pBuf); | ||
410 | result->errorLocation = *pBuf; | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | (*pBuf)++; | ||
415 | } | ||
416 | } | ||
417 | |||
418 | if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
419 | { | ||
420 | if (**pBuf == '\0') | ||
421 | { | ||
422 | result->code = SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD; | ||
423 | result->errorLocation = *pBuf; | ||
424 | } | ||
425 | else | ||
426 | { | ||
427 | (*pBuf)++; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | } | ||
432 | |||
433 | void sdb_txt_parser_get_hex_field(char ** pBuf, uint8_t * field, uint32_t len, | ||
434 | parsingResult_t * result) | ||
435 | { | ||
436 | int i; | ||
437 | unsigned long tempNum; | ||
438 | |||
439 | if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD) | ||
440 | { | ||
441 | result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING; | ||
442 | result->errorLocation = *pBuf; | ||
443 | } | ||
444 | else | ||
445 | { | ||
446 | for (i = 0; (result->code == SDB_TXT_PARSER_RESULT_OK) && (i < len); i++) | ||
447 | { | ||
448 | tempNum = strtoul(*pBuf, pBuf, 16); | ||
449 | if ((errno == ERANGE) | (tempNum > 0xFF)) | ||
450 | { | ||
451 | result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
452 | result->errorLocation = (*pBuf) - 1; | ||
453 | } | ||
454 | else | ||
455 | { | ||
456 | field[(len - 1) - i] = (uint8) tempNum; | ||
457 | |||
458 | if (i < (len - 1)) | ||
459 | { | ||
460 | if (**pBuf != ':') | ||
461 | { | ||
462 | result->code = | ||
463 | SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT; | ||
464 | result->errorLocation = *pBuf; | ||
465 | // printf("pBuf=%p, *pBuf=%p, **pBuf=%d\n", pBuf, *pBuf, **pBuf); | ||
466 | // printf(":result->errorLocation=%p\n", result->errorLocation); | ||
467 | } | ||
468 | else | ||
469 | { | ||
470 | (*pBuf)++; | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | } | ||
475 | |||
476 | if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
477 | { | ||
478 | result->field++; | ||
479 | sdb_txt_parser_move_to_next_field(pBuf, result); | ||
480 | } | ||
481 | } | ||
482 | } | ||
483 | |||
484 | void sdb_txt_parser_get_numeric_field(char ** pBuf, uint8_t * field, | ||
485 | uint32_t len, bool isSigned, parsingResult_t * result) | ||
486 | { | ||
487 | union { | ||
488 | signed long sNum; | ||
489 | unsigned long uNum; | ||
490 | } temp; | ||
491 | int i; | ||
492 | |||
493 | if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD) | ||
494 | { | ||
495 | result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING; | ||
496 | result->errorLocation = *pBuf; | ||
497 | } | ||
498 | else if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
499 | { | ||
500 | if (isSigned) | ||
501 | { | ||
502 | temp.sNum = strtol(*pBuf, pBuf, 0); | ||
503 | |||
504 | if ((errno == ERANGE) | ||
505 | || (temp.sNum > (((signed long) 0x7F) << (8 * (len - 1)))) | ||
506 | || (temp.sNum < (((signed long) 0x80) << (8 * (len - 1))))) | ||
507 | { | ||
508 | result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
509 | result->errorLocation = (*pBuf) - 1; | ||
510 | } | ||
511 | } | ||
512 | else | ||
513 | { | ||
514 | temp.uNum = strtoul(*pBuf, pBuf, 0); | ||
515 | //printf("%u >? %u",temp.uNum, (((unsigned long)0xFF) << (8*(len-1)))); | ||
516 | if ((errno == ERANGE) | ||
517 | || (temp.uNum > (((unsigned long) 0xFF) << (8 * (len - 1))))) | ||
518 | { | ||
519 | result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
520 | result->errorLocation = (*pBuf) - 1; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | // From this point, only temp.uNum is used. It actually access temp.sNum, since temp is a union | ||
525 | |||
526 | if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
527 | { | ||
528 | for (i = 0; i < len; i++) | ||
529 | { | ||
530 | *field++ = temp.uNum & 0xFF; //note: assuming little endian machine | ||
531 | temp.uNum >>= 8; | ||
532 | } | ||
533 | |||
534 | if (temp.uNum != 0) | ||
535 | { | ||
536 | result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
537 | result->errorLocation = (*pBuf) - 1; | ||
538 | } | ||
539 | else | ||
540 | { | ||
541 | result->field++; | ||
542 | sdb_txt_parser_move_to_next_field(pBuf, result); | ||
543 | } | ||
544 | } | ||
545 | } | ||
546 | } | ||
547 | |||
548 | void sdb_txt_parser_get_quoted_string(char ** pBuf, char * field, size_t size, | ||
549 | parsingResult_t * result) | ||
550 | { | ||
551 | char * tmpPtr; | ||
552 | size_t stringLen; | ||
553 | |||
554 | if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD) | ||
555 | { | ||
556 | result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING; | ||
557 | result->errorLocation = *pBuf; | ||
558 | } | ||
559 | else | ||
560 | { | ||
561 | while ((result->code == SDB_TXT_PARSER_RESULT_OK) && (**pBuf != '\"') | ||
562 | && (**pBuf != '\0')) | ||
563 | { | ||
564 | if ((**pBuf != ' ') && (**pBuf != '\t')) | ||
565 | { | ||
566 | result->code = SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE; | ||
567 | result->errorLocation = *pBuf; | ||
568 | } | ||
569 | else | ||
570 | { | ||
571 | (*pBuf)++; | ||
572 | } | ||
573 | } | ||
574 | |||
575 | if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
576 | { | ||
577 | (*pBuf)++; | ||
578 | tmpPtr = *pBuf; | ||
579 | while ((**pBuf != '\"') && (**pBuf != '\0')) | ||
580 | { | ||
581 | (*pBuf)++; | ||
582 | } | ||
583 | |||
584 | if (**pBuf != '\"') | ||
585 | { | ||
586 | result->code = SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE; | ||
587 | result->errorLocation = *pBuf; | ||
588 | } | ||
589 | else | ||
590 | { | ||
591 | stringLen = *pBuf - tmpPtr; | ||
592 | if (stringLen > size) | ||
593 | { | ||
594 | result->code = SDB_TXT_PARSER_RESULT_STRING_TOO_LONG; | ||
595 | result->errorLocation = tmpPtr + size; | ||
596 | } | ||
597 | } | ||
598 | |||
599 | if (result->code == SDB_TXT_PARSER_RESULT_OK) | ||
600 | { | ||
601 | (*pBuf)++; | ||
602 | memcpy(field, tmpPtr, stringLen); | ||
603 | field[stringLen] = '\0'; | ||
604 | |||
605 | result->field++; | ||
606 | sdb_txt_parser_move_to_next_field(pBuf, result); | ||
607 | } | ||
608 | } | ||
609 | } | ||
610 | } | ||
611 | |||
diff --git a/server/Source/SimpleDB.h b/server/Source/SimpleDB.h new file mode 100755 index 0000000..f302968 --- /dev/null +++ b/server/Source/SimpleDB.h | |||
@@ -0,0 +1,93 @@ | |||
1 | #ifndef SIMPLE_DB_H | ||
2 | #define SIMPLE_DB_H | ||
3 | |||
4 | #ifdef __cplusplus | ||
5 | extern "C" { | ||
6 | #endif | ||
7 | |||
8 | /* | ||
9 | #define FALSE 0 | ||
10 | #define TRUE (!FALSE) | ||
11 | typedef int bool; | ||
12 | typedef unsigned __int32 uint32_t; | ||
13 | typedef unsigned __int8 uint8_t; | ||
14 | */ | ||
15 | |||
16 | #define MAX_SUPPORTED_RECORD_SIZE 500 | ||
17 | #define MAX_SUPPORTED_FILENAME 100 | ||
18 | |||
19 | #define SDB_CHECK_KEY_EQUAL 0 | ||
20 | #define SDB_CHECK_KEY_BIGGER 1 | ||
21 | #define SDB_CHECK_KEY_SMALLER (-1) | ||
22 | #define SDB_CHECK_KEY_NOT_EQUAL 2 | ||
23 | #define SDB_CHECK_KEY_ERROR 3 | ||
24 | |||
25 | enum { | ||
26 | SDB_TYPE_TEXT, SDB_TYPE_BINARY | ||
27 | }; | ||
28 | |||
29 | typedef void db_descriptor; | ||
30 | |||
31 | typedef int (*check_key_f)(void * record, void * key); | ||
32 | typedef uint32 (*get_record_size_f)(void * record); | ||
33 | typedef bool (*check_deleted_f)(void * record); | ||
34 | typedef bool (*check_ignore_f)(void * record); | ||
35 | typedef void (*mark_deleted_f)(void * record); | ||
36 | typedef bool (*consolidation_processing_f)(db_descriptor * db, void * record); | ||
37 | |||
38 | typedef struct { | ||
39 | char * errorLocation; | ||
40 | int code; | ||
41 | uint16_t field; | ||
42 | } parsingResult_t; | ||
43 | |||
44 | db_descriptor * sdb_init_db(char * name, get_record_size_f get_record_size, | ||
45 | check_deleted_f check_deleted, check_ignore_f check_ignore, | ||
46 | mark_deleted_f mark_deleted, | ||
47 | consolidation_processing_f consolidation_processing, uint8_t db_type, | ||
48 | uint32_t db_bin_header_size); | ||
49 | bool sdb_add_record(db_descriptor * db, void * rec); | ||
50 | void * sdb_delete_record(db_descriptor * db, void * key, check_key_f check_key); | ||
51 | bool sdb_consolidate_db(db_descriptor ** db); | ||
52 | void * sdb_get_record(db_descriptor * db, void * key, check_key_f check_key, | ||
53 | uint32_t * context); | ||
54 | bool sdb_release_record(void ** record); | ||
55 | bool sdb_release_db(db_descriptor ** db); | ||
56 | void sdb_flush_db(db_descriptor * db); | ||
57 | bool sdb_modify_last_accessed_record(db_descriptor * _db, void * record); | ||
58 | #define SDB_GET_FIRST_RECORD(_db, _context) ((*(_context) = 0), sdb_get_record((_db), NULL, NULL, _context)) | ||
59 | #define SDB_GET_NEXT_RECORD(_db, _context) (sdb_get_record((_db), NULL, NULL, _context)) | ||
60 | #define SDB_GET_UNIQUE_RECORD(_db, _key, _check_key_func) (sdb_get_record((_db), (_key), (_check_key_func), NULL)) | ||
61 | |||
62 | extern int sdbErrno; | ||
63 | extern const char * parsingErrorStrings[]; | ||
64 | |||
65 | /* Macros for parsing records of a TEXT based database */ | ||
66 | /* The following variables are expected to be defined (and initialized as specified): */ | ||
67 | /* bool end_of_record = FALSE; */ | ||
68 | /* char * pBuf = record; */ | ||
69 | |||
70 | #define SDB_TXT_PARSER_RESULT_OK 0 | ||
71 | #define SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD 1 | ||
72 | #define SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG 2 | ||
73 | #define SDB_TXT_PARSER_RESULT_FIELD_MISSING 3 | ||
74 | #define SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT 4 | ||
75 | #define SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE 5 | ||
76 | #define SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE 6 | ||
77 | #define SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE 7 | ||
78 | #define SDB_TXT_PARSER_RESULT_STRING_TOO_LONG 8 | ||
79 | #define SDB_TXT_PARSER_RESULT_MAX 8 | ||
80 | |||
81 | void sdb_txt_parser_get_hex_field(char ** pBuf, uint8_t * field, uint32_t len, | ||
82 | parsingResult_t * reault); | ||
83 | void sdb_txt_parser_get_numeric_field(char ** pBuf, uint8_t * field, | ||
84 | uint32_t len, bool isSigned, parsingResult_t * reault); //, int * prev_result); | ||
85 | void sdb_txt_parser_get_quoted_string(char ** pBuf, char * field, size_t size, | ||
86 | parsingResult_t * reault); | ||
87 | |||
88 | #ifdef __cplusplus | ||
89 | } | ||
90 | #endif | ||
91 | |||
92 | #endif /* SIMPLE_DB_H */ | ||
93 | |||
diff --git a/server/Source/SimpleDBTxt.c b/server/Source/SimpleDBTxt.c new file mode 100755 index 0000000..02d64ee --- /dev/null +++ b/server/Source/SimpleDBTxt.c | |||
@@ -0,0 +1,128 @@ | |||
1 | //This is a specific implemntation of a text-based db system, based on the SimpleDB module | ||
2 | |||
3 | #include <stdint.h> | ||
4 | #include <string.h> | ||
5 | #include <stdio.h> | ||
6 | #include "hal_types.h" | ||
7 | #include "SimpleDBTxt.h" | ||
8 | |||
9 | uint32_t sdbtGetRecordSize(void * record) | ||
10 | { | ||
11 | return strlen(record); | ||
12 | } | ||
13 | |||
14 | bool sdbtCheckDeleted(void * record) | ||
15 | { | ||
16 | return (((char *) record)[0] == SDBT_DELETED_LINE_CHARACTER); | ||
17 | } | ||
18 | |||
19 | bool sdbtCheckIgnored(void * record) | ||
20 | { | ||
21 | return ((((char *) record)[0] == SDBT_BAD_FORMAT_CHARACTER) | ||
22 | || (((char *) record)[0] == SDBT_PENDING_COMMENT_FORMAT_CHARACTER)); | ||
23 | } | ||
24 | |||
25 | void sdbtMarkDeleted(void * record) | ||
26 | { | ||
27 | ((char *) record)[0] = ';'; | ||
28 | } | ||
29 | |||
30 | uint32_t sdbtGetRecordCount(db_descriptor * db) | ||
31 | { | ||
32 | uint32_t recordCnt = 0; | ||
33 | char * rec; | ||
34 | uint32_t context; | ||
35 | |||
36 | rec = SDB_GET_FIRST_RECORD(db, &context); | ||
37 | |||
38 | while (rec != NULL) | ||
39 | { | ||
40 | recordCnt++; | ||
41 | rec = SDB_GET_NEXT_RECORD(db, &context); | ||
42 | } | ||
43 | |||
44 | return recordCnt; | ||
45 | } | ||
46 | |||
47 | bool sdbtErrorComment(db_descriptor * db, char * record) | ||
48 | { | ||
49 | parsingResult_t parsingResult = | ||
50 | { SDB_TXT_PARSER_RESULT_OK, 0 }; | ||
51 | char * pBuf = record + 1; | ||
52 | char comment[MAX_SUPPORTED_RECORD_SIZE]; | ||
53 | uint8_t errorCode; | ||
54 | uint16_t errorOffset; | ||
55 | bool rc; | ||
56 | char tempstr[3] = | ||
57 | { SDBT_BAD_FORMAT_CHARACTER, '\n', '\0' }; | ||
58 | |||
59 | if (record[0] == SDBT_PENDING_COMMENT_FORMAT_CHARACTER) | ||
60 | { | ||
61 | record[0] = SDBT_BAD_FORMAT_CHARACTER; | ||
62 | sprintf(comment, "%c-------\n", SDBT_BAD_FORMAT_CHARACTER); | ||
63 | rc = sdb_add_record(db, comment) && sdb_add_record(db, record); | ||
64 | |||
65 | if (rc == TRUE) | ||
66 | { | ||
67 | // printf("here&\n"); | ||
68 | sdb_txt_parser_get_numeric_field(&pBuf, &errorCode, 1, FALSE, | ||
69 | &parsingResult); | ||
70 | if (errorCode > SDB_TXT_PARSER_RESULT_MAX) | ||
71 | { | ||
72 | //printf("here0\n"); | ||
73 | parsingResult.code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
74 | parsingResult.errorLocation = pBuf - 2; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | //printf("here1 %d \n", parsingResult.code); | ||
79 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &errorOffset, 2, | ||
80 | FALSE, &parsingResult); | ||
81 | if (errorOffset >= strlen(record)) | ||
82 | { | ||
83 | parsingResult.code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE; | ||
84 | parsingResult.errorLocation = pBuf - 2; | ||
85 | } | ||
86 | } | ||
87 | // printf("here2\n"); | ||
88 | if (parsingResult.code == SDB_TXT_PARSER_RESULT_OK) | ||
89 | { | ||
90 | // printf("here3\n"); | ||
91 | // printf("%s\n%d %d\n", record, errorOffset - 7 + 1, errorCode); | ||
92 | sprintf(comment, "%cERROR:%*s %s\n", SDBT_BAD_FORMAT_CHARACTER, | ||
93 | errorOffset - 7 + 1, "^", parsingErrorStrings[errorCode]); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | // printf("here4\n"); | ||
98 | // printf("%s\n%d %d\n", record, parsingResult.errorLocation - record - 1 + 1, parsingResult.code); | ||
99 | sprintf(comment, "%c%*s %s (%s)\n", SDBT_BAD_FORMAT_CHARACTER, | ||
100 | parsingResult.errorLocation - record - 1 + 1, "^", | ||
101 | "BAD_ERROR_DESCRIPTION_HEADER", | ||
102 | parsingErrorStrings[parsingResult.code]); | ||
103 | } | ||
104 | // printf("here5\n"); | ||
105 | |||
106 | rc = sdb_add_record(db, comment) && sdb_add_record(db, tempstr); | ||
107 | } | ||
108 | } | ||
109 | else | ||
110 | { | ||
111 | rc = sdb_add_record(db, record); | ||
112 | } | ||
113 | |||
114 | return rc; | ||
115 | } | ||
116 | |||
117 | void sdbtMarkError(db_descriptor * db, char * record, | ||
118 | parsingResult_t * parsingResult) | ||
119 | { | ||
120 | //mark record as 'bad format' | ||
121 | record[0] = SDBT_PENDING_COMMENT_FORMAT_CHARACTER; | ||
122 | record[1] = '0' + parsingResult->code; | ||
123 | record[2] = ','; | ||
124 | sprintf(record + 3, "%3d", (int) (parsingResult->errorLocation - record)); | ||
125 | record[6] = ','; //must overwrite the '\0' from the above sprintf | ||
126 | sdb_modify_last_accessed_record(db, record); | ||
127 | } | ||
128 | |||
diff --git a/server/Source/SimpleDBTxt.h b/server/Source/SimpleDBTxt.h new file mode 100755 index 0000000..e971fc4 --- /dev/null +++ b/server/Source/SimpleDBTxt.h | |||
@@ -0,0 +1,27 @@ | |||
1 | #ifndef SIMPLE_DB_TXT_H | ||
2 | #define SIMPLE_DB_TXT_H | ||
3 | |||
4 | #ifdef __cplusplus | ||
5 | extern "C" { | ||
6 | #endif | ||
7 | |||
8 | #include "SimpleDB.h" | ||
9 | |||
10 | #define SDBT_BAD_FORMAT_CHARACTER '@' | ||
11 | #define SDBT_PENDING_COMMENT_FORMAT_CHARACTER '?' | ||
12 | #define SDBT_DELETED_LINE_CHARACTER ';' | ||
13 | |||
14 | uint32_t sdbtGetRecordSize(void * record); | ||
15 | bool sdbtCheckDeleted(void * record); | ||
16 | bool sdbtCheckIgnored(void * record); | ||
17 | void sdbtMarkDeleted(void * record); | ||
18 | uint32_t sdbtGetRecordCount(db_descriptor * db); | ||
19 | bool sdbtErrorComment(db_descriptor * db, char * record); | ||
20 | void sdbtMarkError(db_descriptor * db, char * record, parsingResult_t * parsingResult); | ||
21 | |||
22 | #ifdef __cplusplus | ||
23 | } | ||
24 | #endif | ||
25 | |||
26 | #endif /* SIMPLE_DB_TXT_H */ | ||
27 | |||
diff --git a/server/Source/hal_defs.h b/server/Source/hal_defs.h index 6718f3f..6718f3f 100644..100755 --- a/server/Source/hal_defs.h +++ b/server/Source/hal_defs.h | |||
diff --git a/server/Source/hal_types.h b/server/Source/hal_types.h index 4a0c273..4a0c273 100644..100755 --- a/server/Source/hal_types.h +++ b/server/Source/hal_types.h | |||
diff --git a/server/Source/interface_devicelist.c b/server/Source/interface_devicelist.c index 3aebc4a..79a4b75 100644..100755 --- a/server/Source/interface_devicelist.c +++ b/server/Source/interface_devicelist.c | |||
@@ -47,595 +47,250 @@ | |||
47 | #include "interface_srpcserver.h" | 47 | #include "interface_srpcserver.h" |
48 | #include "interface_devicelist.h" | 48 | #include "interface_devicelist.h" |
49 | 49 | ||
50 | #include "hal_types.h" | ||
51 | #include "SimpleDBTxt.h" | ||
52 | |||
50 | /********************************************************************* | 53 | /********************************************************************* |
51 | * DEFINES | 54 | * LOCAL VARIABLES |
52 | */ | 55 | */ |
53 | 56 | ||
57 | static db_descriptor * db; | ||
54 | 58 | ||
55 | /********************************************************************* | 59 | /********************************************************************* |
56 | * TYPEDEFS | 60 | * TYPEDEFS |
57 | */ | 61 | */ |
58 | |||
59 | typedef struct | ||
60 | { | ||
61 | void *next; | ||
62 | epInfo_t epInfo; | ||
63 | }deviceRecord_t; | ||
64 | |||
65 | deviceRecord_t *deviceRecordHead = NULL; | ||
66 | 62 | ||
67 | /********************************************************************* | 63 | /********************************************************************* |
68 | * LOCAL FUNCTION PROTOTYPES | 64 | * LOCAL FUNCTION PROTOTYPES |
69 | */ | 65 | */ |
70 | static deviceRecord_t* createDeviceRec( epInfo_t epInfo ); | ||
71 | static deviceRecord_t* findDeviceRec( uint16_t nwkAddr, uint8_t endpoint); | ||
72 | static char* findDeviceInFileString( uint16_t nwkAddr, uint8_t endpoint, char* fileBuf, uint32_t bufLen ); | ||
73 | static void reomveDeviceFromFile( uint16_t nwkAddr, uint8_t endpoint ); | ||
74 | static void writeDeviceToFile( deviceRecord_t *device ); | ||
75 | static void readDeviceListFromFile( void ); | ||
76 | 66 | ||
77 | /********************************************************************* | 67 | typedef struct { |
78 | * FUNCTIONS | 68 | uint16 nwkAddr; |
79 | *********************************************************************/ | 69 | uint8 endpoint; |
70 | } dev_key_NA_EP; | ||
80 | 71 | ||
81 | /********************************************************************* | 72 | typedef struct { |
82 | * @fn createDeviceRec | 73 | uint8 ieeeAddr[8]; |
83 | * | 74 | uint8 endpoint; |
84 | * @brief create a device and add a rec fto the list. | 75 | } dev_key_IEEE_EP; |
85 | * | 76 | |
86 | * @param table | 77 | typedef uint8 dev_key_IEEE[8]; |
87 | * @param rmTimer | 78 | |
88 | * | 79 | static char * devListComposeRecord(epInfo_t *epInfo, char * record) |
89 | * @return none | ||
90 | */ | ||
91 | static deviceRecord_t* createDeviceRec( epInfo_t epInfo ) | ||
92 | { | 80 | { |
93 | deviceRecord_t *srchRec; | 81 | uint8 hasName=0; |
94 | 82 | ||
95 | //printf("createDeviceRec++\n"); | 83 | if(epInfo->deviceName != NULL) |
96 | 84 | { | |
97 | //does it already exist | 85 | hasName = 1; |
98 | if( findDeviceRec( epInfo.nwkAddr, epInfo.endpoint ) ) | 86 | } |
99 | { | 87 | |
100 | //printf("createDeviceRec: Device already exists\n"); | 88 | sprintf(record, |
101 | return NULL; | 89 | " %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X , 0x%04X , 0x%02X , 0x%04X , 0x%04X , 0x%02X , 0x%02X , \"%s\"\n", //leave a space at the beginning to mark this record as deleted if needed later, or as bad format (can happen if edited manually). Another space to write the reason of bad format. |
102 | } | 90 | epInfo->IEEEAddr[7], epInfo->IEEEAddr[6], epInfo->IEEEAddr[5], |
103 | 91 | epInfo->IEEEAddr[4], epInfo->IEEEAddr[3], epInfo->IEEEAddr[2], | |
104 | deviceRecord_t *newDevice = malloc( sizeof( deviceRecord_t ) ); | 92 | epInfo->IEEEAddr[1], epInfo->IEEEAddr[0], epInfo->nwkAddr, |
105 | 93 | epInfo->endpoint, epInfo->profileID, epInfo->deviceID, epInfo->version, | |
106 | //Store the epInfo | 94 | epInfo->status, hasName ? epInfo->deviceName : ""); |
107 | memcpy( &(newDevice->epInfo), &epInfo, sizeof(epInfo_t)); | 95 | |
108 | 96 | return record; | |
109 | newDevice->epInfo.deviceName = NULL; | ||
110 | newDevice->epInfo.status = DEVLIST_STATE_ACTIVE; | ||
111 | |||
112 | //printf("New Device added (%x) - ADDR:%x, DEVICE:%x, PROFILE:%x, EP:%x\n", newDevice, newDevice->epInfo.nwkAddr, newDevice->epInfo.deviceID, newDevice->epInfo.profileID, newDevice->epInfo.endpoint); | ||
113 | |||
114 | newDevice->next = NULL; | ||
115 | |||
116 | if(deviceRecordHead) | ||
117 | { | ||
118 | //find the end of the list and add the record | ||
119 | srchRec = deviceRecordHead; | ||
120 | // Stop at the last record | ||
121 | while ( srchRec->next ) | ||
122 | srchRec = srchRec->next; | ||
123 | |||
124 | // Add to the list | ||
125 | srchRec->next = newDevice; | ||
126 | |||
127 | //printf("New Device added to end of list (%x)\n", srchRec->next); | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | //printf("createDeviceRec: adding new device to head of the list\n"); | ||
132 | deviceRecordHead = newDevice; | ||
133 | } | ||
134 | |||
135 | return newDevice; | ||
136 | //printf("createDeviceRec--\n"); | ||
137 | } | 97 | } |
138 | 98 | ||
139 | /********************************************************************* | 99 | void devListAddDevice(epInfo_t *epInfo) |
140 | * @fn findDeviceRec | ||
141 | * | ||
142 | * @brief find a device and in the list. | ||
143 | * | ||
144 | * @param nwkAddr | ||
145 | * @param endpoint | ||
146 | * | ||
147 | * @return deviceRecord_t for the device foundm null if not found | ||
148 | */ | ||
149 | static deviceRecord_t* findDeviceRec( uint16_t nwkAddr, uint8_t endpoint) | ||
150 | { | 100 | { |
151 | deviceRecord_t *srchRec = deviceRecordHead; | 101 | char rec[MAX_SUPPORTED_RECORD_SIZE]; |
152 | 102 | ||
153 | //printf("findDeviceRec++: nwkAddr:%x, ep:%x\n", nwkAddr, endpoint); | 103 | devListComposeRecord(epInfo, rec); |
154 | 104 | ||
155 | // find record | 105 | sdb_add_record(db, rec); |
156 | while ( (srchRec) && !((srchRec->epInfo.nwkAddr == nwkAddr) && (srchRec->epInfo.endpoint == endpoint)) ) | ||
157 | { | ||
158 | //printf("findDeviceRec++: searching nwkAddr:%x, ep:%x\n", srchRec->epInfo.nwkAddr, srchRec->epInfo.endpoint); | ||
159 | srchRec = srchRec->next; | ||
160 | } | ||
161 | |||
162 | //printf("findDeviceRec[%x]--\n", srchRec); | ||
163 | |||
164 | return srchRec; | ||
165 | } | 106 | } |
166 | 107 | ||
167 | /*************************************************************************************************** | 108 | static epInfo_t * devListParseRecord(char * record) |
168 | * @fn findDeviceInFileString - remove device from file. | ||
169 | * | ||
170 | * @brief | ||
171 | * @param | ||
172 | * | ||
173 | * @return | ||
174 | ***************************************************************************************************/ | ||
175 | static char* findDeviceInFileString( uint16_t nwkAddr, uint8_t endpoint, char* fileBuf, uint32_t bufLen ) | ||
176 | { | 109 | { |
177 | char *deviceIdx = NULL, *deviceStartIdx, *deviceEndIdx; | 110 | char * pBuf = record + 1; //+1 is to ignore the 'for deletion' mark that may just be added to this record. |
178 | uint32_t remainingBytes; | 111 | static epInfo_t epInfo; |
179 | 112 | static char deviceName[MAX_SUPPORTED_DEVICE_NAME_LENGTH + 1]; | |
180 | //printf("findDeviceInFile++\n"); | 113 | parsingResult_t parsingResult = |
181 | 114 | { SDB_TXT_PARSER_RESULT_OK, 0 }; | |
182 | deviceStartIdx = fileBuf; | 115 | |
183 | remainingBytes = bufLen; | 116 | if (record == NULL) |
184 | //set to a non NULL value | 117 | { |
185 | deviceEndIdx = fileBuf; | 118 | return NULL; |
186 | 119 | } | |
187 | while( ((fileBuf - deviceStartIdx) < bufLen) && (deviceEndIdx != 0) ) | 120 | |
188 | { | 121 | sdb_txt_parser_get_hex_field(&pBuf, epInfo.IEEEAddr, 8, &parsingResult); |
189 | //is this device the correct device | 122 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.nwkAddr, 2, FALSE, |
190 | if( *((uint16_t*)deviceStartIdx) == nwkAddr ) | 123 | &parsingResult); |
191 | { | 124 | sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.endpoint, 1, FALSE, |
192 | //device found | 125 | &parsingResult); |
193 | deviceIdx = deviceStartIdx; | 126 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.profileID, 2, |
194 | break; | 127 | FALSE, &parsingResult); |
195 | } | 128 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.deviceID, 2, |
196 | 129 | FALSE, &parsingResult); | |
197 | //find end of current device by finding the delimiter | 130 | sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.version, 1, FALSE, |
198 | deviceEndIdx = strchr(deviceStartIdx, ';'); | 131 | &parsingResult); |
199 | if( deviceEndIdx > (fileBuf + bufLen) ) | 132 | sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.status, 1, FALSE, |
200 | { | 133 | &parsingResult); |
201 | //past end of file string | 134 | sdb_txt_parser_get_quoted_string(&pBuf, deviceName, |
202 | //printf("findDeviceInFile++\n"); | 135 | MAX_SUPPORTED_DEVICE_NAME_LENGTH, &parsingResult); |
203 | deviceEndIdx = NULL; | 136 | |
204 | } | 137 | if ((parsingResult.code != SDB_TXT_PARSER_RESULT_OK) |
205 | 138 | && (parsingResult.code != SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)) | |
206 | if( deviceEndIdx ) | 139 | { |
207 | { | 140 | sdbtMarkError(db, record, &parsingResult); |
208 | remainingBytes = bufLen - (fileBuf - deviceEndIdx); | 141 | return NULL; |
209 | deviceStartIdx = &(deviceEndIdx[1]); | 142 | } |
210 | } | 143 | |
211 | } | 144 | if (strlen(deviceName) > 0) |
212 | 145 | { | |
213 | //printf("findDeviceInFile-- [%x]\n", (uint32_t) deviceIdx); | 146 | epInfo.deviceName = deviceName; |
214 | 147 | ||
215 | return deviceIdx; | 148 | } |
149 | else | ||
150 | { | ||
151 | epInfo.deviceName = NULL; | ||
152 | } | ||
153 | |||
154 | return &epInfo; | ||
216 | } | 155 | } |
217 | 156 | ||
218 | /*************************************************************************************************** | 157 | static int devListCheckKeyIeeeEp(char * record, dev_key_IEEE_EP * key) |
219 | * @fn reomveDeviceFromFile - remove device from file. | ||
220 | * | ||
221 | * @brief | ||
222 | * @param | ||
223 | * | ||
224 | * @return | ||
225 | ***************************************************************************************************/ | ||
226 | static void reomveDeviceFromFile( uint16_t nwkAddr, uint8_t endpoint ) | ||
227 | { | 158 | { |
228 | FILE *fpDevFile; | 159 | epInfo_t * epInfo; |
229 | uint32_t fileSize; | 160 | int result = SDB_CHECK_KEY_NOT_EQUAL; |
230 | char *fileBuf, *deviceStr, *devStrEnd; | 161 | |
231 | 162 | epInfo = devListParseRecord(record); | |
232 | //printf("reomveDeviceFromFile++\n"); | 163 | if (epInfo == NULL) |
233 | 164 | { | |
234 | fpDevFile = fopen("devicelistfile.dat", "w+b"); | 165 | return SDB_CHECK_KEY_ERROR; |
235 | 166 | } | |
236 | if(fpDevFile) | 167 | |
237 | { | 168 | if ((memcmp(epInfo->IEEEAddr, key->ieeeAddr, Z_EXTADDR_LEN) == 0) |
238 | //read the file into a buffer | 169 | && (epInfo->endpoint == key->endpoint)) |
239 | fseek(fpDevFile, 0, SEEK_END); | 170 | { |
240 | fileSize = ftell(fpDevFile); | 171 | result = SDB_CHECK_KEY_EQUAL; |
241 | rewind(fpDevFile); | 172 | } |
242 | fileBuf = (char*) calloc(sizeof(char), fileSize); | 173 | |
243 | fread(fileBuf, 1, fileSize, fpDevFile); | 174 | return result; |
244 | |||
245 | //printf("reomveDeviceFromFile: number of bytes in file = %d\n", fileSize); | ||
246 | //printf("reomveDeviceFromFile: Searching for device string\n"); | ||
247 | //find the device | ||
248 | deviceStr = findDeviceInFileString( nwkAddr, endpoint, fileBuf, fileSize ); | ||
249 | |||
250 | if( deviceStr ) | ||
251 | { | ||
252 | //printf("reomveDeviceFromFile: device string:%x\n", (uint32_t) deviceStr); | ||
253 | //find device delimiter | ||
254 | devStrEnd = strchr(deviceStr, ';'); | ||
255 | |||
256 | if( devStrEnd ) | ||
257 | { | ||
258 | //copy start of file to bigenning of device | ||
259 | fwrite((const void *) fileBuf, fileBuf-deviceStr, 1, fpDevFile); | ||
260 | //copy end of device to end of file | ||
261 | fwrite((const void *) devStrEnd, fileSize - (fileBuf - devStrEnd), 1, fpDevFile); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | //printf("reomveDeviceFromFile: device delimiter not found\n"); | ||
266 | } | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | //printf("reomveDeviceFromFile: device not found in file\n"); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | fflush(fpDevFile); | ||
275 | fclose(fpDevFile); | ||
276 | free(fileBuf); | ||
277 | } | 175 | } |
278 | 176 | ||
279 | /*************************************************************************************************** | 177 | static int devListCheckKeyIeee(char * record, uint8_t key[Z_EXTADDR_LEN]) |
280 | * @fn writeDeviceToFile - store device list. | ||
281 | * | ||
282 | * @brief | ||
283 | * @param | ||
284 | * | ||
285 | * @return | ||
286 | ***************************************************************************************************/ | ||
287 | static void writeDeviceToFile( deviceRecord_t *device ) | ||
288 | { | 178 | { |
289 | FILE *fpDevFile; | 179 | epInfo_t * epInfo; |
290 | 180 | int result = SDB_CHECK_KEY_NOT_EQUAL; | |
291 | //printf("writeDeviceToFile++\n"); | 181 | |
292 | 182 | epInfo = devListParseRecord(record); | |
293 | fpDevFile = fopen("devicelistfile.dat", "a+b"); | 183 | if (epInfo == NULL) |
294 | 184 | { | |
295 | if(fpDevFile) | 185 | return SDB_CHECK_KEY_ERROR; |
296 | { | 186 | } |
297 | //printf("writeDeviceToFile: opened file\n"); | 187 | //printf("Comparing 0x%08X%08X to 0x%08X%08X\n", *(uint32_t *)((epInfo->IEEEAddr)+4), *(uint32_t *)((epInfo->IEEEAddr)+0), *(uint32_t *)(key+4), *(uint32_t *)(key+0)); |
298 | 188 | if (memcmp(epInfo->IEEEAddr, key, Z_EXTADDR_LEN) == 0) | |
299 | //printf("writeDeviceToFile: Store epInfo[%d - %d - %d - %d]\n", sizeof(epInfo_t), sizeof (char*), sizeof (uint8_t), ((sizeof(epInfo_t)) - (sizeof (char*) + sizeof (uint8_t)))); | 189 | { |
300 | //Store epInfo - device name pointer and status | 190 | result = SDB_CHECK_KEY_EQUAL; |
301 | fwrite((const void *) &(device->epInfo), (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), 1, fpDevFile); | 191 | } |
302 | 192 | ||
303 | //Store deviceName len | 193 | return result; |
304 | if(device->epInfo.deviceName) | 194 | } |
305 | { | 195 | |
306 | uint8_t i; | 196 | static int devListCheckKeyNaEp(char * record, dev_key_NA_EP * key) |
307 | //printf("writeDeviceToFile: Store deviceName\n"); | 197 | { |
308 | 198 | epInfo_t * epInfo; | |
309 | //first char of dev name is str length | 199 | int result = SDB_CHECK_KEY_NOT_EQUAL; |
310 | for(i = 0; i < (device->epInfo.deviceName[0] + 1) ; i++) | 200 | |
311 | { | 201 | epInfo = devListParseRecord(record); |
312 | fwrite((const void *) (&(device->epInfo.deviceName[i])), 1, 1, fpDevFile); | 202 | if (epInfo == NULL) |
313 | } | 203 | { |
314 | } | 204 | return SDB_CHECK_KEY_ERROR; |
315 | else | 205 | } |
316 | { | 206 | |
317 | //just store the len of 0 | 207 | if ((epInfo->nwkAddr == key->nwkAddr) && (( key->endpoint == 0xFF) || (epInfo->endpoint == key->endpoint)) ) |
318 | uint8_t tmp = 0; | 208 | { |
319 | fwrite(&tmp, 1, 1, fpDevFile); | 209 | result = SDB_CHECK_KEY_EQUAL; |
320 | } | 210 | } |
321 | 211 | ||
322 | //printf("writeDeviceToFile: Store status\n"); | 212 | return result; |
323 | //Store status | 213 | } |
324 | fwrite((const void *) &(device->epInfo.status), 1, 1, fpDevFile); | 214 | |
325 | //write delimter | 215 | epInfo_t * devListRemoveDeviceByNaEp(uint16 nwkAddr, uint8 endpoint) |
326 | fwrite(";", 1, 1, fpDevFile); | ||
327 | |||
328 | fflush(fpDevFile); | ||
329 | fclose(fpDevFile); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | /*************************************************************************************************** | ||
334 | * @fn readDeviceListFromFile - restore the device list. | ||
335 | * | ||
336 | * @brief | ||
337 | * | ||
338 | * @return | ||
339 | ***************************************************************************************************/ | ||
340 | static void readDeviceListFromFile( void ) | ||
341 | { | 216 | { |
342 | FILE *fpDevFile; | 217 | dev_key_NA_EP key = |
343 | deviceRecord_t *device; | 218 | { nwkAddr, endpoint }; |
344 | epInfo_t epInfo; | 219 | |
345 | char chTmp; | 220 | return devListParseRecord( |
346 | 221 | sdb_delete_record(db, &key, (check_key_f) devListCheckKeyNaEp)); | |
347 | //printf("readDeviceListFromFile++\n"); | 222 | |
348 | fpDevFile = fopen("devicelistfile.dat", "a+b"); | ||
349 | |||
350 | if(fpDevFile) | ||
351 | { | ||
352 | //printf("readDeviceListFromFile: file opened\n"); | ||
353 | //read epInfo_t - device name pointer and status | ||
354 | while(fread(&(epInfo), (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), 1, fpDevFile)) | ||
355 | { | ||
356 | //printf("readDeviceListFromFile: epInfo[%d] read for device %x\n", (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), epInfo.nwkAddr); | ||
357 | |||
358 | device = createDeviceRec(epInfo); | ||
359 | |||
360 | if(device) | ||
361 | { | ||
362 | uint8_t strLen; | ||
363 | char *strName; | ||
364 | fread(&(strLen), 1, 1, fpDevFile); | ||
365 | //printf("readDeviceListFromFile: strLen %d\n", strLen); | ||
366 | |||
367 | if(strLen > 0) | ||
368 | { | ||
369 | strName = malloc(strLen + 1); | ||
370 | if(strName) | ||
371 | { | ||
372 | strName[0] = strLen; | ||
373 | fread(&(strName[1]), 1, strLen, fpDevFile); | ||
374 | } | ||
375 | device->epInfo.deviceName = strName; | ||
376 | } | ||
377 | |||
378 | fread(&(device->epInfo.status), 1, 1, fpDevFile); | ||
379 | //printf("readDeviceListFromFile: device->epInfo.status %x\n", device->epInfo.status); | ||
380 | |||
381 | //read ';' delimeter | ||
382 | fread(&chTmp, 1, 1, fpDevFile); | ||
383 | |||
384 | if(chTmp != ';') | ||
385 | { | ||
386 | //printf("readDeviceListFromFile: Error, device delimter not found\n"); | ||
387 | return; | ||
388 | } | ||
389 | } | ||
390 | } | ||
391 | |||
392 | fflush(fpDevFile); | ||
393 | fclose(fpDevFile); | ||
394 | } | ||
395 | |||
396 | //printf("readDeviceListFromFile--\n"); | ||
397 | } | 223 | } |
398 | 224 | ||
399 | /********************************************************************* | 225 | epInfo_t * devListRemoveDeviceByIeee(uint8_t ieeeAddr[8]) |
400 | * @fn devListAddDevice | 226 | { |
401 | * | 227 | return devListParseRecord( |
402 | * @brief create a device and add a rec to the list. | 228 | sdb_delete_record(db, ieeeAddr, (check_key_f) devListCheckKeyIeee)); |
403 | * | ||
404 | * @param epInfo | ||
405 | * | ||
406 | * @return none | ||
407 | */ | ||
408 | void devListAddDevice( epInfo_t *epInfo) | ||
409 | { | ||
410 | //printf("devListAddDevice++(%x:%x)\n", epInfo->nwkAddr, epInfo->endpoint); | ||
411 | |||
412 | deviceRecord_t *device = createDeviceRec(*epInfo); | ||
413 | if(device) | ||
414 | { | ||
415 | writeDeviceToFile(device); | ||
416 | } | ||
417 | |||
418 | //printf("\n\n\ndevListAddDevice: list=\n"); | ||
419 | //find the end of the list and add the record | ||
420 | deviceRecord_t *srchRec = deviceRecordHead; | ||
421 | //printf("%x", srchRec); | ||
422 | |||
423 | while ( srchRec->next ) | ||
424 | { | ||
425 | srchRec = srchRec->next; | ||
426 | //printf("%x\n", srchRec); | ||
427 | } | ||
428 | //printf("\n\n\n"); | ||
429 | |||
430 | //printf("devListAddDevice--\n"); | ||
431 | } | 229 | } |
432 | 230 | ||
433 | /********************************************************************* | 231 | epInfo_t * devListGetDeviceByIeeeEp(uint8_t ieeeAddr[8], uint8_t endpoint) |
434 | * @fn devListRemoveDevice | ||
435 | * | ||
436 | * @brief remove a device rec from the list. | ||
437 | * | ||
438 | * @param nwkAddr - nwkAddr of device to be removed | ||
439 | * @param endpoint - endpoint of device to be removed | ||
440 | * | ||
441 | * @return none | ||
442 | */ | ||
443 | void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint ) | ||
444 | { | 232 | { |
445 | deviceRecord_t *srchRec, *prevRec=NULL; | 233 | char * rec; |
446 | 234 | dev_key_IEEE_EP key; | |
447 | // find record and prev device record | 235 | |
448 | srchRec = deviceRecordHead; | 236 | memcpy(key.ieeeAddr, ieeeAddr, 8); |
449 | 237 | key.endpoint = endpoint; | |
450 | // find record | 238 | rec = SDB_GET_UNIQUE_RECORD(db, &key, (check_key_f)devListCheckKeyIeeeEp); |
451 | while ( (srchRec) && !((srchRec->epInfo.nwkAddr == nwkAddr) && (srchRec->epInfo.endpoint == endpoint)) ) | 239 | if (rec == NULL) |
452 | { | 240 | { |
453 | prevRec = srchRec; | 241 | return NULL; |
454 | srchRec = srchRec->next; | 242 | } |
455 | } | 243 | |
456 | 244 | return devListParseRecord(rec); | |
457 | if (srchRec == NULL) | ||
458 | { | ||
459 | //printf("deleteDeviceRec: record not found\n"); | ||
460 | return; | ||
461 | } | ||
462 | else | ||
463 | { | ||
464 | // delete the rec from the list | ||
465 | if ( prevRec == NULL ) | ||
466 | { | ||
467 | //at head of the list | ||
468 | //remove record from list | ||
469 | deviceRecordHead = srchRec->next; | ||
470 | } | ||
471 | else | ||
472 | { | ||
473 | //remove record from list | ||
474 | prevRec->next = srchRec->next; | ||
475 | } | ||
476 | |||
477 | free(srchRec); | ||
478 | } | ||
479 | } | 245 | } |
480 | 246 | ||
481 | /********************************************************************* | 247 | epInfo_t * devListGetDeviceByNaEp(uint16_t nwkAddr, uint8_t endpoint) |
482 | * @fn devListRestorDevices | ||
483 | * | ||
484 | * @brief create a device list from file. | ||
485 | * | ||
486 | * @param none | ||
487 | * | ||
488 | * @return none | ||
489 | */ | ||
490 | void devListRestorDevices( void ) | ||
491 | { | 248 | { |
492 | //printf("devListRestorDevices++\n"); | 249 | char * rec; |
493 | if( deviceRecordHead == NULL) | 250 | dev_key_NA_EP key; |
494 | { | 251 | |
495 | readDeviceListFromFile(); | 252 | key.nwkAddr = nwkAddr; |
496 | } | 253 | key.endpoint = endpoint; |
497 | //else do what, should we delete the list and recreate from the file? | 254 | rec = SDB_GET_UNIQUE_RECORD(db, &key, (check_key_f)devListCheckKeyNaEp); |
255 | if (rec == NULL) | ||
256 | { | ||
257 | return NULL; | ||
258 | } | ||
259 | |||
260 | return devListParseRecord(rec); | ||
498 | } | 261 | } |
499 | 262 | ||
500 | /********************************************************************* | 263 | uint32_t devListNumDevices(void) |
501 | * @fn devListChangeDeviceName | ||
502 | * | ||
503 | * @brief change the name of a device. | ||
504 | * | ||
505 | * @return | ||
506 | */ | ||
507 | void devListChangeDeviceName( uint16_t devNwkAddr, uint8_t devEndpoint, char *deviceNameStr) | ||
508 | { | 264 | { |
509 | //printf("devListChangeDeviceName++\n"); | 265 | return sdbtGetRecordCount(db); |
510 | |||
511 | deviceRecord_t *device = findDeviceRec( devNwkAddr, devEndpoint ); | ||
512 | |||
513 | if(device) | ||
514 | { | ||
515 | if(device->epInfo.deviceName) | ||
516 | { | ||
517 | free(device->epInfo.deviceName); | ||
518 | } | ||
519 | |||
520 | //printf("devListChangeDeviceName: removing device from file\n"); | ||
521 | reomveDeviceFromFile(devNwkAddr, devEndpoint); | ||
522 | |||
523 | //printf("devListChangeDeviceName: Changing device name\n"); | ||
524 | //fisrt byte of deviceNameStr is the size of the string | ||
525 | device->epInfo.deviceName = malloc(deviceNameStr[0]); | ||
526 | strncpy(device->epInfo.deviceName, &(deviceNameStr[0]), (deviceNameStr[0] + 1) ); | ||
527 | |||
528 | //printf("devListChangeDeviceName: writing device to file\n"); | ||
529 | writeDeviceToFile(device); | ||
530 | } | ||
531 | else | ||
532 | { | ||
533 | //printf("devListChangeDeviceName: Device not found"); | ||
534 | } | ||
535 | |||
536 | //printf("devListChangeDeviceName--\n"); | ||
537 | |||
538 | return; | ||
539 | } | 266 | } |
540 | 267 | ||
541 | /********************************************************************* | 268 | epInfo_t * devListGetNextDev(uint32_t *context) |
542 | * @fn devListNumDevices | 269 | { |
543 | * | 270 | char * rec; |
544 | * @brief get the number of devices in the list. | 271 | epInfo_t *epInfo; |
545 | * | 272 | |
546 | * @param none | 273 | do |
547 | * | 274 | { |
548 | * @return none | 275 | rec = SDB_GET_NEXT_RECORD(db,context); |
549 | */ | 276 | |
550 | uint32_t devListNumDevices( void ) | 277 | if (rec == NULL) |
551 | { | 278 | { |
552 | uint32_t recordCnt=0; | 279 | return NULL; |
553 | deviceRecord_t *srchRec; | 280 | } |
554 | 281 | ||
555 | //printf("devListNumDevices++\n"); | 282 | epInfo = devListParseRecord(rec); |
556 | 283 | } | |
557 | // Head of the list | 284 | while (epInfo == NULL); //in case of a bad-format record - skip it and read the next one |
558 | srchRec = deviceRecordHead; | 285 | |
559 | 286 | return epInfo; | |
560 | if(srchRec==NULL) | ||
561 | { | ||
562 | //printf("devListNumDevices: deviceRecordHead NULL\n"); | ||
563 | return -1; | ||
564 | } | ||
565 | |||
566 | // Stop when rec found or at the end | ||
567 | while ( srchRec ) | ||
568 | { | ||
569 | //printf("devListNumDevices: recordCnt=%d\n", recordCnt); | ||
570 | srchRec = srchRec->next; | ||
571 | recordCnt++; | ||
572 | } | ||
573 | |||
574 | //printf("devListNumDevices %d\n", recordCnt); | ||
575 | return (recordCnt); | ||
576 | } | 287 | } |
577 | 288 | ||
578 | /********************************************************************* | 289 | void devListInitDatabase(char * dbFilename) |
579 | * @fn devListGetNextDev | 290 | { |
580 | * | 291 | db = sdb_init_db(dbFilename, sdbtGetRecordSize, sdbtCheckDeleted, |
581 | * @brief Return the next device in the list. | 292 | sdbtCheckIgnored, sdbtMarkDeleted, |
582 | * | 293 | (consolidation_processing_f) sdbtErrorComment, SDB_TYPE_TEXT, 0); |
583 | * @param nwkAddr - if 0xFFFF it will return head of the list | 294 | sdb_consolidate_db(&db); |
584 | * | ||
585 | * @return epInfo, return next epInfo from nwkAddr and ep supplied or | ||
586 | * NULL if at end of the list | ||
587 | */ | ||
588 | epInfo_t* devListGetNextDev( uint16_t nwkAddr, uint8_t endpoint ) | ||
589 | { | ||
590 | epInfo_t* epInfo = NULL; | ||
591 | deviceRecord_t *srchRec; | ||
592 | |||
593 | //printf("devListGetNextDev++: nwkAddr=%x, endpoint=%x\n", nwkAddr, endpoint); | ||
594 | |||
595 | // Head of the list | ||
596 | srchRec = deviceRecordHead; | ||
597 | |||
598 | if(nwkAddr != 0xFFFF) | ||
599 | { | ||
600 | //Find the record for nwkAddr | ||
601 | srchRec = findDeviceRec(nwkAddr, endpoint); | ||
602 | //get the next record (may be NULL if at end of list) | ||
603 | srchRec = srchRec->next; | ||
604 | |||
605 | //printf("devListGetNextDev: found device %x\n", srchRec); | ||
606 | |||
607 | //Store the epInfo | ||
608 | if(srchRec) | ||
609 | { | ||
610 | //printf("devListGetNextDev: returning next device %x\n", srchRec); | ||
611 | epInfo = &(srchRec->epInfo); | ||
612 | } | ||
613 | } | ||
614 | else | ||
615 | { | ||
616 | //printf("\n\n\ndevListGetNextDev: list= [%x]\n", deviceRecordHead); | ||
617 | //find the end of the list and add the record | ||
618 | deviceRecord_t *srchRec1 = deviceRecordHead; | ||
619 | //printf("%x", srchRec1); | ||
620 | if(srchRec1) | ||
621 | { | ||
622 | while ( srchRec1->next ) | ||
623 | { | ||
624 | srchRec1 = srchRec1->next; | ||
625 | //printf("%x\n", srchRec1); | ||
626 | } | ||
627 | } | ||
628 | //printf("\n\n\n"); | ||
629 | |||
630 | //printf("devListGetNextDev: returning head of list\n"); | ||
631 | //return fisrt record | ||
632 | if(deviceRecordHead) | ||
633 | { | ||
634 | epInfo = &(deviceRecordHead->epInfo); | ||
635 | } | ||
636 | } | ||
637 | |||
638 | //printf("devListGetNextDev[%x]--\n", epInfo); | ||
639 | |||
640 | return (epInfo); | ||
641 | } | 295 | } |
296 | |||
diff --git a/server/Source/interface_devicelist.h b/server/Source/interface_devicelist.h index 3d7fe87..4ceb092 100644..100755 --- a/server/Source/interface_devicelist.h +++ b/server/Source/interface_devicelist.h | |||
@@ -40,30 +40,37 @@ | |||
40 | #define INTERFACE_DEVICELIST_H | 40 | #define INTERFACE_DEVICELIST_H |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" | 43 | extern "C" { |
44 | { | ||
45 | #endif | 44 | #endif |
46 | 45 | ||
47 | |||
48 | /********************************************************************* | 46 | /********************************************************************* |
49 | * INCLUDES | 47 | * INCLUDES |
50 | */ | 48 | */ |
51 | #include <stdint.h> | 49 | #include <stdint.h> |
52 | #include "zllSocCmd.h" | 50 | #include "zbSocCmd.h" |
51 | #include "hal_types.h" | ||
53 | 52 | ||
54 | //device states | 53 | //device states |
55 | #define DEVLIST_STATE_NOT_ACTIVE 0 | 54 | #define DEVLIST_STATE_NOT_ACTIVE 0 |
56 | #define DEVLIST_STATE_ACTIVE 1 | 55 | #define DEVLIST_STATE_ACTIVE 1 |
57 | 56 | ||
57 | #define MAX_SUPPORTED_DEVICE_NAME_LENGTH 32 | ||
58 | |||
59 | typedef struct | ||
60 | { | ||
61 | void *next; | ||
62 | epInfo_t epInfo; | ||
63 | }deviceRecord_t; | ||
64 | |||
58 | /* | 65 | /* |
59 | * devListAddDevice - create a device and add a rec to the list. | 66 | * devListAddDevice - create a device and add a rec to the list. |
60 | */ | 67 | */ |
61 | void devListAddDevice( epInfo_t *epInfo); | 68 | void devListAddDevice( epInfo_t *epInfo); |
62 | 69 | ||
63 | /* | 70 | /* |
64 | * devListRemoveDevice - remove a device rec from the list. | 71 | * devListRemoveDeviceByNaEp - remove a device rec from the list. |
65 | */ | 72 | */ |
66 | void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint ); | 73 | epInfo_t * devListRemoveDeviceByNaEp( uint16_t nwkAddr, uint8_t endpoint ); |
67 | 74 | ||
68 | /* | 75 | /* |
69 | * devListNumDevices - get the number of devices in the list. | 76 | * devListNumDevices - get the number of devices in the list. |
@@ -71,19 +78,17 @@ void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint ); | |||
71 | uint32_t devListNumDevices( void ); | 78 | uint32_t devListNumDevices( void ); |
72 | 79 | ||
73 | /* | 80 | /* |
74 | * devListGetNextDev - Return the next device in the list. | 81 | * devListInitDatabase - restore device list from file. |
75 | */ | 82 | */ |
76 | epInfo_t* devListGetNextDev( uint16_t nwkAddr, uint8_t endpoint ); | 83 | void devListInitDatabase( char * dbFilename ); |
77 | 84 | ||
78 | /* | 85 | epInfo_t * devListGetNextDev(uint32 *context); |
79 | * devListChangeDeviceName - Return the next device in the listchange device name. | ||
80 | */ | ||
81 | void devListChangeDeviceName( uint16_t devNwkAddr, uint8_t devEndpoint, char *deviceNameStr); | ||
82 | 86 | ||
83 | /* | 87 | epInfo_t * devListGetDeviceByIeeeEp( uint8_t ieeeAddr[8], uint8_t endpoint ); |
84 | * devListRestorDevices - restore device list from file. | 88 | |
85 | */ | 89 | epInfo_t * devListGetDeviceByNaEp( uint16_t nwkAddr, uint8_t endpoint ); |
86 | void devListRestorDevices( void ); | 90 | |
91 | epInfo_t * devListRemoveDeviceByIeee( uint8_t ieeeAddr[8] ); | ||
87 | 92 | ||
88 | #ifdef __cplusplus | 93 | #ifdef __cplusplus |
89 | } | 94 | } |
diff --git a/server/Source/interface_grouplist.c b/server/Source/interface_grouplist.c index 304056f..553551a 100644..100755 --- a/server/Source/interface_grouplist.c +++ b/server/Source/interface_grouplist.c | |||
@@ -45,516 +45,273 @@ | |||
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | 46 | ||
47 | #include "interface_grouplist.h" | 47 | #include "interface_grouplist.h" |
48 | #include "hal_types.h" | ||
49 | #include "SimpleDBTxt.h" | ||
50 | |||
51 | static db_descriptor * db; | ||
48 | 52 | ||
49 | /********************************************************************* | 53 | /********************************************************************* |
50 | * TYPEDEFS | 54 | * TYPEDEFS |
51 | */ | 55 | */ |
52 | typedef struct | 56 | |
57 | void groupListInitDatabase(char * dbFilename) | ||
53 | { | 58 | { |
54 | void *next; | 59 | db = sdb_init_db(dbFilename, sdbtGetRecordSize, sdbtCheckDeleted, |
55 | uint16_t groupMemberNwkAddr; | 60 | sdbtCheckIgnored, sdbtMarkDeleted, |
56 | }groupMembersRecord_t; | 61 | (consolidation_processing_f) sdbtErrorComment, SDB_TYPE_TEXT, 0); |
57 | 62 | sdb_consolidate_db(&db); | |
58 | typedef struct | 63 | } |
64 | |||
65 | static char * groupListComposeRecord(groupRecord_t *group, char * record) | ||
59 | { | 66 | { |
60 | uint16_t groupId; | 67 | groupMembersRecord_t *groupMembers; |
61 | char *groupNameStr; | ||
62 | groupMembersRecord_t *groupMembers; | ||
63 | void *next; | ||
64 | }groupRecord_t; | ||
65 | |||
66 | groupRecord_t *groupRecordHead = NULL; | ||
67 | 68 | ||
68 | /********************************************************************* | 69 | sprintf(record, " 0x%04X , \"%s\"", //leave a space at the beginning to mark this record as deleted if needed later, or as bad format (can happen if edited manually). Another space to write the reason of bad format. |
69 | * LOCAL FUNCTION PROTOTYPES | 70 | group->id, group->name ? group->name : ""); |
70 | */ | ||
71 | static groupRecord_t* createGroupRec( char *groupNameStr, uint16_t groupId, uint8_t storeToFile ); | ||
72 | static groupRecord_t* findGroupRec(char *groupNameStr ); | ||
73 | static uint16_t getFreeGroupId(void); | ||
74 | static int addGroupMemberToGroup( char *groupNameStr, uint16_t nwkAddr ); | ||
75 | static void writeGroupListToFile( groupRecord_t *device ); | ||
76 | static void writeGroupMemberToFile( char *groupNameStr, uint16_t nwkAddr ); | ||
77 | static void readGroupListFromFile( void ); | ||
78 | 71 | ||
79 | /********************************************************************* | 72 | groupMembers = group->members; |
80 | * FUNCTIONS | ||
81 | *********************************************************************/ | ||
82 | 73 | ||
83 | /********************************************************************* | 74 | while (groupMembers != NULL) |
84 | * @fn createGroupRec | 75 | { |
85 | * | 76 | sprintf(record + strlen(record), " , 0x%04X , 0x%02X", |
86 | * @brief create a group and rec to the list. | 77 | groupMembers->nwkAddr, groupMembers->endpoint); |
87 | * | 78 | groupMembers = groupMembers->next; |
88 | * @return none | 79 | } |
89 | */ | 80 | |
90 | static groupRecord_t* createGroupRec( char *groupNameStr, uint16_t groupId, uint8_t storeToFile ) | 81 | sprintf(record + strlen(record), "\n"); |
91 | { | 82 | |
92 | //printf("createGroupRec++\n"); | 83 | return record; |
93 | |||
94 | //does it already exist | ||
95 | if( findGroupRec( groupNameStr ) ) | ||
96 | { | ||
97 | //printf("createGroupRec: Device already exists\n"); | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | groupRecord_t *newGroup = malloc( sizeof( groupRecord_t ) ); | ||
102 | |||
103 | newGroup->groupNameStr = malloc(groupNameStr[0]+1); | ||
104 | memcpy( newGroup->groupNameStr, groupNameStr, groupNameStr[0]+1); | ||
105 | |||
106 | //set groupId | ||
107 | newGroup->groupId = groupId; | ||
108 | //NULL the pointers | ||
109 | newGroup->groupMembers = NULL; | ||
110 | newGroup->next = NULL; | ||
111 | |||
112 | //store the record | ||
113 | if(groupRecordHead) | ||
114 | { | ||
115 | groupRecord_t *srchRec; | ||
116 | |||
117 | //find the end of the list and add the record | ||
118 | srchRec = groupRecordHead; | ||
119 | // Stop at the last record | ||
120 | while ( srchRec->next ) | ||
121 | srchRec = srchRec->next; | ||
122 | |||
123 | // Add to the list | ||
124 | srchRec->next = newGroup; | ||
125 | } | ||
126 | else | ||
127 | groupRecordHead = newGroup; | ||
128 | |||
129 | if(storeToFile) | ||
130 | { | ||
131 | writeGroupListToFile(newGroup); | ||
132 | } | ||
133 | |||
134 | //printf("createGroupRec--\n"); | ||
135 | return newGroup; | ||
136 | } | 84 | } |
137 | 85 | ||
138 | /********************************************************************* | 86 | #define MAX_SUPPORTED_GROUP_NAME_LENGTH 32 |
139 | * @fn addGroupMemberToGroup | 87 | #define MAX_SUPPORTED_GROUP_MEMBERS 20 |
140 | * | 88 | |
141 | * @brief add a device to an existing groupRecordHead. | 89 | static groupRecord_t * groupListParseRecord(char * record) |
142 | * | ||
143 | * @return none | ||
144 | */ | ||
145 | static int addGroupMemberToGroup( char *groupNameStr, uint16_t nwkAddr ) | ||
146 | { | 90 | { |
147 | groupRecord_t* group; | 91 | char * pBuf = record + 1; //+1 is to ignore the 'for deletion' mark that may just be added to this record. |
148 | 92 | static groupRecord_t group; | |
149 | group = findGroupRec( groupNameStr ); | 93 | static char groupName[MAX_SUPPORTED_GROUP_NAME_LENGTH + 1]; |
150 | 94 | static groupMembersRecord_t member[MAX_SUPPORTED_GROUP_MEMBERS]; | |
151 | if(group != NULL) | 95 | groupMembersRecord_t ** nextMemberPtr; |
152 | { | 96 | parsingResult_t parsingResult = |
153 | groupMembersRecord_t *srchGroupMember = group->groupMembers; | 97 | { SDB_TXT_PARSER_RESULT_OK, 0 }; |
154 | 98 | int i; | |
155 | //find the end of the list and check device not already in the list | 99 | |
156 | while ( srchGroupMember ) | 100 | if (record == NULL) |
157 | { | 101 | { |
158 | if(srchGroupMember->groupMemberNwkAddr == nwkAddr) | 102 | return NULL; |
159 | { | 103 | } |
160 | //device already in group | 104 | |
161 | return 0; | 105 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &group.id, 2, FALSE, |
162 | } | 106 | &parsingResult); |
163 | 107 | sdb_txt_parser_get_quoted_string(&pBuf, groupName, | |
164 | if(srchGroupMember->next == NULL) | 108 | MAX_SUPPORTED_GROUP_NAME_LENGTH, &parsingResult); |
165 | { | 109 | nextMemberPtr = &group.members; |
166 | groupMembersRecord_t* newGroupMembersRecord; | 110 | for (i = 0; |
167 | //we at the end of the list store the groupMember | 111 | (parsingResult.code == SDB_TXT_PARSER_RESULT_OK) |
168 | newGroupMembersRecord = malloc(sizeof(groupMembersRecord_t)); | 112 | && (i < MAX_SUPPORTED_GROUP_MEMBERS); i++) |
169 | newGroupMembersRecord->groupMemberNwkAddr = nwkAddr; | 113 | { |
170 | srchGroupMember->next = newGroupMembersRecord; | 114 | *nextMemberPtr = &(member[i]); |
171 | 115 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].nwkAddr), 2, | |
172 | writeGroupMemberToFile(groupNameStr, nwkAddr); | 116 | FALSE, &parsingResult); |
173 | 117 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].endpoint), | |
174 | return 0; | 118 | 1, FALSE, &parsingResult); |
175 | } | 119 | nextMemberPtr = &(member[i].next); |
176 | else | 120 | } |
177 | { | 121 | *nextMemberPtr = NULL; |
178 | srchGroupMember = srchGroupMember->next; | 122 | |
179 | } | 123 | if ((parsingResult.code != SDB_TXT_PARSER_RESULT_OK) |
180 | } | 124 | && (parsingResult.code != SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)) |
181 | } | 125 | { |
182 | 126 | sdbtMarkError(db, record, &parsingResult); | |
183 | return 0; | 127 | return NULL; |
128 | } | ||
129 | |||
130 | if (strlen(groupName) > 0) | ||
131 | { | ||
132 | group.name = groupName; | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | group.name = NULL; | ||
137 | } | ||
138 | |||
139 | return &group; | ||
184 | } | 140 | } |
185 | 141 | ||
186 | /********************************************************************* | 142 | static int groupListCheckKeyName(char * record, char * key) |
187 | * @fn findGroupRec | ||
188 | * | ||
189 | * @brief find a record in the list. | ||
190 | * | ||
191 | * | ||
192 | * @return none | ||
193 | */ | ||
194 | static groupRecord_t* findGroupRec( char *groupNameStr ) | ||
195 | { | 143 | { |
196 | groupRecord_t *srchRec = groupRecordHead; | 144 | groupRecord_t * group; |
197 | 145 | int result = SDB_CHECK_KEY_NOT_EQUAL; | |
198 | //printf("findGroupRec++\n"); | 146 | |
199 | // find record | 147 | group = groupListParseRecord(record); |
200 | while ( (srchRec != NULL) ) | 148 | if (group == NULL) |
201 | { | 149 | { |
202 | //printf("findGroupRec: srchRec:%x\n", (uint32_t) srchRec); | 150 | return SDB_CHECK_KEY_ERROR; |
203 | //printf("findGroupRec: srchRec->groupNameStr:%x\n", (uint32_t) srchRec->groupNameStr); | 151 | } |
204 | //printf("findGroupRec: groupNameStr:%x\n", (uint32_t) groupNameStr); | 152 | |
205 | if(srchRec->groupNameStr[0] == groupNameStr[0]) | 153 | if (strcmp(group->name, key) == 0) |
206 | { | 154 | { |
207 | if(strncmp(srchRec->groupNameStr, groupNameStr, srchRec->groupNameStr[0]) == 0) | 155 | result = SDB_CHECK_KEY_EQUAL; |
208 | { | 156 | } |
209 | //we found the group | 157 | |
210 | //printf("findGroupRec: group found\n"); | 158 | return result; |
211 | break; | ||
212 | } | ||
213 | } | ||
214 | srchRec = srchRec->next; | ||
215 | } | ||
216 | |||
217 | //printf("findGroupRec--\n"); | ||
218 | |||
219 | return srchRec; | ||
220 | } | 159 | } |
221 | 160 | ||
222 | /********************************************************************* | 161 | static int groupListCheckKeyId(char * record, uint16_t * key) |
223 | * @fn getFreeGroupId | ||
224 | * | ||
225 | * @brief Finds the next (hieghst) free group ID. | ||
226 | * | ||
227 | * | ||
228 | * @return none | ||
229 | */ | ||
230 | static uint16_t getFreeGroupId( void ) | ||
231 | { | 162 | { |
232 | groupRecord_t *srchRec = groupRecordHead; | 163 | groupRecord_t * group; |
233 | uint16_t heighestGroupIdx = 0; | 164 | int result = SDB_CHECK_KEY_NOT_EQUAL; |
234 | 165 | ||
235 | //printf("findGroupRec++\n"); | 166 | group = groupListParseRecord(record); |
236 | 167 | if (group == NULL) | |
237 | // find record | 168 | { |
238 | while ( srchRec ) | 169 | return SDB_CHECK_KEY_ERROR; |
239 | { | 170 | } |
240 | if(heighestGroupIdx < srchRec->groupId) | 171 | |
241 | { | 172 | if (group->id == *key) |
242 | heighestGroupIdx = srchRec->groupId; | 173 | { |
243 | } | 174 | result = SDB_CHECK_KEY_EQUAL; |
244 | 175 | } | |
245 | srchRec = srchRec->next; | 176 | |
246 | } | 177 | return result; |
247 | |||
248 | //printf("findGroupRec--\n"); | ||
249 | |||
250 | return heighestGroupIdx + 1; | ||
251 | } | 178 | } |
252 | 179 | ||
253 | /*************************************************************************************************** | 180 | groupRecord_t * groupListGetGroupByName(char * groupName) |
254 | * @fn writeGroupListToFile - store group list. | ||
255 | * | ||
256 | * @brief | ||
257 | * @param | ||
258 | * | ||
259 | * @return | ||
260 | ***************************************************************************************************/ | ||
261 | static void writeGroupListToFile( groupRecord_t *group ) | ||
262 | { | 181 | { |
263 | FILE *fpGRoupFile; | 182 | char * rec; |
264 | 183 | ||
265 | //printf("writeGroupListToFile++\n"); | 184 | rec = SDB_GET_UNIQUE_RECORD(db, groupName, (check_key_f)groupListCheckKeyName); |
266 | 185 | if (rec == NULL) | |
267 | fpGRoupFile = fopen("grouplistfile.dat", "a+b"); | 186 | { |
268 | 187 | return NULL; | |
269 | if(fpGRoupFile) | 188 | } |
270 | { | 189 | |
271 | //printf("writeGroupListToFile: opened file\n"); | 190 | return groupListParseRecord(rec); |
272 | |||
273 | //printf("writeGroupListToFile: Store group: groupId %x, groupNameLen %x, groupName %s\n", group->groupId, (group->groupNameStr[0] + 1), group->groupNameStr); | ||
274 | //Store group | ||
275 | fwrite((const void *) &(group->groupId), 2, 1, fpGRoupFile); | ||
276 | fwrite((const void *) &(group->groupNameStr[0]), 1, 1, fpGRoupFile); | ||
277 | fwrite((const void *) &(group->groupNameStr[1]), (group->groupNameStr[0]), 1, fpGRoupFile); | ||
278 | |||
279 | //write group delimeter | ||
280 | fwrite((const void *) ";", 1, 1, fpGRoupFile); | ||
281 | |||
282 | fflush(fpGRoupFile); | ||
283 | fclose(fpGRoupFile); | ||
284 | } | ||
285 | } | 191 | } |
286 | 192 | ||
287 | /*************************************************************************************************** | 193 | uint16_t groupListGetUnusedGroupId(void) |
288 | * @fn writeGroupMemberToFile - store group list. | ||
289 | * | ||
290 | * @brief | ||
291 | * @param | ||
292 | * | ||
293 | * @return | ||
294 | ***************************************************************************************************/ | ||
295 | static void writeGroupMemberToFile( char *groupNameStr, uint16_t nwkAddr ) | ||
296 | { | ||
297 | FILE *fpGroupMemberFile; | ||
298 | uint32_t fileSize, groupStrIdx=0; | ||
299 | char *fileBuf, *groupStr, *groupStrEnd; | ||
300 | |||
301 | //printf("writeGroupMemberToFile++\n"); | ||
302 | |||
303 | fpGroupMemberFile = fopen("grouplistfile.dat", "a+b"); | ||
304 | |||
305 | if(fpGroupMemberFile) | ||
306 | { | ||
307 | //read the file into a buffer | ||
308 | fseek(fpGroupMemberFile, 0, SEEK_END); | ||
309 | fileSize = ftell(fpGroupMemberFile); | ||
310 | rewind(fpGroupMemberFile); | ||
311 | fileBuf = (char*) calloc(sizeof(char), fileSize + 20); | ||
312 | fread(fileBuf, 1, fileSize, fpGroupMemberFile); | ||
313 | |||
314 | //find the group | ||
315 | groupStr = strstr(groupNameStr, fileBuf); | ||
316 | //find group delimiter | ||
317 | groupStrEnd = strchr(groupStr, ';'); | ||
318 | //get byte offset in fileSize | ||
319 | groupStrIdx += (groupStr - groupStrEnd); | ||
320 | //back up to before the ; | ||
321 | groupStrIdx =- 1; | ||
322 | |||
323 | //set the file pointer to the | ||
324 | fseek(fpGroupMemberFile, SEEK_SET, groupStrIdx); | ||
325 | |||
326 | //printf("writeGroupMemberToFile: Store group member\n"); | ||
327 | //write member delimeter | ||
328 | fwrite((const void *) ":", 1, 1, fpGroupMemberFile); | ||
329 | //write the member nwk addr | ||
330 | fwrite((const void *) &(nwkAddr), sizeof(uint16_t), 1, fpGroupMemberFile); | ||
331 | } | ||
332 | |||
333 | fflush(fpGroupMemberFile); | ||
334 | fclose(fpGroupMemberFile); | ||
335 | free(fileBuf); | ||
336 | } | ||
337 | |||
338 | /*************************************************************************************************** | ||
339 | * @fn readGroupListFromFile - restore the group list. | ||
340 | * | ||
341 | * @brief | ||
342 | * | ||
343 | * @return | ||
344 | ***************************************************************************************************/ | ||
345 | static void readGroupListFromFile( void ) | ||
346 | { | 194 | { |
347 | FILE *fpGRoupFile; | 195 | static uint16_t lastUsedGroupId = 0; |
348 | groupRecord_t *group; | 196 | |
349 | uint32_t fileSize, groupStrIdx=0, bytesRead=0; | 197 | lastUsedGroupId++; |
350 | char *fileBuf; | 198 | |
351 | 199 | while (SDB_GET_UNIQUE_RECORD(db, &lastUsedGroupId, (check_key_f)groupListCheckKeyId) | |
352 | //printf("readGroupListFromFile++\n"); | 200 | != NULL) |
353 | fpGRoupFile = fopen("grouplistfile.dat", "a+b"); | 201 | { |
354 | 202 | lastUsedGroupId++; | |
355 | if(fpGRoupFile) | 203 | } |
356 | { | 204 | |
357 | //printf("readGroupListFromFile: file opened\n"); | 205 | return lastUsedGroupId; |
358 | |||
359 | //read the file into a buffer | ||
360 | fseek(fpGRoupFile, 0, SEEK_END); | ||
361 | fileSize = ftell(fpGRoupFile); | ||
362 | rewind(fpGRoupFile); | ||
363 | fileBuf = (char*) calloc(sizeof(char), fileSize); | ||
364 | bytesRead = fread(fileBuf, 1, fileSize, fpGRoupFile); | ||
365 | |||
366 | //printf("readGroupListFromFile: read file [%d:%d]\n", fileSize, bytesRead); | ||
367 | |||
368 | if(fileBuf) | ||
369 | { | ||
370 | //printf("readGroupListFromFile: processing filebuf. groupStrIdx: %x, (groupStrIdx + fileBuf[groupStrIdx + 2] + 2) : %x \n", groupStrIdx, (groupStrIdx + fileBuf[groupStrIdx + 2] + 2)); | ||
371 | |||
372 | //read group if there is a full group to read (uint16_t groupId + string length byte + string length (stored in byte before string) ) | ||
373 | while((groupStrIdx + 2 + fileBuf[groupStrIdx + 2] + 1) < fileSize) | ||
374 | { | ||
375 | //printf("readGroupListFromFile: group read for group ID %x, str len %d\n", (uint16_t) fileBuf[groupStrIdx], fileBuf[(groupStrIdx + 2)]); | ||
376 | |||
377 | group = createGroupRec(&(fileBuf[(groupStrIdx + 2)]), (uint16_t) fileBuf[groupStrIdx], 0); | ||
378 | |||
379 | //printf("readGroupListFromFile: group ID %x read\n", fileBuf[groupStrIdx]); | ||
380 | |||
381 | //index past GroupId + groupNameStr + groupNameStrLen + ';' | ||
382 | groupStrIdx += 2 + fileBuf[groupStrIdx + 2] + 1 + 1; | ||
383 | } | ||
384 | |||
385 | //printf("readGroupListFromFile: processed filebuf\n"); | ||
386 | |||
387 | free(fileBuf); | ||
388 | } | ||
389 | |||
390 | fflush(fpGRoupFile); | ||
391 | fclose(fpGRoupFile); | ||
392 | } | ||
393 | |||
394 | //printf("readGroupListFromFile--\n"); | ||
395 | } | 206 | } |
396 | 207 | ||
397 | /********************************************************************* | 208 | uint16_t groupListAddGroup(char *groupNameStr) |
398 | * @fn devListRestorDevices | ||
399 | * | ||
400 | * @brief create a device list from file. | ||
401 | * | ||
402 | * @param none | ||
403 | * | ||
404 | * @return none | ||
405 | */ | ||
406 | void groupListRestorGroups( void ) | ||
407 | { | 209 | { |
408 | //printf("groupListRestorGroups++\n"); | 210 | groupRecord_t *exsistingGroup; |
409 | 211 | groupRecord_t newGroup; | |
410 | if( groupRecordHead == NULL) | 212 | char rec[MAX_SUPPORTED_RECORD_SIZE]; |
411 | { | 213 | |
412 | readGroupListFromFile(); | 214 | //printf("groupListAddGroup++\n"); |
413 | } | 215 | |
414 | //else do what, should we delete the list and recreate from the file? | 216 | exsistingGroup = groupListGetGroupByName(groupNameStr); |
415 | 217 | ||
416 | //printf("groupListRestorGroups--\n"); | 218 | if (exsistingGroup != NULL) |
219 | { | ||
220 | return exsistingGroup->id; | ||
221 | } | ||
222 | |||
223 | newGroup.id = groupListGetUnusedGroupId(); | ||
224 | newGroup.name = groupNameStr; | ||
225 | newGroup.members = NULL; | ||
226 | |||
227 | groupListComposeRecord(&newGroup, rec); | ||
228 | |||
229 | sdb_add_record(db, rec); | ||
230 | |||
231 | //printf("groupListAddGroup--\n"); | ||
232 | |||
233 | return newGroup.id; | ||
417 | } | 234 | } |
418 | 235 | ||
419 | /********************************************************************* | 236 | groupRecord_t * groupListRemoveGroupByName(char * groupName) |
420 | * @fn devListDescoverDevice | 237 | { |
421 | * | 238 | return groupListParseRecord( |
422 | * @brief Descovers a GRoup. | 239 | sdb_delete_record(db, groupName, (check_key_f) groupListCheckKeyName)); |
423 | * | ||
424 | * @param table | ||
425 | * @param rmTimer | ||
426 | * | ||
427 | * @return none | ||
428 | */ | ||
429 | void groupListDescoverGroup( char *groupNameStr ) | ||
430 | { | ||
431 | //printf("groupListDescoverDevice++\n"); | ||
432 | |||
433 | //Need to BCast a get group membership | ||
434 | |||
435 | //printf("groupListDescoverDevice--\n"); | ||
436 | } | 240 | } |
437 | 241 | ||
438 | /********************************************************************* | 242 | uint16_t groupListAddDeviceToGroup(char *groupNameStr, uint16_t nwkAddr, |
439 | * @fn groupListGetNextGroup | 243 | uint8_t endpoint) |
440 | * | 244 | { |
441 | * @brief Return the next group in the list. | 245 | groupRecord_t *group; |
442 | * | 246 | groupRecord_t newGroup; |
443 | * @param groupNameStr - if NULL it will return head of the list | 247 | char rec[MAX_SUPPORTED_RECORD_SIZE]; |
444 | * | 248 | groupMembersRecord_t ** nextMemberPtr; |
445 | * @return groupListItem_t, return next group from groupNameStr supplied or | 249 | groupMembersRecord_t newMember; |
446 | * NULL if at end of the list | 250 | bool memberExists = FALSE; |
447 | */ | 251 | uint16_t groupId; |
448 | groupListItem_t* groupListGetNextGroup( char *groupNameStr ) | 252 | |
449 | { | 253 | //printf("groupListAddGroup++\n"); |
450 | groupRecord_t *srchRec = groupRecordHead; | 254 | |
451 | groupListItem_t *groupItem = NULL; | 255 | group = groupListGetGroupByName(groupNameStr); |
452 | 256 | ||
453 | //printf("groupListGetNextGroup++\n"); | 257 | if (group == NULL) |
454 | 258 | { | |
455 | if(groupNameStr != NULL) | 259 | group = &newGroup; |
456 | { | 260 | group->id = groupListGetUnusedGroupId(); |
457 | //printf("groupListGetNextGroup: groupNameStr != NULL\n"); | 261 | group->name = groupNameStr; |
458 | 262 | group->members = NULL; | |
459 | //Find the record for group | 263 | } |
460 | srchRec = findGroupRec( groupNameStr ); | 264 | |
461 | //printf("groupListGetNextGroup: findGroupRec %x \n", (uint32_t) srchRec); | 265 | groupId = group->id; |
462 | //get the next record (may be NULL if at end of list) | 266 | |
463 | srchRec = srchRec->next; | 267 | nextMemberPtr = &(group->members); |
464 | //printf("groupListGetNextGroup: findGroupRec next %x \n", (uint32_t) srchRec); | 268 | while ((*nextMemberPtr != NULL) && (!memberExists)) |
465 | //Store the groupItem | 269 | { |
466 | if(srchRec) | 270 | if (((*nextMemberPtr)->nwkAddr == nwkAddr) |
467 | { | 271 | && ((*nextMemberPtr)->endpoint == endpoint)) |
468 | //printf("groupListGetNextGroup: storing groupItem\n"); | 272 | { |
469 | groupItem = malloc(sizeof(groupListItem_t)); | 273 | memberExists = TRUE; |
470 | if(groupItem) | 274 | } |
471 | { | 275 | else |
472 | groupItem->groupId = srchRec->groupId; | 276 | { |
473 | groupItem->groupNameStr = malloc(srchRec->groupNameStr[0] + 1); | 277 | nextMemberPtr = &((*nextMemberPtr)->next); |
474 | if(groupItem->groupNameStr) | 278 | } |
475 | { | 279 | } |
476 | strncpy(groupItem->groupNameStr, srchRec->groupNameStr, (srchRec->groupNameStr[0] + 1)); | 280 | |
477 | } | 281 | if (!memberExists) |
478 | } | 282 | { |
479 | } | 283 | *nextMemberPtr = &newMember; |
480 | 284 | newMember.nwkAddr = nwkAddr; | |
481 | } | 285 | newMember.endpoint = endpoint; |
482 | else if(groupRecordHead) | 286 | newMember.next = NULL; |
483 | { | 287 | groupListComposeRecord(group, rec); |
484 | //else return the head of revord | 288 | groupListRemoveGroupByName(groupNameStr); |
485 | groupItem = malloc(sizeof(groupListItem_t)); | 289 | sdb_add_record(db, rec); |
486 | if(groupItem) | 290 | } |
487 | { | 291 | |
488 | groupItem->groupId = groupRecordHead->groupId; | 292 | //printf("groupListAddGroup--\n"); |
489 | groupItem->groupNameStr = malloc(groupRecordHead->groupNameStr[0] + 1); | 293 | |
490 | if(groupItem->groupNameStr) | 294 | return groupId; |
491 | { | ||
492 | strncpy(groupItem->groupNameStr, groupRecordHead->groupNameStr, (groupRecordHead->groupNameStr[0] + 1)); | ||
493 | } | ||
494 | } | ||
495 | } | ||
496 | |||
497 | //printf("groupListGetNextGroup--\n"); | ||
498 | |||
499 | return (groupItem); | ||
500 | } | 295 | } |
501 | 296 | ||
502 | /********************************************************************* | 297 | groupRecord_t * groupListGetNextGroup(uint32_t *context) |
503 | * @fn groupListAddGroup | ||
504 | * | ||
505 | * @brief add a device to the group list. | ||
506 | * | ||
507 | * @return none | ||
508 | */ | ||
509 | uint16_t groupListAddGroup( char *groupNameStr ) | ||
510 | { | 298 | { |
511 | groupRecord_t *group; | 299 | char * rec; |
512 | uint16_t groupId; | 300 | groupRecord_t *group; |
513 | 301 | ||
514 | //printf("groupListAddGroup++\n"); | 302 | do |
515 | 303 | { | |
516 | group = findGroupRec( groupNameStr ); | 304 | rec = SDB_GET_NEXT_RECORD(db,context); |
517 | 305 | ||
518 | if( group == NULL) | 306 | if (rec == NULL) |
519 | { | 307 | { |
520 | groupId = getFreeGroupId(); | 308 | return NULL; |
521 | createGroupRec( groupNameStr, groupId, 1); | 309 | } |
522 | } | 310 | |
523 | else | 311 | group = groupListParseRecord(rec); |
524 | { | 312 | } |
525 | groupId = group->groupId; | 313 | while (group == NULL); //in case of a bad-format record - skip it and read the next one |
526 | } | 314 | |
527 | 315 | return group; | |
528 | //printf("groupListAddGroup--\n"); | ||
529 | |||
530 | return groupId; | ||
531 | } | 316 | } |
532 | 317 | ||
533 | /********************************************************************* | ||
534 | * @fn groupListAddDeviceToGroup | ||
535 | * | ||
536 | * @brief create a group and add a rec to the list. | ||
537 | * | ||
538 | * @param table | ||
539 | * @param rmTimer | ||
540 | * | ||
541 | * @return none | ||
542 | */ | ||
543 | void groupListAddDeviceToGroup( char *groupNameStr, uint16_t nwkAddr ) | ||
544 | { | ||
545 | groupRecord_t* group; | ||
546 | |||
547 | //printf("groupListAddDeviceToGroup++\n"); | ||
548 | |||
549 | group = findGroupRec( groupNameStr ); | ||
550 | |||
551 | if( group == NULL) | ||
552 | { | ||
553 | createGroupRec( groupNameStr, getFreeGroupId(), 1 ); | ||
554 | } | ||
555 | |||
556 | if(group) | ||
557 | { | ||
558 | addGroupMemberToGroup(groupNameStr, nwkAddr); | ||
559 | } | ||
560 | } \ No newline at end of file | ||
diff --git a/server/Source/interface_grouplist.h b/server/Source/interface_grouplist.h index f8e1b1a..9ca20c5 100644..100755 --- a/server/Source/interface_grouplist.h +++ b/server/Source/interface_grouplist.h | |||
@@ -40,8 +40,7 @@ | |||
40 | #define INTERFACE_GROUPLIST_H | 40 | #define INTERFACE_GROUPLIST_H |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" | 43 | extern "C" { |
44 | { | ||
45 | #endif | 44 | #endif |
46 | 45 | ||
47 | /********************************************************************* | 46 | /********************************************************************* |
@@ -49,31 +48,39 @@ extern "C" | |||
49 | */ | 48 | */ |
50 | #include <stdint.h> | 49 | #include <stdint.h> |
51 | 50 | ||
52 | typedef struct | 51 | typedef struct groupMembersRecord_s { |
53 | { | 52 | struct groupMembersRecord_s * next; |
54 | uint16_t groupId; | 53 | uint16_t nwkAddr; |
55 | char *groupNameStr; | 54 | uint8_t endpoint; |
56 | }groupListItem_t; | 55 | } groupMembersRecord_t; |
56 | |||
57 | typedef struct { | ||
58 | char *name; | ||
59 | groupMembersRecord_t *members; | ||
60 | void *next; | ||
61 | uint16_t id; | ||
62 | } groupRecord_t; | ||
57 | 63 | ||
58 | /* | 64 | /* |
59 | * groupListAddGroup - create a group and add a rec fto the list. | 65 | * groupListAddGroup - create a group and add a rec fto the list. |
60 | */ | 66 | */ |
61 | uint16_t groupListAddGroup( char *groupNameStr ); | 67 | uint16_t groupListAddGroup(char *groupNameStr); |
62 | 68 | ||
63 | /* | 69 | /* |
64 | * groupListAddDeviceToGroup - Add a device to a group. | 70 | * groupListAddDeviceToGroup - Add a device to a group. |
65 | */ | 71 | */ |
66 | void groupListAddDeviceToGroup( char *groupNameStr, uint16_t nwkAddr ); | 72 | uint16_t groupListAddDeviceToGroup(char *groupNameStr, uint16_t nwkAddr, |
73 | uint8_t endpoint); | ||
67 | 74 | ||
68 | /* | 75 | /* |
69 | * groupListGetNextGroup - Return the next group in the list.. | 76 | * groupListGetNextGroup - Return the next group in the list.. |
70 | */ | 77 | */ |
71 | groupListItem_t* groupListGetNextGroup( char *groupNameStr ); | 78 | groupRecord_t * groupListGetNextGroup(uint32_t *context); |
72 | 79 | ||
73 | /* | 80 | /* |
74 | * groupListRestorGroups - Restore Group List from file. | 81 | * groupListInitDatabase - Restore Group List from file. |
75 | */ | 82 | */ |
76 | void groupListRestorGroups( void ); | 83 | void groupListInitDatabase(char * dbFilename); |
77 | 84 | ||
78 | #ifdef __cplusplus | 85 | #ifdef __cplusplus |
79 | } | 86 | } |
diff --git a/server/Source/interface_scenelist.c b/server/Source/interface_scenelist.c index 2da7ab3..3df05e0 100644..100755 --- a/server/Source/interface_scenelist.c +++ b/server/Source/interface_scenelist.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /************************************************************************************************** | 1 | /************************************************************************************************** |
2 | * Filename: interface_devicelist.c | 2 | * Filename: interface_scenelist.c |
3 | * Description: Socket Remote Procedure Call Interface - sample device application. | 3 | * Description: Socket Remote Procedure Call Interface - sample device application. |
4 | * | 4 | * |
5 | * | 5 | * |
@@ -45,362 +45,188 @@ | |||
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | 46 | ||
47 | #include "interface_scenelist.h" | 47 | #include "interface_scenelist.h" |
48 | #include "hal_types.h" | ||
49 | #include "SimpleDBTxt.h" | ||
50 | |||
51 | static db_descriptor * db; | ||
48 | 52 | ||
49 | /********************************************************************* | 53 | /********************************************************************* |
50 | * TYPEDEFS | 54 | * TYPEDEFS |
51 | */ | 55 | */ |
52 | 56 | typedef struct { | |
53 | typedef struct | 57 | char* name; |
54 | { | 58 | uint16 groupId; |
55 | uint8_t sceneId; | 59 | } scene_key_NA_GID; |
56 | uint16_t groupId; | ||
57 | char *sceneNameStr; | ||
58 | void *next; | ||
59 | }sceneRecord_t; | ||
60 | |||
61 | sceneRecord_t *sceneRecordHead = NULL; | ||
62 | 60 | ||
63 | /********************************************************************* | 61 | /********************************************************************* |
64 | * LOCAL FUNCTION PROTOTYPES | 62 | * LOCAL FUNCTION PROTOTYPES |
65 | */ | 63 | */ |
66 | static sceneRecord_t* createSceneRec( char *sceneNameStr, uint8_t sceneId, uint16_t groupId, uint8_t storeToFile ); | 64 | static char * sceneListComposeRecord(sceneRecord_t *group, char * record); |
67 | static sceneRecord_t* findSceneRec( char *sceneNameStr, uint16_t groupId ); | 65 | static sceneRecord_t * sceneListParseRecord(char * record); |
68 | static uint16_t getFreeSceneId(void); | 66 | static int sceneListCheckKeyId(char * record, uint8_t * key); |
69 | static void writeSceneListToFile( sceneRecord_t *device ); | 67 | static int sceneListCheckKeyNameGid(char * record, scene_key_NA_GID * key); |
70 | static void readSceneListFromFile( void ); | 68 | static sceneRecord_t * sceneListGetSceneByNameGid(char *sceneNameStr, uint16_t groupId); |
69 | static uint8_t sceneListGetUnusedSceneId(void); | ||
71 | 70 | ||
72 | /********************************************************************* | 71 | /********************************************************************* |
73 | * FUNCTIONS | 72 | * FUNCTIONS |
74 | *********************************************************************/ | 73 | *********************************************************************/ |
75 | 74 | ||
76 | /********************************************************************* | 75 | void sceneListInitDatabase(char * dbFilename) |
77 | * @fn createSceneRec | 76 | { |
78 | * | 77 | db = sdb_init_db(dbFilename, sdbtGetRecordSize, sdbtCheckDeleted, |
79 | * @brief create a scene and rec to the list. | 78 | sdbtCheckIgnored, sdbtMarkDeleted, |
80 | * | 79 | (consolidation_processing_f) sdbtErrorComment, SDB_TYPE_TEXT, 0); |
81 | * @return none | 80 | sdb_consolidate_db(&db); |
82 | */ | 81 | } |
83 | static sceneRecord_t* createSceneRec( char *sceneNameStr, uint8_t sceneId, uint16_t groupId, uint8_t storeToFile ) | ||
84 | { | ||
85 | //printf("createSceneRec++: sceneId %x, groupId %x\n", sceneId, groupId); | ||
86 | |||
87 | //does it already exist | ||
88 | if( findSceneRec( sceneNameStr, groupId ) ) | ||
89 | { | ||
90 | //printf("createSceneRec: Device already exists\n"); | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | sceneRecord_t *newScene = malloc( sizeof( sceneRecord_t ) ); | ||
95 | |||
96 | newScene->sceneNameStr = malloc(sceneNameStr[0]+1); | ||
97 | memcpy( newScene->sceneNameStr, sceneNameStr, sceneNameStr[0]+1); | ||
98 | |||
99 | //set sceneId | ||
100 | newScene->sceneId = sceneId; | ||
101 | //set groupId | ||
102 | newScene->groupId = groupId; | ||
103 | //NULL the pointers | ||
104 | newScene->next = NULL; | ||
105 | |||
106 | //store the record | ||
107 | if(sceneRecordHead) | ||
108 | { | ||
109 | sceneRecord_t *srchRec; | ||
110 | 82 | ||
111 | //find the end of the list and add the record | 83 | static char * sceneListComposeRecord(sceneRecord_t *scene, char * record) |
112 | srchRec = sceneRecordHead; | 84 | { |
113 | // Stop at the last record | 85 | sceneMembersRecord_t *sceneMembers; |
114 | while ( srchRec->next ) | ||
115 | srchRec = srchRec->next; | ||
116 | 86 | ||
117 | // Add to the list | 87 | sprintf(record, " 0x%04X , 0x%02X , \"%s\"", //leave a space at the beginning to mark this record as deleted if needed later, or as bad format (can happen if edited manually). Another space to write the reason of bad format. |
118 | srchRec->next = newScene; | 88 | scene->groupId, scene->sceneId, scene->name ? scene->name : ""); |
119 | } | 89 | |
120 | else | 90 | sceneMembers = scene->members; |
121 | sceneRecordHead = newScene; | 91 | |
122 | 92 | while (sceneMembers != NULL) | |
123 | if(storeToFile) | 93 | { |
124 | { | 94 | sprintf(record + strlen(record), " , 0x%04X , 0x%02X", |
125 | writeSceneListToFile(newScene); | 95 | sceneMembers->nwkAddr, sceneMembers->endpoint); |
126 | } | 96 | sceneMembers = sceneMembers->next; |
127 | 97 | } | |
128 | //printf("createSceneRec--\n"); | 98 | |
129 | return newScene; | 99 | sprintf(record + strlen(record), "\n"); |
100 | |||
101 | return record; | ||
130 | } | 102 | } |
131 | 103 | ||
132 | /********************************************************************* | 104 | #define MAX_SUPPORTED_SCENE_NAME_LENGTH 32 |
133 | * @fn findSceneRec | 105 | #define MAX_SUPPORTED_SCENE_MEMBERS 20 |
134 | * | 106 | |
135 | * @brief find a record in the list that matches scene and group. | 107 | static sceneRecord_t * sceneListParseRecord(char * record) |
136 | * | ||
137 | * | ||
138 | * @return none | ||
139 | */ | ||
140 | static sceneRecord_t* findSceneRec( char *sceneNameStr, uint16_t groupId ) | ||
141 | { | 108 | { |
142 | sceneRecord_t *srchRec = sceneRecordHead; | 109 | char * pBuf = record + 1; //+1 is to ignore the 'for deletion' mark that may just be added to this record. |
110 | static sceneRecord_t scene; | ||
111 | static char sceneName[MAX_SUPPORTED_SCENE_NAME_LENGTH + 1]; | ||
112 | static sceneMembersRecord_t member[MAX_SUPPORTED_SCENE_MEMBERS]; | ||
113 | sceneMembersRecord_t ** nextMemberPtr; | ||
114 | parsingResult_t parsingResult = | ||
115 | { SDB_TXT_PARSER_RESULT_OK, 0 }; | ||
116 | int i; | ||
143 | 117 | ||
144 | //printf("findSceneRec++\n"); | 118 | if (record == NULL) |
145 | // find record | 119 | { |
146 | while ( (srchRec != NULL) ) | 120 | return NULL; |
147 | { | 121 | } |
148 | //printf("findSceneRec: srchRec:%x\n", (uint32_t) srchRec); | 122 | |
149 | //printf("findSceneRec: srchRec->sceneNameStr:%x\n", (uint32_t) srchRec->sceneNameStr); | 123 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &scene.groupId, 2, FALSE, |
150 | //printf("findSceneRec: sceneNameStr:%x\n", (uint32_t) sceneNameStr); | 124 | &parsingResult); |
151 | if(srchRec->sceneNameStr[0] == sceneNameStr[0]) | 125 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &scene.sceneId, 1, FALSE, |
152 | { | 126 | &parsingResult); |
153 | if( (strncmp(srchRec->sceneNameStr, sceneNameStr, srchRec->sceneNameStr[0]) == 0) && | 127 | sdb_txt_parser_get_quoted_string(&pBuf, sceneName, |
154 | srchRec->groupId == groupId) | 128 | MAX_SUPPORTED_SCENE_NAME_LENGTH, &parsingResult); |
155 | { | 129 | nextMemberPtr = &scene.members; |
156 | //we found the scene | 130 | for (i = 0; |
157 | //printf("findSceneRec: scene found\n"); | 131 | (parsingResult.code == SDB_TXT_PARSER_RESULT_OK) |
158 | break; | 132 | && (i < MAX_SUPPORTED_SCENE_MEMBERS); i++) |
159 | } | 133 | { |
160 | } | 134 | *nextMemberPtr = &(member[i]); |
161 | srchRec = srchRec->next; | 135 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].nwkAddr), 2, |
162 | } | 136 | FALSE, &parsingResult); |
163 | 137 | sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].endpoint), | |
164 | //printf("findSceneRec--\n"); | 138 | 1, FALSE, &parsingResult); |
165 | 139 | nextMemberPtr = &(member[i].next); | |
166 | return srchRec; | 140 | } |
141 | *nextMemberPtr = NULL; | ||
142 | |||
143 | if ((parsingResult.code != SDB_TXT_PARSER_RESULT_OK) | ||
144 | && (parsingResult.code != SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)) | ||
145 | { | ||
146 | sdbtMarkError(db, record, &parsingResult); | ||
147 | return NULL; | ||
148 | } | ||
149 | |||
150 | if (strlen(sceneName) > 0) | ||
151 | { | ||
152 | scene.name = sceneName; | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | scene.name = NULL; | ||
157 | } | ||
158 | |||
159 | return &scene; | ||
167 | } | 160 | } |
168 | 161 | ||
169 | /********************************************************************* | 162 | static int sceneListCheckKeyId(char * record, uint8_t * key) |
170 | * @fn getFreeSceneId | ||
171 | * | ||
172 | * @brief Finds the next (hieghst) free scene ID. | ||
173 | * | ||
174 | * | ||
175 | * @return none | ||
176 | */ | ||
177 | static uint16_t getFreeSceneId( void ) | ||
178 | { | 163 | { |
179 | sceneRecord_t *srchRec = sceneRecordHead; | 164 | sceneRecord_t * scene; |
180 | uint16_t heighestSceneIdx = 0; | 165 | int result = SDB_CHECK_KEY_NOT_EQUAL; |
181 | 166 | ||
182 | //printf("getFreeSceneId++\n"); | 167 | scene = sceneListParseRecord(record); |
183 | 168 | if (scene == NULL) | |
184 | // find record | 169 | { |
185 | while ( srchRec ) | 170 | return SDB_CHECK_KEY_ERROR; |
186 | { | 171 | } |
187 | //printf("getFreeSceneId: srchRec->sceneId %x\n", srchRec->sceneId); | 172 | |
188 | if(heighestSceneIdx < srchRec->sceneId) | 173 | if (scene->sceneId == *key) |
189 | { | 174 | { |
190 | heighestSceneIdx = srchRec->sceneId; | 175 | result = SDB_CHECK_KEY_EQUAL; |
191 | } | 176 | } |
192 | 177 | ||
193 | srchRec = srchRec->next; | 178 | return result; |
194 | } | ||
195 | |||
196 | heighestSceneIdx++; | ||
197 | |||
198 | //printf("getFreeSceneId--: %x\n", heighestSceneIdx); | ||
199 | |||
200 | return (heighestSceneIdx); | ||
201 | } | 179 | } |
202 | 180 | ||
203 | /*************************************************************************************************** | 181 | static int sceneListCheckKeyNameGid(char * record, scene_key_NA_GID * key) |
204 | * @fn writeSceneListToFile - store scene list. | ||
205 | * | ||
206 | * @brief | ||
207 | * @param | ||
208 | * | ||
209 | * @return | ||
210 | ***************************************************************************************************/ | ||
211 | static void writeSceneListToFile( sceneRecord_t *scene ) | ||
212 | { | 182 | { |
213 | FILE *fpSceneFile; | 183 | sceneRecord_t * scene; |
214 | 184 | int result = SDB_CHECK_KEY_NOT_EQUAL; | |
215 | //printf("writeSceneListToFile++\n"); | ||
216 | |||
217 | fpSceneFile = fopen("scenelistfile.dat", "a+b"); | ||
218 | 185 | ||
219 | if(fpSceneFile) | 186 | scene = sceneListParseRecord(record); |
220 | { | 187 | if (scene == NULL) |
221 | //printf("writeSceneListToFile: opened file\n"); | 188 | { |
222 | 189 | return SDB_CHECK_KEY_ERROR; | |
223 | //printf("writeSceneListToFile: Store scene: sceneId %x, sceneNameLen %x, sceneName %s\n", scene->sceneId, (scene->sceneNameStr[0] + 1), scene->sceneNameStr); | 190 | } |
224 | //Store scene | 191 | |
225 | fwrite((const void *) &(scene->groupId), 2, 1, fpSceneFile); | 192 | if ( (strcmp(scene->name, key->name) == 0) && (scene->groupId == key->groupId) ) |
226 | fwrite((const void *) &(scene->sceneId), 1, 1, fpSceneFile); | 193 | { |
227 | fwrite((const void *) &(scene->sceneNameStr[0]), 1, 1, fpSceneFile); | 194 | result = SDB_CHECK_KEY_EQUAL; |
228 | fwrite((const void *) &(scene->sceneNameStr[1]), (scene->sceneNameStr[0]), 1, fpSceneFile); | 195 | } |
229 | 196 | ||
230 | //write scene delimeter | 197 | return result; |
231 | fwrite((const void *) ";", 1, 1, fpSceneFile); | ||
232 | |||
233 | fflush(fpSceneFile); | ||
234 | fclose(fpSceneFile); | ||
235 | } | ||
236 | } | 198 | } |
237 | 199 | ||
238 | /*************************************************************************************************** | 200 | static sceneRecord_t * sceneListGetSceneByNameGid(char *sceneNameStr, uint16_t groupId) |
239 | * @fn readSceneListFromFile - restore the scene list. | ||
240 | * | ||
241 | * @brief | ||
242 | * | ||
243 | * @return | ||
244 | ***************************************************************************************************/ | ||
245 | static void readSceneListFromFile( void ) | ||
246 | { | 201 | { |
247 | FILE *fpSceneFile; | 202 | char * rec; |
248 | sceneRecord_t *scene; | 203 | scene_key_NA_GID key; |
249 | uint32_t fileSize, sceneStrIdx=0, bytesRead=0; | 204 | |
250 | char *fileBuf; | 205 | key.groupId = groupId; |
251 | 206 | key.name = sceneNameStr; | |
252 | //printf("readSceneListFromFile++\n"); | 207 | |
253 | fpSceneFile = fopen("scenelistfile.dat", "a+b"); | 208 | rec = SDB_GET_UNIQUE_RECORD(db, &key, (check_key_f)sceneListCheckKeyNameGid); |
254 | 209 | if (rec == NULL) | |
255 | if(fpSceneFile) | 210 | { |
256 | { | 211 | return NULL; |
257 | //printf("readSceneListFromFile: file opened\n"); | 212 | } |
258 | 213 | ||
259 | //read the file into a buffer | 214 | return sceneListParseRecord(rec); |
260 | fseek(fpSceneFile, 0, SEEK_END); | ||
261 | fileSize = ftell(fpSceneFile); | ||
262 | rewind(fpSceneFile); | ||
263 | fileBuf = (char*) calloc(sizeof(char), fileSize); | ||
264 | bytesRead = fread(fileBuf, 1, fileSize, fpSceneFile); | ||
265 | |||
266 | //printf("readSceneListFromFile: read file [%d:%d]\n", fileSize, bytesRead); | ||
267 | |||
268 | if(fileBuf) | ||
269 | { | ||
270 | //printf("readSceneListFromFile: processing filebuf. sceneStrIdx: %x, (sceneStrIdx + fileBuf[sceneStrIdx + 2] + 2) : %x \n", sceneStrIdx, (sceneStrIdx + fileBuf[sceneStrIdx + 2] + 2)); | ||
271 | |||
272 | //read scene if there is a full scene to read (uint16_t groupId + uint8_t sceneId + string length byte + string length (stored in byte before string) ) | ||
273 | while((sceneStrIdx + fileBuf[sceneStrIdx + 3] + 2 + 1 + 1) < fileSize) | ||
274 | { | ||
275 | uint16_t groupId = (uint16_t) fileBuf[sceneStrIdx]; | ||
276 | uint8_t sceneId = (uint8_t) fileBuf[sceneStrIdx + 2]; | ||
277 | |||
278 | scene = createSceneRec(&(fileBuf[(sceneStrIdx + 3)]), sceneId, groupId, 0); | ||
279 | |||
280 | //printf("readSceneListFromFile: scene ID %s read\n", fileBuf[sceneStrIdx]); | ||
281 | |||
282 | //index past GroupId + SceneId + sceneNameStrLen + sceneNameStr + ';' | ||
283 | sceneStrIdx += (fileBuf[sceneStrIdx + 3] + 2 + 1 + 1) + 1; | ||
284 | } | ||
285 | |||
286 | //printf("readSceneListFromFile: processed filebuf\n"); | ||
287 | |||
288 | free(fileBuf); | ||
289 | } | ||
290 | |||
291 | fflush(fpSceneFile); | ||
292 | fclose(fpSceneFile); | ||
293 | } | ||
294 | |||
295 | //printf("readSceneListFromFile--\n"); | ||
296 | } | 215 | } |
297 | 216 | ||
298 | /********************************************************************* | 217 | static uint8_t sceneListGetUnusedSceneId(void) |
299 | * @fn devListRestorDevices | ||
300 | * | ||
301 | * @brief create a device list from file. | ||
302 | * | ||
303 | * @param none | ||
304 | * | ||
305 | * @return none | ||
306 | */ | ||
307 | void sceneListRestorScenes( void ) | ||
308 | { | 218 | { |
309 | //printf("sceneListRestorScenes++\n"); | 219 | static uint8_t lastUsedSceneId = 0; |
310 | |||
311 | if( sceneRecordHead == NULL) | ||
312 | { | ||
313 | readSceneListFromFile(); | ||
314 | } | ||
315 | //else do what, should we delete the list and recreate from the file? | ||
316 | |||
317 | //printf("sceneListRestorScenes--\n"); | ||
318 | } | ||
319 | 220 | ||
320 | /********************************************************************* | 221 | lastUsedSceneId++; |
321 | * @fn devListDescoverDevice | ||
322 | * | ||
323 | * @brief Descovers a Scene. | ||
324 | * | ||
325 | * @param table | ||
326 | * @param rmTimer | ||
327 | * | ||
328 | * @return none | ||
329 | */ | ||
330 | void sceneListDescoverScene( char *sceneNameStr ) | ||
331 | { | ||
332 | //printf("sceneListDescoverDevice++\n"); | ||
333 | |||
334 | //Need to BCast a get scene membership | ||
335 | |||
336 | //printf("sceneListDescoverDevice--\n"); | ||
337 | } | ||
338 | 222 | ||
339 | /********************************************************************* | 223 | while (SDB_GET_UNIQUE_RECORD(db, &lastUsedSceneId, (check_key_f)sceneListCheckKeyId) |
340 | * @fn sceneListGetNextScene | 224 | != NULL) |
341 | * | 225 | { |
342 | * @brief Return the next scene in the list. | 226 | lastUsedSceneId++; |
343 | * | 227 | } |
344 | * @param sceneNameStr - if NULL it will return head of the list | 228 | |
345 | * groupId - group that the scene is apart of, ignored if sceneStr is NULL. | 229 | return lastUsedSceneId; |
346 | * | ||
347 | * @return sceneListItem_t, return next scene from sceneNameStr supplied or | ||
348 | * NULL if at end of the list | ||
349 | */ | ||
350 | sceneListItem_t* sceneListGetNextScene( char *sceneNameStr, uint16_t groupId ) | ||
351 | { | ||
352 | sceneRecord_t *srchRec = sceneRecordHead; | ||
353 | sceneListItem_t *sceneItem = NULL; | ||
354 | |||
355 | //printf("sceneListGetNextScene++\n"); | ||
356 | |||
357 | if(sceneNameStr != NULL) | ||
358 | { | ||
359 | //printf("sceneListGetNextScene: sceneNameStr != NULL\n"); | ||
360 | |||
361 | //Find the record for previous scene found | ||
362 | srchRec = findSceneRec( sceneNameStr, groupId ); | ||
363 | //printf("sceneListGetNextScene: findSceneRec %x \n", (uint32_t) srchRec); | ||
364 | //get the next record (may be NULL if at end of list) | ||
365 | srchRec = srchRec->next; | ||
366 | //printf("sceneListGetNextScene: findSceneRec next %x \n", (uint32_t) srchRec); | ||
367 | //Store the sceneItem | ||
368 | if(srchRec) | ||
369 | { | ||
370 | //printf("sceneListGetNextScene: storing sceneItem, sceneId %x, groupId %x\n", srchRec->sceneId, srchRec->groupId); | ||
371 | sceneItem = malloc(sizeof(sceneListItem_t)); | ||
372 | if(sceneItem) | ||
373 | { | ||
374 | sceneItem->groupId = srchRec->groupId; | ||
375 | sceneItem->sceneId = srchRec->sceneId; | ||
376 | sceneItem->sceneNameStr = malloc(srchRec->sceneNameStr[0] + 1); | ||
377 | if(sceneItem->sceneNameStr) | ||
378 | { | ||
379 | strncpy(sceneItem->sceneNameStr, srchRec->sceneNameStr, (srchRec->sceneNameStr[0] + 1)); | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | |||
384 | } | ||
385 | else if(sceneRecordHead) | ||
386 | { | ||
387 | //else return the head of revord | ||
388 | sceneItem = malloc(sizeof(sceneListItem_t)); | ||
389 | if(sceneItem) | ||
390 | { | ||
391 | sceneItem->groupId = sceneRecordHead->groupId; | ||
392 | sceneItem->sceneId = sceneRecordHead->sceneId; | ||
393 | sceneItem->sceneNameStr = malloc(sceneRecordHead->sceneNameStr[0] + 1); | ||
394 | if(sceneItem->sceneNameStr) | ||
395 | { | ||
396 | strncpy(sceneItem->sceneNameStr, sceneRecordHead->sceneNameStr, (sceneRecordHead->sceneNameStr[0] + 1)); | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | |||
401 | //printf("sceneListGetNextScene--\n"); | ||
402 | |||
403 | return (sceneItem); | ||
404 | } | 230 | } |
405 | 231 | ||
406 | /********************************************************************* | 232 | /********************************************************************* |
@@ -412,26 +238,29 @@ sceneListItem_t* sceneListGetNextScene( char *sceneNameStr, uint16_t groupId ) | |||
412 | */ | 238 | */ |
413 | uint8_t sceneListAddScene( char *sceneNameStr, uint16_t groupId ) | 239 | uint8_t sceneListAddScene( char *sceneNameStr, uint16_t groupId ) |
414 | { | 240 | { |
415 | uint8_t sceneId = 0; | 241 | sceneRecord_t *exsistingScene; |
416 | sceneRecord_t *scene; | 242 | sceneRecord_t newScene; |
417 | 243 | char rec[MAX_SUPPORTED_RECORD_SIZE]; | |
418 | //printf("sceneListAddScene++\n"); | 244 | |
419 | 245 | exsistingScene = sceneListGetSceneByNameGid(sceneNameStr, groupId); | |
420 | scene = findSceneRec( sceneNameStr, groupId ); | 246 | |
421 | 247 | if (exsistingScene != NULL) | |
422 | if( scene == NULL) | 248 | { |
423 | { | 249 | return exsistingScene->sceneId; |
424 | sceneId = getFreeSceneId(); | 250 | } |
425 | createSceneRec( sceneNameStr, sceneId, groupId, 1); | 251 | |
426 | } | 252 | newScene.groupId = groupId; |
427 | else | 253 | newScene.sceneId = sceneListGetUnusedSceneId(); |
428 | { | 254 | newScene.name = sceneNameStr; |
429 | sceneId = scene->sceneId; | 255 | newScene.members = NULL; |
430 | } | 256 | |
431 | 257 | sceneListComposeRecord(&newScene, rec); | |
432 | //printf("sceneListAddScene--\n"); | 258 | |
433 | 259 | sdb_add_record(db, rec); | |
434 | return sceneId; | 260 | |
261 | //printf("SceneListAddScene--\n"); | ||
262 | |||
263 | return newScene.sceneId; | ||
435 | } | 264 | } |
436 | 265 | ||
437 | /********************************************************************* | 266 | /********************************************************************* |
@@ -445,10 +274,8 @@ uint8_t sceneListGetSceneId( char *sceneNameStr, uint16_t groupId ) | |||
445 | { | 274 | { |
446 | uint8_t sceneId = 0; | 275 | uint8_t sceneId = 0; |
447 | sceneRecord_t *scene; | 276 | sceneRecord_t *scene; |
448 | 277 | ||
449 | //printf("sceneListGetSceneId++\n"); | 278 | scene = sceneListGetSceneByNameGid(sceneNameStr, groupId); |
450 | |||
451 | scene = findSceneRec( sceneNameStr, groupId ); | ||
452 | 279 | ||
453 | if( scene == NULL) | 280 | if( scene == NULL) |
454 | { | 281 | { |
@@ -462,4 +289,34 @@ uint8_t sceneListGetSceneId( char *sceneNameStr, uint16_t groupId ) | |||
462 | //printf("sceneListGetSceneId--\n"); | 289 | //printf("sceneListGetSceneId--\n"); |
463 | 290 | ||
464 | return sceneId; | 291 | return sceneId; |
465 | } \ No newline at end of file | 292 | } |
293 | |||
294 | /********************************************************************* | ||
295 | * @fn sceneListGetNextScene | ||
296 | * | ||
297 | * @brief Return the next scene in the list. | ||
298 | * | ||
299 | * @param context Pointer to the current scene record | ||
300 | * | ||
301 | * @return sceneRecord_t, return next scene record in the DB | ||
302 | */ | ||
303 | sceneRecord_t* sceneListGetNextScene(uint32_t *context) | ||
304 | { | ||
305 | char * rec; | ||
306 | sceneRecord_t *scene; | ||
307 | |||
308 | do | ||
309 | { | ||
310 | rec = SDB_GET_NEXT_RECORD(db,context); | ||
311 | |||
312 | if (rec == NULL) | ||
313 | { | ||
314 | return NULL; | ||
315 | } | ||
316 | |||
317 | scene = sceneListParseRecord(rec); | ||
318 | } | ||
319 | while (scene == NULL); //in case of a bad-format record - skip it and read the next one | ||
320 | |||
321 | return scene; | ||
322 | } | ||
diff --git a/server/Source/interface_scenelist.h b/server/Source/interface_scenelist.h index d562d4d..0cb634a 100644..100755 --- a/server/Source/interface_scenelist.h +++ b/server/Source/interface_scenelist.h | |||
@@ -40,8 +40,7 @@ | |||
40 | #define INTERFACE_SCENELIST_H | 40 | #define INTERFACE_SCENELIST_H |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" | 43 | extern "C" { |
44 | { | ||
45 | #endif | 44 | #endif |
46 | 45 | ||
47 | /********************************************************************* | 46 | /********************************************************************* |
@@ -49,32 +48,39 @@ extern "C" | |||
49 | */ | 48 | */ |
50 | #include <stdint.h> | 49 | #include <stdint.h> |
51 | 50 | ||
52 | typedef struct | 51 | typedef struct sceneMembersRecord_s { |
53 | { | 52 | struct sceneMembersRecord_s * next; |
54 | uint16_t groupId; | 53 | uint16_t nwkAddr; |
55 | uint8_t sceneId; | 54 | uint8_t endpoint; |
56 | char *sceneNameStr; | 55 | } sceneMembersRecord_t; |
57 | }sceneListItem_t; | 56 | |
57 | typedef struct { | ||
58 | char *name; | ||
59 | sceneMembersRecord_t *members; | ||
60 | void *next; | ||
61 | uint8_t sceneId; | ||
62 | uint16_t groupId; | ||
63 | } sceneRecord_t; | ||
58 | 64 | ||
59 | /* | 65 | /* |
60 | * sceneListAddScene - create a scene and add a rec fto the list. | 66 | * sceneListAddScene - create a scene and add a rec fto the list. |
61 | */ | 67 | */ |
62 | uint8_t sceneListAddScene( char *sceneNameStr, uint16_t groupId ); | 68 | uint8_t sceneListAddScene(char *sceneNameStr, uint16_t groupId); |
63 | 69 | ||
64 | /* | 70 | /* |
65 | * sceneListAddScene - gets the scen id of a a scene | 71 | * sceneListAddScene - gets the scen id of a a scene |
66 | */ | 72 | */ |
67 | uint8_t sceneListGetSceneId( char *sceneNameStr, uint16_t groupId ); | 73 | uint8_t sceneListGetSceneId(char *sceneNameStr, uint16_t groupId); |
68 | 74 | ||
69 | /* | 75 | /* |
70 | * sceneListGetNextScene - Return the next scene in the list.. | 76 | * sceneListGetNextScene - Return the next scene in the list. |
71 | */ | 77 | */ |
72 | sceneListItem_t* sceneListGetNextScene( char *sceneNameStr, uint16_t groupId ); | 78 | sceneRecord_t* sceneListGetNextScene(uint32_t *context); |
73 | 79 | ||
74 | /* | 80 | /* |
75 | * sceneListRestorScenes - Restore Scene List from file. | 81 | * groupListInitDatabase - Restore Scene List from file. |
76 | */ | 82 | */ |
77 | void sceneListRestorScenes( void ); | 83 | void groupListInitDatabase(char * dbFilename); |
78 | 84 | ||
79 | #ifdef __cplusplus | 85 | #ifdef __cplusplus |
80 | } | 86 | } |
diff --git a/server/Source/interface_srpcserver.c b/server/Source/interface_srpcserver.c index 0d58c8b..e7bc1b3 100644..100755 --- a/server/Source/interface_srpcserver.c +++ b/server/Source/interface_srpcserver.c | |||
@@ -56,60 +56,72 @@ | |||
56 | 56 | ||
57 | #include "hal_defs.h" | 57 | #include "hal_defs.h" |
58 | 58 | ||
59 | #include "zllSocCmd.h" | 59 | #include "zbSocCmd.h" |
60 | 60 | ||
61 | void SRPC_RxCB( int clientFd ); | 61 | void SRPC_RxCB(int clientFd); |
62 | void SRPC_ConnectCB( int status ); | 62 | void SRPC_ConnectCB(int status); |
63 | 63 | ||
64 | static uint8_t RPCS_ZLL_setDeviceState(uint8_t *pBuf, uint32_t clientFd); | 64 | static uint8_t SRPC_setDeviceState(uint8_t *pBuf, uint32_t clientFd); |
65 | static uint8_t RPCS_ZLL_setDeviceLevel(uint8_t *pBuf, uint32_t clientFd); | 65 | static uint8_t SRPC_setDeviceLevel(uint8_t *pBuf, uint32_t clientFd); |
66 | static uint8_t RPCS_ZLL_setDeviceColor(uint8_t *pBuf, uint32_t clientFd); | 66 | static uint8_t SRPC_setDeviceColor(uint8_t *pBuf, uint32_t clientFd); |
67 | static uint8_t RPCS_ZLL_getDeviceState(uint8_t *pBuf, uint32_t clientFd); | 67 | static uint8_t SRPC_getDeviceState(uint8_t *pBuf, uint32_t clientFd); |
68 | static uint8_t RPCS_ZLL_getDeviceLevel(uint8_t *pBuf, uint32_t clientFd); | 68 | static uint8_t SRPC_getDeviceLevel(uint8_t *pBuf, uint32_t clientFd); |
69 | static uint8_t RPCS_ZLL_getDeviceHue(uint8_t *pBuf, uint32_t clientFd); | 69 | static uint8_t SRPC_getDeviceHue(uint8_t *pBuf, uint32_t clientFd); |
70 | static uint8_t RPCS_ZLL_getDeviceSat(uint8_t *pBuf, uint32_t clientFd); | 70 | static uint8_t SRPC_getDeviceSat(uint8_t *pBuf, uint32_t clientFd); |
71 | static uint8_t RSPC_ZLL_bindDevices(uint8_t *pBuf, uint32 clientFd); | 71 | static uint8_t SRPC_bindDevices(uint8_t *pBuf, uint32_t clientFd); |
72 | static uint8_t RPCS_ZLL_getGroups(uint8_t *pBuf, uint32 clientFd); | 72 | static uint8_t SRPC_getGroups(uint8_t *pBuf, uint32_t clientFd); |
73 | static uint8_t RPCS_ZLL_addGroup(uint8_t *pBuf, uint32 clientFd); | 73 | static uint8_t SRPC_addGroup(uint8_t *pBuf, uint32_t clientFd); |
74 | static uint8_t RPCS_ZLL_getScenes(uint8_t *pBuf, uint32 clientFd); | 74 | static uint8_t SRPC_getScenes(uint8_t *pBuf, uint32_t clientFd); |
75 | static uint8_t RPCS_ZLL_storeScene(uint8_t *pBuf, uint32 clientFd); | 75 | static uint8_t SRPC_storeScene(uint8_t *pBuf, uint32_t clientFd); |
76 | static uint8_t RPCS_ZLL_recallScene(uint8_t *pBuf, uint32 clientFd); | 76 | static uint8_t SRPC_recallScene(uint8_t *pBuf, uint32_t clientFd); |
77 | static uint8_t RPCS_ZLL_identifyDevice(uint8_t *pBuf, uint32_t clientFd); | 77 | static uint8_t SRPC_identifyDevice(uint8_t *pBuf, uint32_t clientFd); |
78 | static uint8_t RSPC_ZLL_close(uint8_t *pBuf, uint32_t clientFd); | 78 | static uint8_t SRPC_close(uint8_t *pBuf, uint32_t clientFd); |
79 | static uint8_t RSPC_ZLL_getDevices(uint8_t *pBuf, uint32_t clientFd); | 79 | static uint8_t SRPC_getDevices(uint8_t *pBuf, uint32_t clientFd); |
80 | static uint8_t RPSC_ZLL_notSupported(uint8_t *pBuf, uint32_t clientFd); | 80 | static uint8_t SRPC_permitJoin(uint8_t *pBuf, uint32_t clientFd); |
81 | static uint8_t SRPC_changeDeviceName(uint8_t *pBuf, uint32_t clientFd); | ||
82 | static uint8_t SRPC_notSupported(uint8_t *pBuf, uint32_t clientFd); | ||
81 | 83 | ||
82 | //RPSC ZLL Interface call back functions | 84 | //RPSC ZLL Interface call back functions |
83 | static void RPCS_ZLL_CallBack_addGroupRsp(uint16_t groupId, char *nameStr, uint32 clientFd); | 85 | static void SRPC_CallBack_addGroupRsp(uint16_t groupId, char *nameStr, |
84 | static void RPCS_ZLL_CallBack_addSceneRsp(uint16_t groupId, uint8_t sceneId, char *nameStr, uint32 clientFd); | 86 | uint32_t clientFd); |
85 | 87 | static void SRPC_CallBack_addSceneRsp(uint16_t groupId, uint8_t sceneId, | |
86 | typedef uint8_t (*rpcsProcessMsg_t)(uint8_t *pBuf, uint32_t clientFd); | 88 | char *nameStr, uint32_t clientFd); |
87 | 89 | ||
88 | rpcsProcessMsg_t rpcsProcessIncoming[] = | 90 | static uint8_t* srpcParseEpInfo(epInfoExtended_t* epInfoEx); |
89 | { | 91 | |
90 | RSPC_ZLL_close, //RPCS_CLOSE | 92 | typedef uint8_t (*srpcProcessMsg_t)(uint8_t *pBuf, uint32_t clientFd); |
91 | RSPC_ZLL_getDevices, //RPCS_GET_DEVICES | 93 | |
92 | RPCS_ZLL_setDeviceState, //RPCS_SET_DEV_STATE | 94 | srpcProcessMsg_t rpcsProcessIncoming[] = |
93 | RPCS_ZLL_setDeviceLevel, //RPCS_SET_DEV_LEVEL | 95 | { SRPC_close, //SRPC_CLOSE |
94 | RPCS_ZLL_setDeviceColor, //RPCS_SET_DEV_COLOR | 96 | SRPC_getDevices, //SRPC_GET_DEVICES |
95 | RPCS_ZLL_getDeviceState, //RPCS_GET_DEV_STATE | 97 | SRPC_setDeviceState, //SRPC_SET_DEV_STATE |
96 | RPCS_ZLL_getDeviceLevel, //RPCS_GET_DEV_LEVEL | 98 | SRPC_setDeviceLevel, //SRPC_SET_DEV_LEVEL |
97 | RPCS_ZLL_getDeviceHue, //RPCS_GET_DEV_HUE | 99 | SRPC_setDeviceColor, //SRPC_SET_DEV_COLOR |
98 | RPCS_ZLL_getDeviceSat, //RPCS_GET_DEV_HUE | 100 | SRPC_getDeviceState, //SRPC_GET_DEV_STATE |
99 | RSPC_ZLL_bindDevices, //RPCS_BIND_DEVICES | 101 | SRPC_getDeviceLevel, //SRPC_GET_DEV_LEVEL |
100 | RPSC_ZLL_notSupported, //RPCS_GET_THERM_READING | 102 | SRPC_getDeviceHue, //SRPC_GET_DEV_HUE |
101 | RPSC_ZLL_notSupported, //RPCS_GET_POWER_READING | 103 | SRPC_getDeviceSat, //SRPC_GET_DEV_HUE |
102 | RPSC_ZLL_notSupported, //RPCS_DISCOVER_DEVICES | 104 | SRPC_bindDevices, //SRPC_BIND_DEVICES |
103 | RPSC_ZLL_notSupported, //RPCS_SEND_ZCL | 105 | SRPC_notSupported, //reserved |
104 | RPCS_ZLL_getGroups, //RPCS_GET_GROUPS | 106 | SRPC_notSupported, //reserved |
105 | RPCS_ZLL_addGroup, //RPCS_ADD_GROUP | 107 | SRPC_notSupported, //reserved |
106 | RPCS_ZLL_getScenes, //RPCS_GET_SCENES | 108 | SRPC_notSupported, //reserved |
107 | RPCS_ZLL_storeScene, //RPCS_STORE_SCENE | 109 | SRPC_getGroups, //SRPC_GET_GROUPS |
108 | RPCS_ZLL_recallScene, //RPCS_RECALL_SCENE | 110 | SRPC_addGroup, //SRPC_ADD_GROUP |
109 | RPCS_ZLL_identifyDevice, //RPCS_IDENTIFY_DEVICE | 111 | SRPC_getScenes, //SRPC_GET_SCENES |
110 | RPSC_ZLL_notSupported, //RPCS_CHANGE_DEVICE_NAME | 112 | SRPC_storeScene, //SRPC_STORE_SCENE |
111 | RPSC_ZLL_notSupported, //RPCS_REMOVE_DEVICE | 113 | SRPC_recallScene, //SRPC_RECALL_SCENE |
112 | }; | 114 | SRPC_identifyDevice, //SRPC_IDENTIFY_DEVICE |
115 | SRPC_changeDeviceName, //SRPC_CHANGE_DEVICE_NAME | ||
116 | SRPC_notSupported, //SRPC_REMOVE_DEVICE | ||
117 | SRPC_notSupported, //SRPC_RESERVED_10 | ||
118 | SRPC_notSupported, //SRPC_RESERVED_11 | ||
119 | SRPC_notSupported, //SRPC_RESERVED_12 | ||
120 | SRPC_notSupported, //SRPC_RESERVED_13 | ||
121 | SRPC_notSupported, //SRPC_RESERVED_14 | ||
122 | SRPC_notSupported, //SRPC_RESERVED_15 | ||
123 | SRPC_permitJoin, //SRPC_PERMIT_JOIN | ||
124 | }; | ||
113 | 125 | ||
114 | static void srpcSend(uint8_t* srpcMsg, int fdClient); | 126 | static void srpcSend(uint8_t* srpcMsg, int fdClient); |
115 | static void srpcSendAll(uint8_t* srpcMsg); | 127 | static void srpcSendAll(uint8_t* srpcMsg); |
@@ -122,64 +134,101 @@ static void srpcSendAll(uint8_t* srpcMsg); | |||
122 | * | 134 | * |
123 | * @return pSrpcMessage | 135 | * @return pSrpcMessage |
124 | ***************************************************************************************************/ | 136 | ***************************************************************************************************/ |
125 | static uint8_t* srpcParseEpInfo(epInfo_t* epInfo) | 137 | static uint8_t* srpcParseEpInfo(epInfoExtended_t* epInfoEx) |
126 | { | 138 | { |
127 | uint8_t i; | 139 | uint8_t i; |
128 | uint8_t *pSrpcMessage, *pTmp, devNameLen = 1, pSrpcMessageLen; | 140 | uint8_t *pSrpcMessage, *pTmp, devNameLen = 0, pSrpcMessageLen; |
129 | 141 | ||
130 | //printf("srpcParseEpInfo++\n"); | 142 | //printf("srpcParseEpInfo++\n"); |
131 | 143 | ||
132 | //RpcMessage contains function ID param Data Len and param data | 144 | //RpcMessage contains function ID param Data Len and param data |
133 | if( epInfo->deviceName ) | 145 | if (epInfoEx->epInfo->deviceName) |
134 | { | 146 | { |
135 | devNameLen = epInfo->deviceName[0]; | 147 | devNameLen = strlen(epInfoEx->epInfo->deviceName); |
136 | } | 148 | } |
137 | 149 | ||
138 | //sizre of EP infor - the name char* + num bytes of device name (byte 0 being len on name str) | 150 | //sizre of EP infor - the name char* + num bytes of device name |
139 | pSrpcMessageLen = sizeof(epInfo_t) - sizeof(char*) + devNameLen; | 151 | //pSrpcMessageLen = sizeof(epInfo_t) - sizeof(char*) + devNameLen; |
140 | pSrpcMessage = malloc(pSrpcMessageLen + 2); | 152 | pSrpcMessageLen = 2 /* network address */ |
141 | 153 | + 1 /* endpoint */ | |
142 | pTmp = pSrpcMessage; | 154 | + 2 /* profile ID */ |
143 | 155 | + 2 /* device ID */ | |
144 | if( pSrpcMessage ) | 156 | + 1 /* version */ |
145 | { | 157 | + 1 /* device name length */ |
146 | //Set func ID in RPCS buffer | 158 | + devNameLen /* device name */ |
147 | *pTmp++ = RPCS_NEW_ZLL_DEVICE; | 159 | + 1 /* status */ |
148 | //param size | 160 | + 8 /* IEEE address */ |
149 | *pTmp++ = pSrpcMessageLen; | 161 | + 1 /* type */ |
150 | 162 | + 2 /* previous network address */ | |
151 | *pTmp++ = LO_UINT16(epInfo->nwkAddr); | 163 | + 1; /* flags */ |
152 | *pTmp++ = HI_UINT16(epInfo->nwkAddr); | 164 | pSrpcMessage = malloc(pSrpcMessageLen + 2); |
153 | *pTmp++ = epInfo->endpoint; | 165 | |
154 | *pTmp++ = LO_UINT16(epInfo->profileID); | 166 | pTmp = pSrpcMessage; |
155 | *pTmp++ = HI_UINT16(epInfo->profileID); | 167 | |
156 | *pTmp++ = LO_UINT16(epInfo->deviceID); | 168 | if (pSrpcMessage) |
157 | *pTmp++ = HI_UINT16(epInfo->deviceID); | 169 | { |
158 | *pTmp++ = epInfo->version; | 170 | //Set func ID in SRPC buffer |
159 | if( epInfo->deviceName ) | 171 | *pTmp++ = SRPC_NEW_DEVICE; |
160 | { | 172 | //param size |
161 | for(i = 0; i < (epInfo->deviceName[0] + 1); i++) | 173 | *pTmp++ = pSrpcMessageLen; |
162 | { | 174 | |
163 | *pTmp++ = epInfo->deviceName[i]; | 175 | *pTmp++ = LO_UINT16(epInfoEx->epInfo->nwkAddr); |
164 | } | 176 | *pTmp++ = HI_UINT16(epInfoEx->epInfo->nwkAddr); |
165 | } | 177 | *pTmp++ = epInfoEx->epInfo->endpoint; |
166 | else | 178 | *pTmp++ = LO_UINT16(epInfoEx->epInfo->profileID); |
167 | { | 179 | *pTmp++ = HI_UINT16(epInfoEx->epInfo->profileID); |
168 | *pTmp++=0; | 180 | *pTmp++ = LO_UINT16(epInfoEx->epInfo->deviceID); |
169 | } | 181 | *pTmp++ = HI_UINT16(epInfoEx->epInfo->deviceID); |
170 | *pTmp++ = epInfo->status; | 182 | *pTmp++ = epInfoEx->epInfo->version; |
171 | 183 | ||
172 | for(i = 0; i < 8; i++) | 184 | if (devNameLen > 0) |
173 | { | 185 | { |
174 | //printf("srpcParseEpInfp: IEEEAddr[%d] = %x\n", i, epInfo->IEEEAddr[i]); | 186 | *pTmp++ = devNameLen; |
175 | *pTmp++ = epInfo->IEEEAddr[i]; | 187 | for (i = 0; i < devNameLen; i++) |
176 | } | 188 | { |
177 | } | 189 | *pTmp++ = epInfoEx->epInfo->deviceName[i]; |
178 | 190 | } | |
179 | //printf("srpcParseEpInfp--\n"); | 191 | printf("srpcParseEpInfo: name:%s\n", epInfoEx->epInfo->deviceName); |
180 | 192 | } | |
181 | return pSrpcMessage; | 193 | else |
182 | } | 194 | { |
195 | *pTmp++ = 0; | ||
196 | } | ||
197 | *pTmp++ = epInfoEx->epInfo->status; | ||
198 | |||
199 | for (i = 0; i < 8; i++) | ||
200 | { | ||
201 | //printf("srpcParseEpInfp: IEEEAddr[%d] = %x\n", i, epInfo->IEEEAddr[i]); | ||
202 | *pTmp++ = epInfoEx->epInfo->IEEEAddr[i]; | ||
203 | } | ||
204 | |||
205 | *pTmp++ = epInfoEx->type; | ||
206 | *pTmp++ = LO_UINT16(epInfoEx->prevNwkAddr); | ||
207 | *pTmp++ = HI_UINT16(epInfoEx->prevNwkAddr); | ||
208 | *pTmp++ = epInfoEx->epInfo->flags; //bit 0 : start, bit 1: end | ||
209 | |||
210 | } | ||
211 | //printf("srpcParseEpInfp--\n"); | ||
212 | |||
213 | // printf("srpcParseEpInfo %0x:%0x\n", epInfo->nwkAddr, epInfo->endpoint); | ||
214 | |||
215 | printf( | ||
216 | "srpcParseEpInfo: %s device, nwkAddr=0x%04X, endpoint=0x%X, profileID=0x%04X, deviceID=0x%04X, flags=0x%02X", | ||
217 | epInfoEx->type == EP_INFO_TYPE_EXISTING ? "EXISTING" : | ||
218 | epInfoEx->type == EP_INFO_TYPE_NEW ? "NEW" : "UPDATED", | ||
219 | epInfoEx->epInfo->nwkAddr, epInfoEx->epInfo->endpoint, | ||
220 | epInfoEx->epInfo->profileID, epInfoEx->epInfo->deviceID, | ||
221 | epInfoEx->epInfo->flags); | ||
222 | |||
223 | if (epInfoEx->type == EP_INFO_TYPE_UPDATED) | ||
224 | { | ||
225 | printf(", prevNwkAddr=0x%04X\n", epInfoEx->prevNwkAddr); | ||
226 | } | ||
227 | |||
228 | printf("\n"); | ||
229 | |||
230 | return pSrpcMessage; | ||
231 | } | ||
183 | 232 | ||
184 | /*************************************************************************************************** | 233 | /*************************************************************************************************** |
185 | * @fn srpcSend | 234 | * @fn srpcSend |
@@ -190,16 +239,16 @@ static uint8_t* srpcParseEpInfo(epInfo_t* epInfo) | |||
190 | * @return Status | 239 | * @return Status |
191 | ***************************************************************************************************/ | 240 | ***************************************************************************************************/ |
192 | static void srpcSend(uint8_t* srpcMsg, int fdClient) | 241 | static void srpcSend(uint8_t* srpcMsg, int fdClient) |
193 | { | 242 | { |
194 | int rtn; | 243 | int rtn; |
195 | 244 | ||
196 | rtn = socketSeverSend(srpcMsg, (srpcMsg[SRPC_MSG_LEN] + 2), fdClient); | 245 | rtn = socketSeverSend(srpcMsg, (srpcMsg[SRPC_MSG_LEN] + 2), fdClient); |
197 | if (rtn < 0) | 246 | if (rtn < 0) |
198 | { | 247 | { |
199 | printf("ERROR writing to socket\n"); | 248 | printf("ERROR writing to socket\n"); |
200 | } | 249 | } |
201 | 250 | ||
202 | return; | 251 | return; |
203 | } | 252 | } |
204 | 253 | ||
205 | /*************************************************************************************************** | 254 | /*************************************************************************************************** |
@@ -211,21 +260,20 @@ static void srpcSend(uint8_t* srpcMsg, int fdClient) | |||
211 | * @return Status | 260 | * @return Status |
212 | ***************************************************************************************************/ | 261 | ***************************************************************************************************/ |
213 | static void srpcSendAll(uint8_t* srpcMsg) | 262 | static void srpcSendAll(uint8_t* srpcMsg) |
214 | { | 263 | { |
215 | int rtn; | 264 | int rtn; |
216 | 265 | ||
217 | rtn = socketSeverSendAllclients(srpcMsg, (srpcMsg[SRPC_MSG_LEN] + 2)); | 266 | rtn = socketSeverSendAllclients(srpcMsg, (srpcMsg[SRPC_MSG_LEN] + 2)); |
218 | if (rtn < 0) | 267 | if (rtn < 0) |
219 | { | 268 | { |
220 | printf("ERROR writing to socket\n"); | 269 | printf("ERROR writing to socket\n"); |
221 | } | 270 | } |
222 | |||
223 | return; | ||
224 | } | ||
225 | 271 | ||
272 | return; | ||
273 | } | ||
226 | 274 | ||
227 | /********************************************************************* | 275 | /********************************************************************* |
228 | * @fn RPSC_ProcessIncoming | 276 | * @fn SRPC_ProcessIncoming |
229 | * | 277 | * |
230 | * @brief This function processes incoming messages. | 278 | * @brief This function processes incoming messages. |
231 | * | 279 | * |
@@ -233,27 +281,27 @@ static void srpcSendAll(uint8_t* srpcMsg) | |||
233 | * | 281 | * |
234 | * @return afStatus_t | 282 | * @return afStatus_t |
235 | */ | 283 | */ |
236 | void RPSC_ProcessIncoming(uint8_t *pBuf, uint32_t clientFd) | 284 | void SRPC_ProcessIncoming(uint8_t *pBuf, uint32_t clientFd) |
237 | { | 285 | { |
238 | rpcsProcessMsg_t func; | 286 | srpcProcessMsg_t func; |
239 | 287 | ||
240 | //printf("RPSC_ProcessIncoming++[%x]\n", pBuf[SRPC_FUNC_ID]); | 288 | // printf("SRPC_ProcessIncoming++[%x]\n", pBuf[SRPC_FUNC_ID]); |
241 | /* look up and call processing function */ | 289 | /* look up and call processing function */ |
242 | func = rpcsProcessIncoming[(pBuf[SRPC_FUNC_ID] & ~(0x80))]; | 290 | func = rpcsProcessIncoming[(pBuf[SRPC_FUNC_ID] & ~(0x80))]; |
243 | if (func) | 291 | if (func) |
244 | { | 292 | { |
245 | (*func)(pBuf, clientFd); | 293 | (*func)(pBuf, clientFd); |
246 | } | 294 | } |
247 | else | 295 | else |
248 | { | 296 | { |
249 | //printf("Error: no processing function for CMD 0x%x\n", pBuf[SRPC_FUNC_ID]); | 297 | //printf("Error: no processing function for CMD 0x%x\n", pBuf[SRPC_FUNC_ID]); |
250 | } | 298 | } |
251 | 299 | ||
252 | //printf("RPSC_ProcessIncoming--\n"); | 300 | //printf("SRPC_ProcessIncoming--\n"); |
253 | } | 301 | } |
254 | 302 | ||
255 | /********************************************************************* | 303 | /********************************************************************* |
256 | * @fn RPCS_ZLL_addGroup | 304 | * @fn SRPC_addGroup |
257 | * | 305 | * |
258 | * @brief This function exposes an interface to add a devices to a group. | 306 | * @brief This function exposes an interface to add a devices to a group. |
259 | * | 307 | * |
@@ -261,52 +309,53 @@ void RPSC_ProcessIncoming(uint8_t *pBuf, uint32_t clientFd) | |||
261 | * | 309 | * |
262 | * @return afStatus_t | 310 | * @return afStatus_t |
263 | */ | 311 | */ |
264 | static uint8_t RPCS_ZLL_addGroup(uint8_t *pBuf, uint32 clientFd) | 312 | static uint8_t SRPC_addGroup(uint8_t *pBuf, uint32_t clientFd) |
265 | { | 313 | { |
266 | uint16_t dstAddr; | 314 | uint16_t dstAddr; |
267 | uint8_t addrMode; | 315 | uint8_t addrMode; |
268 | uint8_t endpoint; | 316 | uint8_t endpoint; |
269 | char *nameStr; | 317 | char *nameStr; |
270 | uint8_t nameLen; | 318 | uint8_t nameLen; |
271 | uint16_t groupId; | 319 | uint16_t groupId; |
272 | |||
273 | //printf("RPCS_ZLL_addGroup++\n"); | ||
274 | |||
275 | //increment past SRPC header | ||
276 | pBuf+=2; | ||
277 | |||
278 | addrMode = (afAddrMode_t)*pBuf++; | ||
279 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
280 | pBuf += Z_EXTADDR_LEN; | ||
281 | endpoint = *pBuf++; | ||
282 | // index past panId | ||
283 | pBuf += 2; | ||
284 | |||
285 | nameLen = *pBuf++; | ||
286 | nameStr = malloc(nameLen + 1); | ||
287 | nameStr[0] = nameLen; | ||
288 | int i; | ||
289 | for(i = 0; i < nameLen; i++) | ||
290 | { | ||
291 | nameStr[i+1] = *pBuf++; | ||
292 | } | ||
293 | |||
294 | //printf("RPCS_ZLL_addGroup++: %x:%x:%x name[%d] %s \n", dstAddr, addrMode, endpoint, nameLen, nameStr); | ||
295 | |||
296 | groupId = groupListAddGroup( nameStr ); | ||
297 | zllSocAddGroup(groupId, dstAddr, endpoint, addrMode); | ||
298 | 320 | ||
299 | RPCS_ZLL_CallBack_addGroupRsp(groupId, nameStr, clientFd); | 321 | //printf("SRPC_addGroup++\n"); |
300 | 322 | ||
301 | free(nameStr); | 323 | //increment past SRPC header |
302 | 324 | pBuf += 2; | |
303 | //printf("RPCS_ZLL_addGroup--\n"); | 325 | |
304 | 326 | addrMode = (afAddrMode_t) *pBuf++; | |
305 | return 0; | 327 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); |
328 | pBuf += Z_EXTADDR_LEN; | ||
329 | endpoint = *pBuf++; | ||
330 | // index past panId | ||
331 | pBuf += 2; | ||
332 | |||
333 | nameLen = *pBuf++; | ||
334 | nameStr = malloc(nameLen + 1); | ||
335 | int i; | ||
336 | for (i = 0; i < nameLen; i++) | ||
337 | { | ||
338 | nameStr[i] = *pBuf++; | ||
339 | } | ||
340 | nameStr[nameLen] = '\0'; | ||
341 | |||
342 | printf("SRPC_addGroup++: %x:%x:%x name[%d] %s \n", dstAddr, addrMode, | ||
343 | endpoint, nameLen, nameStr); | ||
344 | |||
345 | groupId = groupListAddDeviceToGroup(nameStr, dstAddr, endpoint); | ||
346 | zbSocAddGroup(groupId, dstAddr, endpoint, addrMode); | ||
347 | |||
348 | SRPC_CallBack_addGroupRsp(groupId, nameStr, clientFd); | ||
349 | |||
350 | free(nameStr); | ||
351 | |||
352 | //printf("SRPC_addGroup--\n"); | ||
353 | |||
354 | return 0; | ||
306 | } | 355 | } |
307 | 356 | ||
308 | /********************************************************************* | 357 | /********************************************************************* |
309 | * @fn uint8_t RPCS_ZLL_storeScene(uint8_t *pBuf, uint32 clientFd) | 358 | * @fn uint8_t SRPC_storeScene(uint8_t *pBuf, uint32_t clientFd) |
310 | * | 359 | * |
311 | * @brief This function exposes an interface to store a scene. | 360 | * @brief This function exposes an interface to store a scene. |
312 | * | 361 | * |
@@ -314,55 +363,55 @@ static uint8_t RPCS_ZLL_addGroup(uint8_t *pBuf, uint32 clientFd) | |||
314 | * | 363 | * |
315 | * @return afStatus_t | 364 | * @return afStatus_t |
316 | */ | 365 | */ |
317 | static uint8_t RPCS_ZLL_storeScene(uint8_t *pBuf, uint32 clientFd) | 366 | static uint8_t SRPC_storeScene(uint8_t *pBuf, uint32_t clientFd) |
318 | { | 367 | { |
319 | uint16_t dstAddr; | 368 | uint16_t dstAddr; |
320 | uint8_t addrMode; | 369 | uint8_t addrMode; |
321 | uint8_t endpoint; | 370 | uint8_t endpoint; |
322 | char *nameStr; | 371 | char *nameStr; |
323 | uint8_t nameLen; | 372 | uint8_t nameLen; |
324 | uint16_t groupId; | 373 | uint16_t groupId; |
325 | uint8_t sceneId; | 374 | uint8_t sceneId; |
326 | |||
327 | //printf("RPCS_ZLL_storeScene++\n"); | ||
328 | |||
329 | //increment past SRPC header | ||
330 | pBuf+=2; | ||
331 | |||
332 | addrMode = (afAddrMode_t)*pBuf++; | ||
333 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
334 | pBuf += Z_EXTADDR_LEN; | ||
335 | endpoint = *pBuf++; | ||
336 | // index past panId | ||
337 | pBuf += 2; | ||
338 | |||
339 | groupId = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
340 | pBuf += 2; | ||
341 | |||
342 | nameLen = *pBuf++; | ||
343 | nameStr = malloc(nameLen + 1); | ||
344 | nameStr[0] = nameLen; | ||
345 | int i; | ||
346 | for(i = 0; i < nameLen; i++) | ||
347 | { | ||
348 | nameStr[i+1] = *pBuf++; | ||
349 | } | ||
350 | |||
351 | //printf("RPCS_ZLL_storeScene++: name[%d] %s, group %d \n", nameLen, nameStr, groupId); | ||
352 | |||
353 | sceneId = sceneListAddScene( nameStr, groupId ); | ||
354 | zllSocStoreScene(groupId, sceneId, dstAddr, endpoint, addrMode); | ||
355 | RPCS_ZLL_CallBack_addSceneRsp(groupId, sceneId, nameStr, clientFd); | ||
356 | 375 | ||
357 | free(nameStr); | 376 | //printf("SRPC_storeScene++\n"); |
358 | 377 | ||
359 | //printf("RPCS_ZLL_storeScene--\n"); | 378 | //increment past SRPC header |
360 | 379 | pBuf += 2; | |
361 | return 0; | 380 | |
381 | addrMode = (afAddrMode_t) *pBuf++; | ||
382 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
383 | pBuf += Z_EXTADDR_LEN; | ||
384 | endpoint = *pBuf++; | ||
385 | // index past panId | ||
386 | pBuf += 2; | ||
387 | |||
388 | groupId = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
389 | pBuf += 2; | ||
390 | |||
391 | nameLen = *pBuf++; | ||
392 | nameStr = malloc(nameLen + 1); | ||
393 | int i; | ||
394 | for (i = 0; i < nameLen; i++) | ||
395 | { | ||
396 | nameStr[i] = *pBuf++; | ||
397 | } | ||
398 | nameStr[nameLen] = '\0'; | ||
399 | |||
400 | printf("SRPC_storeScene++: name[%d] %s, group %d \n", nameLen, nameStr, groupId); | ||
401 | |||
402 | sceneId = sceneListAddScene(nameStr, groupId); | ||
403 | zbSocStoreScene(groupId, sceneId, dstAddr, endpoint, addrMode); | ||
404 | SRPC_CallBack_addSceneRsp(groupId, sceneId, nameStr, clientFd); | ||
405 | |||
406 | free(nameStr); | ||
407 | |||
408 | //printf("SRPC_storeScene--: id:%x\n", sceneId); | ||
409 | |||
410 | return 0; | ||
362 | } | 411 | } |
363 | 412 | ||
364 | /********************************************************************* | 413 | /********************************************************************* |
365 | * @fn uint8_t RPCS_ZLL_recallScene(uint8_t *pBuf, uint32 clientFd) | 414 | * @fn uint8_t SRPC_recallScene(uint8_t *pBuf, uint32_t clientFd) |
366 | * | 415 | * |
367 | * @brief This function exposes an interface to recall a scene. | 416 | * @brief This function exposes an interface to recall a scene. |
368 | * | 417 | * |
@@ -370,54 +419,54 @@ static uint8_t RPCS_ZLL_storeScene(uint8_t *pBuf, uint32 clientFd) | |||
370 | * | 419 | * |
371 | * @return afStatus_t | 420 | * @return afStatus_t |
372 | */ | 421 | */ |
373 | static uint8_t RPCS_ZLL_recallScene(uint8_t *pBuf, uint32 clientFd) | 422 | static uint8_t SRPC_recallScene(uint8_t *pBuf, uint32_t clientFd) |
374 | { | 423 | { |
375 | uint16_t dstAddr; | 424 | uint16_t dstAddr; |
376 | uint8_t addrMode; | 425 | uint8_t addrMode; |
377 | uint8_t endpoint; | 426 | uint8_t endpoint; |
378 | char *nameStr; | 427 | char *nameStr; |
379 | uint8_t nameLen; | 428 | uint8_t nameLen; |
380 | uint16_t groupId; | 429 | uint16_t groupId; |
381 | uint8_t sceneId; | 430 | uint8_t sceneId; |
382 | |||
383 | //printf("RPCS_ZLL_recallScene++\n"); | ||
384 | |||
385 | //increment past SRPC header | ||
386 | pBuf+=2; | ||
387 | |||
388 | addrMode = (afAddrMode_t)*pBuf++; | ||
389 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
390 | pBuf += Z_EXTADDR_LEN; | ||
391 | endpoint = *pBuf++; | ||
392 | // index past panId | ||
393 | pBuf += 2; | ||
394 | |||
395 | groupId = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
396 | pBuf += 2; | ||
397 | |||
398 | nameLen = *pBuf++; | ||
399 | nameStr = malloc(nameLen + 1); | ||
400 | nameStr[0] = nameLen; | ||
401 | int i; | ||
402 | for(i = 0; i < nameLen; i++) | ||
403 | { | ||
404 | nameStr[i+1] = *pBuf++; | ||
405 | } | ||
406 | |||
407 | //printf("RPCS_ZLL_recallScene++: name[%d] %s, group %d \n", nameLen, nameStr, groupId); | ||
408 | |||
409 | sceneId = sceneListGetSceneId( nameStr, groupId ); | ||
410 | zllSocRecallScene(groupId, sceneId, dstAddr, endpoint, addrMode); | ||
411 | 431 | ||
412 | free(nameStr); | 432 | //printf("SRPC_recallScene++\n"); |
413 | 433 | ||
414 | //printf("RPCS_ZLL_recallScene--\n"); | 434 | //increment past SRPC header |
415 | 435 | pBuf += 2; | |
416 | return 0; | 436 | |
437 | addrMode = (afAddrMode_t) *pBuf++; | ||
438 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
439 | pBuf += Z_EXTADDR_LEN; | ||
440 | endpoint = *pBuf++; | ||
441 | // index past panId | ||
442 | pBuf += 2; | ||
443 | |||
444 | groupId = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
445 | pBuf += 2; | ||
446 | |||
447 | nameLen = *pBuf++; | ||
448 | nameStr = malloc(nameLen + 1); | ||
449 | int i; | ||
450 | for (i = 0; i < nameLen; i++) | ||
451 | { | ||
452 | nameStr[i] = *pBuf++; | ||
453 | } | ||
454 | nameStr[nameLen] = '\0'; | ||
455 | |||
456 | printf("SRPC_recallScene++: name[%d] %s, group %d \n", nameLen, nameStr, groupId); | ||
457 | |||
458 | sceneId = sceneListGetSceneId(nameStr, groupId); | ||
459 | zbSocRecallScene(groupId, sceneId, dstAddr, endpoint, addrMode); | ||
460 | |||
461 | free(nameStr); | ||
462 | |||
463 | //printf("SRPC_recallScene--: id:%x\n", sceneId); | ||
464 | |||
465 | return 0; | ||
417 | } | 466 | } |
418 | 467 | ||
419 | /********************************************************************* | 468 | /********************************************************************* |
420 | * @fn uint8_t RPCS_ZLL_identifyDevice(uint8_t *pBuf, uint32_t clientFd) | 469 | * @fn uint8_t SRPC_identifyDevice(uint8_t *pBuf, uint32_t clientFd) |
421 | * | 470 | * |
422 | * @brief This function exposes an interface to make a device identify. | 471 | * @brief This function exposes an interface to make a device identify. |
423 | * | 472 | * |
@@ -425,41 +474,34 @@ static uint8_t RPCS_ZLL_recallScene(uint8_t *pBuf, uint32 clientFd) | |||
425 | * | 474 | * |
426 | * @return afStatus_t | 475 | * @return afStatus_t |
427 | */ | 476 | */ |
428 | static uint8_t RPCS_ZLL_identifyDevice(uint8_t *pBuf, uint32_t clientFd) | 477 | static uint8_t SRPC_identifyDevice(uint8_t *pBuf, uint32_t clientFd) |
429 | { | 478 | { |
430 | afAddrType_t dstAddr; | 479 | uint8_t endpoint, addrMode; |
431 | uint16_t identifyTime; | 480 | uint16_t dstAddr; |
432 | 481 | uint16_t identifyTime; | |
433 | //printf("RPCS_ZLL_identifyDevice++\n"); | 482 | |
434 | 483 | //printf("SRPC_identifyDevice++\n"); | |
435 | //increment past SRPC header | 484 | |
436 | pBuf+=2; | 485 | //increment past SRPC header |
437 | 486 | pBuf += 2; | |
438 | dstAddr.addrMode = (afAddrMode_t)*pBuf++; | 487 | |
439 | if (dstAddr.addrMode == afAddr64Bit) | 488 | addrMode = (afAddrMode_t) *pBuf++; |
440 | { | 489 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); |
441 | memcpy(dstAddr.addr.extAddr, pBuf, Z_EXTADDR_LEN); | 490 | pBuf += Z_EXTADDR_LEN; |
442 | } | 491 | endpoint = *pBuf++; |
443 | else | 492 | // index past panId |
444 | { | 493 | pBuf += 2; |
445 | dstAddr.addr.shortAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | 494 | |
446 | } | 495 | identifyTime = BUILD_UINT16(pBuf[0], pBuf[1]); |
447 | pBuf += Z_EXTADDR_LEN; | 496 | pBuf += 2; |
448 | 497 | ||
449 | dstAddr.endPoint = *pBuf++; | 498 | zbSocSendIdentify(identifyTime, dstAddr, endpoint, addrMode); |
450 | dstAddr.panId = BUILD_UINT16(pBuf[0], pBuf[1]); | 499 | |
451 | pBuf += 2; | 500 | return 0; |
452 | |||
453 | identifyTime = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
454 | |||
455 | //TODO: implement zllSocIdentify | ||
456 | |||
457 | |||
458 | return 0; | ||
459 | } | 501 | } |
460 | 502 | ||
461 | /********************************************************************* | 503 | /********************************************************************* |
462 | * @fn RSPC_ZLL_bindDevices | 504 | * @fn SRPC_bindDevices |
463 | * | 505 | * |
464 | * @brief This function exposes an interface to set a bind devices. | 506 | * @brief This function exposes an interface to set a bind devices. |
465 | * | 507 | * |
@@ -467,44 +509,44 @@ static uint8_t RPCS_ZLL_identifyDevice(uint8_t *pBuf, uint32_t clientFd) | |||
467 | * | 509 | * |
468 | * @return afStatus_t | 510 | * @return afStatus_t |
469 | */ | 511 | */ |
470 | uint8_t RSPC_ZLL_bindDevices(uint8_t *pBuf, uint32 clientFd) | 512 | uint8_t SRPC_bindDevices(uint8_t *pBuf, uint32_t clientFd) |
471 | { | 513 | { |
472 | uint16_t srcNwkAddr; | 514 | uint16_t srcNwkAddr; |
473 | uint8_t srcEndpoint; | 515 | uint8_t srcEndpoint; |
474 | uint8 srcIEEE[8]; | 516 | uint8 srcIEEE[8]; |
475 | uint8_t dstEndpoint; | 517 | uint8_t dstEndpoint; |
476 | uint8 dstIEEE[8]; | 518 | uint8 dstIEEE[8]; |
477 | uint16 clusterId; | 519 | uint16 clusterId; |
478 | |||
479 | //printf("RSPC_ZLL_bindDevices++\n"); | ||
480 | |||
481 | //increment past SRPC header | ||
482 | pBuf+=2; | ||
483 | |||
484 | /* Src Address */ | ||
485 | srcNwkAddr = BUILD_UINT16( pBuf[0], pBuf[1] ); | ||
486 | pBuf += 2; | ||
487 | 520 | ||
488 | srcEndpoint = *pBuf++; | 521 | //printf("SRPC_bindDevices++\n"); |
489 | |||
490 | memcpy(srcIEEE, pBuf, Z_EXTADDR_LEN); | ||
491 | pBuf += Z_EXTADDR_LEN; | ||
492 | 522 | ||
493 | dstEndpoint = *pBuf++; | 523 | //increment past SRPC header |
494 | 524 | pBuf += 2; | |
495 | memcpy(dstIEEE, pBuf, Z_EXTADDR_LEN); | 525 | |
496 | pBuf += Z_EXTADDR_LEN; | 526 | /* Src Address */ |
497 | 527 | srcNwkAddr = BUILD_UINT16( pBuf[0], pBuf[1] ); | |
498 | clusterId = BUILD_UINT16(pBuf[0], pBuf[1]); | 528 | pBuf += 2; |
499 | pBuf += 2; | 529 | |
500 | 530 | srcEndpoint = *pBuf++; | |
501 | zllSocBind(srcNwkAddr, srcEndpoint, srcIEEE, dstEndpoint, dstIEEE, clusterId); | 531 | |
532 | memcpy(srcIEEE, pBuf, Z_EXTADDR_LEN); | ||
533 | pBuf += Z_EXTADDR_LEN; | ||
534 | |||
535 | dstEndpoint = *pBuf++; | ||
536 | |||
537 | memcpy(dstIEEE, pBuf, Z_EXTADDR_LEN); | ||
538 | pBuf += Z_EXTADDR_LEN; | ||
539 | |||
540 | clusterId = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
541 | pBuf += 2; | ||
502 | 542 | ||
503 | return 0; | 543 | zbSocBind(srcNwkAddr, srcEndpoint, srcIEEE, dstEndpoint, dstIEEE, clusterId); |
544 | |||
545 | return 0; | ||
504 | } | 546 | } |
505 | 547 | ||
506 | /********************************************************************* | 548 | /********************************************************************* |
507 | * @fn RPCS_ZLL_setDeviceState | 549 | * @fn SRPC_setDeviceState |
508 | * | 550 | * |
509 | * @brief This function exposes an interface to set a devices on/off attribute. | 551 | * @brief This function exposes an interface to set a devices on/off attribute. |
510 | * | 552 | * |
@@ -512,38 +554,38 @@ uint8_t RSPC_ZLL_bindDevices(uint8_t *pBuf, uint32 clientFd) | |||
512 | * | 554 | * |
513 | * @return afStatus_t | 555 | * @return afStatus_t |
514 | */ | 556 | */ |
515 | static uint8_t RPCS_ZLL_setDeviceState(uint8_t *pBuf, uint32_t clientFd) | 557 | static uint8_t SRPC_setDeviceState(uint8_t *pBuf, uint32_t clientFd) |
516 | { | 558 | { |
517 | uint8_t endpoint, addrMode; | 559 | uint8_t endpoint, addrMode; |
518 | uint16_t dstAddr; | 560 | uint16_t dstAddr; |
519 | bool state; | 561 | bool state; |
520 | |||
521 | //printf("RPCS_ZLL_setDeviceState++\n"); | ||
522 | |||
523 | //increment past SRPC header | ||
524 | pBuf+=2; | ||
525 | |||
526 | addrMode = (afAddrMode_t)*pBuf++; | ||
527 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
528 | pBuf += Z_EXTADDR_LEN; | ||
529 | endpoint = *pBuf++; | ||
530 | // index past panId | ||
531 | pBuf += 2; | ||
532 | |||
533 | state = (bool)*pBuf; | ||
534 | |||
535 | //printf("RPCS_ZLL_setDeviceState: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x, state=%x\n", dstAddr, endpoint, addrMode, state); | ||
536 | |||
537 | // Set light state on/off | ||
538 | zllSocSetState(state, dstAddr, endpoint, addrMode); | ||
539 | 562 | ||
540 | //printf("RPCS_ZLL_setDeviceState--\n"); | 563 | //printf("SRPC_setDeviceState++\n"); |
541 | 564 | ||
542 | return 0; | 565 | //increment past SRPC header |
566 | pBuf += 2; | ||
567 | |||
568 | addrMode = (afAddrMode_t) *pBuf++; | ||
569 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
570 | pBuf += Z_EXTADDR_LEN; | ||
571 | endpoint = *pBuf++; | ||
572 | // index past panId | ||
573 | pBuf += 2; | ||
574 | |||
575 | state = (bool) *pBuf; | ||
576 | |||
577 | //printf("SRPC_setDeviceState: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x, state=%x\n", dstAddr, endpoint, addrMode, state); | ||
578 | |||
579 | // Set light state on/off | ||
580 | zbSocSetState(state, dstAddr, endpoint, addrMode); | ||
581 | |||
582 | //printf("SRPC_setDeviceState--\n"); | ||
583 | |||
584 | return 0; | ||
543 | } | 585 | } |
544 | 586 | ||
545 | /********************************************************************* | 587 | /********************************************************************* |
546 | * @fn RPCS_ZLL_setDeviceLevel | 588 | * @fn SRPC_setDeviceLevel |
547 | * | 589 | * |
548 | * @brief This function exposes an interface to set a devices level attribute. | 590 | * @brief This function exposes an interface to set a devices level attribute. |
549 | * | 591 | * |
@@ -551,41 +593,41 @@ static uint8_t RPCS_ZLL_setDeviceState(uint8_t *pBuf, uint32_t clientFd) | |||
551 | * | 593 | * |
552 | * @return afStatus_t | 594 | * @return afStatus_t |
553 | */ | 595 | */ |
554 | static uint8_t RPCS_ZLL_setDeviceLevel(uint8_t *pBuf, uint32_t clientFd) | 596 | static uint8_t SRPC_setDeviceLevel(uint8_t *pBuf, uint32_t clientFd) |
555 | { | 597 | { |
556 | uint8_t endpoint, addrMode; | 598 | uint8_t endpoint, addrMode; |
557 | uint16_t dstAddr; | 599 | uint16_t dstAddr; |
558 | uint8_t level; | 600 | uint8_t level; |
559 | uint16_t transitionTime; | 601 | uint16_t transitionTime; |
560 | 602 | ||
561 | //printf("RPCS_ZLL_setDeviceLevel++\n"); | 603 | //printf("SRPC_setDeviceLevel++\n"); |
562 | 604 | ||
563 | //increment past SRPC header | 605 | //increment past SRPC header |
564 | pBuf+=2; | 606 | pBuf += 2; |
565 | 607 | ||
566 | addrMode = (afAddrMode_t)*pBuf++; | 608 | addrMode = (afAddrMode_t) *pBuf++; |
567 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | 609 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); |
568 | pBuf += Z_EXTADDR_LEN; | 610 | pBuf += Z_EXTADDR_LEN; |
569 | endpoint = *pBuf++; | 611 | endpoint = *pBuf++; |
570 | // index past panId | 612 | // index past panId |
571 | pBuf += 2; | 613 | pBuf += 2; |
572 | 614 | ||
573 | level = *pBuf++; | 615 | level = *pBuf++; |
574 | 616 | ||
575 | transitionTime = BUILD_UINT16(pBuf[0], pBuf[1]); | 617 | transitionTime = BUILD_UINT16(pBuf[0], pBuf[1]); |
576 | pBuf += 2; | 618 | pBuf += 2; |
577 | 619 | ||
578 | //printf("RPCS_ZLL_setDeviceLevel: dstAddr.addr.shortAddr=%x ,level=%x, tr=%x \n", dstAddr, level, transitionTime); | 620 | //printf("SRPC_setDeviceLevel: dstAddr.addr.shortAddr=%x ,level=%x, tr=%x \n", dstAddr, level, transitionTime); |
579 | 621 | ||
580 | zllSocSetLevel(level, transitionTime, dstAddr, endpoint, addrMode); | 622 | zbSocSetLevel(level, transitionTime, dstAddr, endpoint, addrMode); |
581 | 623 | ||
582 | //printf("RPCS_ZLL_setDeviceLevel--\n"); | 624 | //printf("SRPC_setDeviceLevel--\n"); |
583 | 625 | ||
584 | return 0; | 626 | return 0; |
585 | } | 627 | } |
586 | 628 | ||
587 | /********************************************************************* | 629 | /********************************************************************* |
588 | * @fn RPCS_ZLL_setDeviceColor | 630 | * @fn SRPC_setDeviceColor |
589 | * | 631 | * |
590 | * @brief This function exposes an interface to set a devices hue and saturation attribute. | 632 | * @brief This function exposes an interface to set a devices hue and saturation attribute. |
591 | * | 633 | * |
@@ -593,43 +635,43 @@ static uint8_t RPCS_ZLL_setDeviceLevel(uint8_t *pBuf, uint32_t clientFd) | |||
593 | * | 635 | * |
594 | * @return afStatus_t | 636 | * @return afStatus_t |
595 | */ | 637 | */ |
596 | static uint8_t RPCS_ZLL_setDeviceColor(uint8_t *pBuf, uint32_t clientFd) | 638 | static uint8_t SRPC_setDeviceColor(uint8_t *pBuf, uint32_t clientFd) |
597 | { | 639 | { |
598 | uint8_t endpoint, addrMode; | 640 | uint8_t endpoint, addrMode; |
599 | uint16_t dstAddr; | 641 | uint16_t dstAddr; |
600 | uint8_t hue, saturation; | 642 | uint8_t hue, saturation; |
601 | uint16_t transitionTime; | 643 | uint16_t transitionTime; |
602 | 644 | ||
603 | //printf("RPCS_ZLL_setDeviceColor++\n"); | 645 | //printf("SRPC_setDeviceColor++\n"); |
604 | 646 | ||
605 | //increment past SRPC header | 647 | //increment past SRPC header |
606 | pBuf+=2; | 648 | pBuf += 2; |
607 | 649 | ||
608 | addrMode = (afAddrMode_t)*pBuf++; | 650 | addrMode = (afAddrMode_t) *pBuf++; |
609 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | 651 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); |
610 | pBuf += Z_EXTADDR_LEN; | 652 | pBuf += Z_EXTADDR_LEN; |
611 | endpoint = *pBuf++; | 653 | endpoint = *pBuf++; |
612 | // index past panId | 654 | // index past panId |
613 | pBuf += 2; | 655 | pBuf += 2; |
614 | 656 | ||
615 | hue = *pBuf++; | 657 | hue = *pBuf++; |
616 | 658 | ||
617 | saturation = *pBuf++; | 659 | saturation = *pBuf++; |
618 | 660 | ||
619 | transitionTime = BUILD_UINT16(pBuf[0], pBuf[1]); | 661 | transitionTime = BUILD_UINT16(pBuf[0], pBuf[1]); |
620 | pBuf += 2; | 662 | pBuf += 2; |
621 | 663 | ||
622 | //printf("RPCS_ZLL_setDeviceColor: dstAddr=%x ,hue=%x, saturation=%x, tr=%x \n", dstAddr, hue, saturation, transitionTime); | 664 | // printf("SRPC_setDeviceColor: dstAddr=%x ,hue=%x, saturation=%x, tr=%x \n", dstAddr, hue, saturation, transitionTime); |
623 | 665 | ||
624 | zllSocSetHueSat(hue, saturation, transitionTime, dstAddr, endpoint, addrMode); | 666 | zbSocSetHueSat(hue, saturation, transitionTime, dstAddr, endpoint, addrMode); |
625 | 667 | ||
626 | //printf("RPCS_ZLL_setDeviceColor--\n"); | 668 | //printf("SRPC_setDeviceColor--\n"); |
627 | 669 | ||
628 | return 0; | 670 | return 0; |
629 | } | 671 | } |
630 | 672 | ||
631 | /********************************************************************* | 673 | /********************************************************************* |
632 | * @fn RPCS_ZLL_getDeviceState | 674 | * @fn SRPC_getDeviceState |
633 | * | 675 | * |
634 | * @brief This function exposes an interface to get a devices on/off attribute. | 676 | * @brief This function exposes an interface to get a devices on/off attribute. |
635 | * | 677 | * |
@@ -637,35 +679,35 @@ static uint8_t RPCS_ZLL_setDeviceColor(uint8_t *pBuf, uint32_t clientFd) | |||
637 | * | 679 | * |
638 | * @return afStatus_t | 680 | * @return afStatus_t |
639 | */ | 681 | */ |
640 | static uint8_t RPCS_ZLL_getDeviceState(uint8_t *pBuf, uint32_t clientFd) | 682 | static uint8_t SRPC_getDeviceState(uint8_t *pBuf, uint32_t clientFd) |
641 | { | 683 | { |
642 | uint8_t endpoint, addrMode; | 684 | uint8_t endpoint, addrMode; |
643 | uint16_t dstAddr; | 685 | uint16_t dstAddr; |
644 | |||
645 | //printf("RPCS_ZLL_getDeviceState++\n"); | ||
646 | |||
647 | //increment past SRPC header | ||
648 | pBuf+=2; | ||
649 | |||
650 | addrMode = (afAddrMode_t)*pBuf++; | ||
651 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
652 | pBuf += Z_EXTADDR_LEN; | ||
653 | endpoint = *pBuf++; | ||
654 | // index past panId | ||
655 | pBuf += 2; | ||
656 | |||
657 | //printf("RPCS_ZLL_getDeviceState: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x", dstAddr, endpoint, addrMode); | ||
658 | |||
659 | // Get light state on/off | ||
660 | zllSocGetState(dstAddr, endpoint, addrMode); | ||
661 | 686 | ||
662 | //printf("RPCS_ZLL_getDeviceState--\n"); | 687 | //printf("SRPC_getDeviceState++\n"); |
663 | 688 | ||
664 | return 0; | 689 | //increment past SRPC header |
690 | pBuf += 2; | ||
691 | |||
692 | addrMode = (afAddrMode_t) *pBuf++; | ||
693 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
694 | pBuf += Z_EXTADDR_LEN; | ||
695 | endpoint = *pBuf++; | ||
696 | // index past panId | ||
697 | pBuf += 2; | ||
698 | |||
699 | //printf("SRPC_getDeviceState: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x", dstAddr, endpoint, addrMode); | ||
700 | |||
701 | // Get light state on/off | ||
702 | zbSocGetState(dstAddr, endpoint, addrMode); | ||
703 | |||
704 | //printf("SRPC_getDeviceState--\n"); | ||
705 | |||
706 | return 0; | ||
665 | } | 707 | } |
666 | 708 | ||
667 | /********************************************************************* | 709 | /********************************************************************* |
668 | * @fn RPCS_ZLL_getDeviceLevel | 710 | * @fn SRPC_getDeviceLevel |
669 | * | 711 | * |
670 | * @brief This function exposes an interface to get a devices level attribute. | 712 | * @brief This function exposes an interface to get a devices level attribute. |
671 | * | 713 | * |
@@ -673,35 +715,35 @@ static uint8_t RPCS_ZLL_getDeviceState(uint8_t *pBuf, uint32_t clientFd) | |||
673 | * | 715 | * |
674 | * @return afStatus_t | 716 | * @return afStatus_t |
675 | */ | 717 | */ |
676 | static uint8_t RPCS_ZLL_getDeviceLevel(uint8_t *pBuf, uint32_t clientFd) | 718 | static uint8_t SRPC_getDeviceLevel(uint8_t *pBuf, uint32_t clientFd) |
677 | { | 719 | { |
678 | uint8_t endpoint, addrMode; | 720 | uint8_t endpoint, addrMode; |
679 | uint16_t dstAddr; | 721 | uint16_t dstAddr; |
680 | |||
681 | //printf("RPCS_ZLL_getDeviceLevel++\n"); | ||
682 | |||
683 | //increment past SRPC header | ||
684 | pBuf+=2; | ||
685 | |||
686 | addrMode = (afAddrMode_t)*pBuf++; | ||
687 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
688 | pBuf += Z_EXTADDR_LEN; | ||
689 | endpoint = *pBuf++; | ||
690 | // index past panId | ||
691 | pBuf += 2; | ||
692 | |||
693 | //printf("RPCS_ZLL_getDeviceLevel: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
694 | |||
695 | // Get light level | ||
696 | zllSocGetLevel(dstAddr, endpoint, addrMode); | ||
697 | 722 | ||
698 | //printf("RPCS_ZLL_getDeviceLevel--\n"); | 723 | //printf("SRPC_getDeviceLevel++\n"); |
699 | 724 | ||
700 | return 0; | 725 | //increment past SRPC header |
726 | pBuf += 2; | ||
727 | |||
728 | addrMode = (afAddrMode_t) *pBuf++; | ||
729 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
730 | pBuf += Z_EXTADDR_LEN; | ||
731 | endpoint = *pBuf++; | ||
732 | // index past panId | ||
733 | pBuf += 2; | ||
734 | |||
735 | //printf("SRPC_getDeviceLevel: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
736 | |||
737 | // Get light level | ||
738 | zbSocGetLevel(dstAddr, endpoint, addrMode); | ||
739 | |||
740 | //printf("SRPC_getDeviceLevel--\n"); | ||
741 | |||
742 | return 0; | ||
701 | } | 743 | } |
702 | 744 | ||
703 | /********************************************************************* | 745 | /********************************************************************* |
704 | * @fn RPCS_ZLL_getDeviceHue | 746 | * @fn SRPC_getDeviceHue |
705 | * | 747 | * |
706 | * @brief This function exposes an interface to get a devices hue attribute. | 748 | * @brief This function exposes an interface to get a devices hue attribute. |
707 | * | 749 | * |
@@ -709,35 +751,35 @@ static uint8_t RPCS_ZLL_getDeviceLevel(uint8_t *pBuf, uint32_t clientFd) | |||
709 | * | 751 | * |
710 | * @return afStatus_t | 752 | * @return afStatus_t |
711 | */ | 753 | */ |
712 | static uint8_t RPCS_ZLL_getDeviceHue(uint8_t *pBuf, uint32_t clientFd) | 754 | static uint8_t SRPC_getDeviceHue(uint8_t *pBuf, uint32_t clientFd) |
713 | { | 755 | { |
714 | uint8_t endpoint, addrMode; | 756 | uint8_t endpoint, addrMode; |
715 | uint16_t dstAddr; | 757 | uint16_t dstAddr; |
716 | |||
717 | //printf("RPCS_ZLL_getDeviceHue++\n"); | ||
718 | |||
719 | //increment past SRPC header | ||
720 | pBuf+=2; | ||
721 | |||
722 | addrMode = (afAddrMode_t)*pBuf++; | ||
723 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
724 | pBuf += Z_EXTADDR_LEN; | ||
725 | endpoint = *pBuf++; | ||
726 | // index past panId | ||
727 | pBuf += 2; | ||
728 | |||
729 | //printf("RPCS_ZLL_getDeviceHue: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
730 | |||
731 | // Get light hue | ||
732 | zllSocGetHue(dstAddr, endpoint, addrMode); | ||
733 | 758 | ||
734 | //printf("RPCS_ZLL_getDeviceHue--\n"); | 759 | //printf("SRPC_getDeviceHue++\n"); |
735 | 760 | ||
736 | return 0; | 761 | //increment past SRPC header |
762 | pBuf += 2; | ||
763 | |||
764 | addrMode = (afAddrMode_t) *pBuf++; | ||
765 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
766 | pBuf += Z_EXTADDR_LEN; | ||
767 | endpoint = *pBuf++; | ||
768 | // index past panId | ||
769 | pBuf += 2; | ||
770 | |||
771 | //printf("SRPC_getDeviceHue: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
772 | |||
773 | // Get light hue | ||
774 | zbSocGetHue(dstAddr, endpoint, addrMode); | ||
775 | |||
776 | //printf("SRPC_getDeviceHue--\n"); | ||
777 | |||
778 | return 0; | ||
737 | } | 779 | } |
738 | 780 | ||
739 | /********************************************************************* | 781 | /********************************************************************* |
740 | * @fn RPCS_ZLL_getDeviceSat | 782 | * @fn SRPC_getDeviceSat |
741 | * | 783 | * |
742 | * @brief This function exposes an interface to get a devices sat attribute. | 784 | * @brief This function exposes an interface to get a devices sat attribute. |
743 | * | 785 | * |
@@ -745,35 +787,92 @@ static uint8_t RPCS_ZLL_getDeviceHue(uint8_t *pBuf, uint32_t clientFd) | |||
745 | * | 787 | * |
746 | * @return afStatus_t | 788 | * @return afStatus_t |
747 | */ | 789 | */ |
748 | static uint8_t RPCS_ZLL_getDeviceSat(uint8_t *pBuf, uint32_t clientFd) | 790 | static uint8_t SRPC_getDeviceSat(uint8_t *pBuf, uint32_t clientFd) |
749 | { | 791 | { |
750 | uint8_t endpoint, addrMode; | 792 | uint8_t endpoint, addrMode; |
751 | uint16_t dstAddr; | 793 | uint16_t dstAddr; |
752 | |||
753 | //printf("RPCS_ZLL_getDeviceSat++\n"); | ||
754 | |||
755 | //increment past SRPC header | ||
756 | pBuf+=2; | ||
757 | |||
758 | addrMode = (afAddrMode_t)*pBuf++; | ||
759 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
760 | pBuf += Z_EXTADDR_LEN; | ||
761 | endpoint = *pBuf++; | ||
762 | // index past panId | ||
763 | pBuf += 2; | ||
764 | |||
765 | //printf("RPCS_ZLL_getDeviceSat: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
766 | |||
767 | // Get light sat | ||
768 | zllSocGetSat(dstAddr, endpoint, addrMode); | ||
769 | 794 | ||
770 | //printf("RPCS_ZLL_getDeviceSat--\n"); | 795 | //printf("SRPC_getDeviceSat++\n"); |
771 | 796 | ||
772 | return 0; | 797 | //increment past SRPC header |
798 | pBuf += 2; | ||
799 | |||
800 | addrMode = (afAddrMode_t) *pBuf++; | ||
801 | dstAddr = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
802 | pBuf += Z_EXTADDR_LEN; | ||
803 | endpoint = *pBuf++; | ||
804 | // index past panId | ||
805 | pBuf += 2; | ||
806 | |||
807 | //printf("SRPC_getDeviceSat: dstAddr.addr.shortAddr=%x, endpoint=%x dstAddr.mode=%x\n", dstAddr, endpoint, addrMode); | ||
808 | |||
809 | // Get light sat | ||
810 | zbSocGetSat(dstAddr, endpoint, addrMode); | ||
811 | |||
812 | //printf("SRPC_getDeviceSat--\n"); | ||
813 | |||
814 | return 0; | ||
815 | } | ||
816 | |||
817 | /********************************************************************* | ||
818 | * @fn SRPC_changeDeviceName | ||
819 | * | ||
820 | * @brief This function exposes an interface to set a bind devices. | ||
821 | * | ||
822 | * @param pBuf - incomin messages | ||
823 | * | ||
824 | * @return afStatus_t | ||
825 | */ | ||
826 | static uint8_t SRPC_changeDeviceName(uint8_t *pBuf, uint32_t clientFd) | ||
827 | { | ||
828 | uint16_t devNwkAddr; | ||
829 | uint8_t devEndpoint; | ||
830 | uint8_t nameLen; | ||
831 | epInfo_t * epInfo; | ||
832 | |||
833 | printf("RSPC_ZLL_changeDeviceName++\n"); | ||
834 | |||
835 | //increment past SRPC header | ||
836 | pBuf += 2; | ||
837 | |||
838 | // Src Address | ||
839 | devNwkAddr = BUILD_UINT16( pBuf[0], pBuf[1] ); | ||
840 | pBuf += 2; | ||
841 | |||
842 | devEndpoint = *pBuf++; | ||
843 | |||
844 | nameLen = *pBuf++; | ||
845 | if (nameLen > MAX_SUPPORTED_DEVICE_NAME_LENGTH) | ||
846 | { | ||
847 | nameLen = MAX_SUPPORTED_DEVICE_NAME_LENGTH; | ||
848 | } | ||
849 | |||
850 | printf("RSPC_ZLL_changeDeviceName: renaming device %s, len=%d\n", pBuf, | ||
851 | nameLen); | ||
852 | printf("RSPC_ZLL_changeDeviceName: devNwkAddr=%x, devEndpoint=%x\n", | ||
853 | devNwkAddr, devEndpoint); | ||
854 | |||
855 | epInfo = devListRemoveDeviceByNaEp(devNwkAddr, devEndpoint); | ||
856 | if (epInfo != NULL) | ||
857 | { | ||
858 | /* | ||
859 | if(epInfo->deviceName != NULL) | ||
860 | { | ||
861 | free(epInfo->deviceName); | ||
862 | }*/ | ||
863 | epInfo->deviceName = malloc(nameLen + 1); | ||
864 | printf("RSPC_ZLL_changeDeviceName: renamed device %s, len=%d\n", pBuf, | ||
865 | nameLen); | ||
866 | strncpy(epInfo->deviceName, (char *) pBuf, nameLen); | ||
867 | epInfo->deviceName[nameLen] = '\0'; | ||
868 | devListAddDevice(epInfo); | ||
869 | } | ||
870 | |||
871 | return 0; | ||
773 | } | 872 | } |
774 | 873 | ||
775 | /********************************************************************* | 874 | /********************************************************************* |
776 | * @fn RSPC_ZLL_close | 875 | * @fn SRPC_close |
777 | * | 876 | * |
778 | * @brief This function exposes an interface to allow an upper layer to close the interface. | 877 | * @brief This function exposes an interface to allow an upper layer to close the interface. |
779 | * | 878 | * |
@@ -781,31 +880,60 @@ static uint8_t RPCS_ZLL_getDeviceSat(uint8_t *pBuf, uint32_t clientFd) | |||
781 | * | 880 | * |
782 | * @return afStatus_t | 881 | * @return afStatus_t |
783 | */ | 882 | */ |
784 | uint8_t RSPC_ZLL_close(uint8_t *pBuf, uint32_t clientFd) | 883 | uint8_t SRPC_close(uint8_t *pBuf, uint32_t clientFd) |
785 | { | 884 | { |
786 | uint16_t magicNumber; | 885 | uint16_t magicNumber; |
787 | |||
788 | //printf("RSPC_ZLL_close++\n"); | ||
789 | 886 | ||
790 | //increment past SRPC header | 887 | //printf("SRPC_close++\n"); |
791 | pBuf+=2; | 888 | |
792 | 889 | //increment past SRPC header | |
793 | magicNumber = BUILD_UINT16(pBuf[0], pBuf[1]); | 890 | pBuf += 2; |
794 | 891 | ||
795 | if(magicNumber == CLOSE_AUTH_NUM) | 892 | magicNumber = BUILD_UINT16(pBuf[0], pBuf[1]); |
796 | { | 893 | |
797 | //Close the application | 894 | if (magicNumber == CLOSE_AUTH_NUM) |
798 | socketSeverClose(); | 895 | { |
799 | //TODO: Need to create API's and close other fd's | 896 | //Close the application |
800 | 897 | socketSeverClose(); | |
801 | exit(EXIT_SUCCESS ); | 898 | //TODO: Need to create API's and close other fd's |
802 | } | 899 | |
803 | 900 | exit(EXIT_SUCCESS); | |
804 | return 0; | 901 | } |
805 | } | 902 | |
903 | return 0; | ||
904 | } | ||
905 | |||
906 | /********************************************************************* | ||
907 | * @fn uint8_t SRPC_permitJoin(uint8_t *pBuf, uint32_t clientFd) | ||
908 | * | ||
909 | * @brief This function exposes an interface to permit other devices to join the network. | ||
910 | * | ||
911 | * @param pBuf - incomin messages | ||
912 | * | ||
913 | * @return none | ||
914 | */ | ||
915 | static uint8_t SRPC_permitJoin(uint8_t *pBuf, uint32_t clientFd) | ||
916 | { | ||
917 | uint8_t duration; | ||
918 | uint16_t magicNumber; | ||
919 | |||
920 | //increment past SRPC header | ||
921 | pBuf += 2; | ||
922 | |||
923 | duration = *pBuf++; | ||
924 | magicNumber = BUILD_UINT16(pBuf[0], pBuf[1]); | ||
925 | |||
926 | if (magicNumber == JOIN_AUTH_NUM) | ||
927 | { | ||
928 | //Open the network for joining | ||
929 | zbSocOpenNwk(duration); | ||
930 | } | ||
931 | |||
932 | return 0; | ||
933 | } | ||
806 | 934 | ||
807 | /********************************************************************* | 935 | /********************************************************************* |
808 | * @fn uint8_t RPCS_ZLL_getGroups(uint8_t *pBuf, uint32 clientFd) | 936 | * @fn uint8_t SRPC_getGroups(uint8_t *pBuf, uint32_t clientFd) |
809 | * | 937 | * |
810 | * @brief This function exposes an interface to get the group list. | 938 | * @brief This function exposes an interface to get the group list. |
811 | * | 939 | * |
@@ -813,99 +941,111 @@ uint8_t RSPC_ZLL_close(uint8_t *pBuf, uint32_t clientFd) | |||
813 | * | 941 | * |
814 | * @return none | 942 | * @return none |
815 | */ | 943 | */ |
816 | static uint8_t RPCS_ZLL_getGroups(uint8_t *pBuf, uint32 clientFd) | 944 | static uint8_t SRPC_getGroups(uint8_t *pBuf, uint32_t clientFd) |
817 | { | 945 | { |
818 | groupListItem_t *group = groupListGetNextGroup(NULL); | 946 | uint32_t context = 0; |
819 | 947 | groupRecord_t *group = groupListGetNextGroup(&context); | |
820 | //printf("RPCS_ZLL_getGroups++\n"); | 948 | uint8_t nameLen, nameIdx; |
821 | 949 | ||
822 | while(group != NULL) | 950 | //printf("SRPC_getGroups++\n"); |
823 | { | 951 | |
824 | uint8_t *pSrpcMessage, *pBuf; | 952 | while (group != NULL) |
825 | //printf("RPCS_ZLL_getGroups: group != null\n"); | 953 | { |
826 | 954 | uint8_t *pSrpcMessage, *pBuf; | |
827 | //printf("RPCS_ZLL_getGroups: malloc'ing %d bytes\n", (2 + (sizeof(uint16_t)) + ((uint8_t) (group->groupNameStr[0])))); | 955 | //printf("SRPC_getGroups: group != null\n"); |
828 | 956 | ||
829 | //RpcMessage contains function ID param Data Len and param data | 957 | //printf("SRPC_getGroups: malloc'ing %d bytes\n", (2 + (sizeof(uint16_t)) + ((uint8_t) (group->groupNameStr[0])))); |
830 | //2 (SRPC header) + sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (GroupName Len) + group->groupNameStr[0] (string) | 958 | |
831 | pSrpcMessage = malloc(2 + (sizeof(uint16_t)) + sizeof(uint8_t) + ((uint8_t) (group->groupNameStr[0]))); | 959 | //RpcMessage contains function ID param Data Len and param data |
832 | 960 | //2 (SRPC header) + sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (GroupName Len) + group->groupNameStr[0] (string) | |
833 | pBuf = pSrpcMessage; | 961 | pSrpcMessage = malloc( |
834 | 962 | 2 + (sizeof(uint16_t)) + sizeof(uint8_t) + ((uint8_t)(group->name[0]))); | |
835 | //Set func ID in RPCS buffer | 963 | |
836 | *pBuf++ = RPCS_GET_GROUP_RSP; | 964 | pBuf = pSrpcMessage; |
837 | //param size | 965 | |
838 | //sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (GroupName Len) + group->groupNameStr[0] (string) | 966 | //Set func ID in RPCS buffer |
839 | *pBuf++ = (sizeof(uint16_t) + sizeof(uint8_t) + group->groupNameStr[0]); | 967 | *pBuf++ = SRPC_GET_GROUP_RSP; |
840 | 968 | //param size | |
841 | *pBuf++ = group->groupId & 0xFF; | 969 | //sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (GroupName Len) + group->groupNameStr[0] (string) |
842 | *pBuf++ = (group->groupId & 0xFF00) >> 8; | 970 | *pBuf++ = (sizeof(uint16_t) + sizeof(uint8_t) + group->name[0]); |
843 | 971 | ||
844 | *pBuf++ = group->groupNameStr[0]; | 972 | *pBuf++ = group->id & 0xFF; |
845 | 973 | *pBuf++ = (group->id & 0xFF00) >> 8; | |
846 | int i; | 974 | |
847 | for(i = 0; i < group->groupNameStr[0]; i++) | 975 | nameLen = strlen(group->name); |
848 | { | 976 | if (nameLen > 0) |
849 | *pBuf++ = group->groupNameStr[i+1]; | 977 | { |
850 | } | 978 | *pBuf++ = nameLen; |
851 | 979 | for (nameIdx = 0; nameIdx < nameLen; nameIdx++) | |
852 | //printf("RPCS_ZLL_CallBack_addGroupRsp: groupName[%d] %s\n", group->groupNameStr[0], &(group->groupNameStr[1])); | 980 | { |
853 | //Send SRPC | 981 | *pBuf++ = group->name[nameIdx]; |
854 | srpcSend(pSrpcMessage, clientFd); | 982 | } |
855 | free(pSrpcMessage); | 983 | printf("SRPC_getGroups: name:%s\n", group->name); |
856 | //get next group (NULL if all done) | 984 | } |
857 | group = groupListGetNextGroup(group->groupNameStr); | 985 | else |
858 | } | 986 | { |
859 | //printf("RPCS_ZLL_getGroups--\n"); | 987 | *pBuf++ = 0; |
860 | 988 | } | |
861 | return 0; | 989 | |
990 | //printf("SRPC_CallBack_addGroupRsp: groupName[%d] %s\n", group->groupNameStr[0], &(group->groupNameStr[1])); | ||
991 | //Send SRPC | ||
992 | srpcSend(pSrpcMessage, clientFd); | ||
993 | free(pSrpcMessage); | ||
994 | //get next group (NULL if all done) | ||
995 | group = groupListGetNextGroup(&context); | ||
996 | } | ||
997 | //printf("SRPC_getGroups--\n"); | ||
998 | |||
999 | return 0; | ||
862 | } | 1000 | } |
863 | 1001 | ||
864 | /*************************************************************************************************** | 1002 | /*************************************************************************************************** |
865 | * @fn RPCS_ZLL_CallBack_addGroupRsp | 1003 | * @fn SRPC_CallBack_addGroupRsp |
866 | * | 1004 | * |
867 | * @brief Sends the groupId to the client after a groupAdd | 1005 | * @brief Sends the groupId to the client after a groupAdd |
868 | * | 1006 | * |
869 | * @return Status | 1007 | * @return Status |
870 | ***************************************************************************************************/ | 1008 | ***************************************************************************************************/ |
871 | void RPCS_ZLL_CallBack_addGroupRsp(uint16_t groupId, char *nameStr, uint32 clientFd) | 1009 | void SRPC_CallBack_addGroupRsp(uint16_t groupId, char *nameStr, |
1010 | uint32_t clientFd) | ||
872 | { | 1011 | { |
873 | uint8_t *pSrpcMessage, *pBuf; | 1012 | uint8_t *pSrpcMessage, *pBuf; |
874 | 1013 | ||
875 | //printf("RPCS_ZLL_CallBack_addGroupRsp++\n"); | 1014 | //printf("SRPC_CallBack_addGroupRsp++\n"); |
876 | 1015 | ||
877 | //printf("RPCS_ZLL_CallBack_addGroupRsp: malloc'ing %d bytes\n", 2 + 3 + nameStr[0]); | 1016 | //printf("SRPC_CallBack_addGroupRsp: malloc'ing %d bytes\n", 2 + 3 + nameStr[0]); |
878 | //RpcMessage contains function ID param Data Len and param data | 1017 | //RpcMessage contains function ID param Data Len and param data |
879 | pSrpcMessage = malloc(2 + 3 + nameStr[0]); | 1018 | pSrpcMessage = malloc(2 + 3 + strlen(nameStr)); |
880 | 1019 | ||
881 | pBuf = pSrpcMessage; | 1020 | pBuf = pSrpcMessage; |
882 | 1021 | ||
883 | //Set func ID in RPCS buffer | 1022 | //Set func ID in SRPC buffer |
884 | *pBuf++ = RPCS_ADD_GROUP_RSP; | 1023 | *pBuf++ = SRPC_ADD_GROUP_RSP; |
885 | //param size | 1024 | //param size |
886 | *pBuf++ = 3 + nameStr[0]; | 1025 | *pBuf++ = 3 + strlen(nameStr); |
887 | 1026 | ||
888 | *pBuf++ = groupId & 0xFF; | 1027 | *pBuf++ = groupId & 0xFF; |
889 | *pBuf++ = (groupId & 0xFF00) >> 8; | 1028 | *pBuf++ = (groupId & 0xFF00) >> 8; |
890 | 1029 | ||
891 | *pBuf++ = nameStr[0]; | 1030 | *pBuf++ = strlen(nameStr); |
892 | int i; | 1031 | int i; |
893 | for(i = 0; i < nameStr[0]; i++) | 1032 | for (i = 0; i < strlen(nameStr); i++) |
894 | { | 1033 | { |
895 | *pBuf++ = nameStr[i+1]; | 1034 | *pBuf++ = nameStr[i]; |
896 | } | 1035 | } |
897 | 1036 | ||
898 | //printf("RPCS_ZLL_CallBack_addGroupRsp: groupName[%d] %s\n", nameStr[0], nameStr); | 1037 | printf("SRPC_CallBack_addGroupRsp: groupName[%d] %s\n", strlen(nameStr), |
899 | //Send SRPC | 1038 | nameStr); |
900 | srpcSend(pSrpcMessage, clientFd); | 1039 | //Send SRPC |
1040 | srpcSend(pSrpcMessage, clientFd); | ||
901 | 1041 | ||
902 | //printf("RPCS_ZLL_CallBack_addGroupRsp--\n"); | 1042 | //printf("SRPC_CallBack_addGroupRsp--\n"); |
903 | 1043 | ||
904 | return; | 1044 | return; |
905 | } | 1045 | } |
906 | 1046 | ||
907 | /********************************************************************* | 1047 | /********************************************************************* |
908 | * @fn uint8_t RPCS_ZLL_getScenes(uint8_t *pBuf, uint32 clientFd) | 1048 | * @fn uint8_t SRPC_getScenes(uint8_t *pBuf, uint32_t clientFd) |
909 | * | 1049 | * |
910 | * @brief This function exposes an interface to get the scenes defined for a group. | 1050 | * @brief This function exposes an interface to get the scenes defined for a group. |
911 | * | 1051 | * |
@@ -913,265 +1053,278 @@ void RPCS_ZLL_CallBack_addGroupRsp(uint16_t groupId, char *nameStr, uint32 clien | |||
913 | * | 1053 | * |
914 | * @return afStatus_t | 1054 | * @return afStatus_t |
915 | */ | 1055 | */ |
916 | static uint8_t RPCS_ZLL_getScenes(uint8_t *pBuf, uint32 clientFd) | 1056 | static uint8_t SRPC_getScenes(uint8_t *pBuf, uint32_t clientFd) |
917 | { | 1057 | { |
918 | sceneListItem_t *scene = sceneListGetNextScene(NULL, 0); | 1058 | uint32_t context = 0; |
919 | 1059 | sceneRecord_t *scene = sceneListGetNextScene(&context); | |
920 | //printf("RPCS_ZLL_getScenes++\n"); | 1060 | uint8_t nameLen, nameIdx; |
921 | 1061 | ||
922 | while(scene != NULL) | 1062 | //printf("SRPC_getScenes++\n"); |
923 | { | 1063 | |
924 | uint8_t *pSrpcMessage, *pBuf; | 1064 | while (scene != NULL) |
925 | //printf("RPCS_ZLL_getScenes: scene != null\n"); | 1065 | { |
926 | 1066 | uint8_t *pSrpcMessage, *pBuf; | |
927 | //printf("RPCS_ZLL_getScenes: malloc'ing %d bytes\n", (2 + (sizeof(uint16_t)) + (sizeof(uint8_t)) + (sizeof(uint8_t)) + ((uint8_t) (scene->sceneNameStr[0])))); | 1067 | //printf("SRPC_getScenes: scene != null\n"); |
928 | 1068 | ||
929 | //RpcMessage contains function ID param Data Len and param data | 1069 | //printf("SRPC_getScenes: malloc'ing %d bytes\n", (2 + (sizeof(uint16_t)) + (sizeof(uint8_t)) + (sizeof(uint8_t)) + ((uint8_t) (scene->sceneNameStr[0])))); |
930 | //2 (SRPC header) + sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (SceneName Len) + scene->sceneNameStr[0] (string) | 1070 | |
931 | pSrpcMessage = malloc(2 + (sizeof(uint16_t)) + (sizeof(uint8_t)) + (sizeof(uint8_t)) + ((uint8_t) (scene->sceneNameStr[0]))); | 1071 | //RpcMessage contains function ID param Data Len and param data |
932 | 1072 | //2 (SRPC header) + sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (SceneName Len) + scene->sceneNameStr[0] (string) | |
933 | pBuf = pSrpcMessage; | 1073 | pSrpcMessage = malloc( |
934 | 1074 | 2 + (sizeof(uint16_t)) + (sizeof(uint8_t)) + (sizeof(uint8_t)) | |
935 | //Set func ID in RPCS buffer | 1075 | + ((uint8_t)(scene->name[0]))); |
936 | *pBuf++ = RPCS_GET_SCENE_RSP; | 1076 | |
937 | //param size | 1077 | pBuf = pSrpcMessage; |
938 | //sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (SceneName Len) + scene->sceneNameStr[0] (string) | 1078 | |
939 | *pBuf++ = (sizeof(uint16_t) + (sizeof(uint8_t)) + (sizeof(uint8_t)) + scene->sceneNameStr[0]); | 1079 | //Set func ID in RPCS buffer |
940 | 1080 | *pBuf++ = SRPC_GET_SCENE_RSP; | |
941 | *pBuf++ = scene->groupId & 0xFF; | 1081 | //param size |
942 | *pBuf++ = (scene->groupId & 0xFF00) >> 8; | 1082 | //sizeof(uint16_t) (GroupId) + sizeof(uint8_t) (SceneId) + sizeof(uint8_t) (SceneName Len) + scene->sceneNameStr[0] (string) |
943 | 1083 | *pBuf++ = (sizeof(uint16_t) + (sizeof(uint8_t)) + (sizeof(uint8_t)) | |
944 | *pBuf++ = scene->sceneId; | 1084 | + scene->name[0]); |
945 | 1085 | ||
946 | *pBuf++ = scene->sceneNameStr[0]; | 1086 | *pBuf++ = scene->groupId & 0xFF; |
947 | int i; | 1087 | *pBuf++ = (scene->groupId & 0xFF00) >> 8; |
948 | for(i = 0; i < scene->sceneNameStr[0]; i++) | 1088 | |
949 | { | 1089 | *pBuf++ = scene->sceneId; |
950 | *pBuf++ = scene->sceneNameStr[i+1]; | 1090 | |
951 | } | 1091 | nameLen = strlen(scene->name); |
952 | 1092 | if (nameLen > 0) | |
953 | //printf("RPCS_ZLL_getScenes: sceneName[%d] %s, groupId %x\n", scene->sceneNameStr[0], &(scene->sceneNameStr[1]), scene->groupId); | 1093 | { |
954 | //Send SRPC | 1094 | *pBuf++ = nameLen; |
955 | srpcSend(pSrpcMessage, clientFd); | 1095 | for (nameIdx = 0; nameIdx < nameLen; nameIdx++) |
956 | free(pSrpcMessage); | 1096 | { |
957 | //get next scene (NULL if all done) | 1097 | *pBuf++ = scene->name[nameIdx]; |
958 | scene = sceneListGetNextScene(scene->sceneNameStr, scene->groupId); | 1098 | } |
959 | } | 1099 | printf("SRPC_getScenes: name:%s\n", scene->name); |
960 | //printf("RPCS_ZLL_getScenes--\n"); | 1100 | } |
961 | 1101 | else | |
962 | return 0; | 1102 | { |
1103 | *pBuf++ = 0; | ||
1104 | } | ||
1105 | |||
1106 | //printf("SRPC_getScenes: sceneName[%d] %s, groupId %x\n", scene->sceneNameStr[0], &(scene->sceneNameStr[1]), scene->groupId); | ||
1107 | //Send SRPC | ||
1108 | srpcSend(pSrpcMessage, clientFd); | ||
1109 | free(pSrpcMessage); | ||
1110 | //get next scene (NULL if all done) | ||
1111 | scene = sceneListGetNextScene(&context); | ||
1112 | } | ||
1113 | //printf("SRPC_getScenes--\n"); | ||
1114 | |||
1115 | return 0; | ||
963 | } | 1116 | } |
964 | 1117 | ||
965 | /*************************************************************************************************** | 1118 | /*************************************************************************************************** |
966 | * @fn RPCS_ZLL_CallBack_addSceneRsp | 1119 | * @fn SRPC_CallBack_addSceneRsp |
967 | * | 1120 | * |
968 | * @brief Sends the sceneId to the client after a storeScene | 1121 | * @brief Sends the sceneId to the client after a storeScene |
969 | * | 1122 | * |
970 | * @return Status | 1123 | * @return Status |
971 | ***************************************************************************************************/ | 1124 | ***************************************************************************************************/ |
972 | void RPCS_ZLL_CallBack_addSceneRsp(uint16_t groupId, uint8_t sceneId, char *nameStr, uint32 clientFd) | 1125 | void SRPC_CallBack_addSceneRsp(uint16_t groupId, uint8_t sceneId, char *nameStr, |
1126 | uint32_t clientFd) | ||
973 | { | 1127 | { |
974 | uint8_t *pSrpcMessage, *pBuf; | 1128 | uint8_t *pSrpcMessage, *pBuf; |
975 | 1129 | ||
976 | //printf("RPCS_ZLL_CallBack_addSceneRsp++\n"); | 1130 | //printf("SRPC_CallBack_addSceneRsp++\n"); |
977 | 1131 | ||
978 | //printf("RPCS_ZLL_CallBack_addSceneRsp: malloc'ing %d bytes\n", 2 + 4 + nameStr[0]); | 1132 | //printf("SRPC_CallBack_addSceneRsp: malloc'ing %d bytes\n", 2 + 4 + nameStr[0]); |
979 | //RpcMessage contains function ID param Data Len and param data | 1133 | //RpcMessage contains function ID param Data Len and param data |
980 | pSrpcMessage = malloc(2 + 4 + nameStr[0]); | 1134 | pSrpcMessage = malloc(2 + 4 + nameStr[0]); |
981 | 1135 | ||
982 | pBuf = pSrpcMessage; | 1136 | pBuf = pSrpcMessage; |
983 | |||
984 | //Set func ID in RPCS buffer | ||
985 | *pBuf++ = RPCS_ADD_SCENE_RSP; | ||
986 | //param size | ||
987 | *pBuf++ = 4 + nameStr[0]; | ||
988 | |||
989 | *pBuf++ = groupId & 0xFF; | ||
990 | *pBuf++ = (groupId & 0xFF00) >> 8; | ||
991 | |||
992 | *pBuf++ = sceneId & 0xFF; | ||
993 | |||
994 | *pBuf++ = nameStr[0]; | ||
995 | int i; | ||
996 | for(i = 0; i < nameStr[0]; i++) | ||
997 | { | ||
998 | *pBuf++ = nameStr[i+1]; | ||
999 | } | ||
1000 | |||
1001 | //printf("RPCS_ZLL_CallBack_addSceneRsp: groupName[%d] %s\n", nameStr[0], nameStr); | ||
1002 | //Send SRPC | ||
1003 | srpcSend(pSrpcMessage, clientFd); | ||
1004 | 1137 | ||
1005 | //printf("RPCS_ZLL_CallBack_addSceneRsp--\n"); | 1138 | //Set func ID in SRPC buffer |
1006 | 1139 | *pBuf++ = SRPC_ADD_SCENE_RSP; | |
1007 | return; | 1140 | //param size |
1141 | *pBuf++ = 4 + nameStr[0]; | ||
1142 | |||
1143 | *pBuf++ = groupId & 0xFF; | ||
1144 | *pBuf++ = (groupId & 0xFF00) >> 8; | ||
1145 | |||
1146 | *pBuf++ = sceneId & 0xFF; | ||
1147 | |||
1148 | *pBuf++ = nameStr[0]; | ||
1149 | int i; | ||
1150 | for (i = 0; i < nameStr[0]; i++) | ||
1151 | { | ||
1152 | *pBuf++ = nameStr[i + 1]; | ||
1153 | } | ||
1154 | |||
1155 | //printf("SRPC_CallBack_addSceneRsp: groupName[%d] %s\n", nameStr[0], nameStr); | ||
1156 | //Send SRPC | ||
1157 | srpcSend(pSrpcMessage, clientFd); | ||
1158 | |||
1159 | //printf("SRPC_CallBack_addSceneRsp--\n"); | ||
1160 | |||
1161 | return; | ||
1008 | } | 1162 | } |
1009 | 1163 | ||
1010 | /*************************************************************************************************** | 1164 | /*************************************************************************************************** |
1011 | * @fn RPCS_ZLL_CallBack_getStateRsp | 1165 | * @fn SRPC_CallBack_getStateRsp |
1012 | * | 1166 | * |
1013 | * @brief Sends the get State Rsp to the client that sent a get state | 1167 | * @brief Sends the get State Rsp to the client that sent a get state |
1014 | * | 1168 | * |
1015 | * @return Status | 1169 | * @return Status |
1016 | ***************************************************************************************************/ | 1170 | ***************************************************************************************************/ |
1017 | void RPCS_ZLL_CallBack_getStateRsp(uint8_t state, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd) | 1171 | void SRPC_CallBack_getStateRsp(uint8_t state, uint16_t srcAddr, |
1172 | uint8_t endpoint, uint32_t clientFd) | ||
1018 | { | 1173 | { |
1019 | uint8_t *pSrpcMessage, *pBuf; | 1174 | uint8_t * pBuf; |
1020 | 1175 | uint8_t pSrpcMessage[2 + 4]; | |
1021 | //printf("RPCS_ZLL_CallBack_getStateRsp++\n"); | 1176 | |
1022 | 1177 | //printf("SRPC_CallBack_getStateRsp++\n"); | |
1023 | //printf("RPCS_ZLL_CallBack_getStateRsp: malloc'ing %d bytes\n", 2+ 4); | 1178 | |
1024 | //RpcMessage contains function ID param Data Len and param data | 1179 | //RpcMessage contains function ID param Data Len and param data |
1025 | pSrpcMessage = malloc(2+ 4); | 1180 | |
1026 | 1181 | pBuf = pSrpcMessage; | |
1027 | pBuf = pSrpcMessage; | 1182 | |
1028 | 1183 | //Set func ID in RPCS buffer | |
1029 | //Set func ID in RPCS buffer | 1184 | *pBuf++ = SRPC_GET_DEV_STATE_RSP; |
1030 | *pBuf++ = RPCS_GET_DEV_STATE_RSP; | 1185 | //param size |
1031 | //param size | 1186 | *pBuf++ = 4; |
1032 | *pBuf++ = 4; | 1187 | |
1033 | 1188 | *pBuf++ = srcAddr & 0xFF; | |
1034 | *pBuf++ = srcAddr & 0xFF; | 1189 | *pBuf++ = (srcAddr & 0xFF00) >> 8; |
1035 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | 1190 | *pBuf++ = endpoint; |
1036 | *pBuf++ = endpoint; | 1191 | *pBuf++ = state & 0xFF; |
1037 | *pBuf++ = state & 0xFF; | 1192 | |
1038 | 1193 | //printf("SRPC_CallBack_getStateRsp: state=%x\n", state); | |
1039 | //printf("RPCS_ZLL_CallBack_getStateRsp: state=%x\n", state); | 1194 | |
1040 | 1195 | //Store the device that sent the request, for now send to all clients | |
1041 | //Store the device that sent the request, for now send to all clients | 1196 | srpcSendAll(pSrpcMessage); |
1042 | srpcSendAll(pSrpcMessage); | ||
1043 | 1197 | ||
1044 | //printf("RPCS_ZLL_CallBack_addSceneRsp--\n"); | 1198 | //printf("SRPC_CallBack_addSceneRsp--\n"); |
1045 | 1199 | ||
1046 | return; | 1200 | return; |
1047 | } | 1201 | } |
1048 | 1202 | ||
1049 | /*************************************************************************************************** | 1203 | /*************************************************************************************************** |
1050 | * @fn RPCS_ZLL_CallBack_getLevelRsp | 1204 | * @fn SRPC_CallBack_getLevelRsp |
1051 | * | 1205 | * |
1052 | * @brief Sends the get Level Rsp to the client that sent a get level | 1206 | * @brief Sends the get Level Rsp to the client that sent a get level |
1053 | * | 1207 | * |
1054 | * @return Status | 1208 | * @return Status |
1055 | ***************************************************************************************************/ | 1209 | ***************************************************************************************************/ |
1056 | void RPCS_ZLL_CallBack_getLevelRsp(uint8_t level, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd) | 1210 | void SRPC_CallBack_getLevelRsp(uint8_t level, uint16_t srcAddr, |
1211 | uint8_t endpoint, uint32_t clientFd) | ||
1057 | { | 1212 | { |
1058 | uint8_t *pSrpcMessage, *pBuf; | 1213 | uint8_t * pBuf; |
1059 | 1214 | uint8_t pSrpcMessage[2 + 4]; | |
1060 | //printf("RPCS_ZLL_CallBack_getLevelRsp++\n"); | 1215 | |
1061 | 1216 | //printf("SRPC_CallBack_getLevelRsp++\n"); | |
1062 | //printf("RPCS_ZLL_CallBack_getLevelRsp: malloc'ing %d bytes\n", 2 + 4); | 1217 | |
1063 | //RpcMessage contains function ID param Data Len and param data | 1218 | //RpcMessage contains function ID param Data Len and param data |
1064 | pSrpcMessage = malloc(2 + 4); | ||
1065 | |||
1066 | pBuf = pSrpcMessage; | ||
1067 | |||
1068 | //Set func ID in RPCS buffer | ||
1069 | *pBuf++ = RPCS_GET_DEV_LEVEL_RSP; | ||
1070 | //param size | ||
1071 | *pBuf++ = 4; | ||
1072 | |||
1073 | *pBuf++ = srcAddr & 0xFF; | ||
1074 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | ||
1075 | *pBuf++ = endpoint; | ||
1076 | *pBuf++ = level & 0xFF; | ||
1077 | |||
1078 | //printf("RPCS_ZLL_CallBack_getLevelRsp: level=%x\n", level); | ||
1079 | |||
1080 | //Store the device that sent the request, for now send to all clients | ||
1081 | srpcSendAll(pSrpcMessage); | ||
1082 | 1219 | ||
1083 | //printf("RPCS_ZLL_CallBack_getLevelRsp--\n"); | 1220 | pBuf = pSrpcMessage; |
1084 | 1221 | ||
1085 | return; | 1222 | //Set func ID in RPCS buffer |
1223 | *pBuf++ = SRPC_GET_DEV_LEVEL_RSP; | ||
1224 | //param size | ||
1225 | *pBuf++ = 4; | ||
1226 | |||
1227 | *pBuf++ = srcAddr & 0xFF; | ||
1228 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | ||
1229 | *pBuf++ = endpoint; | ||
1230 | *pBuf++ = level & 0xFF; | ||
1231 | |||
1232 | //printf("SRPC_CallBack_getLevelRsp: level=%x\n", level); | ||
1233 | |||
1234 | //Store the device that sent the request, for now send to all clients | ||
1235 | srpcSendAll(pSrpcMessage); | ||
1236 | |||
1237 | //printf("SRPC_CallBack_getLevelRsp--\n"); | ||
1238 | |||
1239 | return; | ||
1086 | } | 1240 | } |
1087 | 1241 | ||
1088 | /*************************************************************************************************** | 1242 | /*************************************************************************************************** |
1089 | * @fn RPCS_ZLL_CallBack_getHueRsp | 1243 | * @fn SRPC_CallBack_getHueRsp |
1090 | * | 1244 | * |
1091 | * @brief Sends the get Hue Rsp to the client that sent a get hue | 1245 | * @brief Sends the get Hue Rsp to the client that sent a get hue |
1092 | * | 1246 | * |
1093 | * @return Status | 1247 | * @return Status |
1094 | ***************************************************************************************************/ | 1248 | ***************************************************************************************************/ |
1095 | void RPCS_ZLL_CallBack_getHueRsp(uint8_t hue, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd) | 1249 | void SRPC_CallBack_getHueRsp(uint8_t hue, uint16_t srcAddr, uint8_t endpoint, |
1250 | uint32_t clientFd) | ||
1096 | { | 1251 | { |
1097 | uint8_t *pSrpcMessage, *pBuf; | 1252 | uint8_t * pBuf; |
1098 | 1253 | uint8_t pSrpcMessage[2 + 4]; | |
1099 | //printf("RPCS_ZLL_CallBack_getLevelRsp++\n"); | 1254 | |
1100 | 1255 | //printf("SRPC_CallBack_getLevelRsp++\n"); | |
1101 | //printf("RPCS_ZLL_CallBack_getHueRsp: malloc'ing %d bytes\n", 2 + 4); | 1256 | |
1102 | //RpcMessage contains function ID param Data Len and param data | 1257 | //RpcMessage contains function ID param Data Len and param data |
1103 | pSrpcMessage = malloc(2 + 4); | 1258 | |
1104 | 1259 | pBuf = pSrpcMessage; | |
1105 | pBuf = pSrpcMessage; | 1260 | |
1106 | 1261 | //Set func ID in RPCS buffer | |
1107 | //Set func ID in RPCS buffer | 1262 | *pBuf++ = SRPC_GET_DEV_HUE_RSP; |
1108 | *pBuf++ = RPCS_GET_DEV_HUE_RSP; | 1263 | //param size |
1109 | //param size | 1264 | *pBuf++ = 4; |
1110 | *pBuf++ = 4; | 1265 | |
1111 | 1266 | *pBuf++ = srcAddr & 0xFF; | |
1112 | *pBuf++ = srcAddr & 0xFF; | 1267 | *pBuf++ = (srcAddr & 0xFF00) >> 8; |
1113 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | 1268 | *pBuf++ = endpoint; |
1114 | *pBuf++ = endpoint; | 1269 | *pBuf++ = hue & 0xFF; |
1115 | *pBuf++ = hue & 0xFF; | 1270 | |
1116 | 1271 | //printf("SRPC_CallBack_getHueRsp: hue=%x\n", hue); | |
1117 | //printf("RPCS_ZLL_CallBack_getHueRsp: hue=%x\n", hue); | 1272 | |
1118 | 1273 | //Store the device that sent the request, for now send to all clients | |
1119 | //Store the device that sent the request, for now send to all clients | 1274 | srpcSendAll(pSrpcMessage); |
1120 | srpcSendAll(pSrpcMessage); | 1275 | |
1276 | //printf("SRPC_CallBack_getHueRsp--\n"); | ||
1121 | 1277 | ||
1122 | //printf("RPCS_ZLL_CallBack_getHueRsp--\n"); | 1278 | return; |
1123 | |||
1124 | return; | ||
1125 | } | 1279 | } |
1126 | 1280 | ||
1127 | /*************************************************************************************************** | 1281 | /*************************************************************************************************** |
1128 | * @fn RPCS_ZLL_CallBack_getSatRsp | 1282 | * @fn SRPC_CallBack_getSatRsp |
1129 | * | 1283 | * |
1130 | * @brief Sends the get Sat Rsp to the client that sent a get sat | 1284 | * @brief Sends the get Sat Rsp to the client that sent a get sat |
1131 | * | 1285 | * |
1132 | * @return Status | 1286 | * @return Status |
1133 | ***************************************************************************************************/ | 1287 | ***************************************************************************************************/ |
1134 | void RPCS_ZLL_CallBack_getSatRsp(uint8_t sat, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd) | 1288 | void SRPC_CallBack_getSatRsp(uint8_t sat, uint16_t srcAddr, uint8_t endpoint, |
1289 | uint32_t clientFd) | ||
1135 | { | 1290 | { |
1136 | uint8_t *pSrpcMessage, *pBuf; | 1291 | uint8_t * pBuf; |
1137 | 1292 | uint8_t pSrpcMessage[2 + 4]; | |
1138 | //printf("RPCS_ZLL_CallBack_getSatRsp++\n"); | ||
1139 | |||
1140 | //printf("RPCS_ZLL_CallBack_getSatRsp: malloc'ing %d bytes\n", 2 + 4); | ||
1141 | //RpcMessage contains function ID param Data Len and param data | ||
1142 | pSrpcMessage = malloc(2 + 4); | ||
1143 | |||
1144 | pBuf = pSrpcMessage; | ||
1145 | |||
1146 | //Set func ID in RPCS buffer | ||
1147 | *pBuf++ = RPCS_GET_DEV_SAT_RSP; | ||
1148 | //param size | ||
1149 | *pBuf++ = 4; | ||
1150 | |||
1151 | *pBuf++ = srcAddr & 0xFF; | ||
1152 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | ||
1153 | *pBuf++ = endpoint; | ||
1154 | *pBuf++ = sat & 0xFF; | ||
1155 | |||
1156 | //printf("RPCS_ZLL_CallBack_getSatRsp: sat=%x\n", sat); | ||
1157 | |||
1158 | //Store the device that sent the request, for now send to all clients | ||
1159 | srpcSendAll(pSrpcMessage); | ||
1160 | 1293 | ||
1161 | //printf("RPCS_ZLL_CallBack_getSatRsp--\n"); | 1294 | //printf("SRPC_CallBack_getSatRsp++\n"); |
1162 | 1295 | ||
1163 | return; | 1296 | //RpcMessage contains function ID param Data Len and param data |
1164 | } | 1297 | |
1298 | pBuf = pSrpcMessage; | ||
1165 | 1299 | ||
1300 | //Set func ID in RPCS buffer | ||
1301 | *pBuf++ = SRPC_GET_DEV_SAT_RSP; | ||
1302 | //param size | ||
1303 | *pBuf++ = 4; | ||
1304 | |||
1305 | *pBuf++ = srcAddr & 0xFF; | ||
1306 | *pBuf++ = (srcAddr & 0xFF00) >> 8; | ||
1307 | *pBuf++ = endpoint; | ||
1308 | *pBuf++ = sat & 0xFF; | ||
1309 | |||
1310 | //printf("SRPC_CallBack_getSatRsp: sat=%x\n", sat); | ||
1311 | |||
1312 | //Store the device that sent the request, for now send to all clients | ||
1313 | srpcSendAll(pSrpcMessage); | ||
1314 | |||
1315 | //printf("SRPC_CallBack_getSatRsp--\n"); | ||
1316 | |||
1317 | return; | ||
1318 | } | ||
1166 | 1319 | ||
1167 | void error(const char *msg) | 1320 | void error(const char *msg) |
1168 | { | 1321 | { |
1169 | perror(msg); | 1322 | perror(msg); |
1170 | exit(1); | 1323 | exit(1); |
1171 | } | 1324 | } |
1172 | 1325 | ||
1173 | /********************************************************************* | 1326 | /********************************************************************* |
1174 | * @fn RSPC_ZLL_getDevices | 1327 | * @fn SRPC_getDevices |
1175 | * | 1328 | * |
1176 | * @brief This function exposes an interface to allow an upper layer to start device discovery. | 1329 | * @brief This function exposes an interface to allow an upper layer to start device discovery. |
1177 | * | 1330 | * |
@@ -1179,34 +1332,40 @@ void error(const char *msg) | |||
1179 | * | 1332 | * |
1180 | * @return afStatus_t | 1333 | * @return afStatus_t |
1181 | */ | 1334 | */ |
1182 | static uint8_t RSPC_ZLL_getDevices(uint8_t *pBuf, uint32_t clientFd) | 1335 | static uint8_t SRPC_getDevices(uint8_t *pBuf, uint32_t clientFd) |
1183 | { | 1336 | { |
1184 | epInfo_t *epInfo; | 1337 | epInfoExtended_t epInfoEx; |
1185 | 1338 | uint32_t context = 0; | |
1186 | //printf("RSPC_ZLL_getDevices++ \n"); | 1339 | uint8_t *pSrpcMessage; |
1187 | 1340 | ||
1188 | epInfo = devListGetNextDev(0xFFFF, 0); | 1341 | //printf("SRPC_getDevices++ \n"); |
1189 | 1342 | ||
1190 | while(epInfo) | 1343 | while ((epInfoEx.epInfo = devListGetNextDev(&context)) != NULL) |
1191 | { | 1344 | { |
1192 | //Send epInfo | 1345 | epInfoEx.type = EP_INFO_TYPE_EXISTING; |
1193 | uint8_t *pSrpcMessage = srpcParseEpInfo(epInfo); | 1346 | epInfoEx.prevNwkAddr = 0xFFFF; |
1194 | //printf("RSPC_ZLL_getDevices: %x:%x:%x:%x\n", epInfo->nwkAddr, epInfo->endpoint, epInfo->profileID, epInfo->deviceID); | 1347 | epInfoEx.epInfo->flags = MT_NEW_DEVICE_FLAGS_NONE; |
1195 | //Send SRPC | 1348 | |
1196 | srpcSend(pSrpcMessage, clientFd); | 1349 | //Send epInfo |
1197 | free(pSrpcMessage); | 1350 | pSrpcMessage = srpcParseEpInfo(&epInfoEx); |
1198 | 1351 | printf("SRPC_getDevices: %x:%x:%x:%x:%x\n", epInfoEx.epInfo->nwkAddr, epInfoEx.epInfo->endpoint, | |
1199 | usleep(1000); | 1352 | epInfoEx.epInfo->profileID, epInfoEx.epInfo->deviceID, epInfoEx.type); |
1200 | 1353 | //Send SRPC | |
1201 | //get next device (NULL if all done) | 1354 | srpcSend(pSrpcMessage, clientFd); |
1202 | epInfo = devListGetNextDev(epInfo->nwkAddr, epInfo->endpoint); | 1355 | free(pSrpcMessage); |
1203 | } | 1356 | |
1204 | 1357 | usleep(1000); | |
1205 | return 0; | 1358 | |
1359 | //get next device (NULL if all done) | ||
1360 | //printf("--?--> 0x%04X, 0x%02X", (uint32_t)epInfoEx.epInfo->nwkAddr, (uint32_t)epInfoEx.epInfo->endpoint); | ||
1361 | //printf(" --!--> 0x%08X\n", (uint32_t)epInfoEx.epInfo); | ||
1362 | } | ||
1363 | |||
1364 | return 0; | ||
1206 | } | 1365 | } |
1207 | 1366 | ||
1208 | /********************************************************************* | 1367 | /********************************************************************* |
1209 | * @fn RPSC_ZLL_notSupported | 1368 | * @fn SRPC_notSupported |
1210 | * | 1369 | * |
1211 | * @brief This function is called for unsupported commands. | 1370 | * @brief This function is called for unsupported commands. |
1212 | * | 1371 | * |
@@ -1214,9 +1373,9 @@ static uint8_t RSPC_ZLL_getDevices(uint8_t *pBuf, uint32_t clientFd) | |||
1214 | * | 1373 | * |
1215 | * @return afStatus_t | 1374 | * @return afStatus_t |
1216 | */ | 1375 | */ |
1217 | static uint8_t RPSC_ZLL_notSupported(uint8_t *pBuf, uint32_t clientFd) | 1376 | static uint8_t SRPC_notSupported(uint8_t *pBuf, uint32_t clientFd) |
1218 | { | 1377 | { |
1219 | return 0; | 1378 | return 0; |
1220 | } | 1379 | } |
1221 | 1380 | ||
1222 | /*************************************************************************************************** | 1381 | /*************************************************************************************************** |
@@ -1226,20 +1385,20 @@ static uint8_t RPSC_ZLL_notSupported(uint8_t *pBuf, uint32_t clientFd) | |||
1226 | * @param | 1385 | * @param |
1227 | * | 1386 | * |
1228 | * @return Status | 1387 | * @return Status |
1229 | ***************************************************************************************************/ | 1388 | ***************************************************************************************************/ |
1230 | void SRPC_Init( void ) | 1389 | void SRPC_Init(void) |
1231 | { | 1390 | { |
1232 | if(socketSeverInit(SRPC_TCP_PORT) == -1) | 1391 | if (socketSeverInit(SRPC_TCP_PORT) == -1) |
1233 | { | 1392 | { |
1234 | //exit if the server does not start | 1393 | //exit if the server does not start |
1235 | exit(-1); | 1394 | exit(-1); |
1236 | } | 1395 | } |
1237 | 1396 | ||
1238 | serverSocketConfig(SRPC_RxCB, SRPC_ConnectCB); | 1397 | serverSocketConfig(SRPC_RxCB, SRPC_ConnectCB); |
1239 | } | 1398 | } |
1240 | 1399 | ||
1241 | /********************************************************************* | 1400 | /********************************************************************* |
1242 | * @fn RSPC_SendEpInfo | 1401 | * @fn SRPC_SendEpInfo |
1243 | * | 1402 | * |
1244 | * @brief This function exposes an interface to allow an upper layer to start send an ep indo to all devices. | 1403 | * @brief This function exposes an interface to allow an upper layer to start send an ep indo to all devices. |
1245 | * | 1404 | * |
@@ -1247,16 +1406,15 @@ void SRPC_Init( void ) | |||
1247 | * | 1406 | * |
1248 | * @return afStatus_t | 1407 | * @return afStatus_t |
1249 | */ | 1408 | */ |
1250 | uint8_t RSPC_SendEpInfo(epInfo_t *epInfo) | 1409 | uint8_t SRPC_SendEpInfo(epInfoExtended_t *epInfoEx) |
1251 | { | 1410 | { |
1252 | uint8_t *pSrpcMessage = srpcParseEpInfo(epInfo); | 1411 | uint8_t *pSrpcMessage = srpcParseEpInfo(epInfoEx); |
1253 | 1412 | ||
1254 | printf("RSPC_SendEpInfo++ %x:%x:%x:%x\n", epInfo->nwkAddr, epInfo->endpoint, epInfo->profileID, epInfo->deviceID); | 1413 | printf("SRPC_SendEpInfo++ %x:%x:%x:%x\n", epInfoEx->epInfo->nwkAddr, epInfoEx->epInfo->endpoint, epInfoEx->epInfo->profileID, epInfoEx->epInfo->deviceID); |
1255 | 1414 | ||
1256 | //Send SRPC | 1415 | //Send SRPC |
1257 | srpcSendAll(pSrpcMessage); | 1416 | srpcSendAll(pSrpcMessage); |
1258 | free(pSrpcMessage); | 1417 | free(pSrpcMessage); |
1259 | |||
1260 | printf("RSPC_SendEpInfo--\n"); | 1418 | printf("RSPC_SendEpInfo--\n"); |
1261 | 1419 | ||
1262 | return 0; | 1420 | return 0; |
@@ -1269,30 +1427,30 @@ uint8_t RSPC_SendEpInfo(epInfo_t *epInfo) | |||
1269 | * | 1427 | * |
1270 | * @return Status | 1428 | * @return Status |
1271 | ***************************************************************************************************/ | 1429 | ***************************************************************************************************/ |
1272 | void SRPC_ConnectCB( int clientFd ) | 1430 | void SRPC_ConnectCB(int clientFd) |
1273 | { | 1431 | { |
1274 | //printf("SRPC_ConnectCB++ \n"); | 1432 | //printf("SRPC_ConnectCB++ \n"); |
1275 | /* | 1433 | /* |
1276 | epInfo = devListGetNextDev(0xFFFF, 0); | 1434 | epInfo = devListGetNextDev(0xFFFF, 0); |
1277 | 1435 | ||
1278 | while(epInfo) | 1436 | while(epInfo) |
1279 | { | 1437 | { |
1280 | printf("SRPC_ConnectCB: send epInfo\n"); | 1438 | printf("SRPC_ConnectCB: send epInfo\n"); |
1281 | //Send device Annce | 1439 | //Send device Annce |
1282 | uint8_t *pSrpcMessage = srpcParseEpInfo(epInfo); | 1440 | uint8_t *pSrpcMessage = srpcParseEpInfo(epInfo); |
1283 | //Send SRPC | 1441 | //Send SRPC |
1284 | srpcSend(pSrpcMessage, clientFd); | 1442 | srpcSend(pSrpcMessage, clientFd); |
1285 | free(pSrpcMessage); | 1443 | free(pSrpcMessage); |
1286 | 1444 | ||
1287 | usleep(1000); | 1445 | usleep(1000); |
1288 | 1446 | ||
1289 | //get next device (NULL if all done) | 1447 | //get next device (NULL if all done) |
1290 | epInfo = devListGetNextDev(epInfo->nwkAddr, epInfo->endpoint); | 1448 | epInfo = devListGetNextDev(epInfo->nwkAddr, epInfo->endpoint); |
1291 | } | 1449 | } |
1292 | */ | 1450 | */ |
1293 | //printf("SRPC_ConnectCB--\n"); | 1451 | //printf("SRPC_ConnectCB--\n"); |
1294 | } | 1452 | } |
1295 | 1453 | ||
1296 | /*************************************************************************************************** | 1454 | /*************************************************************************************************** |
1297 | * @fn SRPC_RxCB | 1455 | * @fn SRPC_RxCB |
1298 | * | 1456 | * |
@@ -1300,45 +1458,44 @@ void SRPC_ConnectCB( int clientFd ) | |||
1300 | * | 1458 | * |
1301 | * @return Status | 1459 | * @return Status |
1302 | ***************************************************************************************************/ | 1460 | ***************************************************************************************************/ |
1303 | void SRPC_RxCB( int clientFd ) | 1461 | void SRPC_RxCB(int clientFd) |
1304 | { | 1462 | { |
1305 | char buffer[256]; | 1463 | char buffer[256]; |
1306 | int byteToRead; | 1464 | int byteToRead; |
1307 | int byteRead; | 1465 | int byteRead; |
1308 | int rtn; | 1466 | int rtn; |
1309 | 1467 | ||
1310 | //printf("SRPC_RxCB++[%x]\n", clientFd); | 1468 | //printf("SRPC_RxCB++[%x]\n", clientFd); |
1311 | 1469 | ||
1312 | rtn = ioctl(clientFd, FIONREAD, &byteToRead); | 1470 | rtn = ioctl(clientFd, FIONREAD, &byteToRead); |
1313 | 1471 | ||
1314 | if(rtn !=0) | 1472 | if (rtn != 0) |
1315 | { | 1473 | { |
1316 | printf("SRPC_RxCB: Socket error\n"); | 1474 | printf("SRPC_RxCB: Socket error\n"); |
1317 | } | 1475 | } |
1318 | 1476 | ||
1319 | while(byteToRead) | 1477 | while (byteToRead) |
1320 | { | 1478 | { |
1321 | bzero(buffer,256); | 1479 | bzero(buffer, 256); |
1322 | byteRead = 0; | 1480 | byteRead = 0; |
1323 | //Get the CMD-ID and Len | 1481 | //Get the CMD-ID and Len |
1324 | byteRead += read(clientFd,buffer,2); | 1482 | byteRead += read(clientFd, buffer, 2); |
1325 | //Get the rest of the message | 1483 | //Get the rest of the message |
1326 | //printf("SRPC: reading %x byte message\n",buffer[SRPC_MSG_LEN]); | 1484 | //printf("SRPC: reading %x byte message\n",buffer[SRPC_MSG_LEN]); |
1327 | byteRead += read(clientFd,&buffer[2],buffer[SRPC_MSG_LEN]); | 1485 | byteRead += read(clientFd, &buffer[2], buffer[SRPC_MSG_LEN]); |
1328 | byteToRead -= byteRead; | 1486 | byteToRead -= byteRead; |
1329 | if (byteRead < 0) error("SRPC ERROR: error reading from socket\n"); | 1487 | if (byteRead < 0) error("SRPC ERROR: error reading from socket\n"); |
1330 | if (byteRead < buffer[SRPC_MSG_LEN]) error("SRPC ERROR: full message not read\n"); | 1488 | if (byteRead < buffer[SRPC_MSG_LEN]) |
1331 | //printf("Read the message[%x]\n",byteRead); | 1489 | error("SRPC ERROR: full message not read\n"); |
1332 | RPSC_ProcessIncoming((uint8_t*)buffer, clientFd); | 1490 | //printf("Read the message[%x]\n",byteRead); |
1333 | } | 1491 | SRPC_ProcessIncoming((uint8_t*) buffer, clientFd); |
1334 | 1492 | } | |
1335 | //printf("SRPC_RxCB--\n"); | 1493 | |
1336 | 1494 | //printf("SRPC_RxCB--\n"); | |
1337 | return; | 1495 | |
1496 | return; | ||
1338 | } | 1497 | } |
1339 | 1498 | ||
1340 | |||
1341 | |||
1342 | /*************************************************************************************************** | 1499 | /*************************************************************************************************** |
1343 | * @fn Closes the TCP port | 1500 | * @fn Closes the TCP port |
1344 | * | 1501 | * |
@@ -1348,6 +1505,6 @@ void SRPC_RxCB( int clientFd ) | |||
1348 | ***************************************************************************************************/ | 1505 | ***************************************************************************************************/ |
1349 | void SRPC_Close(void) | 1506 | void SRPC_Close(void) |
1350 | { | 1507 | { |
1351 | socketSeverClose(); | 1508 | socketSeverClose(); |
1352 | } | 1509 | } |
1353 | 1510 | ||
diff --git a/server/Source/interface_srpcserver.h b/server/Source/interface_srpcserver.h index e32c55c..797a827 100644..100755 --- a/server/Source/interface_srpcserver.h +++ b/server/Source/interface_srpcserver.h | |||
@@ -35,59 +35,64 @@ | |||
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
36 | * | 36 | * |
37 | */ | 37 | */ |
38 | 38 | ||
39 | #ifndef ZCL_INTERFACE_SERVER_H | 39 | #ifndef ZCL_INTERFACE_SERVER_H |
40 | #define ZCL_INTERFACE_SERVER_H | 40 | #define ZCL_INTERFACE_SERVER_H |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" | 43 | extern "C" { |
44 | { | ||
45 | #endif | 44 | #endif |
46 | 45 | ||
47 | #include <stdint.h> | 46 | #include <stdint.h> |
48 | #include "zllSocCmd.h" | 47 | #include "zbSocCmd.h" |
49 | #include "interface_devicelist.h" | 48 | #include "interface_devicelist.h" |
50 | 49 | ||
51 | //define the outgoing RPSC command ID's | 50 | //define the outgoing RPSC command ID's |
52 | #define RPCS_NEW_ZLL_DEVICE 0x0001 | 51 | #define SRPC_NEW_DEVICE 0x0001 |
53 | #define RPCS_DEV_ANNCE 0x0002 | 52 | #define SRPC_RESERVED_1 0x0002 |
54 | #define RPCS_SIMPLE_DESC 0x0003 | 53 | #define SRPC_RESERVED_2 0x0003 |
55 | #define RPCS_TEMP_READING 0x0004 | 54 | #define SRPC_RESERVED_3 0x0004 |
56 | #define RPCS_POWER_READING 0x0005 | 55 | #define SRPC_RESERVED_4 0x0005 |
57 | #define RPCS_PING 0x0006 | 56 | #define SRPC_RESERVED_5 0x0006 |
58 | #define RPCS_GET_DEV_STATE_RSP 0x0007 | 57 | #define SRPC_GET_DEV_STATE_RSP 0x0007 |
59 | #define RPCS_GET_DEV_LEVEL_RSP 0x0008 | 58 | #define SRPC_GET_DEV_LEVEL_RSP 0x0008 |
60 | #define RPCS_GET_DEV_HUE_RSP 0x0009 | 59 | #define SRPC_GET_DEV_HUE_RSP 0x0009 |
61 | #define RPCS_GET_DEV_SAT_RSP 0x000a | 60 | #define SRPC_GET_DEV_SAT_RSP 0x000a |
62 | #define RPCS_ADD_GROUP_RSP 0x000b | 61 | #define SRPC_ADD_GROUP_RSP 0x000b |
63 | #define RPCS_GET_GROUP_RSP 0x000c | 62 | #define SRPC_GET_GROUP_RSP 0x000c |
64 | #define RPCS_ADD_SCENE_RSP 0x000d | 63 | #define SRPC_ADD_SCENE_RSP 0x000d |
65 | #define RPCS_GET_SCENE_RSP 0x000e | 64 | #define SRPC_GET_SCENE_RSP 0x000e |
66 | |||
67 | 65 | ||
68 | //define incoming RPCS command ID's | 66 | //define incoming SRPC command ID's |
69 | #define RPCS_CLOSE 0x80; | 67 | #define SRPC_CLOSE 0x80; |
70 | #define RPCS_GET_DEVICES 0x81; | 68 | #define SRPC_GET_DEVICES 0x81; |
71 | #define RPCS_SET_DEV_STATE 0x82; | 69 | #define SRPC_SET_DEV_STATE 0x82; |
72 | #define RPCS_SET_DEV_LEVEL 0x83; | 70 | #define SRPC_SET_DEV_LEVEL 0x83; |
73 | #define RPCS_SET_DEV_COLOR 0x84; | 71 | #define SRPC_SET_DEV_COLOR 0x84; |
74 | #define RPCS_GET_DEV_STATE 0x85; | 72 | #define SRPC_GET_DEV_STATE 0x85; |
75 | #define RPCS_GET_DEV_LEVEL 0x86; | 73 | #define SRPC_GET_DEV_LEVEL 0x86; |
76 | #define RPCS_GET_DEV_HUE 0x87; | 74 | #define SRPC_GET_DEV_HUE 0x87; |
77 | #define RPCS_GET_DEV_SAT 0x88; | 75 | #define SRPC_GET_DEV_SAT 0x88; |
78 | #define RPCS_BIND_DEVICES 0x89; | 76 | #define SRPC_BIND_DEVICES 0x89; |
79 | #define RPCS_GET_THERM_READING 0x8a; | 77 | #define SRPC_RESERVED_6 0x8a; |
80 | #define RPCS_GET_POWER_READING 0x8b; | 78 | #define SRPC_RESERVED_7 0x8b; |
81 | #define RPCS_DISCOVER_DEVICES 0x8c; | 79 | #define SRPC_RESERVED_8 0x8c; |
82 | #define RPCS_SEND_ZCL 0x8d; | 80 | #define SRPC_RESERVED_9 0x8d; |
83 | #define RPCS_GET_GROUPS 0x8e; | 81 | #define SRPC_GET_GROUPS 0x8e; |
84 | #define RPCS_ADD_GROUP 0x8f; | 82 | #define SRPC_ADD_GROUP 0x8f; |
85 | #define RPCS_GET_SCENES 0x90; | 83 | #define SRPC_GET_SCENES 0x90; |
86 | #define RPCS_STORE_SCENE 0x91; | 84 | #define SRPC_STORE_SCENE 0x91; |
87 | #define RPCS_RECALL_SCENE 0x92; | 85 | #define SRPC_RECALL_SCENE 0x92; |
88 | #define RPCS_IDENTIFY_DEVICE 0x93; | 86 | #define SRPC_IDENTIFY_DEVICE 0x93; |
89 | #define RPCS_CHANGE_DEVICE_NAME 0x94; | 87 | #define SRPC_CHANGE_DEVICE_NAME 0x94; |
90 | #define RPCS_REMOVE_DEVICE 0x95; | 88 | #define SRPC_REMOVE_DEVICE 0x95; |
89 | #define SRPC_RESERVED_10 0x96; | ||
90 | #define SRPC_RESERVED_11 0x97; | ||
91 | #define SRPC_RESERVED_12 0x98; | ||
92 | #define SRPC_RESERVED_13 0x99; | ||
93 | #define SRPC_RESERVED_14 0x9a; | ||
94 | #define SRPC_RESERVED_15 0x9b; | ||
95 | #define SRPC_PERMIT_JOIN 0x9c; | ||
91 | 96 | ||
92 | #define SRPC_FUNC_ID 0 | 97 | #define SRPC_FUNC_ID 0 |
93 | #define SRPC_MSG_LEN 1 | 98 | #define SRPC_MSG_LEN 1 |
@@ -95,32 +100,39 @@ extern "C" | |||
95 | #define SRPC_TCP_PORT 0x2be3 | 100 | #define SRPC_TCP_PORT 0x2be3 |
96 | 101 | ||
97 | #define CLOSE_AUTH_NUM 0x2536 | 102 | #define CLOSE_AUTH_NUM 0x2536 |
103 | #define JOIN_AUTH_NUM 0xebd4 | ||
104 | |||
105 | #define Z_EXTADDR_LEN 8 | ||
106 | |||
107 | #define MT_NEW_DEVICE_FLAGS_NONE 0x00 | ||
108 | #define MT_NEW_DEVICE_FLAGS_FIRST 0x01 | ||
109 | #define MT_NEW_DEVICE_FLAGS_LAST 0x02 | ||
98 | 110 | ||
99 | typedef struct | 111 | typedef struct |
100 | { | 112 | { |
101 | union | 113 | union |
102 | { | 114 | { |
103 | uint16_t shortAddr; | 115 | uint16_t shortAddr; |
104 | uint8_t extAddr[Z_EXTADDR_LEN]; | 116 | uint8_t extAddr[Z_EXTADDR_LEN]; |
105 | } addr; | 117 | }addr; |
106 | afAddrMode_t addrMode; | 118 | afAddrMode_t addrMode; |
107 | uint8_t endPoint; | 119 | uint8_t endPoint; |
108 | uint16_t panId; // used for the INTER_PAN feature | 120 | uint16_t panId; // used for the INTER_PAN feature |
109 | } afAddrType_t; | 121 | }afAddrType_t; |
110 | 122 | ||
111 | //RPSC ZLL Interface functions | 123 | //RPSC ZLL Interface functions |
112 | void SRPC_Init(void); | 124 | void SRPC_Init(void); |
113 | uint8_t RSPC_SendEpInfo(epInfo_t *epInfo); | 125 | uint8_t SRPC_SendEpInfo(epInfoExtended_t *epInfoEx); |
114 | 126 | ||
115 | void RPCS_ZLL_CallBack_getStateRsp(uint8_t state, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 127 | void SRPC_CallBack_getStateRsp(uint8_t state, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
116 | void RPCS_ZLL_CallBack_getLevelRsp(uint8_t level, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 128 | void SRPC_CallBack_getLevelRsp(uint8_t level, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
117 | void RPCS_ZLL_CallBack_getHueRsp(uint8_t hue, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 129 | void SRPC_CallBack_getHueRsp(uint8_t hue, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
118 | void RPCS_ZLL_CallBack_getSatRsp(uint8_t sat, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 130 | void SRPC_CallBack_getSatRsp(uint8_t sat, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
119 | void RPCS_ZLL_CallBack_getTempRsp(uint16_t temp, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 131 | void SRPC_CallBack_getTempRsp(uint16_t temp, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
120 | void RPCS_ZLL_CallBack_getPowerRsp(uint32_t power, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); | 132 | void SRPC_CallBack_getPowerRsp(uint32_t power, uint16_t srcAddr, uint8_t endpoint, uint32_t clientFd); |
121 | 133 | ||
122 | #ifdef __cplusplus | 134 | #ifdef __cplusplus |
123 | } | 135 | } |
124 | #endif | 136 | #endif |
125 | 137 | ||
126 | #endif //ZCL_INTERFACE_SERVER_H \ No newline at end of file | 138 | #endif //ZCL_INTERFACE_SERVER_H |
diff --git a/server/Source/socket_server.c b/server/Source/socket_server.c index 8a59304..b8372e2 100644..100755 --- a/server/Source/socket_server.c +++ b/server/Source/socket_server.c | |||
@@ -60,16 +60,15 @@ | |||
60 | /********************************************************************* | 60 | /********************************************************************* |
61 | * GLOBAL VARIABLES | 61 | * GLOBAL VARIABLES |
62 | */ | 62 | */ |
63 | 63 | ||
64 | /********************************************************************* | 64 | /********************************************************************* |
65 | * TYPEDEFS | 65 | * TYPEDEFS |
66 | */ | 66 | */ |
67 | typedef struct | 67 | typedef struct { |
68 | { | 68 | void *next; |
69 | void *next; | 69 | int socketFd; |
70 | int socketFd; | 70 | socklen_t clilen; |
71 | socklen_t clilen; | 71 | struct sockaddr_in cli_addr; |
72 | struct sockaddr_in cli_addr; | ||
73 | } socketRecord_t; | 72 | } socketRecord_t; |
74 | 73 | ||
75 | socketRecord_t *socketRecordHead = NULL; | 74 | socketRecord_t *socketRecordHead = NULL; |
@@ -79,9 +78,9 @@ socketServerCb_t socketServerConnectCb; | |||
79 | 78 | ||
80 | /********************************************************************* | 79 | /********************************************************************* |
81 | * LOCAL FUNCTION PROTOTYPES | 80 | * LOCAL FUNCTION PROTOTYPES |
82 | */ | 81 | */ |
83 | static void deleteSocketRec( int rmSocketFd ); | 82 | static void deleteSocketRec(int rmSocketFd); |
84 | static int createSocketRec( void ); | 83 | static int createSocketRec(void); |
85 | 84 | ||
86 | /********************************************************************* | 85 | /********************************************************************* |
87 | * FUNCTIONS | 86 | * FUNCTIONS |
@@ -97,50 +96,46 @@ static int createSocketRec( void ); | |||
97 | * | 96 | * |
98 | * @return new clint fd | 97 | * @return new clint fd |
99 | */ | 98 | */ |
100 | int createSocketRec( void ) | 99 | int createSocketRec(void) |
101 | { | 100 | { |
102 | int tr=1; | 101 | int tr = 1; |
103 | socketRecord_t *srchRec; | 102 | socketRecord_t *srchRec; |
104 | 103 | ||
105 | socketRecord_t *newSocket = malloc( sizeof( socketRecord_t ) ); | 104 | socketRecord_t *newSocket = malloc(sizeof(socketRecord_t)); |
106 | 105 | ||
107 | //open a new client connection with the listening socket (at head of list) | 106 | //open a new client connection with the listening socket (at head of list) |
108 | newSocket->clilen = sizeof(newSocket->cli_addr); | 107 | newSocket->clilen = sizeof(newSocket->cli_addr); |
109 | 108 | ||
110 | //Head is always the listening socket | 109 | //Head is always the listening socket |
111 | newSocket->socketFd = accept(socketRecordHead->socketFd, | 110 | newSocket->socketFd = accept(socketRecordHead->socketFd, |
112 | (struct sockaddr *) &(newSocket->cli_addr), | 111 | (struct sockaddr *) &(newSocket->cli_addr), &(newSocket->clilen)); |
113 | &(newSocket->clilen)); | ||
114 | |||
115 | //printf("connected\n"); | ||
116 | |||
117 | if (newSocket->socketFd < 0) | ||
118 | printf("ERROR on accept"); | ||
119 | |||
120 | // Set the socket option SO_REUSEADDR to reduce the chance of a | ||
121 | // "Address Already in Use" error on the bind | ||
122 | setsockopt(newSocket->socketFd,SOL_SOCKET,SO_REUSEADDR,&tr,sizeof(int)); | ||
123 | // Set the fd to none blocking | ||
124 | fcntl(newSocket->socketFd, F_SETFL, O_NONBLOCK); | ||
125 | |||
126 | //printf("New Client Connected fd:%d - IP:%s\n", newSocket->socketFd, inet_ntoa(newSocket->cli_addr.sin_addr)); | ||
127 | |||
128 | newSocket->next = NULL; | ||
129 | |||
130 | //find the end of the list and add the record | ||
131 | srchRec = socketRecordHead; | ||
132 | // Stop at the last record | ||
133 | while ( srchRec->next ) | ||
134 | srchRec = srchRec->next; | ||
135 | |||
136 | // Add to the list | ||
137 | srchRec->next = newSocket; | ||
138 | |||
139 | return(newSocket->socketFd); | ||
140 | } | ||
141 | 112 | ||
113 | //printf("connected\n"); | ||
114 | |||
115 | if (newSocket->socketFd < 0) printf("ERROR on accept"); | ||
116 | |||
117 | // Set the socket option SO_REUSEADDR to reduce the chance of a | ||
118 | // "Address Already in Use" error on the bind | ||
119 | setsockopt(newSocket->socketFd, SOL_SOCKET, SO_REUSEADDR, &tr, sizeof(int)); | ||
120 | // Set the fd to none blocking | ||
121 | fcntl(newSocket->socketFd, F_SETFL, O_NONBLOCK); | ||
122 | |||
123 | //printf("New Client Connected fd:%d - IP:%s\n", newSocket->socketFd, inet_ntoa(newSocket->cli_addr.sin_addr)); | ||
124 | |||
125 | newSocket->next = NULL; | ||
126 | |||
127 | //find the end of the list and add the record | ||
128 | srchRec = socketRecordHead; | ||
129 | // Stop at the last record | ||
130 | while (srchRec->next) | ||
131 | srchRec = srchRec->next; | ||
132 | |||
133 | // Add to the list | ||
134 | srchRec->next = newSocket; | ||
135 | |||
136 | return (newSocket->socketFd); | ||
137 | } | ||
142 | 138 | ||
143 | |||
144 | /********************************************************************* | 139 | /********************************************************************* |
145 | * @fn deleteSocketRec | 140 | * @fn deleteSocketRec |
146 | * | 141 | * |
@@ -151,44 +146,45 @@ int createSocketRec( void ) | |||
151 | * | 146 | * |
152 | * @return none | 147 | * @return none |
153 | */ | 148 | */ |
154 | void deleteSocketRec( int rmSocketFd ) | 149 | void deleteSocketRec(int rmSocketFd) |
155 | { | 150 | { |
156 | socketRecord_t *srchRec, *prevRec=NULL; | 151 | socketRecord_t *srchRec, *prevRec = NULL; |
157 | 152 | ||
158 | // Head of the timer list | 153 | // Head of the timer list |
159 | srchRec = socketRecordHead; | 154 | srchRec = socketRecordHead; |
160 | 155 | ||
161 | // Stop when rec found or at the end | 156 | // Stop when rec found or at the end |
162 | while ( (srchRec->socketFd != rmSocketFd) && (srchRec->next) ) | 157 | while ((srchRec->socketFd != rmSocketFd) && (srchRec->next)) |
163 | { | 158 | { |
164 | prevRec = srchRec; | 159 | prevRec = srchRec; |
165 | // over to next | 160 | // over to next |
166 | srchRec = srchRec->next; | 161 | srchRec = srchRec->next; |
167 | } | 162 | } |
168 | 163 | ||
169 | if (srchRec->socketFd != rmSocketFd) | 164 | if (srchRec->socketFd != rmSocketFd) |
170 | { | 165 | { |
171 | printf("deleteSocketRec: record not found\n"); | 166 | printf("deleteSocketRec: record not found\n"); |
172 | return; | 167 | return; |
173 | } | 168 | } |
174 | 169 | ||
175 | // Does the record exist | 170 | // Does the record exist |
176 | if ( srchRec ) | 171 | if (srchRec) |
177 | { | 172 | { |
178 | // delete the timer from the list | 173 | // delete the timer from the list |
179 | if ( prevRec == NULL ) | 174 | if (prevRec == NULL) |
180 | { | 175 | { |
181 | //trying to remove first rec, which is always the listining socket | 176 | //trying to remove first rec, which is always the listining socket |
182 | printf("deleteSocketRec: removing first rec, which is always the listining socket\n"); | 177 | printf( |
183 | return; | 178 | "deleteSocketRec: removing first rec, which is always the listining socket\n"); |
184 | } | 179 | return; |
185 | 180 | } | |
186 | //remove record from list | 181 | |
187 | prevRec->next = srchRec->next; | 182 | //remove record from list |
188 | 183 | prevRec->next = srchRec->next; | |
189 | close(srchRec->socketFd); | 184 | |
190 | free(srchRec); | 185 | close(srchRec->socketFd); |
191 | } | 186 | free(srchRec); |
187 | } | ||
192 | } | 188 | } |
193 | 189 | ||
194 | /*************************************************************************************************** | 190 | /*************************************************************************************************** |
@@ -198,52 +194,52 @@ void deleteSocketRec( int rmSocketFd ) | |||
198 | * @param | 194 | * @param |
199 | * | 195 | * |
200 | * @return Status | 196 | * @return Status |
201 | */ | 197 | */ |
202 | int32 socketSeverInit( uint32 port ) | 198 | int32 socketSeverInit(uint32 port) |
203 | { | 199 | { |
204 | struct sockaddr_in serv_addr; | 200 | struct sockaddr_in serv_addr; |
205 | int stat, tr=1; | 201 | int stat, tr = 1; |
206 | 202 | ||
207 | if(socketRecordHead == NULL) | 203 | if (socketRecordHead == NULL) |
208 | { | 204 | { |
209 | // New record | 205 | // New record |
210 | socketRecord_t *lsSocket = malloc( sizeof( socketRecord_t ) ); | 206 | socketRecord_t *lsSocket = malloc(sizeof(socketRecord_t)); |
211 | 207 | ||
212 | lsSocket->socketFd = socket(AF_INET, SOCK_STREAM, 0); | 208 | lsSocket->socketFd = socket(AF_INET, SOCK_STREAM, 0); |
213 | if (lsSocket->socketFd < 0) | 209 | if (lsSocket->socketFd < 0) |
214 | { | 210 | { |
215 | printf("ERROR opening socket"); | 211 | printf("ERROR opening socket"); |
216 | return -1; | 212 | return -1; |
217 | } | 213 | } |
218 | 214 | ||
219 | // Set the socket option SO_REUSEADDR to reduce the chance of a | 215 | // Set the socket option SO_REUSEADDR to reduce the chance of a |
220 | // "Address Already in Use" error on the bind | 216 | // "Address Already in Use" error on the bind |
221 | setsockopt(lsSocket->socketFd,SOL_SOCKET,SO_REUSEADDR,&tr,sizeof(int)); | 217 | setsockopt(lsSocket->socketFd, SOL_SOCKET, SO_REUSEADDR, &tr, sizeof(int)); |
222 | // Set the fd to none blocking | 218 | // Set the fd to none blocking |
223 | fcntl(lsSocket->socketFd, F_SETFL, O_NONBLOCK); | 219 | fcntl(lsSocket->socketFd, F_SETFL, O_NONBLOCK); |
224 | 220 | ||
225 | bzero((char *) &serv_addr, sizeof(serv_addr)); | 221 | bzero((char *) &serv_addr, sizeof(serv_addr)); |
226 | serv_addr.sin_family = AF_INET; | 222 | serv_addr.sin_family = AF_INET; |
227 | serv_addr.sin_addr.s_addr = INADDR_ANY; | 223 | serv_addr.sin_addr.s_addr = INADDR_ANY; |
228 | serv_addr.sin_port = htons(port); | 224 | serv_addr.sin_port = htons(port); |
229 | stat = bind(lsSocket->socketFd, (struct sockaddr *) &serv_addr, | 225 | stat = bind(lsSocket->socketFd, (struct sockaddr *) &serv_addr, |
230 | sizeof(serv_addr)); | 226 | sizeof(serv_addr)); |
231 | if ( stat < 0) | 227 | if (stat < 0) |
232 | { | 228 | { |
233 | printf("ERROR on binding: %s\n", strerror( errno ) ); | 229 | printf("ERROR on binding: %s\n", strerror(errno)); |
234 | return -1; | 230 | return -1; |
235 | } | 231 | } |
236 | //will have 5 pending open client requests | 232 | //will have 5 pending open client requests |
237 | listen(lsSocket->socketFd,5); | 233 | listen(lsSocket->socketFd, 5); |
238 | 234 | ||
239 | lsSocket->next = NULL; | 235 | lsSocket->next = NULL; |
240 | //Head is always the listening socket | 236 | //Head is always the listening socket |
241 | socketRecordHead = lsSocket; | 237 | socketRecordHead = lsSocket; |
242 | } | 238 | } |
243 | 239 | ||
244 | //printf("waiting for socket new connection\n"); | 240 | //printf("waiting for socket new connection\n"); |
245 | 241 | ||
246 | return 0; | 242 | return 0; |
247 | } | 243 | } |
248 | 244 | ||
249 | /*************************************************************************************************** | 245 | /*************************************************************************************************** |
@@ -253,13 +249,13 @@ int32 socketSeverInit( uint32 port ) | |||
253 | * @param | 249 | * @param |
254 | * | 250 | * |
255 | * @return Status | 251 | * @return Status |
256 | */ | 252 | */ |
257 | int32 serverSocketConfig(socketServerCb_t rxCb, socketServerCb_t connectCb) | 253 | int32 serverSocketConfig(socketServerCb_t rxCb, socketServerCb_t connectCb) |
258 | { | 254 | { |
259 | socketServerRxCb = rxCb; | 255 | socketServerRxCb = rxCb; |
260 | socketServerConnectCb = connectCb; | 256 | socketServerConnectCb = connectCb; |
261 | 257 | ||
262 | return 0; | 258 | return 0; |
263 | } | 259 | } |
264 | /********************************************************************* | 260 | /********************************************************************* |
265 | * @fn socketSeverGetClientFds() | 261 | * @fn socketSeverGetClientFds() |
@@ -271,23 +267,23 @@ int32 serverSocketConfig(socketServerCb_t rxCb, socketServerCb_t connectCb) | |||
271 | * @return list of Timerfd's | 267 | * @return list of Timerfd's |
272 | */ | 268 | */ |
273 | void socketSeverGetClientFds(int *fds, int maxFds) | 269 | void socketSeverGetClientFds(int *fds, int maxFds) |
274 | { | 270 | { |
275 | uint32 recordCnt=0; | 271 | uint32 recordCnt = 0; |
276 | socketRecord_t *srchRec; | 272 | socketRecord_t *srchRec; |
277 | 273 | ||
278 | // Head of the timer list | 274 | // Head of the timer list |
279 | srchRec = socketRecordHead; | 275 | srchRec = socketRecordHead; |
280 | 276 | ||
281 | // Stop when at the end or max is reached | 277 | // Stop when at the end or max is reached |
282 | while ( (srchRec) && (recordCnt < maxFds) ) | 278 | while ((srchRec) && (recordCnt < maxFds)) |
283 | { | 279 | { |
284 | //printf("getClientFds: adding fd%d, to idx:%d \n", srchRec->socketFd, recordCnt); | 280 | //printf("getClientFds: adding fd%d, to idx:%d \n", srchRec->socketFd, recordCnt); |
285 | fds[recordCnt++] = srchRec->socketFd; | 281 | fds[recordCnt++] = srchRec->socketFd; |
286 | 282 | ||
287 | srchRec = srchRec->next; | 283 | srchRec = srchRec->next; |
288 | } | 284 | } |
289 | 285 | ||
290 | return; | 286 | return; |
291 | } | 287 | } |
292 | 288 | ||
293 | /********************************************************************* | 289 | /********************************************************************* |
@@ -300,31 +296,31 @@ void socketSeverGetClientFds(int *fds, int maxFds) | |||
300 | * @return list of Timerfd's | 296 | * @return list of Timerfd's |
301 | */ | 297 | */ |
302 | uint32 socketSeverGetNumClients(void) | 298 | uint32 socketSeverGetNumClients(void) |
303 | { | 299 | { |
304 | uint32 recordCnt=0; | 300 | uint32 recordCnt = 0; |
305 | socketRecord_t *srchRec; | 301 | socketRecord_t *srchRec; |
306 | 302 | ||
307 | //printf("socketSeverGetNumClients++\n", recordCnt); | 303 | //printf("socketSeverGetNumClients++\n", recordCnt); |
308 | 304 | ||
309 | // Head of the timer list | 305 | // Head of the timer list |
310 | srchRec = socketRecordHead; | 306 | srchRec = socketRecordHead; |
311 | 307 | ||
312 | if(srchRec==NULL) | 308 | if (srchRec == NULL) |
313 | { | 309 | { |
314 | //printf("socketSeverGetNumClients: socketRecordHead NULL\n"); | 310 | //printf("socketSeverGetNumClients: socketRecordHead NULL\n"); |
315 | return -1; | 311 | return -1; |
316 | } | 312 | } |
317 | 313 | ||
318 | // Stop when rec found or at the end | 314 | // Stop when rec found or at the end |
319 | while ( srchRec ) | 315 | while (srchRec) |
320 | { | 316 | { |
321 | //printf("socketSeverGetNumClients: recordCnt=%d\n", recordCnt); | 317 | //printf("socketSeverGetNumClients: recordCnt=%d\n", recordCnt); |
322 | srchRec = srchRec->next; | 318 | srchRec = srchRec->next; |
323 | recordCnt++; | 319 | recordCnt++; |
324 | } | 320 | } |
325 | 321 | ||
326 | //printf("socketSeverGetNumClients %d\n", recordCnt); | 322 | //printf("socketSeverGetNumClients %d\n", recordCnt); |
327 | return (recordCnt); | 323 | return (recordCnt); |
328 | } | 324 | } |
329 | 325 | ||
330 | /********************************************************************* | 326 | /********************************************************************* |
@@ -339,46 +335,45 @@ uint32 socketSeverGetNumClients(void) | |||
339 | */ | 335 | */ |
340 | void socketSeverPoll(int clinetFd, int revent) | 336 | void socketSeverPoll(int clinetFd, int revent) |
341 | { | 337 | { |
342 | //printf("pollSocket++\n"); | 338 | //printf("pollSocket++\n"); |
343 | 339 | ||
344 | //is this a new connection on the listening socket | 340 | //is this a new connection on the listening socket |
345 | if(clinetFd == socketRecordHead->socketFd) | 341 | if (clinetFd == socketRecordHead->socketFd) |
346 | { | 342 | { |
347 | int newClientFd = createSocketRec(); | 343 | int newClientFd = createSocketRec(); |
348 | 344 | ||
349 | if(socketServerConnectCb) | 345 | if (socketServerConnectCb) |
350 | { | 346 | { |
351 | socketServerConnectCb(newClientFd); | 347 | socketServerConnectCb(newClientFd); |
352 | } | 348 | } |
353 | } | 349 | } |
354 | else | 350 | else |
355 | { | 351 | { |
356 | //this is a client socket is it a input or shutdown event | 352 | //this is a client socket is it a input or shutdown event |
357 | if (revent & POLLIN) | 353 | if (revent & POLLIN) |
358 | { | 354 | { |
359 | uint32 pakcetCnt = 0; | 355 | //uint32 pakcetCnt = 0; |
360 | //its a Rx event | 356 | //its a Rx event |
361 | //printf("got Rx on fd %d, pakcetCnt=%d\n", clinetFd, pakcetCnt++); | 357 | //printf("got Rx on fd %d, pakcetCnt=%d\n", clinetFd, pakcetCnt++); |
362 | if(socketServerRxCb) | 358 | if (socketServerRxCb) |
363 | { | 359 | { |
364 | socketServerRxCb(clinetFd); | 360 | socketServerRxCb(clinetFd); |
365 | } | 361 | } |
366 | 362 | ||
367 | } | 363 | } |
368 | if (revent & POLLRDHUP) | 364 | if (revent & POLLRDHUP) |
369 | { | 365 | { |
370 | //its a shut down close the socket | 366 | //its a shut down close the socket |
371 | //printf("Client fd:%d disconnected\n", clinetFd); | 367 | //printf("Client fd:%d disconnected\n", clinetFd); |
372 | 368 | ||
373 | //remove the record and close the socket | 369 | //remove the record and close the socket |
374 | deleteSocketRec(clinetFd); | 370 | deleteSocketRec(clinetFd); |
375 | } | 371 | } |
376 | } | 372 | } |
377 | 373 | ||
378 | 374 | //write(clientSockFd,"I got your message",18); | |
379 | //write(clientSockFd,"I got your message",18); | 375 | |
380 | 376 | return; | |
381 | return; | ||
382 | } | 377 | } |
383 | 378 | ||
384 | /*************************************************************************************************** | 379 | /*************************************************************************************************** |
@@ -391,26 +386,25 @@ void socketSeverPoll(int clinetFd, int revent) | |||
391 | * @return Status | 386 | * @return Status |
392 | */ | 387 | */ |
393 | int32 socketSeverSend(uint8* buf, uint32 len, int32 fdClient) | 388 | int32 socketSeverSend(uint8* buf, uint32 len, int32 fdClient) |
394 | { | 389 | { |
395 | int32 rtn; | 390 | int32 rtn; |
396 | 391 | ||
397 | //printf("socketSeverSend++: writing to socket fd %d\n", fdClient); | 392 | //printf("socketSeverSend++: writing to socket fd %d\n", fdClient); |
398 | 393 | ||
399 | if(fdClient) | 394 | if (fdClient) |
400 | { | 395 | { |
401 | rtn = write(fdClient, buf, len); | 396 | rtn = write(fdClient, buf, len); |
402 | if (rtn < 0) | 397 | if (rtn < 0) |
403 | { | 398 | { |
404 | printf("ERROR writing to socket %d\n", fdClient); | 399 | printf("ERROR writing to socket %d\n", fdClient); |
405 | return rtn; | 400 | return rtn; |
406 | } | 401 | } |
407 | } | 402 | } |
408 | 403 | ||
409 | //printf("socketSeverSend--\n"); | 404 | //printf("socketSeverSend--\n"); |
410 | return 0; | 405 | return 0; |
411 | } | 406 | } |
412 | 407 | ||
413 | |||
414 | /*************************************************************************************************** | 408 | /*************************************************************************************************** |
415 | * @fn socketSeverSendAllclients | 409 | * @fn socketSeverSendAllclients |
416 | * | 410 | * |
@@ -420,31 +414,31 @@ int32 socketSeverSend(uint8* buf, uint32 len, int32 fdClient) | |||
420 | * @return Status | 414 | * @return Status |
421 | */ | 415 | */ |
422 | int32 socketSeverSendAllclients(uint8* buf, uint32 len) | 416 | int32 socketSeverSendAllclients(uint8* buf, uint32 len) |
423 | { | 417 | { |
424 | int rtn, cnt=0; | 418 | int rtn; |
425 | socketRecord_t *srchRec; | 419 | socketRecord_t *srchRec; |
426 | 420 | ||
427 | // first client socket | 421 | // first client socket |
428 | srchRec = socketRecordHead->next; | 422 | srchRec = socketRecordHead->next; |
429 | 423 | ||
430 | // Stop when at the end or max is reached | 424 | // Stop when at the end or max is reached |
431 | while ( srchRec ) | 425 | while (srchRec) |
432 | { | 426 | { |
433 | //printf("SRPC_Send: client %d\n", cnt++); | 427 | //printf("SRPC_Send: client %d\n", cnt++); |
434 | rtn = write(srchRec->socketFd, buf, len); | 428 | rtn = write(srchRec->socketFd, buf, len); |
435 | if (rtn < 0) | 429 | if (rtn < 0) |
436 | { | 430 | { |
437 | printf("ERROR writing to socket %d\n", srchRec->socketFd); | 431 | printf("ERROR writing to socket %d\n", srchRec->socketFd); |
438 | printf("closing client socket\n"); | 432 | printf("closing client socket\n"); |
439 | //remove the record and close the socket | 433 | //remove the record and close the socket |
440 | deleteSocketRec(srchRec->socketFd); | 434 | deleteSocketRec(srchRec->socketFd); |
441 | 435 | ||
442 | return rtn; | 436 | return rtn; |
443 | } | 437 | } |
444 | srchRec = srchRec->next; | 438 | srchRec = srchRec->next; |
445 | } | 439 | } |
446 | 440 | ||
447 | return 0; | 441 | return 0; |
448 | } | 442 | } |
449 | 443 | ||
450 | /*************************************************************************************************** | 444 | /*************************************************************************************************** |
@@ -456,21 +450,21 @@ int32 socketSeverSendAllclients(uint8* buf, uint32 len) | |||
456 | */ | 450 | */ |
457 | void socketSeverClose(void) | 451 | void socketSeverClose(void) |
458 | { | 452 | { |
459 | int fds[MAX_CLIENTS], idx=0; | 453 | int fds[MAX_CLIENTS], idx = 0; |
460 | 454 | ||
461 | socketSeverGetClientFds(fds, MAX_CLIENTS); | 455 | socketSeverGetClientFds(fds, MAX_CLIENTS); |
462 | 456 | ||
463 | while(socketSeverGetNumClients() > 1) | 457 | while (socketSeverGetNumClients() > 1) |
464 | { | 458 | { |
465 | printf("socketSeverClose: Closing socket fd:%d\n", fds[idx]); | 459 | printf("socketSeverClose: Closing socket fd:%d\n", fds[idx]); |
466 | deleteSocketRec( fds[idx++] ); | 460 | deleteSocketRec(fds[idx++]); |
467 | } | 461 | } |
468 | 462 | ||
469 | //Now remove the listening socket | 463 | //Now remove the listening socket |
470 | if(fds[0]) | 464 | if (fds[0]) |
471 | { | 465 | { |
472 | printf("socketSeverClose: Closing the listening socket\n"); | 466 | printf("socketSeverClose: Closing the listening socket\n"); |
473 | close(fds[0]); | 467 | close(fds[0]); |
474 | } | 468 | } |
475 | } | 469 | } |
476 | 470 | ||
diff --git a/server/Source/socket_server.h b/server/Source/socket_server.h index 3336caa..2884b6c 100644..100755 --- a/server/Source/socket_server.h +++ b/server/Source/socket_server.h | |||
@@ -34,21 +34,20 @@ | |||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | #ifndef SOCKET_SERVER_H | 38 | #ifndef SOCKET_SERVER_H |
39 | #define SOCKET_SERVER_H | 39 | #define SOCKET_SERVER_H |
40 | 40 | ||
41 | #ifdef __cplusplus | 41 | #ifdef __cplusplus |
42 | extern "C" | 42 | extern "C" { |
43 | { | ||
44 | #endif | 43 | #endif |
45 | 44 | ||
46 | /********************************************************************* | 45 | /********************************************************************* |
47 | * TYPEDEFS | 46 | * TYPEDEFS |
48 | */ | 47 | */ |
49 | 48 | ||
50 | typedef void (*socketServerCb_t)( int clientFd ); | 49 | typedef void (*socketServerCb_t)(int clientFd); |
51 | 50 | ||
52 | /********************************************************************* | 51 | /********************************************************************* |
53 | * INCLUDES | 52 | * INCLUDES |
54 | */ | 53 | */ |
@@ -62,12 +61,12 @@ typedef void (*socketServerCb_t)( int clientFd ); | |||
62 | 61 | ||
63 | /* | 62 | /* |
64 | * serverSocketInit - initialises the server. | 63 | * serverSocketInit - initialises the server. |
65 | */ | 64 | */ |
66 | int32 socketSeverInit( uint32 port ); | 65 | int32 socketSeverInit(uint32 port); |
67 | 66 | ||
68 | /* | 67 | /* |
69 | * serverSocketConfig - initialises the server. | 68 | * serverSocketConfig - initialises the server. |
70 | */ | 69 | */ |
71 | int32 serverSocketConfig(socketServerCb_t rxCb, socketServerCb_t connectCb); | 70 | int32 serverSocketConfig(socketServerCb_t rxCb, socketServerCb_t connectCb); |
72 | 71 | ||
73 | /* | 72 | /* |
@@ -95,15 +94,13 @@ int32 socketSeverSendAllclients(uint8* buf, uint32 len); | |||
95 | */ | 94 | */ |
96 | int32 socketSeverSend(uint8* buf, uint32 len, int32 fdClient); | 95 | int32 socketSeverSend(uint8* buf, uint32 len, int32 fdClient); |
97 | 96 | ||
98 | |||
99 | /* | 97 | /* |
100 | * socketSeverClose - Closes the client connections. | 98 | * socketSeverClose - Closes the client connections. |
101 | */ | 99 | */ |
102 | void socketSeverClose(void); | 100 | void socketSeverClose(void); |
103 | 101 | ||
104 | |||
105 | #ifdef __cplusplus | 102 | #ifdef __cplusplus |
106 | } | 103 | } |
107 | #endif | 104 | #endif |
108 | 105 | ||
109 | #endif /* SOCKET_SERVER_H */ \ No newline at end of file | 106 | #endif /* SOCKET_SERVER_H */ |
diff --git a/server/Source/zbController.c b/server/Source/zbController.c new file mode 100755 index 0000000..2b26c2e --- /dev/null +++ b/server/Source/zbController.c | |||
@@ -0,0 +1,302 @@ | |||
1 | /************************************************************************************************** | ||
2 | * Filename: zll_controller.c | ||
3 | * Description: This file contains the interface to the UART. | ||
4 | * | ||
5 | * | ||
6 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ | ||
7 | * | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
22 | * its contributors may be used to endorse or promote products derived | ||
23 | * from this software without specific prior written permission. | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
36 | * | ||
37 | */ | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <poll.h> | ||
43 | |||
44 | #include "zbSocCmd.h" | ||
45 | #include "interface_devicelist.h" | ||
46 | #include "interface_grouplist.h" | ||
47 | #include "interface_scenelist.h" | ||
48 | |||
49 | #define MAX_DB_FILENAMR_LEN 255 | ||
50 | |||
51 | uint8_t tlIndicationCb(epInfo_t *epInfo); | ||
52 | uint8_t newDevIndicationCb(epInfo_t *epInfo); | ||
53 | uint8_t zclGetStateCb(uint8_t state, uint16_t nwkAddr, uint8_t endpoint); | ||
54 | uint8_t zclGetLevelCb(uint8_t level, uint16_t nwkAddr, uint8_t endpoint); | ||
55 | uint8_t zclGetHueCb(uint8_t hue, uint16_t nwkAddr, uint8_t endpoint); | ||
56 | uint8_t zclGetSatCb(uint8_t sat, uint16_t nwkAddr, uint8_t endpoint); | ||
57 | uint8_t zdoSimpleDescRspCb(epInfo_t *epInfo); | ||
58 | uint8_t zdoLeaveIndCb(uint16_t nwkAddr); | ||
59 | |||
60 | static zbSocCallbacks_t zbSocCbs = | ||
61 | { tlIndicationCb, // pfnTlIndicationCb - TouchLink Indication callback | ||
62 | newDevIndicationCb, // pfnNewDevIndicationCb - New Device Indication callback | ||
63 | zclGetStateCb, //pfnZclGetStateCb - ZCL response callback for get State | ||
64 | zclGetLevelCb, //pfnZclGetLevelCb_t - ZCL response callback for get Level | ||
65 | zclGetHueCb, // pfnZclGetHueCb - ZCL response callback for get Hue | ||
66 | zclGetSatCb, //pfnZclGetSatCb - ZCL response callback for get Sat | ||
67 | zdoSimpleDescRspCb, //pfnzdoSimpleDescRspCb - ZDO simple desc rsp | ||
68 | zdoLeaveIndCb, // pfnZdoLeaveIndCb - ZDO Leave indication | ||
69 | NULL, | ||
70 | NULL | ||
71 | }; | ||
72 | |||
73 | #include "interface_srpcserver.h" | ||
74 | #include "socket_server.h" | ||
75 | |||
76 | void usage(char* exeName) | ||
77 | { | ||
78 | printf("Usage: ./%s <port>\n", exeName); | ||
79 | printf("Eample: ./%s /dev/ttyACM0\n", exeName); | ||
80 | } | ||
81 | |||
82 | int main(int argc, char* argv[]) | ||
83 | { | ||
84 | int retval = 0; | ||
85 | int zbSoc_fd; | ||
86 | char dbFilename[MAX_DB_FILENAMR_LEN]; | ||
87 | |||
88 | printf("%s -- %s %s\n", argv[0], __DATE__, __TIME__); | ||
89 | |||
90 | // accept only 1 | ||
91 | if (argc != 2) | ||
92 | { | ||
93 | usage(argv[0]); | ||
94 | printf("attempting to use /dev/ttyACM0\n"); | ||
95 | zbSoc_fd = zbSocOpen("/dev/ttyACM0"); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | zbSoc_fd = zbSocOpen(argv[1]); | ||
100 | } | ||
101 | |||
102 | if (zbSoc_fd == -1) | ||
103 | { | ||
104 | exit(-1); | ||
105 | } | ||
106 | |||
107 | //printf("zllMain: restoring device, group and scene lists\n"); | ||
108 | sprintf(dbFilename, "%.*s/devicelistfile.dat", | ||
109 | strrchr(argv[0], '/') - argv[0], argv[0]); | ||
110 | printf("zllMain: device DB file name %s\n", dbFilename); | ||
111 | devListInitDatabase(dbFilename); | ||
112 | |||
113 | sprintf(dbFilename, "%.*s/grouplistfile.dat", strrchr(argv[0], '/') - argv[0], | ||
114 | argv[0]); | ||
115 | printf("zllMain: group DB file name %s\n", dbFilename); | ||
116 | groupListInitDatabase(dbFilename); | ||
117 | |||
118 | sprintf(dbFilename, "%.*s/scenelistfile.dat", strrchr(argv[0], '/') - argv[0], | ||
119 | argv[0]); | ||
120 | printf("zllMain: scene DB file name %s\n", dbFilename); | ||
121 | sceneListInitDatabase(dbFilename); | ||
122 | |||
123 | zbSocRegisterCallbacks(zbSocCbs); | ||
124 | |||
125 | zbSocGetInfo(); | ||
126 | |||
127 | SRPC_Init(); | ||
128 | |||
129 | while (1) | ||
130 | { | ||
131 | int numClientFds = socketSeverGetNumClients(); | ||
132 | |||
133 | //poll on client socket fd's and the ZllSoC serial port for any activity | ||
134 | if (numClientFds) | ||
135 | { | ||
136 | int pollFdIdx; | ||
137 | int *client_fds = malloc(numClientFds * sizeof(int)); | ||
138 | //socket client FD's + zllSoC serial port FD | ||
139 | struct pollfd *pollFds = malloc( | ||
140 | ((numClientFds + 1) * sizeof(struct pollfd))); | ||
141 | |||
142 | if (client_fds && pollFds) | ||
143 | { | ||
144 | //set the zllSoC serial port FD in the poll file descriptors | ||
145 | pollFds[0].fd = zbSoc_fd; | ||
146 | pollFds[0].events = POLLIN; | ||
147 | |||
148 | //Set the socket file descriptors | ||
149 | socketSeverGetClientFds(client_fds, numClientFds); | ||
150 | for (pollFdIdx = 0; pollFdIdx < numClientFds; pollFdIdx++) | ||
151 | { | ||
152 | pollFds[pollFdIdx + 1].fd = client_fds[pollFdIdx]; | ||
153 | pollFds[pollFdIdx + 1].events = POLLIN | POLLRDHUP; | ||
154 | //printf("zllMain: adding fd %d to poll()\n", pollFds[pollFdIdx].fd); | ||
155 | } | ||
156 | |||
157 | printf("zllMain: waiting for poll()\n"); | ||
158 | |||
159 | poll(pollFds, (numClientFds + 1), -1); | ||
160 | |||
161 | //printf("zllMain: got poll()\n"); | ||
162 | |||
163 | //did the poll unblock because of the zllSoC serial? | ||
164 | if (pollFds[0].revents) | ||
165 | { | ||
166 | printf("Message from ZLL SoC\n"); | ||
167 | zbSocProcessRpc(); | ||
168 | } | ||
169 | //did the poll unblock because of activity on the socket interface? | ||
170 | for (pollFdIdx = 1; pollFdIdx < (numClientFds + 1); pollFdIdx++) | ||
171 | { | ||
172 | if ((pollFds[pollFdIdx].revents)) | ||
173 | { | ||
174 | printf("Message from Socket Sever\n"); | ||
175 | socketSeverPoll(pollFds[pollFdIdx].fd, pollFds[pollFdIdx].revents); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | free(client_fds); | ||
180 | free(pollFds); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | return retval; | ||
186 | } | ||
187 | |||
188 | uint8_t tlIndicationCb(epInfo_t *epInfo) | ||
189 | { | ||
190 | epInfoExtended_t epInfoEx; | ||
191 | |||
192 | epInfoEx.epInfo = epInfo; | ||
193 | epInfoEx.type = EP_INFO_TYPE_NEW; | ||
194 | |||
195 | devListAddDevice(epInfo); | ||
196 | SRPC_SendEpInfo(&epInfoEx); | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | uint8_t newDevIndicationCb(epInfo_t *epInfo) | ||
202 | { | ||
203 | //Just add to device list to store | ||
204 | devListAddDevice(epInfo); | ||
205 | |||
206 | return 0; | ||
207 | } | ||
208 | |||
209 | uint8_t zdoSimpleDescRspCb(epInfo_t *epInfo) | ||
210 | { | ||
211 | epInfo_t *ieeeEpInfo; | ||
212 | epInfo_t* oldRec; | ||
213 | epInfoExtended_t epInfoEx; | ||
214 | |||
215 | printf("zdoSimpleDescRspCb: NwkAddr:0x%04x\n End:0x%02x ", epInfo->nwkAddr, | ||
216 | epInfo->endpoint); | ||
217 | |||
218 | //find the IEEE address. Any ep (0xFF), if the is the first simpleDesc for this nwkAddr | ||
219 | //then devAnnce will enter a dummy entry with ep=0, other wise get IEEE from a previous EP | ||
220 | ieeeEpInfo = devListGetDeviceByNaEp(epInfo->nwkAddr, 0xFF); | ||
221 | memcpy(epInfo->IEEEAddr, ieeeEpInfo->IEEEAddr, Z_EXTADDR_LEN); | ||
222 | |||
223 | //remove dummy ep, the devAnnce will enter a dummy entry with ep=0, | ||
224 | //this is only used for storing the IEEE address until the first real EP | ||
225 | //is enter. | ||
226 | devListRemoveDeviceByNaEp(epInfo->nwkAddr, 0x00); | ||
227 | |||
228 | //is this a new device or an update | ||
229 | oldRec = devListGetDeviceByIeeeEp(epInfo->IEEEAddr, epInfo->endpoint); | ||
230 | |||
231 | if (oldRec != NULL) | ||
232 | { | ||
233 | if (epInfo->nwkAddr != oldRec->nwkAddr) | ||
234 | { | ||
235 | epInfoEx.type = EP_INFO_TYPE_UPDATED; | ||
236 | epInfoEx.prevNwkAddr = oldRec->nwkAddr; | ||
237 | devListRemoveDeviceByNaEp(oldRec->nwkAddr, oldRec->endpoint); //theoretically, update the database record in place is possible, but this other approach is selected to provide change logging. Records that are marked as deleted soes not have to be phisically deleted (e.g. by avoiding consilidation) and thus the database can be used as connection log | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | //not checking if any of the records has changed. assuming that for a given device (ieee_addr+endpoint_number) nothing will change except the network address. | ||
242 | epInfoEx.type = EP_INFO_TYPE_EXISTING; | ||
243 | } | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | epInfoEx.type = EP_INFO_TYPE_NEW; | ||
248 | } | ||
249 | |||
250 | printf("zdoSimpleDescRspCb: NwkAddr:0x%04x Ep:0x%02x Type:0x%02x ", epInfo->nwkAddr, | ||
251 | epInfo->endpoint, epInfoEx.type); | ||
252 | |||
253 | if (epInfoEx.type != EP_INFO_TYPE_EXISTING) | ||
254 | { | ||
255 | devListAddDevice(epInfo); | ||
256 | epInfoEx.epInfo = epInfo; | ||
257 | SRPC_SendEpInfo(&epInfoEx); | ||
258 | } | ||
259 | |||
260 | return 0; | ||
261 | } | ||
262 | |||
263 | uint8_t zdoLeaveIndCb(uint16_t nwkAddr) | ||
264 | { | ||
265 | epInfoExtended_t removeEpInfoEx; | ||
266 | |||
267 | removeEpInfoEx.epInfo = devListRemoveDeviceByNaEp(nwkAddr, 0xFF); | ||
268 | |||
269 | while(removeEpInfoEx.epInfo) | ||
270 | { | ||
271 | removeEpInfoEx.type = EP_INFO_TYPE_REMOVED; | ||
272 | SRPC_SendEpInfo(&removeEpInfoEx); | ||
273 | removeEpInfoEx.epInfo = devListRemoveDeviceByNaEp(nwkAddr, 0xFF); | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | uint8_t zclGetStateCb(uint8_t state, uint16_t nwkAddr, uint8_t endpoint) | ||
280 | { | ||
281 | SRPC_CallBack_getStateRsp(state, nwkAddr, endpoint, 0); | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | uint8_t zclGetLevelCb(uint8_t level, uint16_t nwkAddr, uint8_t endpoint) | ||
286 | { | ||
287 | SRPC_CallBack_getLevelRsp(level, nwkAddr, endpoint, 0); | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | uint8_t zclGetHueCb(uint8_t hue, uint16_t nwkAddr, uint8_t endpoint) | ||
292 | { | ||
293 | SRPC_CallBack_getHueRsp(hue, nwkAddr, endpoint, 0); | ||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | uint8_t zclGetSatCb(uint8_t sat, uint16_t nwkAddr, uint8_t endpoint) | ||
298 | { | ||
299 | SRPC_CallBack_getSatRsp(sat, nwkAddr, endpoint, 0); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
diff --git a/server/i486-linux-gnu/Makefile b/server/i486-linux-gnu/Makefile index 1d79e61..4f7b966 100644..100755 --- a/server/i486-linux-gnu/Makefile +++ b/server/i486-linux-gnu/Makefile | |||
@@ -1,13 +1,12 @@ | |||
1 | 1 | ||
2 | SBU_REV= "0.1" | 2 | SBU_REV= "0.1" |
3 | 3 | ||
4 | #GCC = gcc | 4 | GCC = gcc |
5 | GCC=/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc | ||
6 | 5 | ||
7 | CFLAGS = -Wall -DVERSION_NUMBER=${SBU_REV} | 6 | CFLAGS = -Wall -DVERSION_NUMBER=${SBU_REV} |
8 | OBJECTS = zll_controller.o zllSocCmd.o interface_devicelist.o interface_grouplist.o interface_scenelist.o interface_srpcserver.o socket_server.o | 7 | OBJECTS = zbController.o ../../zbSocDriver/zbSocCmd.o interface_devicelist.o interface_grouplist.o interface_scenelist.o interface_srpcserver.o socket_server.o SimpleDB.o SimpleDBTxt.o |
9 | |||
10 | DEFS += -D_GNU_SOURCE | 8 | DEFS += -D_GNU_SOURCE |
9 | INCLUDE = -I../../zbSocDriver/ | ||
11 | 10 | ||
12 | APP_NAME=zllGateway.bin | 11 | APP_NAME=zllGateway.bin |
13 | 12 | ||
@@ -23,3 +22,4 @@ all: ${APP_NAME} | |||
23 | 22 | ||
24 | clean: | 23 | clean: |
25 | rm -rf *.o ${APP_NAME} | 24 | rm -rf *.o ${APP_NAME} |
25 | rm -rf ../../zbSocDriver/*.o ${APP_NAME} | ||
diff --git a/zbSocDriver/zbSocCmd.c b/zbSocDriver/zbSocCmd.c new file mode 100755 index 0000000..e3e87aa --- /dev/null +++ b/zbSocDriver/zbSocCmd.c | |||
@@ -0,0 +1,1652 @@ | |||
1 | /* | ||
2 | * zbSocCmd.c | ||
3 | * | ||
4 | * This module contains the API for the zll SoC Host Interface. | ||
5 | * | ||
6 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ | ||
7 | * | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
22 | * its contributors may be used to endorse or promote products derived | ||
23 | * from this software without specific prior written permission. | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
36 | * | ||
37 | */ | ||
38 | |||
39 | /********************************************************************* | ||
40 | * INCLUDES | ||
41 | */ | ||
42 | #include <termios.h> | ||
43 | #include <string.h> | ||
44 | #include <stdio.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <unistd.h> | ||
47 | #include <fcntl.h> | ||
48 | #include <sys/ioctl.h> | ||
49 | |||
50 | #include <errno.h> | ||
51 | #include <string.h> | ||
52 | |||
53 | #include "zbSocCmd.h" | ||
54 | |||
55 | /********************************************************************* | ||
56 | * MACROS | ||
57 | */ | ||
58 | |||
59 | #define APPCMDHEADER(len) \ | ||
60 | 0xFE, \ | ||
61 | len, /*RPC payload Len */ \ | ||
62 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ \ | ||
63 | 0x00, /*MT_APP_MSG */ \ | ||
64 | 0x0B, /*Application Endpoint */ \ | ||
65 | 0x02, /*short Addr 0x0002 */ \ | ||
66 | 0x00, /*short Addr 0x0002 */ \ | ||
67 | 0x0B, /*Dst EP */ \ | ||
68 | 0xFF, /*Cluster ID 0xFFFF invalid, used for key */ \ | ||
69 | 0xFF, /*Cluster ID 0xFFFF invalid, used for key */ \ | ||
70 | |||
71 | #define BUILD_UINT16(loByte, hiByte) \ | ||
72 | ((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8))) | ||
73 | |||
74 | #define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \ | ||
75 | ((uint32_t)((uint32_t)((Byte0) & 0x00FF) \ | ||
76 | + ((uint32_t)((Byte1) & 0x00FF) << 8) \ | ||
77 | + ((uint32_t)((Byte2) & 0x00FF) << 16) \ | ||
78 | + ((uint32_t)((Byte3) & 0x00FF) << 24))) | ||
79 | |||
80 | /********************************************************************* | ||
81 | * CONSTANTS | ||
82 | */ | ||
83 | #define ZLL_MT_APP_RPC_CMD_TOUCHLINK 0x01 | ||
84 | #define ZLL_MT_APP_RPC_CMD_RESET_TO_FN 0x02 | ||
85 | #define ZLL_MT_APP_RPC_CMD_CH_CHANNEL 0x03 | ||
86 | #define ZLL_MT_APP_RPC_CMD_JOIN_HA 0x04 | ||
87 | #define ZLL_MT_APP_RPC_CMD_PERMIT_JOIN 0x05 | ||
88 | #define ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN 0x06 | ||
89 | |||
90 | #define MT_APP_RSP 0x80 | ||
91 | #define MT_APP_ZLL_TL_IND 0x81 | ||
92 | #define MT_APP_ZLL_NEW_DEV_IND 0x82 | ||
93 | |||
94 | #define MT_DEBUG_MSG 0x80 | ||
95 | |||
96 | #define COMMAND_LIGHTING_MOVE_TO_HUE 0x00 | ||
97 | #define COMMAND_LIGHTING_MOVE_TO_SATURATION 0x03 | ||
98 | #define COMMAND_LEVEL_MOVE_TO_LEVEL 0x00 | ||
99 | #define COMMAND_IDENTIFY 0x00 | ||
100 | #define COMMAND_IDENTIFY_TRIGGER_EFFECT 0x40 | ||
101 | |||
102 | /*** Foundation Command IDs ***/ | ||
103 | #define ZCL_CMD_READ 0x00 | ||
104 | #define ZCL_CMD_READ_RSP 0x01 | ||
105 | #define ZCL_CMD_WRITE 0x02 | ||
106 | #define ZCL_CMD_WRITE_UNDIVIDED 0x03 | ||
107 | #define ZCL_CMD_WRITE_RSP 0x04 | ||
108 | //ZDO | ||
109 | #define MT_ZDO_SIMPLE_DESC_RSP 0x84 | ||
110 | #define MT_ZDO_ACTIVE_EP_RSP 0x85 | ||
111 | #define MT_ZDO_END_DEVICE_ANNCE_IND 0xC1 | ||
112 | #define MT_ZDO_LEAVE_IND 0xC9 | ||
113 | |||
114 | //UTIL | ||
115 | #define MT_UTIL_GET_DEVICE_INFO 0x00 | ||
116 | |||
117 | // General Clusters | ||
118 | #define ZCL_CLUSTER_ID_GEN_BASIC 0x0000 | ||
119 | #define ZCL_CLUSTER_ID_GEN_IDENTIFY 0x0003 | ||
120 | #define ZCL_CLUSTER_ID_GEN_GROUPS 0x0004 | ||
121 | #define ZCL_CLUSTER_ID_GEN_SCENES 0x0005 | ||
122 | #define ZCL_CLUSTER_ID_GEN_ON_OFF 0x0006 | ||
123 | #define ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL 0x0008 | ||
124 | // Lighting Clusters | ||
125 | #define ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL 0x0300 | ||
126 | |||
127 | // Data Types | ||
128 | #define ZCL_DATATYPE_BOOLEAN 0x10 | ||
129 | #define ZCL_DATATYPE_UINT8 0x20 | ||
130 | #define ZCL_DATATYPE_INT16 0x29 | ||
131 | #define ZCL_DATATYPE_INT24 0x2a | ||
132 | #define ZCL_DATATYPE_CHAR_STR 0x42 | ||
133 | |||
134 | /*******************************/ | ||
135 | /*** Generic Cluster ATTR's ***/ | ||
136 | /*******************************/ | ||
137 | #define ATTRID_BASIC_MODEL_ID 0x0005 | ||
138 | #define ATTRID_ON_OFF 0x0000 | ||
139 | #define ATTRID_LEVEL_CURRENT_LEVEL 0x0000 | ||
140 | |||
141 | /*******************************/ | ||
142 | /*** Lighting Cluster ATTR's ***/ | ||
143 | /*******************************/ | ||
144 | #define ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE 0x0000 | ||
145 | #define ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION 0x0001 | ||
146 | |||
147 | /*******************************/ | ||
148 | /*** Scenes Cluster Commands ***/ | ||
149 | /*******************************/ | ||
150 | #define COMMAND_SCENE_STORE 0x04 | ||
151 | #define COMMAND_SCENE_RECALL 0x05 | ||
152 | |||
153 | /*******************************/ | ||
154 | /*** Groups Cluster Commands ***/ | ||
155 | /*******************************/ | ||
156 | #define COMMAND_GROUP_ADD 0x00 | ||
157 | |||
158 | /* The 3 MSB's of the 1st command field byte are for command type. */ | ||
159 | #define MT_RPC_CMD_TYPE_MASK 0xE0 | ||
160 | |||
161 | /* The 5 LSB's of the 1st command field byte are for the subsystem. */ | ||
162 | #define MT_RPC_SUBSYSTEM_MASK 0x1F | ||
163 | |||
164 | #define MT_RPC_SOF 0xFE | ||
165 | |||
166 | /*******************************/ | ||
167 | /*** Bootloader Commands ***/ | ||
168 | /*******************************/ | ||
169 | #define SB_FORCE_BOOT 0xF8 | ||
170 | #define SB_FORCE_RUN (SB_FORCE_BOOT ^ 0xFF) | ||
171 | |||
172 | typedef enum { | ||
173 | MT_RPC_CMD_POLL = 0x00, | ||
174 | MT_RPC_CMD_SREQ = 0x20, | ||
175 | MT_RPC_CMD_AREQ = 0x40, | ||
176 | MT_RPC_CMD_SRSP = 0x60, | ||
177 | MT_RPC_CMD_RES4 = 0x80, | ||
178 | MT_RPC_CMD_RES5 = 0xA0, | ||
179 | MT_RPC_CMD_RES6 = 0xC0, | ||
180 | MT_RPC_CMD_RES7 = 0xE0 | ||
181 | } mtRpcCmdType_t; | ||
182 | |||
183 | typedef enum { | ||
184 | MT_RPC_SYS_RES0, /* Reserved. */ | ||
185 | MT_RPC_SYS_SYS, | ||
186 | MT_RPC_SYS_MAC, | ||
187 | MT_RPC_SYS_NWK, | ||
188 | MT_RPC_SYS_AF, | ||
189 | MT_RPC_SYS_ZDO, | ||
190 | MT_RPC_SYS_SAPI, /* Simple API. */ | ||
191 | MT_RPC_SYS_UTIL, | ||
192 | MT_RPC_SYS_DBG, | ||
193 | MT_RPC_SYS_APP, | ||
194 | MT_RPC_SYS_OTA, | ||
195 | MT_RPC_SYS_ZNP, | ||
196 | MT_RPC_SYS_SPARE_12, | ||
197 | MT_RPC_SYS_UBL = 13, // 13 to be compatible with existing RemoTI. | ||
198 | MT_RPC_SYS_MAX // Maximum value, must be last (so 14-32 available, not yet assigned). | ||
199 | } mtRpcSysType_t; | ||
200 | |||
201 | /************************************************************ | ||
202 | * TYPEDEFS | ||
203 | */ | ||
204 | |||
205 | /********************************************************************* | ||
206 | * GLOBAL VARIABLES | ||
207 | */ | ||
208 | |||
209 | /********************************************************************* | ||
210 | * LOCAL VARIABLES | ||
211 | */ | ||
212 | int serialPortFd = 0; | ||
213 | uint8_t transSeqNumber = 0; | ||
214 | |||
215 | zbSocCallbacks_t zbSocCb; | ||
216 | |||
217 | /********************************************************************* | ||
218 | * LOCAL FUNCTIONS | ||
219 | */ | ||
220 | void calcFcs(uint8_t *msg, int size); | ||
221 | static void processRpcSysAppTlInd(uint8_t *TlIndBuff); | ||
222 | static void processRpcSysAppZcl(uint8_t *zclRspBuff); | ||
223 | static void processRpcSysAppZclFoundation(uint8_t *zclRspBuff, | ||
224 | uint8_t zclFrameLen, uint16_t clusterID, uint16_t nwkAddr, uint8_t endpoint); | ||
225 | static void processRpcSysApp(uint8_t *rpcBuff); | ||
226 | static void processRpcSysDbg(uint8_t *rpcBuff); | ||
227 | static void zbSocTransportWrite(uint8_t* buf, uint8_t len); | ||
228 | |||
229 | /********************************************************************* | ||
230 | * @fn calcFcs | ||
231 | * | ||
232 | * @brief populates the Frame Check Sequence of the RPC payload. | ||
233 | * | ||
234 | * @param msg - pointer to the RPC message | ||
235 | * | ||
236 | * @return none | ||
237 | */ | ||
238 | void calcFcs(uint8_t *msg, int size) | ||
239 | { | ||
240 | uint8_t result = 0; | ||
241 | int idx = 1; //skip SOF | ||
242 | int len = (size - 1); // skip FCS | ||
243 | |||
244 | while ((len--) != 0) | ||
245 | { | ||
246 | result ^= msg[idx++]; | ||
247 | } | ||
248 | |||
249 | msg[(size - 1)] = result; | ||
250 | } | ||
251 | |||
252 | /********************************************************************* | ||
253 | * API FUNCTIONS | ||
254 | */ | ||
255 | |||
256 | /********************************************************************* | ||
257 | * @fn zbSocOpen | ||
258 | * | ||
259 | * @brief opens the serial port to the CC253x. | ||
260 | * | ||
261 | * @param devicePath - path to the UART device | ||
262 | * | ||
263 | * @return status | ||
264 | */ | ||
265 | int32_t zbSocOpen(char *devicePath) | ||
266 | { | ||
267 | struct termios tio; | ||
268 | |||
269 | /* open the device to be non-blocking (read will return immediatly) */ | ||
270 | serialPortFd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK); | ||
271 | if (serialPortFd < 0) | ||
272 | { | ||
273 | perror(devicePath); | ||
274 | printf("%s open failed\n", devicePath); | ||
275 | return (-1); | ||
276 | } | ||
277 | |||
278 | //make the access exclusive so other instances will return -1 and exit | ||
279 | ioctl(serialPortFd, TIOCEXCL); | ||
280 | |||
281 | /* c-iflags | ||
282 | B115200 : set board rate to 115200 | ||
283 | CRTSCTS : HW flow control (disabled below) | ||
284 | CS8 : 8n1 (8bit,no parity,1 stopbit) | ||
285 | CLOCAL : local connection, no modem contol | ||
286 | CREAD : enable receiving characters*/ | ||
287 | tio.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD; | ||
288 | /* c-iflags | ||
289 | ICRNL : maps 0xD (CR) to 0x10 (LR), we do not want this. | ||
290 | IGNPAR : ignore bits with parity erros, I guess it is | ||
291 | better to ignStateore an erronious bit then interprit it incorrectly. */ | ||
292 | tio.c_iflag = IGNPAR & ~ICRNL; | ||
293 | tio.c_oflag = 0; | ||
294 | tio.c_lflag = 0; | ||
295 | |||
296 | tcflush(serialPortFd, TCIFLUSH); | ||
297 | tcsetattr(serialPortFd, TCSANOW, &tio); | ||
298 | |||
299 | //Send the bootloader force boot incase we have a bootloader that waits | ||
300 | uint8_t forceBoot = SB_FORCE_RUN; | ||
301 | zbSocTransportWrite(&forceBoot, 1); | ||
302 | |||
303 | return serialPortFd; | ||
304 | } | ||
305 | |||
306 | void zbSocClose(void) | ||
307 | { | ||
308 | tcflush(serialPortFd, TCOFLUSH); | ||
309 | close(serialPortFd); | ||
310 | |||
311 | return; | ||
312 | } | ||
313 | |||
314 | /********************************************************************* | ||
315 | * @fn zbSocTransportWrite | ||
316 | * | ||
317 | * @brief Write to the the serial port to the CC253x. | ||
318 | * | ||
319 | * @param fd - file descriptor of the UART device | ||
320 | * | ||
321 | * @return status | ||
322 | */ | ||
323 | static void zbSocTransportWrite(uint8_t* buf, uint8_t len) | ||
324 | { | ||
325 | int remain = len; | ||
326 | int offset = 0; | ||
327 | #if 1 | ||
328 | //printf("zbSocTransportWrite : len = %d\n", len); | ||
329 | |||
330 | while (remain > 0) | ||
331 | { | ||
332 | int sub = (remain >= 8 ? 8 : remain); | ||
333 | //printf("writing %d bytes (offset = %d, remain = %d)\n", sub, offset, | ||
334 | // remain); | ||
335 | write(serialPortFd, buf + offset, sub); | ||
336 | |||
337 | tcflush(serialPortFd, TCOFLUSH); | ||
338 | usleep(5000); | ||
339 | remain -= 8; | ||
340 | offset += 8; | ||
341 | } | ||
342 | #else | ||
343 | write (serialPortFd, buf, len); | ||
344 | tcflush(serialPortFd, TCOFLUSH); | ||
345 | |||
346 | #endif | ||
347 | return; | ||
348 | } | ||
349 | |||
350 | /********************************************************************* | ||
351 | * @fn zbSocRegisterCallbacks | ||
352 | * | ||
353 | * @brief opens the serial port to the CC253x. | ||
354 | * | ||
355 | * @param devicePath - path to the UART device | ||
356 | * | ||
357 | * @return status | ||
358 | */ | ||
359 | void zbSocRegisterCallbacks(zbSocCallbacks_t zbSocCallbacks) | ||
360 | { | ||
361 | //copy the callback function pointers | ||
362 | memcpy(&zbSocCb, &zbSocCallbacks, sizeof(zbSocCallbacks_t)); | ||
363 | return; | ||
364 | } | ||
365 | |||
366 | /********************************************************************* | ||
367 | * @fn zbSocTouchLink | ||
368 | * | ||
369 | * @brief Send the touchLink command to the CC253x. | ||
370 | * | ||
371 | * @param none | ||
372 | * | ||
373 | * @return none | ||
374 | */ | ||
375 | void zbSocTouchLink(void) | ||
376 | { | ||
377 | uint8_t cmd[] = | ||
378 | { APPCMDHEADER(13) 0x06, //Data Len | ||
379 | 0x02, //Address Mode | ||
380 | 0x00,//2dummy bytes | ||
381 | 0x00, ZLL_MT_APP_RPC_CMD_TOUCHLINK, 0x00, // | ||
382 | 0x00, // | ||
383 | 0x00 //FCS - fill in later | ||
384 | }; | ||
385 | |||
386 | calcFcs(cmd, sizeof(cmd)); | ||
387 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
388 | } | ||
389 | |||
390 | /********************************************************************* | ||
391 | * @fn zbSocResetToFn | ||
392 | * | ||
393 | * @brief Send the reset to factory new command to the CC253x. | ||
394 | * | ||
395 | * @param none | ||
396 | * | ||
397 | * @return none | ||
398 | */ | ||
399 | void zbSocResetToFn(void) | ||
400 | { | ||
401 | uint8_t cmd[] = | ||
402 | { APPCMDHEADER(13) 0x06, //Data Len | ||
403 | 0x02, //Address Mode | ||
404 | 0x00,//2dummy bytes | ||
405 | 0x00, ZLL_MT_APP_RPC_CMD_RESET_TO_FN, 0x00, // | ||
406 | 0x00, // | ||
407 | 0x00 //FCS - fill in later | ||
408 | }; | ||
409 | |||
410 | calcFcs(cmd, sizeof(cmd)); | ||
411 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
412 | } | ||
413 | |||
414 | /********************************************************************* | ||
415 | * @fn zbSocSendResetToFn | ||
416 | * | ||
417 | * @brief Send the reset to factory new command to a ZLL device. | ||
418 | * | ||
419 | * @param none | ||
420 | * | ||
421 | * @return none | ||
422 | */ | ||
423 | void zbSocSendResetToFn(void) | ||
424 | { | ||
425 | uint8_t cmd[] = | ||
426 | { APPCMDHEADER(13) 0x06, //Data Len | ||
427 | 0x02, //Address Mode | ||
428 | 0x00,//2dummy bytes | ||
429 | 0x00, ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN, 0x00, // | ||
430 | 0x00, // | ||
431 | 0x00 //FCS - fill in later | ||
432 | }; | ||
433 | |||
434 | calcFcs(cmd, sizeof(cmd)); | ||
435 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
436 | } | ||
437 | |||
438 | /********************************************************************* | ||
439 | * @fn zbSocOpenNwk | ||
440 | * | ||
441 | * @brief Send the open network command to a ZLL device. | ||
442 | * | ||
443 | * @param none | ||
444 | * | ||
445 | * @return none | ||
446 | */ | ||
447 | void zbSocOpenNwk(uint8_t duration) | ||
448 | { | ||
449 | uint8_t cmd[] = | ||
450 | { APPCMDHEADER(13) 0x06, //Data Len | ||
451 | 0x02, //Address Mode | ||
452 | 0x00,//2dummy bytes | ||
453 | 0x00, ZLL_MT_APP_RPC_CMD_PERMIT_JOIN, 0x00, // | ||
454 | 0x00, // | ||
455 | 0x00 //FCS - fill in later | ||
456 | }; | ||
457 | |||
458 | cmd[15] = duration; | ||
459 | |||
460 | printf("zbSocOpenNwk: duration %ds\n", duration); | ||
461 | |||
462 | calcFcs(cmd, sizeof(cmd)); | ||
463 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
464 | } | ||
465 | |||
466 | /********************************************************************* | ||
467 | * @fn zbSocSendIdentify | ||
468 | * | ||
469 | * @brief Send identify command to a ZLL light. | ||
470 | * | ||
471 | * @param identifyTime - in s. | ||
472 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
473 | * @param endpoint - endpoint of the Light. | ||
474 | * @param addrMode - Unicast or Group cast. | ||
475 | * | ||
476 | * @return none | ||
477 | */ | ||
478 | void zbSocSendIdentify(uint16_t identifyTime, uint16_t dstAddr, | ||
479 | uint8_t endpoint, uint8_t addrMode) | ||
480 | { | ||
481 | uint8_t cmd[] = | ||
482 | { 0xFE, | ||
483 | 13, //RPC payload Len | ||
484 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
485 | 0x00, //MT_APP_MSG | ||
486 | 0x0B, //Application Endpoint | ||
487 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
488 | endpoint, //Dst EP | ||
489 | (ZCL_CLUSTER_ID_GEN_IDENTIFY & 0x00ff), | ||
490 | (ZCL_CLUSTER_ID_GEN_IDENTIFY & 0xff00) >> 8, 0x06, //Data Len | ||
491 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
492 | transSeqNumber++, COMMAND_IDENTIFY, (identifyTime | ||
493 | & 0xff), (identifyTime & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
494 | }; | ||
495 | |||
496 | calcFcs(cmd, sizeof(cmd)); | ||
497 | |||
498 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
499 | |||
500 | printf("zbSocSendIdentify: dstAddr=%x, endpoint=%x, addrMode=%x, identifyTime=%x\n", | ||
501 | dstAddr, endpoint, addrMode, identifyTime); | ||
502 | } | ||
503 | |||
504 | /********************************************************************* | ||
505 | * @fn COMMAND_IDENTIFY_TRIGGER_EFFECT | ||
506 | * | ||
507 | * @brief Send identify command to a ZLL light. | ||
508 | * | ||
509 | * @param effect - effect. | ||
510 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
511 | * @param endpoint - endpoint of the Light. | ||
512 | * @param addrMode - Unicast or Group cast. | ||
513 | * | ||
514 | * @return none | ||
515 | */ | ||
516 | void zbSocSendIdentifyEffect(uint8_t effect, uint8_t effectVarient, uint16_t dstAddr, | ||
517 | uint8_t endpoint, uint8_t addrMode) | ||
518 | { | ||
519 | uint8_t cmd[] = | ||
520 | { 0xFE, | ||
521 | 13, //RPC payload Len | ||
522 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
523 | 0x00, //MT_APP_MSG | ||
524 | 0x0B, //Application Endpoint | ||
525 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
526 | endpoint, //Dst EP | ||
527 | (ZCL_CLUSTER_ID_GEN_IDENTIFY & 0x00ff), | ||
528 | (ZCL_CLUSTER_ID_GEN_IDENTIFY & 0xff00) >> 8, 0x06, //Data Len | ||
529 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
530 | transSeqNumber++, COMMAND_IDENTIFY_TRIGGER_EFFECT, effect, | ||
531 | effectVarient, 0x00 //FCS - fill in later | ||
532 | }; | ||
533 | |||
534 | calcFcs(cmd, sizeof(cmd)); | ||
535 | |||
536 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
537 | |||
538 | printf("zbSocSendIdentify: dstAddr=%x, endpoint=%x, addrMode=%x, effect=%x\n", | ||
539 | dstAddr, endpoint, addrMode, effect); | ||
540 | } | ||
541 | |||
542 | /********************************************************************* | ||
543 | * @fn zbSocSetState | ||
544 | * | ||
545 | * @brief Send the on/off command to a ZLL light. | ||
546 | * | ||
547 | * @param state - 0: Off, 1: On. | ||
548 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
549 | * @param endpoint - endpoint of the Light. | ||
550 | * @param addrMode - Unicast or Group cast. | ||
551 | * | ||
552 | * @return none | ||
553 | */ | ||
554 | void zbSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, | ||
555 | uint8_t addrMode) | ||
556 | { | ||
557 | uint8_t cmd[] = | ||
558 | { 0xFE, 11, /*RPC payload Len */ | ||
559 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
560 | 0x00, /*MT_APP_MSG */ | ||
561 | 0x0B, /*Application Endpoint */ | ||
562 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
563 | (ZCL_CLUSTER_ID_GEN_ON_OFF & 0x00ff), (ZCL_CLUSTER_ID_GEN_ON_OFF & 0xff00) | ||
564 | >> 8, 0x04, //Data Len | ||
565 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
566 | transSeqNumber++, (state ? 1 : 0), 0x00 //FCS - fill in later | ||
567 | }; | ||
568 | |||
569 | calcFcs(cmd, sizeof(cmd)); | ||
570 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
571 | } | ||
572 | |||
573 | /********************************************************************* | ||
574 | * @fn zbSocSetLevel | ||
575 | * | ||
576 | * @brief Send the level command to a ZLL light. | ||
577 | * | ||
578 | * @param level - 0-128 = 0-100% | ||
579 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
580 | * @param endpoint - endpoint of the Light. | ||
581 | * @param addrMode - Unicast or Group cast. | ||
582 | * | ||
583 | * @return none | ||
584 | */ | ||
585 | void zbSocSetLevel(uint8_t level, uint16_t time, uint16_t dstAddr, | ||
586 | uint8_t endpoint, uint8_t addrMode) | ||
587 | { | ||
588 | uint8_t cmd[] = | ||
589 | { 0xFE, | ||
590 | 14, //RPC payload Len | ||
591 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
592 | 0x00, //MT_APP_MSG | ||
593 | 0x0B, //Application Endpoint | ||
594 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
595 | endpoint, //Dst EP | ||
596 | (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0x00ff), | ||
597 | (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0xff00) >> 8, 0x07, //Data Len | ||
598 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
599 | transSeqNumber++, COMMAND_LEVEL_MOVE_TO_LEVEL, (level & 0xff), (time | ||
600 | & 0xff), (time & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
601 | }; | ||
602 | |||
603 | calcFcs(cmd, sizeof(cmd)); | ||
604 | |||
605 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
606 | |||
607 | printf("zbSocSetLevel: dstAddr=%x, endpoint=%x, addrMode=%x, level=%x\n", | ||
608 | dstAddr, endpoint, addrMode, level); | ||
609 | } | ||
610 | |||
611 | /********************************************************************* | ||
612 | * @fn zbSocSetHue | ||
613 | * | ||
614 | * @brief Send the hue command to a ZLL light. | ||
615 | * | ||
616 | * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green | ||
617 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
618 | * @param endpoint - endpoint of the Light. | ||
619 | * @param addrMode - Unicast or Group cast. | ||
620 | * | ||
621 | * @return none | ||
622 | */ | ||
623 | void zbSocSetHue(uint8_t hue, uint16_t time, uint16_t dstAddr, uint8_t endpoint, | ||
624 | uint8_t addrMode) | ||
625 | { | ||
626 | uint8_t cmd[] = | ||
627 | { 0xFE, | ||
628 | 15, //RPC payload Len | ||
629 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
630 | 0x00, //MT_APP_MSG | ||
631 | 0x0B, //Application Endpoint | ||
632 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
633 | endpoint, //Dst EP | ||
634 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff), | ||
635 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8, 0x08, //Data Len | ||
636 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
637 | transSeqNumber++, COMMAND_LIGHTING_MOVE_TO_HUE, (hue & 0xff), 0x00, //Move with shortest distance | ||
638 | (time & 0xff), (time & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
639 | }; | ||
640 | |||
641 | calcFcs(cmd, sizeof(cmd)); | ||
642 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
643 | } | ||
644 | |||
645 | /********************************************************************* | ||
646 | * @fn zbSocSetSat | ||
647 | * | ||
648 | * @brief Send the satuartion command to a ZLL light. | ||
649 | * | ||
650 | * @param sat - 0-128 : 0=white, 128: fully saturated color | ||
651 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
652 | * @param endpoint - endpoint of the Light. | ||
653 | * @param addrMode - Unicast or Group cast. | ||
654 | * | ||
655 | * @return none | ||
656 | */ | ||
657 | void zbSocSetSat(uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, | ||
658 | uint8_t addrMode) | ||
659 | { | ||
660 | uint8_t cmd[] = | ||
661 | { 0xFE, | ||
662 | 14, //RPC payload Len | ||
663 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
664 | 0x00, //MT_APP_MSG | ||
665 | 0x0B, //Application Endpoint | ||
666 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
667 | endpoint, //Dst EP | ||
668 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff), | ||
669 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8, 0x07, //Data Len | ||
670 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
671 | transSeqNumber++, COMMAND_LIGHTING_MOVE_TO_SATURATION, (sat & 0xff), (time | ||
672 | & 0xff), (time & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
673 | }; | ||
674 | |||
675 | calcFcs(cmd, sizeof(cmd)); | ||
676 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
677 | } | ||
678 | |||
679 | /********************************************************************* | ||
680 | * @fn zbSocSetHueSat | ||
681 | * | ||
682 | * @brief Send the hue and satuartion command to a ZLL light. | ||
683 | * | ||
684 | * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green | ||
685 | * @param sat - 0-128 : 0=white, 128: fully saturated color | ||
686 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
687 | * @param endpoint - endpoint of the Light. | ||
688 | * @param addrMode - Unicast or Group cast. | ||
689 | * | ||
690 | * @return none | ||
691 | */ | ||
692 | void zbSocSetHueSat(uint8_t hue, uint8_t sat, uint16_t time, uint16_t dstAddr, | ||
693 | uint8_t endpoint, uint8_t addrMode) | ||
694 | { | ||
695 | uint8_t cmd[] = | ||
696 | { 0xFE, | ||
697 | 15, //RPC payload Len | ||
698 | 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP | ||
699 | 0x00, //MT_APP_MSG | ||
700 | 0x0B, //Application Endpoint | ||
701 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, | ||
702 | endpoint, //Dst EP | ||
703 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff), | ||
704 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8, 0x08, //Data Len | ||
705 | addrMode, 0x01, //ZCL Header Frame Control | ||
706 | transSeqNumber++, 0x06, //ZCL Header Frame Command (COMMAND_LEVEL_MOVE_TO_HUE_AND_SAT) | ||
707 | hue, //HUE - fill it in later | ||
708 | sat, //SAT - fill it in later | ||
709 | (time & 0xff), (time & 0xff00) >> 8, 0x00 //fcs | ||
710 | }; | ||
711 | |||
712 | calcFcs(cmd, sizeof(cmd)); | ||
713 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
714 | } | ||
715 | |||
716 | /********************************************************************* | ||
717 | * @fn zbSocAddGroup | ||
718 | * | ||
719 | * @brief Add Group. | ||
720 | * | ||
721 | * @param groupId - Group ID of the Scene. | ||
722 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
723 | * @param endpoint - endpoint of the Light. | ||
724 | * @param addrMode - Unicast or Group cast. | ||
725 | * | ||
726 | * @return none | ||
727 | */ | ||
728 | void zbSocAddGroup(uint16_t groupId, uint16_t dstAddr, uint8_t endpoint, | ||
729 | uint8_t addrMode) | ||
730 | { | ||
731 | uint8_t cmd[] = | ||
732 | { 0xFE, 14, /*RPC payload Len */ | ||
733 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
734 | 0x00, /*MT_APP_MSG */ | ||
735 | 0x0B, /*Application Endpoint */ | ||
736 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
737 | (ZCL_CLUSTER_ID_GEN_GROUPS & 0x00ff), (ZCL_CLUSTER_ID_GEN_GROUPS & 0xff00) | ||
738 | >> 8, | ||
739 | 0x07, //Data Len | ||
740 | addrMode, | ||
741 | 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
742 | transSeqNumber++, COMMAND_GROUP_ADD, (groupId & 0x00ff), | ||
743 | (groupId & 0xff00) >> 8, 0, //Null group name - Group Name not pushed to the devices | ||
744 | 0x00 //FCS - fill in later | ||
745 | }; | ||
746 | |||
747 | printf("zbSocAddGroup: dstAddr 0x%x\n", dstAddr); | ||
748 | |||
749 | calcFcs(cmd, sizeof(cmd)); | ||
750 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
751 | } | ||
752 | |||
753 | /********************************************************************* | ||
754 | * @fn zbSocStoreScene | ||
755 | * | ||
756 | * @brief Store Scene. | ||
757 | * | ||
758 | * @param groupId - Group ID of the Scene. | ||
759 | * @param sceneId - Scene ID of the Scene. | ||
760 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
761 | * @param endpoint - endpoint of the Light. | ||
762 | * @param addrMode - Unicast or Group cast. | ||
763 | * | ||
764 | * @return none | ||
765 | */ | ||
766 | void zbSocStoreScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, | ||
767 | uint8_t endpoint, uint8_t addrMode) | ||
768 | { | ||
769 | uint8_t cmd[] = | ||
770 | { 0xFE, 14, /*RPC payload Len */ | ||
771 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
772 | 0x00, /*MT_APP_MSG */ | ||
773 | 0x0B, /*Application Endpoint */ | ||
774 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
775 | (ZCL_CLUSTER_ID_GEN_SCENES & 0x00ff), (ZCL_CLUSTER_ID_GEN_SCENES & 0xff00) | ||
776 | >> 8, 0x07, //Data Len | ||
777 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
778 | transSeqNumber++, COMMAND_SCENE_STORE, (groupId & 0x00ff), (groupId | ||
779 | & 0xff00) >> 8, sceneId++, 0x00 //FCS - fill in later | ||
780 | }; | ||
781 | |||
782 | calcFcs(cmd, sizeof(cmd)); | ||
783 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
784 | } | ||
785 | |||
786 | /********************************************************************* | ||
787 | * @fn zbSocRecallScene | ||
788 | * | ||
789 | * @brief Recall Scene. | ||
790 | * | ||
791 | * @param groupId - Group ID of the Scene. | ||
792 | * @param sceneId - Scene ID of the Scene. | ||
793 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled. | ||
794 | * @param endpoint - endpoint of the Light. | ||
795 | * @param addrMode - Unicast or Group cast. | ||
796 | |||
797 | * @return none | ||
798 | */ | ||
799 | void zbSocRecallScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, | ||
800 | uint8_t endpoint, uint8_t addrMode) | ||
801 | { | ||
802 | uint8_t cmd[] = | ||
803 | { 0xFE, 14, /*RPC payload Len */ | ||
804 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
805 | 0x00, /*MT_APP_MSG */ | ||
806 | 0x0B, /*Application Endpoint */ | ||
807 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
808 | (ZCL_CLUSTER_ID_GEN_SCENES & 0x00ff), (ZCL_CLUSTER_ID_GEN_SCENES & 0xff00) | ||
809 | >> 8, 0x07, //Data Len | ||
810 | addrMode, 0x01, //0x01 ZCL frame control field. (send to the light cluster only) | ||
811 | transSeqNumber++, COMMAND_SCENE_RECALL, (groupId & 0x00ff), (groupId | ||
812 | & 0xff00) >> 8, sceneId++, 0x00 //FCS - fill in later | ||
813 | }; | ||
814 | |||
815 | calcFcs(cmd, sizeof(cmd)); | ||
816 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
817 | } | ||
818 | |||
819 | /********************************************************************* | ||
820 | * @fn zbSocBind | ||
821 | * | ||
822 | * @brief Recall Scene. | ||
823 | * | ||
824 | * @param | ||
825 | * | ||
826 | * @return none | ||
827 | */ | ||
828 | void zbSocBind(uint16_t srcNwkAddr, uint8_t srcEndpoint, uint8_t srcIEEE[8], | ||
829 | uint8_t dstEndpoint, uint8_t dstIEEE[8], uint16_t clusterID) | ||
830 | { | ||
831 | uint8_t cmd[] = | ||
832 | { 0xFE, 23, /*RPC payload Len */ | ||
833 | MT_RPC_CMD_SREQ | MT_RPC_SYS_ZDO, | ||
834 | 0x21, /*MT_ZDO_BIND_REQ*/ | ||
835 | (srcNwkAddr & 0x00ff), /*Src Nwk Addr - To send the bind message to*/ | ||
836 | (srcNwkAddr & 0xff00) >> 8, /*Src Nwk Addr - To send the bind message to*/ | ||
837 | srcIEEE[0], /*Src IEEE Addr for the binding*/ | ||
838 | srcIEEE[1], /*Src IEEE Addr for the binding*/ | ||
839 | srcIEEE[2], /*Src IEEE Addr for the binding*/ | ||
840 | srcIEEE[3], /*Src IEEE Addr for the binding*/ | ||
841 | srcIEEE[4], /*Src IEEE Addr for the binding*/ | ||
842 | srcIEEE[5], /*Src IEEE Addr for the binding*/ | ||
843 | srcIEEE[6], /*Src IEEE Addr for the binding*/ | ||
844 | srcIEEE[7], /*Src IEEE Addr for the binding*/ | ||
845 | srcEndpoint, /*Src endpoint for the binding*/ | ||
846 | (clusterID & 0x00ff), /*cluster ID to bind*/ | ||
847 | (clusterID & 0xff00) >> 8, /*cluster ID to bind*/ | ||
848 | afAddr64Bit, /*Addr mode of the dst to bind*/ | ||
849 | dstIEEE[0], /*Dst IEEE Addr for the binding*/ | ||
850 | dstIEEE[1], /*Dst IEEE Addr for the binding*/ | ||
851 | dstIEEE[2], /*Dst IEEE Addr for the binding*/ | ||
852 | dstIEEE[3], /*Dst IEEE Addr for the binding*/ | ||
853 | dstIEEE[4], /*Dst IEEE Addr for the binding*/ | ||
854 | dstIEEE[5], /*Dst IEEE Addr for the binding*/ | ||
855 | dstIEEE[6], /*Dst IEEE Addr for the binding*/ | ||
856 | dstIEEE[7], /*Dst IEEE Addr for the binding*/ | ||
857 | dstEndpoint, /*Dst endpoint for the binding*/ | ||
858 | 0x00 //FCS - fill in later | ||
859 | }; | ||
860 | |||
861 | /*printf("zbSocBind: srcNwkAddr=0x%x, srcEndpoint=0x%x, srcIEEE=0x%x:%x:%x:%x:%x:%x:%x:%x, dstEndpoint=0x%x, dstIEEE=0x%x:%x:%x:%x:%x:%x:%x:%x, clusterID:%x\n", | ||
862 | srcNwkAddr, srcEndpoint, srcIEEE[0], srcIEEE[1], srcIEEE[2], srcIEEE[3], srcIEEE[4], srcIEEE[5], srcIEEE[6], srcIEEE[7], | ||
863 | srcEndpoint, dstIEEE[0], dstIEEE[1], dstIEEE[2], dstIEEE[3], dstIEEE[4], dstIEEE[5], dstIEEE[6], dstIEEE[7], clusterID);*/ | ||
864 | |||
865 | calcFcs(cmd, sizeof(cmd)); | ||
866 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
867 | } | ||
868 | |||
869 | void zbSocGetInfo(void) | ||
870 | { | ||
871 | uint8_t cmd[] = | ||
872 | { 0xFE, 0, /*RPC payload Len */ | ||
873 | MT_RPC_CMD_SREQ | MT_RPC_SYS_UTIL, | ||
874 | MT_UTIL_GET_DEVICE_INFO, | ||
875 | 0x00 //FCS - fill in later | ||
876 | }; | ||
877 | |||
878 | //printf("zbSocGetInfo++ \n"); | ||
879 | |||
880 | calcFcs(cmd, sizeof(cmd)); | ||
881 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
882 | } | ||
883 | |||
884 | /********************************************************************* | ||
885 | * @fn zbSocGetState | ||
886 | * | ||
887 | * @brief Send the get state command to a ZLL light. | ||
888 | * | ||
889 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command. | ||
890 | * @param endpoint - endpoint of the Light. | ||
891 | * @param addrMode - Unicast or Group cast. | ||
892 | * | ||
893 | * @return none | ||
894 | */ | ||
895 | void zbSocGetState(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode) | ||
896 | { | ||
897 | uint8_t cmd[] = | ||
898 | { 0xFE, 13, /*RPC payload Len */ | ||
899 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
900 | 0x00, /*MT_APP_MSG */ | ||
901 | 0x0B, /*Application Endpoint */ | ||
902 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
903 | (ZCL_CLUSTER_ID_GEN_ON_OFF & 0x00ff), (ZCL_CLUSTER_ID_GEN_ON_OFF & 0xff00) | ||
904 | >> 8, 0x06, //Data Len | ||
905 | addrMode, 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command) | ||
906 | transSeqNumber++, ZCL_CMD_READ, (ATTRID_ON_OFF & 0x00ff), (ATTRID_ON_OFF | ||
907 | & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
908 | }; | ||
909 | |||
910 | calcFcs(cmd, sizeof(cmd)); | ||
911 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
912 | } | ||
913 | |||
914 | /********************************************************************* | ||
915 | * @fn zbSocGetLevel | ||
916 | * | ||
917 | * @brief Send the get level command to a ZLL light. | ||
918 | * | ||
919 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command. | ||
920 | * @param endpoint - endpoint of the Light. | ||
921 | * @param addrMode - Unicast or Group cast. | ||
922 | * | ||
923 | * @return none | ||
924 | */ | ||
925 | void zbSocGetLevel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode) | ||
926 | { | ||
927 | uint8_t cmd[] = | ||
928 | { 0xFE, 13, /*RPC payload Len */ | ||
929 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
930 | 0x00, /*MT_APP_MSG */ | ||
931 | 0x0B, /*Application Endpoint */ | ||
932 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
933 | (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0x00ff), (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL | ||
934 | & 0xff00) >> 8, | ||
935 | 0x06, //Data Len | ||
936 | addrMode, | ||
937 | 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command) | ||
938 | transSeqNumber++, ZCL_CMD_READ, (ATTRID_LEVEL_CURRENT_LEVEL & 0x00ff), | ||
939 | (ATTRID_LEVEL_CURRENT_LEVEL & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
940 | }; | ||
941 | |||
942 | calcFcs(cmd, sizeof(cmd)); | ||
943 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
944 | } | ||
945 | |||
946 | /********************************************************************* | ||
947 | * @fn zbSocGetHue | ||
948 | * | ||
949 | * @brief Send the get hue command to a ZLL light. | ||
950 | * | ||
951 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command. | ||
952 | * @param endpoint - endpoint of the Light. | ||
953 | * @param addrMode - Unicast or Group cast. | ||
954 | * | ||
955 | * @return none | ||
956 | */ | ||
957 | void zbSocGetHue(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode) | ||
958 | { | ||
959 | uint8_t cmd[] = | ||
960 | { 0xFE, 13, /*RPC payload Len */ | ||
961 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
962 | 0x00, /*MT_APP_MSG */ | ||
963 | 0x0B, /*Application Endpoint */ | ||
964 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
965 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff), | ||
966 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8, | ||
967 | 0x06, //Data Len | ||
968 | addrMode, | ||
969 | 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command) | ||
970 | transSeqNumber++, ZCL_CMD_READ, (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE | ||
971 | & 0x00ff), (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE & 0xff00) >> 8, | ||
972 | 0x00 //FCS - fill in later | ||
973 | }; | ||
974 | |||
975 | calcFcs(cmd, sizeof(cmd)); | ||
976 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
977 | } | ||
978 | |||
979 | /********************************************************************* | ||
980 | * @fn zbSocGetSat | ||
981 | * | ||
982 | * @brief Send the get saturation command to a ZLL light. | ||
983 | * | ||
984 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command. | ||
985 | * @param endpoint - endpoint of the Light. | ||
986 | * @param addrMode - Unicast or Group cast. | ||
987 | * | ||
988 | * @return none | ||
989 | */ | ||
990 | void zbSocGetSat(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode) | ||
991 | { | ||
992 | uint8_t cmd[] = | ||
993 | { 0xFE, 13, /*RPC payload Len */ | ||
994 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
995 | 0x00, /*MT_APP_MSG */ | ||
996 | 0x0B, /*Application Endpoint */ | ||
997 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
998 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff), | ||
999 | (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8, | ||
1000 | 0x06, //Data Len | ||
1001 | addrMode, | ||
1002 | 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command) | ||
1003 | transSeqNumber++, ZCL_CMD_READ, | ||
1004 | (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION & 0x00ff), | ||
1005 | (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION & 0xff00) >> 8, 0x00 //FCS - fill in later | ||
1006 | }; | ||
1007 | |||
1008 | calcFcs(cmd, sizeof(cmd)); | ||
1009 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
1010 | } | ||
1011 | |||
1012 | /********************************************************************* | ||
1013 | * @fn zbSocGetModel | ||
1014 | * | ||
1015 | * @brief Send the get saturation command to a ZLL light. | ||
1016 | * | ||
1017 | * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command. | ||
1018 | * @param endpoint - endpoint of the Light. | ||
1019 | * @param addrMode - Unicast or Group cast. | ||
1020 | * | ||
1021 | * @return none | ||
1022 | */ | ||
1023 | void zbSocGetModel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode) | ||
1024 | { | ||
1025 | uint8_t cmd[] = | ||
1026 | { 0xFE, 13, /*RPC payload Len */ | ||
1027 | 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ | ||
1028 | 0x00, /*MT_APP_MSG */ | ||
1029 | 0x0B, /*Application Endpoint */ | ||
1030 | (dstAddr & 0x00ff), (dstAddr & 0xff00) >> 8, endpoint, /*Dst EP */ | ||
1031 | (ZCL_CLUSTER_ID_GEN_BASIC & 0x00ff), | ||
1032 | (ZCL_CLUSTER_ID_GEN_BASIC & 0xff00) >> 8, | ||
1033 | 0x06, //Data Len | ||
1034 | addrMode, | ||
1035 | 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL foundation command) | ||
1036 | transSeqNumber++, ZCL_CMD_READ, | ||
1037 | (ATTRID_BASIC_MODEL_ID & 0x00ff), | ||
1038 | (ATTRID_BASIC_MODEL_ID & 0xff00) >> 8, | ||
1039 | 0x00 //FCS - fill in later | ||
1040 | }; | ||
1041 | |||
1042 | //printf("zbSocGetModel: dstAddr:%x, endpoint:%x, addrMode:%x\n", dstAddr, endpoint, addrMode); | ||
1043 | |||
1044 | calcFcs(cmd, sizeof(cmd)); | ||
1045 | zbSocTransportWrite(cmd, sizeof(cmd)); | ||
1046 | } | ||
1047 | |||
1048 | /************************************************************************************************* | ||
1049 | * @fn processRpcSysAppTlInd() | ||
1050 | * | ||
1051 | * @brief process the TL Indication from the ZLL controller | ||
1052 | * | ||
1053 | * @param none | ||
1054 | * | ||
1055 | * @return length of current Rx Buffer | ||
1056 | *************************************************************************************************/ | ||
1057 | static void processRpcSysAppTlInd(uint8_t *TlIndBuff) | ||
1058 | { | ||
1059 | epInfo_t epInfo; | ||
1060 | |||
1061 | epInfo.nwkAddr = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]); | ||
1062 | TlIndBuff += 2; | ||
1063 | epInfo.endpoint = *TlIndBuff++; | ||
1064 | epInfo.profileID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]); | ||
1065 | TlIndBuff += 2; | ||
1066 | epInfo.deviceID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]); | ||
1067 | TlIndBuff += 2; | ||
1068 | epInfo.version = *TlIndBuff++; | ||
1069 | epInfo.status = *TlIndBuff++; | ||
1070 | |||
1071 | if (zbSocCb.pfnTlIndicationCb) | ||
1072 | { | ||
1073 | zbSocCb.pfnTlIndicationCb(&epInfo); | ||
1074 | } | ||
1075 | } | ||
1076 | |||
1077 | /************************************************************************************************* | ||
1078 | * @fn processRpcSysAppZcl() | ||
1079 | * | ||
1080 | * @brief process the ZCL Rsp from the ZLL controller | ||
1081 | * | ||
1082 | * @param none | ||
1083 | * | ||
1084 | * @return length of current Rx Buffer | ||
1085 | *************************************************************************************************/ | ||
1086 | static void processRpcSysAppZcl(uint8_t *zclRspBuff) | ||
1087 | { | ||
1088 | uint8_t zclHdrLen = 3; | ||
1089 | uint16_t nwkAddr, clusterID; | ||
1090 | uint8_t endpoint, zclFrameLen, zclFrameFrameControl; | ||
1091 | |||
1092 | //printf("processRpcSysAppZcl++\n"); | ||
1093 | |||
1094 | //This is a ZCL response | ||
1095 | |||
1096 | //Index past app EP | ||
1097 | zclRspBuff++; | ||
1098 | nwkAddr = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]); | ||
1099 | zclRspBuff += 2; | ||
1100 | |||
1101 | endpoint = *zclRspBuff++; | ||
1102 | clusterID = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]); | ||
1103 | zclRspBuff += 2; | ||
1104 | |||
1105 | zclFrameLen = *zclRspBuff++; | ||
1106 | zclFrameFrameControl = *zclRspBuff++; | ||
1107 | //is it manufacturer specific | ||
1108 | if (zclFrameFrameControl & (1 << 2)) | ||
1109 | { | ||
1110 | //currently not supported shown for reference | ||
1111 | uint16_t ManSpecCode; | ||
1112 | //manu spec code | ||
1113 | ManSpecCode = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]); | ||
1114 | zclRspBuff += 2; | ||
1115 | //Manufacturer specif commands have 2 extra byte in te header | ||
1116 | zclHdrLen += 2; | ||
1117 | |||
1118 | //supress warning | ||
1119 | (void)ManSpecCode; | ||
1120 | } | ||
1121 | |||
1122 | //is this a foundation command | ||
1123 | if ((zclFrameFrameControl & 0x3) == 0) | ||
1124 | { | ||
1125 | //printf("processRpcSysAppZcl: Foundation messagex\n"); | ||
1126 | processRpcSysAppZclFoundation(zclRspBuff, zclFrameLen, clusterID, nwkAddr, | ||
1127 | endpoint); | ||
1128 | } | ||
1129 | } | ||
1130 | |||
1131 | /************************************************************************************************* | ||
1132 | * @fn processRpcSysAppZclFoundation() | ||
1133 | * | ||
1134 | * @brief process the ZCL Rsp from the ZLL controller | ||
1135 | * | ||
1136 | * @param none | ||
1137 | * | ||
1138 | * @return length of current Rx Buffer | ||
1139 | *************************************************************************************************/ | ||
1140 | static void processRpcSysAppZclFoundation(uint8_t *zclRspBuff, | ||
1141 | uint8_t zclFrameLen, uint16_t clusterID, uint16_t nwkAddr, uint8_t endpoint) | ||
1142 | { | ||
1143 | uint8_t transSeqNum, commandID; | ||
1144 | |||
1145 | transSeqNum = *zclRspBuff++; | ||
1146 | commandID = *zclRspBuff++; | ||
1147 | |||
1148 | if (commandID == ZCL_CMD_READ_RSP) | ||
1149 | { | ||
1150 | uint16_t attrID; | ||
1151 | uint8_t status; | ||
1152 | uint8_t dataType; | ||
1153 | |||
1154 | attrID = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]); | ||
1155 | zclRspBuff += 2; | ||
1156 | status = *zclRspBuff++; | ||
1157 | //get data type; | ||
1158 | dataType = *zclRspBuff++; | ||
1159 | |||
1160 | //printf("processRpcSysAppZclFoundation: clusterID:%x, attrID:%x, dataType=%x\n", clusterID, attrID, dataType); | ||
1161 | if ((clusterID == ZCL_CLUSTER_ID_GEN_BASIC) && (attrID == ATTRID_BASIC_MODEL_ID) | ||
1162 | && (dataType == ZCL_DATATYPE_CHAR_STR)) | ||
1163 | { | ||
1164 | if (zbSocCb.pfnZclGetModelCb) | ||
1165 | { | ||
1166 | zbSocCb.pfnZclGetModelCb(&zclRspBuff[0]); | ||
1167 | } | ||
1168 | } | ||
1169 | else if ((clusterID == ZCL_CLUSTER_ID_GEN_ON_OFF) && (attrID == ATTRID_ON_OFF) | ||
1170 | && (dataType == ZCL_DATATYPE_BOOLEAN)) | ||
1171 | { | ||
1172 | if (zbSocCb.pfnZclGetStateCb) | ||
1173 | { | ||
1174 | uint8_t state = zclRspBuff[0]; | ||
1175 | zbSocCb.pfnZclGetStateCb(state, nwkAddr, endpoint); | ||
1176 | } | ||
1177 | } | ||
1178 | else if ((clusterID == ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL) | ||
1179 | && (attrID == ATTRID_LEVEL_CURRENT_LEVEL) | ||
1180 | && (dataType == ZCL_DATATYPE_UINT8)) | ||
1181 | { | ||
1182 | if (zbSocCb.pfnZclGetLevelCb) | ||
1183 | { | ||
1184 | uint8_t level = zclRspBuff[0]; | ||
1185 | zbSocCb.pfnZclGetLevelCb(level, nwkAddr, endpoint); | ||
1186 | } | ||
1187 | } | ||
1188 | else if ((clusterID == ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL) | ||
1189 | && (attrID == ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE) | ||
1190 | && (dataType == ZCL_DATATYPE_UINT8)) | ||
1191 | { | ||
1192 | if (zbSocCb.pfnZclGetHueCb) | ||
1193 | { | ||
1194 | uint8_t hue = zclRspBuff[0]; | ||
1195 | zbSocCb.pfnZclGetHueCb(hue, nwkAddr, endpoint); | ||
1196 | } | ||
1197 | } | ||
1198 | else if ((clusterID == ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL) | ||
1199 | && (attrID == ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION) | ||
1200 | && (dataType == ZCL_DATATYPE_UINT8)) | ||
1201 | { | ||
1202 | if (zbSocCb.pfnZclGetSatCb) | ||
1203 | { | ||
1204 | uint8_t sat = zclRspBuff[0]; | ||
1205 | zbSocCb.pfnZclGetSatCb(sat, nwkAddr, endpoint); | ||
1206 | } | ||
1207 | } | ||
1208 | else | ||
1209 | { | ||
1210 | //unsupported ZCL Read Rsp | ||
1211 | printf("processRpcSysAppZclFoundation: Unsupported ZCL Rsp\n"); | ||
1212 | } | ||
1213 | } | ||
1214 | else | ||
1215 | { | ||
1216 | //unsupported ZCL Rsp | ||
1217 | printf("processRpcSysAppZclFoundation: Unsupported ZCL Rsp"); | ||
1218 | ; | ||
1219 | } | ||
1220 | |||
1221 | return; | ||
1222 | } | ||
1223 | |||
1224 | /************************************************************************************************* | ||
1225 | * @fn processRpcSysZdoEndDeviceAnnceInd | ||
1226 | * | ||
1227 | * @brief read and process the RPC ZDO message from the ZLL controller | ||
1228 | * | ||
1229 | * @param none | ||
1230 | * | ||
1231 | * @return length of current Rx Buffer | ||
1232 | *************************************************************************************************/ | ||
1233 | void processRpcSysZdoEndDeviceAnnceInd(uint8_t *EndDeviceAnnceIndBuff) | ||
1234 | { | ||
1235 | epInfo_t epInfo = { 0 }; | ||
1236 | uint8_t i; | ||
1237 | |||
1238 | EndDeviceAnnceIndBuff += 2; | ||
1239 | epInfo.nwkAddr = | ||
1240 | BUILD_UINT16(EndDeviceAnnceIndBuff[0], EndDeviceAnnceIndBuff[1]); | ||
1241 | EndDeviceAnnceIndBuff += 2; | ||
1242 | |||
1243 | printf("processRpcSysZdoEndDeviceAnnceInd nwkAddr: %x, IEEE Addr: ", | ||
1244 | epInfo.nwkAddr); | ||
1245 | |||
1246 | for (i = 0; i < 8; i++) | ||
1247 | { | ||
1248 | epInfo.IEEEAddr[i] = *EndDeviceAnnceIndBuff++; | ||
1249 | printf("%x", epInfo.IEEEAddr[i]); | ||
1250 | if (i < 7) printf(":"); | ||
1251 | } | ||
1252 | printf("\n"); | ||
1253 | |||
1254 | if (zbSocCb.pfnNewDevIndicationCb) | ||
1255 | { | ||
1256 | zbSocCb.pfnNewDevIndicationCb(&epInfo); | ||
1257 | } | ||
1258 | |||
1259 | } | ||
1260 | |||
1261 | /************************************************************************************************* | ||
1262 | * @fn processRpcSysZdoActiveEPRsp | ||
1263 | * | ||
1264 | * @brief read and process the RPC ZDO message from the ZLL controller | ||
1265 | * | ||
1266 | * @param none | ||
1267 | * | ||
1268 | * @return length of current Rx Buffer | ||
1269 | *************************************************************************************************/ | ||
1270 | void processRpcSysZdoActiveEPRsp(uint8_t *ActiveEPRspBuff) | ||
1271 | { | ||
1272 | uint16_t nwkAddr; | ||
1273 | uint8_t epCount; | ||
1274 | |||
1275 | nwkAddr = BUILD_UINT16(ActiveEPRspBuff[0], ActiveEPRspBuff[1]); | ||
1276 | ActiveEPRspBuff += 2; | ||
1277 | epCount = *ActiveEPRspBuff; | ||
1278 | |||
1279 | printf("processRpcSysZdoActiveEPRsp nwkAddr: %x, Num Ep's: %d\n", nwkAddr, | ||
1280 | epCount); | ||
1281 | |||
1282 | //Can be used to check all Ep's have associated ZdoSimpleDesc. | ||
1283 | } | ||
1284 | |||
1285 | /************************************************************************************************* | ||
1286 | * @fn processRpcSysZdoSimpleDescRsp | ||
1287 | * | ||
1288 | * @brief read and process the RPC ZDO message from the ZLL controller | ||
1289 | * | ||
1290 | * @param none | ||
1291 | * | ||
1292 | * @return length of current Rx Buffer | ||
1293 | *************************************************************************************************/ | ||
1294 | void processRpcSysZdoSimpleDescRsp(uint8_t *SimpleDescRspBuff) | ||
1295 | { | ||
1296 | epInfo_t epInfo; | ||
1297 | uint8_t numInputClusters, numOutputClusters, clusterIdx; | ||
1298 | uint16_t *inClusters, *outClusters; | ||
1299 | |||
1300 | SimpleDescRspBuff += 2; //src address | ||
1301 | epInfo.status = *SimpleDescRspBuff++; //status..offset 2 | ||
1302 | epInfo.nwkAddr = BUILD_UINT16(SimpleDescRspBuff[0], SimpleDescRspBuff[1]); //network address | ||
1303 | SimpleDescRspBuff += 2; //increment | ||
1304 | //printf("processRpcSysZdoSimpleDescRsp: Length:%x \n",SimpleDescRspBuff[0] ); | ||
1305 | SimpleDescRspBuff += 1; | ||
1306 | epInfo.endpoint = *SimpleDescRspBuff++; //end point | ||
1307 | epInfo.profileID = BUILD_UINT16(SimpleDescRspBuff[0], SimpleDescRspBuff[1]); //profile id | ||
1308 | SimpleDescRspBuff += 2; | ||
1309 | epInfo.deviceID = BUILD_UINT16(SimpleDescRspBuff[0], SimpleDescRspBuff[1]); //device id | ||
1310 | SimpleDescRspBuff += 2; | ||
1311 | epInfo.version = *SimpleDescRspBuff++; | ||
1312 | // epInfo.status = *TlIndBuff++; | ||
1313 | epInfo.deviceName = NULL; | ||
1314 | |||
1315 | printf("processRpcSysZdoSimpleDescRsp: nwkAddr:%x endpoint:%x\n", epInfo.nwkAddr, epInfo.endpoint); | ||
1316 | |||
1317 | numInputClusters = *SimpleDescRspBuff++; | ||
1318 | inClusters = (uint16_t*) malloc(2*numInputClusters); | ||
1319 | if(inClusters) | ||
1320 | { | ||
1321 | printf("processRpcSysZdoSimpleDescRsp: inClusters[%d]:\n", numInputClusters); | ||
1322 | for(clusterIdx = 0; clusterIdx < numInputClusters; clusterIdx++) | ||
1323 | { | ||
1324 | inClusters[clusterIdx] = BUILD_UINT16(SimpleDescRspBuff[0], SimpleDescRspBuff[1]); //profile id | ||
1325 | SimpleDescRspBuff += 2; | ||
1326 | printf("0x%x ", inClusters[clusterIdx]); | ||
1327 | } | ||
1328 | } | ||
1329 | printf("\n"); | ||
1330 | |||
1331 | numOutputClusters = *SimpleDescRspBuff++; | ||
1332 | outClusters = (uint16_t*) malloc(2*numOutputClusters); | ||
1333 | if(outClusters) | ||
1334 | { | ||
1335 | printf("processRpcSysZdoSimpleDescRsp: outClusters[%d]:\n", numOutputClusters); | ||
1336 | for(clusterIdx = 0; clusterIdx < numOutputClusters; clusterIdx++) | ||
1337 | { | ||
1338 | outClusters[clusterIdx] = BUILD_UINT16(SimpleDescRspBuff[0], SimpleDescRspBuff[1]); //profile id | ||
1339 | SimpleDescRspBuff += 2; | ||
1340 | printf("0x%x ", outClusters[clusterIdx]); | ||
1341 | } | ||
1342 | } | ||
1343 | printf("\n"); | ||
1344 | |||
1345 | //if this is the TL endpoint then ignore it | ||
1346 | if( !((numInputClusters == 1) && (numOutputClusters == 1) && (epInfo.profileID) == (0xC05E)) ) | ||
1347 | { | ||
1348 | if (zbSocCb.pfnZdoSimpleDescRspCb) | ||
1349 | { | ||
1350 | zbSocCb.pfnZdoSimpleDescRspCb(&epInfo); | ||
1351 | } | ||
1352 | } | ||
1353 | |||
1354 | if(inClusters) | ||
1355 | { | ||
1356 | free(inClusters); | ||
1357 | } | ||
1358 | if(outClusters) | ||
1359 | { | ||
1360 | free(outClusters); | ||
1361 | } | ||
1362 | } | ||
1363 | |||
1364 | void processRpcSysZdoLeaveInd(uint8_t *LeaveIndRspBuff) | ||
1365 | { | ||
1366 | uint16_t nwkAddr; | ||
1367 | |||
1368 | nwkAddr = BUILD_UINT16(LeaveIndRspBuff[0], LeaveIndRspBuff[1]); | ||
1369 | LeaveIndRspBuff += 2; | ||
1370 | |||
1371 | printf("processRpcSysZdoLeaveInd nwkAddr: %x\n", nwkAddr); | ||
1372 | |||
1373 | if (zbSocCb.pfnZdoLeaveIndCb) | ||
1374 | { | ||
1375 | zbSocCb.pfnZdoLeaveIndCb(nwkAddr); | ||
1376 | } | ||
1377 | } | ||
1378 | |||
1379 | void processRpcUtilGetDevInfoRsp(uint8_t *GetDevInfoRsp) | ||
1380 | { | ||
1381 | uint8_t ieeeAddr[8], ieeeIdx, devType, devState, status; | ||
1382 | uint16_t nwkAddr; | ||
1383 | |||
1384 | status = *GetDevInfoRsp++; | ||
1385 | |||
1386 | if(status == 0) | ||
1387 | { | ||
1388 | for(ieeeIdx = 0; ieeeIdx < 8; ieeeIdx++) | ||
1389 | { | ||
1390 | ieeeAddr[ieeeIdx] = *GetDevInfoRsp++; | ||
1391 | } | ||
1392 | |||
1393 | nwkAddr = BUILD_UINT16(GetDevInfoRsp[0], GetDevInfoRsp[1]); | ||
1394 | GetDevInfoRsp += 2; | ||
1395 | |||
1396 | devType = *GetDevInfoRsp++; | ||
1397 | |||
1398 | devState = *GetDevInfoRsp++; | ||
1399 | |||
1400 | //printf("processRpcUtilGetDevInfoRsp: status:%x devState:%x, nwkAddr:%x ieeeIdx:%x:%x:%x:%x:%x:%x:%x:%x\n", status, devState, nwkAddr, | ||
1401 | // ieeeAddr[7], ieeeAddr[6], ieeeAddr[5], ieeeAddr[4], ieeeAddr[3], ieeeAddr[2], ieeeAddr[1], ieeeAddr[0]); | ||
1402 | } | ||
1403 | |||
1404 | if (zbSocCb.pfnUtilGetDevInfoRsp) | ||
1405 | { | ||
1406 | zbSocCb.pfnUtilGetDevInfoRsp(status, nwkAddr, ieeeAddr, devType, devState); | ||
1407 | } | ||
1408 | } | ||
1409 | |||
1410 | /************************************************************************************************* | ||
1411 | * @fn processRpcSysApp() | ||
1412 | * | ||
1413 | * @brief read and process the RPC App message from the ZLL controller | ||
1414 | * | ||
1415 | * @param none | ||
1416 | * | ||
1417 | * @return length of current Rx Buffer | ||
1418 | *************************************************************************************************/ | ||
1419 | static void processRpcSysApp(uint8_t *rpcBuff) | ||
1420 | { | ||
1421 | if (rpcBuff[1] == MT_APP_ZLL_TL_IND) | ||
1422 | { | ||
1423 | processRpcSysAppTlInd(&rpcBuff[2]); | ||
1424 | } | ||
1425 | |||
1426 | else if (rpcBuff[1] == MT_APP_RSP) | ||
1427 | { | ||
1428 | processRpcSysAppZcl(&rpcBuff[2]); | ||
1429 | } | ||
1430 | else if (rpcBuff[1] == 0) | ||
1431 | { | ||
1432 | if (rpcBuff[2] == 0) | ||
1433 | { | ||
1434 | //printf("processRpcSysApp: Command Received Successfully\n\n"); | ||
1435 | } | ||
1436 | else | ||
1437 | { | ||
1438 | printf("processRpcSysApp: Command Error\n\n"); | ||
1439 | } | ||
1440 | } | ||
1441 | else | ||
1442 | { | ||
1443 | printf("processRpcSysApp: Unsupported MT App Msg\n"); | ||
1444 | } | ||
1445 | |||
1446 | return; | ||
1447 | } | ||
1448 | |||
1449 | /************************************************************************************************* | ||
1450 | * @fn processRpcSysZdo() | ||
1451 | * | ||
1452 | * @brief read and process the RPC ZDO messages from the ZLL controller | ||
1453 | * | ||
1454 | * @param none | ||
1455 | * | ||
1456 | * @return length of current Rx Buffer | ||
1457 | *************************************************************************************************/ | ||
1458 | void processRpcSysZdo(uint8_t *rpcBuff) | ||
1459 | { | ||
1460 | if (rpcBuff[1] == MT_ZDO_END_DEVICE_ANNCE_IND) | ||
1461 | { | ||
1462 | processRpcSysZdoEndDeviceAnnceInd(&rpcBuff[2]); | ||
1463 | } | ||
1464 | else if (rpcBuff[1] == MT_ZDO_ACTIVE_EP_RSP) | ||
1465 | { | ||
1466 | processRpcSysZdoActiveEPRsp(&rpcBuff[2]); | ||
1467 | } | ||
1468 | else if (rpcBuff[1] == MT_ZDO_SIMPLE_DESC_RSP) | ||
1469 | { | ||
1470 | processRpcSysZdoSimpleDescRsp(&rpcBuff[2]); | ||
1471 | } | ||
1472 | else if (rpcBuff[1] == MT_ZDO_LEAVE_IND) | ||
1473 | { | ||
1474 | processRpcSysZdoLeaveInd(&rpcBuff[2]); | ||
1475 | } | ||
1476 | else | ||
1477 | { | ||
1478 | printf("processRpcSysZdo: Unsupported MT ZDO Msg\n"); | ||
1479 | } | ||
1480 | |||
1481 | return; | ||
1482 | |||
1483 | } | ||
1484 | |||
1485 | /************************************************************************************************* | ||
1486 | * @fn processRpcSysUtil() | ||
1487 | * | ||
1488 | * @brief read and process the RPC UTIL messages from the ZLL controller | ||
1489 | * | ||
1490 | * @param none | ||
1491 | * | ||
1492 | * @return length of current Rx Buffer | ||
1493 | *************************************************************************************************/ | ||
1494 | void processRpcSysUtil(uint8_t *rpcBuff) | ||
1495 | { | ||
1496 | if (rpcBuff[1] == MT_UTIL_GET_DEVICE_INFO) | ||
1497 | { | ||
1498 | processRpcUtilGetDevInfoRsp(&rpcBuff[2]); | ||
1499 | } | ||
1500 | else | ||
1501 | { | ||
1502 | printf("processRpcSysUtil: Unsupported MT UTIL Msg\n"); | ||
1503 | } | ||
1504 | |||
1505 | return; | ||
1506 | |||
1507 | } | ||
1508 | |||
1509 | /* @fn processRpcSysDbg() | ||
1510 | * | ||
1511 | * @brief read and process the RPC debug message from the ZLL controller | ||
1512 | * | ||
1513 | * @param none | ||
1514 | * | ||
1515 | * @return length of current Rx Buffer | ||
1516 | *************************************************************************************************/ | ||
1517 | static void processRpcSysDbg(uint8_t *rpcBuff) | ||
1518 | { | ||
1519 | if (rpcBuff[1] == MT_DEBUG_MSG) | ||
1520 | { | ||
1521 | //we got a debug string | ||
1522 | printf("lcd_debug message from zll controller: %s\n", | ||
1523 | (char*) &(rpcBuff[2])); | ||
1524 | } | ||
1525 | else if (rpcBuff[1] == 0) | ||
1526 | { | ||
1527 | if (rpcBuff[2] == 0) | ||
1528 | { | ||
1529 | //printf("processRpcSysDbg: Command Received Successfully\n\n"); | ||
1530 | } | ||
1531 | else | ||
1532 | { | ||
1533 | printf("processRpcSysDbg: Command Error\n\n"); | ||
1534 | } | ||
1535 | } | ||
1536 | else | ||
1537 | { | ||
1538 | printf("processRpcSysDbg: Unsupported MT App Msg\n"); | ||
1539 | } | ||
1540 | } | ||
1541 | |||
1542 | /************************************************************************************************* | ||
1543 | * @fn zbSocProcessRpc() | ||
1544 | * | ||
1545 | * @brief read and process the RPC from the ZLL controller | ||
1546 | * | ||
1547 | * @param none | ||
1548 | * | ||
1549 | * @return length of current Rx Buffer | ||
1550 | *************************************************************************************************/ | ||
1551 | void zbSocProcessRpc(void) | ||
1552 | { | ||
1553 | uint8_t rpcLen, bytesRead, sofByte, *rpcBuff, rpcBuffIdx; | ||
1554 | static uint8_t retryAttempts = 0; | ||
1555 | |||
1556 | //read first byte and check it is a SOF | ||
1557 | read(serialPortFd, &sofByte, 1); | ||
1558 | if (sofByte == MT_RPC_SOF) | ||
1559 | { | ||
1560 | retryAttempts = 0; | ||
1561 | |||
1562 | //read len | ||
1563 | bytesRead = read(serialPortFd, &rpcLen, 1); | ||
1564 | |||
1565 | if (bytesRead == 1) | ||
1566 | { | ||
1567 | //allocating RPC payload (+ cmd0, cmd1 and fcs) | ||
1568 | rpcLen += 3; | ||
1569 | |||
1570 | rpcBuff = malloc(rpcLen); | ||
1571 | |||
1572 | //non blocking read, so we need to wait for the rpc to be read | ||
1573 | rpcBuffIdx = 0; | ||
1574 | while (rpcLen > 0) | ||
1575 | { | ||
1576 | //read rpc | ||
1577 | bytesRead = read(serialPortFd, &(rpcBuff[rpcBuffIdx]), rpcLen); | ||
1578 | |||
1579 | //check for error | ||
1580 | if (bytesRead > rpcLen) | ||
1581 | { | ||
1582 | //there was an error | ||
1583 | printf("zbSocProcessRpc: read of %d bytes failed - %s\n", rpcLen, | ||
1584 | strerror(errno)); | ||
1585 | |||
1586 | if (retryAttempts++ < 5) | ||
1587 | { | ||
1588 | //sleep for 10ms | ||
1589 | usleep(10000); | ||
1590 | //try again | ||
1591 | bytesRead = 0; | ||
1592 | } | ||
1593 | else | ||
1594 | { | ||
1595 | //something went wrong. | ||
1596 | printf("zbSocProcessRpc: failed\n"); | ||
1597 | free(rpcBuff); | ||
1598 | return; | ||
1599 | } | ||
1600 | } | ||
1601 | |||
1602 | rpcLen -= bytesRead; | ||
1603 | rpcBuffIdx += bytesRead; | ||
1604 | } | ||
1605 | |||
1606 | //printf("zbSocProcessRpc: Processing CMD0:%x, CMD1:%x\n", rpcBuff[0], | ||
1607 | // rpcBuff[1]); | ||
1608 | //Read CMD0 | ||
1609 | switch (rpcBuff[0] & MT_RPC_SUBSYSTEM_MASK) | ||
1610 | { | ||
1611 | case MT_RPC_SYS_DBG: | ||
1612 | { | ||
1613 | processRpcSysDbg(rpcBuff); | ||
1614 | break; | ||
1615 | } | ||
1616 | case MT_RPC_SYS_APP: | ||
1617 | { | ||
1618 | processRpcSysApp(rpcBuff); | ||
1619 | break; | ||
1620 | } | ||
1621 | |||
1622 | case MT_RPC_SYS_ZDO: | ||
1623 | { | ||
1624 | processRpcSysZdo(rpcBuff); | ||
1625 | break; | ||
1626 | } | ||
1627 | |||
1628 | case MT_RPC_SYS_UTIL: | ||
1629 | { | ||
1630 | processRpcSysUtil(rpcBuff); | ||
1631 | break; | ||
1632 | } | ||
1633 | |||
1634 | default: | ||
1635 | { | ||
1636 | printf("zbSocProcessRpc: CMD0:%x, CMD1:%x, not handled\n", rpcBuff[0], | ||
1637 | rpcBuff[1]); | ||
1638 | break; | ||
1639 | } | ||
1640 | } | ||
1641 | |||
1642 | free(rpcBuff); | ||
1643 | } | ||
1644 | else | ||
1645 | { | ||
1646 | printf("zbSocProcessRpc: No valid Start Of Frame found\n"); | ||
1647 | } | ||
1648 | } | ||
1649 | |||
1650 | return; | ||
1651 | } | ||
1652 | |||
diff --git a/zbSocDriver/zbSocCmd.h b/zbSocDriver/zbSocCmd.h new file mode 100755 index 0000000..e622206 --- /dev/null +++ b/zbSocDriver/zbSocCmd.h | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | * zbSocCmd.h | ||
3 | * | ||
4 | * This module contains the API for the zll SoC Host Interface. | ||
5 | * | ||
6 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ | ||
7 | * | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
22 | * its contributors may be used to endorse or promote products derived | ||
23 | * from this software without specific prior written permission. | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
36 | * | ||
37 | */ | ||
38 | |||
39 | #ifndef ZLLSOCCMD_H | ||
40 | #define ZLLSOCCMD_H | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | extern "C" { | ||
44 | #endif | ||
45 | |||
46 | #include <stdint.h> | ||
47 | |||
48 | /********************************************************************/ | ||
49 | // ZLL Soc Types | ||
50 | typedef enum | ||
51 | { | ||
52 | afAddrNotPresent = 0, | ||
53 | afAddrGroup = 1, | ||
54 | afAddr16Bit = 2, | ||
55 | afAddr64Bit = 3, | ||
56 | afAddrBroadcast = 15 | ||
57 | } afAddrMode_t; | ||
58 | |||
59 | #define Z_EXTADDR_LEN 8 | ||
60 | |||
61 | // Endpoint information record entry | ||
62 | typedef struct { | ||
63 | uint8_t IEEEAddr[8]; | ||
64 | uint16_t nwkAddr; // Network address | ||
65 | uint8_t endpoint; // Endpoint identifier | ||
66 | uint16_t profileID; // Profile identifier | ||
67 | uint16_t deviceID; // Device identifier | ||
68 | uint8_t version; // Version | ||
69 | char* deviceName; | ||
70 | uint8_t status; | ||
71 | uint8_t flags; | ||
72 | } epInfo_t; | ||
73 | |||
74 | typedef struct | ||
75 | { | ||
76 | epInfo_t * epInfo; | ||
77 | uint16_t prevNwkAddr; // Precious network address | ||
78 | uint8_t type; // new / updated / old | ||
79 | } epInfoExtended_t; | ||
80 | |||
81 | #define EP_INFO_TYPE_EXISTING 0 | ||
82 | #define EP_INFO_TYPE_NEW 1 | ||
83 | #define EP_INFO_TYPE_UPDATED 2 | ||
84 | #define EP_INFO_TYPE_REMOVED 4 | ||
85 | |||
86 | typedef uint8_t (*zbSocTlIndicationCb_t)(epInfo_t *epInfo); | ||
87 | typedef uint8_t (*zllNewDevIndicationCb_t)(epInfo_t *epInfo); | ||
88 | typedef uint8_t (*zbSocZclGetStateCb_t)(uint8_t state, uint16_t nwkAddr, | ||
89 | uint8_t endpoint); | ||
90 | typedef uint8_t (*zbSocZclGetLevelCb_t)(uint8_t level, uint16_t nwkAddr, | ||
91 | uint8_t endpoint); | ||
92 | typedef uint8_t (*zbSocZclGetHueCb_t)(uint8_t hue, uint16_t nwkAddr, | ||
93 | uint8_t endpoint); | ||
94 | typedef uint8_t (*zbSocZclGetSatCb_t)(uint8_t sat, uint16_t nwkAddr, | ||
95 | uint8_t endpoint); | ||
96 | typedef uint8_t (*zdoSimpleDescRspCb_t)(epInfo_t *epInfo); | ||
97 | typedef uint8_t (*zdoLeaveIndCb_t)(uint16_t nwkAddr); | ||
98 | typedef uint8_t (*utilGetDevInfoRspcb_t) (uint8_t status, uint16_t nwkAddr, uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState); | ||
99 | typedef uint8_t (*zbSocZclGetModelCb_t)(uint8_t *ModelId); | ||
100 | |||
101 | typedef struct { | ||
102 | zbSocTlIndicationCb_t pfnTlIndicationCb; // TouchLink Indication callback | ||
103 | zllNewDevIndicationCb_t pfnNewDevIndicationCb; // New device Indication callback | ||
104 | zbSocZclGetStateCb_t pfnZclGetStateCb; // ZCL response callback for get State | ||
105 | zbSocZclGetLevelCb_t pfnZclGetLevelCb; // ZCL response callback for get Level | ||
106 | zbSocZclGetHueCb_t pfnZclGetHueCb; // ZCL response callback for get Hue | ||
107 | zbSocZclGetSatCb_t pfnZclGetSatCb; // ZCL response callback for get Sat | ||
108 | zdoSimpleDescRspCb_t pfnZdoSimpleDescRspCb; // ZCL callback for simple desc response | ||
109 | zdoLeaveIndCb_t pfnZdoLeaveIndCb; // ZCL callback for simple desc response | ||
110 | utilGetDevInfoRspcb_t pfnUtilGetDevInfoRsp; | ||
111 | zbSocZclGetModelCb_t pfnZclGetModelCb; // | ||
112 | } zbSocCallbacks_t; | ||
113 | |||
114 | |||
115 | /********************************************************************/ | ||
116 | // ZLL Soc API | ||
117 | //configuration API's | ||
118 | int32_t zbSocOpen(char *devicePath); | ||
119 | void zbSocRegisterCallbacks(zbSocCallbacks_t zbSocCallbacks); | ||
120 | void zbSocClose(void); | ||
121 | void zbSocProcessRpc(void); | ||
122 | |||
123 | //ZLL API's | ||
124 | void zbSocTouchLink(void); | ||
125 | void zbSocResetToFn(void); | ||
126 | void zbSocSendResetToFn(void); | ||
127 | void zbSocOpenNwk(uint8_t duration); | ||
128 | //ZCL Set API's | ||
129 | void zbSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, | ||
130 | uint8_t addrMode); | ||
131 | void zbSocSetLevel(uint8_t level, uint16_t time, uint16_t dstAddr, | ||
132 | uint8_t endpoint, uint8_t addrMode); | ||
133 | void zbSocSetHue(uint8_t hue, uint16_t time, uint16_t dstAddr, | ||
134 | uint8_t endpoint, uint8_t addrMode); | ||
135 | void zbSocSetSat(uint8_t sat, uint16_t time, uint16_t dstAddr, | ||
136 | uint8_t endpoint, uint8_t addrMode); | ||
137 | void zbSocSetHueSat(uint8_t hue, uint8_t sat, uint16_t time, uint16_t dstAddr, | ||
138 | uint8_t endpoint, uint8_t addrMode); | ||
139 | void zbSocAddGroup(uint16_t groupId, uint16_t dstAddr, uint8_t endpoint, | ||
140 | uint8_t addrMode); | ||
141 | void zbSocStoreScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, | ||
142 | uint8_t endpoint, uint8_t addrMode); | ||
143 | void zbSocRecallScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, | ||
144 | uint8_t endpoint, uint8_t addrMode); | ||
145 | void zbSocBind(uint16_t srcNwkAddr, uint8_t srcEndpoint, uint8_t srcIEEE[8], | ||
146 | uint8_t dstEndpoint, uint8_t dstIEEE[8], uint16_t clusterID); | ||
147 | void zbSocSendIdentify(uint16_t identifyTime, uint16_t dstAddr, | ||
148 | uint8_t endpoint, uint8_t addrMode); | ||
149 | void zbSocSendIdentifyEffect(uint8_t effect, uint8_t effectVarient, uint16_t dstAddr, | ||
150 | uint8_t endpoint, uint8_t addrMode); | ||
151 | void zbSocGetInfo(void); | ||
152 | void zbSocGetModel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode); | ||
153 | |||
154 | //ZCL Get API's | ||
155 | void zbSocGetState(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode); | ||
156 | void zbSocGetLevel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode); | ||
157 | void zbSocGetHue(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode); | ||
158 | void zbSocGetSat(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode); | ||
159 | #ifdef __cplusplus | ||
160 | } | ||
161 | #endif | ||
162 | |||
163 | #endif /* ZLLSOCCMD_H */ | ||