Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
* Updated "Listen-Before-Talk" JSON configuration to match with LBT rework.
* Added TX Notch Filter JSON configuration.
* Updated Parson library to latest version
* Fixed Class-B beacon CRC-16 calculation
* Removed JiT time_on_air local function, and use lgw_time_on_air() function
  • Loading branch information
mcoracin committed Nov 9, 2016
1 parent f31ee2e commit fcd2565
Show file tree
Hide file tree
Showing 13 changed files with 1,561 additions and 484 deletions.
3 changes: 2 additions & 1 deletion PROTOCOL.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ occured.
0 | protocol version = 2
1-2 | same token as the PULL_RESP packet to acknowledge
3 | TX_ACK identifier 0x05
4-end | [optional] JSON object, starting with {, ending with }, see section 6
4-11 | Gateway unique identifier (MAC address)
12-end | [optional] JSON object, starting with {, ending with }, see section 6

6. Downstream JSON data structure
----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.0
15 changes: 9 additions & 6 deletions lora_pkt_fwd/cfg/global_conf.json.PCB_E336.EU868.basic
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"clksrc": 1, /* radio_1 provides clock to concentrator */
"lbt_cfg": {
"enable": false,
"rssi_target": 160, /* rssi in dBm = -lbt_rssi_target/2 */
"nb_channel": 1,
"start_freq": 869525000,
"scan_time_us": 5000,
"tx_delay_1ch_us": 4000000,
"tx_delay_2ch_us": 4000000
"rssi_target": -80, /* dBm */
"chan_cfg":[ /* 8 channels maximum */
{ "freq_hz": 867100000, "scan_time_us": 128 },
{ "freq_hz": 867300000, "scan_time_us": 5000 },
{ "freq_hz": 867500000, "scan_time_us": 128 },
{ "freq_hz": 869525000, "scan_time_us": 128 }
],
"sx127x_rssi_offset": -4 /* dB */
},
"antenna_gain": 0, /* antenna gain, in dBi */
"radio_0": {
Expand All @@ -18,6 +20,7 @@
"freq": 867500000,
"rssi_offset": -165.0,
"tx_enable": true,
"tx_notch_freq": 129000, /* [126..250] KHz */
"tx_freq_min": 863000000,
"tx_freq_max": 870000000
},
Expand Down
15 changes: 9 additions & 6 deletions lora_pkt_fwd/cfg/global_conf.json.PCB_E336.EU868.beacon
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"clksrc": 1, /* radio_1 provides clock to concentrator */
"lbt_cfg": {
"enable": false,
"rssi_target": 160, /* rssi in dBm = -lbt_rssi_target/2 */
"nb_channel": 1,
"start_freq": 869525000,
"scan_time_us": 5000,
"tx_delay_1ch_us": 4000000,
"tx_delay_2ch_us": 4000000
"rssi_target": -80, /* dBm */
"chan_cfg":[ /* 8 channels maximum */
{ "freq_hz": 867100000, "scan_time_us": 128 },
{ "freq_hz": 867300000, "scan_time_us": 5000 },
{ "freq_hz": 867500000, "scan_time_us": 128 },
{ "freq_hz": 869525000, "scan_time_us": 128 }
],
"sx127x_rssi_offset": -4 /* dB */
},
"antenna_gain": 0, /* antenna gain, in dBi */
"radio_0": {
Expand All @@ -18,6 +20,7 @@
"freq": 867500000,
"rssi_offset": -165.0,
"tx_enable": true,
"tx_notch_freq": 129000, /* [126..250] KHz */
"tx_freq_min": 863000000,
"tx_freq_max": 870000000
},
Expand Down
15 changes: 9 additions & 6 deletions lora_pkt_fwd/cfg/global_conf.json.PCB_E336.EU868.gps
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"clksrc": 1, /* radio_1 provides clock to concentrator */
"lbt_cfg": {
"enable": false,
"rssi_target": 160, /* rssi in dBm = -lbt_rssi_target/2 */
"nb_channel": 1,
"start_freq": 869525000,
"scan_time_us": 5000,
"tx_delay_1ch_us": 4000000,
"tx_delay_2ch_us": 4000000
"rssi_target": -80, /* dBm */
"chan_cfg":[ /* 8 channels maximum */
{ "freq_hz": 867100000, "scan_time_us": 128 },
{ "freq_hz": 867300000, "scan_time_us": 5000 },
{ "freq_hz": 867500000, "scan_time_us": 128 },
{ "freq_hz": 869525000, "scan_time_us": 128 }
],
"sx127x_rssi_offset": -4 /* dB */
},
"antenna_gain": 0, /* antenna gain, in dBi */
"radio_0": {
Expand All @@ -18,6 +20,7 @@
"freq": 867500000,
"rssi_offset": -165.0,
"tx_enable": true,
"tx_notch_freq": 129000, /* [126..250] KHz */
"tx_freq_min": 863000000,
"tx_freq_max": 870000000
},
Expand Down
15 changes: 9 additions & 6 deletions lora_pkt_fwd/global_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"clksrc": 1, /* radio_1 provides clock to concentrator */
"lbt_cfg": {
"enable": false,
"rssi_target": 160, /* rssi in dBm = -lbt_rssi_target/2 */
"nb_channel": 1,
"start_freq": 869525000,
"scan_time_us": 5000,
"tx_delay_1ch_us": 4000000,
"tx_delay_2ch_us": 4000000
"rssi_target": -80, /* dBm */
"chan_cfg":[ /* 8 channels maximum */
{ "freq_hz": 867100000, "scan_time_us": 128 },
{ "freq_hz": 867300000, "scan_time_us": 5000 },
{ "freq_hz": 867500000, "scan_time_us": 128 },
{ "freq_hz": 869525000, "scan_time_us": 128 }
],
"sx127x_rssi_offset": -4 /* dB */
},
"antenna_gain": 0, /* antenna gain, in dBi */
"radio_0": {
Expand All @@ -18,6 +20,7 @@
"freq": 867500000,
"rssi_offset": -166.0,
"tx_enable": true,
"tx_notch_freq": 129000, /* [126..250] KHz */
"tx_freq_min": 863000000,
"tx_freq_max": 870000000
},
Expand Down
173 changes: 142 additions & 31 deletions lora_pkt_fwd/inc/parson.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
Parson ( http://kgabis.github.com/parson/ )
Copyright (C) 2013 Krzysztof Gabis
Copyright (c) 2012 - 2016 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -27,49 +27,91 @@
#ifdef __cplusplus
extern "C"
{
#endif
#include <stddef.h> /* size_t */
#endif

#include <stddef.h> /* size_t */

#define PARSON_VERSION 20131130

/* Types and enums */
typedef struct json_object_t JSON_Object;
typedef struct json_array_t JSON_Array;
typedef struct json_value_t JSON_Value;

typedef enum json_value_type {
JSONError = 0,
enum json_value_type {
JSONError = -1,
JSONNull = 1,
JSONString = 2,
JSONNumber = 3,
JSONObject = 4,
JSONArray = 5,
JSONBoolean = 6
} JSON_Value_Type;
};
typedef int JSON_Value_Type;

enum json_result_t {
JSONSuccess = 0,
JSONFailure = -1
};
typedef int JSON_Status;

typedef void * (*JSON_Malloc_Function)(size_t);
typedef void (*JSON_Free_Function)(void *);

/* Call only once, before calling any other function from parson API. If not called, malloc and free
from stdlib will be used for all allocations */
void json_set_allocation_functions(JSON_Malloc_Function malloc_fun, JSON_Free_Function free_fun);


/* Parses first JSON value in a file, returns NULL in case of error */
JSON_Value * json_parse_file(const char *filename);
JSON_Value * json_parse_file(const char *filename);

/* Parses first JSON value in a file and ignores comments (/ * * / and //),
returns NULL in case of error */
JSON_Value * json_parse_file_with_comments(const char *filename);
JSON_Value * json_parse_file_with_comments(const char *filename);

/* Parses first JSON value in a string, returns NULL in case of error */
JSON_Value * json_parse_string(const char *string);
JSON_Value * json_parse_string(const char *string);

/* Parses first JSON value in a string and ignores comments (/ * * / and //),
returns NULL in case of error */
JSON_Value * json_parse_string_with_comments(const char *string);

/* JSON Object */
JSON_Value * json_parse_string_with_comments(const char *string);

/* Serialization */
size_t json_serialization_size(const JSON_Value *value); /* returns 0 on fail */
JSON_Status json_serialize_to_buffer(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename);
char * json_serialize_to_string(const JSON_Value *value);

/* Pretty serialization */
size_t json_serialization_size_pretty(const JSON_Value *value); /* returns 0 on fail */
JSON_Status json_serialize_to_buffer_pretty(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *filename);
char * json_serialize_to_string_pretty(const JSON_Value *value);

void json_free_serialized_string(char *string); /* frees string from json_serialize_to_string and json_serialize_to_string_pretty */

/* Comparing */
int json_value_equals(const JSON_Value *a, const JSON_Value *b);

/* Validation
This is *NOT* JSON Schema. It validates json by checking if object have identically
named fields with matching types.
For example schema {"name":"", "age":0} will validate
{"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
In case of arrays, only first value in schema is checked against all values in tested array.
Empty objects ({}) validate all objects, empty arrays ([]) validate all arrays,
null validates values of every type.
*/
JSON_Status json_validate(const JSON_Value *schema, const JSON_Value *value);

/*
* JSON Object
*/
JSON_Value * json_object_get_value (const JSON_Object *object, const char *name);
const char * json_object_get_string (const JSON_Object *object, const char *name);
JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
JSON_Array * json_object_get_array (const JSON_Object *object, const char *name);
double json_object_get_number (const JSON_Object *object, const char *name);
int json_object_get_boolean(const JSON_Object *object, const char *name);
double json_object_get_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
int json_object_get_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */

/* dotget functions enable addressing values with dot notation in nested objects,
just like in structs or c++/java/c# objects (e.g. objectA.objectB.value).
Expand All @@ -79,31 +121,100 @@ JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *
const char * json_object_dotget_string (const JSON_Object *object, const char *name);
JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name);
double json_object_dotget_number (const JSON_Object *object, const char *name);
int json_object_dotget_boolean(const JSON_Object *object, const char *name);
double json_object_dotget_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
int json_object_dotget_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */

/* Functions to get available names */
size_t json_object_get_count(const JSON_Object *object);
const char * json_object_get_name (const JSON_Object *object, size_t index);

/* JSON Array */

/* Creates new name-value pair or frees and replaces old value with a new one.
* json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string);
JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number);
JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean);
JSON_Status json_object_set_null(JSON_Object *object, const char *name);

/* Works like dotget functions, but creates whole hierarchy if necessary.
* json_object_dotset_value does not copy passed value so it shouldn't be freed afterwards. */
JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value);
JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string);
JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number);
JSON_Status json_object_dotset_boolean(JSON_Object *object, const char *name, int boolean);
JSON_Status json_object_dotset_null(JSON_Object *object, const char *name);

