2014-05-29 17:06:43 +02:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Resource for timestamp handling
|
|
|
|
* \author
|
|
|
|
* Ralf Schlatterbeck <rsc@runtux.com>
|
|
|
|
*
|
|
|
|
* \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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "time.h"
|
|
|
|
#include "time_resource.h"
|
|
|
|
#include "jsonparse.h"
|
2015-01-21 15:09:31 +01:00
|
|
|
#include "er-coap.h"
|
2014-06-27 22:25:51 +02:00
|
|
|
#include "generic_resource.h"
|
2014-05-29 17:06:43 +02:00
|
|
|
|
2016-02-26 07:54:05 +01:00
|
|
|
int timestamp_from_string (const char *name, const char *uri, const char *s)
|
2014-05-29 17:06:43 +02:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
2014-06-27 22:25:51 +02:00
|
|
|
// FIXME: Platform has no strtoll (long long)?
|
|
|
|
tv.tv_sec = strtol (s, NULL, 10);
|
|
|
|
settimeofday (&tv, NULL);
|
2016-02-26 07:54:05 +01:00
|
|
|
return 0;
|
2014-06-27 22:25:51 +02:00
|
|
|
}
|
2014-05-29 17:06:43 +02:00
|
|
|
|
2014-06-27 22:25:51 +02:00
|
|
|
size_t
|
2016-02-26 07:54:05 +01:00
|
|
|
timestamp_to_string (const char *name, const char *uri, char *buf, size_t bsize)
|
2014-06-27 22:25:51 +02:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
// FIXME: Platform doesn't seem to support long long printing
|
|
|
|
// We get empty string
|
2016-02-26 07:54:05 +01:00
|
|
|
return snprintf (buf, bsize, "%ld", (long)tv.tv_sec);
|
2014-06-27 22:25:51 +02:00
|
|
|
}
|
2014-05-29 17:06:43 +02:00
|
|
|
|
2014-06-27 22:25:51 +02:00
|
|
|
GENERIC_RESOURCE
|
|
|
|
( timestamp
|
|
|
|
, Time
|
|
|
|
, s
|
2016-02-26 07:54:05 +01:00
|
|
|
, 1
|
2014-06-27 22:25:51 +02:00
|
|
|
, timestamp_from_string
|
|
|
|
, timestamp_to_string
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VI settings, see coding style
|
|
|
|
* ex:ts=8:et:sw=2
|
|
|
|
*/
|
2014-05-29 17:06:43 +02:00
|
|
|
|