lora experiments

Dependencies:   BLE_API LoRaWAN-lib SX1276Lib mbed nRF51822 HCSR04Lib

Fork of LoRa by Olav Nymoen

Committer:
haaspors
Date:
Thu Jun 09 14:42:23 2016 +0000
Revision:
4:63d6744a61b6
Parent:
0:4c1fcbfcc7bf
Add 'device joined lora network' gatt char.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
olav 0:4c1fcbfcc7bf 1 /*
olav 0:4c1fcbfcc7bf 2 / _____) _ | |
olav 0:4c1fcbfcc7bf 3 ( (____ _____ ____ _| |_ _____ ____| |__
olav 0:4c1fcbfcc7bf 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
olav 0:4c1fcbfcc7bf 5 _____) ) ____| | | || |_| ____( (___| | | |
olav 0:4c1fcbfcc7bf 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
olav 0:4c1fcbfcc7bf 7 (C)2013 Semtech
olav 0:4c1fcbfcc7bf 8
olav 0:4c1fcbfcc7bf 9 Description: Helper functions implementation
olav 0:4c1fcbfcc7bf 10
olav 0:4c1fcbfcc7bf 11 License: Revised BSD License, see LICENSE.TXT file include in the project
olav 0:4c1fcbfcc7bf 12
olav 0:4c1fcbfcc7bf 13 Maintainer: Miguel Luis and Gregory Cristian
olav 0:4c1fcbfcc7bf 14 */
olav 0:4c1fcbfcc7bf 15 #include <stdlib.h>
olav 0:4c1fcbfcc7bf 16 #include <stdio.h>
olav 0:4c1fcbfcc7bf 17 #include "board.h"
olav 0:4c1fcbfcc7bf 18 #include "utilities.h"
olav 0:4c1fcbfcc7bf 19
olav 0:4c1fcbfcc7bf 20 /*!
olav 0:4c1fcbfcc7bf 21 * Redefinition of rand() and srand() standard C functions.
olav 0:4c1fcbfcc7bf 22 * These functions are redefined in order to get the same behavior across
olav 0:4c1fcbfcc7bf 23 * different compiler toolchains implementations.
olav 0:4c1fcbfcc7bf 24 */
olav 0:4c1fcbfcc7bf 25 // Standard random functions redefinition start
olav 0:4c1fcbfcc7bf 26 #define RAND_LOCAL_MAX 2147483647L
olav 0:4c1fcbfcc7bf 27
olav 0:4c1fcbfcc7bf 28 static uint32_t next = 1;
olav 0:4c1fcbfcc7bf 29
olav 0:4c1fcbfcc7bf 30 int32_t rand1( void )
olav 0:4c1fcbfcc7bf 31 {
olav 0:4c1fcbfcc7bf 32 return ( ( next = next * 1103515245L + 12345L ) % RAND_LOCAL_MAX );
olav 0:4c1fcbfcc7bf 33 }
olav 0:4c1fcbfcc7bf 34
olav 0:4c1fcbfcc7bf 35 void srand1( uint32_t seed )
olav 0:4c1fcbfcc7bf 36 {
olav 0:4c1fcbfcc7bf 37 next = seed;
olav 0:4c1fcbfcc7bf 38 }
olav 0:4c1fcbfcc7bf 39 // Standard random functions redefinition end
olav 0:4c1fcbfcc7bf 40
olav 0:4c1fcbfcc7bf 41 int32_t randr( int32_t min, int32_t max )
olav 0:4c1fcbfcc7bf 42 {
olav 0:4c1fcbfcc7bf 43 return ( int32_t )rand1( ) % ( max - min + 1 ) + min;
olav 0:4c1fcbfcc7bf 44 }
olav 0:4c1fcbfcc7bf 45
olav 0:4c1fcbfcc7bf 46 void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size )
olav 0:4c1fcbfcc7bf 47 {
olav 0:4c1fcbfcc7bf 48 while( size-- )
olav 0:4c1fcbfcc7bf 49 {
olav 0:4c1fcbfcc7bf 50 *dst++ = *src++;
olav 0:4c1fcbfcc7bf 51 }
olav 0:4c1fcbfcc7bf 52 }
olav 0:4c1fcbfcc7bf 53
olav 0:4c1fcbfcc7bf 54 void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size )
olav 0:4c1fcbfcc7bf 55 {
olav 0:4c1fcbfcc7bf 56 dst = dst + ( size - 1 );
olav 0:4c1fcbfcc7bf 57 while( size-- )
olav 0:4c1fcbfcc7bf 58 {
olav 0:4c1fcbfcc7bf 59 *dst-- = *src++;
olav 0:4c1fcbfcc7bf 60 }
olav 0:4c1fcbfcc7bf 61 }
olav 0:4c1fcbfcc7bf 62
olav 0:4c1fcbfcc7bf 63 void memset1( uint8_t *dst, uint8_t value, uint16_t size )
olav 0:4c1fcbfcc7bf 64 {
olav 0:4c1fcbfcc7bf 65 while( size-- )
olav 0:4c1fcbfcc7bf 66 {
olav 0:4c1fcbfcc7bf 67 *dst++ = value;
olav 0:4c1fcbfcc7bf 68 }
olav 0:4c1fcbfcc7bf 69 }
olav 0:4c1fcbfcc7bf 70
olav 0:4c1fcbfcc7bf 71 int8_t Nibble2HexChar( uint8_t a )
olav 0:4c1fcbfcc7bf 72 {
olav 0:4c1fcbfcc7bf 73 if( a < 10 )
olav 0:4c1fcbfcc7bf 74 {
olav 0:4c1fcbfcc7bf 75 return '0' + a;
olav 0:4c1fcbfcc7bf 76 }
olav 0:4c1fcbfcc7bf 77 else if( a < 16 )
olav 0:4c1fcbfcc7bf 78 {
olav 0:4c1fcbfcc7bf 79 return 'A' + ( a - 10 );
olav 0:4c1fcbfcc7bf 80 }
olav 0:4c1fcbfcc7bf 81 else
olav 0:4c1fcbfcc7bf 82 {
olav 0:4c1fcbfcc7bf 83 return '?';
olav 0:4c1fcbfcc7bf 84 }
olav 0:4c1fcbfcc7bf 85 }