/* Frees and removes name-value pair */
JSON_Status json_object_remove(JSON_Object *object, const char *name);

/* Works like dotget function, but removes name-value pair only on exact match. */
JSON_Status json_object_dotremove(JSON_Object *object, const char *key);

/* Removes all name-value pairs in object */
JSON_Status json_object_clear(JSON_Object *object);

/*
*JSON Array
*/
JSON_Value * json_array_get_value (const JSON_Array *array, size_t index);
const char * json_array_get_string (const JSON_Array *array, size_t index);
JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
JSON_Array * json_array_get_array (const JSON_Array *array, size_t index);
double json_array_get_number (const JSON_Array *array, size_t index);
int json_array_get_boolean(const JSON_Array *array, size_t index);
double json_array_get_number (const JSON_Array *array, size_t index); /* returns 0 on fail */
int json_array_get_boolean(const JSON_Array *array, size_t index); /* returns -1 on fail */
size_t json_array_get_count (const JSON_Array *array);

/* JSON Value */
/* Frees and removes value at given index, does nothing and returns JSONFailure if index doesn't exist.
* Order of values in array may change during execution. */
JSON_Status json_array_remove(JSON_Array *array, size_t i);

/* Frees and removes from array value at given index and replaces it with given one.
* Does nothing and returns JSONFailure if index doesn't exist.
* json_array_replace_value does not copy passed value so it shouldn't be freed afterwards. */
JSON_Status json_array_replace_value(JSON_Array *array, size_t i, JSON_Value *value);
JSON_Status json_array_replace_string(JSON_Array *array, size_t i, const char* string);
JSON_Status json_array_replace_number(JSON_Array *array, size_t i, double number);
JSON_Status json_array_replace_boolean(JSON_Array *array, size_t i, int boolean);
JSON_Status json_array_replace_null(JSON_Array *array, size_t i);

