Fixed Erbium example simulation

This commit is contained in:
Matthias Kovatsch 2011-10-10 14:16:27 +02:00
parent dd71927576
commit ce6f8de078
4 changed files with 45 additions and 39 deletions

View file

@ -93,7 +93,7 @@
* Resources are defined by the RESOURCE macro.
* Signature: resource name, the RESTful methods it handles, and its URI path (omitting the leading slash).
*/
RESOURCE(helloworld, METHOD_GET, "hello", "title=\"Hello world (set length with ?len query)\";rt=\"Text\"");
RESOURCE(helloworld, METHOD_GET, "hello", "title=\"Hello world: ?len=0..\";rt=\"Text\"");
/*
* A handler function named [resource name]_handler must be implemented for each RESOURCE.
@ -105,8 +105,9 @@ void
helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
const char *len = NULL;
int length = 12; /* ------->| */
char *message = "Hello World! ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?!at 86 now+2+4at 99 now100..105..110..115..120..125..130..135..140..145..150..155..160";
/* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */
char const * const message = "Hello World! ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy";
int length = 12; /* |<-------->| */
/* The query string can be retrieved by rest_get_query() or parsed for its key-value pairs. */
if (REST.get_query_variable(request, "len", &len)) {
@ -124,7 +125,7 @@ helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t pref
}
/* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE | HAS_SUB_RESOURCES, "mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
void
mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -283,7 +284,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
*/
RESOURCE(chunks, METHOD_GET, "chunks", "title=\"Blockwise demo\";rt=\"Data\"");
#define CHUNKS_TOTAL 1030
#define CHUNKS_TOTAL 2050
void
chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -294,7 +295,8 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
if (*offset>=CHUNKS_TOTAL)
{
REST.set_response_status(response, REST.status.BAD_OPTION);
REST.set_response_payload(response, (uint8_t*)"Block out of scope", 18);
/* A block error message should not exceed the minimum block size (16). */
REST.set_response_payload(response, (uint8_t*)"BlockOutOfScope", 15);
return;
}
@ -310,7 +312,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
REST.set_response_payload(response, buffer, strpos);
/* Signal chunk awareness of resource to framework. */
/* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */
*offset += strpos;
/* Signal end of resource. */
@ -395,7 +397,7 @@ event_event_handler(resource_t *r)
#if defined (PLATFORM_HAS_LEDS)
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
RESOURCE(led, METHOD_POST | METHOD_PUT , "leds", "title=\"Led control (use ?color=red|green|blue and POST/PUT mode=on|off)\";rt=\"Control\"");
RESOURCE(led, METHOD_POST | METHOD_PUT , "leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\"");
void
led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -409,11 +411,11 @@ led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s
if ((len=REST.get_query_variable(request, "color", &color))) {
PRINTF("color %.*s\n", len, color);
if (strncmp(color, "red", len)==0) {
if (strncmp(color, "r", len)==0) {
led = LEDS_RED;
} else if(strncmp(color,"green", len)==0) {
} else if(strncmp(color,"g", len)==0) {
led = LEDS_GREEN;
} else if (strncmp(color,"blue", len)==0) {
} else if (strncmp(color,"b", len)==0) {
led = LEDS_BLUE;
} else {
success = 0;
@ -524,7 +526,6 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
}
#endif /* PLATFORM_HAS_BATTERY */
PROCESS(rest_server_example, "Rest Server Example");
AUTOSTART_PROCESSES(&rest_server_example);
@ -569,6 +570,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
rest_activate_resource(&resource_led);
rest_activate_resource(&resource_toggle);
#endif /* PLATFORM_HAS_LEDS */
#if defined (PLATFORM_HAS_LIGHT)
SENSORS_ACTIVATE(light_sensor);
rest_activate_resource(&resource_light);