Skip to content

Commit 9c90a79

Browse files
authored
Merge pull request #3 from exsilium/feature/smartthings
Improvements to structure, support for SmartThings local processing
2 parents 94ebc21 + a41b93a commit 9c90a79

File tree

7 files changed

+132
-28
lines changed

7 files changed

+132
-28
lines changed

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2016 - 2018, Sten Feldman
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ all: start cpu drivers misc pan link burn
7878

7979
start: $(OUTPUT) \
8080
$(OUTPUT)/start08.o \
81+
$(OUTPUT)/util.o \
8182
$(OUTPUT)/main.o
8283

8384
$(OUTPUT)/start08.o: ./src/start08.c
8485
$(CC) $(CFLAGS) -ObjN="$@" -Lm="$@.d" -LmCfg=xilmou $<
8586

87+
$(OUTPUT)/util.o: ./src/util.c
88+
$(CC) $(CFLAGS) -ObjN="$@" -Lm="$@.d" -LmCfg=xilmou $<
89+
8690
$(OUTPUT)/main.o: ./src/main.c
8791
$(CC) $(CFLAGS) -ObjN="$@" -Lm="$@.d" -LmCfg=xilmou $<
8892

@@ -283,6 +287,7 @@ link:
283287
"$(OUTPUT)/pan/zigbee/zigbee_zcl.o" \
284288
"$(OUTPUT)/pan/zigbee/zigbee_zdo.o" \
285289
"$(OUTPUT)/start08.o" \
290+
"$(OUTPUT)/util.o" \
286291
"$(OUTPUT)/main.o" \
287292
"$(HC08C)/lib/$(HC08C_LIB)"\) \
288293
-O"$(OUTPUT)/$(APP_NAME).abs"

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pxbee-trigger
22

