Added no telemetry geofence for China, NK and Yemen. Added test case

master
Richard Meadows 2015-07-22 22:33:51 +01:00
rodzic 276d50f82f
commit 2be1e3344e
10 zmienionych plików z 1350 dodań i 87 usunięć

Wyświetl plik

@ -0,0 +1,16 @@
/**
* Autogenerated telemetry zone structures. See sim/geofence
*/
#ifndef GEOFENCE_TELEMETRY_H
#define GEOFENCE_TELEMETRY_H
#include <stdbool.h>
#include "samd20.h"
const int32_t* no_telem_outlines[6];
const uint32_t no_telem_outline_lengths[6];
#endif /* GEOFENCE_APRS_H */

Wyświetl plik

@ -26,14 +26,14 @@
#define LOCATION_H
#include <stdbool.h>
#include "samd20.h"
bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon, float lat);
bool telemetry_location_tx_allow(void);
void telemetry_location_update(float lon, float lat);
bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon, float lat);
bool aprs_location_tx_allow(void);
int32_t aprs_location_frequency(void);
void aprs_location_update(float lon, float lat);
#endif /* LOCATION_H */

Wyświetl plik

@ -0,0 +1,329 @@
/**
* Autogenerated telemetry zone structures. See sim/geofence
*/
#include <stdbool.h>
#include "samd20.h"
#include "geofence_telemetry.h"
/* Longitude, Latitude */
const int32_t no_telemetry_outline_1[] = {
126460837, 37610364,
126493599, 37782547,
126516030, 37604675,
};
const int32_t no_telemetry_outline_2[] = {
114139006, 22348450,
114015398, 22511902,
114266028, 22540970,
114267986, 22295536,
};
const int32_t no_telemetry_outline_3[] = {
113851581, 22220447,
114043919, 22333416,
113877318, 22210452,
};
const int32_t no_telemetry_outline_4[] = {
44009777, 12166151,
45212478, 12409143,
45865185, 12932397,
48822870, 13638045,
49552005, 14246210,
51800875, 14944831,
52542093, 15354487,
52647833, 15979852,
53372423, 16314819,
53532198, 16695168,
53085672, 16648384,
51977627, 18996149,
49041996, 18581784,
48172175, 18156923,
47143613, 16946661,
46727666, 17265581,
43417994, 17516244,
43033578, 16550382,
42799324, 16371788,
42645209, 16802934,
42368681, 16494948,
42101729, 15280713,
42557893, 14457642,
42243016, 13627775,
43384577, 12269216,
44006939, 12166133,
};
const int32_t no_telemetry_outline_5[] = {
53722470, 11876992,
54654751, 12110599,
54950197, 12645713,
54330405, 13081775,
53441845, 13146754,
52876922, 12439418,
53719631, 11876974,
};
const int32_t no_telemetry_outline_6[] = {
78946013, 31337204,
81110324, 30036796,
81417126, 30337602,
82043395, 30326778,
83583503, 29183591,
84101355, 29219973,
84228682, 28911749,
85159067, 28592227,
85122425, 28315946,
85678311, 28277447,
85994572, 27910409,
86136991, 28114327,
87290715, 27821914,
88756209, 28039679,
88891343, 27316052,
89897896, 28294138,
91977667, 27730349,
92664348, 27948938,
93251954, 28629462,
94622989, 29312422,
95389243, 29037396,
96035303, 29447143,
96355795, 29249063,
96137154, 28922601,
96435691, 29050681,
96580904, 28763669,
96281486, 28412060,
97322508, 28217986,
97658873, 28500016,
98298833, 27550100,
98651161, 27572444,
98656281, 25863559,
97819483, 25251838,
97564559, 23911046,
98835082, 24121207,
98863756, 23191239,
99507130, 22959139,
99192989, 22125985,
99917705, 22028008,
100214733, 21462974,
101120675, 21746112,
101247903, 21197309,
101704777, 21150124,
101524476, 22253648,
101707517, 22486585,
102127434, 22379198,
102470878, 22750908,
102981957, 22448263,
103620210, 22782040,
103941483, 22540068,
105275356, 23345186,
105842974, 22922806,
106541846, 22908343,
106780276, 22778891,
106550425, 22501386,
106663540, 21978909,
107972664, 21507930,
107375904, 21187275,
109224601, 21010445,
109429660, 20368542,
108277534, 19518784,
108259892, 18457559,
108861924, 17969540,
109847080, 17847857,
110783376, 18459591,
111438517, 19517455,
110986826, 20987264,
112097072, 21352715,
112898989, 21178546,
113976312, 22095541,
116669596, 22572425,
119351040, 24810410,
120138925, 25168636,
120092788, 25976655,
121105764, 27563350,
121986113, 28074608,
122103218, 28775217,
122819507, 29720600,
122658655, 30290044,
121991494, 30532329,
122323071, 30865072,
122234407, 32070475,
121346396, 32851299,
120630771, 34492113,
119761902, 34961222,
121316473, 36316843,
122830718, 36686311,
123078833, 37545618,
120741219, 38189241,
120004699, 37973643,
119448274, 37486048,
119280765, 38273881,
118190578, 38515657,
118061949, 38768482,
119235660, 38896214,
119748149, 39536612,
120762868, 39963606,
121364632, 40546367,
121751850, 40479383,
121637639, 40357637,
120872579, 39710182,
120661682, 38968083,
120992334, 38405676,
121866197, 38556650,
123005216, 39271515,
124212749, 39503891,
124834500, 39158929,
124269837, 38005614,
125199764, 37390078,
126676711, 37426137,
126563362, 37716504,
127009636, 38240504,
128106263, 38327320,
128374617, 38623453,
128595450, 38219069,
128798784, 38739248,
127996543, 39558463,
130062354, 40646751,
130161240, 41541861,
131052360, 42107932,
131047491, 42529526,
131609010, 43055711,
131158325, 42625997,
130709365, 42656412,
130687348, 42302532,
130424779, 42727027,
131086182, 43038093,
131255272, 44071572,
130981699, 44844314,
131851825, 45326843,
133113455, 45130729,
133861311, 46247772,
134167655, 47302176,
134752314, 47715403,
134680799, 48210438,
134293383, 48373426,
133020129, 48064403,
132476280, 47714966,
130961954, 47709310,
130553139, 48861203,
130196005, 48891641,
129498167, 49388815,
127999606, 49568602,
127550790, 49801789,
127590271, 50208975,
126341667, 52362021,
125649048, 53042265,
123607779, 53546520,
122337777, 53485001,
120985462, 53284576,
120094504, 52787217,
120067527, 52632908,
120656121, 52566659,
120749816, 52096509,
120066907, 51600671,
119163705, 50406015,
119259825, 50066400,
117873455, 49513489,
116683295, 49823780,
115525070, 48130855,
115898221, 47686932,
116760550, 47869788,
117350797, 47652182,
117768397, 47987868,
118498377, 47983996,
119711166, 47149985,
119867230, 46672186,
118843932, 46760217,
117438132, 46586247,
117333433, 46362026,
116562580, 46289804,
115681027, 45458253,
114560163, 45389992,
113586991, 44745714,
111898006, 45064043,
111402216, 44367264,
111933139, 43711439,
111007200, 43341384,
110400424, 42773668,
109443161, 42455958,
106770045, 42288734,
104982047, 41595520,
104498250, 41658694,
104498250, 41876974,
103711110, 41751297,
102156684, 42158094,
101495281, 42538747,
96385457, 42720338,
95350283, 44278070,
94711968, 44350830,
93516229, 44944461,
90877266, 45196104,
90661832, 45525226,
91028893, 46566071,
90330641, 47655150,
89479218, 48029057,
89047667, 48002544,
87979723, 48555121,
87762475, 49165809,
86885989, 49090568,
86549417, 48528612,
85749368, 48385077,
85484787, 47063505,
84786168, 46830733,
83029431, 47185952,
82315208, 45594943,
82611625, 45424250,
82521452, 45125483,
81692046, 45349372,
79950186, 44944078,
80481522, 44714631,
80355227, 44097278,
80785745, 43161546,
80390208, 43043134,
80538933, 42873505,
80165000, 42665509,
80235132, 42043475,
78742608, 41560047,
78123426, 41075632,
76986644, 41039145,
76318522, 40352263,
75677161, 40305808,
75520791, 40627542,
74020524, 40059358,
73607317, 39229202,
73801622, 38606890,
74277460, 38659757,
74835978, 38404318,
75118804, 37385670,
74376158, 37137370,
75840259, 36649701,
75912295, 36048958,
76177810, 35810523,
76551275, 35887060,
77008078, 35189300,
78042703, 35479795,
78281970, 34653928,
78970088, 34302603,
78726645, 34013398,
79219380, 32501061,
78389660, 32519870,
78899499, 31331367,
};
const int32_t* no_telem_outlines[] = {
no_telemetry_outline_1,
no_telemetry_outline_2,
no_telemetry_outline_3,
no_telemetry_outline_4,
no_telemetry_outline_5,
no_telemetry_outline_6,
};
const uint32_t no_telem_outline_lengths[] = {
3,
4,
3,
26,
7,
242,
};

