Api wrapper to communicate with EVRYTHNG's Engine.
Dependencies: EthernetInterface mbed-rtos
Dependents: EvrythngApiExample
util.cpp@1:7162d0e030f5, 2012-08-30 (annotated)
- Committer:
- vladounet
- Date:
- Thu Aug 30 13:25:41 2012 +0000
- Revision:
- 1:7162d0e030f5
- Parent:
- 0:d38d192c2f5f
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vladounet | 0:d38d192c2f5f | 1 | /* |
vladounet | 0:d38d192c2f5f | 2 | * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich |
vladounet | 0:d38d192c2f5f | 3 | * www.evrythng.com |
vladounet | 0:d38d192c2f5f | 4 | * |
vladounet | 0:d38d192c2f5f | 5 | * --- DISCLAIMER --- |
vladounet | 0:d38d192c2f5f | 6 | * |
vladounet | 0:d38d192c2f5f | 7 | * EVRYTHNG provides this source code "as is" and without warranty of any kind, |
vladounet | 0:d38d192c2f5f | 8 | * and hereby disclaims all express or implied warranties, including without |
vladounet | 0:d38d192c2f5f | 9 | * limitation warranties of merchantability, fitness for a particular purpose, |
vladounet | 0:d38d192c2f5f | 10 | * performance, accuracy, reliability, and non-infringement. |
vladounet | 0:d38d192c2f5f | 11 | * |
vladounet | 0:d38d192c2f5f | 12 | * Author: Michel Yerly |
vladounet | 0:d38d192c2f5f | 13 | * |
vladounet | 0:d38d192c2f5f | 14 | */ |
vladounet | 0:d38d192c2f5f | 15 | #include "util.h" |
vladounet | 0:d38d192c2f5f | 16 | |
vladounet | 0:d38d192c2f5f | 17 | Serial dbg(USBTX, USBRX); |
vladounet | 0:d38d192c2f5f | 18 | |
vladounet | 0:d38d192c2f5f | 19 | |
vladounet | 0:d38d192c2f5f | 20 | void sprinti64(char* dest, int64_t v, char** end) |
vladounet | 0:d38d192c2f5f | 21 | { |
vladounet | 0:d38d192c2f5f | 22 | int len; |
vladounet | 0:d38d192c2f5f | 23 | if (v != 0x8000000000000000LL) { |
vladounet | 0:d38d192c2f5f | 24 | char str[20]; |
vladounet | 0:d38d192c2f5f | 25 | int p = sizeof(str); |
vladounet | 0:d38d192c2f5f | 26 | str[--p] = '\0'; |
vladounet | 0:d38d192c2f5f | 27 | str[p-1] = '0'; |
vladounet | 0:d38d192c2f5f | 28 | bool neg = false; |
vladounet | 0:d38d192c2f5f | 29 | if (v < 0) { |
vladounet | 0:d38d192c2f5f | 30 | v = -v; |
vladounet | 0:d38d192c2f5f | 31 | neg = true; |
vladounet | 0:d38d192c2f5f | 32 | } |
vladounet | 0:d38d192c2f5f | 33 | while (v > 0) { |
vladounet | 0:d38d192c2f5f | 34 | str[--p] = '0' + (v % 10); |
vladounet | 0:d38d192c2f5f | 35 | v /= 10; |
vladounet | 0:d38d192c2f5f | 36 | } |
vladounet | 0:d38d192c2f5f | 37 | if (neg) { |
vladounet | 0:d38d192c2f5f | 38 | str[--p] = '-'; |
vladounet | 0:d38d192c2f5f | 39 | } |
vladounet | 0:d38d192c2f5f | 40 | len = sizeof(str) - p; |
vladounet | 0:d38d192c2f5f | 41 | strncpy(dest, str + p, len); |
vladounet | 0:d38d192c2f5f | 42 | } else { |
vladounet | 0:d38d192c2f5f | 43 | len = 20; |
vladounet | 0:d38d192c2f5f | 44 | strncpy(dest, "-9223372036854775808", len); |
vladounet | 0:d38d192c2f5f | 45 | } *end = dest + len; |
vladounet | 0:d38d192c2f5f | 46 | } |