3-
Programmable XBee Trigger that is ZigBee Home Automation profile compliant. The testing of this feature branch is carried out using [SmartThings](https://www.smartthings.com) Hub and a default ZigBee device handler.
3+
Programmable XBee Trigger that is ZigBee Home Automation profile compliant. The testing of this feature is carried out using [SmartThings](https://www.smartthings.com) Hub and a default ZigBee device handler.
44

55
## Bill of Materials
66

@@ -38,3 +38,27 @@ clusterId: 0x0006,
3838
profileId: 0x0104,
3939
command: 0x01
4040
```
41+
42+
## Settings
43+
44+
The following defines can be altered in `custom.h` prior to compilation to change the behavior how the Trigger works:
45+
46+
| Name | Description | Default |
47+
| ------| ----------- | ------- |
48+
| `PXBEE_TRIGGER_IGNORE_BROADCAST` | When enabled, ignores broadcast commands and reacts only when unicast messages are sent to the specific address (ignores All On/All Off commands). | Enabled |
49+
| `ZCL_MANUFACTURER` | The reported manufacturer string. For SmartThings local execution support without custom device handler, set this to "Leviton". | "PXBee" |
50+
| `ZCL_MODEL` | The reported model string. For SmartThings local execution support without custom device handler, set this to "ZSS-10". | "Trigger" |
51+
52+
## License
53+
54+
This project is based on [exsilium/pxbee-blink-led](https://github.com/exsilium/pxbee-blink-led) boilerplate and includes the full [Digi](http://www.digi.com) XBee SDK version 1.6.0 sources.
55+
56+
Includes the necessary build binaries:
57+
```
58+
HI-CROSS+ ANSI-C Compiler for HC08 V-5.0.39, Dec 13 2011
59+
HI-CROSS+ SmartLinker V-5.0.48, Dec 13 2011
60+
HI-CROSS+ Burner V-5.0.16, Dec 13 2011
61+
(c) Copyright Freescale 1987-2010
62+
```
63+
64+
If not otherwise noted, the added code is [BSD licensed](LICENSE).

include/custom.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
/* Additional XBee settings */
9+
/* Additional XBee settings for SmartThings compatibility */
1010
#define XBEE_PARAM_ZS 2
1111
#define XBEE_PARAM_NJ 0x5A
1212
#define XBEE_PARAM_NH 0x1E
@@ -16,8 +16,19 @@
1616
#define XBEE_PARAM_EO 1
1717
#define XBEE_PARAM_KY "5A6967426565416C6C69616E63653039"
1818

19+
/* Reported manufacturer and model in basic cluster
20+
*
21+
* For SmartThings local execution without custom device handler, set the following:
22+
* - ZCL_MANUFACTURER "Leviton"
23+
* - ZCL_MODEL "ZSS-10"
24+
*/
25+
#define ZCL_MANUFACTURER "PXBee"
26+
#define ZCL_MODEL "Trigger"
27+
1928
/* Ignore On command received via Broadcast message */
2029
#define PXBEE_TRIGGER_IGNORE_BROADCAST
30+
31+
/* Settings END */
2132

2233
#include <zigbee/zdo.h>
2334

@@ -29,13 +40,13 @@ extern wpan_ep_state_t custom_ha_ep_state;
2940

3041
/* With this macro the prototypes of clusters' callbacks and extern variables are included in endpoints.c
3142
* Array custom_ep_data_clusters[] is declared in main.c
32-
* Function custom_ep_default_cluster() is implemented in main.c */
43+
* Function custom_ep_basic_cluster() is implemented in main.c */
3344
#define EP_INCLUDE_DECLARATIONS extern const wpan_cluster_table_entry_t custom_ep_clusters[]; \
34-
int custom_ep_default_cluster(const wpan_envelope_t FAR *, void FAR *);
45+
int custom_ep_basic_cluster(const wpan_envelope_t FAR *, void FAR *);
3546

3647
/* This is a wpan_endpoint_table_entry_t structure, see its declaration in aps.h, the '{}' are because they
3748
* will be included in endpoints_table[] in endpoints.c */
38-
#define ADDITIONAL_ENDPOINTS {CUSTOM_ENDPOINT, CUSTOM_EP_PROFILE, custom_ep_default_cluster, &custom_ha_ep_state, 0x0002, 0x00, custom_ep_clusters}, \
49+
#define ADDITIONAL_ENDPOINTS {CUSTOM_ENDPOINT, CUSTOM_EP_PROFILE, custom_ep_basic_cluster, &custom_ha_ep_state, 0x0002, 0x00, custom_ep_clusters}, \
3950
ZDO_ENDPOINT(zdo_ep_state)
4051

4152
/* This macro is automatically defined if Process Incoming frames, Node Discovery Support or Over-the-Air

include/util.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uint8_t* appendStringChar(uint8_t* dest, const char* str);

src/main.c

+42-23
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,33 @@
5252
*
5353
************************************/
5454

55-
5655
#include <xbee_config.h>
5756
#include <types.h>
57+
#include <util.h>
5858

5959
// Custom profile and cluster implementation
60-
#define CUSTOM_EP_NULL_CLUSTER 0x0000
61-
#define CUSTOM_EP_CUSTOM_CLUSTER 0x0006
60+
#define CUSTOM_EP_BASIC_CLUSTER 0x0000
61+
#define CUSTOM_EP_IDENTIFY_CLUSTER 0x0003 /* Not implemented */
62+
#define CUSTOM_EP_GROUPS_CLUSTER 0x0004 /* Not implemented */
63+
#define CUSTOM_EP_SCENES_CLUSTER 0x0005 /* Not implemented */
64+
#define CUSTOM_EP_ONOFF_CLUSTER 0x0006
6265

6366
zcl_command_t zcl;
6467

6568
int trigger(void);
66-
int custom_ep_rx_cluster(const wpan_envelope_t FAR *envelope, void FAR *context);
69+
int custom_ep_rx_on_off_cluster(const wpan_envelope_t FAR *envelope, void FAR *context);
70+
int custom_ep_rx_notimpl_cluster(const wpan_envelope_t FAR *envelope, void FAR *context);
6771

6872
const wpan_cluster_table_entry_t custom_ep_clusters[] = {
69-
{CUSTOM_EP_NULL_CLUSTER, NULL, NULL, WPAN_CLUST_FLAG_INPUT},
70-
{CUSTOM_EP_CUSTOM_CLUSTER, custom_ep_rx_cluster, NULL, WPAN_CLUST_FLAG_INPUT},
73+
{CUSTOM_EP_BASIC_CLUSTER, NULL, NULL, WPAN_CLUST_FLAG_INPUT},
74+
{CUSTOM_EP_IDENTIFY_CLUSTER, custom_ep_rx_notimpl_cluster, NULL, WPAN_CLUST_FLAG_INPUT},
75+
{CUSTOM_EP_GROUPS_CLUSTER, custom_ep_rx_notimpl_cluster, NULL, WPAN_CLUST_FLAG_INPUT},
76+
{CUSTOM_EP_SCENES_CLUSTER, custom_ep_rx_notimpl_cluster, NULL, WPAN_CLUST_FLAG_INPUT},
77+
{CUSTOM_EP_ONOFF_CLUSTER, custom_ep_rx_on_off_cluster, NULL, WPAN_CLUST_FLAG_INPUT},
7178
WPAN_CLUST_ENTRY_LIST_END
7279
};
7380

74-
75-
int custom_ep_default_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
81+
int custom_ep_basic_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
7682
{
7783
uint8_t *payload_pointer = envelope->payload;
7884
int i = 0;
@@ -141,12 +147,7 @@ int custom_ep_default_cluster(const wpan_envelope_t FAR *envelope, void FAR *con
141147
*end_response++ = 0x00;
142148
*end_response++ = ZCL_STATUS_SUCCESS;
143149
*end_response++ = 0x42;
144-
*end_response++ = 0x05; // Length of data
145-
*end_response++ = 'P';
146-
*end_response++ = 'X';
147-
*end_response++ = 'B';
148-
*end_response++ = 'e';
149-
*end_response++ = 'e';
150+
end_response = appendStringChar(end_response, ZCL_MANUFACTURER);
150151

151152
printf("Response length: %02X\n", end_response - start_response);
152153
if(zcl_send_response(&zcl, start_response, end_response - start_response) == 0) {
@@ -160,14 +161,7 @@ int custom_ep_default_cluster(const wpan_envelope_t FAR *envelope, void FAR *con
160161
*end_response++ = 0x00;
161162
*end_response++ = ZCL_STATUS_SUCCESS;
162163
*end_response++ = 0x42;
163-
*end_response++ = 0x07; // Length of data
164-
*end_response++ = 'T';
165-
*end_response++ = 'r';
166-
*end_response++ = 'i';
167-
*end_response++ = 'g';
168-
*end_response++ = 'g';
169-
*end_response++ = 'e';
170-
*end_response++ = 'r';
164+
end_response = appendStringChar(end_response, ZCL_MODEL);
171165

172166
printf("Response length: %02X\n", end_response - start_response);
173167
if(zcl_send_response(&zcl, start_response, end_response - start_response) == 0) {
@@ -186,7 +180,7 @@ int custom_ep_default_cluster(const wpan_envelope_t FAR *envelope, void FAR *con
186180
return 0;
187181
}
188182

189-
int custom_ep_rx_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
183+
int custom_ep_rx_on_off_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
190184
{
191185
uint8_t *start_response;
192186
uint8_t *end_response;
@@ -332,6 +326,31 @@ int custom_ep_rx_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
332326

333327
return 0;
334328
}
329+
330+
int custom_ep_rx_notimpl_cluster(const wpan_envelope_t FAR *envelope, void FAR *context)
331+
{
332+
uint8_t *start_response;
333+
uint8_t *end_response;
334+
PACKED_STRUCT {
335+
zcl_header_response_t header;
336+
uint8_t buffer[20];
337+
} response;
338+
339+
printf("\nNOTIMPL CLUSTER HANDLER\n");
340+
printf("=======================\n");
341+
printf("\n\nBuilding ZCL Command based on received envelope: ");
342+
if(zcl_command_build(&zcl, envelope, context) == 0) {
343+
printf("OK!\n");
344+
printf("----------------------\n");
345+
printf("Frame Control: %02X\n", zcl.frame_control);
346+
printf("Command: %02X\n", zcl.command);
347+
printf("ZCL Payload length: %02X\n", zcl.length);
348+
hex_dump(zcl.zcl_payload, zcl.length, HEX_DUMP_FLAG_TAB);
349+
printf("----------------------\n");
350+
zcl_envelope_payload_dump(envelope);
351+
}
352+
return 0;
353+
}
335354
// END: Custom profile and cluster implementation
336355

337356
/* Callback function for XBee commands */

src/util.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Generic Helper/Utility functions */
2+
3+
#include <types.h>
4+
5+
// Contribution by ST Community member - gazor
6+
uint8_t* appendStringChar(uint8_t* dest, const char* str)
7+
{
8+
// Write string, preceeded by length byte, no termination character
9+
size_t len = 0;
10+
for(;;)
11+
{
12+
uint8_t c = (uint8_t) str[len];
13+
if(c == 0) break;
14+
dest[1+len] = c;
15+
len++;
16+
}
17+
dest[0] = (uint8_t) len;
18+
return dest + 1 + len;
19+
}

0 commit comments

Comments
 (0)