Skip to content

Commit d1146d1

Browse files
author
betzrhodes
authored
Merge pull request #14 from electricimp/develop
Update CI
2 parents 8d2a17b + a936adf commit d1146d1

8 files changed

+113
-90
lines changed

Diff for: .dummy.nut

Whitespace-only changes.

Diff for: .editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ build/*
66
logs/*
77
**/*.bak
88
**/*.bkp
9+
.impt.git.auth
10+
.builder-cache

Diff for: .impt.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"deviceGroupId": "3e4a50eb-0fc8-cab6-41b9-3e02ced9270e",
3+
"deviceGroupName" : "impFarm K",
4+
"timeout": 60,
5+
"stopOnFail": false,
6+
"allowDisconnect": false,
7+
"builderCache": true,
8+
"testFiles": [
9+
"*.test.nut",
10+
"tests/**/*.test.nut"
11+
],
12+
"deviceFile": "SPIFlashLogger.device.lib.nut",
13+
"githubConfig": ".impt.git.auth"
14+
}
15+

Diff for: .imptest

-14
This file was deleted.

Diff for: .imptest-auth.enc

-2
This file was deleted.

Diff for: .travis.yml

-14
This file was deleted.

Diff for: README.md

+84-60
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ SPIFlashLogger uses the [Serializer library](https://developer.electricimp.com/l
88

99
**To add this library to your project, place the line** `#require "SPIFlashLogger.device.lib.nut:2.2.0"` **at the top of your device code.**
1010

11-
## Memory Efficiency ##
11+
![Build Status](https://cse-ci.electricimp.com/app/rest/builds/buildType:(id:SpiFlashLogger_BuildAndTest)/statusIcon)
12+
13+
### Memory Efficiency ###
1214

1315
SPIFlashLogger operates on 4KB sectors and 256-byte chunks. Objects need not be aligned with chunks or sectors. Some necessary overhead is added to the beginning of each sector, as well as each serialized object (assuming you are using the standard [Serializer library](https://developer.electricimp.com/libraries/utilities/serializer)). The overhead includes:
1416

@@ -21,7 +23,7 @@ SPIFlashLogger operates on 4KB sectors and 256-byte chunks. Objects need not be
2123

2224
### Constructor: SPIFlashLogger(*[start][, end][, spiflash][, serializer]*) ###
2325

24-
SPIFlashLogger’s constructor takes four parameters, all of which are optional:
26+
#### Parameters ####
2527

2628
| Parameter | Default Value | Description |
2729
| --- | --- | --- |
@@ -30,6 +32,8 @@ SPIFlashLogger’s constructor takes four parameters, all of which are optional:
3032
| *spiflash* | **hardware.spiflash** | **hardware.spiflash**, or an object with an equivalent interface such as the [SPIFlash](https://developer.electricimp.com/libraries/hardware/spiflash) library |
3133
| *serializer* | Serializer class | The static [Serializer library](https://developer.electricimp.com/libraries/hardware/spiflash), or an object with an equivalent interface |
3234

35+
#### Example ####
36+
3337
```squirrel
3438
// Initializing a SPIFlashLogger on an imp003+
3539
#require "Serializer.class.nut:1.0.0"
@@ -78,21 +82,25 @@ This method writes any serializable object to the memory allocated for SPIFlashL
7882

7983
If the provided object can not be serialized, the exception is thrown by the underlying serializer class.
8084

85+
#### Example ####
86+
8187
```squirrel
8288
function readAndSleep() {
83-
// Read and log the data
84-
local data = getData();
85-
logger.write(data);
89+
// Read and log the data
90+
local data = getData();
91+
logger.write(data);
8692
87-
// Go to sleep for an hour
88-
imp.onidle(function() { server.deepsleepfor(3600); });
93+
// Go to sleep for an hour
94+
imp.onidle(function() { server.deepsleepfor(3600); });
8995
}
9096
```
9197

9298
### read(*onData[, onFinish][, step][, skip]*) ###
9399

94100
This method reads objects from the logger asynchronously. This mechanism is intended for the asynchronous processing of each log object, such as sending data to the agent and waiting for an acknowledgement.
95101

102+
#### Parameters ####
103+
96104
| Parameter | Data Type | Required? | Description |
97105
| --- | --- | --- | --- |
98106
| *onData* | Function | Yes | A callback which provides the object which has been read from the logger (see below) |
@@ -120,23 +128,27 @@ As a potential use case, one might log two versions of each message: a short, co
120128

121129
**Note** The logger does not erase objects when they are read, but each object can be erased in the *onData* callback by passing *address* to the *erase()* method.
122130

131+
#### Example ####
132+
123133
```squirrel
124134
logger.read(
125-
// For each object in the logs (onData)
126-
function(dataPoint, address, next) {
127-
// Send the dataPoint to the agent
128-
server.log(format("Found object at SPI flash address %d", address))
129-
agent.send("data", dataPoint);
130-
// Erase it from the logger
131-
logger.erase(address);
132-
// Wait a little while for it to arrive
133-
imp.wakeup(0.5, next);
134-
},
135-
136-
// All finished (onFinish)(
137-
function() {
138-
server.log("Finished sending and all entries are erased")
139-
}
135+
// For each object in the logs (onData)
136+
function(dataPoint, address, next) {
137+
// Send the dataPoint to the agent
138+
server.log(format("Found object at SPI flash address %d", address))
139+
agent.send("data", dataPoint);
140+
141+
// Erase it from the logger
142+
logger.erase(address);
143+
144+
// Wait a little while for it to arrive
145+
imp.wakeup(0.5, next);
146+
},
147+
148+
// All finished (onFinish)
149+
function() {
150+
server.log("Finished sending and all entries are erased")
151+
}
140152
);
141153
```
142154

@@ -152,12 +164,14 @@ This method reads objects from the logger synchronously, returning a single log
152164

153165
*readSync*() starts from the current logger position, which is equal to the current write position. Therefore `readSync(0)` could not contain any object, and `readSync(-1)` is equal to ‘step back to read the last written object’. If the value of *index* is greater than zero, the logger is looking for an object in a first populated sector right after the current logger position, or it will read the beginning of the sector at the current position if there are no more sectors with objects.
154166

167+
#### Example ####
168+
155169
```squirrel
156170
logger <- SPIFlashLogger(0, 16384);
157171
158172
local microsAtStart = hardware.micros();
159173
for (local i = 0 ; i <= 1500 ; i++) {
160-
logger.write(i)
174+
logger.write(i)
161175
}
162176
163177
server.log("Writing took " + (hardware.micros() - microsAtStart) / 1000000.0 + " seconds");
@@ -179,6 +193,8 @@ server.log("Index 1178 = " + logger.readSync(1178) + " in " + (hardware.micros(
179193

180194
This method synchronously returns the first object written to the log that hasn’t yet been erased (ie. the oldest entry in flash). If there are no logs in the flash, it returns *default*, or `null` if no argument is passed into *default*.
181195

196+
#### Example ####
197+
182198
```squirrel
183199
logger.write("This is the oldest");
184200
logger.write("This is the newest");
@@ -189,6 +205,8 @@ assert(logger.first() == "This is the oldest");
189205

190206
This method synchronously returns the last object written to the log that hasn’t yet been erased (ie. the newest entry in flash). If there are no logs in the flash, it returns *default*, or `null` if no argument is passed into *default*.
191207

208+
#### Example ####
209+
192210
```squirrel
193211
logger.eraseAll();
194212
assert(logger.last("Test Default value") == "Test Default value");
@@ -214,18 +232,20 @@ See *setPosition()* for sample usage.
214232

215233
This method sets the current SPI flash pointer, ie. where SPIFlashLogger will perform the next read/write task. Setting the pointer can help optimize SPI flash memory usage between deep sleeps, as it allows SPIFlashLogger to be precise to one byte rather 256 bytes (the size of a chunk).
216234

235+
#### Example ####
236+
217237
```squirrel
218238
// Create the logger object
219239
logger <- SPIFlashLogger();
220240
221241
// Check if we have position information in the nv table:
222242
if ("nv" in getroottable() && "position" in nv) {
223-
// If we do, update the position pointers in the logger object
224-
logger.setPosition(nv.position);
243+
// If we do, update the position pointers in the logger object
244+
logger.setPosition(nv.position);
225245
} else {
226-
// If we don't, grab the position points and set nv
227-
local position = logger.getPosition();
228-
nv <- { "position": position };
246+
// If we don't, grab the position points and set nv
247+
local position = logger.getPosition();
248+
nv <- { "position": position };
229249
}
230250
231251
// Get some data and log it
@@ -234,51 +254,55 @@ logger.write(data);
234254
235255
// Increment a counter
236256
if (!("count" in nv)) {
237-
nv.count <- 1;
257+
nv.count <- 1;
238258
} else {
239-
nv.count++;
259+
nv.count++;
240260
}
241261
242262
// If we have more than 100 samples
243263
if (nv.count > 100) {
244-
// Send the samples to the agent
245-
logger.read(
246-
function(dataPoint, addr, next) {
247-
// Send the dataPoint to the agent
248-
agent.send("data", dataPoint);
249-
// Erase it from the logger
250-
logger.erase(addr);
251-
// Wait a little while for it to arrive
252-
imp.wakeup(0.5, next);
253-
},
254-
function() {
255-
server.log("Finished sending and all entries are erased");
256-
// Reset counter
257-
nv.count <- 1;
258-
// Go to sleep when done
259-
imp.onidle(function() {
260-
// Get and store position pointers for next run
261-
local position = logger.getPosition();
262-
nv.position <- position;
263-
264-
// Sleep for 1 minute
265-
imp.deepsleepfor(60);
266-
});
267-
}
268-
);
269-
} else {
270-
// Go to sleep
271-
imp.onidle(function() {
264+
// Send the samples to the agent
265+
logger.read(
266+
function(dataPoint, addr, next) {
267+
// Send the dataPoint to the agent
268+
agent.send("data", dataPoint);
269+
270+
// Erase it from the logger
271+
logger.erase(addr);
272+
273+
// Wait a little while for it to arrive
274+
imp.wakeup(0.5, next);
275+
},
276+
function() {
277+
server.log("Finished sending and all entries are erased");
278+
279+
// Reset counter
280+
nv.count <- 1;
281+
282+
// Go to sleep when done
283+
imp.onidle(function() {
272284
// Get and store position pointers for next run
273285
local position = logger.getPosition();
274286
nv.position <- position;
275287
276288
// Sleep for 1 minute
277289
imp.deepsleepfor(60);
278-
});
290+
});
291+
}
292+
);
293+
} else {
294+
// Go to sleep
295+
imp.onidle(function() {
296+
// Get and store position pointers for next run
297+
local position = logger.getPosition();
298+
nv.position <- position;
299+
300+
// Sleep for 1 minute
301+
imp.deepsleepfor(60);
302+
});
279303
}
280304
```
281305

282-
# License
306+
## License ##
283307

284308
The SPIFlashLogger library is licensed under [MIT License](https://github.com/electricimp/spiflashlogger/tree/master/LICENSE).

0 commit comments

Comments
 (0)