summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTonyCave2013-11-28 05:30:05 -0600
committerTonyCave2013-11-28 05:30:05 -0600
commitc26bd9dbde9d106444c08de8de655bedcdd4c6dc (patch)
treef4b3454e07bf5e8316fd9c26e52dd67c0b1954cc
parentf4aaf49f442b44c8dec3dc0271fa11ebd0d16889 (diff)
downloadlighting-gateway-c26bd9dbde9d106444c08de8de655bedcdd4c6dc.tar.gz
lighting-gateway-c26bd9dbde9d106444c08de8de655bedcdd4c6dc.tar.xz
lighting-gateway-c26bd9dbde9d106444c08de8de655bedcdd4c6dc.zip
merged control bridge changes
-rw-r--r--client/AndroidClients/LightingController/bin/LightingController.apkbin336063 -> 0 bytes
-rw-r--r--client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask$1.classbin996 -> 0 bytes
-rw-r--r--client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask.classbin3426 -> 0 bytes
-rw-r--r--client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask$1.classbin996 -> 0 bytes
-rw-r--r--client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask.classbin3426 -> 0 bytes
-rw-r--r--client/CClients/Source/socket_client.c.bak658
-rw-r--r--[-rwxr-xr-x]client/CClients/lightFlashCmdLine/linux-gnu/makefile (renamed from client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile)0
-rw-r--r--[-rwxr-xr-x]client/CClients/listDevsCmdLine/linux-gnu/makefile (renamed from client/CClients/listDevsCmdLine/i486-linux-gnu/makefile)0
-rw-r--r--[-rwxr-xr-x]client/CClients/openNetwork/linux-gnu/makefile (renamed from client/CClients/openNetwork/i486-linux-gnu/makefile)0
-rwxr-xr-xserver/Source/SimpleDB.c38
-rwxr-xr-xserver/Source/SimpleDB.h38
-rwxr-xr-xserver/Source/SimpleDBTxt.c38
-rwxr-xr-xserver/Source/SimpleDBTxt.h37
-rw-r--r--server/Source/zllSocCmd-TH.c473
-rw-r--r--server/Source/zllSocCmd.c1341
-rw-r--r--server/Source/zllSocCmd.h126
-rw-r--r--server/Source/zll_controller.c202
-rw-r--r--[-rwxr-xr-x]server/linux-gnu/makefile (renamed from server/i486-linux-gnu/Makefile)0
18 files changed, 150 insertions, 2801 deletions
diff --git a/client/AndroidClients/LightingController/bin/LightingController.apk b/client/AndroidClients/LightingController/bin/LightingController.apk
deleted file mode 100644
index b9a659e..0000000
--- a/client/AndroidClients/LightingController/bin/LightingController.apk
+++ /dev/null
Binary files differ
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask$1.class
deleted file mode 100644
index 66df729..0000000
--- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask$1.class
+++ /dev/null
Binary files differ
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask.class
deleted file mode 100644
index ccf8883..0000000
--- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/groupSelect$waitRspTask.class
+++ /dev/null
Binary files differ
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask$1.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask$1.class
deleted file mode 100644
index d08fab8..0000000
--- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask$1.class
+++ /dev/null
Binary files differ
diff --git a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask.class b/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask.class
deleted file mode 100644
index 84eb088..0000000
--- a/client/AndroidClients/LightingController/bin/classes/com/lightingcontroller/sceneSelect$waitRspTask.class
+++ /dev/null
Binary files differ
diff --git a/client/CClients/Source/socket_client.c.bak b/client/CClients/Source/socket_client.c.bak
deleted file mode 100644
index 97b8aad..0000000
--- a/client/CClients/Source/socket_client.c.bak
+++ /dev/null
@@ -1,658 +0,0 @@
1 /**************************************************************************************************
2 Filename: socket_client.c
3 Revised: $Date: 2012-03-21 17:37:33 -0700 (Wed, 21 Mar 2012) $
4 Revision: $Revision: 246 $
5
6 Description: This file contains Linux platform specific RemoTI (RTI) API
7 Surrogate implementation
8
9 Copyright (C) {2012} Texas Instruments Incorporated - http://www.ti.com/
10
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
15
16 Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18
19 Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the
22 distribution.
23
24 Neither the name of Texas Instruments Incorporated nor the names of
25 its contributors may be used to endorse or promote products derived
26 from this software without specific prior written permission.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 The following guide and a small portion of the code from Beej's Guide to Unix
41 IPC was used in the development of this software:
42 http://beej.us/guide/bgipc/output/html/multipage/intro.html#audience.
43 The code is Public Domain
44**************************************************************************************************/
45
46/**************************************************************************************************
47 * Includes
48 **************************************************************************************************/
49
50#include <stdio.h>
51#include <stdlib.h>
52#include <errno.h>
53#include <string.h>
54#include <sys/types.h>
55#include <sys/socket.h>
56#include <sys/un.h>
57#include <pthread.h>
58#include <poll.h>
59#include <sys/time.h>
60#include <unistd.h>
61
62#ifndef NPI_UNIX
63#include <netdb.h>
64#include <arpa/inet.h>
65#endif
66
67#include "socket_client.h"
68
69#define __BIG_DEBUG__
70#ifdef __BIG_DEBUG__
71#define debug_printf(fmt, ...) printf( fmt, ##__VA_ARGS__)
72#else
73#define debug_printf(fmt, ...)
74#endif
75
76#define msg_memcpy(src, dst, len) memcpy(src, dst, len)
77
78/**************************************************************************************************
79 * Externals
80 **************************************************************************************************/
81
82/**************************************************************************************************
83 * Constant
84 **************************************************************************************************/
85
86/**************************************************************************************************
87 * Type definitions
88 **************************************************************************************************/
89
90struct LinkedMsg
91{
92 msgData_t message;
93 void *nextMessage;
94};
95
96typedef struct LinkedMsg linkedMsg;
97
98#define TX_BUF_SIZE (2 * (sizeof(msgData_t)))
99
100
101/**************************************************************************************************
102 * Global Variables
103 **************************************************************************************************/
104
105/**************************************************************************************************
106 * Local Variables
107 **************************************************************************************************/
108
109// Client socket handle
110int sClientFd;
111// Client data transmission buffers
112char socketBuf[2][TX_BUF_SIZE];
113// Client data received buffer
114linkedMsg *rxBuf;
115// Client data processing buffer
116linkedMsg *rxProcBuf;
117
118// Message count to keep track of incoming and processed messages
119static int messageCount = 0;
120
121static pthread_t RTISThreadId;
122static void *rxThreadFunc (void *ptr);
123static void *handleThreadFunc (void *ptr);
124
125// Mutex to handle rx
126pthread_mutex_t clientRxMutex = PTHREAD_MUTEX_INITIALIZER;
127
128// conditional variable to notify that the AREQ is handled
129static pthread_cond_t clientRxCond;
130
131#ifndef NPI_UNIX
132struct addrinfo *resAddr;
133#endif
134
135socketClientCb_t socketClientRxCb;
136
137/**************************************************************************************************
138 * Local Function Prototypes
139 **************************************************************************************************/
140static void initSyncRes(void);
141static void delSyncRes(void);
142
143
144
145/**************************************************************************************************
146 *
147 * @fn socketClientInit
148 *
149 * @brief This function initializes RTI Surrogate
150 *
151 * input parameters
152 *
153 * @param ipAddress - path to the NPI Server Socket
154 *
155 * output parameters
156 *
157 * None.
158 *
159 * @return 1 if the surrogate module started off successfully.
160 * 0, otherwise.
161 *
162 **************************************************************************************************/
163int socketClientInit(const char *devPath, socketClientCb_t cb)
164{
165 int res = 1, i = 0;
166 const char *ipAddress = "", *port = "";
167 char *pStr, strTmp[128];
168
169 socketClientRxCb = cb;
170
171 strncpy(strTmp, devPath, 128);
172 // use strtok to split string and find IP address and port;
173 // the format is = IPaddress:port
174 // Get first token
175 pStr = strtok (strTmp, ":");
176 while ( pStr != NULL)
177 {
178 if (i == 0)
179 {
180 // First part is the IP address
181 ipAddress = pStr;
182 }
183 else if (i == 1)
184 {
185 // Second part is the port
186 port = pStr;
187 }
188 i++;
189 if (i > 2)
190 break;
191 // Now get next token
192 pStr = strtok (NULL, " ,:;-|");
193 }
194
195 /**********************************************************************
196 * Initiate synchronization resources
197 */
198 initSyncRes();
199
200 /**********************************************************************
201 * Connect to the NPI server
202 **********************************************************************/
203
204#ifdef NPI_UNIX
205 int len;
206 struct sockaddr_un remote;
207
208 if ((sClientFd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
209 perror("socket");
210 exit(1);
211 }
212#else
213 struct addrinfo hints;
214
215 memset(&hints, 0, sizeof(hints));
216 hints.ai_family = AF_UNSPEC;
217 hints.ai_socktype = SOCK_STREAM;
218
219// ipAddress = "192.168.128.133";
220// if ((res = getaddrinfo(NULL, ipAddress, &hints, &resAddr)) != 0)
221 if (port == NULL)
222 {
223 // Fall back to default if port was not found in the configuration file
224 printf("Warning! Port not sent to RTIS. Will use default port: %s", DEFAULT_PORT);
225
226 if ((res = getaddrinfo(ipAddress, DEFAULT_PORT, &hints, &resAddr)) != 0)
227 {
228 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(res));
229 res = 2;
230 }
231 else
232 {
233 // Because of inverted logic on return value
234 res = 1;
235 }
236 }
237 else
238 {
239 printf("Port: %s\n\n", port);
240 if ((res = getaddrinfo(ipAddress, port, &hints, &resAddr)) != 0)
241 {
242 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(res));
243 res = 2;
244 }
245 else
246 {
247 // Because of inverted logic on return value
248 res = 1;
249 }
250 }
251
252 printf("IP addresses for %s:\n\n", ipAddress);
253
254 struct addrinfo *p;
255 char ipstr[INET6_ADDRSTRLEN];
256 for(p = resAddr;p != NULL; p = p->ai_next) {
257 void *addr;
258 char *ipver;
259
260 // get the pointer to the address itself,
261 // different fields in IPv4 and IPv6:
262 if (p->ai_family == AF_INET) { // IPv4
263 struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
264 addr = &(ipv4->sin_addr);
265 ipver = "IPv4";
266 } else { // IPv6
267 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
268 addr = &(ipv6->sin6_addr);
269 ipver = "IPv6";
270 }
271
272 // convert the IP to a string and print it:
273 inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
274 printf(" %s: %s\n", ipver, ipstr);
275 }
276
277
278 if ((sClientFd = socket(resAddr->ai_family, resAddr->ai_socktype, resAddr->ai_protocol)) == -1) {
279 perror("socket");
280 exit(1);
281 }
282#endif
283
284 printf("Trying to connect...\n");
285
286#ifdef NPI_UNIX
287 remote.sun_family = AF_UNIX;
288 strcpy(remote.sun_path, ipAddress);
289 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
290 if (connect(sClientFd, (struct sockaddr *)&remote, len) == -1) {
291 perror("connect");
292 res = 0;
293 }
294#else
295 if (connect(sClientFd, resAddr->ai_addr, resAddr->ai_addrlen) == -1) {
296 perror("connect");
297 res = 0;
298 }
299#endif
300
301 if (res == 1)
302 printf("Connected.\n");
303
304
305 int no = 0;
306 // allow out-of-band data
307 if (setsockopt(sClientFd, SOL_SOCKET, SO_OOBINLINE, &no, sizeof(int)) == -1)
308 {
309 perror("setsockopt");
310 res = 0;
311 }
312
313 /**********************************************************************
314 * Create thread which can read new messages from the NPI server
315 **********************************************************************/
316
317 if (pthread_create(&RTISThreadId, NULL, rxThreadFunc, NULL))
318 {
319 // thread creation failed
320 printf("Failed to create RTIS LNX IPC Client read thread\n");
321 return -1;
322 }
323
324 /**********************************************************************
325 * Create thread which can handle new messages from the NPI server
326 **********************************************************************/
327
328 if (pthread_create(&RTISThreadId, NULL, handleThreadFunc, NULL))
329 {
330 // thread creation failed
331 printf("Failed to create RTIS LNX IPC Client handle thread\n");
332 return -1;
333 }
334
335 return res;
336}
337
338static void *handleThreadFunc (void *ptr)
339{
340 int done = 0, tryLockFirstTimeOnly = 0;
341
342 // Handle message from socket
343 do {
344
345 if (tryLockFirstTimeOnly == 0)
346 {
347 // Lock mutex
348 debug_printf("[MUTEX] Lock AREQ Mutex (Handle)\n");
349 pthread_mutex_lock(&clientRxMutex);
350
351 debug_printf("\n[MUTEX] AREQ Lock (Handle)\n");
352 tryLockFirstTimeOnly = 1;
353 }
354
355 // Conditional wait for the response handled in the Rx handling thread,
356 debug_printf("[MUTEX] Wait for Rx Cond (Handle) signal...\n");
357 pthread_cond_wait(&clientRxCond, &clientRxMutex);
358
359 debug_printf("[MUTEX] (Handle) has lock\n");
360
361 // Walk through all received AREQ messages before releasing MUTEX
362 linkedMsg *searchList = rxProcBuf, *clearList;
363 while (searchList != NULL)
364 {
365 debug_printf("\n\n[DBG] Processing \t@ 0x%.16X next \t@ 0x%.16X\n",
366 (unsigned int)searchList,
367 (unsigned int)(searchList->nextMessage));
368
369 if( socketClientRxCb != NULL)
370 {
371 debug_printf("[MUTEX] Calling socketClientRxCb (Handle)...\n");
372 socketClientRxCb((msgData_t *)&(searchList->message));
373 }
374
375 debug_printf("[MUTEX] (Handle) (message @ 0x%.16X)...\n", (unsigned int)searchList);
376
377 clearList = searchList;
378 // Set search list to next message
379 searchList = searchList->nextMessage;
380 // Free processed buffer
381 if (clearList == NULL)
382 {
383 // Impossible error, must abort
384 done = 1;
385 printf("[ERR] clearList buffer was already free\n");
386 break;
387 }
388 else
389 {
390 messageCount--;
391 debug_printf("[DBG] Clearing \t\t@ 0x%.16X (processed %d messages)...\n",
392 (unsigned int)clearList,
393 messageCount);
394 memset(clearList, 0, sizeof(linkedMsg));
395 free(clearList);
396 }
397 }
398 debug_printf("[MUTEX] Signal message(s) handled (Handle) (processed %d messages)...\n", messageCount);
399
400 debug_printf("[DBG] Finished processing (processed %d messages)...\n",
401 messageCount);
402
403 } while (!done);
404
405 return ptr;
406}
407
408static void *rxThreadFunc (void *ptr)
409{
410 int done = 0, n;
411
412 /* thread loop */
413
414 struct pollfd ufds[1];
415 int pollRet;
416 ufds[0].fd = sClientFd;
417 ufds[0].events = POLLIN | POLLPRI;
418
419 // Read from socket
420 do {
421 pollRet = poll((struct pollfd*)&ufds, 1, 1);
422 if (pollRet == -1)
423 {
424 // Error occured in poll()
425 perror("poll");
426 }
427 else if (pollRet == 0)
428 {
429 // Timeout, could still be AREQ to process
430 }
431 else
432 {
433 if (ufds[0].revents & POLLIN) {
434 n = recv(sClientFd,
435 socketBuf[0],
436 SRPC_FRAME_HDR_SZ,
437 0); // normal data
438 }
439 if (ufds[0].revents & POLLPRI) {
440 n = recv(sClientFd,
441 socketBuf[0],
442 SRPC_FRAME_HDR_SZ,
443 MSG_OOB); // out-of-band data
444 }
445 if (n <= 0)
446 {
447 if (n < 0)
448 perror("recv");
449 done = 1;
450 }
451 else if (n == SRPC_FRAME_HDR_SZ)
452 {
453 // We have received the header, now read out length byte and process it
454 n = recv(sClientFd,
455 (uint8_t*)&(socketBuf[0][SRPC_FRAME_HDR_SZ]),
456 ((msgData_t *)&(socketBuf[0][0]))->len,
457 0);
458 if (n == ((msgData_t *)&(socketBuf[0][0]))->len)
459 {
460 int i;
461 debug_printf("Received %d bytes,\t cmdId 0x%.2X, pData:\t",
462 ((msgData_t *)&(socketBuf[0][0]))->len,
463 ((msgData_t *)&(socketBuf[0][0]))->cmdId);
464 for (i = SRPC_FRAME_HDR_SZ; i < (n + SRPC_FRAME_HDR_SZ); i++)
465 {
466 debug_printf(" 0x%.2X", (uint8_t)socketBuf[0][i]);
467 }
468 debug_printf("\n");
469
470 // Allocate memory for new message
471 linkedMsg *newMessage = (linkedMsg *) malloc(sizeof(linkedMsg));
472
473 //debug_printf("Freeing new message (@ 0x%.16X)...\n", (unsigned int)newMessage);
474 //free(newMessage);
475
476 if (newMessage == NULL)
477 {
478 // Serious error, must abort
479 done = 1;
480 printf("[ERR] Could not allocate memory for AREQ message\n");
481 break;
482 }
483 else
484 {
485 messageCount++;
486 memset(newMessage, 0, sizeof(linkedMsg));
487 debug_printf("\n[DBG] Allocated \t@ 0x%.16X (received\040 %d messages), size:%x...\n",
488 (unsigned int)newMessage,
489 messageCount,
490 sizeof(linkedMsg));
491 }
492
493 debug_printf("Filling new message (@ 0x%.16X)...\n", (unsigned int)newMessage);
494
495 // Copy AREQ message into AREQ buffer
496 memcpy(&(newMessage->message),
497 (uint8_t*)&(socketBuf[0][0]),
498 (((msgData_t *)&(socketBuf[0][0]))->len + SRPC_FRAME_HDR_SZ));
499
500 // Place message in read list
501 if (rxBuf == NULL)
502 {
503 // First message in list
504 rxBuf = newMessage;
505 }
506 else
507 {
508 linkedMsg *searchList = rxBuf;
509 // Find last entry and place it here
510 while (searchList->nextMessage != NULL)
511 {
512 searchList = searchList->nextMessage;
513 }
514 searchList->nextMessage = newMessage;
515 }
516 }
517 else
518 {
519 // Serious error
520 printf("ERR: Incoming Rx has incorrect length field; %d\n",
521 ((msgData_t *)&(socketBuf[0][0]))->len);
522
523 debug_printf("[MUTEX] Unlock Rx Mutex (Read)\n");
524 // Then unlock the thread so the handle can handle the AREQ
525 pthread_mutex_unlock(&clientRxMutex);
526 }
527 }
528 else
529 {
530 // Impossible. ... ;)
531 }
532 }
533
534 // Handle thread must make sure it has finished its list. See if there are new messages to move over
535 if (rxBuf != NULL)
536 {
537 pthread_mutex_lock(&clientRxMutex);
538
539 // Move list over for processing
540 rxProcBuf = rxBuf;
541
542 // Clear receiving buffer for new messages
543 rxBuf = NULL;
544
545 debug_printf("[DBG] Copied message list (processed %d messages)...\n",
546 messageCount);
547
548 debug_printf("[MUTEX] Unlock Mutex (Read)\n");
549 // Then unlock the thread so the handle can handle the AREQ
550 pthread_mutex_unlock(&clientRxMutex);
551
552 debug_printf("[MUTEX] Signal message read (Read)...\n");
553 // Signal to the handle thread an AREQ message is ready
554 pthread_cond_signal(&clientRxCond);
555 debug_printf("[MUTEX] Signal message read (Read)... sent\n");
556 }
557
558 } while (!done);
559
560
561 return ptr;
562}
563
564/* Initialize thread synchronization resources */
565static void initSyncRes(void)
566{
567 // initialize all mutexes
568 pthread_mutex_init(&clientRxMutex, NULL);
569
570 // initialize all conditional variables
571 pthread_cond_init(&clientRxCond, NULL);
572}
573
574/* Destroy thread synchronization resources */
575static void delSyncRes(void)
576{
577 // In Linux, there is no dynamically allocated resources
578 // and hence the following calls do not actually matter.
579
580 // destroy all conditional variables
581 pthread_cond_destroy(&clientRxCond);
582
583 // destroy all mutexes
584 pthread_mutex_destroy(&clientRxMutex);
585
586}
587
588/**************************************************************************************************
589 *
590 * @fn socketClientClose
591 *
592 * @brief This function stops RTI surrogate module
593 *
594 * input parameters
595 *
596 * None.
597 *
598 * output parameters
599 *
600 * None.
601 *
602 * @return None.
603 *
604 **************************************************************************************************/
605void socketClientClose(void)
606{
607 // Close the NPI socket connection
608
609 close(sClientFd);
610
611 // Delete synchronization resources
612 delSyncRes();
613
614#ifndef NPI_UNIX
615 freeaddrinfo(resAddr); // free the linked-list
616#endif //NPI_UNIX
617
618}
619
620/**************************************************************************************************
621 *
622 * @fn socketClientSendData
623 *
624 * @brief This function sends a message asynchronously over the socket
625 *
626 * input parameters
627 *
628 * None.
629 *
630 * output parameters
631 *
632 * None.
633 *
634 * @return None.
635 *
636 **************************************************************************************************/
637void socketClientSendData (msgData_t *pMsg)
638{
639 int i;
640 debug_printf("trying to send %d bytes,\t cmdId 0x%.2X, pData:",
641 pMsg->len,
642 pMsg->cmdId);
643 debug_printf("\t");
644 for (i = 0; i < pMsg->len; i++)
645 {
646 debug_printf(" 0x%.2X", pMsg->pData[i]);
647 }
648 debug_printf("\n");
649
650 if (send(sClientFd, ((uint8_t*)pMsg), pMsg->len + SRPC_FRAME_HDR_SZ , 0) == -1)
651 {
652 perror("send");
653 exit(1);
654 }
655}
656
657/**************************************************************************************************
658 **************************************************************************************************/
diff --git a/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile b/client/CClients/lightFlashCmdLine/linux-gnu/makefile
index 8d799d3..8d799d3 100755..100644
--- a/client/CClients/lightFlashCmdLine/i486-linux-gnu/makefile
+++ b/client/CClients/lightFlashCmdLine/linux-gnu/makefile
diff --git a/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile b/client/CClients/listDevsCmdLine/linux-gnu/makefile
index 5d05687..5d05687 100755..100644
--- a/client/CClients/listDevsCmdLine/i486-linux-gnu/makefile
+++ b/client/CClients/listDevsCmdLine/linux-gnu/makefile
diff --git a/client/CClients/openNetwork/i486-linux-gnu/makefile b/client/CClients/openNetwork/linux-gnu/makefile
index 1ea0e57..1ea0e57 100755..100644
--- a/client/CClients/openNetwork/i486-linux-gnu/makefile
+++ b/client/CClients/openNetwork/linux-gnu/makefile
diff --git a/server/Source/SimpleDB.c b/server/Source/SimpleDB.c
index bc486fe..9d175eb 100755
--- a/server/Source/SimpleDB.c
+++ b/server/Source/SimpleDB.c
@@ -1,3 +1,41 @@
1/**************************************************************************************************
2 * Filename: SimpleDB.c
3 * Description: Simple Data Base
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
1#include <stdio.h> 39#include <stdio.h>
2#include <stdlib.h> 40#include <stdlib.h>
3#include <string.h> 41#include <string.h>
diff --git a/server/Source/SimpleDB.h b/server/Source/SimpleDB.h
index f302968..7c4030c 100755
--- a/server/Source/SimpleDB.h
+++ b/server/Source/SimpleDB.h
@@ -1,3 +1,41 @@
1/**************************************************************************************************
2 * Filename: SimpleDB.c
3 * Description: Simple Data Base
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
1#ifndef SIMPLE_DB_H 39#ifndef SIMPLE_DB_H
2#define SIMPLE_DB_H 40#define SIMPLE_DB_H
3 41
diff --git a/server/Source/SimpleDBTxt.c b/server/Source/SimpleDBTxt.c
index 02d64ee..0c9fe8b 100755
--- a/server/Source/SimpleDBTxt.c
+++ b/server/Source/SimpleDBTxt.c
@@ -1,4 +1,40 @@
1//This is a specific implemntation of a text-based db system, based on the SimpleDB module 1/**************************************************************************************************
2 * Filename: SimpleDBTxt.c
3 * Description: This is a specific implemntation of a text-based db system, based on the SimpleDB module.
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
2 38
3#include <stdint.h> 39#include <stdint.h>
4#include <string.h> 40#include <string.h>
diff --git a/server/Source/SimpleDBTxt.h b/server/Source/SimpleDBTxt.h
index e971fc4..84870f3 100755
--- a/server/Source/SimpleDBTxt.h
+++ b/server/Source/SimpleDBTxt.h
@@ -1,3 +1,40 @@
1/**************************************************************************************************
2 * Filename: SimpleDBTxt.h
3 * Description: This is a specific implemntation of a text-based db system, based on the SimpleDB module.
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
1#ifndef SIMPLE_DB_TXT_H 38#ifndef SIMPLE_DB_TXT_H
2#define SIMPLE_DB_TXT_H 39#define SIMPLE_DB_TXT_H
3 40
diff --git a/server/Source/zllSocCmd-TH.c b/server/Source/zllSocCmd-TH.c
deleted file mode 100644
index 5391712..0000000
--- a/server/Source/zllSocCmd-TH.c
+++ /dev/null
@@ -1,473 +0,0 @@
1/*
2 * zllSocCmd.c
3 *
4 * This module contains the API for the zll SoC Host Interface.
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39
40/*********************************************************************
41 * INCLUDES
42 */
43#include <termios.h>
44#include <string.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <fcntl.h>
49#include <sys/ioctl.h>
50
51#include "zllSocCmd.h"
52
53
54/*********************************************************************
55 * MACROS
56 */
57
58/*********************************************************************
59 * CONSTANTS
60 */
61#define MAX_CONSOLE_CMD_LEN 128
62
63/************************************************************
64 * TYPEDEFS
65 */
66
67/*********************************************************************
68 * GLOBAL VARIABLES
69 */
70static uint16_t savedNwkAddr;
71static uint8_t savedAddrMode;
72static uint8_t savedEp;
73static uint8_t savedValue;
74static uint16_t savedTransitionTime;
75static uint16_t savedDeviceId;
76static uint16_t savedProfileId;
77
78/*********************************************************************
79 * LOCAL VARIABLES
80 */
81zllSocCallbacks_t zllSocCb;
82
83/*********************************************************************
84 * LOCAL FUNCTIONS
85 */
86void commandUsage( void );
87void processConsoleCommand( void );
88void getConsoleCommandParams(char* cmdBuff, uint16_t *nwkAddr, uint16_t *deviceId, uint16_t *profileId, uint8_t *addrMode, uint8_t *ep, uint8_t *value, uint16_t *transitionTime);
89uint32_t getParam( char *cmdBuff, char *paramId, uint32_t *paramInt);
90
91/*********************************************************************
92 * API FUNCTIONS
93 */
94
95/*********************************************************************
96 * @fn zllSocOpen
97 *
98 * @brief opens the serial port to the CC253x.
99 *
100 * @param devicePath - path to the UART device
101 *
102 * @return status
103 */
104int32_t zllSocOpen( char *devicePath )
105{
106 //do nothing, TH is going to read command from stdin to simulate a zll device
107 return 0;
108}
109
110void zllSocClose( void )
111{
112 return;
113}
114
115/*********************************************************************
116 * @fn zllSocOpen
117 *
118 * @brief opens the serial port to the CC253x.
119 *
120 * @param devicePath - path to the UART device
121 *
122 * @return status
123 */
124void zllSocRegisterCallbacks( zllSocCallbacks_t zllSocCallbacks)
125{
126 //copy the callback function pointers
127 memcpy(&zllSocCb, &zllSocCallbacks, sizeof(zllSocCallbacks_t));
128 return;
129}
130
131
132/*********************************************************************
133 * @fn zllSocTouchLink
134 *
135 * @brief Send the touchLink command to the CC253x.
136 *
137 * @param none
138 *
139 * @return none
140 */
141void zllSocTouchLink(void)
142{
143}
144
145
146/*********************************************************************
147 * @fn zllSocResetToFn
148 *
149 * @brief Send the reset to factory new command to the CC253x.
150 *
151 * @param none
152 *
153 * @return none
154 */
155void zllSocResetToFn(void)
156{
157}
158
159/*********************************************************************
160 * @fn zllSocSendResetToFn
161 *
162 * @brief Send the reset to factory new command to a ZLL device.
163 *
164 * @param none
165 *
166 * @return none
167 */
168void zllSocSendResetToFn(void)
169{
170}
171
172/*********************************************************************
173 * @fn zllSocSetState
174 *
175 * @brief Send the on/off command to a ZLL light.
176 *
177 * @param state - 0: Off, 1: On.
178 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
179 * @param endpoint - endpoint of the Light.
180 * @param addrMode - Unicast or Group cast.
181 *
182 * @return none
183 */
184void zllSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
185{
186}
187
188/*********************************************************************
189 * @fn zllSocSetLevel
190 *
191 * @brief Send the level command to a ZLL light.
192 *
193 * @param level - 0-128 = 0-100%
194 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
195 * @param endpoint - endpoint of the Light.
196 * @param addrMode - Unicast or Group cast.
197 *
198 * @return none
199 */
200void zllSocSetLevel(uint8_t level, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
201{
202}
203
204/*********************************************************************
205 * @fn zllSocSetHue
206 *
207 * @brief Send the hue command to a ZLL light.
208 *
209 * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green
210 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
211 * @param endpoint - endpoint of the Light.
212 * @param addrMode - Unicast or Group cast.
213 *
214 * @return none
215 */
216void zllSocSetHue(uint8_t hue, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
217{
218}
219
220/*********************************************************************
221 * @fn zllSocSetSat
222 *
223 * @brief Send the satuartion command to a ZLL light.
224 *
225 * @param sat - 0-128 : 0=white, 128: fully saturated color
226 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
227 * @param endpoint - endpoint of the Light.
228 * @param addrMode - Unicast or Group cast.
229 *
230 * @return none
231 */
232void zllSocSetSat(uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
233{
234}
235
236/*********************************************************************
237 * @fn zllSocSetHueSat
238 *
239 * @brief Send the hue and satuartion command to a ZLL light.
240 *
241 * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green
242 * @param sat - 0-128 : 0=white, 128: fully saturated color
243 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
244 * @param endpoint - endpoint of the Light.
245 * @param addrMode - Unicast or Group cast.
246 *
247 * @return none
248 */
249void zllSocSetHueSat(uint8_t hue, uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
250{
251}
252
253/*********************************************************************
254 * @fn zllSocGetState
255 *
256 * @brief Send the get state command to a ZLL light.
257 *
258 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
259 * @param endpoint - endpoint of the Light.
260 * @param addrMode - Unicast or Group cast.
261 *
262 * @return none
263 */
264void zllSocGetState(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
265{
266}
267
268/*********************************************************************
269 * @fn zllSocGetLevel
270 *
271 * @brief Send the get level command to a ZLL light.
272 *
273 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
274 * @param endpoint - endpoint of the Light.
275 * @param addrMode - Unicast or Group cast.
276 *
277 * @return none
278 */
279void zllSocGetLevel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
280{
281}
282
283/*********************************************************************
284 * @fn zllSocGetHue
285 *
286 * @brief Send the get hue command to a ZLL light.
287 *
288 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
289 * @param endpoint - endpoint of the Light.
290 * @param addrMode - Unicast or Group cast.
291 *
292 * @return none
293 */
294void zllSocGetHue(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
295{
296}
297
298/*********************************************************************
299 * @fn zllSocGetSat
300 *
301 * @brief Send the get saturation command to a ZLL light.
302 *
303 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
304 * @param endpoint - endpoint of the Light.
305 * @param addrMode - Unicast or Group cast.
306 *
307 * @return none
308 */
309void zllSocGetSat(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
310{
311}
312
313/*************************************************************************************************
314 * @fn zllSocProcessRpc()
315 *
316 * @brief read and process the RPC from the ZLL controller
317 *
318 * @param none
319 *
320 * @return length of current Rx Buffer
321 *************************************************************************************************/
322void zllSocProcessRpc (void)
323{
324 char cmdBuff[MAX_CONSOLE_CMD_LEN];
325 uint32_t bytesRead;
326 uint16_t nwkAddr;
327 uint16_t deviceId;
328 uint16_t profileId;
329 uint8_t addrMode;
330 uint8_t endpoint;
331 uint8_t value;
332 uint16_t transitionTime;
333
334 //read stdin
335 bytesRead = read(0, cmdBuff, (MAX_CONSOLE_CMD_LEN-1));
336 cmdBuff[bytesRead] = '\0';
337
338 getConsoleCommandParams(cmdBuff, &nwkAddr, &deviceId, &profileId, &addrMode, &endpoint, &value, &transitionTime);
339
340 if((strstr(cmdBuff, "touchlink")) != 0)
341 {
342 printf("processRpcSysAppTlInd: %x:%x:%x:%x\n", nwkAddr, endpoint, deviceId, profileId);
343 if(zllSocCb.pfnTlIndicationCb)
344 {
345 epInfo_t epInfo;
346 epInfo.nwkAddr = nwkAddr;
347 epInfo.endpoint = endpoint;
348 epInfo.deviceID = deviceId;
349 epInfo.profileID = profileId;
350 zllSocCb.pfnTlIndicationCb(&epInfo);
351 }
352 }
353 return;
354}
355
356void getConsoleCommandParams(char* cmdBuff, uint16_t *nwkAddr, uint16_t *deviceId, uint16_t *profileId, uint8_t *addrMode, uint8_t *ep, uint8_t *value, uint16_t *transitionTime)
357{
358 //set some default values
359 uint32_t tmpInt;
360
361 if( getParam( cmdBuff, "-n", &tmpInt) )
362 {
363 savedNwkAddr = (uint16_t) tmpInt;
364 }
365 if( getParam( cmdBuff, "-d", &tmpInt) )
366 {
367 savedDeviceId = (uint16_t) tmpInt;
368 }
369 if( getParam( cmdBuff, "-p", &tmpInt) )
370 {
371 savedProfileId = (uint16_t) tmpInt;
372 }
373 if( getParam( cmdBuff, "-m", &tmpInt) )
374 {
375 savedAddrMode = (uint8_t) tmpInt;
376 }
377 if( getParam( cmdBuff, "-e", &tmpInt) )
378 {
379 savedEp = (uint8_t) tmpInt;
380 }
381 if( getParam( cmdBuff, "-v", &tmpInt) )
382 {
383 savedValue = (uint8_t) tmpInt;
384 }
385 if( getParam( cmdBuff, "-t", &tmpInt) )
386 {
387 savedTransitionTime = (uint16_t) tmpInt;
388 }
389
390 *nwkAddr = savedNwkAddr;
391 *addrMode = savedAddrMode;
392 *ep = savedEp;
393 *value = savedValue;
394 *transitionTime = savedTransitionTime;
395 *deviceId = savedDeviceId;
396 *profileId = savedProfileId;
397
398 return;
399}
400
401uint32_t getParam( char *cmdBuff, char *paramId, uint32_t *paramInt)
402{
403 char* paramStrStart;
404 char* paramStrEnd;
405 //0x1234+null termination
406 char paramStr[7];
407 uint32_t rtn = 0;
408
409 memset(paramStr, 0, sizeof(paramStr));
410 paramStrStart = strstr(cmdBuff, paramId);
411
412 if( paramStrStart )
413 {
414 //index past the param idenentifier "-?"
415 paramStrStart+=2;
416 //find the the end of the param text
417 paramStrEnd = strstr(paramStrStart, " ");
418 if( paramStrEnd )
419 {
420 if(paramStrEnd-paramStrStart > (sizeof(paramStr)-1))
421 {
422 //we are not on the last param, but the param str is too long
423 strncpy( paramStr, paramStrStart, (sizeof(paramStr)-1));
424 paramStr[sizeof(paramStr)-1] = '\0';
425 }
426 else
427 {
428 //we are not on the last param so use the " " as the delimiter
429 strncpy( paramStr, paramStrStart, paramStrEnd-paramStrStart);
430 paramStr[paramStrEnd-paramStrStart] = '\0';
431 }
432 }
433
434 else
435 {
436 //we are on the last param so use the just go the the end of the string
437 //(which will be null terminate). But make sure that it is not bigger
438 //than our paramStr buffer.
439 if(strlen(paramStrStart) > (sizeof(paramStr)-1))
440 {
441 //command was entered wrong and paramStrStart will over flow the
442 //paramStr buffer.
443 strncpy( paramStr, paramStrStart, (sizeof(paramStr)-1));
444 paramStr[sizeof(paramStr)-1] = '\0';
445 }
446 else
447 {
448 //Param is the correct size so just copy it.
449 strcpy( paramStr, paramStrStart);
450 paramStr[strlen(paramStrStart)-1] = '\0';
451 }
452 }
453
454 //was the param in hex or dec?
455 if(strstr(paramStr, "0x"))
456 {
457 //convert the hex value to an int.
458 sscanf(paramStr, "0x%x", paramInt);
459 }
460 else
461 {
462 //assume that it ust be dec and convert to int.
463 sscanf(paramStr, "%d", paramInt);
464 }
465
466 //paramInt was set
467 rtn = 1;
468
469 }
470
471 return rtn;
472}
473
diff --git a/server/Source/zllSocCmd.c b/server/Source/zllSocCmd.c
deleted file mode 100644
index b0fd2f8..0000000
--- a/server/Source/zllSocCmd.c
+++ /dev/null
@@ -1,1341 +0,0 @@
1/*
2 * zllSocCmd.c
3 *
4 * This module contains the API for the zll SoC Host Interface.
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39
40/*********************************************************************
41 * INCLUDES
42 */
43#include <termios.h>
44#include <string.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <fcntl.h>
49#include <sys/ioctl.h>
50
51#include <errno.h>
52#include <string.h>
53
54#include "zllSocCmd.h"
55
56
57/*********************************************************************
58 * MACROS
59 */
60
61#define APPCMDHEADER(len) \
620xFE, \
63len, /*RPC payload Len */ \
640x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */ \
650x00, /*MT_APP_MSG */ \
660x0B, /*Application Endpoint */ \
670x02, /*short Addr 0x0002 */ \
680x00, /*short Addr 0x0002 */ \
690x0B, /*Dst EP */ \
700xFF, /*Cluster ID 0xFFFF invalid, used for key */ \
710xFF, /*Cluster ID 0xFFFF invalid, used for key */ \
72
73#define BUILD_UINT16(loByte, hiByte) \
74 ((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
75
76#define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \
77 ((uint32_t)((uint32_t)((Byte0) & 0x00FF) \
78 + ((uint32_t)((Byte1) & 0x00FF) << 8) \
79 + ((uint32_t)((Byte2) & 0x00FF) << 16) \
80 + ((uint32_t)((Byte3) & 0x00FF) << 24)))
81
82/*********************************************************************
83 * CONSTANTS
84 */
85#define ZLL_MT_APP_RPC_CMD_TOUCHLINK 0x01
86#define ZLL_MT_APP_RPC_CMD_RESET_TO_FN 0x02
87#define ZLL_MT_APP_RPC_CMD_CH_CHANNEL 0x03
88#define ZLL_MT_APP_RPC_CMD_JOIN_HA 0x04
89#define ZLL_MT_APP_RPC_CMD_PERMIT_JOIN 0x05
90#define ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN 0x06
91
92#define MT_APP_RSP 0x80
93#define MT_APP_ZLL_TL_IND 0x81
94#define MT_APP_ZLL_NEW_DEV_IND 0x82
95
96#define MT_DEBUG_MSG 0x80
97
98#define COMMAND_LIGHTING_MOVE_TO_HUE 0x00
99#define COMMAND_LIGHTING_MOVE_TO_SATURATION 0x03
100#define COMMAND_LEVEL_MOVE_TO_LEVEL 0x00
101
102/*** Foundation Command IDs ***/
103#define ZCL_CMD_READ 0x00
104#define ZCL_CMD_READ_RSP 0x01
105#define ZCL_CMD_WRITE 0x02
106#define ZCL_CMD_WRITE_UNDIVIDED 0x03
107#define ZCL_CMD_WRITE_RSP 0x04
108
109// General Clusters
110#define ZCL_CLUSTER_ID_GEN_IDENTIFY 0x0003
111#define ZCL_CLUSTER_ID_GEN_GROUPS 0x0004
112#define ZCL_CLUSTER_ID_GEN_SCENES 0x0005
113#define ZCL_CLUSTER_ID_GEN_ON_OFF 0x0006
114#define ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL 0x0008
115// Lighting Clusters
116#define ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL 0x0300
117
118// Data Types
119#define ZCL_DATATYPE_BOOLEAN 0x10
120#define ZCL_DATATYPE_UINT8 0x20
121#define ZCL_DATATYPE_INT16 0x29
122#define ZCL_DATATYPE_INT24 0x2a
123
124/*******************************/
125/*** Generic Cluster ATTR's ***/
126/*******************************/
127#define ATTRID_ON_OFF 0x0000
128#define ATTRID_LEVEL_CURRENT_LEVEL 0x0000
129
130/*******************************/
131/*** Lighting Cluster ATTR's ***/
132/*******************************/
133#define ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE 0x0000
134#define ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION 0x0001
135
136
137/*******************************/
138/*** Scenes Cluster Commands ***/
139/*******************************/
140#define COMMAND_SCENE_STORE 0x04
141#define COMMAND_SCENE_RECALL 0x05
142
143/*******************************/
144/*** Groups Cluster Commands ***/
145/*******************************/
146#define COMMAND_GROUP_ADD 0x00
147
148/* The 3 MSB's of the 1st command field byte are for command type. */
149#define MT_RPC_CMD_TYPE_MASK 0xE0
150
151/* The 5 LSB's of the 1st command field byte are for the subsystem. */
152#define MT_RPC_SUBSYSTEM_MASK 0x1F
153
154#define MT_RPC_SOF 0xFE
155
156/*******************************/
157/*** Bootloader Commands ***/
158/*******************************/
159#define SB_FORCE_BOOT 0xF8
160#define SB_FORCE_RUN (SB_FORCE_BOOT ^ 0xFF)
161
162typedef enum {
163 MT_RPC_CMD_POLL = 0x00,
164 MT_RPC_CMD_SREQ = 0x20,
165 MT_RPC_CMD_AREQ = 0x40,
166 MT_RPC_CMD_SRSP = 0x60,
167 MT_RPC_CMD_RES4 = 0x80,
168 MT_RPC_CMD_RES5 = 0xA0,
169 MT_RPC_CMD_RES6 = 0xC0,
170 MT_RPC_CMD_RES7 = 0xE0
171} mtRpcCmdType_t;
172
173typedef enum {
174 MT_RPC_SYS_RES0, /* Reserved. */
175 MT_RPC_SYS_SYS,
176 MT_RPC_SYS_MAC,
177 MT_RPC_SYS_NWK,
178 MT_RPC_SYS_AF,
179 MT_RPC_SYS_ZDO,
180 MT_RPC_SYS_SAPI, /* Simple API. */
181 MT_RPC_SYS_UTIL,
182 MT_RPC_SYS_DBG,
183 MT_RPC_SYS_APP,
184 MT_RPC_SYS_OTA,
185 MT_RPC_SYS_ZNP,
186 MT_RPC_SYS_SPARE_12,
187 MT_RPC_SYS_UBL = 13, // 13 to be compatible with existing RemoTI.
188 MT_RPC_SYS_MAX // Maximum value, must be last (so 14-32 available, not yet assigned).
189} mtRpcSysType_t;
190
191/************************************************************
192 * TYPEDEFS
193 */
194
195/*********************************************************************
196 * GLOBAL VARIABLES
197 */
198
199/*********************************************************************
200 * LOCAL VARIABLES
201 */
202int serialPortFd = 0;
203uint8_t transSeqNumber = 0;
204
205zllSocCallbacks_t zllSocCb;
206
207/*********************************************************************
208 * LOCAL FUNCTIONS
209 */
210void calcFcs(uint8_t *msg, int size);
211static void processRpcSysAppTlInd(uint8_t *TlIndBuff);
212static void processRpcSysAppNewDevInd(uint8_t *TlIndBuff);
213static void processRpcSysAppZcl(uint8_t *zclRspBuff);
214static void processRpcSysAppZclFoundation(uint8_t *zclRspBuff, uint8_t zclFrameLen, uint16_t clusterID, uint16_t nwkAddr, uint8_t endpoint);
215static void processRpcSysApp(uint8_t *rpcBuff);
216static void processRpcSysDbg(uint8_t *rpcBuff);
217
218/*********************************************************************
219 * @fn calcFcs
220 *
221 * @brief populates the Frame Check Sequence of the RPC payload.
222 *
223 * @param msg - pointer to the RPC message
224 *
225 * @return none
226 */
227void calcFcs(uint8_t *msg, int size)
228{
229 uint8_t result = 0;
230 int idx = 1; //skip SOF
231 int len = (size - 1); // skip FCS
232
233 while ((len--) != 0) {
234 result ^= msg[idx++];
235 }
236
237 msg[(size-1)] = result;
238}
239
240/*********************************************************************
241 * API FUNCTIONS
242 */
243
244/*********************************************************************
245 * @fn zllSocOpen
246 *
247 * @brief opens the serial port to the CC253x.
248 *
249 * @param devicePath - path to the UART device
250 *
251 * @return status
252 */
253int32_t zllSocOpen( char *devicePath )
254{
255 struct termios tio;
256
257 /* open the device to be non-blocking (read will return immediatly) */
258 serialPortFd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK);
259 if (serialPortFd <0)
260 {
261 perror(devicePath);
262 printf("%s open failed\n",devicePath);
263 return(-1);
264 }
265
266 //make the access exclusive so other instances will return -1 and exit
267 ioctl(serialPortFd, TIOCEXCL);
268
269 /* c-iflags
270 B115200 : set board rate to 115200
271 CRTSCTS : HW flow control (disabled below)
272 CS8 : 8n1 (8bit,no parity,1 stopbit)
273 CLOCAL : local connection, no modem contol
274 CREAD : enable receiving characters*/
275 tio.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD;
276 /* c-iflags
277 ICRNL : maps 0xD (CR) to 0x10 (LR), we do not want this.
278 IGNPAR : ignore bits with parity erros, I guess it is
279 better to ignStateore an erronious bit then interprit it incorrectly. */
280 tio.c_iflag = IGNPAR & ~ICRNL;
281 tio.c_oflag = 0;
282 tio.c_lflag = 0;
283
284 tcflush(serialPortFd, TCIFLUSH);
285 tcsetattr(serialPortFd,TCSANOW,&tio);
286
287 //Send the bootloader force boot incase we have a bootloader that waits
288 uint8_t forceBoot = SB_FORCE_RUN;
289 write(serialPortFd,&forceBoot, 1);
290 tcflush(serialPortFd, TCOFLUSH);
291
292 return serialPortFd;
293}
294
295void zllSocClose( void )
296{
297 tcflush(serialPortFd, TCOFLUSH);
298 close(serialPortFd);
299
300 return;
301}
302
303/*********************************************************************
304 * @fn zllSocRegisterCallbacks
305 *
306 * @brief opens the serial port to the CC253x.
307 *
308 * @param devicePath - path to the UART device
309 *
310 * @return status
311 */
312void zllSocRegisterCallbacks( zllSocCallbacks_t zllSocCallbacks)
313{
314 //copy the callback function pointers
315 memcpy(&zllSocCb, &zllSocCallbacks, sizeof(zllSocCallbacks_t));
316 return;
317}
318
319
320/*********************************************************************
321 * @fn zllSocTouchLink
322 *
323 * @brief Send the touchLink command to the CC253x.
324 *
325 * @param none
326 *
327 * @return none
328 */
329void zllSocTouchLink(void)
330{
331 uint8_t tlCmd[] = {
332 APPCMDHEADER(13)
333 0x06, //Data Len
334 0x02, //Address Mode
335 0x00, //2dummy bytes
336 0x00,
337 ZLL_MT_APP_RPC_CMD_TOUCHLINK,
338 0x00, //
339 0x00, //
340 0x00 //FCS - fill in later
341 };
342
343 calcFcs(tlCmd, sizeof(tlCmd));
344 write(serialPortFd,tlCmd, sizeof(tlCmd));
345 tcflush(serialPortFd, TCOFLUSH);
346}
347
348/*********************************************************************
349 * @fn zllSocResetToFn
350 *
351 * @brief Send the reset to factory new command to the CC253x.
352 *
353 * @param none
354 *
355 * @return none
356 */
357void zllSocResetToFn(void)
358{
359 uint8_t tlCmd[] = {
360 APPCMDHEADER(13)
361 0x06, //Data Len
362 0x02, //Address Mode
363 0x00, //2dummy bytes
364 0x00,
365 ZLL_MT_APP_RPC_CMD_RESET_TO_FN,
366 0x00, //
367 0x00, //
368 0x00 //FCS - fill in later
369 };
370
371 calcFcs(tlCmd, sizeof(tlCmd));
372 write(serialPortFd,tlCmd, sizeof(tlCmd));
373 tcflush(serialPortFd, TCOFLUSH);
374}
375
376/*********************************************************************
377 * @fn zllSocSendResetToFn
378 *
379 * @brief Send the reset to factory new command to a ZLL device.
380 *
381 * @param none
382 *
383 * @return none
384 */
385void zllSocSendResetToFn(void)
386{
387 uint8_t tlCmd[] = {
388 APPCMDHEADER(13)
389 0x06, //Data Len
390 0x02, //Address Mode
391 0x00, //2dummy bytes
392 0x00,
393 ZLL_MT_APP_RPC_CMD_SEND_RESET_TO_FN,
394 0x00, //
395 0x00, //
396 0x00 //FCS - fill in later
397 };
398
399 calcFcs(tlCmd, sizeof(tlCmd));
400 write(serialPortFd,tlCmd, sizeof(tlCmd));
401 tcflush(serialPortFd, TCOFLUSH);
402}
403
404/*********************************************************************
405 * @fn zllSocOpenNwk
406 *
407 * @brief Send the open network command to a ZLL device.
408 *
409 * @param none
410 *
411 * @return none
412 */
413void zllSocOpenNwk(void)
414{
415 uint8_t cmd[] = {
416 APPCMDHEADER(13)
417 0x06, //Data Len
418 0x02, //Address Mode
419 0x00, //2dummy bytes
420 0x00,
421 ZLL_MT_APP_RPC_CMD_PERMIT_JOIN,
422 60, // open for 60s
423 1, // open all devices
424 0x00 //FCS - fill in later
425 };
426
427 calcFcs(cmd, sizeof(cmd));
428 write(serialPortFd,cmd, sizeof(cmd));
429 tcflush(serialPortFd, TCOFLUSH);
430}
431
432/*********************************************************************
433 * @fn zllSocSetState
434 *
435 * @brief Send the on/off command to a ZLL light.
436 *
437 * @param state - 0: Off, 1: On.
438 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
439 * @param endpoint - endpoint of the Light.
440 * @param addrMode - Unicast or Group cast.
441 *
442 * @return none
443 */
444void zllSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
445{
446 uint8_t cmd[] = {
447 0xFE,
448 11, /*RPC payload Len */
449 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
450 0x00, /*MT_APP_MSG */
451 0x0B, /*Application Endpoint */
452 (dstAddr & 0x00ff),
453 (dstAddr & 0xff00) >> 8,
454 endpoint, /*Dst EP */
455 (ZCL_CLUSTER_ID_GEN_ON_OFF & 0x00ff),
456 (ZCL_CLUSTER_ID_GEN_ON_OFF & 0xff00) >> 8,
457 0x04, //Data Len
458 addrMode,
459 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
460 transSeqNumber++,
461 (state ? 1:0),
462 0x00 //FCS - fill in later
463 };
464
465 calcFcs(cmd, sizeof(cmd));
466
467 write(serialPortFd,cmd,sizeof(cmd));
468 tcflush(serialPortFd, TCOFLUSH);
469}
470
471/*********************************************************************
472 * @fn zllSocSetLevel
473 *
474 * @brief Send the level command to a ZLL light.
475 *
476 * @param level - 0-128 = 0-100%
477 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
478 * @param endpoint - endpoint of the Light.
479 * @param addrMode - Unicast or Group cast.
480 *
481 * @return none
482 */
483void zllSocSetLevel(uint8_t level, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
484{
485 uint8_t cmd[] = {
486 0xFE,
487 14, //RPC payload Len
488 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP
489 0x00, //MT_APP_MSG
490 0x0B, //Application Endpoint
491 (dstAddr & 0x00ff),
492 (dstAddr & 0xff00) >> 8,
493 endpoint, //Dst EP
494 (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0x00ff),
495 (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0xff00) >> 8,
496 0x07, //Data Len
497 addrMode,
498 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
499 transSeqNumber++,
500 COMMAND_LEVEL_MOVE_TO_LEVEL,
501 (level & 0xff),
502 (time & 0xff),
503 (time & 0xff00) >> 8,
504 0x00 //FCS - fill in later
505 };
506
507 calcFcs(cmd, sizeof(cmd));
508
509 write(serialPortFd,cmd,sizeof(cmd));
510 tcflush(serialPortFd, TCOFLUSH);
511}
512
513/*********************************************************************
514 * @fn zllSocSetHue
515 *
516 * @brief Send the hue command to a ZLL light.
517 *
518 * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green
519 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
520 * @param endpoint - endpoint of the Light.
521 * @param addrMode - Unicast or Group cast.
522 *
523 * @return none
524 */
525void zllSocSetHue(uint8_t hue, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
526{
527 uint8_t cmd[] = {
528 0xFE,
529 15, //RPC payload Len
530 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP
531 0x00, //MT_APP_MSG
532 0x0B, //Application Endpoint
533 (dstAddr & 0x00ff),
534 (dstAddr & 0xff00) >> 8,
535 endpoint, //Dst EP
536 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff),
537 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8,
538 0x08, //Data Len
539 addrMode,
540 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
541 transSeqNumber++,
542 COMMAND_LIGHTING_MOVE_TO_HUE,
543 (hue & 0xff),
544 0x00, //Move with shortest distance
545 (time & 0xff),
546 (time & 0xff00) >> 8,
547 0x00 //FCS - fill in later
548 };
549
550 calcFcs(cmd, sizeof(cmd));
551 write(serialPortFd,cmd,sizeof(cmd));
552 tcflush(serialPortFd, TCOFLUSH);
553}
554
555/*********************************************************************
556 * @fn zllSocSetSat
557 *
558 * @brief Send the satuartion command to a ZLL light.
559 *
560 * @param sat - 0-128 : 0=white, 128: fully saturated color
561 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
562 * @param endpoint - endpoint of the Light.
563 * @param addrMode - Unicast or Group cast.
564 *
565 * @return none
566 */
567void zllSocSetSat(uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
568{
569 uint8_t cmd[] = {
570 0xFE,
571 14, //RPC payload Len
572 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP
573 0x00, //MT_APP_MSG
574 0x0B, //Application Endpoint
575 (dstAddr & 0x00ff),
576 (dstAddr & 0xff00) >> 8,
577 endpoint, //Dst EP
578 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff),
579 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8,
580 0x07, //Data Len
581 addrMode,
582 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
583 transSeqNumber++,
584 COMMAND_LIGHTING_MOVE_TO_SATURATION,
585 (sat & 0xff),
586 (time & 0xff),
587 (time & 0xff00) >> 8,
588 0x00 //FCS - fill in later
589 };
590
591 calcFcs(cmd, sizeof(cmd));
592 write(serialPortFd,cmd,sizeof(cmd));
593 tcflush(serialPortFd, TCOFLUSH);
594}
595
596/*********************************************************************
597 * @fn zllSocSetHueSat
598 *
599 * @brief Send the hue and satuartion command to a ZLL light.
600 *
601 * @param hue - 0-128 represent the 360Deg hue color wheel : 0=red, 42=blue, 85=green
602 * @param sat - 0-128 : 0=white, 128: fully saturated color
603 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
604 * @param endpoint - endpoint of the Light.
605 * @param addrMode - Unicast or Group cast.
606 *
607 * @return none
608 */
609void zllSocSetHueSat(uint8_t hue, uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
610{
611 uint8_t cmd[] = {
612 0xFE,
613 15, //RPC payload Len
614 0x29, //MT_RPC_CMD_AREQ + MT_RPC_SYS_APP
615 0x00, //MT_APP_MSG
616 0x0B, //Application Endpoint
617 (dstAddr & 0x00ff),
618 (dstAddr & 0xff00) >> 8,
619 endpoint, //Dst EP
620 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff),
621 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8,
622 0x08, //Data Len
623 addrMode,
624 0x01, //ZCL Header Frame Control
625 transSeqNumber++,
626 0x06, //ZCL Header Frame Command (COMMAND_LEVEL_MOVE_TO_HUE_AND_SAT)
627 hue, //HUE - fill it in later
628 sat, //SAT - fill it in later
629 (time & 0xff),
630 (time & 0xff00) >> 8,
631 0x00 //fcs
632 };
633
634 calcFcs(cmd, sizeof(cmd));
635 write(serialPortFd,cmd,sizeof(cmd));
636 tcflush(serialPortFd, TCOFLUSH);
637}
638
639/*********************************************************************
640 * @fn zllSocAddGroup
641 *
642 * @brief Add Group.
643 *
644 * @param groupId - Group ID of the Scene.
645 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
646 * @param endpoint - endpoint of the Light.
647 * @param addrMode - Unicast or Group cast.
648 *
649 * @return none
650 */
651void zllSocAddGroup(uint16_t groupId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
652{
653 uint8_t cmd[] = {
654 0xFE,
655 14, /*RPC payload Len */
656 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
657 0x00, /*MT_APP_MSG */
658 0x0B, /*Application Endpoint */
659 (dstAddr & 0x00ff),
660 (dstAddr & 0xff00) >> 8,
661 endpoint, /*Dst EP */
662 (ZCL_CLUSTER_ID_GEN_GROUPS & 0x00ff),
663 (ZCL_CLUSTER_ID_GEN_GROUPS & 0xff00) >> 8,
664 0x07, //Data Len
665 addrMode,
666 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
667 transSeqNumber++,
668 COMMAND_GROUP_ADD,
669 (groupId & 0x00ff),
670 (groupId & 0xff00) >> 8,
671 0, //Null group name - Group Name not pushed to the devices
672 0x00 //FCS - fill in later
673 };
674
675 printf("zllSocAddGroup: dstAddr 0x%x\n", dstAddr);
676
677 calcFcs(cmd, sizeof(cmd));
678
679 write(serialPortFd,cmd,sizeof(cmd));
680 tcflush(serialPortFd, TCOFLUSH);
681}
682
683/*********************************************************************
684 * @fn zllSocStoreScene
685 *
686 * @brief Store Scene.
687 *
688 * @param groupId - Group ID of the Scene.
689 * @param sceneId - Scene ID of the Scene.
690 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
691 * @param endpoint - endpoint of the Light.
692 * @param addrMode - Unicast or Group cast.
693 *
694 * @return none
695 */
696void zllSocStoreScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
697{
698 uint8_t cmd[] = {
699 0xFE,
700 14, /*RPC payload Len */
701 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
702 0x00, /*MT_APP_MSG */
703 0x0B, /*Application Endpoint */
704 (dstAddr & 0x00ff),
705 (dstAddr & 0xff00) >> 8,
706 endpoint, /*Dst EP */
707 (ZCL_CLUSTER_ID_GEN_SCENES & 0x00ff),
708 (ZCL_CLUSTER_ID_GEN_SCENES & 0xff00) >> 8,
709 0x07, //Data Len
710 addrMode,
711 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
712 transSeqNumber++,
713 COMMAND_SCENE_STORE,
714 (groupId & 0x00ff),
715 (groupId & 0xff00) >> 8,
716 sceneId++,
717 0x00 //FCS - fill in later
718 };
719
720 calcFcs(cmd, sizeof(cmd));
721
722 write(serialPortFd,cmd,sizeof(cmd));
723 tcflush(serialPortFd, TCOFLUSH);
724}
725
726/*********************************************************************
727 * @fn zllSocRecallScene
728 *
729 * @brief Recall Scene.
730 *
731 * @param groupId - Group ID of the Scene.
732 * @param sceneId - Scene ID of the Scene.
733 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be controled.
734 * @param endpoint - endpoint of the Light.
735 * @param addrMode - Unicast or Group cast.
736
737 * @return none
738 */
739void zllSocRecallScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
740{
741 uint8_t cmd[] = {
742 0xFE,
743 14, /*RPC payload Len */
744 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
745 0x00, /*MT_APP_MSG */
746 0x0B, /*Application Endpoint */
747 (dstAddr & 0x00ff),
748 (dstAddr & 0xff00) >> 8,
749 endpoint, /*Dst EP */
750 (ZCL_CLUSTER_ID_GEN_SCENES & 0x00ff),
751 (ZCL_CLUSTER_ID_GEN_SCENES & 0xff00) >> 8,
752 0x07, //Data Len
753 addrMode,
754 0x01, //0x01 ZCL frame control field. (send to the light cluster only)
755 transSeqNumber++,
756 COMMAND_SCENE_RECALL,
757 (groupId & 0x00ff),
758 (groupId & 0xff00) >> 8,
759 sceneId++,
760 0x00 //FCS - fill in later
761 };
762
763 calcFcs(cmd, sizeof(cmd));
764
765 write(serialPortFd,cmd,sizeof(cmd));
766 tcflush(serialPortFd, TCOFLUSH);
767}
768
769/*********************************************************************
770 * @fn zllSocBind
771 *
772 * @brief Recall Scene.
773 *
774 * @param
775 *
776 * @return none
777 */
778void zllSocBind(uint16_t srcNwkAddr, uint8_t srcEndpoint, uint8_t srcIEEE[8], uint8_t dstEndpoint, uint8_t dstIEEE[8], uint16_t clusterID )
779{
780 uint8_t cmd[] = {
781 0xFE,
782 23, /*RPC payload Len */
783 0x25, /*MT_RPC_CMD_SREQ + MT_RPC_SYS_ZDO */
784 0x21, /*MT_ZDO_BIND_REQ*/
785 (srcNwkAddr & 0x00ff), /*Src Nwk Addr - To send the bind message to*/
786 (srcNwkAddr & 0xff00) >> 8, /*Src Nwk Addr - To send the bind message to*/
787 srcIEEE[0], /*Src IEEE Addr for the binding*/
788 srcIEEE[1], /*Src IEEE Addr for the binding*/
789 srcIEEE[2], /*Src IEEE Addr for the binding*/
790 srcIEEE[3], /*Src IEEE Addr for the binding*/
791 srcIEEE[4], /*Src IEEE Addr for the binding*/
792 srcIEEE[5], /*Src IEEE Addr for the binding*/
793 srcIEEE[6], /*Src IEEE Addr for the binding*/
794 srcIEEE[7], /*Src IEEE Addr for the binding*/
795 srcEndpoint, /*Src endpoint for the binding*/
796 (clusterID & 0x00ff), /*cluster ID to bind*/
797 (clusterID & 0xff00) >> 8, /*cluster ID to bind*/
798 afAddr64Bit, /*Addr mode of the dst to bind*/
799 dstIEEE[0], /*Dst IEEE Addr for the binding*/
800 dstIEEE[1], /*Dst IEEE Addr for the binding*/
801 dstIEEE[2], /*Dst IEEE Addr for the binding*/
802 dstIEEE[3], /*Dst IEEE Addr for the binding*/
803 dstIEEE[4], /*Dst IEEE Addr for the binding*/
804 dstIEEE[5], /*Dst IEEE Addr for the binding*/
805 dstIEEE[6], /*Dst IEEE Addr for the binding*/
806 dstIEEE[7], /*Dst IEEE Addr for the binding*/
807 dstEndpoint, /*Dst endpoint for the binding*/
808 0x00 //FCS - fill in later
809 };
810
811 calcFcs(cmd, sizeof(cmd));
812
813 /*printf("zllSocBind: srcNwkAddr=0x%x, srcEndpoint=0x%x, srcIEEE=0x%x:%x:%x:%x:%x:%x:%x:%x, dstEndpoint=0x%x, dstIEEE=0x%x:%x:%x:%x:%x:%x:%x:%x, clusterID:%x\n",
814 srcNwkAddr, srcEndpoint, srcIEEE[0], srcIEEE[1], srcIEEE[2], srcIEEE[3], srcIEEE[4], srcIEEE[5], srcIEEE[6], srcIEEE[7],
815 srcEndpoint, dstIEEE[0], dstIEEE[1], dstIEEE[2], dstIEEE[3], dstIEEE[4], dstIEEE[5], dstIEEE[6], dstIEEE[7], clusterID);*/
816
817 write(serialPortFd,cmd,sizeof(cmd));
818 tcflush(serialPortFd, TCOFLUSH);
819}
820
821/*********************************************************************
822 * @fn zllSocGetState
823 *
824 * @brief Send the get state command to a ZLL light.
825 *
826 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
827 * @param endpoint - endpoint of the Light.
828 * @param addrMode - Unicast or Group cast.
829 *
830 * @return none
831 */
832void zllSocGetState(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
833{
834 uint8_t cmd[] = {
835 0xFE,
836 13, /*RPC payload Len */
837 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
838 0x00, /*MT_APP_MSG */
839 0x0B, /*Application Endpoint */
840 (dstAddr & 0x00ff),
841 (dstAddr & 0xff00) >> 8,
842 endpoint, /*Dst EP */
843 (ZCL_CLUSTER_ID_GEN_ON_OFF & 0x00ff),
844 (ZCL_CLUSTER_ID_GEN_ON_OFF & 0xff00) >> 8,
845 0x06, //Data Len
846 addrMode,
847 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command)
848 transSeqNumber++,
849 ZCL_CMD_READ,
850 (ATTRID_ON_OFF & 0x00ff),
851 (ATTRID_ON_OFF & 0xff00) >> 8,
852 0x00 //FCS - fill in later
853 };
854
855 calcFcs(cmd, sizeof(cmd));
856
857 write(serialPortFd,cmd,sizeof(cmd));
858 tcflush(serialPortFd, TCOFLUSH);
859}
860
861/*********************************************************************
862 * @fn zllSocGetLevel
863 *
864 * @brief Send the get level command to a ZLL light.
865 *
866 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
867 * @param endpoint - endpoint of the Light.
868 * @param addrMode - Unicast or Group cast.
869 *
870 * @return none
871 */
872void zllSocGetLevel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
873{
874 uint8_t cmd[] = {
875 0xFE,
876 13, /*RPC payload Len */
877 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
878 0x00, /*MT_APP_MSG */
879 0x0B, /*Application Endpoint */
880 (dstAddr & 0x00ff),
881 (dstAddr & 0xff00) >> 8,
882 endpoint, /*Dst EP */
883 (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0x00ff),
884 (ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL & 0xff00) >> 8,
885 0x06, //Data Len
886 addrMode,
887 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command)
888 transSeqNumber++,
889 ZCL_CMD_READ,
890 (ATTRID_LEVEL_CURRENT_LEVEL & 0x00ff),
891 (ATTRID_LEVEL_CURRENT_LEVEL & 0xff00) >> 8,
892 0x00 //FCS - fill in later
893 };
894
895 calcFcs(cmd, sizeof(cmd));
896
897 write(serialPortFd,cmd,sizeof(cmd));
898 tcflush(serialPortFd, TCOFLUSH);
899}
900
901/*********************************************************************
902 * @fn zllSocGetHue
903 *
904 * @brief Send the get hue command to a ZLL light.
905 *
906 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
907 * @param endpoint - endpoint of the Light.
908 * @param addrMode - Unicast or Group cast.
909 *
910 * @return none
911 */
912void zllSocGetHue(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
913{
914 uint8_t cmd[] = {
915 0xFE,
916 13, /*RPC payload Len */
917 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
918 0x00, /*MT_APP_MSG */
919 0x0B, /*Application Endpoint */
920 (dstAddr & 0x00ff),
921 (dstAddr & 0xff00) >> 8,
922 endpoint, /*Dst EP */
923 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff),
924 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8,
925 0x06, //Data Len
926 addrMode,
927 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command)
928 transSeqNumber++,
929 ZCL_CMD_READ,
930 (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE & 0x00ff),
931 (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE & 0xff00) >> 8,
932 0x00 //FCS - fill in later
933 };
934
935 calcFcs(cmd, sizeof(cmd));
936
937 write(serialPortFd,cmd,sizeof(cmd));
938 tcflush(serialPortFd, TCOFLUSH);
939}
940
941/*********************************************************************
942 * @fn zllSocGetSat
943 *
944 * @brief Send the get saturation command to a ZLL light.
945 *
946 * @param dstAddr - Nwk Addr or Group ID of the Light(s) to be sent the command.
947 * @param endpoint - endpoint of the Light.
948 * @param addrMode - Unicast or Group cast.
949 *
950 * @return none
951 */
952void zllSocGetSat(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode)
953{
954 uint8_t cmd[] = {
955 0xFE,
956 13, /*RPC payload Len */
957 0x29, /*MT_RPC_CMD_AREQ + MT_RPC_SYS_APP */
958 0x00, /*MT_APP_MSG */
959 0x0B, /*Application Endpoint */
960 (dstAddr & 0x00ff),
961 (dstAddr & 0xff00) >> 8,
962 endpoint, /*Dst EP */
963 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0x00ff),
964 (ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL & 0xff00) >> 8,
965 0x06, //Data Len
966 addrMode,
967 0x00, //0x00 ZCL frame control field. not specific to a cluster (i.e. a SCL founadation command)
968 transSeqNumber++,
969 ZCL_CMD_READ,
970 (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION & 0x00ff),
971 (ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION & 0xff00) >> 8,
972 0x00 //FCS - fill in later
973 };
974
975 calcFcs(cmd, sizeof(cmd));
976
977 write(serialPortFd,cmd,sizeof(cmd));
978 tcflush(serialPortFd, TCOFLUSH);
979}
980
981/*************************************************************************************************
982 * @fn processRpcSysAppTlInd()
983 *
984 * @brief process the TL Indication from the ZLL controller
985 *
986 * @param none
987 *
988 * @return length of current Rx Buffer
989 *************************************************************************************************/
990static void processRpcSysAppTlInd(uint8_t *TlIndBuff)
991{
992 epInfo_t epInfo;
993
994 epInfo.nwkAddr = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
995 TlIndBuff+=2;
996 epInfo.endpoint = *TlIndBuff++;
997 epInfo.profileID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
998 TlIndBuff+=2;
999 epInfo.deviceID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
1000 TlIndBuff+=2;
1001 epInfo.version = *TlIndBuff++;
1002 epInfo.status = *TlIndBuff++;
1003
1004 if(zllSocCb.pfnTlIndicationCb)
1005 {
1006 zllSocCb.pfnTlIndicationCb(&epInfo);
1007 }
1008}
1009
1010/*************************************************************************************************
1011 * @fn processRpcSysAppNewDevInd()
1012 *
1013 * @brief process the New Device Indication from the ZLL controller
1014 *
1015 * @param none
1016 *
1017 * @return length of current Rx Buffer
1018 *************************************************************************************************/
1019static void processRpcSysAppNewDevInd(uint8_t *TlIndBuff)
1020{
1021 epInfo_t epInfo = {0};
1022 uint8_t i;
1023
1024 epInfo.status = 0;
1025
1026 epInfo.nwkAddr = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
1027 TlIndBuff+=2;
1028 epInfo.endpoint = *TlIndBuff++;
1029 epInfo.profileID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
1030 TlIndBuff+=2;
1031 epInfo.deviceID = BUILD_UINT16(TlIndBuff[0], TlIndBuff[1]);
1032 TlIndBuff+=2;
1033 epInfo.version = *TlIndBuff++;
1034
1035 for(i=0; i<8; i++)
1036 {
1037 epInfo.IEEEAddr[i] = *TlIndBuff++;
1038 }
1039
1040 //printf("processRpcSysAppNewDevInd: %x:%x\n", epInfo.nwkAddr, epInfo.endpoint);
1041 if(zllSocCb.pfnNewDevIndicationCb)
1042 {
1043 zllSocCb.pfnNewDevIndicationCb(&epInfo);
1044 }
1045}
1046
1047/*************************************************************************************************
1048 * @fn processRpcSysAppZcl()
1049 *
1050 * @brief process the ZCL Rsp from the ZLL controller
1051 *
1052 * @param none
1053 *
1054 * @return length of current Rx Buffer
1055 *************************************************************************************************/
1056static void processRpcSysAppZcl(uint8_t *zclRspBuff)
1057{
1058 uint8_t zclHdrLen = 3;
1059 uint16_t nwkAddr, clusterID;
1060 uint8_t endpoint, appEP, zclFrameLen, zclFrameFrameControl;
1061
1062 //printf("processRpcSysAppZcl++\n");
1063
1064 //This is a ZCL response
1065 appEP = *zclRspBuff++;
1066 nwkAddr = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]);
1067 zclRspBuff+=2;
1068
1069 endpoint = *zclRspBuff++;
1070 clusterID = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]);
1071 zclRspBuff+=2;
1072
1073 zclFrameLen = *zclRspBuff++;
1074 zclFrameFrameControl = *zclRspBuff++;
1075 //is it manufacturer specific
1076 if ( zclFrameFrameControl & (1 <<2) )
1077 {
1078 //currently not supported shown for reference
1079 uint16_t ManSpecCode;
1080 //manu spec code
1081 ManSpecCode = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]);
1082 zclRspBuff+=2;
1083 //Manufacturer specif commands have 2 extra byte in te header
1084 zclHdrLen+=2;
1085 }
1086
1087 //is this a foundation command
1088 if( (zclFrameFrameControl & 0x3) == 0)
1089 {
1090 //printf("processRpcSysAppZcl: Foundation messagex\n");
1091 processRpcSysAppZclFoundation(zclRspBuff, zclFrameLen, clusterID, nwkAddr, endpoint);
1092 }
1093}
1094
1095/*************************************************************************************************
1096 * @fn processRpcSysAppZclFoundation()
1097 *
1098 * @brief process the ZCL Rsp from the ZLL controller
1099 *
1100 * @param none
1101 *
1102 * @return length of current Rx Buffer
1103 *************************************************************************************************/
1104static void processRpcSysAppZclFoundation(uint8_t *zclRspBuff, uint8_t zclFrameLen, uint16_t clusterID, uint16_t nwkAddr, uint8_t endpoint)
1105{
1106 uint8_t transSeqNum, commandID;
1107
1108 transSeqNum = *zclRspBuff++;
1109 commandID = *zclRspBuff++;
1110
1111 if(commandID == ZCL_CMD_READ_RSP)
1112 {
1113 uint16_t attrID;
1114 uint8_t status;
1115 uint8_t dataType;
1116
1117 attrID = BUILD_UINT16(zclRspBuff[0], zclRspBuff[1]);
1118 zclRspBuff+=2;
1119 status = *zclRspBuff++;
1120 //get data type;
1121 dataType = *zclRspBuff++;
1122
1123
1124 //printf("processRpcSysAppZclFoundation: clusterID:%x, attrID:%x, dataType=%x\n", clusterID, attrID, dataType);
1125
1126 if( (clusterID == ZCL_CLUSTER_ID_GEN_ON_OFF) && (attrID == ATTRID_ON_OFF) && (dataType == ZCL_DATATYPE_BOOLEAN) )
1127 {
1128 if(zllSocCb.pfnZclGetStateCb)
1129 {
1130 uint8_t state = zclRspBuff[0];
1131 zllSocCb.pfnZclGetStateCb(state, nwkAddr, endpoint);
1132 }
1133 }
1134 else if( (clusterID == ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL) && (attrID == ATTRID_LEVEL_CURRENT_LEVEL) && (dataType == ZCL_DATATYPE_UINT8) )
1135 {
1136 if(zllSocCb.pfnZclGetLevelCb)
1137 {
1138 uint8_t level = zclRspBuff[0];
1139 zllSocCb.pfnZclGetLevelCb(level, nwkAddr, endpoint);
1140 }
1141 }
1142 else if( (clusterID == ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL) && (attrID == ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_HUE) && (dataType == ZCL_DATATYPE_UINT8) )
1143 {
1144 if(zllSocCb.pfnZclGetHueCb)
1145 {
1146 uint8_t hue = zclRspBuff[0];
1147 zllSocCb.pfnZclGetHueCb(hue, nwkAddr, endpoint);
1148 }
1149 }
1150 else if( (clusterID == ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL) && (attrID == ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_SATURATION) && (dataType == ZCL_DATATYPE_UINT8) )
1151 {
1152 if(zllSocCb.pfnZclGetSatCb)
1153 {
1154 uint8_t sat = zclRspBuff[0];
1155 zllSocCb.pfnZclGetSatCb(sat, nwkAddr, endpoint);
1156 }
1157 }
1158 else
1159 {
1160 //unsupported ZCL Read Rsp
1161 printf("processRpcSysAppZclFoundation: Unsupported ZCL Rsp\n");
1162 }
1163 }
1164 else
1165 {
1166 //unsupported ZCL Rsp
1167 printf("processRpcSysAppZclFoundation: Unsupported ZCL Rsp");;
1168 }
1169
1170 return;
1171}
1172
1173/*************************************************************************************************
1174 * @fn processRpcSysApp()
1175 *
1176 * @brief read and process the RPC App message from the ZLL controller
1177 *
1178 * @param none
1179 *
1180 * @return length of current Rx Buffer
1181 *************************************************************************************************/
1182static void processRpcSysApp(uint8_t *rpcBuff)
1183{
1184 if( rpcBuff[1] == MT_APP_ZLL_TL_IND )
1185 {
1186 processRpcSysAppTlInd(&rpcBuff[2]);
1187 }
1188 else if( rpcBuff[1] == MT_APP_ZLL_NEW_DEV_IND )
1189 {
1190 processRpcSysAppNewDevInd(&rpcBuff[2]);
1191 }
1192 else if( rpcBuff[1] == MT_APP_RSP )
1193 {
1194 processRpcSysAppZcl(&rpcBuff[2]);
1195 }
1196 else if( rpcBuff[1] == 0 )
1197 {
1198 if( rpcBuff[2] == 0)
1199 {
1200 //printf("processRpcSysApp: Command Received Successfully\n\n");
1201 }
1202 else
1203 {
1204 printf("processRpcSysApp: Command Error\n\n");
1205 }
1206 }
1207 else
1208 {
1209 printf("processRpcSysApp: Unsupported MT App Msg\n");
1210 }
1211
1212 return;
1213}
1214
1215/*************************************************************************************************
1216 * @fn processRpcSysDbg()
1217 *
1218 * @brief read and process the RPC debug message from the ZLL controller
1219 *
1220 * @param none
1221 *
1222 * @return length of current Rx Buffer
1223 *************************************************************************************************/
1224static void processRpcSysDbg(uint8_t *rpcBuff)
1225{
1226 if( rpcBuff[1] == MT_DEBUG_MSG )
1227 {
1228 //we got a debug string
1229 printf("lcd_debug message from zll controller: %s\n", (char*) &(rpcBuff[2]));
1230 }
1231 else if( rpcBuff[1] == 0 )
1232 {
1233 if( rpcBuff[2] == 0)
1234 {
1235 //printf("processRpcSysDbg: Command Received Successfully\n\n");
1236 }
1237 else
1238 {
1239 printf("processRpcSysDbg: Command Error\n\n");
1240 }
1241 }
1242 else
1243 {
1244 printf("processRpcSysDbg: Unsupported MT App Msg\n");
1245 }
1246}
1247
1248/*************************************************************************************************
1249 * @fn zllSocProcessRpc()
1250 *
1251 * @brief read and process the RPC from the ZLL controller
1252 *
1253 * @param none
1254 *
1255 * @return length of current Rx Buffer
1256 *************************************************************************************************/
1257void zllSocProcessRpc (void)
1258{
1259 uint8_t rpcLen, bytesRead, sofByte, *rpcBuff, rpcBuffIdx;
1260 static uint8_t retryAttempts = 0;
1261
1262 //read first byte and check it is a SOF
1263 read(serialPortFd, &sofByte, 1);
1264 if ( sofByte == MT_RPC_SOF )
1265 {
1266 retryAttempts = 0;
1267
1268 //read len
1269 bytesRead = read(serialPortFd, &rpcLen, 1);
1270
1271 if( bytesRead == 1)
1272 {
1273 //allocating RPC payload (+ cmd0, cmd1 and fcs)
1274 rpcLen += 3;
1275
1276 rpcBuff = malloc(rpcLen);
1277
1278 //non blocking read, so we need to wait for the rpc to be read
1279 rpcBuffIdx = 0;
1280 while(rpcLen > 0)
1281 {
1282 //read rpc
1283 bytesRead = read(serialPortFd, &(rpcBuff[rpcBuffIdx]), rpcLen);
1284
1285 //check for error
1286 if( bytesRead > rpcLen)
1287 {
1288 //there was an error
1289 printf("zllSocProcessRpc: read of %d bytes failed - %s\n", rpcLen, strerror(errno) );
1290
1291 if( retryAttempts++ < 5 )
1292 {
1293 //sleep for 10ms
1294 usleep(10000);
1295 //try again
1296 bytesRead = 0;
1297 }
1298 else
1299 {
1300 //something went wrong.
1301 printf("zllSocProcessRpc: failed\n");
1302 return;
1303 }
1304 }
1305
1306 rpcLen -= bytesRead;
1307 rpcBuffIdx += bytesRead;
1308 }
1309
1310 //printf("zllSocProcessRpc: Processing CMD0:%x, CMD1:%x\n", rpcBuff[0], rpcBuff[1] );
1311 //Read CMD0
1312 switch (rpcBuff[0] & MT_RPC_SUBSYSTEM_MASK)
1313 {
1314 case MT_RPC_SYS_DBG:
1315 {
1316 processRpcSysDbg(rpcBuff);
1317 break;
1318 }
1319 case MT_RPC_SYS_APP:
1320 {
1321 processRpcSysApp(rpcBuff);
1322 break;
1323 }
1324 default:
1325 {
1326 printf("zllSocProcessRpc: CMD0:%x, CMD1:%x, not handled\n", rpcBuff[0], rpcBuff[1] );
1327 break;
1328 }
1329 }
1330
1331 free(rpcBuff);
1332 }
1333 else
1334 {
1335 printf("zllSocProcessRpc: No valid Start Of Frame found\n");
1336 }
1337 }
1338
1339 return;
1340}
1341
diff --git a/server/Source/zllSocCmd.h b/server/Source/zllSocCmd.h
deleted file mode 100644
index e9e0b82..0000000
--- a/server/Source/zllSocCmd.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * zllSocCmd.h
3 *
4 * This module contains the API for the zll SoC Host Interface.
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39#ifndef ZLLSOCCMD_H
40#define ZLLSOCCMD_H
41
42#ifdef __cplusplus
43extern "C"
44{
45#endif
46
47#include <stdint.h>
48
49/********************************************************************/
50// ZLL Soc Types
51
52// Endpoint information record entry
53typedef struct
54{
55 uint8_t IEEEAddr[8];
56 uint16_t nwkAddr; // Network address
57 uint8_t endpoint; // Endpoint identifier
58 uint16_t profileID; // Profile identifier
59 uint16_t deviceID; // Device identifier
60 uint8_t version; // Version
61 char* deviceName;
62 uint8_t status;
63} epInfo_t;
64
65typedef uint8_t (*zllSocTlIndicationCb_t)(epInfo_t *epInfo);
66typedef uint8_t (*zllNewDevIndicationCb_t)(epInfo_t *epInfo);
67typedef uint8_t (*zllSocZclGetStateCb_t)(uint8_t state, uint16_t nwkAddr, uint8_t endpoint);
68typedef uint8_t (*zllSocZclGetLevelCb_t)(uint8_t level, uint16_t nwkAddr, uint8_t endpoint);
69typedef uint8_t (*zllSocZclGetHueCb_t)(uint8_t hue, uint16_t nwkAddr, uint8_t endpoint);
70typedef uint8_t (*zllSocZclGetSatCb_t)(uint8_t sat, uint16_t nwkAddr, uint8_t endpoint);
71
72typedef struct
73{
74 zllSocTlIndicationCb_t pfnTlIndicationCb; // TouchLink Indication callback
75 zllNewDevIndicationCb_t pfnNewDevIndicationCb; // New device Indication callback
76 zllSocZclGetStateCb_t pfnZclGetStateCb; // ZCL response callback for get State
77 zllSocZclGetLevelCb_t pfnZclGetLevelCb; // ZCL response callback for get Level
78 zllSocZclGetHueCb_t pfnZclGetHueCb; // ZCL response callback for get Hue
79 zllSocZclGetSatCb_t pfnZclGetSatCb; // ZCL response callback for get Sat
80} zllSocCallbacks_t;
81
82#define Z_EXTADDR_LEN 8
83
84typedef enum
85{
86 afAddrNotPresent = 0,
87 afAddrGroup = 1,
88 afAddr16Bit = 2,
89 afAddr64Bit = 3,
90 afAddrBroadcast = 15
91} afAddrMode_t;
92
93/********************************************************************/
94// ZLL Soc API
95
96//configuration API's
97int32_t zllSocOpen( char *devicePath );
98void zllSocRegisterCallbacks( zllSocCallbacks_t zllSocCallbacks);
99void zllSocClose( void );
100void zllSocProcessRpc (void);
101
102//ZLL API's
103void zllSocTouchLink(void);
104void zllSocResetToFn(void);
105void zllSocSendResetToFn(void);
106void zllSocOpenNwk(void);
107//ZCL Set API's
108void zllSocSetState(uint8_t state, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
109void zllSocSetLevel(uint8_t level, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
110void zllSocSetHue(uint8_t hue, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
111void zllSocSetSat(uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
112void zllSocSetHueSat(uint8_t hue, uint8_t sat, uint16_t time, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
113void zllSocAddGroup(uint16_t groupId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
114void zllSocStoreScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
115void zllSocRecallScene(uint16_t groupId, uint8_t sceneId, uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
116void zllSocBind(uint16_t srcNwkAddr, uint8_t srcEndpoint, uint8_t srcIEEE[8], uint8_t dstEndpoint, uint8_t dstIEEE[8], uint16_t clusterID);
117//ZCL Get API's
118void zllSocGetState(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
119void zllSocGetLevel(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
120void zllSocGetHue(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
121void zllSocGetSat(uint16_t dstAddr, uint8_t endpoint, uint8_t addrMode);
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* ZLLSOCCMD_H */
diff --git a/server/Source/zll_controller.c b/server/Source/zll_controller.c
deleted file mode 100644
index b2eef91..0000000
--- a/server/Source/zll_controller.c
+++ /dev/null
@@ -1,202 +0,0 @@
1/**************************************************************************************************
2 * Filename: zll_controller.c
3 * Description: This file contains the interface to the UART.
4 *
5 *
6 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39#include <string.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <poll.h>
43
44#include "zllSocCmd.h"
45#include "interface_devicelist.h"
46#include "interface_grouplist.h"
47#include "interface_scenelist.h"
48
49uint8_t pfnTlIndicationCb(epInfo_t *epInfo);
50uint8_t pfnNewDevIndicationCb(epInfo_t *epInfo);
51uint8_t zclGetStateCb(uint8_t state, uint16_t nwkAddr, uint8_t endpoint);
52uint8_t zclGetLevelCb(uint8_t level, uint16_t nwkAddr, uint8_t endpoint);
53uint8_t zclGetHueCb(uint8_t hue, uint16_t nwkAddr, uint8_t endpoint);
54uint8_t zclGetSatCb(uint8_t sat, uint16_t nwkAddr, uint8_t endpoint);
55
56static zllSocCallbacks_t zllSocCbs =
57{
58 pfnTlIndicationCb, // pfnTlIndicationCb - TouchLink Indication callback
59 pfnNewDevIndicationCb, // pfnNewDevIndicationCb - New Device Indication callback
60 zclGetStateCb, //pfnZclGetStateCb - ZCL response callback for get State
61 zclGetLevelCb, //pfnZclGetLevelCb_t - ZCL response callback for get Level
62 zclGetHueCb, // pfnZclGetHueCb - ZCL response callback for get Hue
63 zclGetSatCb, //pfnZclGetSatCb - ZCL response callback for get Sat
64};
65
66#include "interface_srpcserver.h"
67#include "socket_server.h"
68
69void usage( char* exeName )
70{
71 printf("Usage: ./%s <port>\n", exeName);
72 printf("Eample: ./%s /dev/ttyACM0\n", exeName);
73}
74
75int main(int argc, char* argv[])
76{
77 int retval = 0;
78 int zllSoc_fd;
79
80 printf("%s -- %s %s\n", argv[0], __DATE__, __TIME__ );
81
82 // accept only 1
83 if( argc != 2 )
84 {
85 usage(argv[0]);
86 printf("attempting to use /dev/ttyACM0\n");
87 zllSoc_fd = zllSocOpen( "/dev/ttyACM0" );
88 }
89 else
90 {
91 zllSoc_fd = zllSocOpen( argv[1] );
92 }
93
94 if( zllSoc_fd == -1 )
95 {
96 exit(-1);
97 }
98
99 //printf("zllMain: restoring device, group and scene lists\n");
100 devListRestorDevices();
101 groupListRestorGroups();
102 sceneListRestorScenes();
103
104 zllSocRegisterCallbacks( zllSocCbs );
105 SRPC_Init();
106
107 while(1)
108 {
109 int numClientFds = socketSeverGetNumClients();
110
111 //poll on client socket fd's and the ZllSoC serial port for any activity
112 if(numClientFds)
113 {
114 int pollFdIdx;
115 int *client_fds = malloc( numClientFds * sizeof( int ) );
116 //socket client FD's + zllSoC serial port FD
117 struct pollfd *pollFds = malloc( ((numClientFds + 1) * sizeof( struct pollfd )) );
118
119 if(client_fds && pollFds)
120 {
121 //set the zllSoC serial port FD in the poll file descriptors
122 pollFds[0].fd = zllSoc_fd;
123 pollFds[0].events = POLLIN;
124
125 //Set the socket file descriptors
126 socketSeverGetClientFds(client_fds, numClientFds);
127 for(pollFdIdx=0; pollFdIdx < numClientFds; pollFdIdx++)
128 {
129 pollFds[pollFdIdx+1].fd = client_fds[pollFdIdx];
130 pollFds[pollFdIdx+1].events = POLLIN | POLLRDHUP;
131 //printf("zllMain: adding fd %d to poll()\n", pollFds[pollFdIdx].fd);
132 }
133
134 printf("zllMain: waiting for poll()\n");
135
136 poll(pollFds, (numClientFds+1), -1);
137
138 //printf("zllMain: got poll()\n");
139
140 //did the poll unblock because of the zllSoC serial?
141 if(pollFds[0].revents)
142 {
143 printf("Message from ZLL SoC\n");
144 zllSocProcessRpc();
145 }
146 //did the poll unblock because of activity on the socket interface?
147 for(pollFdIdx=1; pollFdIdx < (numClientFds+1); pollFdIdx++)
148 {
149 if ( (pollFds[pollFdIdx].revents) )
150 {
151 printf("Message from Socket Sever\n");
152 socketSeverPoll(pollFds[pollFdIdx].fd, pollFds[pollFdIdx].revents);
153 }
154 }
155
156 free( client_fds );
157 free( pollFds );
158 }
159 }
160 }
161
162 return retval;
163}
164
165uint8_t pfnTlIndicationCb(epInfo_t *epInfo)
166{
167 devListAddDevice(epInfo);
168 RSPC_SendEpInfo(epInfo);
169 return 0;
170}
171
172uint8_t pfnNewDevIndicationCb(epInfo_t *epInfo)
173{
174 devListAddDevice(epInfo);
175 RSPC_SendEpInfo(epInfo);
176 return 0;
177}
178
179uint8_t zclGetStateCb(uint8_t state, uint16_t nwkAddr, uint8_t endpoint)
180{
181 RPCS_ZLL_CallBack_getStateRsp(state, nwkAddr, endpoint, 0);
182 return 0;
183}
184
185uint8_t zclGetLevelCb(uint8_t level, uint16_t nwkAddr, uint8_t endpoint)
186{
187 RPCS_ZLL_CallBack_getLevelRsp(level, nwkAddr, endpoint, 0);
188 return 0;
189}
190
191uint8_t zclGetHueCb(uint8_t hue, uint16_t nwkAddr, uint8_t endpoint)
192{
193 RPCS_ZLL_CallBack_getHueRsp(hue, nwkAddr, endpoint, 0);
194 return 0;
195}
196
197uint8_t zclGetSatCb(uint8_t sat, uint16_t nwkAddr, uint8_t endpoint)
198{
199 RPCS_ZLL_CallBack_getSatRsp(sat, nwkAddr, endpoint, 0);
200 return 0;
201}
202
diff --git a/server/i486-linux-gnu/Makefile b/server/linux-gnu/makefile
index 4f7b966..4f7b966 100755..100644
--- a/server/i486-linux-gnu/Makefile
+++ b/server/linux-gnu/makefile