Fixed Erbium chunks for minimal-net
This commit is contained in:
parent
2522566b68
commit
df9f871313
2 changed files with 19 additions and 14 deletions
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
#include "er-coap-07-engine.h"
|
#include "er-coap-07-engine.h"
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define PRINTF(...) printf(__VA_ARGS__)
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
|
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
|
||||||
|
@ -315,7 +315,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
||||||
|
|
||||||
for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next)
|
for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next)
|
||||||
{
|
{
|
||||||
PRINTF("res: /%s (%p)\n", resource->url, resource);
|
PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos);
|
||||||
|
|
||||||
if (strpos >= *offset && bufpos < preferred_size)
|
if (strpos >= *offset && bufpos < preferred_size)
|
||||||
{
|
{
|
||||||
|
@ -333,7 +333,8 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
||||||
if (strpos+tmplen > *offset)
|
if (strpos+tmplen > *offset)
|
||||||
{
|
{
|
||||||
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
|
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
|
||||||
"%s", resource->url + (*offset-strpos > 0 ? *offset-strpos : 0));
|
"%s", resource->url + ((*offset-(int32_t)strpos > 0) ? (*offset-(int32_t)strpos) : 0));
|
||||||
|
/* minimal-net requires these casts */
|
||||||
}
|
}
|
||||||
strpos += tmplen;
|
strpos += tmplen;
|
||||||
|
|
||||||
|
@ -355,10 +356,9 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
||||||
if (strpos+tmplen > *offset)
|
if (strpos+tmplen > *offset)
|
||||||
{
|
{
|
||||||
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
|
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
|
||||||
"%s", resource->attributes + (*offset-strpos > 0 ? *offset-strpos : 0));
|
"%s", resource->attributes + (*offset-(int32_t)strpos > 0 ? *offset-(int32_t)strpos : 0));
|
||||||
}
|
}
|
||||||
strpos += tmplen;
|
strpos += tmplen;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource->next)
|
if (resource->next)
|
||||||
|
@ -367,10 +367,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
|
||||||
{
|
{
|
||||||
buffer[bufpos++] = ',';
|
buffer[bufpos++] = ',';
|
||||||
}
|
}
|
||||||
if (bufpos <= preferred_size)
|
++strpos;
|
||||||
{
|
|
||||||
++strpos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* buffer full, but resource not completed yet; or: do not break if resource exactly fills buffer. */
|
/* buffer full, but resource not completed yet; or: do not break if resource exactly fills buffer. */
|
||||||
|
|
|
@ -301,11 +301,19 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate data until reaching CHUNKS_TOTAL. */
|
/* Generate data until reaching CHUNKS_TOTAL. */
|
||||||
while (strpos<REST_MAX_CHUNK_SIZE) {
|
while (strpos<preferred_size)
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "|%ld|", *offset);
|
{
|
||||||
|
strpos += snprintf((char *)buffer+strpos, preferred_size-strpos+1, "|%ld|", *offset);
|
||||||
}
|
}
|
||||||
/* Truncate if above. */
|
|
||||||
if (*offset+strpos > CHUNKS_TOTAL)
|
/* snprintf() does not adjust return value if truncated by size. */
|
||||||
|
if (strpos > preferred_size)
|
||||||
|
{
|
||||||
|
strpos = preferred_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Truncate if above total size. */
|
||||||
|
if (*offset+(int32_t)strpos > CHUNKS_TOTAL)
|
||||||
{
|
{
|
||||||
strpos = CHUNKS_TOTAL - *offset;
|
strpos = CHUNKS_TOTAL - *offset;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +323,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||||
/* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */
|
/* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */
|
||||||
*offset += strpos;
|
*offset += strpos;
|
||||||
|
|
||||||
/* Signal end of resource. */
|
/* Signal end of resource representation. */
|
||||||
if (*offset>=CHUNKS_TOTAL)
|
if (*offset>=CHUNKS_TOTAL)
|
||||||
{
|
{
|
||||||
*offset = -1;
|
*offset = -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue