22
22
const Log = require ( './simple-logger' )
23
23
const AppDefs = require ( './app-defs' )
24
24
const LoadConfig = require ( './load-config' )
25
- const { MongoClient } = require ( 'mongodb' )
25
+ const { MongoClient, Double } = require ( 'mongodb' )
26
26
27
27
const pipeline = [
28
28
{
@@ -80,6 +80,7 @@ Log.log('Connecting to ' + jsConfig.mongoConnectionString)
80
80
. updateMany (
81
81
{
82
82
origin : 'supervised' ,
83
+ invalid : true ,
83
84
} ,
84
85
[
85
86
{
@@ -99,7 +100,49 @@ Log.log('Connecting to ' + jsConfig.mongoConnectionString)
99
100
} )
100
101
101
102
// simulate protocol writes of digital values
102
-
103
+ let tagDocs = await db
104
+ . collection ( jsConfig . RealtimeDataCollectionName )
105
+ . find ( {
106
+ type : 'digital' ,
107
+ origin : 'supervised' ,
108
+ $expr : { $eq : [ { $indexOfBytes : [ '$tag' , 'XSWI' ] } , - 1 ] } ,
109
+ _id : { $mod : [ Math . floor ( Math . random ( ) * 500 ) + 500 , 0 ] } ,
110
+ } )
111
+ . toArray ( )
112
+ for ( let i = 0 ; i < tagDocs . length ; i ++ ) {
113
+ const document = tagDocs [ i ]
114
+ console . log ( `${ document . _id } ${ document . tag } ${ document . value } ` )
115
+ let res = await db
116
+ . collection ( jsConfig . RealtimeDataCollectionName )
117
+ . updateOne (
118
+ {
119
+ _id : document . _id ,
120
+ } ,
121
+ {
122
+ $set : {
123
+ sourceDataUpdate : {
124
+ valueAtSource : document . value == 0 ? 1 : 0 ,
125
+ valueStringAtSource : '' ,
126
+ asduAtSource : 'M_SP_NA_1' ,
127
+ causeOfTransmissionAtSource : '3' ,
128
+ timeTag : new Date ( ) ,
129
+ timeTagAtSource : new Date ( ) ,
130
+ timeTagAtSourceOk : true ,
131
+ invalid : false ,
132
+ invalidAtSource : false ,
133
+ substitutedAtSource : false ,
134
+ overflowAtSource : false ,
135
+ blockedAtSource : false ,
136
+ notTopicalAtSource : false ,
137
+ test : true ,
138
+ originator : AppDefs . NAME ,
139
+ CntUpd : cntUpd ,
140
+ } ,
141
+ } ,
142
+ }
143
+ )
144
+ }
145
+ /*
103
146
let res = await db
104
147
.collection(jsConfig.RealtimeDataCollectionName)
105
148
.updateMany(
@@ -189,14 +232,65 @@ Log.log('Connecting to ' + jsConfig.mongoConnectionString)
189
232
clientMongo = null
190
233
}
191
234
})
192
-
235
+ */
193
236
cntUpd ++
194
237
}
195
- } , 5777 )
238
+ } , 11777 )
196
239
197
240
setInterval ( async function ( ) {
198
241
if ( clientMongo !== null && HintMongoIsConnected ) {
199
242
const db = clientMongo . db ( jsConfig . mongoDatabaseName )
243
+
244
+ // simulate protocol writes of analog values
245
+ let tagDocs = await db
246
+ . collection ( jsConfig . RealtimeDataCollectionName )
247
+ . find ( {
248
+ type : 'analog' ,
249
+ origin : 'supervised' ,
250
+ _id : {
251
+ $mod : [
252
+ 1 +
253
+ Math . floor ( Math . random ( ) * 50 ) +
254
+ Math . floor ( Math . random ( ) * 10 ) ,
255
+ 0 ,
256
+ ] ,
257
+ } ,
258
+ } )
259
+ . toArray ( )
260
+ for ( let i = 0 ; i < tagDocs . length ; i ++ ) {
261
+ const document = tagDocs [ i ]
262
+ console . log ( `${ document . _id } ${ document . tag } ${ document . value } ` )
263
+ let res = await db
264
+ . collection ( jsConfig . RealtimeDataCollectionName )
265
+ . updateOne (
266
+ {
267
+ _id : document . _id ,
268
+ } ,
269
+ {
270
+ $set : {
271
+ sourceDataUpdate : {
272
+ valueAtSource : document . valueDefault * ( 1 + 0.1 * Math . random ( ) - 0.05 ) ,
273
+ valueStringAtSource : '' ,
274
+ asduAtSource : 'M_ME_NC_1' ,
275
+ causeOfTransmissionAtSource : '3' ,
276
+ timeTag : new Date ( ) ,
277
+ timeTagAtSource : null ,
278
+ timeTagAtSourceOk : false ,
279
+ invalid : false ,
280
+ invalidAtSource : false ,
281
+ substitutedAtSource : false ,
282
+ overflowAtSource : false ,
283
+ blockedAtSource : false ,
284
+ notTopicalAtSource : false ,
285
+ test : true ,
286
+ originator : AppDefs . NAME ,
287
+ CntUpd : cntUpd ,
288
+ } ,
289
+ } ,
290
+ }
291
+ )
292
+ }
293
+ /*
200
294
let res = await db
201
295
.collection(jsConfig.RealtimeDataCollectionName)
202
296
.updateMany(
@@ -291,9 +385,11 @@ Log.log('Connecting to ' + jsConfig.mongoConnectionString)
291
385
clientMongo = null
292
386
}
293
387
})
388
+
389
+ */
294
390
cntUpd ++
295
391
}
296
- } , 2000 )
392
+ } , 2333 )
297
393
298
394
while ( true ) {
299
395
if ( clientMongo === null )
@@ -336,29 +432,31 @@ Log.log('Connecting to ' + jsConfig.mongoConnectionString)
336
432
337
433
let res = await db
338
434
. collection ( jsConfig . RealtimeDataCollectionName )
339
- . updateOne ( { _id : data . supervisedOfCommand } , [
435
+ . updateOne (
436
+ { _id : data . supervisedOfCommand } ,
340
437
{
341
438
$set : {
342
439
sourceDataUpdate : {
343
- valueAtSource : val ,
440
+ valueAtSource : new Double ( val ) ,
344
441
valueStringAtSource : '' ,
345
- asduAtSource : ' M_SP_NA_1',
442
+ asduAtSource : change . fullDocument . tag . indexOf ( 'YTAP' ) === - 1 ? ' M_SP_NA_1' : 'M_ST_TB_1 ',
346
443
causeOfTransmissionAtSource : '3' ,
347
444
invalid : false ,
348
445
timeTag : new Date ( ) ,
349
446
timeTagAtSource : new Date ( ) ,
350
447
timeTagAtSourceOk : true ,
448
+ invalidAtSource : false ,
351
449
substitutedAtSource : false ,
352
450
overflowAtSource : false ,
353
451
blockedAtSource : false ,
354
452
notTopicalAtSource : false ,
355
453
test : true ,
356
- originator : AppDefs . NAME ,
454
+ originator : AppDefs . NAME + "CMD" ,
357
455
CntUpd : cntUpd ,
358
456
} ,
359
457
} ,
360
- } ,
361
- ] )
458
+ }
459
+ )
362
460
Log . log ( res ?. matchedCount )
363
461
Log . log ( res ?. modifiedCount )
364
462
if ( res ?. matchedCount > 0 ) {
0 commit comments