/* Frees and removes all values from array */
JSON_Status json_array_clear(JSON_Array *array);

/* Appends new value at the end of array.
* json_array_append_value does not copy passed value so it shouldn't be freed afterwards. */
JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value);
JSON_Status json_array_append_string(JSON_Array *array, const char *string);
JSON_Status json_array_append_number(JSON_Array *array, double number);
JSON_Status json_array_append_boolean(JSON_Array *array, int boolean);
JSON_Status json_array_append_null(JSON_Array *array);

/*
*JSON Value
*/
JSON_Value * json_value_init_object (void);
JSON_Value * json_value_init_array (void);
JSON_Value * json_value_init_string (const char *string); /* copies passed string */
JSON_Value * json_value_init_number (double number);
JSON_Value * json_value_init_boolean(int boolean);
JSON_Value * json_value_init_null (void);
JSON_Value * json_value_deep_copy (const JSON_Value *value);
void json_value_free (JSON_Value *value);

JSON_Value_Type json_value_get_type (const JSON_Value *value);
JSON_Object * json_value_get_object (const JSON_Value *value);
JSON_Array * json_value_get_array (const JSON_Value *value);
const char * json_value_get_string (const JSON_Value *value);
double json_value_get_number (const JSON_Value *value);
int json_value_get_boolean(const JSON_Value *value);
void json_value_free (JSON_Value *value);


/* Same as above, but shorter */
JSON_Value_Type json_type (const JSON_Value *value);
JSON_Object * json_object (const JSON_Value *value);
JSON_Array * json_array (const JSON_Value *value);
const char * json_string (const JSON_Value *value);
double json_number (const JSON_Value *value);
int json_boolean(const JSON_Value *value);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions lora_pkt_fwd/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ configured in 2 different ways:
- Real time mode: when GPS is disabled, the value read in sample register is
the actual concentrator counter value.
- PPS mode: when GPS is enabled, the value read in sample register is the
value
that the concentrator counter had when last GPS’s PPS occurred. So this changes
every second only.
value that the concentrator counter had when last GPS’s PPS occurred. So
this changes every second only.
As in our case GPS is enabled (LGW_GPS_EN==1), we need to have a way to get the
actual concentrator current time, at any time.
For this, a new thread has been added to the packet forwarder (thread_timersync)
Expand Down
Loading

0 comments on commit fcd2565

Please sign in to comment.