Wyświetl plik

@ -28,9 +28,11 @@
#include "samd20.h"
#include "geofence_aprs.h"
#include "geofence_telemetry.h"
int32_t current_aprs_zone = -2, current_aprs_zone_outline = -2;
uint32_t _altitude = 0;
int32_t current_no_telem_outline = -1;
#define polyX(i) (poly[(i*2)+0])
#define polyY(i) (poly[(i*2)+1])
@ -49,8 +51,8 @@ uint32_t _altitude = 0;
* Note that division by zero is avoided because the division is
* protected by the "if" clause which surrounds it.
*/
bool point_in_polygon(const int32_t* poly, uint32_t points, int32_t x, int32_t y) {
bool point_in_polygon(const int32_t* poly, uint32_t points, int32_t x, int32_t y)
{
uint32_t i, j = points-1;
bool oddNodes = false;
@ -72,8 +74,8 @@ bool point_in_polygon(const int32_t* poly, uint32_t points, int32_t x, int32_t y
/**
* Returns if a latitude and longitude is in a polygon
*/
bool latlon_in_polygon(const int32_t* poly, uint32_t points, float lon, float lat) {
bool latlon_in_polygon(const int32_t* poly, uint32_t points, float lon, float lat)
{
int32_t x = (int32_t)round(lon * 1000 * 1000); // longitude: µdegrees
int32_t y = (int32_t)round(lat * 1000 * 1000); // latitude: µdegrees
@ -81,23 +83,78 @@ bool latlon_in_polygon(const int32_t* poly, uint32_t points, float lon, float la
}
/**
* ============================== Telemetry ============================
*/
/**
* Returns if a latitude and longitude is in a given no telem outline
*/
bool latlon_in_no_telem_zone(int32_t no_telem_outline, float lon, float lat)
{
return latlon_in_polygon(
no_telem_outlines[no_telem_outline],
no_telem_outline_lengths[no_telem_outline],
lon, lat);
}
/**
* Return if telemetry should be transmitted in the current zone
*/
bool telemetry_location_tx_allow(void)
{
/* Outside no telem zone */
return (current_no_telem_outline == -1);
}
/**
* Updates the current telemetry location based on the current lat/lon
*/
void telemetry_location_update(float lon, float lat)
{
uint32_t outline;
/* Were we in a telemetry outline last time? */
if (current_no_telem_outline >= 0) {
/* Are we still in this outline? */
if (latlon_in_no_telem_zone(current_no_telem_outline, lon, lat)) {
return; /* Still in this outline */
}
}
/* Check all the no telemetry outlines */
while (sizeof(no_telem_outlines)/sizeof(int32_t*) != 6);
for (outline = 0; outline < sizeof(no_telem_outlines) / sizeof(int32_t*); outline++) {
if (latlon_in_no_telem_zone(outline, lon, lat)) { /* If we're in this zone */
/* Record the current outline */
current_no_telem_outline = outline;
return; /* Go home. We return the first outline we match */
}
}
}
/**
* ============================== APRS =================================
*/
/**
* Returns if a latitude and longitude is in a given aprs zone outline
*/
bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon, float lat) {
bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon, float lat)
{
return latlon_in_polygon(
aprs_zones[aprs_zone].outlines[aprs_zone_outline],
aprs_zones[aprs_zone].outline_lengths[aprs_zone_outline],
lon, lat);
}
/**
* Returns if aprs should be transmitted in the current zone
*/
bool aprs_location_tx_allow(void) {
bool aprs_location_tx_allow(void)
{
/* Not in any zone, or in a zone other than Alpha */
return (current_aprs_zone == -1) || (current_aprs_zone > 0);
}
@ -106,21 +163,19 @@ bool aprs_location_tx_allow(void) {
*
* Where aprs is not allowed this function is unspecified
*/
int32_t aprs_location_frequency(void) {
int32_t aprs_location_frequency(void)
{
if (current_aprs_zone >= 0) {
return aprs_zones[current_aprs_zone].frequency;
}
return 144800000;
}
/**
* Updates the aprs location based on the current lat/lon
*/
void aprs_location_update(float lon, float lat) {
void aprs_location_update(float lon, float lat)
{
uint32_t z, outline;
/* Were we in an aprs zone last time? */

Wyświetl plik

@ -0,0 +1,26 @@
#ifndef __verification__
#define __verification__
#endif
/****************************//* location_telemetry_tc *//****************************/
/* Checks the location is returning the right things etc. etc */
#include "location.h"
/* Parameters in */
struct location_telemetry_tc_params {
float lat;
float lon;
} location_telemetry_tc_params;
/* Results out */
struct location_telemetry_tc_results {
bool tx_allow;
} location_telemetry_tc_results;
/* Function */
__verification__ void location_telemetry_tc(void) {
telemetry_location_update(location_telemetry_tc_params.lon, location_telemetry_tc_params.lat);
location_telemetry_tc_results.tx_allow = telemetry_location_tx_allow();
}

Wyświetl plik

@ -0,0 +1,67 @@
#!/usr/bin/env python
# ------------------------------------------------------------------------------
# Imports
# ------------------------------------------------------------------------------
import sys
sys.path.append("./test")
import main
from random import randint
# ------------------------------------------------------------------------------
# Test Script
# ------------------------------------------------------------------------------
class location_telemetry_tc:
def __init__(self):
self.name = self.__class__.__name__
# Load CSV file into memory
self.locations = []
with open("./test/tc/location_telemetry_tc_list.csv") as f:
for line in f:
if line[0] is not "#" and len(line) is not 0:
parts = [x.strip() for x in line.split(',')]
if len(parts) is 4:
self.locations.append({
'name': parts[0],
'tx_allow': float(parts[1]),
'lat': float(parts[2]),
'lon': float(parts[3])
})
self.locations_index = 0
def get_test(self):
"""Returns some suitable test parameters"""
params = main.struct_location_telemetry_tc_params()
if self.locations_index >= len(self.locations):
return None
params.lon = self.locations[self.locations_index]['lon']
params.lat = self.locations[self.locations_index]['lat']
return params
def is_correct(self, params, result, print_info):
"""Returns if a result is correct for the given parameters"""
name = self.locations[self.locations_index]['name']
expected_tx_allow = self.locations[self.locations_index]['tx_allow']
self.locations_index += 1
tx_allow = result['tx_allow']
if tx_allow == expected_tx_allow:
print_info("{}: {}".format(name,
"Permitted" if tx_allow else "Not Permitted"))
return True
else:
print_info("{} ({:.1f}, {:.1f}): Expected {}, Geofence {}".format(
name, params.lat, params.lon,
"Permitted" if expeced_tx_allow else "Not Permitted",
"Permitted" if tx_allow else "Not Permitted"))
return False

Wyświetl plik

@ -0,0 +1,37 @@
# name,?,lat,lon
# Permitted
UK,1,52,-1
UK,1,52,0
UK,1,52,1
Wales,1,52,-4
Lewis,1,58,-6.5
NI,1,54.5,-6.5
France,1,49,2
Portugal,1,40,-8
Italy,1,43,12
Romania,1,46,24
Sweden,1,58,12
Stockholm,1,59.3,18
Malmo,1,55.6,13
Copenhagen,1,55.7,12.5
Amsterdam,1,52.4,5.7
Germany,1,52,9
Poland,1,51,20
Russia,1,55,37
Mongolia,1,48,107
Vladivostok,1,43,132
Armenia,1,40,44
Africa,1,9,2
LA,1,34,-118
New York,1,41,-74
Canada,1,44,-76
South Korea,1,37,128
Japan,1,36,140
Thailand,1,14,100
# Not permitted
West China,0,39,80
Beijing,0,40,116
Hong Kong,0,22.4,114.1
Yemen,0,15,44
NK,0,39,126
1 # name,?,lat,lon
2 # Permitted
3 UK,1,52,-1
4 UK,1,52,0
5 UK,1,52,1
6 Wales,1,52,-4
7 Lewis,1,58,-6.5
8 NI,1,54.5,-6.5
9 France,1,49,2
10 Portugal,1,40,-8
11 Italy,1,43,12
12 Romania,1,46,24
13 Sweden,1,58,12
14 Stockholm,1,59.3,18
15 Malmo,1,55.6,13
16 Copenhagen,1,55.7,12.5
17 Amsterdam,1,52.4,5.7
18 Germany,1,52,9
19 Poland,1,51,20
20 Russia,1,55,37
21 Mongolia,1,48,107
22 Vladivostok,1,43,132
23 Armenia,1,40,44
24 Africa,1,9,2
25 LA,1,34,-118
26 New York,1,41,-74
27 Canada,1,44,-76
28 South Korea,1,37,128
29 Japan,1,36,140
30 Thailand,1,14,100
31 # Not permitted
32 West China,0,39,80
33 Beijing,0,40,116
34 Hong Kong,0,22.4,114.1
35 Yemen,0,15,44
36 NK,0,39,126

Wyświetl plik

@ -39,6 +39,7 @@
#include "times_two.h"
#include "osc8m_calib.h"
#include "location_aprs.h"
#include "location_telemetry.h"
#include "mem_write_page.h"
#include "mem_write_all.h"
#include "location_aprs_file.h"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long