Browse Source

Upload files to 'src'

master
cse47122 4 years ago
parent
commit
7279b3c2d0
  1. 26
      src/fake-device.js

26
src/fake-device.js

@ -28,7 +28,8 @@ module.exports = function FakeDevice ({
} }
let data = [] let data = []
let tmpdata=[]
let per=[]
let __metricsInterval = null let __metricsInterval = null
let __sendInterval = null let __sendInterval = null
@ -63,11 +64,34 @@ module.exports = function FakeDevice ({
data.push(chunk) data.push(chunk)
} }
const sendif = () => {
// send data buffer to connection
}
/** /**
* Send data to db and clear data buffer * Send data to db and clear data buffer
* Calls onSendData function if set * Calls onSendData function if set
*/ */
const send = () => { const send = () => {
tmpdata=data
per=tmpdata+tmpdata*0.10
if (data>=per)
{
connection.send(deviceId, data)
.then(() => {
if (!onSendData) return
onSendData(null, data)
// clear internal data buffer on successfull send
data = []
tmpdata=[]
per=[]
})
.catch(err => {
if (!onSendData) return
onSendData(err)
})
}
// send data buffer to connection // send data buffer to connection
connection.send(deviceId, data) connection.send(deviceId, data)
.then(() => { .then(() => {

Loading…
Cancel
Save