Skip to content

Commit 132dada

Browse files
authored
Merge pull request #6 from electricimp/IDC-develop
Test file modified with new lib,v1.0.2 and test case modified for the new library changes
2 parents 8aa5025 + a84c086 commit 132dada

File tree

4 files changed

+64
-32
lines changed

4 files changed

+64
-32
lines changed

Diff for: .impt.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"deviceGroupId": "f3ef6490-0ffc-cb1a-4ede-03718f9aaf86",
3-
"deviceGroupName" : "impFarm F",
2+
"deviceGroupId": "23ad0139-0262-4475-e7bd-230c9a37ed55",
3+
"deviceGroupName": "impFarm F",
44
"timeout": 450,
55
"stopOnFail": false,
66
"allowDisconnect": false,
@@ -11,4 +11,4 @@
1111
],
1212
"deviceFile": "./tests/bg96_gps.device.nut",
1313
"agentFile": "./tests/bg96_gps.agent.nut"
14-
}
14+
}

Diff for: bg96_gps.device.lib.nut

+5-3
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,18 @@ BG96_GPS <- {
390390

391391
if (_session != null) {
392392
local t = _session.assist.read();
393+
local data = {};
393394
if (t.status == 0) {
394-
local data = {};
395395
data.time <- _getValidTime(t.injecteddatatime,t.xtradatadurtime);
396396
data.valid <- data.time > 0;
397397
local msg = data.valid ? "GNSS assist data valid" : "GNSS assist data invalid";
398398
_notify(msg, data);
399399
return data.valid;
400400
} else {
401-
_notify("Assist data not present or invalid", null, t.status);
402-
return false;
401+
local msg = "Assist data not present or invalid";
402+
data.valid <- false;
403+
_notify(msg, data);
404+
return data.valid;
403405
}
404406
} else {
405407
_notify("GNSS not enabled", null, 1);

Diff for: tests/bg96_gps.device.nut

+24-11
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const BG96_GPS_EN_POLLING_TIMEOUT = 3;
116116
*/
117117
BG96_GPS <- {
118118

119-
VERSION = "1.0.1",
119+
VERSION = "1.0.2",
120120

121121
/*
122122
* PUBLIC PROPERTIES
@@ -390,14 +390,19 @@ BG96_GPS <- {
390390

391391
if (_session != null) {
392392
local t = _session.assist.read();
393-
local valid = (t.status == 0);
394-
if ("xtradatadurtime" in t && t.xtradatadurtime == 0) valid = false;
395-
local msg = valid ? "GNSS assist data valid" : "GNSS assist data invalid";
396393
local data = {};
397-
data.valid <- valid;
398-
if (valid) data.time <- _getValidTime(t.injecteddatatime);
399-
_notify(msg, data);
400-
return valid;
394+
if (t.status == 0) {
395+
data.time <- _getValidTime(t.injecteddatatime,t.xtradatadurtime);
396+
data.valid <- data.time > 0;
397+
local msg = data.valid ? "GNSS assist data valid" : "GNSS assist data invalid";
398+
_notify(msg, data);
399+
return data.valid;
400+
} else {
401+
local msg = "Assist data not present or invalid";
402+
data.valid <- false;
403+
_notify(msg, data);
404+
return data.valid;
405+
}
401406
} else {
402407
_notify("GNSS not enabled", null, 1);
403408
return false;
@@ -599,7 +604,7 @@ BG96_GPS <- {
599604
// Get assist data remaining validity period in mins
600605
// 'uploadDate' is <= now, format: YYYY/MM/DD,hh:mm:ss
601606
// Returns -99 on error
602-
_getValidTime = function(uploadDate, now = null) {
607+
_getValidTime = function(uploadDate,validDuration, now = null) {
603608
local invalid = -1;
604609
// Convert date string to date table
605610
local date_parts = split(uploadDate, ","); // YYYY/MM/DD,hh:mm:ss
@@ -615,8 +620,8 @@ BG96_GPS <- {
615620
if (now == null) now = date();
616621
if (now.year - old.year > 1) return invalid;
617622
if (now.year < old.year || (now.year == old.year && old.month > now.month)) return invalid;
618-
local remaining = _getTime(now) - _getTime(old);
619-
return (remaining < 10080 ? remaining : invalid);
623+
local remaining = _getTime(old) + validDuration -_getTime(now) ;
624+
return (remaining > 0 ? remaining : invalid);
620625
},
621626

622627
// FROM 0.2.1
@@ -663,3 +668,11 @@ BG96_GPS <- {
663668
}
664669

665670
}
671+
672+
adb <- null;
673+
674+
agent.on("set.assist.data", function(assistData) {
675+
adb = assistData;
676+
});
677+
678+
agent.send("get.assist.data", true);

Diff for: tests/device-02.test.nut

+32-15
Original file line numberDiff line numberDiff line change
@@ -51,59 +51,75 @@ class GNSSTestCase extends ImpTestCase {
5151

5252
function testGetValidTime() {
5353

54-
// Valid results should come in at less than 10080 minutes
54+
// Valid results should come in at less than "validDuration" minutes
5555

5656
// Set 'now' for consistent testing: 23/02/2021,15:57:00
5757
local nowTime = {"year": 2021, "month": 1, "day": 23, "hour": 15, "min": 57};
5858

59-
// Ten days ago -- data invalid
59+
// Ten days ago and 7 day validity -- data invalid
6060
local testDate = "2021/02/13,15:00:00"
61-
local result = BG96_GPS._getValidTime(testDate, nowTime);
61+
local validDuration = 10080 //7*24*60 minutes
62+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
6263
//this.info(result);
6364
this.assertEqual(result, -1);
6465

65-
// 4 hrs, 45 mins ago -- data valid
66+
// Ten days ago and 11 day validity-- data valid
67+
local testDate = "2021/02/13,15:00:00"
68+
local validDuration = 15840
69+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
70+
//this.info(result);
71+
this.assert(result < validDuration && result != -1);
72+
73+
// 4 hrs, 45 mins ago and 7 day vailidy-- data valid
6674
local testDate = "2021/02/23,11:12:00"
67-
local result = BG96_GPS._getValidTime(testDate, nowTime);
75+
local validDuration = 10080
76+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
6877
//this.info(result);
69-
this.assert(result < 10080 && result != -1);
78+
this.assert(result < validDuration && result != -1);
7079

7180
// Ancient time
7281
testDate = "1980/01/01,00:00:00"
73-
result = BG96_GPS._getValidTime(testDate, nowTime);
82+
local validDuration = 10080
83+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
7484
//this.info(result);
7585
this.assertEqual(result, -1);
7686

7787
// Future time
7888
testDate = "2021/05/15,13:00:00"
79-
result = BG96_GPS._getValidTime(testDate, nowTime);
89+
local validDuration = 10080
90+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
8091
//this.info(result);
8192
this.assertEqual(result, -1);
8293

8394
// Just in the zone
8495
testDate = "2021/02/16,16:01:00"
85-
result = BG96_GPS._getValidTime(testDate, nowTime);
96+
local validDuration = 10080
97+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
98+
8699
//this.info(result);
87-
this.assert(result < 10080 && result != -1);
100+
this.assert(result < validDuration && result != -1);
88101

89102
// Cross-month valid
90103
nowTime = {"year": 2021, "month": 4, "day": 4, "hour": 11, "min": 57};
91104
testDate = "2021/04/30,12:12:00"
92-
result = BG96_GPS._getValidTime(testDate, nowTime);
105+
local validDuration = 10080
106+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
93107
//this.info(result);
94-
this.assert(result < 10080 && result != -1);
108+
this.assert(result < validDuration && result != -1);
95109

96110
// Cross-month valid -- just
97111
nowTime = {"year": 2021, "month": 4, "day": 4, "hour": 11, "min": 57};
98112
testDate = "2021/04/27,12:12:00"
99-
result = BG96_GPS._getValidTime(testDate, nowTime);
113+
local validDuration = 10080
114+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
100115
//this.info(result);
101-
this.assert(result < 10080 && result != -1);
116+
this.assert(result < validDuration && result != -1);
102117

103118
// Cross-month invalid
104119
nowTime = {"year": 2021, "month": 4, "day": 4, "hour": 11, "min": 57};
105120
testDate = "2021/04/27,09:22:00"
106-
result = BG96_GPS._getValidTime(testDate, nowTime);
121+
local validDuration = 10080
122+
local result = BG96_GPS._getValidTime(testDate,validDuration,nowTime);
107123
//this.info(result);
108124
this.assertEqual(result, -1);
109125
}
@@ -112,6 +128,7 @@ class GNSSTestCase extends ImpTestCase {
112128
function tearDown() {
113129

114130
// TEST WE CAN DISABLE GNSS
131+
imp.sleep(4); // A small delay is introduced here to ensure there is enough time to update the assist data in the modem; otherwise, test3 will fail.
115132
local result = BG96_GPS.disableGNSS();
116133
this.assert(result);
117134
}

0 commit comments

Comments
 (0)