add support for control bridge FW conrolbridge
authorTonyCave <t-cave@ti.com>
Thu, 28 Nov 2013 10:26:44 +0000 (10:26 +0000)
committerTonyCave <t-cave@ti.com>
Thu, 28 Nov 2013 10:26:44 +0000 (10:26 +0000)
146 files changed:
Manifest.pdf [changed mode: 0644->0755]
client/AndroidClients/LightingController/.classpath [changed mode: 0644->0755]
client/AndroidClients/LightingController/.project [changed mode: 0644->0755]
client/AndroidClients/LightingController/.settings/org.eclipse.jdt.core.prefs [changed mode: 0644->0755]
client/AndroidClients/LightingController/AndroidManifest.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/AndroidManifest.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/BuildConfig.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$anim.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$array.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$attr.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeGroup.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$5.class [new file with mode: 0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$6.class [new file with mode: 0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$7.class [new file with mode: 0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeScene.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$2.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$3.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect$4.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/optionsMenu.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask$1.class [new file with mode: 0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask.class [new file with mode: 0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class [changed mode: 0644->0755]
client/AndroidClients/LightingController/default.properties [changed mode: 0644->0755]
client/AndroidClients/LightingController/gen/com/lightingcontroller/BuildConfig.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/gen/com/lightingcontroller/R.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/lint.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/proguard.cfg [changed mode: 0644->0755]
client/AndroidClients/LightingController/project.properties [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/animation_enter_l.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/animation_enter_r.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/animation_leave_l.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/animation_leave_r.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/popup_in.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/anim/popup_out.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_add.png [new file with mode: 0755]
client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_bind.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_group.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_list_devices.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_scene.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/layoutborder.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-hdpi/tizllicon.bmp [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-ldpi/layoutborder.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-ldpi/tizllicon.bmp [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/background.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/butt_down.9.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/butt_high.9.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/butt_norm.9.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/button9.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/popup.9.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/tilogo.png [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/drawable-mdpi/tizllicon.bmp [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/bindview.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/groupview.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/main.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/optionmenu.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/popup.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/sceneview.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/zllmain.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/layout/zllmainportraite.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/values/strings.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/res/values/styles.xml [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/ColourPicker.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/LightingController.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeAssistant.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeDevice.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeGroup.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeNotification.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeScene.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/bindSelect.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/groupSelect.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/optionsMenu.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/sceneSelect.java [changed mode: 0644->0755]
client/AndroidClients/LightingController/src/com/lightingcontroller/zllMain.java [changed mode: 0644->0755]
client/CClients/Source/socket_client.c [changed mode: 0644->0755]
client/CClients/Source/socket_client.h [changed mode: 0644->0755]
client/CClients/lightFlashCmdLine/Source/flashled.c [changed mode: 0644->0755]
client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile [changed mode: 0644->0755]
client/CClients/listDevsCmdLine/Source/listdevs.c [changed mode: 0644->0755]
client/CClients/listDevsCmdLine/i486-linux-gnu/makefile [changed mode: 0644->0755]
client/CClients/openNetwork/Source/openNetwork.c [new file with mode: 0755]
client/CClients/openNetwork/i486-linux-gnu/makefile [new file with mode: 0755]
getFwModel/getFwModel.c [new file with mode: 0755]
getFwModel/makefile [new file with mode: 0755]
server/Source/SimpleDB.c [new file with mode: 0755]
server/Source/SimpleDB.h [new file with mode: 0755]
server/Source/SimpleDBTxt.c [new file with mode: 0755]
server/Source/SimpleDBTxt.h [new file with mode: 0755]
server/Source/hal_defs.h [changed mode: 0644->0755]
server/Source/hal_types.h [changed mode: 0644->0755]
server/Source/interface_devicelist.c [changed mode: 0644->0755]
server/Source/interface_devicelist.h [changed mode: 0644->0755]
server/Source/interface_grouplist.c [changed mode: 0644->0755]
server/Source/interface_grouplist.h [changed mode: 0644->0755]
server/Source/interface_scenelist.c [changed mode: 0644->0755]
server/Source/interface_scenelist.h [changed mode: 0644->0755]
server/Source/interface_srpcserver.c [changed mode: 0644->0755]
server/Source/interface_srpcserver.h [changed mode: 0644->0755]
server/Source/socket_server.c [changed mode: 0644->0755]
server/Source/socket_server.h [changed mode: 0644->0755]
server/Source/zbController.c [new file with mode: 0755]
server/i486-linux-gnu/Makefile [changed mode: 0644->0755]
zbSocDriver/zbSocCmd.c [new file with mode: 0755]
zbSocDriver/zbSocCmd.h [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index a4763d1..ce3da48
@@ -1,8 +1,9 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-       <classpathentry kind="src" path="src"/>
-       <classpathentry kind="src" path="gen"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-       <classpathentry kind="output" path="bin/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>\r
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="src" path="gen"/>\r
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>\r
+       <classpathentry kind="output" path="bin/classes"/>\r
+</classpath>\r
old mode 100644 (file)
new mode 100755 (executable)
index baa30fb..1d3a710
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/ColourPicker.class differ
old mode 100644 (file)
new mode 100755 (executable)
index fe1d34f..60b14a1
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 05ccbad..0f34055
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController$waitRspTask.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 9cdb686..aa4167b
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/LightingController.class differ
old mode 100644 (file)
new mode 100755 (executable)
index a692e54..8e6dc24
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$drawable.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 9e9ccb6..db57ba3
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$id.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 4d0f706..6353fb4
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$layout.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 568ef69..c1801d9
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$string.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 6e491a1..d7e130e
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/R$style.class differ
old mode 100644 (file)
new mode 100755 (executable)
index dcefaa8..832b485
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeAssistant.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 94bd22b..a687013
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeDevice.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 03d1817..bea7621
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 57b7301..35eed7d
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$2.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 08bcf8e..2b3b1e6
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$3.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 5728e2a..0987c98
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$4.class 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 (executable)
index 0000000..6a7610f
Binary files /dev/null and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$5.class 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 (executable)
index 0000000..37ef8db
Binary files /dev/null and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$6.class 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 (executable)
index 0000000..84bd686
Binary files /dev/null and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification$7.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 17a40db..923a406
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeNotification.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 294d077..c3e85eb
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 6b1a6bd..0d5cb62
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/Zigbee/ZigbeeSrpcClient.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 13c417c..a41989a
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/bindSelect.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 1e5b0ef..882dada
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 953fcd2..87de90d
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$2.class differ
old mode 100644 (file)
new mode 100755 (executable)
index e5da882..4d427dc
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$3.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 3ee9217..012da77
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$4.class differ
old mode 100644 (file)
new mode 100755 (executable)
index a284f8f..880bfb7
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$5.class differ
old mode 100644 (file)
new mode 100755 (executable)
index b3a3b27..94a3e65
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$6.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 8e54580..bd8ce1d
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect.class differ
old mode 100644 (file)
new mode 100755 (executable)
index b94c549..794d8ff
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 67a9bf5..c9b509b
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$2.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 9c9591b..8a66c1c
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$3.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 1def5cd..49f39ca
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$4.class differ
old mode 100644 (file)
new mode 100755 (executable)
index b2270eb..861ee15
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$5.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 35a0da8..9b8d0f8
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect.class differ
old mode 100644 (file)
new mode 100755 (executable)
index ed819a7..fc3af5a
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index c79b064..620f2d2
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$2.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 4a45b81..ac26807
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$3.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 55eb520..6c88c01
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$4.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 6c06c87..c2bf6ed
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$5.class 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 (executable)
index 0000000..edcc641
Binary files /dev/null and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask$1.class 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 (executable)
index 0000000..d462643
Binary files /dev/null and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$addDeviceTask.class differ
old mode 100644 (file)
new mode 100755 (executable)
index be8981b..4071416
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask$1.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 12496d8..eff697c
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain$waitRspTask.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 1f0dfad..ab55b41
Binary files a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class and b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/zllMain.class differ
old mode 100644 (file)
new mode 100755 (executable)
index 9a7c7b9..9e0e0d6
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package com.lightingcontroller;
-
-public final class R {
-    public static final class anim {
-        public static final int animation_enter_l=0x7f040000;
-        public static final int animation_enter_r=0x7f040001;
-        public static final int animation_leave_l=0x7f040002;
-        public static final int animation_leave_r=0x7f040003;
-        public static final int popup_in=0x7f040004;
-        public static final int popup_out=0x7f040005;
-    }
-    public static final class array {
-        public static final int BUAD_Rate=0x7f060001;
-        public static final int OSC=0x7f060000;
-        public static final int Parity_Check=0x7f060002;
-    }
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int background=0x7f020000;
-        public static final int butt_down=0x7f020001;
-        public static final int butt_high=0x7f020002;
-        public static final int butt_norm=0x7f020003;
-        public static final int button9=0x7f020004;
-        public static final int ic_menu_bind=0x7f020005;
-        public static final int ic_menu_group=0x7f020006;
-        public static final int ic_menu_list_devices=0x7f020007;
-        public static final int ic_menu_scene=0x7f020008;
-        public static final int layoutborder=0x7f020009;
-        public static final int popup=0x7f02000a;
-        public static final int tilogo=0x7f02000b;
-        public static final int tizllicon=0x7f02000c;
-    }
-    public static final class id {
-        public static final int FrameLable03=0x7f080033;
-        public static final int FrameLable04=0x7f080028;
-        public static final int FrameLable06=0x7f08000c;
-        public static final int IdControlledToggle=0x7f080009;
-        public static final int IdControlledToggleText=0x7f08000a;
-        public static final int IdControllingToggle=0x7f080006;
-        public static final int IdControllingToggleText=0x7f080007;
-        public static final int IdGroupToggle=0x7f080018;
-        public static final int IdGroupToggleText=0x7f080019;
-        public static final int IdLightToggle=0x7f080016;
-        public static final int IdLightToggleText=0x7f080017;
-        public static final int addToGroupRadio=0x7f080013;
-        public static final int bindRadio=0x7f08000b;
-        public static final int colourPick=0x7f08002e;
-        public static final int controlFrame=0x7f08002c;
-        public static final int controlledDeviceSpinner=0x7f080004;
-        public static final int controllingDeviceSpinner=0x7f080002;
-        public static final int deviceChangeNameButton=0x7f08000f;
-        public static final int deviceFrame=0x7f08002a;
-        public static final int deviceIdLayout=0x7f080005;
-        public static final int deviceSpinner=0x7f08000e;
-        public static final int groupIdLayout=0x7f080008;
-        public static final int groupSpinner=0x7f080011;
-        public static final int image=0x7f08001f;
-        public static final int lightIdLayout=0x7f080015;
-        public static final int linearLayout1=0x7f08002d;
-        public static final int linearLayout1a=0x7f08002f;
-        public static final int linearLayout3=0x7f08002b;
-        public static final int linearLayout4=0x7f080021;
-        public static final int linearLayout6=0x7f080000;
-        public static final int newGroupRadio=0x7f080012;
-        public static final int newSceneRadio=0x7f080025;
-        public static final int offButton=0x7f080030;
-        public static final int onButton=0x7f080032;
-        public static final int optionMenuBinding=0x7f08001c;
-        public static final int optionMenuGroups=0x7f08001a;
-        public static final int optionMenuListDevices=0x7f08001d;
-        public static final int optionMenuScenes=0x7f08001b;
-        public static final int popup_text_box=0x7f080020;
-        public static final int radioGroup2=0x7f080024;
-        public static final int sceneRadio0=0x7f080014;
-        public static final int sceneRestoreRadio=0x7f080027;
-        public static final int sceneSelectSpinner=0x7f080023;
-        public static final int sceneStoreRadio=0x7f080026;
-        public static final int seekBarLevel=0x7f080031;
-        public static final int textViewControl=0x7f080001;
-        public static final int textViewControlled=0x7f080003;
-        public static final int textViewDev=0x7f08000d;
-        public static final int textViewGroup=0x7f080010;
-        public static final int textViewScene=0x7f080022;
-        public static final int toast_layout_root=0x7f08001e;
-        public static final int zllMainLayout=0x7f080029;
-    }
-    public static final class layout {
-        public static final int bindview=0x7f030000;
-        public static final int groupview=0x7f030001;
-        public static final int main=0x7f030002;
-        public static final int optionmenu=0x7f030003;
-        public static final int popup=0x7f030004;
-        public static final int sceneview=0x7f030005;
-        public static final int zllmain=0x7f030006;
-        public static final int zllmainportraite=0x7f030007;
-    }
-    public static final class string {
-        public static final int SelectDevice=0x7f050018;
-        public static final int SelectGroup=0x7f050019;
-        public static final int app_name=0x7f050001;
-        public static final int bt_ConfigInitial=0x7f05000d;
-        public static final int bt_startrecv=0x7f05000e;
-        public static final int bt_startsend=0x7f050010;
-        public static final int bt_stoprecv=0x7f05000f;
-        public static final int bt_stopsend=0x7f050011;
-        public static final int groupAdd=0x7f05001a;
-        public static final int hello=0x7f050000;
-        public static final int lb_BaudRate=0x7f050004;
-        public static final int lb_SendData=0x7f050003;
-        public static final int lb_osc=0x7f050005;
-        public static final int lb_paritycheck=0x7f050006;
-        public static final int m_about=0x7f05000b;
-        public static final int m_clear=0x7f05000a;
-        public static final int m_configinitial=0x7f050007;
-        public static final int m_quit=0x7f05000c;
-        public static final int m_recvdata=0x7f050009;
-        public static final int m_senddata=0x7f050008;
-        public static final int optionMenuGroupsTitle=0x7f05001c;
-        public static final int optionMenuTitle=0x7f05001b;
-        public static final int optionMuneBindingTitle=0x7f05001d;
-        public static final int optionMuneListDevicesTitle=0x7f05001e;
-        public static final int rbt_0=0x7f050012;
-        public static final int rbt_1=0x7f050013;
-        public static final int rbt_2=0x7f050014;
-        public static final int rbt_3=0x7f050015;
-        public static final int rbt_4=0x7f050016;
-        public static final int str_sendtext=0x7f050017;
-        public static final int textviewMSG=0x7f050002;
-    }
-    public static final class style {
-        public static final int Animation_Popup=0x7f070008;
-        public static final int ApplicationTheme=0x7f070000;
-        public static final int DialogMenuText=0x7f070007;
-        public static final int SideMenuText=0x7f070006;
-        public static final int StdButton=0x7f070001;
-        public static final int StdButtonIcon=0x7f070002;
-        public static final int StdButtonText=0x7f070003;
-        public static final int StdScreen=0x7f070005;
-        public static final int TitleText=0x7f070004;
-    }
-}
+/* AUTO-GENERATED FILE.  DO NOT MODIFY.\r
+ *\r
+ * This class was automatically generated by the\r
+ * aapt tool from the resource data it found.  It\r
+ * should not be modified by hand.\r
+ */\r
+\r
+package com.lightingcontroller;\r
+\r
+public final class R {\r
+    public static final class anim {\r
+        public static final int animation_enter_l=0x7f040000;\r
+        public static final int animation_enter_r=0x7f040001;\r
+        public static final int animation_leave_l=0x7f040002;\r
+        public static final int animation_leave_r=0x7f040003;\r
+        public static final int popup_in=0x7f040004;\r
+        public static final int popup_out=0x7f040005;\r
+    }\r
+    public static final class array {\r
+        public static final int BUAD_Rate=0x7f060001;\r
+        public static final int OSC=0x7f060000;\r
+        public static final int Parity_Check=0x7f060002;\r
+    }\r
+    public static final class attr {\r
+    }\r
+    public static final class drawable {\r
+        public static final int background=0x7f020000;\r
+        public static final int butt_down=0x7f020001;\r
+        public static final int butt_high=0x7f020002;\r
+        public static final int butt_norm=0x7f020003;\r
+        public static final int button9=0x7f020004;\r
+        public static final int ic_menu_add=0x7f020005;\r
+        public static final int ic_menu_bind=0x7f020006;\r
+        public static final int ic_menu_group=0x7f020007;\r
+        public static final int ic_menu_list_devices=0x7f020008;\r
+        public static final int ic_menu_scene=0x7f020009;\r
+        public static final int layoutborder=0x7f02000a;\r
+        public static final int popup=0x7f02000b;\r
+        public static final int tilogo=0x7f02000c;\r
+        public static final int tizllicon=0x7f02000d;\r
+    }\r
+    public static final class id {\r
+        public static final int FrameLable03=0x7f080034;\r
+        public static final int FrameLable04=0x7f080029;\r
+        public static final int FrameLable06=0x7f08000c;\r
+        public static final int IdControlledToggle=0x7f080009;\r
+        public static final int IdControlledToggleText=0x7f08000a;\r
+        public static final int IdControllingToggle=0x7f080006;\r
+        public static final int IdControllingToggleText=0x7f080007;\r
+        public static final int IdGroupToggle=0x7f080018;\r
+        public static final int IdGroupToggleText=0x7f080019;\r
+        public static final int IdLightToggle=0x7f080016;\r
+        public static final int IdLightToggleText=0x7f080017;\r
+        public static final int addToGroupRadio=0x7f080013;\r
+        public static final int bindRadio=0x7f08000b;\r
+        public static final int colourPick=0x7f08002f;\r
+        public static final int controlFrame=0x7f08002d;\r
+        public static final int controlledDeviceSpinner=0x7f080004;\r
+        public static final int controllingDeviceSpinner=0x7f080002;\r
+        public static final int deviceChangeNameButton=0x7f08000f;\r
+        public static final int deviceFrame=0x7f08002b;\r
+        public static final int deviceIdLayout=0x7f080005;\r
+        public static final int deviceSpinner=0x7f08000e;\r
+        public static final int groupIdLayout=0x7f080008;\r
+        public static final int groupSpinner=0x7f080011;\r
+        public static final int image=0x7f080020;\r
+        public static final int lightIdLayout=0x7f080015;\r
+        public static final int linearLayout1=0x7f08002e;\r
+        public static final int linearLayout1a=0x7f080030;\r
+        public static final int linearLayout3=0x7f08002c;\r
+        public static final int linearLayout4=0x7f080022;\r
+        public static final int linearLayout6=0x7f080000;\r
+        public static final int newGroupRadio=0x7f080012;\r
+        public static final int newSceneRadio=0x7f080026;\r
+        public static final int offButton=0x7f080031;\r
+        public static final int onButton=0x7f080033;\r
+        public static final int optionMenuAddDevice=0x7f08001a;\r
+        public static final int optionMenuBinding=0x7f08001d;\r
+        public static final int optionMenuGroups=0x7f08001b;\r
+        public static final int optionMenuListDevices=0x7f08001e;\r
+        public static final int optionMenuScenes=0x7f08001c;\r
+        public static final int popup_text_box=0x7f080021;\r
+        public static final int radioGroup2=0x7f080025;\r
+        public static final int sceneRadio0=0x7f080014;\r
+        public static final int sceneRestoreRadio=0x7f080028;\r
+        public static final int sceneSelectSpinner=0x7f080024;\r
+        public static final int sceneStoreRadio=0x7f080027;\r
+        public static final int seekBarLevel=0x7f080032;\r
+        public static final int textViewControl=0x7f080001;\r
+        public static final int textViewControlled=0x7f080003;\r
+        public static final int textViewDev=0x7f08000d;\r
+        public static final int textViewGroup=0x7f080010;\r
+        public static final int textViewScene=0x7f080023;\r
+        public static final int toast_layout_root=0x7f08001f;\r
+        public static final int zllMainLayout=0x7f08002a;\r
+    }\r
+    public static final class layout {\r
+        public static final int bindview=0x7f030000;\r
+        public static final int groupview=0x7f030001;\r
+        public static final int main=0x7f030002;\r
+        public static final int optionmenu=0x7f030003;\r
+        public static final int popup=0x7f030004;\r
+        public static final int sceneview=0x7f030005;\r
+        public static final int zllmain=0x7f030006;\r
+        public static final int zllmainportraite=0x7f030007;\r
+    }\r
+    public static final class string {\r
+        public static final int SelectDevice=0x7f050018;\r
+        public static final int SelectGroup=0x7f050019;\r
+        public static final int app_name=0x7f050001;\r
+        public static final int bt_ConfigInitial=0x7f05000d;\r
+        public static final int bt_startrecv=0x7f05000e;\r
+        public static final int bt_startsend=0x7f050010;\r
+        public static final int bt_stoprecv=0x7f05000f;\r
+        public static final int bt_stopsend=0x7f050011;\r
+        public static final int groupAdd=0x7f05001a;\r
+        public static final int hello=0x7f050000;\r
+        public static final int lb_BaudRate=0x7f050004;\r
+        public static final int lb_SendData=0x7f050003;\r
+        public static final int lb_osc=0x7f050005;\r
+        public static final int lb_paritycheck=0x7f050006;\r
+        public static final int m_about=0x7f05000b;\r
+        public static final int m_clear=0x7f05000a;\r
+        public static final int m_configinitial=0x7f050007;\r
+        public static final int m_quit=0x7f05000c;\r
+        public static final int m_recvdata=0x7f050009;\r
+        public static final int m_senddata=0x7f050008;\r
+        public static final int optionMenuGroupsTitle=0x7f05001c;\r
+        public static final int optionMenuTitle=0x7f05001b;\r
+        public static final int optionMuneBindingTitle=0x7f05001d;\r
+        public static final int optionMuneListDevicesTitle=0x7f05001e;\r
+        public static final int rbt_0=0x7f050012;\r
+        public static final int rbt_1=0x7f050013;\r
+        public static final int rbt_2=0x7f050014;\r
+        public static final int rbt_3=0x7f050015;\r
+        public static final int rbt_4=0x7f050016;\r
+        public static final int str_sendtext=0x7f050017;\r
+        public static final int textviewMSG=0x7f050002;\r
+    }\r
+    public static final class style {\r
+        public static final int Animation_Popup=0x7f070008;\r
+        public static final int ApplicationTheme=0x7f070000;\r
+        public static final int DialogMenuText=0x7f070007;\r
+        public static final int SideMenuText=0x7f070006;\r
+        public static final int StdButton=0x7f070001;\r
+        public static final int StdButtonIcon=0x7f070002;\r
+        public static final int StdButtonText=0x7f070003;\r
+        public static final int StdScreen=0x7f070005;\r
+        public static final int TitleText=0x7f070004;\r
+    }\r
+}\r
old mode 100644 (file)
new mode 100755 (executable)
index f049142..c4f09d2
@@ -8,4 +8,4 @@
 # project structure.
 
 # Project target.
-target=android-10
+target=android-17
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 (executable)
index 0000000..3fa5552
Binary files /dev/null and b/client/AndroidClients/LightingController/res/drawable-hdpi/ic_menu_add.png differ
old mode 100644 (file)
new mode 100755 (executable)
index 3a9f65b..29973bf
@@ -4,6 +4,8 @@
     android:layout_height="wrap_content"    
     android:maxRows="1"
     android:maxItemsPerRow="6"   >
+            <item android:id="@+id/optionMenuAddDevice"
+                  android:icon="@drawable/ic_menu_add" />     
             <item android:id="@+id/optionMenuGroups"
                   android:icon="@drawable/ic_menu_group" />
             <item android:id="@+id/optionMenuScenes"
@@ -11,5 +13,5 @@
             <item android:id="@+id/optionMenuBinding"
                   android:icon="@drawable/ic_menu_bind" />
             <item android:id="@+id/optionMenuListDevices"
-                  android:icon="@drawable/ic_menu_list_devices" />
+                  android:icon="@drawable/ic_menu_list_devices" />           
 </menu>
old mode 100644 (file)
new mode 100755 (executable)
index 8c787fd..4ee66fd
@@ -145,7 +145,7 @@ public class LightingController extends Activity{
                                  ZigbeeSrpcClient.discoverGroups();
                                  ZigbeeSrpcClient.discoverScenes();
                                  //wait for responses
-                                 try { TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException e) {e.printStackTrace();}  
+                                 try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) {e.printStackTrace();}  
        
                                  startActivity(new Intent(LightingController.this, zllMain.class));                            
                                }
old mode 100644 (file)
new mode 100755 (executable)
index bfe52aa..29aed19
@@ -41,7 +41,7 @@
 package com.lightingcontroller.Zigbee;
 
 import java.util.ArrayList;
-import java.util.Calendar;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 
@@ -54,15 +54,11 @@ import android.widget.Toast;
 
 public class ZigbeeAssistant implements Runnable {
 
-       //public static final boolean USE_JNI = true;
-       public static final boolean USE_JNI = false;
-
        public static boolean gateWayConnected = false;
        public static boolean initializing = true;
        
        private static String TAG = "ZigbeeAssistant";
        public static ZigbeeSrpcClient zigbeeSrpcClient;
-       public static String ZigbeeSrpcClientGatewayIp = "192.168.1.220";
        
        static Thread thread;
        static Activity mainAct;
@@ -73,15 +69,9 @@ public class ZigbeeAssistant implements Runnable {
        
        private static int LightDeviceIdx = 0;
 
-       static public int lastTempReading = 65535;
-       static public List<Integer> powerReadings = new ArrayList<Integer>();
-       static public List<Long> powerReadingsTimes = new ArrayList<Long>();
        static public HashMap<Short,Long> nwrkToIEEE = new HashMap<Short,Long>();
                
        public static native int runMain();
-       public static native boolean isRunning();
-       public static native short requestThermostatReading(short networkaddr, char end); // Get ThermostatReading
-       public static native short requestPowerReading(short networkaddr, char end); // Get ThermostatReading
        public static native void setDeviceState(short networkaddr, char end, boolean state);   // Set device state on/off
        public static native void setDeviceLevel(short networkaddr, char end, char level, short transitionTime);        // Set device level/dim
        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 {
                                                                                  short network_b, char end_b, int ieel_b, int ieeh_b,
                                                                                  short clusterId);     // Bind Devices
        
+       static final byte EP_INFO_TYPE_EXISTING = 0;
+       static final byte EP_INFO_TYPE_NEW = 1;
+       static final byte EP_INFO_TYPE_UPDATED = 2;
+       static final byte EP_INFO_TYPE_REMOVED = 4;
        
+       static int cnt = 0;
        
-       static
-       {
-               if(USE_JNI)                     
-                  System.loadLibrary("zigbee_assistant_jni");                  //Loading native library        
-               
-       }       
-       
-       public static void notifyUser(String s)
-       {
-               ZigbeeNotification.showNotification(s);
-       }
+       public static void enableNotify(Activity activity, int timeOut) 
+       {               
+               ZigbeeNotification.init(activity);              
+       }               
 
        public static List<ZigbeeDevice> getDevices()
        {
@@ -111,9 +99,6 @@ public class ZigbeeAssistant implements Runnable {
        
        public static void addGroup(ZigbeeDevice d, String groupName )
        {               
-               //ZigbeeGroup newGroup = new ZigbeeGroup(groupName);
-               //ourGroups.add(newGroup);              
-               
                ZigbeeSrpcClient.addGroup((short) d.NetworkAddr,d.EndPoint, groupName);
        }
        
@@ -142,60 +127,48 @@ public class ZigbeeAssistant implements Runnable {
                return ourScenes;
        }
        
-       public static void deviceAnnounce(int nwrk, long ieee1) 
-       {
-               // TODO Auto-generated method stub
-
-               if (nwrkToIEEE.containsKey(nwrk))
-                       nwrkToIEEE.remove(nwrk);
-               nwrkToIEEE.put((short)nwrk, ieee1);             
-       }
-
-       
-       public static void deviceAnnounce(int nwrk, int ieee1, int ieee2)
+       public static void newDevice(int ProfileId, int DeviceId, int NetworkAddr, char EndPoint, byte ieee[], String deviceName, byte newDevFlag)
        {
-               long t2;
-               long t = (((long)ieee2))<<32;
-               
-               if(ieee1 < 0)
+               //find old device
+               ZigbeeDevice device = getDevice(ieee, EndPoint);
+                               
+               if(newDevFlag != EP_INFO_TYPE_REMOVED)
                {
-                       long t3 = 2147483647;
-                       t3 = t3 + 2147483647;
-                       t3 = t3 + 2;
-                       t2 = (((long)ieee1));           
-                       t2 = t2+t3;
+                       if(device != null)
+                       {
+                               ZigbeeDevice newDevice = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint,  ieee, deviceName, LightDeviceIdx++);
+                               device.updateDevice(newDevice);
+                       }
+                       else
+                       {
+                               device = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint,  ieee, deviceName, LightDeviceIdx++);
+                               ourDevices.add(device);
+                       }
                }
                else
                {
-                       t2 = ieee1;                     
-               }
-               t = t | t2;
-               if (nwrkToIEEE.containsKey(nwrk))
-                       nwrkToIEEE.remove(nwrk);
-               nwrkToIEEE.put((short)nwrk, t);
-       }
-
-       public static void newDevice(int ProfileId, int DeviceId, int NetworkAddr, char EndPoint, byte ieee[], String deviceName)
-       {
-               ZigbeeDevice oldD = ifDeviceExists(NetworkAddr,EndPoint);
-               if (oldD != null)
-               {
-                       if (oldD.ProfileId == ProfileId)
-                               return;
-                       oldD = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint, ieee, deviceName, LightDeviceIdx++);
-                       return;
+                       if(device != null)
+                       {
+                               ourDevices.remove(device);      
+                               if(device.hasColourable || device.hasSwitchable || device.hasDimmable)
+                               {
+                                       ZigbeeNotification.showRemoveDeviceNotification(device.Name, 5000);
+                               }
+                       }
                }
-               ZigbeeDevice newDevice = new ZigbeeDevice(ProfileId, DeviceId, NetworkAddr, EndPoint,  ieee, deviceName, LightDeviceIdx++);
-               ourDevices.add(newDevice);
+               
+               if( (newDevFlag == EP_INFO_TYPE_NEW) && (device.hasColourable || device.hasSwitchable || device.hasDimmable))
+               {               
+                       ZigbeeNotification.showNewDeviceNotification(device);
+               }               
        }
-
+       
        public static void newGroup( String groupName )
        {               
                ZigbeeGroup newGroup = new ZigbeeGroup(groupName);
                ourGroups.add(newGroup);        
                
-               //Create new group on gateway (with invalid nwkAddr so not device is added to the group)
-               ZigbeeSrpcClient.addGroup((short) 0xFFFF, (char) 0xFF, groupName);
+               //Group will not be created on the GW until a device is added
        }       
        
        public static void newGroup(String groupName, int groupId, int status)
@@ -253,9 +226,8 @@ public class ZigbeeAssistant implements Runnable {
                if(ourScenes.contains(newScene) == false)
                {
                        ourScenes.add(newScene);
-               }
-               
-               ZigbeeSrpcClient.storeScene( sceneName, groupId );
+               }               
+               //Scene will not be created on the GW until scene is stored
        }
        
        public static boolean bindDevicesOnOff(ZigbeeDevice a, ZigbeeDevice b)
@@ -301,6 +273,11 @@ public class ZigbeeAssistant implements Runnable {
                        ZigbeeSrpcClient.changeDeviceName(d, newName);
                }
        }
+
+       public static void openNetwork(byte duration)
+       {
+               ZigbeeSrpcClient.openNetwork(duration);
+       }
        
        public static ZigbeeDevice ifDeviceExists(int NetworkAddr, char EndPoint)
        {
@@ -319,6 +296,23 @@ public class ZigbeeAssistant implements Runnable {
                        return ret;
        }
        
+       public static ZigbeeDevice getDevice(byte ieee[], char EndPoint)
+       {
+               int last = ourDevices.size()-1;
+               int i = last;
+               ZigbeeDevice ret = null;
+               for (i = last ; i >= 0 ; i--)
+               {
+                       ret = ourDevices.get(i);
+                       if( (Arrays.equals(ret.Ieee, ieee)) && (ret.EndPoint == EndPoint))
+                               break;
+               }
+               if (i < 0) 
+                       return null;
+               else
+                       return ret;
+       }
+       
        public static boolean hasAnySwitchers()
        {
                for (int i = 0 ; i < ourDevices.size() ; i++)
@@ -330,18 +324,6 @@ public class ZigbeeAssistant implements Runnable {
                return false;   
        }
        
-       public static void newDeviceCluster(int NetworkAddr, char EndPoint, boolean in, int ClusterId)
-       {
-               ZigbeeDevice toAddto = ifDeviceExists(NetworkAddr, EndPoint);
-               if (toAddto == null) 
-               {
-                       Log.w(TAG, "Couldn't find Device");
-                       return;
-               }
-               
-               toAddto.addCluster(in, ClusterId);      
-       }
-       
        public ZigbeeAssistant()
        {
                ourDevices.clear();
@@ -363,11 +345,7 @@ public class ZigbeeAssistant implements Runnable {
                        if (d.hasDimmable)
                                s+="\t: Dimmable\n";
                        if (d.hasColourable)
-                               s+="\t: Colourable\n";
-                       if (d.hasThermometer)
-                               s+="\t: Measures Temperature\n";
-                       if (d.hasPowerUsage)
-                               s+="\t: Measures Power Usage\n";                        
+                               s+="\t: Colourable\n";          
                        if (d.hasOutSwitch)
                                s+="\t: Switches Others\n";
                        if (d.hasOutLeveL)
@@ -406,17 +384,20 @@ public class ZigbeeAssistant implements Runnable {
                return s;
        }       
        
-       public static void haveTemperature(int NetworkAddr, char EndPoint, int data)
+       public static void IdentifyDevice(ZigbeeDevice d, short identifyTime)
+       {
+               ZigbeeSrpcClient.IdentifyDevice((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, identifyTime);                   
+       }
+
+       public static void IdentifyGroup(ZigbeeGroup g, short identifyTime)
        {
-               lastTempReading = data;
+               ZigbeeSrpcClient.IdentifyDevice((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char)0xFF, identifyTime);                  
        }
        
        public static void setDeviceState(ZigbeeDevice d, boolean state)
        {
-               if(USE_JNI)                     
-                       setDeviceState((short) d.NetworkAddr,d.EndPoint,state);
-               else
-                       ZigbeeSrpcClient.setDeviceState((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,state);                   
+
+               ZigbeeSrpcClient.setDeviceState((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,state);                   
        }
 
        public static void setDeviceState(ZigbeeGroup g, boolean state)
@@ -428,23 +409,17 @@ public class ZigbeeAssistant implements Runnable {
        {
                float[] hsv = new float[3];
                Color.colorToHSV(colour, hsv);
-               if (USE_JNI)
-                       setDeviceColour((short) d.NetworkAddr,d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10);
-               else
-                       ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10);
+               ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,(char)((hsv[0]/360)*0xFF), (char)(hsv[1]*0xFF),(short)10);
        }
 
        public static void setDeviceHueSat(ZigbeeDevice d, byte hue, byte sat)
        {
-               if (USE_JNI)
-                       setDeviceColour((short) d.NetworkAddr,d.EndPoint,(char) hue, (char) sat,(short)10);
-               else
-                       ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, (char) hue, (char) sat,(short)10);
+               ZigbeeSrpcClient.setDeviceColor((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint, (char) hue, (char) sat,(short)10);
        }
 
        public static void setDeviceHueSat(ZigbeeGroup g, byte hue, byte sat)
        {
-                       ZigbeeSrpcClient.setDeviceColor((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF, (char) hue, (char) sat,(short)10);
+               ZigbeeSrpcClient.setDeviceColor((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF, (char) hue, (char) sat,(short)10);
        }       
        
        public static void setDeviceLevel(ZigbeeDevice d, int colour)
@@ -456,15 +431,12 @@ public class ZigbeeAssistant implements Runnable {
        
        public static void setDeviceLevel(ZigbeeDevice d, char level)
        {
-               if(USE_JNI)     
-                       setDeviceLevel((short) d.NetworkAddr,d.EndPoint,level,(short)10);
-               else
-                       ZigbeeSrpcClient.setDeviceLevel((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,level,(short)10);
+               ZigbeeSrpcClient.setDeviceLevel((short) d.NetworkAddr, ZigbeeSrpcClient.Addr16Bit, d.EndPoint,level,(short)10);
        }
 
        public static void setDeviceLevel(ZigbeeGroup g, char level)
        {
-                       ZigbeeSrpcClient.setDeviceLevel((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF,level,(short)10);
+               ZigbeeSrpcClient.setDeviceLevel((short) g.getGroupId(), ZigbeeSrpcClient.AddrGroup, (char) 0xFF,level,(short)10);
        }       
 
        public static void getDeviceState(ZigbeeDevice d)
@@ -488,20 +460,7 @@ public class ZigbeeAssistant implements Runnable {
        }
        
        public void run() {
-               if(USE_JNI)
-               {
-                       Log.d(TAG, "Begin Zigbee");
-                       final int returnvalue = runMain();
-                       mainAct.runOnUiThread(new Runnable() {
-                               public void run() {
-                               Toast.makeText(mainAct, "Zigbee has failed ("+returnvalue+") \n - Is the dongle connected and chmodded?", Toast.LENGTH_LONG).show();
-                       }
-                       });
-               }
-               else
-               {
-                       Log.d(TAG, "Begin Zigbee");             
-                       zigbeeSrpcClient = new ZigbeeSrpcClient();
-               }                       
+               Log.d(TAG, "Begin Zigbee");             
+               zigbeeSrpcClient = new ZigbeeSrpcClient();              
        }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 4ff3119..8076bca
@@ -62,8 +62,6 @@ public class ZigbeeDevice {
        public boolean hasColourable = false;
        public boolean hasDimmable = false;
        public boolean hasSwitchable = false;
-       public boolean hasThermometer = false;
-       public boolean hasPowerUsage = false;
        public boolean hasOutSwitch = false;
        public boolean hasOutLeveL = false;
        public boolean hasOutColor = false;
@@ -374,22 +372,37 @@ public class ZigbeeDevice {
                        default:        Type = "Unknown Device"; Name="Unknown";        
                        }
                }
-
-               //String notification = "New "+Type+" connected!"; 
-               //ZigbeeNotification.showNotification(notification);
+               
+               if(!_deviceName.isEmpty())
+               {
+                       Name = _deviceName;
+               }
        }
        
+       public void updateDevice(ZigbeeDevice device)
+       {       
+               Name = device.Name;
+               Type = device.Type;
+               ProfileId = device.ProfileId;
+               DeviceId = device.DeviceId;
+               NetworkAddr = device.NetworkAddr;
+               hasColourable = device.hasColourable;
+               hasDimmable = device.hasDimmable;
+               hasSwitchable = device.hasSwitchable;
+               hasOutLeveL = device.hasOutLeveL;
+               hasOutScene = device.hasOutScene;
+               hasOutGroup = device.hasOutGroup;
+       }       
+       
        public void addCluster(boolean in, int ClusterId)
        {
                if (in)
                {
                        switch (ClusterId)
                        {
-                       case (0x0402): hasThermometer = true;                   break;
                        case (0x0006): hasSwitchable = true;                    break;
                        case (0x0008): hasDimmable = true;                      break;
                        case (0x0300): hasColourable = true;                    break;
-                       case (0x0702): hasPowerUsage = true;                    break;
                        }
                } else
                {
old mode 100644 (file)
new mode 100755 (executable)
index 88a7c33..57bf439
-/**************************************************************************************************
-  Filename:       ZigBeeNotification.java
-  Revised:        $$
-  Revision:       $$
-
-  Description:    ZigBee Notification Class
-
-    Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
-
-
-   Redistribution and use in source and binary forms, with or without
-   modification, are permitted provided that the following conditions
-   are met:
-
-     Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-
-     Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in the
-     documentation and/or other materials provided with the
-     distribution.
-
-     Neither the name of Texas Instruments Incorporated nor the names of
-     its contributors may be used to endorse or promote products derived
-     from this software without specific prior written permission.
-
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**************************************************************************************************/
-
-package com.lightingcontroller.Zigbee;
-
-import java.util.ArrayList;
-
-import com.lightingcontroller.R;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.graphics.Color;
-import android.graphics.drawable.BitmapDrawable;
-import android.os.Handler;
-import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.View.OnTouchListener;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.PopupWindow;
-import android.widget.TextView;
-import android.widget.Toast;
-
-public class ZigbeeNotification {
-
-       static Activity acty;
-       static Handler handle = new Handler();          
-       static boolean alive;
-       static PopupWindow popwindow = null;
-       
-       static ArrayList<String> notices = new ArrayList<String>();
-       
-       static int timeout = 5000;
-       
-       public static void init(Activity a, int time_out)
-       {
-               init(a);
-               timeout = time_out;
-       }
-       
-       public static void init(Activity a)
-       {
-               acty = a;
-               if (notices.size() > 0)
-               {
-                       for (int i = 0 ; i < notices.size() ; i++)
-                       {
-                               showNotificationOnScreen(notices.get(i));
-                       }
-                       for (int i = 0 ; i < notices.size() ; i++)
-                       {
-                               notices.remove(i);
-                       }                       
-               }
-       }
-       
-       public static void closing()
-       {
-               if (popwindow != null)
-               {
-                       popwindow.dismiss();
-                       handle.removeCallbacks(closePopupTask);
-               }
-               popwindow = null;
-               acty = null;
-       }
-       
-       public static void showNotification(String text)
-       {
-               if (acty == null)
-               {
-                       notices.add(text);
-               }
-               else
-               {
-                       showNotificationOnScreen(text);
-               }
-       }
-       
-       public static void showNotificationOnScreen(final String text)
-       {
-               final TextView text1 = new TextView(acty);
-               text1.setText(text);
-               text1.setTextColor(Color.WHITE);
-               text1.setTextSize(18);
-               text1.setGravity(Gravity.CENTER);
-                               
-               if (popwindow == null)
-               {
-                       LayoutInflater inflater = (LayoutInflater) acty.getLayoutInflater();
-                       View layout = inflater.inflate(R.layout.popup,
-                                                      (ViewGroup) acty.findViewById(R.id.toast_layout_root));  
-       
-                       ((LinearLayout) layout.findViewById(R.id.popup_text_box)).addView(text1);
-
-                       popwindow = new PopupWindow(layout,400,100,false); 
-                       popwindow.setAnimationStyle(R.style.Animation_Popup);
-                       popwindow.setBackgroundDrawable(new BitmapDrawable());
-                       popwindow.setOutsideTouchable(false);
-                       popwindow.setTouchable(true);
-                       popwindow.setTouchInterceptor(new OnTouchListener() {
-                       public boolean onTouch(View v, MotionEvent event) {
-                               handle.removeCallbacks(closePopupTask);                 
-                               handle.post(closePopupTask);
-                               return false;
-                               }
-                       });
-                       try{
-                               acty.runOnUiThread (new Runnable(){
-                                       public void run() {
-//                                             if (acty!=null && acty.findViewById(R.id.MainMenu_lay)!=null)
-//                                                     popwindow.showAtLocation(acty.findViewById(R.id.MainMenu_lay), Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 0);
-//                                             else
-//                                                     notices.add(text);
-                                       }
-                               });
-                       } catch (Exception e)
-                       {
-                               // Dagnabbit.
-                               popwindow = null;
-                       }
-               }
-               else
-               {
-                       
-                       acty.runOnUiThread (new Runnable(){
-                               public void run() {
-                                       LinearLayout l = (LinearLayout)popwindow.getContentView().findViewById(R.id.popup_text_box);
-                                       if (l.getChildCount()>2)
-                                               l.removeViewAt(0);
-                                       l.addView(text1);
-                                       popwindow.update();
-                               }
-                       });
-               }
-                               
-               handle.removeCallbacks(closePopupTask);
-               handle.postDelayed(closePopupTask, timeout);
-               //SoundManager.playSound(SoundManager.NOTIFY, 1);
-       }
-       
-       
-       private static Runnable closePopupTask = new Runnable() {
-                  public void run() {
-                          if (popwindow!=null)
-                          {
-                                  popwindow.dismiss();
-                                  popwindow = null;
-                          }
-                  }
-               };
-       
-       
-}
+/**************************************************************************************************\r
+  Filename:       ZigBeeNotification.java\r
+  Revised:        $$\r
+  Revision:       $$\r
+\r
+  Description:    ZigBee Notification Class\r
+\r
+    Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/\r
+\r
+\r
+   Redistribution and use in source and binary forms, with or without\r
+   modification, are permitted provided that the following conditions\r
+   are met:\r
+\r
+     Redistributions of source code must retain the above copyright\r
+     notice, this list of conditions and the following disclaimer.\r
+\r
+     Redistributions in binary form must reproduce the above copyright\r
+     notice, this list of conditions and the following disclaimer in the\r
+     documentation and/or other materials provided with the\r
+     distribution.\r
+\r
+     Neither the name of Texas Instruments Incorporated nor the names of\r
+     its contributors may be used to endorse or promote products derived\r
+     from this software without specific prior written permission.\r
+\r
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
\r
+ **************************************************************************************************/\r
+\r
+package com.lightingcontroller.Zigbee;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import com.lightingcontroller.R;\r
+import com.lightingcontroller.zllMain;\r
+\r
+import android.app.Activity;\r
+import android.app.AlertDialog;\r
+import android.app.AlertDialog.Builder;\r
+import android.app.Dialog;\r
+import android.content.DialogInterface;\r
+import android.content.Intent;\r
+import android.graphics.Color;\r
+import android.graphics.drawable.BitmapDrawable;\r
+import android.os.Handler;\r
+import android.view.Gravity;\r
+import android.view.LayoutInflater;\r
+import android.view.MotionEvent;\r
+import android.view.View;\r
+import android.view.View.OnTouchListener;\r
+import android.view.ViewGroup;\r
+import android.widget.EditText;\r
+import android.widget.LinearLayout;\r
+import android.widget.PopupWindow;\r
+import android.widget.TextView;\r
+\r
+public class ZigbeeNotification {\r
+\r
+       private static Activity acty = null;\r
+       private static Dialog notificationDialog = null;\r
+       private static boolean deviceRemove = false;\r
+\r
+       static ArrayList<ZigbeeDevice> newDevNotifications = new ArrayList<ZigbeeDevice>();\r
+\r
+       static int timeout = 5000;\r
+       static int cnt = 0;\r
+       \r
+       public static void init(Activity a) {\r
+               acty = a;\r
+       }\r
+\r
+       public static void closing() {\r
+               closeDialog();\r
+               acty = null;\r
+       }\r
+\r
+       public static void showNewDeviceNotification(final ZigbeeDevice device) {\r
+               cnt++;\r
+               if(cnt > 1)\r
+                       cnt = 0;\r
+               \r
+               if (acty != null) {\r
+                       if(notificationDialog != null)\r
+                       {\r
+                               newDevNotifications.add(device);\r
+                       }\r
+                       else\r
+                       {\r
+                               showNewDeviceNotificationDialog(device);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       \r
+               }\r
+               \r
+               while (!newDevNotifications.isEmpty()) {\r
+                       if (acty != null) {\r
+                               if(notificationDialog == null)\r
+                               {\r
+                                       ZigbeeDevice notifyDevice = newDevNotifications.remove(0);\r
+                                       showNewDeviceNotificationDialog(notifyDevice);\r
+                               }\r
+                       }\r
+               }\r
+                               \r
+/*             \r
+               // restart activity to update device drop down          \r
+               Intent intent = new Intent();\r
+               intent.setClass(acty, acty.getClass());\r
+               acty.finish();\r
+               acty.startActivity(intent);\r
+*/\r
+       }\r
+\r
+       public static void showNewDeviceNotificationDialog(\r
+                       final ZigbeeDevice device) {\r
+               // close any existing notification\r
+               closeDialog();\r
+               \r
+               //put device into identify\r
+               ZigbeeAssistant.setDeviceState(device,true);\r
+               ZigbeeAssistant.setDeviceLevel(device,0xFF);\r
+               ZigbeeAssistant.IdentifyDevice(device,(short) 600);\r
+               \r
+       String Title = "New Device Found";\r
+       String Msg = "Please Enter the name of the device";\r
+       final EditText t = new EditText(acty);\r
+       t.setText(device.Name);\r
+\r
+               final AlertDialog.Builder builder = new AlertDialog.Builder(acty);\r
+               builder.setTitle(Title)\r
+               .setMessage(Msg)\r
+               .setView(t)\r
+               .setPositiveButton("OK",  \r
+               new DialogInterface.OnClickListener()\r
+               {\r
+                       public void onClick(DialogInterface dialoginterface,int i){     \r
+                               ZigbeeAssistant.setDeviceName(device.Name, t.getText().toString());     \r
+                               zllMain.setCurrentDevice(device);\r
+                               closeDialog();\r
+                               //stop device identifying\r
+                               ZigbeeAssistant.IdentifyDevice(device,(short) 0);\r
+                       }\r
+           });\r
+               \r
+\r
+               try {\r
+                       acty.runOnUiThread(new Runnable() {\r
+                               public void run() {\r
+                                       if (acty != null) {\r
+                                               // if(acty.hasWindowFocus())\r
+                                               // {\r
+                                               notificationDialog = builder.create();\r
+                                               notificationDialog.show();\r
+                                               // }\r
+                                       }\r
+                               }\r
+                       });\r
+               } catch (Exception e) {\r
+\r
+               }\r
+       }\r
+\r
+       public static void showRemoveDeviceNotification(String deviceStr,\r
+                       final int timeout) {\r
+               if (acty != null) {\r
+                       // close any existing notification\r
+                       closeDialog();\r
+\r
+                       final AlertDialog.Builder builder = new AlertDialog.Builder(acty);\r
+                       builder.setTitle("ZigBee Notification")\r
+                                       .setCancelable(false)\r
+                                       .setMessage("Device Removed: " + deviceStr)\r
+                                       .setPositiveButton("Ok",\r
+                                                       new DialogInterface.OnClickListener() {\r
+                                                               public void onClick(DialogInterface dialog,\r
+                                                                               int id) {\r
+                                                                       // restart activity to update device drop\r
+                                                                       // down\r
+                                                                       Intent intent = new Intent();\r
+                                                                       intent.setClass(acty, acty.getClass());\r
+                                                                       acty.finish();\r
+                                                                       acty.startActivity(intent);\r
+                                                                       closeDialog();\r
+                                                               }\r
+                                                       });\r
+\r
+                       try {\r
+                               acty.runOnUiThread(new Runnable() {\r
+                                       public void run() {\r
+                                               if (acty != null) {\r
+                                                       // if(acty.hasWindowFocus())\r
+                                                       // {\r
+                                                       notificationDialog = builder.create();\r
+                                                       notificationDialog.show();\r
+                                                       // }\r
+                                               }\r
+                                       }\r
+                               });\r
+                       } catch (Exception e) {\r
+\r
+                       }\r
+\r
+                       new Thread(new Runnable() {\r
+                               public void run() {\r
+                                       try {\r
+                                               Thread.sleep(timeout);\r
+                                       } catch (InterruptedException e) {\r
+                                               // TODO Auto-generated catch block\r
+                                               e.printStackTrace();\r
+                                       }\r
+                                       closeDialog();\r
+                               }\r
+                       }).start();\r
+\r
+               }\r
+       }\r
+\r
+       public static void showGeneralNotification(String notification,\r
+                       final int timeout) {\r
+               if (acty != null) {\r
+                       // close any existing notification\r
+                       closeDialog();\r
+\r
+                       final AlertDialog.Builder builder = new AlertDialog.Builder(acty);\r
+                       builder.setTitle("ZigBee Notification").setCancelable(false)\r
+                                       .setMessage(notification);\r
+\r
+                       try {\r
+                               acty.runOnUiThread(new Runnable() {\r
+                                       public void run() {\r
+                                               if (acty != null) {\r
+                                                       // if(acty.hasWindowFocus())\r
+                                                       // {\r
+                                                       notificationDialog = builder.create();\r
+                                                       notificationDialog.show();\r
+                                                       // }\r
+                                               }\r
+                                       }\r
+                               });\r
+                       } catch (Exception e) {\r
+\r
+                       }\r
+\r
+                       new Thread(new Runnable() {\r
+                               public void run() {\r
+                                       try {\r
+                                               Thread.sleep(timeout);\r
+                                       } catch (InterruptedException e) {\r
+                                               // TODO Auto-generated catch block\r
+                                               e.printStackTrace();\r
+                                       }\r
+                                       closeDialog();\r
+                               }\r
+                       }).start();\r
+               }\r
+       }\r
+\r
+       private static void closeDialog() {\r
+               if (notificationDialog != null) {\r
+                       notificationDialog.cancel();\r
+               }\r
+               notificationDialog = null;\r
+       }\r
+}\r
old mode 100644 (file)
new mode 100755 (executable)
index 812aafb..cb70a9f
@@ -91,45 +91,49 @@ public class ZigbeeSrpcClient {
        
        //SRPC CMD ID's 
        //define the outgoing RPSC command ID's
-       private static final byte RPCS_NEW_ZLL_DEVICE     = (byte) 0x0001;
-       private static final byte RPCS_DEV_ANNCE                      = (byte) 0x0002;
-       private static final byte RPCS_SIMPLE_DESC            = (byte) 0x0003;
-       private static final byte RPCS_TEMP_READING       = (byte) 0x0004;
-       private static final byte RPCS_POWER_READING      = (byte) 0x0005;
-       private static final byte RPCS_PING               = (byte) 0x0006;
-       private static final byte RPCS_GET_DEV_STATE_RSP  = (byte) 0x0007;
-       private static final byte RPCS_GET_DEV_LEVEL_RSP  = (byte) 0x0008;
-       private static final byte RPCS_GET_DEV_HUE_RSP    = (byte) 0x0009;
-       private static final byte RPCS_GET_DEV_SAT_RSP    = (byte) 0x000a;
-       private static final byte RPCS_ADD_GROUP_RSP      = (byte) 0x000b;
-       private static final byte RPCS_GET_GROUP_RSP      = (byte) 0x000c;
-       private static final byte RPCS_ADD_SCENE_RSP      = (byte) 0x000d;
-       private static final byte RPCS_GET_SCENE_RSP      = (byte) 0x000e;
-
-
-       //define incoming RPCS command ID's
-       private static final byte RPCS_CLOSE              = (byte) 0x80;
-       private static final byte RPCS_GET_DEVICES        = (byte) 0x81;
-       private static final byte RPCS_SET_DEV_STATE      = (byte) 0x82;        
-       private static final byte RPCS_SET_DEV_LEVEL      = (byte) 0x83;        
-       private static final byte RPCS_SET_DEV_COLOR      = (byte) 0x84;
-       private static final byte RPCS_GET_DEV_STATE      = (byte) 0x85;        
-       private static final byte RPCS_GET_DEV_LEVEL      = (byte) 0x86;        
-       private static final byte RPCS_GET_DEV_HUE        = (byte) 0x87;
-       private static final byte RPCS_GET_DEV_SAT        = (byte) 0x88;
-       private static final byte RPCS_BIND_DEVICES       = (byte) 0x89;
-       private static final byte RPCS_GET_THERM_READING  = (byte) 0x8a;
-       private static final byte RPCS_GET_POWER_READING  = (byte) 0x8b;
-       private static final byte RPCS_DISCOVER_DEVICES   = (byte) 0x8c;
-       private static final byte RPCS_SEND_ZCL           = (byte) 0x8d;
-       private static final byte RPCS_GET_GROUPS         = (byte) 0x8e;        
-       private static final byte RPCS_ADD_GROUP          = (byte) 0x8f;        
-       private static final byte RPCS_GET_SCENES         = (byte) 0x90;        
-       private static final byte RPCS_STORE_SCENE        = (byte) 0x91;        
-       private static final byte RPCS_RECALL_SCENE       = (byte) 0x92;        
-       private static final byte RPCS_IDENTIFY_DEVICE    = (byte) 0x93;        
-       private static final byte RPCS_CHANGE_DEVICE_NAME = (byte) 0x94;   
-
+       private static final byte SRPC_NEW_DEVICE     = (byte) 0x0001;
+       private static final byte SRPC_RESERVED_1                 = (byte) 0x0002;
+       private static final byte SRPC_RESERVED_2             = (byte) 0x0003;
+       private static final byte SRPC_RESERVED_3         = (byte) 0x0004;
+       private static final byte SRPC_RESERVED_4         = (byte) 0x0005;
+       private static final byte SRPC_RESERVED_5         = (byte) 0x0006;
+       private static final byte SRPC_GET_DEV_STATE_RSP  = (byte) 0x0007;
+       private static final byte SRPC_GET_DEV_LEVEL_RSP  = (byte) 0x0008;
+       private static final byte SRPC_GET_DEV_HUE_RSP    = (byte) 0x0009;
+       private static final byte SRPC_GET_DEV_SAT_RSP    = (byte) 0x000a;
+       private static final byte SRPC_ADD_GROUP_RSP      = (byte) 0x000b;
+       private static final byte SRPC_GET_GROUP_RSP      = (byte) 0x000c;
+       private static final byte SRPC_ADD_SCENE_RSP      = (byte) 0x000d;
+       private static final byte SRPC_GET_SCENE_RSP      = (byte) 0x000e;
+
+
+       //define incoming SRPC command ID's
+       private static final byte SRPC_CLOSE              = (byte) 0x80;
+       private static final byte SRPC_GET_DEVICES        = (byte) 0x81;
+       private static final byte SRPC_SET_DEV_STATE      = (byte) 0x82;        
+       private static final byte SRPC_SET_DEV_LEVEL      = (byte) 0x83;        
+       private static final byte SRPC_SET_DEV_COLOR      = (byte) 0x84;
+       private static final byte SRPC_GET_DEV_STATE      = (byte) 0x85;        
+       private static final byte SRPC_GET_DEV_LEVEL      = (byte) 0x86;        
+       private static final byte SRPC_GET_DEV_HUE        = (byte) 0x87;
+       private static final byte SRPC_GET_DEV_SAT        = (byte) 0x88;
+       private static final byte SRPC_BIND_DEVICES       = (byte) 0x89;
+       private static final byte SRPC_RESERVED_6                 = (byte) 0x8a;
+       private static final byte SRPC_RESERVED_7         = (byte) 0x8b;
+       private static final byte SRPC_RESERVED_8         = (byte) 0x8c;
+       private static final byte SRPC_RESERVED_9         = (byte) 0x8d;
+       private static final byte SRPC_GET_GROUPS         = (byte) 0x8e;        
+       private static final byte SRPC_ADD_GROUP          = (byte) 0x8f;        
+       private static final byte SRPC_GET_SCENES         = (byte) 0x90;        
+       private static final byte SRPC_STORE_SCENE        = (byte) 0x91;        
+       private static final byte SRPC_RECALL_SCENE       = (byte) 0x92;        
+       private static final byte SRPC_IDENTIFY_DEVICE    = (byte) 0x93;        
+       private static final byte SRPC_CHANGE_DEVICE_NAME = (byte) 0x94;  
+       private static final byte SRPC_REMOVE_DEVICE      = (byte) 0x95; 
+       private static final byte SRPC_OPEN_NETWORK       = (byte) 0x9c; 
+       
+       private static final short JOIN_AUTH_NUM                  = (short) 0xebd4;
+       
        //SRPC AfAddr Addr modes ID's   
        public static final byte AddrNotPresent = 0;
        public static final byte AddrGroup = 1;
@@ -150,12 +154,13 @@ public class ZigbeeSrpcClient {
                switch (msg[msgPtr + SRPC_CMD_ID_POS])
                {
 
-               case RPCS_NEW_ZLL_DEVICE:
+               case SRPC_NEW_DEVICE:
                {
                        int profileId=0, deviceId=0, nwkAddr=0; 
                        char endPoint;
                        String deviceName = "";
                        byte[] ieee = new byte[8];
+                       byte newDevFlag;
 
                        msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2;
                        //index passed len and cmd ID
@@ -190,14 +195,12 @@ public class ZigbeeSrpcClient {
                        
             //index passed version
                        msgPtr++;
-                       
-                       //index passed device name
+
                        int nameSize = msg[msgPtr++];
                        for(int i = 0; i < nameSize; i++)
                        {
                                deviceName += (char) msg[msgPtr++];
                        }                       
-                       msgPtr += nameSize;
                        
             //index passed status
                        msgPtr++;
@@ -208,11 +211,13 @@ public class ZigbeeSrpcClient {
                                ieee[i] = msg[msgPtr++];
                        }                       
                        
-            ZigbeeAssistant.newDevice(profileId, deviceId, nwkAddr, endPoint, ieee, deviceName);                      
-                                       
+                       newDevFlag = (byte) msg[msgPtr++];
+
+                       ZigbeeAssistant.newDevice(profileId, deviceId, nwkAddr, endPoint, ieee, deviceName, newDevFlag);
+                       
             break;
                }
-               case RPCS_ADD_GROUP_RSP:
+               case SRPC_ADD_GROUP_RSP:
                {
                        short groupId = 0;
                        msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2;
@@ -244,9 +249,10 @@ public class ZigbeeSrpcClient {
                        break;
                }
                                                
-               case RPCS_GET_GROUP_RSP:
+               case SRPC_GET_GROUP_RSP:
                {
                        short groupId = 0;
+                       String groupName = "";
                        msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2;
                          
                        //index passed len and cmd ID
@@ -259,15 +265,19 @@ public class ZigbeeSrpcClient {
                int groupIdTemp = (msg[msgPtr] & 0xff);                  
                groupId += (groupIdTemp << (8 * i));                    
             }                  
+                                   
+                       int nameSize = msg[msgPtr++];
+                       for(int i = 0; i < nameSize; i++)
+                       {
+                               groupName += (char) msg[msgPtr++];
+                       }
                        
-            String groupNameStr = new String(msg, msgPtr+1, msg[msgPtr], Charset.defaultCharset());
-                       
-            ZigbeeAssistant.newGroup(groupNameStr, groupId, ZigbeeGroup.groupStatusActive);
+            ZigbeeAssistant.newGroup(groupName, groupId, ZigbeeGroup.groupStatusActive);
             
                        break;
                }       
                
-               case RPCS_ADD_SCENE_RSP:
+               case SRPC_ADD_SCENE_RSP:
                {
                        short groupId = 0;
                        byte sceneId = 0;
@@ -303,10 +313,11 @@ public class ZigbeeSrpcClient {
                        break;
                }
                                                
-               case RPCS_GET_SCENE_RSP:
+               case SRPC_GET_SCENE_RSP:
                {
                        short groupId = 0;
                        byte sceneId = 0;
+                       String sceneName = "";
                        msgLen = msg[msgPtr + SRPC_CMD_LEN_POS] + 2;
                          
                        //index passed len and cmd ID
@@ -322,14 +333,18 @@ public class ZigbeeSrpcClient {
             
             //Get the sceneId
             sceneId = (byte) msg[msgPtr++];            
+                                   
+                       int nameSize = msg[msgPtr++];
+                       for(int i = 0; i < nameSize; i++)
+                       {
+                               sceneName += (char) msg[msgPtr++];
+                       }
                        
-            String sceneNameStr = new String(msg, msgPtr+1, msg[msgPtr], Charset.defaultCharset());
-                       
-            ZigbeeAssistant.newScene(sceneNameStr, groupId, sceneId, ZigbeeScene.sceneStatusActive);
+            ZigbeeAssistant.newScene(sceneName, groupId, sceneId, ZigbeeScene.sceneStatusActive);
             
                        break;
                }
-               case RPCS_GET_DEV_STATE_RSP:
+               case SRPC_GET_DEV_STATE_RSP:
                {
                        short nwkAddr = 0;
                        byte endPoint = 0;
@@ -366,7 +381,7 @@ public class ZigbeeSrpcClient {
             }                                          
                        break;
                }
-               case RPCS_GET_DEV_LEVEL_RSP:
+               case SRPC_GET_DEV_LEVEL_RSP:
                {
                        short nwkAddr = 0;
                        byte endPoint = 0;
@@ -403,7 +418,7 @@ public class ZigbeeSrpcClient {
             }                                          
                        break;                  
                }               
-               case RPCS_GET_DEV_HUE_RSP:
+               case SRPC_GET_DEV_HUE_RSP:
                {
                        short nwkAddr = 0;
                        byte endPoint = 0;
@@ -440,7 +455,7 @@ public class ZigbeeSrpcClient {
             }                                          
                        break;
                }
-               case RPCS_GET_DEV_SAT_RSP:
+               case SRPC_GET_DEV_SAT_RSP:
                {
                        short nwkAddr = 0;
                        byte endPoint = 0;
@@ -493,7 +508,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_STATE;
+               msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_STATE;
                msg[SRPC_CMD_LEN_POS] = 13;
                
                //set ptr to point to data
@@ -531,7 +546,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_LEVEL;
+               msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_LEVEL;
                msg[SRPC_CMD_LEN_POS] = 15;
                
                //set ptr to point to data
@@ -564,7 +579,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_SET_DEV_COLOR;
+               msg[SRPC_CMD_ID_POS] = SRPC_SET_DEV_COLOR;
                msg[SRPC_CMD_LEN_POS] = 16;
                
                //set ptr to point to data
@@ -600,7 +615,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_STATE;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_STATE;
                msg[SRPC_CMD_LEN_POS] = 13;
                
                //set ptr to point to data
@@ -627,7 +642,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_LEVEL;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_LEVEL;
                msg[SRPC_CMD_LEN_POS] = 13;
                
                //set ptr to point to data
@@ -654,7 +669,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_HUE;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_HUE;
                msg[SRPC_CMD_LEN_POS] = 13;
                
                //set ptr to point to data
@@ -681,7 +696,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_DEV_SAT;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_DEV_SAT;
                msg[SRPC_CMD_LEN_POS] = 13;
                
                //set ptr to point to data
@@ -708,7 +723,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_BIND_DEVICES;
+               msg[SRPC_CMD_ID_POS] = SRPC_BIND_DEVICES;
                msg[SRPC_CMD_LEN_POS] = 22;
                
                //set ptr to point to data
@@ -758,7 +773,7 @@ public class ZigbeeSrpcClient {
                byte[] msg = new byte[2];
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_DEVICES;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_DEVICES;
                msg[SRPC_CMD_LEN_POS] = 0;
                
                sendSrpc(msg);
@@ -769,7 +784,7 @@ public class ZigbeeSrpcClient {
                byte[] msg = new byte[2];
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_GROUPS;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_GROUPS;
                msg[SRPC_CMD_LEN_POS] = 0;
                
                sendSrpc(msg);
@@ -780,7 +795,7 @@ public class ZigbeeSrpcClient {
                byte[] msg = new byte[2];
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_GET_SCENES;
+               msg[SRPC_CMD_ID_POS] = SRPC_GET_SCENES;
                msg[SRPC_CMD_LEN_POS] = 0;
                
                sendSrpc(msg);
@@ -792,7 +807,7 @@ public class ZigbeeSrpcClient {
                byte msgIdx;
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_ADD_GROUP;
+               msg[SRPC_CMD_ID_POS] = SRPC_ADD_GROUP;
                msg[SRPC_CMD_LEN_POS] = (byte) (12 + groupName.length() + 1);
                
                //set ptr to point to data
@@ -825,7 +840,7 @@ public class ZigbeeSrpcClient {
                byte msgIdx;
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_STORE_SCENE;
+               msg[SRPC_CMD_ID_POS] = SRPC_STORE_SCENE;
                msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length());
                
                //set ptr to point to data
@@ -861,7 +876,7 @@ public class ZigbeeSrpcClient {
                byte msgIdx;
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_RECALL_SCENE;
+               msg[SRPC_CMD_ID_POS] = SRPC_RECALL_SCENE;
                msg[SRPC_CMD_LEN_POS] = (byte) (15 + sceneName.length());
                
                //set ptr to point to data
@@ -899,7 +914,7 @@ public class ZigbeeSrpcClient {
                byte  msgIdx;
                 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_IDENTIFY_DEVICE;
+               msg[SRPC_CMD_ID_POS] = SRPC_IDENTIFY_DEVICE;
                msg[SRPC_CMD_LEN_POS] = 14;
                
                //set ptr to point to data
@@ -917,20 +932,21 @@ public class ZigbeeSrpcClient {
                //pad out pan ID
                msgIdx+=2;
 
-               //set transitionTime
-               msg[msgIdx++] = (byte) identifyTime;            
+               //set transitionTime            
+               msg[msgIdx++] = (byte) (identifyTime & 0xFF);
+               msg[msgIdx++] = (byte) ((identifyTime & 0xFF00)>>8);                    
                
                sendSrpc(msg);          
        }       
        
        public static void changeDeviceName(ZigbeeDevice device, String deviceName)
        {
-               byte[] msg = new byte[4 + deviceName.length()];
+               byte[] msg = new byte[6 + deviceName.length()];
                byte msgIdx;
 
                //set SRPC len and CMD ID
-               msg[SRPC_CMD_ID_POS] = RPCS_CHANGE_DEVICE_NAME;
-               msg[SRPC_CMD_LEN_POS] = (byte) (2 + deviceName.length());
+               msg[SRPC_CMD_ID_POS] = SRPC_CHANGE_DEVICE_NAME;
+               msg[SRPC_CMD_LEN_POS] = (byte) (4 + deviceName.length());
                
                //set ptr to point to data
                msgIdx=2;               
@@ -938,6 +954,9 @@ public class ZigbeeSrpcClient {
                //set afAddrMode_t nwk address          
                msg[msgIdx++] = (byte) (device.NetworkAddr & 0xFF);
                msg[msgIdx++] = (byte) ((device.NetworkAddr & 0xFF00)>>8);      
+               
+               //set EP
+               msg[msgIdx++] = (byte) (device.EndPoint);
 
                msg[msgIdx++] = (byte) deviceName.length();
                for(int i = 0; i < deviceName.length(); i++)
@@ -948,6 +967,29 @@ public class ZigbeeSrpcClient {
                sendSrpc(msg);                                  
        }       
        
+       
+       public static void openNetwork(byte duration)
+       {
+               byte[] msg = new byte[5];
+               byte msgIdx;
+
+               //set SRPC len and CMD ID
+               msg[SRPC_CMD_ID_POS] = SRPC_OPEN_NETWORK;
+               msg[SRPC_CMD_LEN_POS] = (byte) (3);
+               
+               //set ptr to point to data
+               msgIdx=2;               
+
+               //set duration          
+               msg[msgIdx++] = duration;
+               
+               //set join auth
+               msg[msgIdx++] = (byte) (JOIN_AUTH_NUM & 0xFF);
+               msg[msgIdx++] = (byte) ((JOIN_AUTH_NUM & 0xFF00)>>8);           
+               
+               sendSrpc(msg);                                  
+       }
+       
        public static int clientConnect( )
        {
                int Port;
@@ -1001,7 +1043,12 @@ public class ZigbeeSrpcClient {
                        new Thread(new Runnable() 
                        {    
                                public void run() {   
-                                       Listen();
+                                       try {
+                                               Listen();
+                                       } catch (IOException e) {
+                                               // TODO Auto-generated catch block
+                                               e.printStackTrace();
+                                       }
                                }  
                        }).start();
                        
@@ -1028,14 +1075,35 @@ public class ZigbeeSrpcClient {
 
        public static void sendSrpc(byte[] msg)
        {
-
                try{            
                        outStream.write( msg ); 
                } catch (Exception e){}         
        }
        
-       private static void Listen() {
+       private static void Listen() throws IOException {
        //listen for Packets
+               while(true)
+               {       
+                       byte[] RxBuffer = new byte[1024];
+                       int bytesRead = ReadMessage(inStream, RxBuffer);
+                       
+                       Log.i("Process Message:", "[" + bytesRead + "]: RPC CMD: " + RxBuffer[0] + ", RPC LEN: " + RxBuffer[1]);
+                       
+                       if(bytesRead == -1)
+                       {
+                               //error
+                       }
+                       else
+                       {
+                               int bytesProcessed;
+                               bytesProcessed = rpcsProcessIncoming(RxBuffer, 0);
+                               if ( bytesRead > bytesProcessed )
+                               {
+                                       //error did not process full buffer
+                               }
+                       }
+               }
+/*                     
                while(true)
                {               
                        byte[] RxBuffer = new byte[1024];
@@ -1051,7 +1119,40 @@ public class ZigbeeSrpcClient {
                                e.printStackTrace();
                        }
                }
+*/             
        }
+       
+       private static int ReadMessage(InputStream is, byte[] bytes) throws IOException {
+           byte[] rpcHeader = new byte[2];
+           int offset, len;
+           int read;
+           
+           read = is.read(rpcHeader, 0, 2);
+           len = rpcHeader[1] + 2;
+           
+           bytes[0] = rpcHeader[0];
+           bytes[1] = rpcHeader[1];
+           
+           if (read == -1) { return -1;}
+           
+           Log.i("ReadMessage", "RPC CMD: " + rpcHeader[0] + ", RPC LEN: " + rpcHeader[1]);
+           
+           offset = 2;
+           while (offset < len) {
+               read = is.read(bytes, offset, len - offset);
+               if (read == -1) {
+/*                 if ( offset == 0 ) {
+                       return -1;
+                   } else {
+                       return offset;
+                   }*/
+               } else {
+                   offset += read;
+               }
+           }
+
+           return len;
+       }       
 
        public static String getGatewayIp() {
                return gatewayIp;
old mode 100644 (file)
new mode 100755 (executable)
index 6709d54..6bd647e
@@ -164,11 +164,11 @@ public class bindSelect extends Activity {
        ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControllingToggle);
        if ( (idDeviceButton.isChecked()) && (currControllingDevice != null))
        {
-               //ZigbeeAssistant.Identify(currControllingDevice, (short) 0x80);
+               ZigbeeAssistant.IdentifyDevice(currControllingDevice, (short) 0x80);
        }
        else if(currControllingDevice != null)
        {
-               //ZigbeeAssistant.Identify(currControllingDevice, (short) 0);                   
+               ZigbeeAssistant.IdentifyDevice(currControllingDevice, (short) 0);               
        }    
     }
     
@@ -176,11 +176,11 @@ public class bindSelect extends Activity {
        ToggleButton idDeviceButton = (ToggleButton) findViewById(R.id.IdControlledToggle);
        if ( (idDeviceButton.isChecked()) && (currControlledDevice != null))
        {
-               //ZigbeeAssistant.Identify(currControlledDevice, (short) 0x80);
+               ZigbeeAssistant.IdentifyDevice(currControlledDevice, (short) 0x80);
        }
        else if(currControlledDevice != null)
        {
-               //ZigbeeAssistant.Identify(currControlledDevice, (short) 0);                    
+               ZigbeeAssistant.IdentifyDevice(currControlledDevice, (short) 0);                
        }    
     }
     
old mode 100644 (file)
new mode 100755 (executable)
index baa6120..97248ac
@@ -205,8 +205,7 @@ public class groupSelect extends Activity {
                        public void onClick(DialogInterface dialoginterface,int i){                                                                     
                                        ZigbeeAssistant.newGroup(t.getText().toString() );                                                      
                                //set selection to the new group, which will be last as this is a new one                                               
-                               currGroup = groupSpinnerAdapter.getCount();                                     
-                               new waitRspTask().execute("Create Group");                                      
+                               currGroup = groupSpinnerAdapter.getCount();                                                                             
                                groupSpinner.setSelection(currGroup);
                                //update the spinner
                                addItemsOnGroupSpinner();                                                                                   
@@ -214,75 +213,7 @@ public class groupSelect extends Activity {
                })                              
                .setNegativeButton("Cancel", null)
                .show();                
-       }
-         
-
-
-    class waitRspTask extends AsyncTask<String , Integer, Void>
-    {
-       private boolean rspSuccess;
-       String param;
-        @Override
-        protected void onPreExecute()
-        {
-            bar = new ProgressDialog(groupSelect.this);
-            bar.setMessage("Processing..");
-            bar.setIndeterminate(true);
-            bar.show();
-        } 
-        @Override
-        protected Void doInBackground(String... params) 
-        {
-               param = params[0];
-               List<ZigbeeGroup> groupList = ZigbeeAssistant.getGroups();
-               //currGroup = 0;
-            for(int i=0;i<10;i++)
-            {
-               if(currGroup < groupList.size())
-               {
-                       //check if group response updated the groupId          
-                       if (groupList.get(currGroup).getStatus() == ZigbeeGroup.groupStatusActive)
-                       {
-                               rspSuccess = true;
-                               return null;
-                       }
-               }
-                       
-                   try
-                   {
-                       Thread.sleep(500);
-                   }
-                   catch(Exception e)
-                   {
-                       System.out.println(e);
-                   }    
-                           
-            }
-                                               
-            rspSuccess = false;    
-            return null;
-        }
-        @Override
-        protected void onPostExecute(Void result) 
-        {
-            bar.dismiss();
-            
-            if (rspSuccess == false)
-               {
-               AlertDialog show = new AlertDialog.Builder(groupSelect.this)
-                       .setTitle(param)
-                       .setMessage("No response from gateway. " + param + " failed.")
-                       .setPositiveButton("OK",             
-                       new DialogInterface.OnClickListener()
-                       {                       
-                               public void onClick(DialogInterface dialoginterface,int i){                                     
-                               }               
-                       })                              
-                       .show();
-               }
-            
-        }
-    }
+       }         
         
 
     public void addToGroupCmdButton(View view) {
@@ -326,11 +257,11 @@ public class groupSelect extends Activity {
        ToggleButton idLightButton = (ToggleButton) findViewById(R.id.IdLightToggle);
        if (idLightButton.isChecked())
        {
-               //ZigbeeAssistant.Identify(currDevice, (short) 0x80);
+               ZigbeeAssistant.IdentifyDevice(currDevice, (short) 0x80);
        }
        else
        {
-               //ZigbeeAssistant.Identify(currDevice, (short) 0);              
+               ZigbeeAssistant.IdentifyDevice(currDevice, (short) 0);                  
        }    
     }
     
@@ -341,11 +272,11 @@ public class groupSelect extends Activity {
                        
        if (idGroupButton.isChecked())
        {
-               //ZigbeeAssistant.Identify(group, (short) 0xFFFF);
+               ZigbeeAssistant.IdentifyGroup(group, (short) 0xFFFF);
        }
        else
        {
-               //ZigbeeAssistant.Identify(group, (short) 0);                   
+               ZigbeeAssistant.IdentifyGroup(group, (short) 0);                
        }       
     }
        
old mode 100644 (file)
new mode 100755 (executable)
index 74277d5..4424ec5
@@ -49,6 +49,4 @@ public class optionsMenu extends Activity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.optionmenu);
     }
-    
 }
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 4b6b2b4..25295d5
@@ -186,8 +186,7 @@ public class sceneSelect extends Activity {
                                List<ZigbeeGroup> groupList = ZigbeeAssistant.getGroups();                              
                                ZigbeeAssistant.newScene(t.getText().toString(), groupList.get(currGroup).getGroupId() );                                                       
                        //set selection to the new group, which will be last as this is a new one                                               
-                       currScene = sceneSpinnerAdapter.getCount();                                     
-                       new waitRspTask().execute("Create Scene");                                      
+                       currScene = sceneSpinnerAdapter.getCount();                                                                             
                        sceneSpinner.setSelection(currScene);
                        //update the spinner
                        addItemsOnSceneSpinner();                                                                                   
@@ -195,76 +194,7 @@ public class sceneSelect extends Activity {
                })                              
                .setNegativeButton("Cancel", null)
                .show();                
-       }
-         
-
-
-    class waitRspTask extends AsyncTask<String , Integer, Void>
-    {
-       private boolean rspSuccess;
-       String param;
-        @Override
-        protected void onPreExecute()
-        {
-            bar = new ProgressDialog(sceneSelect.this);
-            bar.setMessage("Processing..");
-            bar.setIndeterminate(true);
-            bar.show();
-        } 
-        @Override
-        protected Void doInBackground(String... params) 
-        {
-               param = params[0];
-               List<ZigbeeScene> sceneList = ZigbeeAssistant.getScenes();
-               //currGroup = 0;
-            for(int i=0;i<10;i++)
-            {
-               if(currScene < sceneList.size())
-               {
-                       //check if group response updated the groupId          
-                       if (sceneList.get(currScene).getStatus() == ZigbeeScene.sceneStatusActive)
-                       {
-                               rspSuccess = true;
-                               return null;
-                       }
-               }
-                       
-                   try
-                   {
-                       Thread.sleep(500);
-                   }
-                   catch(Exception e)
-                   {
-                       System.out.println(e);
-                   }    
-                           
-            }
-                                               
-            rspSuccess = false;    
-            return null;
-        }
-        @Override
-        protected void onPostExecute(Void result) 
-        {
-            bar.dismiss();
-            
-            if (rspSuccess == false)
-               {
-               AlertDialog show = new AlertDialog.Builder(sceneSelect.this)
-                       .setTitle(param)
-                       .setMessage("No response from gateway. " + param + " failed.")
-                       .setPositiveButton("OK",             
-                       new DialogInterface.OnClickListener()
-                       {                       
-                               public void onClick(DialogInterface dialoginterface,int i){                                     
-                               }               
-                       })                              
-                       .show();
-               }
-            
-        }
-    }
-        
+       }                 
 
     public void sceneStoreButton(View view) {
        
old mode 100644 (file)
new mode 100755 (executable)
index 79e050f..adfcc12
@@ -44,6 +44,7 @@ import android.app.ProgressDialog;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.DisplayMetrics;
+import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -72,6 +73,7 @@ import java.util.concurrent.TimeUnit;
 import com.lightingcontroller.Zigbee.ZigbeeAssistant;
 import com.lightingcontroller.Zigbee.ZigbeeDevice;
 import com.lightingcontroller.Zigbee.ZigbeeGroup;
+import com.lightingcontroller.Zigbee.ZigbeeNotification;
 import com.lightingcontroller.ColourPicker;
 
 public class zllMain extends Activity {
@@ -80,9 +82,9 @@ public class zllMain extends Activity {
        
        public static ColourPicker colourPicker;
        private static ZigbeeGroup currGroup;   
-       private static ZigbeeDevice currDevice;
+       private static ZigbeeDevice currDevice = null;
        private Spinner deviceSpinner;
-       private ArrayAdapter<String> deviceSpinnerAdapter;
+       private static ArrayAdapter<String> deviceSpinnerAdapter;
        private int currentDeviceSpinnerSelection=0;    
        
        ProgressDialog bar;     
@@ -147,6 +149,8 @@ public class zllMain extends Activity {
         
         addItemsOnDeviceSpinner();
         addListenerOnDeviceSpinnerItemSelection();        
+        
+        ZigbeeNotification.init(this);
     }    
 
     // add items into spinner dynamically
@@ -165,6 +169,11 @@ public class zllMain extends Activity {
         {              
                deviceSpinnerAdapter.add("group: " + groupList.get(i).getGroupName());
         }        
+        
+        if( (currDevice == null) && (devList.size() > 0) )
+        {
+               currDevice = devList.get(0);
+        }        
     }
    
     public void addListenerOnDeviceSpinnerItemSelection() {            
@@ -187,7 +196,7 @@ public class zllMain extends Activity {
                        ZigbeeAssistant.getDeviceLevel(currDevice);
                        ZigbeeAssistant.getDeviceHue(currDevice);
                        ZigbeeAssistant.getDeviceSat(currDevice);
-                       //new waitRspTask().execute("Device Select");   
+                       new waitRspTask().execute("Device Select");     
                        
                        currGroup = null;
                }
@@ -243,18 +252,22 @@ public class zllMain extends Activity {
                        if( !currDevice.getCurrentStateUpdated() )
                        {
                                ZigbeeAssistant.getDeviceState(currDevice);
+                               try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();}  
                        }
                        if(     !currDevice.getCurrentLevelUpdated() )
                        {
                                ZigbeeAssistant.getDeviceLevel(currDevice);
+                               try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();}  
                        }
                        if(     !currDevice.getCurrentHueUpdated() )
                        {                       
                                ZigbeeAssistant.getDeviceHue(currDevice);
+                               try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();}  
                        }
                        if(     !currDevice.getCurrentSatUpdated() )
                        {                       
                                ZigbeeAssistant.getDeviceSat(currDevice);
+                               try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) {e.printStackTrace();}  
                        }                                       
                    }
                            
@@ -383,6 +396,11 @@ public class zllMain extends Activity {
 
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
+               case R.id.optionMenuAddDevice:
+               {
+                       new addDeviceTask().execute("Add Device");
+               }               
+                   break;            
             case R.id.optionMenuGroups: 
                startActivity(new Intent(zllMain.this, groupSelect.class));
                 break;                 
@@ -408,12 +426,17 @@ public class zllMain extends Activity {
                        alert = builder.create();
                        alert.show();
             }                  
-                break;
+                break;            
         }
         return true;
     }
  
     public void deviceChangeNameButton(View view)
+    {
+       deviceChangeName();
+    }
+    
+    public void deviceChangeName()
     { 
        String Title = "Set Name";
        String Msg = "Please Enter the name of the device";
@@ -498,4 +521,84 @@ public class zllMain extends Activity {
             ZigbeeAssistant.setDeviceLevel(currGroup, (char) level);
                }       
     }  
+    
+    class addDeviceTask extends AsyncTask<String , Integer, Void>
+    {
+       private boolean rspSuccess;
+       int numCurrentDevices;
+       int timeoutCnt;
+       String param;
+        @Override
+        protected void onPreExecute()
+        {
+            bar = new ProgressDialog(zllMain.this);
+            bar.setMessage("Searching For New Device");
+            bar.setIndeterminate(true);
+            bar.show();
+            
+            //count number of devices
+            numCurrentDevices = ZigbeeAssistant.getDevices().size();
+            
+            //open network
+            ZigbeeAssistant.openNetwork((byte)60);
+            
+        } 
+        @Override
+        protected Void doInBackground(String... params) 
+        {
+               param = params[0];
+               
+               //30s time out
+               for(timeoutCnt = 0; timeoutCnt < 60; timeoutCnt++)
+               {
+                       try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) {e.printStackTrace();}        
+                       
+                       if( ZigbeeAssistant.getDevices().size() > numCurrentDevices)
+                       {                       
+                               rspSuccess = true;                      
+                               return null;
+                       }
+               }
+               
+               rspSuccess = false;                     
+               return null;            
+        }
+        @Override
+        protected void onPostExecute(Void result) 
+        {
+            bar.dismiss();
+            
+            if (rspSuccess == false)
+               {
+               AlertDialog show = new AlertDialog.Builder(zllMain.this)
+                       .setTitle(param)
+                       .setMessage("No new devices found\n")
+                       .setPositiveButton("OK",             
+                       new DialogInterface.OnClickListener()
+                       {                       
+                               public void onClick(DialogInterface dialoginterface,int i){                                     
+                               }               
+                       })                              
+                       .show();
+               }
+            else
+            {
+               //Let notification change the name              
+            }                      
+        }
+    } 
+    
+    public static void setCurrentDevice(ZigbeeDevice device)
+    {
+       currDevice = device;
+        deviceSpinnerAdapter.clear();
+        List<ZigbeeDevice> tList = ZigbeeAssistant.getDevices();
+        for (int j = 0 ; j < tList.size() ; j++)
+        {
+               if (tList.get(j).hasColourable || tList.get(j).hasSwitchable || tList.get(j).hasDimmable)
+               {               
+                       deviceSpinnerAdapter.add(tList.get(j).Name);
+               }
+        }      
+    }
 }
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 9273277..12e6228
@@ -3,7 +3,7 @@
   Revised:        $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $
   Revision:       $Revision: 246 $
 
-  Description:    This file contains an example client for the zllGateway sever
+  Description:    This file contains an example client for the zbGateway sever
 
   Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
 
@@ -59,11 +59,11 @@ int keyFd;
 #define CONSOLEDEVICE "/dev/console"
 
 void sendLightState(uint16_t addr, uint16_t addrMode, uint16_t ep, uint8_t state);
-void socketClientZllCb( msgData_t *msg );
+void socketClientCb( msgData_t *msg );
 
-typedef uint8_t (*rpcsProcessMsg_t)(msgData_t *msg);
+typedef uint8_t (*srpcProcessMsg_t)(msgData_t *msg);
 
-rpcsProcessMsg_t rpcsProcessSeIncoming[] =
+srpcProcessMsg_t rpcsProcessSeIncoming[] =
 {  
 };
 
@@ -77,8 +77,9 @@ int main(int argc, char *argv[])
 {
   uint16_t  addr, period, loops;
   uint8_t addrMode, ep, cnt=0;
+  uint32 start_with = 0;
       
-  if(argc != 6)
+  if(argc < 6)
   {
     printf("Expected 4 and got %d params Usage: %s <device/group addr> <addr mode> <ep> <periodms> <loops>\n", argc, argv[0] );
     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[])
     
     sscanf(argv[5], "%d", &tmpInt);    
     loops = (uint16_t) tmpInt;
+
+    if (argc > 6)
+       {
+      start_with = atoi(argv[6]);
+    }
+               
   }
       
-  socketClientInit("127.0.0.1:11235", socketClientZllCb);
+  socketClientInit("127.0.0.1:11235", socketClientCb);
   
   if(loops != 0)
     loops+=2;
@@ -112,13 +119,13 @@ int main(int argc, char *argv[])
   while(loops != 2)
   {    
     printf("Toggling Light %x:%x - %d\n", addr, ep, cnt++ );
-    if((loops % 2) ==0
+    if((loops % 2) == start_with
     {
-      sendLightState(addr, addrMode, ep, 0);
+      sendLightState(addr, addrMode, ep, 1);
     }
     else
     {
-      sendLightState(addr, addrMode, ep, 1);
+      sendLightState(addr, addrMode, ep, 0);
     }
           
     usleep(period * 1000);
@@ -135,7 +142,7 @@ int main(int argc, char *argv[])
 }
 
 //Process the message from HA-Interface
-void socketClientZllCb( msgData_t *msg )
+void socketClientCb( msgData_t *msg )
 {
   //for now we are not interested in messages from HA server
 }
@@ -145,7 +152,7 @@ void sendLightState(uint16_t addr, uint16_t addrMode, uint16_t ep, uint8_t state
   msgData_t msg;
   uint8_t* pRpcCmd = msg.pData;                 
                
-  msg.cmdId = RPCS_SET_DEV_STATE;
+  msg.cmdId = SRPC_SET_DEV_STATE;
   msg.len = 15;
   //Addr Mode
   *pRpcCmd++ = (afAddrMode_t)addrMode;
old mode 100644 (file)
new mode 100755 (executable)
index 6128911..27b0afd
@@ -1,42 +1,42 @@
- /**************************************************************************************************
 Filename:       flashled.c
 Revised:        $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $
 Revision:       $Revision: 246 $
-
 Description:    This file contains an example client for the zllGateway sever
-
 Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
-
-
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
-
    Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-
    Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the
    distribution.
-
    Neither the name of Texas Instruments Incorporated nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.
-
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/**************************************************************************************************
+ Filename:       flashled.c
+ Revised:        $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $
+ Revision:       $Revision: 246 $
+
Description:    This file contains an example client for the zbGateway sever
+
+ Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
+
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of Texas Instruments Incorporated nor the names of
+ its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
-**************************************************************************************************/
+ **************************************************************************************************/
 
 #include <fcntl.h>
 #include <termios.h>
 #include <sys/socket.h>
 #include <poll.h>
 
-
 #include "socket_client.h"
 #include "interface_srpcserver.h"
 #include "hal_defs.h"
-int keyFd;
 
 #define CONSOLEDEVICE "/dev/console"
 
-void socketClientZllCb( msgData_t *msg ); 
-uint8_t RPSC_ZLL_NewDevice(uint8_t *msg);
-static void srpcSendGetDevices( void );
+void socketClientCb(msgData_t *msg);
+uint8_t SRPC_NewDevice(uint8_t *msg);
+static void srpcSendGetDevices(void);
 
-typedef uint8_t (*rpcsProcessMsg_t)(uint8_t *msg);
+typedef uint8_t (*srpcProcessMsg_t)(uint8_t *msg);
 
-rpcsProcessMsg_t rpcsProcessZllIncoming[] =
+typedef struct {
+       char * str;
+       uint16_t id;
+} device_id_strings_t;
+
+device_id_strings_t device_id_strings[] =
 {
-  NULL,
-  RPSC_ZLL_NewDevice, 
-};
+{ "On/Off Switch", 0x0000 },
+{ "Level Control Switch", 0x0001 },
+{ "On/Off Output", 0x0002 },
+{ "Level Controllable Output", 0x0003 },
+{ "Scene Selector", 0x0004 },
+{ "Configuration Tool", 0x0005 },
+{ "Remote Control", 0x0006 },
+{ "Combined Interface", 0x0007 },
+{ "Range Extender", 0x0008 },
+{ "Mains Power Outlet", 0x0009 },
+{ "Door Lock", 0x000A },
+{ "Door Lock Controller", 0x000B },
+{ "Simple Sensor", 0x000C },
+{ "On/Off Light", 0x0100 },
+{ "Dimmable Light", 0x0101 },
+{ "Color Dimmable Light", 0x0102 },
+{ "On/Off Light Switch", 0x0103 },
+{ "Dimmer Switch", 0x0104 },
+{ "Color Dimmer Switch", 0x0105 },
+{ "Light Sensor", 0x0106 },
+{ "Occupancy Sensor", 0x0107 },
+{ "Shade", 0x0200 },
+{ "Shade Controller", 0x0201 },
+{ "Window Covering Device", 0x0202 },
+{ "Window Covering Controller", 0x0203 },
+{ "Heating/Cooling Unit", 0x0300 },
+{ "Thermostat", 0x0301 },
+{ "Temperature Sensor", 0x0302 },
+{ "Pump", 0x0303 },
+{ "Pump Controller", 0x0304 },
+{ "Pressure Sensor", 0x0305 },
+{ "Flow Sensor", 0x0306 },
+{ "IAS Control and Indicating Equipment", 0x0400 },
+{ "IAS Ancillary Control Equipment", 0x0401 },
+{ "IAS Zone", 0x0402 },
+{ "IAS Warning Device", 0x0403 }, };
+
+srpcProcessMsg_t srpcProcessIncoming[] =
+{ NULL, SRPC_NewDevice, };
 
+int keyFd;
 
+/*********************************************************************
+ * @fn          main
+ *
+ * @brief      
+ *
+ * @param     
+ *
+ * @return     
+ */
 int main(int argc, char *argv[])
 {
-  int ret;
-      
-  socketClientInit("127.0.0.1:11235", socketClientZllCb);
-  
-  //send get devices command
-  srpcSendGetDevices();
-  
-  while(1)
-  {
-    struct pollfd pollFds[1];
-    
-               pollFds[0].fd = keyFd;  
-         pollFds[0].events = POLLIN;
-         
-         ret = poll(pollFds, 1, -1);
-       
-    if (ret > 0) 
-    {
-      if( ((pollFds[0].revents) & POLLIN) )
-      {  
-        //Any key ppress will exit
-        socketClientClose();
-        exit(0);
-      }
-    }    
-  }
-   
-  socketClientClose();
-  
-  return 0;
+       int ret;
+
+       socketClientInit("127.0.0.1:11235", socketClientCb);
+
+       printf(
+                       "--- List of devices ----------------------------------------------------\n");
+       printf(
+                       "addr   ep   profID devID  IEEEAddr                deviceIdString\n");
+       printf(
+                       "------ ---- ------ ------ ----------------------- ----------------------\n");
+
+       //send get devices command
+       srpcSendGetDevices();
+
+       while (1)
+       {
+               struct pollfd pollFds[1];
+
+               pollFds[0].fd = keyFd;
+               pollFds[0].events = POLLIN;
+
+               ret = poll(pollFds, 1, -1);
+
+               if (ret > 0)
+               {
+                       if (((pollFds[0].revents) & POLLIN))
+                       {
+                               //Any key ppress will exit
+                               socketClientClose();
+                               exit(0);
+                       }
+               }
+       }
+
+       socketClientClose();
+
+       return 0;
 }
 
-//Process the message from SE-Interface
-void socketClientZllCb( msgData_t *msg )
+/*********************************************************************
+ * @fn          socketClientCb
+ *
+ * @brief      
+ *
+ * @param     
+ *
+ * @return     
+ */
+void socketClientCb(msgData_t *msg)
 {
-  rpcsProcessMsg_t func;
-
-  func = rpcsProcessZllIncoming[(msg->cmdId)];
-  if (func)
-  {
-    (*func)(msg->pData);
-  }
-  else
-  {
-    printf("Error: no processing function for CMD 0x%x\n", msg->cmdId); 
-  }
-      
+       srpcProcessMsg_t func;
+
+       func = srpcProcessIncoming[(msg->cmdId)];
+       if (func)
+       {
+               (*func)(msg->pData);
+       }
 }
 
-static void srpcSendGetDevices( void )
-{ 
-  msgData_t srpcCmd;
-  
-  srpcCmd.cmdId = RPCS_GET_DEVICES;
-  srpcCmd.len = 0;
-  
-  socketClientSendData (&srpcCmd);
-    
-  return; 
+/*********************************************************************
+ * @fn          srpcSendGetDevices
+ *
+ * @brief      
+ *
+ * @param     
+ *
+ * @return     
+ */
+static void srpcSendGetDevices(void)
+{
+       msgData_t srpcCmd;
+
+       srpcCmd.cmdId = SRPC_GET_DEVICES;
+       srpcCmd.len = 0;
+
+       socketClientSendData(&srpcCmd);
+
+       return;
 }
 
 /*********************************************************************
- * @fn          RPSC_ZLL_NewDevice
+ * @fn          get_device_id_string
+ *
+ * @brief      
+ *
+ * @param     
+ *
+ * @return     
+ */
+char * get_device_id_string(uint16_t id)
+{
+       char * device_id_string = "Unknown device";
+       int x;
+
+       for (x = 0; x < (sizeof(device_id_strings) / sizeof(device_id_strings[0]));
+                       x++)
+       {
+               if (id == device_id_strings[x].id)
+               {
+                       device_id_string = device_id_strings[x].str;
+                       break;
+               }
+       }
+
+       return device_id_string;
+}
+
+/*********************************************************************
+ * @fn          SRPC_NewDevice
  *
  * @brief       This function proccesses the NewDevice message from the ZLL Gateway.
  *
@@ -145,46 +239,51 @@ static void srpcSendGetDevices( void )
  *
  * @return      afStatus_t
  */
-uint8_t RPSC_ZLL_NewDevice(uint8_t *pMsg)
-{    
-  epInfo_t epInfo;
-  uint8_t devNameStrLen;
-  static int i=0;
-  uint8_t* pTmpMsg; 
-   
-  printf("RPSC_ZLL_NewDevice++\n");  
-  
-  pTmpMsg = pMsg;
-  
-  epInfo.nwkAddr = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]);
-  pTmpMsg+=2;
-
-  epInfo.endpoint = *pTmpMsg++;
-  
-  epInfo.profileID = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]);
-  pTmpMsg+=2;
-  
-  epInfo.deviceID = BUILD_UINT16(pTmpMsg[0], pTmpMsg[1]);
-  pTmpMsg+=2;
-
-  epInfo.version = *pTmpMsg++;
-  
-  //skip name for now
-  devNameStrLen = *pTmpMsg;
-  pTmpMsg += devNameStrLen + 1;
-
-  epInfo.status = *pTmpMsg++;
-  
-  epInfo.IEEEAddr[0] = *pTmpMsg++;
-  epInfo.IEEEAddr[1] = *pTmpMsg++;
-  epInfo.IEEEAddr[2] = *pTmpMsg++;
-  epInfo.IEEEAddr[3] = *pTmpMsg++;
-  epInfo.IEEEAddr[4] = *pTmpMsg++;
-  epInfo.IEEEAddr[5] = *pTmpMsg++;
-  epInfo.IEEEAddr[6] = *pTmpMsg++;
-  epInfo.IEEEAddr[7] = *pTmpMsg++;
-    
-  printf("RPSC_ZLL_NewDevice[%d]: %x:%x\n", i++, epInfo.nwkAddr, epInfo.endpoint);  
-      
-  return 0;  
+uint8_t SRPC_NewDevice(uint8_t *pMsg)
+{
+       epInfo_t epInfo;
+       uint8_t devNameStrLen;
+       int i;
+       char * devNameStr;
+
+       epInfo.nwkAddr = BUILD_UINT16(pMsg[0], pMsg[1]);
+       pMsg += 2;
+
+       epInfo.endpoint = *pMsg++;
+
+       epInfo.profileID = BUILD_UINT16(pMsg[0], pMsg[1]);
+       pMsg += 2;
+
+       epInfo.deviceID = BUILD_UINT16(pMsg[0], pMsg[1]);
+       pMsg += 2;
+
+       epInfo.version = *pMsg++;
+
+       //skip name for now
+       devNameStrLen = *pMsg++;
+       devNameStr = (char *) pMsg;
+       pMsg += devNameStrLen;
+
+       epInfo.status = *pMsg++;
+
+       for (i = 0; i < 8; i++)
+       {
+               //printf("srpcParseEpInfp: IEEEAddr[%d] = %x\n", i, epInfo->IEEEAddr[i]);
+               epInfo.IEEEAddr[i] = *pMsg++;
+       }
+
+       printf(" 0x%04X 0x%02X 0x%04X 0x%04X ", epInfo.nwkAddr, epInfo.endpoint,
+                       epInfo.profileID, epInfo.deviceID);
+
+       for (i = 0; i < 8; i++)
+       {
+               printf("%s%02X", i > 0 ? ":" : "", epInfo.IEEEAddr[7 - i]);
+       }
+
+       printf("------");
+
+       printf(" %-*s \"%.*s\"\n", 36, get_device_id_string(epInfo.deviceID),
+                       devNameStrLen, devNameStr);
+
+       return 0;
 }
diff --git a/client/CClients/openNetwork/Source/openNetwork.c b/client/CClients/openNetwork/Source/openNetwork.c
new file mode 100755 (executable)
index 0000000..589493d
--- /dev/null
@@ -0,0 +1,161 @@
+/**************************************************************************************************
+ Filename:       addGroup.c
+ Revised:        $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $
+ Revision:       $Revision: 246 $
+
+ Description:    This file contains an example client for the zbGateway sever
+
+ Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
+
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of Texas Instruments Incorporated nor the names of
+ its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ **************************************************************************************************/
+#include <fcntl.h>
+#include <termios.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <poll.h>
+
+#include "socket_client.h"
+#include "interface_srpcserver.h"
+#include "hal_defs.h"
+
+int keyFd;
+uint8 waitRsp = 1;
+
+#define CONSOLEDEVICE "/dev/console"
+
+void sendOpenNetwork(uint8_t duration);
+void socketClientCb(msgData_t *msg);
+
+typedef uint8_t (*srpcProcessMsg_t)(uint8_t *msg);
+
+srpcProcessMsg_t srpcProcessIncoming[] =
+{
+               NULL,                                                   //0
+               NULL,                                                   //SRPC_NEW_ZLL_DEVICE     0x0001
+               NULL,                                           //SRPC_RESERVED_1                     0x0002
+               NULL,                                           //SRPC_RESERVED_2               0x0003
+               NULL,                                           //SRPC_RESERVED_3         0x0004
+               NULL,                                           //SRPC_RESERVED_4         0x0005
+               NULL,                                           //SRPC_RESERVED_5         0x0006
+               NULL,                                           //SRPC_GET_DEV_STATE_RSP  0x0007
+               NULL,                                           //SRPC_GET_DEV_LEVEL_RSP  0x0008
+               NULL,                                           //SRPC_GET_DEV_HUE_RSP    0x0009
+               NULL,                                           //SRPC_GET_DEV_SAT_RSP    0x000a
+               NULL, //SRPC_ADD_GROUP_RSP      0x000b
+               NULL,                                           //SRPC_GET_GROUP_RSP      0x000c
+               NULL,                                           //SRPC_ADD_SCENE_RSP      0x000d
+               NULL,                                           //SRPC_GET_SCENE_RSP      0x000e
+};
+
+void keyInit(void)
+{
+       keyFd = open(CONSOLEDEVICE, O_RDONLY | O_NOCTTY | O_NONBLOCK);
+       tcflush(keyFd, TCIFLUSH);
+}
+
+int main(int argc, char *argv[])
+{
+       uint8_t duration;
+
+       if (argc < 2)
+       {
+               printf(
+                               "Expected 1 and got %d params Usage: %s <duration> <addr mode> <ep> <group name>\n",
+                               argc, argv[0]);
+               printf(
+                               "Example - open network for 60s: %s 60\n",
+                               argv[0]);
+               exit(0);
+       }
+       else
+       {
+               uint32_t tmpInt;
+
+               sscanf(argv[1], "%d", &tmpInt);
+               duration = (uint8_t) tmpInt;
+       }
+
+       socketClientInit("127.0.0.1:11235", socketClientCb);
+
+       sendOpenNetwork(duration);
+
+       sleep(1);
+
+       socketClientClose();
+
+       return 0;
+}
+
+/*********************************************************************
+ * @fn          socketClientCb
+ *
+ * @brief
+ *
+ * @param
+ *
+ * @return
+ */
+void socketClientCb(msgData_t *msg)
+{
+       srpcProcessMsg_t func;
+
+       printf("socketClientCb: cmdId:%x\n",(msg->cmdId));
+
+       func = srpcProcessIncoming[(msg->cmdId)];
+       if (func)
+       {
+               (*func)(msg->pData);
+       }
+}
+
+void sendOpenNetwork(uint8_t duration)
+{
+       msgData_t msg;
+       uint8_t* pRpcCmd = msg.pData;
+
+       printf("sendOpenNetwork++: duration=%d\n", duration);
+
+       msg.cmdId = SRPC_OPEN_NETWORK;
+       msg.len = 3;
+
+       //duration
+       *pRpcCmd++ = duration;
+
+       socketClientSendData(&msg);
+}
diff --git a/client/CClients/openNetwork/i486-linux-gnu/makefile b/client/CClients/openNetwork/i486-linux-gnu/makefile
new file mode 100755 (executable)
index 0000000..1ea0e57
--- /dev/null
@@ -0,0 +1,34 @@
+DEVICE = COORDINATOR
+#DEVICE = ROUTER
+#DEVICE = ENDDEV
+
+#Relative project path
+PROJ_DIR = 
+
+INCLUDE = -I$(PROJ_DIR)../../../../server/Source -I$(PROJ_DIR)../Source -I$(PROJ_DIR)../../Source
+LIBS = -lpthread
+
+#CC= /data/opt/vendors/codesourcery/lite/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc
+CC= gcc
+#CC=arm-angstrom-linux-gnueabi-gcc
+#CC=arm-none-linux-gnueabi-gcc
+#CC=/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc
+
+CFLAGS= -c -Wall -g -std=gnu99
+
+all: openNetwork.bin
+
+openNetwork.bin: openNetwork.o socket_client.o
+       $(CC) openNetwork.o socket_client.o $(LIBS) -o openNetwork.bin
+
+# rule for file "openNetwork.o".
+openNetwork.o: ../Source/openNetwork.c
+       $(CC) $(CFLAGS) $(INCLUDE) $(DEFS) $(PROJ_DIR)../Source/openNetwork.c 
+
+# rule for file "socket_client.o".
+socket_client.o: $(PROJ_DIR)../../Source/socket_client.h $(PROJ_DIR)../../Source/socket_client.c
+       $(CC) $(CFLAGS) $(INCLUDE) $(DEFS) $(PROJ_DIR)../../Source/socket_client.c
+
+# rule for cleaning files generated during compilations.
+clean:
+       /bin/rm -f openNetwork.bin *.o
diff --git a/getFwModel/getFwModel.c b/getFwModel/getFwModel.c
new file mode 100755 (executable)
index 0000000..094edfb
--- /dev/null
@@ -0,0 +1,178 @@
+/**************************************************************************************************\r
+ * Filename:       fwGetModel.c\r
+ * Description:    This file contains the interface to the UART.\r
+ *\r
+ *\r
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/\r
+ *\r
+ *\r
+ *  Redistribution and use in source and binary forms, with or without\r
+ *  modification, are permitted provided that the following conditions\r
+ *  are met:\r
+ *\r
+ *    Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ *\r
+ *    Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ *    Neither the name of Texas Instruments Incorporated nor the names of\r
+ *    its contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ */\r
+\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <poll.h>\r
+\r
+#include "zbSocCmd.h"\r
+\r
+uint8_t tlIndicationCb(epInfo_t *epInfo);\r
+uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr,\r
+               uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState);\r
+uint8_t zclGetModelCb(uint8_t *ModelId);\r
+\r
+static zbSocCallbacks_t zbSocCbs =\r
+{ tlIndicationCb, // pfnTlIndicationCb - TouchLink Indication callback\r
+               NULL, // pfnNewDevIndicationCb - New Device Indication callback\r
+               NULL, //pfnZclGetStateCb - ZCL response callback for get State\r
+               NULL, //pfnZclGetLevelCb_t - ZCL response callback for get Level\r
+               NULL, // pfnZclGetHueCb - ZCL response callback for get Hue\r
+               NULL, //pfnZclGetSatCb - ZCL response callback for get Sat\r
+               NULL, //pfnzdoSimpleDescRspCb - ZDO simple desc rsp\r
+               NULL, // pfnZdoLeaveIndCb - ZDO Leave indication\r
+               utilGetDevInfoRspCb, //pfnUtilGetDevInfoRspCb\r
+               zclGetModelCb //pfnZclGetModelCb\r
+               };\r
+\r
+void usage(char* exeName)\r
+{\r
+       printf("Usage: ./%s <port>\n", exeName);\r
+       printf("Eample: ./%s /dev/ttyACM0\n", exeName);\r
+}\r
+\r
+int main(int argc, char* argv[])\r
+{      \r
+       int retval = 0;\r
+       int zbSoc_fd;\r
+\r
+       //printf("%s -- %s %s\n", argv[0], __DATE__, __TIME__);\r
+\r
+\r
+       // accept only 1\r
+       if (argc != 2)\r
+       {\r
+               usage(argv[0]);\r
+               //printf("attempting to use /dev/ttyACM0\n");\r
+               zbSoc_fd = zbSocOpen("/dev/ttyO4");\r
+       }\r
+       else\r
+       {\r
+               zbSoc_fd = zbSocOpen(argv[1]);\r
+       }\r
+\r
+       if (zbSoc_fd == -1)\r
+       {\r
+               exit(-1);\r
+       }\r
+\r
+       zbSocRegisterCallbacks(zbSocCbs);\r
+\r
+       zbSocGetInfo();\r
+\r
+       while (1)\r
+       {\r
+               struct pollfd pollFd;\r
+\r
+               //set the zllSoC serial port FD in the poll file descriptors\r
+               pollFd.fd = zbSoc_fd;\r
+               pollFd.events = POLLIN;\r
+\r
+               //printf("%s: waiting for poll()\n", argv[1]);\r
+\r
+               poll(&pollFd, 1, 500);\r
+\r
+               //printf("%s: got poll()\n", argv[1]);\r
+\r
+               //did the poll unblock because of the zllSoC serial?\r
+               if (pollFd.revents)\r
+               {\r
+                       //printf("%s: Message from ZB SoC\n", argv[1]);\r
+                       zbSocProcessRpc();\r
+               }\r
+                else\r
+                {\r
+                        //printf("timeout\n");\r
+                       static int timeoutCnt = 0;\r
+                       timeoutCnt++;\r
+                       if(timeoutCnt > 5)\r
+                       {\r
+                               printf("Unknown model\n");\r
+                               zbSocClose();\r
+                               exit(0);\r
+                       }\r
+                       else if(timeoutCnt > 3)\r
+                       {\r
+                               //maybe MT_UTIL is not define, assume coord (nwkAddr=0x0) and try to get model ID\r
+                               zbSocGetModel(0x0000, 0xff, afAddr16Bit);\r
+                       }\r
+                       else\r
+                       {\r
+                               zbSocGetInfo();\r
+                       }\r
+                }\r
+       }\r
+\r
+       return retval;\r
+}\r
+\r
+uint8_t tlIndicationCb(epInfo_t *epInfo)\r
+{\r
+\r
+return 0;\r
+}\r
+\r
+uint8_t utilGetDevInfoRspCb(uint8_t status, uint16_t nwkAddr,\r
+       uint8_t ieeeAddr[8], uint8_t devType, uint8_t devState)\r
+{\r
+       //printf("processRpcUtilGetDevInfoRsp: status:%x devState:%x, nwkAddr:%x ieeeIdx:%x:%x:%x:%x:%x:%x:%x:%x\n", status, devState, nwkAddr,\r
+//ieeeAddr[7], ieeeAddr[6], ieeeAddr[5], ieeeAddr[4], ieeeAddr[3], ieeeAddr[2], ieeeAddr[1], ieeeAddr[0]);\r
+\r
+       zbSocGetModel(nwkAddr, 0xff, afAddr16Bit);\r
+\r
+       return 0;\r
+}\r
+\r
+uint8_t zclGetModelCb(uint8_t *ModelId)\r
+{\r
+       uint8_t strIdx;\r
+       printf("Model ID:");\r
+\r
+       for(strIdx = 0; strIdx < ModelId[0]; strIdx++)\r
+       {\r
+               printf("%c", ModelId[strIdx+1]);\r
+       }\r
+       printf("\n");\r
+\r
+       zbSocClose();\r
+       exit(0);\r
+\r
+       return 0;\r
+}\r
+\r
diff --git a/getFwModel/makefile b/getFwModel/makefile
new file mode 100755 (executable)
index 0000000..f3530a1
--- /dev/null
@@ -0,0 +1,26 @@
+\r
+SBU_REV= "0.1"\r
+\r
+\r
+GCC = gcc\r
+\r
+CFLAGS = -Wall -DVERSION_NUMBER=${SBU_REV}\r
+OBJECTS = getFwModel.o ../zbSocDriver/zbSocCmd.o\r
+INCLUDE = -I../zbSocDriver/\r
+DEFS =\r
+\r
+APP_NAME=getFwModel.bin\r
+\r
+.PHONY: all, clean\r
+\r
+${APP_NAME}: ${OBJECTS}\r
+       $(GCC) $(CFLAGS) $(OBJECTS) -o ${APP_NAME}\r
+\r
+%.o: %.c\r
+       ${GCC} ${CFLAGS} ${INCLUDE} ${DEFS} -c -o $@ $<\r
+\r
+all: ${APP_NAME}\r
+\r
+clean:\r
+       rm -rf *.o ${APP_NAME}\r
+       rm -rf ../zbSocDriver/*.o ${APP_NAME}\r
diff --git a/server/Source/SimpleDB.c b/server/Source/SimpleDB.c
new file mode 100755 (executable)
index 0000000..bc486fe
--- /dev/null
@@ -0,0 +1,611 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include "hal_types.h"
+#include "SimpleDB.h"
+
+#define TEMP_FILENAME_EXTENTION_LENGTH 4
+
+int sdbErrno;
+
+typedef struct {
+       char name[MAX_SUPPORTED_FILENAME + TEMP_FILENAME_EXTENTION_LENGTH + 1];
+       FILE * file;
+       long last_accessed_record_start_file_pointer;
+       uint32_t last_accessed_record_size;
+       get_record_size_f get_record_size;
+       check_deleted_f check_deleted;
+       check_ignore_f check_ignore;
+       mark_deleted_f mark_deleted;
+       consolidation_processing_f consolidation_processing;
+       uint8_t type;
+       uint32_t bin_header_size;
+} _db_descriptor;
+
+db_descriptor * sdb_init_db(char * name, get_record_size_f get_record_size,
+               check_deleted_f check_deleted, check_ignore_f check_ignore,
+               mark_deleted_f mark_deleted,
+               consolidation_processing_f consolidation_processing, uint8_t db_type,
+               uint32_t db_bin_header_size)
+{
+       _db_descriptor * db;
+       int abort = FALSE;
+
+       db = malloc(sizeof(_db_descriptor));
+
+       if (db != NULL)
+       {
+               if (strlen(name) > MAX_SUPPORTED_FILENAME)
+               {
+                       abort = TRUE;
+               }
+               else
+               {
+                       strcpy(db->name, name);
+
+                       db->file = fopen(name, (db_type == SDB_TYPE_TEXT) ? "r+t" : "r+b");
+                       if ((db->file == NULL) && (errno == ENOENT))
+                       {
+                               db->file = fopen(name, (db_type == SDB_TYPE_TEXT) ? "w+t" : "w+b");
+                       }
+
+                       if (db->file == NULL)
+                       {
+                               abort = TRUE;
+                       }
+                       else
+                       {
+                               db->last_accessed_record_start_file_pointer = 0;
+                               db->last_accessed_record_size = 0;
+                               db->get_record_size = get_record_size;
+                               db->check_deleted = check_deleted;
+                               db->check_ignore = check_ignore;
+                               db->mark_deleted = mark_deleted;
+                               db->consolidation_processing = consolidation_processing;
+                               db->type = db_type;
+                               db->bin_header_size = db_bin_header_size; //used only for binary-type databases.
+                       }
+               }
+       }
+
+       if (abort)
+       {
+               free(db);
+               db = NULL;
+       }
+
+       return (db_descriptor *) db;
+}
+
+bool sdb_release_db(db_descriptor ** _db)
+{
+       _db_descriptor * db = *_db;
+
+       if (db != NULL)
+       {
+               fclose(db->file);
+               free(db);
+               *_db = NULL;
+               return TRUE;
+       }
+       else
+       {
+               return FALSE;
+       }
+}
+
+void sdb_flush_db(db_descriptor * db)
+{
+       // do nothing.
+       // In the current implementation,  flushing is done automatically after every change
+}
+
+bool sdb_release_record(void ** record)
+{
+       // In the current implementation, the retrieved record is statically allocated, so no need to release it.
+       *record = NULL;
+       return TRUE;
+}
+
+bool sdb_add_record(db_descriptor * _db, void * rec)
+{
+       _db_descriptor * db = _db;
+
+       if (fseek(db->file, 0, SEEK_END) != 0)
+       {
+               return FALSE;
+       }
+
+       db->last_accessed_record_start_file_pointer = ftell(db->file);
+       db->last_accessed_record_size = db->get_record_size(rec);
+
+       return ((fwrite(rec, db->get_record_size(rec), 1, db->file) == 1)
+                       && (fflush(db->file) == 0));
+}
+
+bool sdb_modify_last_accessed_record(db_descriptor * _db, void * record)
+{
+       _db_descriptor * db = _db;
+
+       if ((db->get_record_size(record) != db->last_accessed_record_size)
+                       || ((fseek(db->file, db->last_accessed_record_start_file_pointer,
+                                       SEEK_SET) != 0)
+                                       || (fwrite(record, db->last_accessed_record_size, 1, db->file) != 1)
+                                       || (fflush(db->file) != 0)))
+       {
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void * sdb_delete_record(db_descriptor * _db, void * key, check_key_f check_key)
+{
+       _db_descriptor * db = _db;
+       void * rec;
+       uint32_t size;
+
+       sdbErrno = 0;
+
+       rec = sdb_get_record(db, key, check_key, NULL);
+
+       if (rec != NULL)
+       {
+
+               size = db->get_record_size(rec);
+               db->mark_deleted(rec);
+
+               if (!sdb_modify_last_accessed_record(db, rec))
+               {
+                       sdbErrno = 1;
+                       rec = NULL;
+               }
+       }
+
+       return rec;
+}
+
+bool sdb_rename_db(db_descriptor * _db, char * newName)
+{
+       _db_descriptor * db = _db;
+       int rc;
+
+       fclose(db->file);
+
+       rc = rename(db->name, newName);
+       if (rc != 0)
+       {
+               return FALSE;
+       }
+
+       strcpy(db->name, newName);
+
+       db->file = fopen(db->name, (db->type == SDB_TYPE_TEXT) ? "r+t" : "r+b");
+
+       if (db->file == NULL)
+       {
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+bool sdb_consolidate_db(db_descriptor ** _db)
+{
+       _db_descriptor * db = *_db;
+       _db_descriptor * tempDb;
+       void * rec;
+       uint32_t context;
+       int rc;
+
+       char tempfilename[MAX_SUPPORTED_FILENAME + TEMP_FILENAME_EXTENTION_LENGTH + 1];
+
+       strcpy(tempfilename, db->name);
+       strcat(tempfilename, ".tmp");
+
+       rc = remove(tempfilename);
+       if ((rc != 0) && (errno != ENOENT))
+       {
+               return FALSE;
+       }
+
+       tempDb = sdb_init_db(tempfilename, db->get_record_size, db->check_deleted,
+                       db->check_ignore, db->mark_deleted, db->consolidation_processing,
+                       db->type, db->bin_header_size);
+
+       if (tempDb == NULL)
+       {
+               return FALSE;
+       }
+
+       db->check_ignore = NULL; //only deleted lines should be removed. Ignored lines should stay.
+
+       rec = SDB_GET_FIRST_RECORD(db, &context);
+       rc = TRUE;
+       while ((rec != NULL) && (rc == TRUE))
+       {
+
+               if (db->consolidation_processing != NULL)
+               {
+                       rc = db->consolidation_processing(tempDb, rec);
+//                     devListErrorComment(tempDb, rec);
+               }
+               else
+               {
+                       rc = sdb_add_record(tempDb, rec);
+               }
+
+               rec = SDB_GET_NEXT_RECORD(db, &context);
+       }
+
+       strcpy(tempfilename, db->name);
+
+       sdb_release_db(_db);
+       (*_db) = tempDb;
+
+       rc = remove(tempfilename);
+
+       if (rc != 0)
+       {
+               return FALSE;
+       }
+
+       rc = sdb_rename_db(*_db, tempfilename);
+
+       return rc;
+}
+
+void * sdb_get_record(db_descriptor * _db, void * key, check_key_f check_key,
+               uint32_t * context)
+{
+       _db_descriptor * db = _db;
+       static char rec[MAX_SUPPORTED_RECORD_SIZE];
+       bool found = FALSE;
+       uint32_t _context;
+
+       if (context != NULL)
+       {
+               _context = *context;
+       }
+       else
+       {
+               _context = 0;
+       }
+
+       int curPos = ftell(db->file);
+       fseek(db->file, 0, SEEK_END);
+       fseek(db->file, curPos, SEEK_SET);
+
+       if (ftell(db->file) != _context)
+       {
+               fseek(db->file, _context, SEEK_SET);
+       }
+
+       if (db->type == SDB_TYPE_TEXT)
+       {
+               while ((!found) && (fgets(rec, sizeof(rec), db->file) != NULL)) //order matters!!!
+               {
+                       db->last_accessed_record_start_file_pointer = _context;
+                       db->last_accessed_record_size = db->get_record_size(rec);
+                       _context = ftell(db->file);
+
+                       if (rec[strlen(rec) - 1] != '\n')
+                       {
+                               //todo: set errno: record too long
+                               return NULL;
+                       }
+
+                       if ((!(db->check_deleted(rec)))
+                                       && ((db->check_ignore == NULL) || (!(db->check_ignore(rec))))
+                                       && ((check_key == NULL)
+                                                       || (check_key(rec, key) == SDB_CHECK_KEY_EQUAL)))
+                       {
+                               found = TRUE;
+                       }
+               }
+       }
+       else //db->type == SDB_TYPE_BINARY
+       {
+               //todo
+       }
+
+       if (!found)
+       {
+               return NULL;
+       }
+
+       if (context != NULL)
+       {
+               *context = _context;
+       }
+
+       return rec;
+}
+
+/***** USAGE EXAMPLE ***************************************************************
+
+ uint32_t text_db_get_record_size(void * record)
+ {
+ return strlen(record);
+ }
+
+ uint32_t text_db_check_deleted(void * record)
+ {
+ return (((char *)record)[0] == ';');
+ }
+
+ void text_db_mark_deleted(void * record)
+ {
+ ((char *)record)[0] = ';';
+ }
+
+ bool text_db_check_key_test(void * record, void * key)
+ {
+ return memcmp(((char *)record) + 2, key, 4);
+ }
+
+ void main(void)
+ {
+ char * rec;
+ uint32_t context = 0;
+
+ _db_descriptor * db;
+ 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);
+ sdb_add_record(db, "Hello world!\n");
+ sdb_add_record(db, "Hello world2!\n");
+ sdb_add_record(db, "This is line #2...\n");
+ sdb_add_record(db, "Hello world3!\n");
+ sdb_add_record(db, "And this is the third one.\n");
+ sdb_add_record(db, "Hello world4!\n");
+ sdb_add_record(db, "Hello world5!\n");
+ sdb_delete_record(db,"llo ", text_db_check_key_test);
+
+ while ((rec = sdb_get_record(db,"llo ", text_db_check_key_test, &context)) != NULL)
+ {
+ printf("-->%s", rec);
+ }
+
+ rec = SDB_GET_FIRST_RECORD(db, &context);
+ while (rec != NULL)
+ {
+ printf("=->%s", rec);
+ rec = SDB_GET_NEXT_RECORD(db, &context);
+ }
+
+ sdb_consolidate_db(&db);
+
+ rec = SDB_GET_FIRST_RECORD(db, &context);
+ while (rec != NULL)
+ {
+ printf("=->%s", rec);
+ rec = SDB_GET_NEXT_RECORD(db, &context);
+ }
+
+ sdb_release_db(&db);
+ }
+ */
+
+const char * parsingErrorStrings[] =
+{ "SDB_TXT_PARSER_RESULT_OK", "SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD",
+               "SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG",
+               "SDB_TXT_PARSER_RESULT_FIELD_MISSING",
+               "SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT",
+               "SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE",
+               "SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE",
+               "SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE",
+               "SDB_TXT_PARSER_RESULT_STRING_TOO_LONG", };
+
+void sdb_txt_parser_move_to_next_field(char ** pBuf, parsingResult_t * result)
+{
+       while ((result->code == SDB_TXT_PARSER_RESULT_OK) && (**pBuf != ',')
+                       && (**pBuf != '\0'))
+       {
+               if ((**pBuf != ' ') && (**pBuf != '\t') && (**pBuf != '\n')
+                               && (**pBuf != '\r'))
+               {
+                       result->code = SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG;
+//printf("char is %d\n", **pBuf);
+                       result->errorLocation = *pBuf;
+               }
+               else
+               {
+                       (*pBuf)++;
+               }
+       }
+
+       if (result->code == SDB_TXT_PARSER_RESULT_OK)
+       {
+               if (**pBuf == '\0')
+               {
+                       result->code = SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD;
+                       result->errorLocation = *pBuf;
+               }
+               else
+               {
+                       (*pBuf)++;
+               }
+       }
+
+}
+
+void sdb_txt_parser_get_hex_field(char ** pBuf, uint8_t * field, uint32_t len,
+               parsingResult_t * result)
+{
+       int i;
+       unsigned long tempNum;
+
+       if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)
+       {
+               result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING;
+               result->errorLocation = *pBuf;
+       }
+       else
+       {
+               for (i = 0; (result->code == SDB_TXT_PARSER_RESULT_OK) && (i < len); i++)
+               {
+                       tempNum = strtoul(*pBuf, pBuf, 16);
+                       if ((errno == ERANGE) | (tempNum > 0xFF))
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                               result->errorLocation = (*pBuf) - 1;
+                       }
+                       else
+                       {
+                               field[(len - 1) - i] = (uint8) tempNum;
+
+                               if (i < (len - 1))
+                               {
+                                       if (**pBuf != ':')
+                                       {
+                                               result->code =
+                                                               SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT;
+                                               result->errorLocation = *pBuf;
+                                               //                                      printf("pBuf=%p, *pBuf=%p, **pBuf=%d\n", pBuf, *pBuf, **pBuf);
+                                               //                                      printf(":result->errorLocation=%p\n", result->errorLocation);
+                                       }
+                                       else
+                                       {
+                                               (*pBuf)++;
+                                       }
+                               }
+                       }
+               }
+
+               if (result->code == SDB_TXT_PARSER_RESULT_OK)
+               {
+                       result->field++;
+                       sdb_txt_parser_move_to_next_field(pBuf, result);
+               }
+       }
+}
+
+void sdb_txt_parser_get_numeric_field(char ** pBuf, uint8_t * field,
+               uint32_t len, bool isSigned, parsingResult_t * result)
+{
+       union {
+               signed long sNum;
+               unsigned long uNum;
+       } temp;
+       int i;
+
+       if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)
+       {
+               result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING;
+               result->errorLocation = *pBuf;
+       }
+       else if (result->code == SDB_TXT_PARSER_RESULT_OK)
+       {
+               if (isSigned)
+               {
+                       temp.sNum = strtol(*pBuf, pBuf, 0);
+
+                       if ((errno == ERANGE)
+                                       || (temp.sNum > (((signed long) 0x7F) << (8 * (len - 1))))
+                                       || (temp.sNum < (((signed long) 0x80) << (8 * (len - 1)))))
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                               result->errorLocation = (*pBuf) - 1;
+                       }
+               }
+               else
+               {
+                       temp.uNum = strtoul(*pBuf, pBuf, 0);
+//printf("%u >? %u",temp.uNum, (((unsigned long)0xFF) << (8*(len-1))));
+                       if ((errno == ERANGE)
+                                       || (temp.uNum > (((unsigned long) 0xFF) << (8 * (len - 1)))))
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                               result->errorLocation = (*pBuf) - 1;
+                       }
+               }
+
+               // From this point, only temp.uNum is used. It actually access temp.sNum, since temp is a union
+
+               if (result->code == SDB_TXT_PARSER_RESULT_OK)
+               {
+                       for (i = 0; i < len; i++)
+                       {
+                               *field++ = temp.uNum & 0xFF; //note: assuming little endian machine
+                               temp.uNum >>= 8;
+                       }
+
+                       if (temp.uNum != 0)
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                               result->errorLocation = (*pBuf) - 1;
+                       }
+                       else
+                       {
+                               result->field++;
+                               sdb_txt_parser_move_to_next_field(pBuf, result);
+                       }
+               }
+       }
+}
+
+void sdb_txt_parser_get_quoted_string(char ** pBuf, char * field, size_t size,
+               parsingResult_t * result)
+{
+       char * tmpPtr;
+       size_t stringLen;
+
+       if (result->code == SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD)
+       {
+               result->code = SDB_TXT_PARSER_RESULT_FIELD_MISSING;
+               result->errorLocation = *pBuf;
+       }
+       else
+       {
+               while ((result->code == SDB_TXT_PARSER_RESULT_OK) && (**pBuf != '\"')
+                               && (**pBuf != '\0'))
+               {
+                       if ((**pBuf != ' ') && (**pBuf != '\t'))
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE;
+                               result->errorLocation = *pBuf;
+                       }
+                       else
+                       {
+                               (*pBuf)++;
+                       }
+               }
+
+               if (result->code == SDB_TXT_PARSER_RESULT_OK)
+               {
+                       (*pBuf)++;
+                       tmpPtr = *pBuf;
+                       while ((**pBuf != '\"') && (**pBuf != '\0'))
+                       {
+                               (*pBuf)++;
+                       }
+
+                       if (**pBuf != '\"')
+                       {
+                               result->code = SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE;
+                               result->errorLocation = *pBuf;
+                       }
+                       else
+                       {
+                               stringLen = *pBuf - tmpPtr;
+                               if (stringLen > size)
+                               {
+                                       result->code = SDB_TXT_PARSER_RESULT_STRING_TOO_LONG;
+                                       result->errorLocation = tmpPtr + size;
+                               }
+                       }
+
+                       if (result->code == SDB_TXT_PARSER_RESULT_OK)
+                       {
+                               (*pBuf)++;
+                               memcpy(field, tmpPtr, stringLen);
+                               field[stringLen] = '\0';
+
+                               result->field++;
+                               sdb_txt_parser_move_to_next_field(pBuf, result);
+                       }
+               }
+       }
+}
+
diff --git a/server/Source/SimpleDB.h b/server/Source/SimpleDB.h
new file mode 100755 (executable)
index 0000000..f302968
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef SIMPLE_DB_H
+#define SIMPLE_DB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ #define FALSE 0
+ #define TRUE (!FALSE)
+ typedef int bool;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int8 uint8_t;
+ */
+
+#define MAX_SUPPORTED_RECORD_SIZE 500
+#define MAX_SUPPORTED_FILENAME 100
+
+#define SDB_CHECK_KEY_EQUAL 0
+#define SDB_CHECK_KEY_BIGGER 1
+#define SDB_CHECK_KEY_SMALLER (-1)
+#define SDB_CHECK_KEY_NOT_EQUAL 2
+#define SDB_CHECK_KEY_ERROR 3
+
+enum {
+       SDB_TYPE_TEXT, SDB_TYPE_BINARY
+};
+
+typedef void db_descriptor;
+
+typedef int (*check_key_f)(void * record, void * key);
+typedef uint32 (*get_record_size_f)(void * record);
+typedef bool (*check_deleted_f)(void * record);
+typedef bool (*check_ignore_f)(void * record);
+typedef void (*mark_deleted_f)(void * record);
+typedef bool (*consolidation_processing_f)(db_descriptor * db, void * record);
+
+typedef struct {
+       char * errorLocation;
+       int code;
+       uint16_t field;
+} parsingResult_t;
+
+db_descriptor * sdb_init_db(char * name, get_record_size_f get_record_size,
+               check_deleted_f check_deleted, check_ignore_f check_ignore,
+               mark_deleted_f mark_deleted,
+               consolidation_processing_f consolidation_processing, uint8_t db_type,
+               uint32_t db_bin_header_size);
+bool sdb_add_record(db_descriptor * db, void * rec);
+void * sdb_delete_record(db_descriptor * db, void * key, check_key_f check_key);
+bool sdb_consolidate_db(db_descriptor ** db);
+void * sdb_get_record(db_descriptor * db, void * key, check_key_f check_key,
+               uint32_t * context);
+bool sdb_release_record(void ** record);
+bool sdb_release_db(db_descriptor ** db);
+void sdb_flush_db(db_descriptor * db);
+bool sdb_modify_last_accessed_record(db_descriptor * _db, void * record);
+#define SDB_GET_FIRST_RECORD(_db, _context) ((*(_context) = 0), sdb_get_record((_db), NULL, NULL, _context))
+#define SDB_GET_NEXT_RECORD(_db, _context) (sdb_get_record((_db), NULL, NULL, _context))
+#define SDB_GET_UNIQUE_RECORD(_db, _key, _check_key_func) (sdb_get_record((_db), (_key), (_check_key_func), NULL))
+
+extern int sdbErrno;
+extern const char * parsingErrorStrings[];
+
+/* Macros for parsing records of a TEXT based database */
+/* The following variables are expected to be defined (and initialized as specified):   */
+/* bool end_of_record = FALSE; */
+/* char * pBuf = record; */
+
+#define SDB_TXT_PARSER_RESULT_OK 0
+#define SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD 1
+#define SDB_TXT_PARSER_RESULT_UNEXPECTED_CHARACTER_OR_TOO_LONG 2
+#define SDB_TXT_PARSER_RESULT_FIELD_MISSING 3
+#define SDB_TXT_PARSER_RESULT_HEX_UNEXPECTED_CHARACTER_OR_TOO_SHORT 4
+#define SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE 5
+#define SDB_TXT_PARSER_RESULT_MISSING_STARTING_QUOTE 6
+#define SDB_TXT_PARSER_RESULT_MISSING_ENDING_QUOTE 7
+#define SDB_TXT_PARSER_RESULT_STRING_TOO_LONG 8
+#define SDB_TXT_PARSER_RESULT_MAX 8
+
+void sdb_txt_parser_get_hex_field(char ** pBuf, uint8_t * field, uint32_t len,
+               parsingResult_t * reault);
+void sdb_txt_parser_get_numeric_field(char ** pBuf, uint8_t * field,
+               uint32_t len, bool isSigned, parsingResult_t * reault); //, int * prev_result);
+void sdb_txt_parser_get_quoted_string(char ** pBuf, char * field, size_t size,
+               parsingResult_t * reault);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SIMPLE_DB_H */
+
diff --git a/server/Source/SimpleDBTxt.c b/server/Source/SimpleDBTxt.c
new file mode 100755 (executable)
index 0000000..02d64ee
--- /dev/null
@@ -0,0 +1,128 @@
+//This is a specific implemntation of a text-based db system, based on the SimpleDB module
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+#include "hal_types.h"
+#include "SimpleDBTxt.h"
+
+uint32_t sdbtGetRecordSize(void * record)
+{
+       return strlen(record);
+}
+
+bool sdbtCheckDeleted(void * record)
+{
+       return (((char *) record)[0] == SDBT_DELETED_LINE_CHARACTER);
+}
+
+bool sdbtCheckIgnored(void * record)
+{
+       return ((((char *) record)[0] == SDBT_BAD_FORMAT_CHARACTER)
+                       || (((char *) record)[0] == SDBT_PENDING_COMMENT_FORMAT_CHARACTER));
+}
+
+void sdbtMarkDeleted(void * record)
+{
+       ((char *) record)[0] = ';';
+}
+
+uint32_t sdbtGetRecordCount(db_descriptor * db)
+{
+       uint32_t recordCnt = 0;
+       char * rec;
+       uint32_t context;
+
+       rec = SDB_GET_FIRST_RECORD(db, &context);
+
+       while (rec != NULL)
+       {
+               recordCnt++;
+               rec = SDB_GET_NEXT_RECORD(db, &context);
+       }
+
+       return recordCnt;
+}
+
+bool sdbtErrorComment(db_descriptor * db, char * record)
+{
+       parsingResult_t parsingResult =
+       { SDB_TXT_PARSER_RESULT_OK, 0 };
+       char * pBuf = record + 1;
+       char comment[MAX_SUPPORTED_RECORD_SIZE];
+       uint8_t errorCode;
+       uint16_t errorOffset;
+       bool rc;
+       char tempstr[3] =
+       { SDBT_BAD_FORMAT_CHARACTER, '\n', '\0' };
+
+       if (record[0] == SDBT_PENDING_COMMENT_FORMAT_CHARACTER)
+       {
+               record[0] = SDBT_BAD_FORMAT_CHARACTER;
+               sprintf(comment, "%c-------\n", SDBT_BAD_FORMAT_CHARACTER);
+               rc = sdb_add_record(db, comment) && sdb_add_record(db, record);
+
+               if (rc == TRUE)
+               {
+//                     printf("here&\n");
+                       sdb_txt_parser_get_numeric_field(&pBuf, &errorCode, 1, FALSE,
+                                       &parsingResult);
+                       if (errorCode > SDB_TXT_PARSER_RESULT_MAX)
+                       {
+//printf("here0\n");
+                               parsingResult.code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                               parsingResult.errorLocation = pBuf - 2;
+                       }
+                       else
+                       {
+//printf("here1 %d \n", parsingResult.code);
+                               sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &errorOffset, 2,
+                                               FALSE, &parsingResult);
+                               if (errorOffset >= strlen(record))
+                               {
+                                       parsingResult.code = SDB_TXT_PARSER_RESULT_VALUE_OUT_OF_RANGE;
+                                       parsingResult.errorLocation = pBuf - 2;
+                               }
+                       }
+//                     printf("here2\n");
+                       if (parsingResult.code == SDB_TXT_PARSER_RESULT_OK)
+                       {
+//                             printf("here3\n");
+//                             printf("%s\n%d %d\n", record, errorOffset - 7 + 1, errorCode);
+                               sprintf(comment, "%cERROR:%*s %s\n", SDBT_BAD_FORMAT_CHARACTER,
+                                               errorOffset - 7 + 1, "^", parsingErrorStrings[errorCode]);
+                       }
+                       else
+                       {
+//                             printf("here4\n");
+//                             printf("%s\n%d %d\n", record, parsingResult.errorLocation - record - 1 + 1, parsingResult.code);
+                               sprintf(comment, "%c%*s %s (%s)\n", SDBT_BAD_FORMAT_CHARACTER,
+                                               parsingResult.errorLocation - record - 1 + 1, "^",
+                                               "BAD_ERROR_DESCRIPTION_HEADER",
+                                               parsingErrorStrings[parsingResult.code]);
+                       }
+//                     printf("here5\n");
+
+                       rc = sdb_add_record(db, comment) && sdb_add_record(db, tempstr);
+               }
+       }
+       else
+       {
+               rc = sdb_add_record(db, record);
+       }
+
+       return rc;
+}
+
+void sdbtMarkError(db_descriptor * db, char * record,
+               parsingResult_t * parsingResult)
+{
+       //mark record as 'bad format'
+       record[0] = SDBT_PENDING_COMMENT_FORMAT_CHARACTER;
+       record[1] = '0' + parsingResult->code;
+       record[2] = ',';
+       sprintf(record + 3, "%3d", (int) (parsingResult->errorLocation - record));
+       record[6] = ','; //must overwrite the '\0' from the above sprintf
+       sdb_modify_last_accessed_record(db, record);
+}
+
diff --git a/server/Source/SimpleDBTxt.h b/server/Source/SimpleDBTxt.h
new file mode 100755 (executable)
index 0000000..e971fc4
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef SIMPLE_DB_TXT_H
+#define SIMPLE_DB_TXT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "SimpleDB.h"
+
+#define SDBT_BAD_FORMAT_CHARACTER '@'
+#define SDBT_PENDING_COMMENT_FORMAT_CHARACTER '?'
+#define SDBT_DELETED_LINE_CHARACTER ';'
+
+uint32_t sdbtGetRecordSize(void * record);
+bool sdbtCheckDeleted(void * record);
+bool sdbtCheckIgnored(void * record);
+void sdbtMarkDeleted(void * record);
+uint32_t sdbtGetRecordCount(db_descriptor * db);
+bool sdbtErrorComment(db_descriptor * db, char * record);
+void sdbtMarkError(db_descriptor * db, char * record, parsingResult_t * parsingResult);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SIMPLE_DB_TXT_H */
+
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 3aebc4a..79a4b75
 #include "interface_srpcserver.h"
 #include "interface_devicelist.h"
 
+#include "hal_types.h"
+#include "SimpleDBTxt.h"
+
 /*********************************************************************
- * DEFINES
+ * LOCAL VARIABLES
  */
 
+static db_descriptor * db;
 
 /*********************************************************************
  * TYPEDEFS
  */
-typedef struct
-{
-  void   *next;
-  epInfo_t epInfo;  
-}deviceRecord_t;
-
-deviceRecord_t *deviceRecordHead = NULL;
 
 /*********************************************************************
  * LOCAL FUNCTION PROTOTYPES
- */ 
-static deviceRecord_t* createDeviceRec( epInfo_t epInfo );
-static deviceRecord_t* findDeviceRec( uint16_t nwkAddr, uint8_t endpoint);
-static char* findDeviceInFileString( uint16_t nwkAddr, uint8_t endpoint, char* fileBuf, uint32_t bufLen );
-static void reomveDeviceFromFile( uint16_t nwkAddr, uint8_t endpoint );
-static void writeDeviceToFile( deviceRecord_t *device );
-static void readDeviceListFromFile( void );
+ */
 
-/*********************************************************************
- * FUNCTIONS
- *********************************************************************/
+typedef struct {
+       uint16 nwkAddr;
+       uint8 endpoint;
+} dev_key_NA_EP;
 
-/*********************************************************************
- * @fn      createDeviceRec
- *
- * @brief   create a device and add a rec fto the list.
- *
- * @param   table
- * @param   rmTimer
- *
- * @return  none
- */
-static deviceRecord_t* createDeviceRec( epInfo_t epInfo )
+typedef struct {
+       uint8 ieeeAddr[8];
+       uint8 endpoint;
+} dev_key_IEEE_EP;
+
+typedef uint8 dev_key_IEEE[8];
+
+static char * devListComposeRecord(epInfo_t *epInfo, char * record)
 {
-  deviceRecord_t *srchRec;
-  
-  //printf("createDeviceRec++\n");
-  
-  //does it already exist  
-  if( findDeviceRec( epInfo.nwkAddr, epInfo.endpoint ) )
-  {
-    //printf("createDeviceRec: Device already exists\n");
-    return NULL;
-  }
-      
-  deviceRecord_t *newDevice = malloc( sizeof( deviceRecord_t ) );
-  
-  //Store the epInfo
-  memcpy( &(newDevice->epInfo), &epInfo, sizeof(epInfo_t));
-  
-  newDevice->epInfo.deviceName = NULL;
-  newDevice->epInfo.status = DEVLIST_STATE_ACTIVE;
-  
-  //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);
-   
-  newDevice->next = NULL;   
-   
-  if(deviceRecordHead)
-  {
-    //find the end of the list and add the record
-    srchRec = deviceRecordHead;
-    // Stop at the last record
-    while ( srchRec->next )
-      srchRec = srchRec->next;
-
-    // Add to the list
-    srchRec->next = newDevice; 
-    
-    //printf("New Device added to end of list (%x)\n", srchRec->next);
-  }
-  else
-  {
-    //printf("createDeviceRec: adding new device to head of the list\n");
-    deviceRecordHead = newDevice;
-  }
-      
-  return newDevice;
-  //printf("createDeviceRec--\n");
+       uint8 hasName=0;
+
+       if(epInfo->deviceName != NULL)
+       {
+               hasName = 1;
+       }
+
+       sprintf(record,
+                       "        %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.
+                       epInfo->IEEEAddr[7], epInfo->IEEEAddr[6], epInfo->IEEEAddr[5],
+                       epInfo->IEEEAddr[4], epInfo->IEEEAddr[3], epInfo->IEEEAddr[2],
+                       epInfo->IEEEAddr[1], epInfo->IEEEAddr[0], epInfo->nwkAddr,
+                       epInfo->endpoint, epInfo->profileID, epInfo->deviceID, epInfo->version,
+                       epInfo->status, hasName ? epInfo->deviceName : "");
+
+       return record;
 }
 
-/*********************************************************************
- * @fn      findDeviceRec
- *
- * @brief   find a device and in the list.
- *
- * @param   nwkAddr
- * @param   endpoint
- *
- * @return  deviceRecord_t for the device foundm null if not found
- */
-static deviceRecord_t* findDeviceRec( uint16_t nwkAddr, uint8_t endpoint)
+void devListAddDevice(epInfo_t *epInfo)
 {
-  deviceRecord_t *srchRec = deviceRecordHead;
-
-  //printf("findDeviceRec++: nwkAddr:%x, ep:%x\n", nwkAddr, endpoint);
-  
-  // find record
-  while ( (srchRec) && !((srchRec->epInfo.nwkAddr == nwkAddr) && (srchRec->epInfo.endpoint == endpoint)) )
-  {
-    //printf("findDeviceRec++: searching nwkAddr:%x, ep:%x\n", srchRec->epInfo.nwkAddr, srchRec->epInfo.endpoint);
-    srchRec = srchRec->next;  
-  }
-  
-  //printf("findDeviceRec[%x]--\n", srchRec);
-   
-  return srchRec;
+       char rec[MAX_SUPPORTED_RECORD_SIZE];
+
+       devListComposeRecord(epInfo, rec);
+
+       sdb_add_record(db, rec);
 }
 
-/***************************************************************************************************
- * @fn      findDeviceInFileString - remove device from file.
- *
- * @brief   
- * @param   
- *
- * @return 
- ***************************************************************************************************/
-static char* findDeviceInFileString( uint16_t nwkAddr, uint8_t endpoint, char* fileBuf, uint32_t bufLen )
+static epInfo_t * devListParseRecord(char * record)
 {
-  char *deviceIdx = NULL, *deviceStartIdx, *deviceEndIdx;
-  uint32_t remainingBytes;
-  
-  //printf("findDeviceInFile++\n");
-  
-  deviceStartIdx = fileBuf;
-  remainingBytes = bufLen;
-  //set to a non NULL value
-  deviceEndIdx = fileBuf;
-  
-  while( ((fileBuf - deviceStartIdx) < bufLen) && (deviceEndIdx != 0) )
-  {
-    //is this device the correct device
-    if( *((uint16_t*)deviceStartIdx) == nwkAddr )
-    {
-      //device found
-      deviceIdx = deviceStartIdx;
-      break;
-    }       
-     
-    //find end of current device by finding the delimiter
-    deviceEndIdx = strchr(deviceStartIdx, ';');
-    if( deviceEndIdx > (fileBuf + bufLen) )
-    {
-      //past end of file string
-      //printf("findDeviceInFile++\n");
-       deviceEndIdx = NULL;
-    }
-    
-    if( deviceEndIdx )
-    {
-      remainingBytes = bufLen - (fileBuf - deviceEndIdx);
-      deviceStartIdx = &(deviceEndIdx[1]);    
-    }
-  }
-  
-  //printf("findDeviceInFile-- [%x]\n", (uint32_t) deviceIdx);
-  
-  return deviceIdx;
+       char * pBuf = record + 1; //+1 is to ignore the 'for deletion' mark that may just be added to this record.
+       static epInfo_t epInfo;
+       static char deviceName[MAX_SUPPORTED_DEVICE_NAME_LENGTH + 1];
+       parsingResult_t parsingResult =
+       { SDB_TXT_PARSER_RESULT_OK, 0 };
+
+       if (record == NULL)
+       {
+               return NULL;
+       }
+
+       sdb_txt_parser_get_hex_field(&pBuf, epInfo.IEEEAddr, 8, &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.nwkAddr, 2, FALSE,
+                       &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.endpoint, 1, FALSE,
+                       &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.profileID, 2,
+                       FALSE, &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &epInfo.deviceID, 2,
+                       FALSE, &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.version, 1, FALSE,
+                       &parsingResult);
+       sdb_txt_parser_get_numeric_field(&pBuf, &epInfo.status, 1, FALSE,
+                       &parsingResult);
+       sdb_txt_parser_get_quoted_string(&pBuf, deviceName,
+                       MAX_SUPPORTED_DEVICE_NAME_LENGTH, &parsingResult);
+
+       if ((parsingResult.code != SDB_TXT_PARSER_RESULT_OK)
+                       && (parsingResult.code != SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD))
+       {
+               sdbtMarkError(db, record, &parsingResult);
+               return NULL;
+       }
+
+       if (strlen(deviceName) > 0)
+       {
+               epInfo.deviceName = deviceName;
+
+       }
+       else
+       {
+               epInfo.deviceName = NULL;
+       }
+
+       return &epInfo;
 }
 
-/***************************************************************************************************
- * @fn      reomveDeviceFromFile - remove device from file.
- *
- * @brief   
- * @param   
- *
- * @return 
- ***************************************************************************************************/
-static void reomveDeviceFromFile( uint16_t nwkAddr, uint8_t endpoint )
+static int devListCheckKeyIeeeEp(char * record, dev_key_IEEE_EP * key)
 {
-  FILE *fpDevFile;
-  uint32_t fileSize;
-  char *fileBuf, *deviceStr, *devStrEnd;
-  
-  //printf("reomveDeviceFromFile++\n");
-  
-  fpDevFile = fopen("devicelistfile.dat", "w+b");
-  
-  if(fpDevFile)
-  {
-    //read the file into a buffer  
-    fseek(fpDevFile, 0, SEEK_END);
-    fileSize = ftell(fpDevFile);
-    rewind(fpDevFile);  
-    fileBuf = (char*) calloc(sizeof(char), fileSize);  
-    fread(fileBuf, 1, fileSize, fpDevFile);
-
-    //printf("reomveDeviceFromFile: number of bytes in file = %d\n", fileSize);
-    //printf("reomveDeviceFromFile: Searching for device string\n");
-    //find the device
-    deviceStr = findDeviceInFileString( nwkAddr, endpoint, fileBuf, fileSize );
-    
-    if( deviceStr )
-    {
-      //printf("reomveDeviceFromFile: device string:%x\n", (uint32_t) deviceStr);
-      //find device delimiter     
-      devStrEnd = strchr(deviceStr, ';');
-      
-      if( devStrEnd )
-      {         
-        //copy start of file to bigenning of device
-        fwrite((const void *) fileBuf, fileBuf-deviceStr, 1, fpDevFile);
-        //copy end of device to end of file
-        fwrite((const void *) devStrEnd, fileSize - (fileBuf - devStrEnd), 1, fpDevFile);      
-      }
-      else
-      {
-        //printf("reomveDeviceFromFile: device delimiter not found\n");
-      }
-    }
-    else
-    {
-      //printf("reomveDeviceFromFile: device not found in file\n");
-    }
-  }
-    
-  fflush(fpDevFile);
-  fclose(fpDevFile);
-  free(fileBuf);
+       epInfo_t * epInfo;
+       int result = SDB_CHECK_KEY_NOT_EQUAL;
+
+       epInfo = devListParseRecord(record);
+       if (epInfo == NULL)
+       {
+               return SDB_CHECK_KEY_ERROR;
+       }
+
+       if ((memcmp(epInfo->IEEEAddr, key->ieeeAddr, Z_EXTADDR_LEN) == 0)
+                       && (epInfo->endpoint == key->endpoint))
+       {
+               result = SDB_CHECK_KEY_EQUAL;
+       }
+
+       return result;
 }
 
-/***************************************************************************************************
- * @fn      writeDeviceToFile - store device list.
- *
- * @brief   
- * @param   
- *
- * @return 
- ***************************************************************************************************/
-static void writeDeviceToFile( deviceRecord_t *device )
+static int devListCheckKeyIeee(char * record, uint8_t key[Z_EXTADDR_LEN])
 {
-  FILE *fpDevFile;
-  
-  //printf("writeDeviceToFile++\n");
-  
-  fpDevFile = fopen("devicelistfile.dat", "a+b");
-
-  if(fpDevFile)
-  {
-    //printf("writeDeviceToFile: opened file\n");
-    
-    //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))));
-    //Store epInfo - device name pointer and status 
-    fwrite((const void *) &(device->epInfo), (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), 1, fpDevFile);
-    
-    //Store deviceName len
-    if(device->epInfo.deviceName)
-    {    
-      uint8_t i;      
-      //printf("writeDeviceToFile: Store deviceName\n");
-      
-      //first char of dev name is str length
-      for(i = 0; i < (device->epInfo.deviceName[0] + 1) ; i++)
-      {
-        fwrite((const void *) (&(device->epInfo.deviceName[i])), 1, 1, fpDevFile);
-      }
-    }
-    else
-    {
-      //just store the len of 0
-      uint8_t tmp = 0;
-      fwrite(&tmp, 1, 1, fpDevFile);
-    }
-    
-    //printf("writeDeviceToFile: Store status\n");
-    //Store status
-    fwrite((const void *) &(device->epInfo.status), 1, 1, fpDevFile);
-    //write delimter
-    fwrite(";", 1, 1, fpDevFile);
-    
-    fflush(fpDevFile);
-    fclose(fpDevFile); 
-  }
-}    
-
-/***************************************************************************************************
- * @fn      readDeviceListFromFile - restore the device list.
- *
- * @brief   
- *
- * @return 
- ***************************************************************************************************/
-static void readDeviceListFromFile( void )
+       epInfo_t * epInfo;
+       int result = SDB_CHECK_KEY_NOT_EQUAL;
+
+       epInfo = devListParseRecord(record);
+       if (epInfo == NULL)
+       {
+               return SDB_CHECK_KEY_ERROR;
+       }
+//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));
+       if (memcmp(epInfo->IEEEAddr, key, Z_EXTADDR_LEN) == 0)
+       {
+               result = SDB_CHECK_KEY_EQUAL;
+       }
+
+       return result;
+}
+
+static int devListCheckKeyNaEp(char * record, dev_key_NA_EP * key)
+{
+       epInfo_t * epInfo;
+       int result = SDB_CHECK_KEY_NOT_EQUAL;
+
+       epInfo = devListParseRecord(record);
+       if (epInfo == NULL)
+       {
+               return SDB_CHECK_KEY_ERROR;
+       }
+
+       if ((epInfo->nwkAddr == key->nwkAddr) && (( key->endpoint == 0xFF) || (epInfo->endpoint == key->endpoint)) )
+       {
+               result = SDB_CHECK_KEY_EQUAL;
+       }
+
+       return result;
+}
+
+epInfo_t * devListRemoveDeviceByNaEp(uint16 nwkAddr, uint8 endpoint)
 {
-  FILE *fpDevFile;
-  deviceRecord_t *device;
-  epInfo_t epInfo;
-  char chTmp;
-  
-  //printf("readDeviceListFromFile++\n");
-  fpDevFile = fopen("devicelistfile.dat", "a+b");
-
-  if(fpDevFile)
-  {
-    //printf("readDeviceListFromFile: file opened\n");
-    //read epInfo_t - device name pointer and status 
-    while(fread(&(epInfo), (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), 1, fpDevFile))
-    {
-      //printf("readDeviceListFromFile: epInfo[%d] read for device %x\n", (sizeof(epInfo_t) - (sizeof (char*) + sizeof (uint8_t))), epInfo.nwkAddr);
-      
-      device = createDeviceRec(epInfo);      
-      
-      if(device)
-      {
-        uint8_t strLen; 
-        char *strName;
-        fread(&(strLen), 1, 1, fpDevFile);
-        //printf("readDeviceListFromFile: strLen %d\n", strLen); 
-        
-        if(strLen > 0)
-        {
-          strName = malloc(strLen + 1);
-          if(strName)
-          {          
-            strName[0] = strLen;
-            fread(&(strName[1]), 1, strLen, fpDevFile);
-          }
-          device->epInfo.deviceName = strName;
-        }
-
-        fread(&(device->epInfo.status), 1, 1, fpDevFile);
-        //printf("readDeviceListFromFile: device->epInfo.status %x\n", device->epInfo.status); 
-        
-        //read ';' delimeter
-        fread(&chTmp, 1, 1, fpDevFile);
-        
-        if(chTmp != ';')
-        {
-          //printf("readDeviceListFromFile: Error, device delimter not found\n");        
-          return;
-        }
-      }
-    }
-    
-    fflush(fpDevFile);
-    fclose(fpDevFile); 
-  }
-  
-  //printf("readDeviceListFromFile--\n");
+       dev_key_NA_EP key =
+       { nwkAddr, endpoint };
+
+       return devListParseRecord(
+                       sdb_delete_record(db, &key, (check_key_f) devListCheckKeyNaEp));
+
 }
 
-/*********************************************************************
- * @fn      devListAddDevice
- *
- * @brief   create a device and add a rec to the list.
- *
- * @param   epInfo
- *
- * @return  none
- */
-void devListAddDevice( epInfo_t *epInfo)
-{ 
-  //printf("devListAddDevice++(%x:%x)\n", epInfo->nwkAddr, epInfo->endpoint);
-   
-  deviceRecord_t *device = createDeviceRec(*epInfo);
-  if(device)
-  {
-    writeDeviceToFile(device);
-  }
-  
-  //printf("\n\n\ndevListAddDevice: list=\n");
-  //find the end of the list and add the record
-  deviceRecord_t *srchRec = deviceRecordHead;
-  //printf("%x", srchRec);
-  
-  while ( srchRec->next )
-  {
-      srchRec = srchRec->next;
-      //printf("%x\n", srchRec);
-  }
-  //printf("\n\n\n");
-     
-  //printf("devListAddDevice--\n");
+epInfo_t * devListRemoveDeviceByIeee(uint8_t ieeeAddr[8])
+{
+       return devListParseRecord(
+                       sdb_delete_record(db, ieeeAddr, (check_key_f) devListCheckKeyIeee));
 }
 
-/*********************************************************************
- * @fn      devListRemoveDevice
- *
- * @brief   remove a device rec from the list.
- *
- * @param   nwkAddr - nwkAddr of device to be removed
- * @param   endpoint - endpoint of device to be removed 
- *
- * @return  none
- */
-void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint )
+epInfo_t * devListGetDeviceByIeeeEp(uint8_t ieeeAddr[8], uint8_t endpoint)
 {
-  deviceRecord_t *srchRec, *prevRec=NULL;
-
-  // find record and prev device record
-  srchRec = deviceRecordHead;
-  
-  // find record
-  while ( (srchRec) && !((srchRec->epInfo.nwkAddr == nwkAddr) && (srchRec->epInfo.endpoint == endpoint)) )
-  {
-    prevRec = srchRec;
-    srchRec = srchRec->next;  
-  }
-     
-  if (srchRec == NULL)
-  {
-      //printf("deleteDeviceRec: record not found\n");
-      return;    
-  }
-  else
-  {               
-    // delete the rec from the list
-    if ( prevRec == NULL )      
-    {
-      //at head of the list
-      //remove record from list 
-      deviceRecordHead = srchRec->next;
-    }
-    else
-    {
-      //remove record from list    
-      prevRec->next = srchRec->next;    
-    }
-    
-    free(srchRec);        
-  }
+       char * rec;
+       dev_key_IEEE_EP key;
+
+       memcpy(key.ieeeAddr, ieeeAddr, 8);
+       key.endpoint = endpoint;
+       rec = SDB_GET_UNIQUE_RECORD(db, &key, (check_key_f)devListCheckKeyIeeeEp);
+       if (rec == NULL)
+       {
+               return NULL;
+       }
+
+       return devListParseRecord(rec);
 }
 
-/*********************************************************************
- * @fn      devListRestorDevices
- *
- * @brief   create a device list from file.
- *
- * @param   none
- *
- * @return  none
- */
-void devListRestorDevices( void )
+epInfo_t * devListGetDeviceByNaEp(uint16_t nwkAddr, uint8_t endpoint)
 {
-  //printf("devListRestorDevices++\n");
-  if( deviceRecordHead == NULL)
-  {
-    readDeviceListFromFile();
-  }
-  //else do what, should we delete the list and recreate from the file?
+       char * rec;
+       dev_key_NA_EP key;
+
+       key.nwkAddr = nwkAddr;
+       key.endpoint = endpoint;
+       rec = SDB_GET_UNIQUE_RECORD(db, &key, (check_key_f)devListCheckKeyNaEp);
+       if (rec == NULL)
+       {
+               return NULL;
+       }
+
+       return devListParseRecord(rec);
 }
 
-/*********************************************************************
- * @fn      devListChangeDeviceName
- *
- * @brief   change the name of a device.
- *
- * @return 
- */
-void devListChangeDeviceName( uint16_t devNwkAddr, uint8_t devEndpoint, char *deviceNameStr)
+uint32_t devListNumDevices(void)
 {
-  //printf("devListChangeDeviceName++\n");   
-    
-  deviceRecord_t *device = findDeviceRec( devNwkAddr, devEndpoint );             
-  
-  if(device)
-  {
-    if(device->epInfo.deviceName)
-    {
-      free(device->epInfo.deviceName);
-    }
-    
-    //printf("devListChangeDeviceName: removing device from file\n");  
-    reomveDeviceFromFile(devNwkAddr, devEndpoint);
-    
-    //printf("devListChangeDeviceName: Changing device name\n");      
-    //fisrt byte of deviceNameStr is the size of the string
-    device->epInfo.deviceName = malloc(deviceNameStr[0]);
-    strncpy(device->epInfo.deviceName, &(deviceNameStr[0]), (deviceNameStr[0] + 1) );
-        
-    //printf("devListChangeDeviceName: writing device to file\n");  
-    writeDeviceToFile(device);           
-  }
-  else
-  {
-    //printf("devListChangeDeviceName: Device not found");  
-  }  
-  
-  //printf("devListChangeDeviceName--\n");
-
-  return;  
+       return sdbtGetRecordCount(db);
 }
 
-/*********************************************************************
- * @fn      devListNumDevices
- *
- * @brief   get the number of devices in the list.
- *
- * @param   none
- *
- * @return  none
- */
-uint32_t devListNumDevices( void )
-{  
-  uint32_t recordCnt=0;
-  deviceRecord_t *srchRec;
-  
-  //printf("devListNumDevices++\n");
-  
-  // Head of the list
-  srchRec = deviceRecordHead;  
-  
-  if(srchRec==NULL)
-  {
-    //printf("devListNumDevices: deviceRecordHead NULL\n");
-    return -1;
-  }
-    
-  // Stop when rec found or at the end
-  while ( srchRec )
-  {  
-    //printf("devListNumDevices: recordCnt=%d\n", recordCnt);
-    srchRec = srchRec->next;  
-    recordCnt++;      
-  }
-  
-  //printf("devListNumDevices %d\n", recordCnt);
-  return (recordCnt);
+epInfo_t * devListGetNextDev(uint32_t *context)
+{
+       char * rec;
+       epInfo_t *epInfo;
+
+       do
+       {
+               rec = SDB_GET_NEXT_RECORD(db,context);
+
+               if (rec == NULL)
+               {
+                       return NULL;
+               }
+
+               epInfo = devListParseRecord(rec);
+       }
+       while (epInfo == NULL); //in case of a bad-format record - skip it and read the next one
+
+       return epInfo;
 }
 
-/*********************************************************************
- * @fn      devListGetNextDev
- *
- * @brief   Return the next device in the list.
- *
- * @param   nwkAddr - if 0xFFFF it will return head of the list
- *
- * @return  epInfo, return next epInfo from nwkAddr and ep supplied or 
- *          NULL if at end of the list
- */
-epInfo_t* devListGetNextDev( uint16_t nwkAddr, uint8_t endpoint )
-{  
-  epInfo_t* epInfo = NULL;
-  deviceRecord_t *srchRec;
-  
-  //printf("devListGetNextDev++: nwkAddr=%x, endpoint=%x\n", nwkAddr, endpoint);
-  
-  // Head of the list
-  srchRec = deviceRecordHead;  
-  
-  if(nwkAddr != 0xFFFF)
-  {
-    //Find the record for nwkAddr
-    srchRec = findDeviceRec(nwkAddr, endpoint);
-    //get the next record (may be NULL if at end of list)
-    srchRec = srchRec->next;
-    
-    //printf("devListGetNextDev: found device %x\n", srchRec);      
-    
-    //Store the epInfo
-    if(srchRec)
-    {
-      //printf("devListGetNextDev: returning next device %x\n", srchRec);      
-      epInfo = &(srchRec->epInfo);
-    }
-  }
-  else
-  {    
-    //printf("\n\n\ndevListGetNextDev: list= [%x]\n", deviceRecordHead);
-    //find the end of the list and add the record
-    deviceRecord_t *srchRec1 = deviceRecordHead;
-    //printf("%x", srchRec1);
-    if(srchRec1)
-    {
-      while ( srchRec1->next )
-      {
-          srchRec1 = srchRec1->next;
-          //printf("%x\n", srchRec1);
-      }
-    }
-    //printf("\n\n\n");
-        
-    //printf("devListGetNextDev: returning head of list\n");
-    //return fisrt record
-    if(deviceRecordHead)
-    {      
-      epInfo = &(deviceRecordHead->epInfo);
-    }
-  }
-  
-  //printf("devListGetNextDev[%x]--\n", epInfo);
-  
-  return (epInfo);
+void devListInitDatabase(char * dbFilename)
+{
+       db = sdb_init_db(dbFilename, sdbtGetRecordSize, sdbtCheckDeleted,
+                       sdbtCheckIgnored, sdbtMarkDeleted,
+                       (consolidation_processing_f) sdbtErrorComment, SDB_TYPE_TEXT, 0);
+       sdb_consolidate_db(&db);
 }
+
old mode 100644 (file)
new mode 100755 (executable)
index 3d7fe87..4ceb092
 #define INTERFACE_DEVICELIST_H
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
-
 /*********************************************************************
  * INCLUDES
  */
 #include <stdint.h>
-#include "zllSocCmd.h"
+#include "zbSocCmd.h"
+#include "hal_types.h"
 
 //device states
 #define DEVLIST_STATE_NOT_ACTIVE    0
 #define DEVLIST_STATE_ACTIVE        1
 
+#define MAX_SUPPORTED_DEVICE_NAME_LENGTH 32
+
+typedef struct
+{
+       void *next;
+       epInfo_t epInfo;
+}deviceRecord_t;
+
 /*
  * devListAddDevice - create a device and add a rec to the list.
  */
 void devListAddDevice( epInfo_t *epInfo);
 
 /*
- * devListRemoveDevice - remove a device rec from the list.
+ * devListRemoveDeviceByNaEp - remove a device rec from the list.
  */
-void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint );
+epInfo_t * devListRemoveDeviceByNaEp( uint16_t nwkAddr, uint8_t endpoint );
 
 /*
  * devListNumDevices - get the number of devices in the list.
@@ -71,19 +78,17 @@ void devListRemoveDevice( uint16_t nwkAddr, uint8_t endpoint );
 uint32_t devListNumDevices( void );
 
 /*
- * devListGetNextDev - Return the next device in the list.
+ * devListInitDatabase - restore device list from file.
  */
-epInfo_t* devListGetNextDev( uint16_t nwkAddr, uint8_t endpoint );
+void devListInitDatabase( char * dbFilename );
 
-/*
- * devListChangeDeviceName - Return the next device in the listchange device name.
- */
-void devListChangeDeviceName( uint16_t devNwkAddr, uint8_t devEndpoint, char *deviceNameStr);
+epInfo_t * devListGetNextDev(uint32 *context);
 
-/*
- * devListRestorDevices - restore device list from file.
- */
-void devListRestorDevices( void );
+epInfo_t * devListGetDeviceByIeeeEp( uint8_t ieeeAddr[8], uint8_t endpoint );
+
+epInfo_t * devListGetDeviceByNaEp( uint16_t nwkAddr, uint8_t endpoint );
+
+epInfo_t * devListRemoveDeviceByIeee( uint8_t ieeeAddr[8] );
 
 #ifdef __cplusplus
 }
old mode 100644 (file)
new mode 100755 (executable)
index 304056f..553551a
 #include <unistd.h>
 
 #include "interface_grouplist.h"
+#include "hal_types.h"
+#include "SimpleDBTxt.h"
+
+static db_descriptor * db;
 
 /*********************************************************************
  * TYPEDEFS
  */
-typedef struct
+
+void groupListInitDatabase(char * dbFilename)
 {
-  void   *next;
-  uint16_t groupMemberNwkAddr;
-}groupMembersRecord_t;
-typedef struct
+       db = sdb_init_db(dbFilename, sdbtGetRecordSize, sdbtCheckDeleted,
+                       sdbtCheckIgnored, sdbtMarkDeleted,
+                       (consolidation_processing_f) sdbtErrorComment, SDB_TYPE_TEXT, 0);
+       sdb_consolidate_db(&db);
+}
+
+static char * groupListComposeRecord(groupRecord_t *group, char * record)
 {
-  uint16_t groupId;
-  char *groupNameStr;
-  groupMembersRecord_t *groupMembers;
-  void   *next;
-}groupRecord_t;
-groupRecord_t *groupRecordHead = NULL;
+       groupMembersRecord_t *groupMembers;
 
-/*********************************************************************
- * LOCAL FUNCTION PROTOTYPES
- */ 
-static groupRecord_t* createGroupRec( char *groupNameStr, uint16_t groupId, uint8_t storeToFile );
-static groupRecord_t* findGroupRec(char *groupNameStr );
-static uint16_t getFreeGroupId(void);
-static int addGroupMemberToGroup( char *groupNameStr, uint16_t nwkAddr );
-static void writeGroupListToFile( groupRecord_t *device );
-static void writeGroupMemberToFile( char *groupNameStr, uint16_t nwkAddr  );
-static void readGroupListFromFile( void );
+       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. 
+                       group->id, group->name ? group->name : "");
 
-/*********************************************************************
- * FUNCTIONS
- *********************************************************************/
+       groupMembers = group->members;
 
-/*********************************************************************
- * @fn      createGroupRec
- *
- * @brief   create a group and rec to the list.
- *
- * @return  none
- */
-static groupRecord_t* createGroupRec( char *groupNameStr, uint16_t groupId, uint8_t storeToFile )
-{  
-  //printf("createGroupRec++\n");
-  
-  //does it already exist  
-  if( findGroupRec( groupNameStr ) )
-  {
-    //printf("createGroupRec: Device already exists\n");
-    return 0;
-  }
-      
-  groupRecord_t *newGroup = malloc( sizeof( groupRecord_t ) );
-  
-  newGroup->groupNameStr = malloc(groupNameStr[0]+1);
-  memcpy( newGroup->groupNameStr, groupNameStr, groupNameStr[0]+1);
-  
-  //set groupId
-  newGroup->groupId = groupId; 
-  //NULL the pointers
-  newGroup->groupMembers = NULL;
-  newGroup->next = NULL;
-    
-  //store the record
-  if(groupRecordHead)
-  {
-    groupRecord_t *srchRec;
-
-    //find the end of the list and add the record
-    srchRec = groupRecordHead;
-    // Stop at the last record
-    while ( srchRec->next )
-      srchRec = srchRec->next;
-
-    // Add to the list
-    srchRec->next = newGroup; 
-  }
-  else
-    groupRecordHead = newGroup;
-      
-  if(storeToFile)
-  {
-    writeGroupListToFile(newGroup);
-  }
-  
-  //printf("createGroupRec--\n");
-  return newGroup;
+       while (groupMembers != NULL)
+       {
+               sprintf(record + strlen(record), " , 0x%04X , 0x%02X",
+                               groupMembers->nwkAddr, groupMembers->endpoint);
+               groupMembers = groupMembers->next;
+       }
+
+       sprintf(record + strlen(record), "\n");
+
+       return record;
 }
 
-/*********************************************************************
- * @fn      addGroupMemberToGroup
- *
- * @brief   add a device to an existing groupRecordHead.
- *
- * @return  none
- */
-static int addGroupMemberToGroup( char *groupNameStr, uint16_t nwkAddr )
+#define MAX_SUPPORTED_GROUP_NAME_LENGTH 32
+#define MAX_SUPPORTED_GROUP_MEMBERS 20
+
+static groupRecord_t * groupListParseRecord(char * record)
 {
-  groupRecord_t* group;
-  
-  group = findGroupRec( groupNameStr );
-  
-  if(group != NULL)
-  {
-    groupMembersRecord_t *srchGroupMember = group->groupMembers;
-
-    //find the end of the list and check device not already in the list
-    while ( srchGroupMember )
-    {
-      if(srchGroupMember->groupMemberNwkAddr == nwkAddr)
-      {
-        //device already in group
-        return 0;
-      }
-       
-      if(srchGroupMember->next == NULL)
-      {
-        groupMembersRecord_t*  newGroupMembersRecord;
-        //we at the end of the list store the groupMember
-        newGroupMembersRecord = malloc(sizeof(groupMembersRecord_t));
-        newGroupMembersRecord->groupMemberNwkAddr = nwkAddr;
-        srchGroupMember->next = newGroupMembersRecord;
-        
-        writeGroupMemberToFile(groupNameStr, nwkAddr);
-        
-        return 0;
-      }
-      else
-      {
-        srchGroupMember = srchGroupMember->next;            
-      }
-    }    
-  }
-    
-  return 0;
+       char * pBuf = record + 1; //+1 is to ignore the 'for deletion' mark that may just be added to this record.
+       static groupRecord_t group;
+       static char groupName[MAX_SUPPORTED_GROUP_NAME_LENGTH + 1];
+       static groupMembersRecord_t member[MAX_SUPPORTED_GROUP_MEMBERS];
+       groupMembersRecord_t ** nextMemberPtr;
+       parsingResult_t parsingResult =
+       { SDB_TXT_PARSER_RESULT_OK, 0 };
+       int i;
+
+       if (record == NULL)
+       {
+               return NULL;
+       }
+
+       sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &group.id, 2, FALSE,
+                       &parsingResult);
+       sdb_txt_parser_get_quoted_string(&pBuf, groupName,
+                       MAX_SUPPORTED_GROUP_NAME_LENGTH, &parsingResult);
+       nextMemberPtr = &group.members;
+       for (i = 0;
+                       (parsingResult.code == SDB_TXT_PARSER_RESULT_OK)
+                                       && (i < MAX_SUPPORTED_GROUP_MEMBERS); i++)
+       {
+               *nextMemberPtr = &(member[i]);
+               sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].nwkAddr), 2,
+                               FALSE, &parsingResult);
+               sdb_txt_parser_get_numeric_field(&pBuf, (uint8_t *) &(member[i].endpoint),
+                               1, FALSE, &parsingResult);
+               nextMemberPtr = &(member[i].next);
+       }
+       *nextMemberPtr = NULL;
+
+       if ((parsingResult.code != SDB_TXT_PARSER_RESULT_OK)
+                       && (parsingResult.code != SDB_TXT_PARSER_RESULT_REACHED_END_OF_RECORD))
+       {
+               sdbtMarkError(db, record, &parsingResult);
+               return NULL;
+       }
+
+       if (strlen(groupName) > 0)
+       {
+               group.name = groupName;
+       }
+       else
+       {
+               group.name = NULL;
+       }
+
+       return &group;
 }
 
-/*********************************************************************
- * @fn      findGroupRec
- *
- * @brief   find a record in the list.
- *
- *
- * @return  none
- */
-static groupRecord_t* findGroupRec( char *groupNameStr )
+static int groupListCheckKeyName(char * record, char * key)
 {
-  groupRecord_t *srchRec = groupRecordHead;
-
-  //printf("findGroupRec++\n");
-  // find record
-  while ( (srchRec != NULL) ) 
-  {
-      //printf("findGroupRec: srchRec:%x\n", (uint32_t) srchRec);
-      //printf("findGroupRec: srchRec->groupNameStr:%x\n", (uint32_t) srchRec->groupNameStr);
-      //printf("findGroupRec: groupNameStr:%x\n", (uint32_t) groupNameStr);
-      if(srchRec->groupNameStr[0] == groupNameStr[0])
-      {
-        if(strncmp(srchRec->groupNameStr, groupNameStr, srchRec->groupNameStr[0]) == 0)
-        {
-          //we found the group
-          //printf("findGroupRec: group found\n");
-          break;
-        }
-      }
-      srchRec = srchRec->next;  
-  }
-  
-  //printf("findGroupRec--\n");
-   
-  return srchRec;
+       groupRecord_t * group;
+       int result = SDB_CHECK_KEY_NOT_EQUAL;
+
+       group = groupListParseRecord(record);
+       if (group == NULL)
+       {
+               return SDB_CHECK_KEY_ERROR;
+       }
+
+       if (strcmp(group->name, key) == 0)
+       {
+               result = SDB_CHECK_KEY_EQUAL;
+       }
+
+       return result;
 }
 
-/*********************************************************************
- * @fn      getFreeGroupId
- *
- * @brief   Finds the next (hieghst) free group ID.
- *
- *
- * @return  none
- */
-static uint16_t getFreeGroupId( void )
+static int groupListCheckKeyId(char * record, uint16_t * key)
 {
-  groupRecord_t *srchRec = groupRecordHead;
-  uint16_t heighestGroupIdx = 0;
-  
-  //printf("findGroupRec++\n");
-  
-  // find record
-  while ( srchRec ) 
-  {
-    if(heighestGroupIdx < srchRec->groupId)
-    {
-       heighestGroupIdx = srchRec->groupId;
-    }
-       
-    srchRec = srchRec->next;  
-  }
-  
-  //printf("findGroupRec--\n");
-   
-  return heighestGroupIdx + 1;
+       groupRecord_t * group;
+       int result = SDB_CHECK_KEY_NOT_EQUAL;
+
+       group = groupListParseRecord(record);
+       if (group == NULL)
+       {
+               return SDB_CHECK_KEY_ERROR;
+       }
+
+       if (group->id == *key)
+       {
+               result = SDB_CHECK_KEY_EQUAL;
+       }
+
+       return result;
 }
 
-/***************************************************************************************************
- * @fn      writeGroupListToFile - store group list.
- *
- * @brief   
- * @param   
- *
- * @return 
- ***************************************************************************************************/
-static void writeGroupListToFile( groupRecord_t *group )
+groupRecord_t * groupListGetGroupByName(char * groupName)
 {
-  FILE *fpGRoupFile;
-  
-  //printf("writeGroupListToFile++\n");
-  
-  fpGRoupFile = fopen("grouplistfile.dat", "a+b");
-
-  if(fpGRoupFile)
-  {
-    //printf("writeGroupListToFile: opened file\n");
-    
-    //printf("writeGroupListToFile: Store group: groupId %x, groupNameLen %x, groupName %s\n", group->groupId, (group->groupNameStr[0] + 1), group->groupNameStr);
-    //Store group
-    fwrite((const void *) &(group->groupId), 2, 1, fpGRoupFile);
-    fwrite((const void *) &(group->groupNameStr[0]), 1, 1, fpGRoupFile);    
-    fwrite((const void *) &(group->groupNameStr[1]), (group->groupNameStr[0]), 1, fpGRoupFile);
-    
-    //write group delimeter
-    fwrite((const void *) ";", 1, 1, fpGRoupFile);
-    
-    fflush(fpGRoupFile);
-    fclose(fpGRoupFile); 
-  }
+       char * rec;
+
+       rec = SDB_GET_UNIQUE_RECORD(db, groupName, (check_key_f)groupListCheckKeyName);
+       if (rec == NULL)
+       {
+               return NULL;
+       }
+
+       return groupListParseRecord(rec);
 }
 
-/***************************************************************************************************
- * @fn      writeGroupMemberToFile - store group list.
- *
- * @brief   
- * @param   
- *
- * @return 
- ***************************************************************************************************/
-static void writeGroupMemberToFile( char *groupNameStr, uint16_t nwkAddr  )
-{
-  FILE *fpGroupMemberFile;
-  uint32_t fileSize, groupStrIdx=0;
-  char *fileBuf, *groupStr, *groupStrEnd;
-  
-  //printf("writeGroupMemberToFile++\n");
-  
-  fpGroupMemberFile = fopen("grouplistfile.dat", "a+b");
-  
-  if(fpGroupMemberFile)
-  {
-    //read the file into a buffer  
-    fseek(fpGroupMemberFile, 0, SEEK_END);
-    fileSize = ftell(fpGroupMemberFile);
-    rewind(fpGroupMemberFile);  
-    fileBuf = (char*) calloc(sizeof(char), fileSize + 20);  
-    fread(fileBuf, 1, fileSize, fpGroupMemberFile);
-
-    //find the group
-    groupStr = strstr(groupNameStr, fileBuf);
-    //find group delimiter
-    groupStrEnd = strchr(groupStr, ';');
-    //get byte offset in fileSize
-    groupStrIdx += (groupStr - groupStrEnd);
-    //back up to before the ;    
-    groupStrIdx =- 1;
-        
-    //set the file pointer to the 
-    fseek(fpGroupMemberFile, SEEK_SET, groupStrIdx);
-
-    //printf("writeGroupMemberToFile: Store group member\n");
-    //write member delimeter
-    fwrite((const void *) ":", 1, 1, fpGroupMemberFile);
-    //write the member nwk addr
-    fwrite((const void *) &(nwkAddr), sizeof(uint16_t), 1, fpGroupMemberFile);
-  }
-    
-  fflush(fpGroupMemberFile);
-  fclose(fpGroupMemberFile);
-  free(fileBuf);   
-} 
-
-/***************************************************************************************************
- * @fn      readGroupListFromFile - restore the group list.
- *
- * @brief   
- *
- * @return 
- ***************************************************************************************************/
-static void readGroupListFromFile( void )
+uint16_t groupListGetUnusedGroupId(void)
 {
-  FILE *fpGRoupFile;
-  groupRecord_t *group;
-  uint32_t fileSize, groupStrIdx=0, bytesRead=0;
-  char *fileBuf;
-    
-  //printf("readGroupListFromFile++\n");
-  fpGRoupFile = fopen("grouplistfile.dat", "a+b");
-
-  if(fpGRoupFile)
-  {    
-    //printf("readGroupListFromFile: file opened\n");
-
-    //read the file into a buffer  
-    fseek(fpGRoupFile, 0, SEEK_END);
-    fileSize = ftell(fpGRoupFile);
-    rewind(fpGRoupFile);  
-    fileBuf = (char*) calloc(sizeof(char), fileSize);  
-    bytesRead = fread(fileBuf, 1, fileSize, fpGRoupFile);
-    
-    //printf("readGroupListFromFile: read file [%d:%d]\n", fileSize, bytesRead);
-    
-    if(fileBuf)
-    {
-      //printf("readGroupListFromFile: processing filebuf. groupStrIdx: %x, (groupStrIdx + fileBuf[groupStrIdx + 2] + 2) : %x \n", groupStrIdx, (groupStrIdx + fileBuf[groupStrIdx + 2] + 2));
-      
-      //read group if there is a full group to read (uint16_t groupId + string length byte + string length (stored in byte before string) )
-      while((groupStrIdx + 2 + fileBuf[groupStrIdx + 2] + 1) < fileSize)
-      {            
-        //printf("readGroupListFromFile: group read for group ID %x, str len %d\n", (uint16_t) fileBuf[groupStrIdx], fileBuf[(groupStrIdx + 2)]);
-        
-        group = createGroupRec(&(fileBuf[(groupStrIdx + 2)]), (uint16_t) fileBuf[groupStrIdx], 0);              
-        
-        //printf("readGroupListFromFile: group ID %x read\n", fileBuf[groupStrIdx]);
-        
-        //index past GroupId + groupNameStr + groupNameStrLen + ';'
-        groupStrIdx += 2 + fileBuf[groupStrIdx + 2] + 1 + 1;
-      }
-      
-      //printf("readGroupListFromFile: processed filebuf\n");      
-      
-      free(fileBuf);
-    }
-    
-    fflush(fpGRoupFile);
-    fclose(fpGRoupFile);    
-  }
-  
-  //printf("readGroupListFromFile--\n");
+       static uint16_t lastUsedGroupId = 0;
+
+       lastUsedGroupId++;
+
+       while (SDB_GET_UNIQUE_RECORD(db, &lastUsedGroupId, (check_key_f)groupListCheckKeyId)
+                       != NULL)
+       {
+               lastUsedGroupId++;
+       }
+
+       return lastUsedGroupId;
 }
 
-/*********************************************************************
- * @fn      devListRestorDevices
- *
- * @brief   create a device list from file.
- *
- * @param   none
- *
- * @return  none
- */
-void groupListRestorGroups( void )
+uint16_t groupListAddGroup(char *groupNameStr)
 {
-  //printf("groupListRestorGroups++\n");
-  
-  if( groupRecordHead == NULL)
-  {
-    readGroupListFromFile();
-  }
-  //else do what, should we delete the list and recreate from the file?
-  
-  //printf("groupListRestor