/** * \file * Resource for timestamp handling * \author * Ralf Schlatterbeck * * \brief get/put time in seconds since 1970 (UNIX time) * Note: the internal format of the time in seconds is a 64bit number * unfortunately javascript (json) will only support double for which * the mantissa isn't long enough for representing that number. So we're * back to 32 bit and have a year 2038 problem. */ #include #include #include #include "contiki.h" #include "time.h" #include "time_resource.h" #include "jsonparse.h" /* Only coap 13 for now */ #include "er-coap-13.h" /* Error-handling macro */ # define BYE(_exp, _tag) \ do { \ PRINTF("Expect "_exp": %d\n",_tag); \ success=0; \ goto bye; \ } while(0) #define DEBUG 1 #if DEBUG #define PRINTF(...) printf(__VA_ARGS__) #else #define PRINTF(...) #endif RESOURCE \ ( timestamp, METHOD_GET | METHOD_PUT , "clock/timestamp" , "title=\"Time\";rt=\"timestamp\"" ); void timestamp_handler ( void* request , void* response , uint8_t *buffer , uint16_t preferred_size , int32_t *offset ) { int success = 1; int i; char temp[100]; int index = 0; int length = 0; int tag = 0; const uint8_t *bytes = NULL; size_t len = 0; struct timeval tv; int n_acc = 0; const uint16_t *accept = NULL; uint16_t a_ctype = REST.type.APPLICATION_JSON; uint16_t c_ctype = REST.get_header_content_type (request); /* Seems like accepted type is currently unsupported? */ n_acc = REST.get_header_accept (request, &accept); for (i=0; i