-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d12c1b
Showing
21 changed files
with
4,678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: | ||
clear | ||
gcc sw_lib/sitewhere.c sw_lib/sitewhere_pb.c sw_lib/pb_encode.c sw_lib/pb_decode.c sw_lib/pb_common.c sw_lib/double_conversion.c sw_lib/sw_bridge.c sw_test.c -l paho-mqtt3c -o SW_Run | ||
|
||
run: | ||
clear | ||
./SW_Run | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
all: | ||
clear | ||
gcc -c pb_common.c pb_common.h pb_decode.c pb_decode.h pb_encode.c pb_encode.h sitewhere.c sitewhere.h sw_bridge.c sw_bridge.h double_conversion.c double_conversion.h sitewhere_pb.c sitewhere_pb.h -l paho-mqtt3c | ||
ar -cvq SW_Linux.a pb_common.o pb_decode.o pb_encode.o sitewhere.o sw_bridge.o double_conversion.o sitewhere_pb.o | ||
|
||
cross: | ||
arm-cortexa9-linux-gnueabihf-gcc -c pb_common.c pb_common.h pb_decode.c pb_decode.h pb_encode.c pb_encode.h sitewhere.c sitewhere.h sw_bridge.c sw_bridge.h double_conversion.c double_conversion.h sitewhere_pb.c sitewhere_pb.h | ||
ar -cvq SW_Linux.a pb_common.o pb_decode.o pb_encode.o sitewhere.o sw_bridge.o double_conversion.o sitewhere_pb.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Conversion routines for platforms that do not support 'double' directly. */ | ||
|
||
#include "double_conversion.h" | ||
#include <math.h> | ||
|
||
typedef union { | ||
float f; | ||
uint32_t i; | ||
} conversion_t; | ||
|
||
/* Note: IEE 754 standard specifies float formats as follows: | ||
* Single precision: sign, 8-bit exp, 23-bit frac. | ||
* Double precision: sign, 11-bit exp, 52-bit frac. | ||
*/ | ||
|
||
uint64_t float_to_double(float value) | ||
{ | ||
conversion_t in; | ||
in.f = value; | ||
uint8_t sign; | ||
int16_t exponent; | ||
uint64_t mantissa; | ||
|
||
/* Decompose input value */ | ||
sign = (in.i >> 31) & 1; | ||
exponent = ((in.i >> 23) & 0xFF) - 127; | ||
mantissa = in.i & 0x7FFFFF; | ||
|
||
if (exponent == 128) | ||
{ | ||
/* Special value (NaN etc.) */ | ||
exponent = 1024; | ||
} | ||
else if (exponent == -127) | ||
{ | ||
if (!mantissa) | ||
{ | ||
/* Zero */ | ||
exponent = -1023; | ||
} | ||
else | ||
{ | ||
/* Denormalized */ | ||
mantissa <<= 1; | ||
while (!(mantissa & 0x800000)) | ||
{ | ||
mantissa <<= 1; | ||
exponent--; | ||
} | ||
mantissa &= 0x7FFFFF; | ||
} | ||
} | ||
|
||
/* Combine fields */ | ||
mantissa <<= 29; | ||
mantissa |= (uint64_t)(exponent + 1023) << 52; | ||
mantissa |= (uint64_t)sign << 63; | ||
|
||
return mantissa; | ||
} | ||
|
||
float double_to_float(uint64_t value) | ||
{ | ||
uint8_t sign; | ||
int16_t exponent; | ||
uint32_t mantissa; | ||
conversion_t out; | ||
|
||
/* Decompose input value */ | ||
sign = (value >> 63) & 1; | ||
exponent = ((value >> 52) & 0x7FF) - 1023; | ||
mantissa = (value >> 28) & 0xFFFFFF; /* Highest 24 bits */ | ||
|
||
/* Figure if value is in range representable by floats. */ | ||
if (exponent == 1024) | ||
{ | ||
/* Special value */ | ||
exponent = 128; | ||
} | ||
else if (exponent > 127) | ||
{ | ||
/* Too large */ | ||
if (sign) | ||
return -INFINITY; | ||
else | ||
return INFINITY; | ||
} | ||
else if (exponent < -150) | ||
{ | ||
/* Too small */ | ||
if (sign) | ||
return -0.0f; | ||
else | ||
return 0.0f; | ||
} | ||
else if (exponent < -126) | ||
{ | ||
/* Denormalized */ | ||
mantissa |= 0x1000000; | ||
mantissa >>= (-126 - exponent); | ||
exponent = -127; | ||
} | ||
|
||
/* Round off mantissa */ | ||
mantissa = (mantissa + 1) >> 1; | ||
|
||
/* Check if mantissa went over 2.0 */ | ||
if (mantissa & 0x800000) | ||
{ | ||
exponent += 1; | ||
mantissa &= 0x7FFFFF; | ||
mantissa >>= 1; | ||
} | ||
|
||
/* Combine fields */ | ||
out.i = mantissa; | ||
out.i |= (uint32_t)(exponent + 127) << 23; | ||
out.i |= (uint32_t)sign << 31; | ||
|
||
return out.f; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* AVR-GCC does not have real double datatype. Instead its double | ||
* is equal to float, i.e. 32 bit value. If you need to communicate | ||
* with other systems that use double in their .proto files, you | ||
* need to do some conversion. | ||
* | ||
* These functions use bitwise operations to mangle floats into doubles | ||
* and then store them in uint64_t datatype. | ||
*/ | ||
|
||
#ifndef DOUBLE_CONVERSION | ||
#define DOUBLE_CONVERSION | ||
|
||
#include <stdint.h> | ||
|
||
/* Convert native 4-byte float into a 8-byte double. */ | ||
extern uint64_t float_to_double(float value); | ||
|
||
/* Convert 8-byte double into native 4-byte float. | ||
* Values are rounded to nearest, 0.5 away from zero. | ||
* Overflowing values are converted to Inf or -Inf. | ||
*/ | ||
extern float double_to_float(uint64_t value); | ||
|
||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export PATH=$PATH:/home/uvix-0/Desktop/company/Axonet_Emsys/1.PROJECTS/1.Linux_IoT_Gateway/0_arm-cortexa9-linux-gnueabihf/gcc-4.7.3-glibc-2.16.0-binutils-2.22-kernel-3.0.35-sanitized/bin | ||
|
||
export ARCH=arm | ||
|
||
export CROSS_COMPILE=arm-cortexa9-linux-gnueabihf- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
####################################### | ||
# Syntax Coloring Map For SiteWhere | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
sitewhere KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
sw_register KEYWORD2 | ||
sw_acknowledge KEYWORD2 | ||
sw_measurement KEYWORD2 | ||
sw_location KEYWORD2 | ||
sw_alert KEYWORD2 | ||
|
||
####################################### | ||
# Instances (KEYWORD2) | ||
####################################### | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### |
Oops, something went wrong.