Factor/Fix generic resources
Now the old GENERIC_RESOURCE macros works again (but usage has changed). Common resources (battery, leds, radio) are now in resources-common.
This commit is contained in:
parent
76e39b2b5d
commit
baaa2c5741
59 changed files with 440 additions and 2705 deletions
|
@ -1,17 +1,16 @@
|
|||
all: er-example-server \
|
||||
er-example-server.osd-merkur.hex er-example-server.osd-merkur.eep
|
||||
ifeq ($(TARGET), osd-merkur)
|
||||
PLATFORM_FILES= avr-size er-example-server.osd-merkur.hex \
|
||||
er-example-server.osd-merkur.eep
|
||||
endif
|
||||
|
||||
all: er-example-server $(PLATFORM_FILES)
|
||||
# use this target explicitly if requried: er-plugtest-server
|
||||
|
||||
# variable for this Makefile
|
||||
# configure CoAP implementation (3|7|12|13) (er-coap-07 also supports CoAP draft 08)
|
||||
WITH_COAP=13
|
||||
|
||||
# for some platforms
|
||||
UIP_CONF_IPV6=1
|
||||
# IPv6 make config disappeared completely
|
||||
CFLAGS += -DUIP_CONF_IPV6=1
|
||||
|
||||
CONTIKI=../../..
|
||||
|
||||
# Contiki IPv6 configuration
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
PROJECT_SOURCEFILES += resource_led_pwm.c
|
||||
|
@ -33,43 +32,16 @@ endif
|
|||
# linker optimizations
|
||||
SMALL=1
|
||||
|
||||
# REST framework, requires WITH_COAP
|
||||
ifeq ($(WITH_COAP), 13)
|
||||
${info INFO: compiling with CoAP-13}
|
||||
CFLAGS += -DWITH_COAP=13
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-13
|
||||
else ifeq ($(WITH_COAP), 12)
|
||||
${info INFO: compiling with CoAP-12}
|
||||
CFLAGS += -DWITH_COAP=12
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-12
|
||||
else ifeq ($(WITH_COAP), 7)
|
||||
${info INFO: compiling with CoAP-08}
|
||||
CFLAGS += -DWITH_COAP=7
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-07
|
||||
else ifeq ($(WITH_COAP), 3)
|
||||
${info INFO: compiling with CoAP-03}
|
||||
CFLAGS += -DWITH_COAP=3
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-03
|
||||
else
|
||||
${info INFO: compiling with HTTP}
|
||||
CFLAGS += -DWITH_HTTP
|
||||
CFLAGS += -DREST=http_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=1
|
||||
APPS += er-http-engine
|
||||
endif
|
||||
|
||||
APPS += erbium json json-resource
|
||||
# REST Engine shall use Erbium CoAP implementation
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
APPS += json json-resource
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
avr-size: er-example-server.osd-merkur
|
||||
avr-size -C --mcu=MCU=atmega128rfa1 er-example-server.osd-merkur
|
||||
|
||||
er-example-server.osd-merkur.hex: er-example-server.osd-merkur
|
||||
avr-objcopy -j .text -j .data -O ihex er-example-server.osd-merkur \
|
||||
er-example-server.osd-merkur.hex
|
||||
|
@ -84,7 +56,7 @@ flash: er-example-server.osd-merkur.hex er-example-server.osd-merkur.eep
|
|||
flash:w:er-example-server.osd-merkur.hex:a -U \
|
||||
eeprom:w:er-example-server.osd-merkur.eep:a
|
||||
|
||||
.PHONY: flash
|
||||
.PHONY: flash avr-size
|
||||
|
||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||
|
|
|
@ -43,9 +43,7 @@
|
|||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "jsonparse.h"
|
||||
|
||||
#include "erbium.h"
|
||||
#include "er-coap-13.h"
|
||||
#include "er-coap.h"
|
||||
|
||||
#include "led_pwm.h"
|
||||
|
||||
|
@ -58,44 +56,6 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
/*
|
||||
* Resources are defined by the RESOURCE macro.
|
||||
* Signature: resource name, the RESTful methods it handles, and its URI
|
||||
* path (omitting the leading slash).
|
||||
*/
|
||||
RESOURCE(info, METHOD_GET, "info", "title=\"Info\";rt=\"text\"");
|
||||
|
||||
/*
|
||||
* A handler function named [resource name]_handler must be implemented
|
||||
* for each RESOURCE. A buffer for the response payload is provided
|
||||
* through the buffer pointer. Simple resources can ignore
|
||||
* preferred_size and offset, but must respect the REST_MAX_CHUNK_SIZE
|
||||
* limit for the buffer. If a smaller block size is requested for CoAP,
|
||||
* the REST framework automatically splits the data.
|
||||
*/
|
||||
void
|
||||
info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
char message[100];
|
||||
int index = 0;
|
||||
int length = 0; /* |<-------->| */
|
||||
|
||||
/*
|
||||
* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more,
|
||||
* see the chunk resource.
|
||||
*/
|
||||
// jSON Format
|
||||
index += sprintf(message + index,"{\n \"Version\" : \"V1.0pre1\",\n");
|
||||
index += sprintf(message + index," \"name\" : \"PWM\"\n");
|
||||
index += sprintf(message + index,"}\n");
|
||||
|
||||
length = strlen(message);
|
||||
memcpy(buffer, message,length );
|
||||
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
REST.set_response_payload(response, buffer, length);
|
||||
}
|
||||
|
||||
void
|
||||
hw_init()
|
||||
{
|
||||
|
@ -137,8 +97,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
|||
rest_init_engine();
|
||||
|
||||
/* Activate the application-specific resources. */
|
||||
rest_activate_resource(&resource_info);
|
||||
rest_activate_resource(&resource_led_pwm);
|
||||
rest_activate_resource(&res_led_pwm, "led/pwm");
|
||||
|
||||
/* Define application-specific events here. */
|
||||
while(1) {
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
#ifndef led_pwm_h
|
||||
#define led_pwm_h
|
||||
#include "contiki.h"
|
||||
#include "erbium.h"
|
||||
|
||||
extern resource_t resource_led_pwm;
|
||||
extern resource_t res_led_pwm;
|
||||
extern void led_pwm_init (void);
|
||||
|
||||
#endif // led_pwm_h
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
#include "jsonparse.h"
|
||||
/* Only coap 13 for now */
|
||||
#include "er-coap-13.h"
|
||||
#include "er-coap.h"
|
||||
#include "hw_timer.h"
|
||||
#include "generic_resource.h"
|
||||
|
||||
|
@ -59,8 +58,7 @@ size_t pwm_to_string (const char *n, uint8_t is_json, char *buf, size_t bufsize)
|
|||
}
|
||||
|
||||
GENERIC_RESOURCE \
|
||||
( led_pwm, METHOD_GET | METHOD_PUT
|
||||
, "led/pwm"
|
||||
( led_pwm
|
||||
, LED PWM
|
||||
, duty-cycle
|
||||
, pwm_from_string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue