Skip to content

Commit da326db

Browse files
authored
Merge pull request #849 from nasa/event-throttle-time-dict
Fix dictionary encoding of event throttles
2 parents c1dbbfb + 71e8ad0 commit da326db

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed

compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,25 @@ case class DictionaryJsonEncoder(
461461
}
462462
}
463463

464+
/** JSON Encoding for Event.Throttle */
465+
private implicit def eventThrottleEncoder: Encoder[Event.Throttle] = new Encoder[Event.Throttle] {
466+
override def apply(throttle: Event.Throttle): Json = {
467+
throttle match {
468+
case Event.Throttle(count, Some(every)) => Json.obj(
469+
"count" -> count.asJson,
470+
"every" -> Json.obj(
471+
"seconds" -> every.seconds.asJson,
472+
"useconds" -> every.useconds.asJson
473+
)
474+
)
475+
case Event.Throttle(count, None) => Json.obj(
476+
"count" -> count.asJson,
477+
"every" -> Json.Null
478+
)
479+
}
480+
}
481+
}
482+
464483
/** JSON Encoding for TlmChannel.Limits */
465484
private implicit def channelLimitEncoder: Encoder[TlmChannel.Limits] = new Encoder[TlmChannel.Limits] {
466485
override def apply(limits: TlmChannel.Limits): Json = {
@@ -604,6 +623,7 @@ case class DictionaryJsonEncoder(
604623
}
605624
case x: Value => Json.obj(key -> valueAsJson(x)).deepMerge(json)
606625
case x: Ast.QueueFull => Json.obj(key -> x.toString.asJson).deepMerge(json)
626+
case x: Event.Throttle => Json.obj(key -> x.asJson).deepMerge(json)
607627
}
608628
case None => json
609629
}

compiler/tools/fpp-to-dict/test/dictionary.schema.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,26 @@
407407
"type": "string"
408408
},
409409
"throttle": {
410-
"type": "number"
410+
"type": "object",
411+
"properties": {
412+
"count": {
413+
"type": "integer",
414+
"minimum": 1
415+
},
416+
"interval": {
417+
"type": "object",
418+
"properties": {
419+
"seconds": {
420+
"type": "integer",
421+
"minimum": 0
422+
},
423+
"useconds": {
424+
"type": "integer",
425+
"minimum": 0
426+
}
427+
}
428+
}
429+
}
411430
}
412431
},
413432
"required": [
@@ -568,4 +587,4 @@
568587
}
569588
}
570589
}
571-
}
590+
}

compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,55 @@
978978
"format" : "Arg1 is {f}",
979979
"annotation" : "Event with format specifier\nMultiple lines of annotation\nAnd not used on purpose"
980980
},
981+
{
982+
"name" : "Module1.myFirstC1.Event4",
983+
"severity" : "ACTIVITY_HI",
984+
"formalParams" : [
985+
{
986+
"name" : "arg1",
987+
"type" : {
988+
"name" : "F64",
989+
"kind" : "float",
990+
"size" : 64
991+
},
992+
"ref" : false,
993+
"annotation" : "description of arg1 formal param"
994+
}
995+
],
996+
"id" : 771,
997+
"format" : "Arg1 is {}",
998+
"annotation" : "Event with throttle",
999+
"throttle" : {
1000+
"count" : 10,
1001+
"every" : null
1002+
}
1003+
},
1004+
{
1005+
"name" : "Module1.myFirstC1.Event5",
1006+
"severity" : "ACTIVITY_HI",
1007+
"formalParams" : [
1008+
{
1009+
"name" : "arg1",
1010+
"type" : {
1011+
"name" : "F64",
1012+
"kind" : "float",
1013+
"size" : 64
1014+
},
1015+
"ref" : false,
1016+
"annotation" : "description of arg1 formal param"
1017+
}
1018+
],
1019+
"id" : 772,
1020+
"format" : "Arg1 is {}",
1021+
"annotation" : "Event with throttle and timeout",
1022+
"throttle" : {
1023+
"count" : 10,
1024+
"every" : {
1025+
"seconds" : 10,
1026+
"useconds" : 0
1027+
}
1028+
}
1029+
},
9811030
{
9821031
"name" : "Module1.myFirstC2.Event1",
9831032
"severity" : "WARNING_LO",

compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,55 @@
978978
"format" : "Arg1 is {f}",
979979
"annotation" : "Event with format specifier\nMultiple lines of annotation\nAnd not used on purpose"
980980
},
981+
{
982+
"name" : "Module1.mySecondC1.Event4",
983+
"severity" : "ACTIVITY_HI",
984+
"formalParams" : [
985+
{
986+
"name" : "arg1",
987+
"type" : {
988+
"name" : "F64",
989+
"kind" : "float",
990+
"size" : 64
991+
},
992+
"ref" : false,
993+
"annotation" : "description of arg1 formal param"
994+
}
995+
],
996+
"id" : 1283,
997+
"format" : "Arg1 is {}",
998+
"annotation" : "Event with throttle",
999+
"throttle" : {
1000+
"count" : 10,
1001+
"every" : null
1002+
}
1003+
},
1004+
{
1005+
"name" : "Module1.mySecondC1.Event5",
1006+
"severity" : "ACTIVITY_HI",
1007+
"formalParams" : [
1008+
{
1009+
"name" : "arg1",
1010+
"type" : {
1011+
"name" : "F64",
1012+
"kind" : "float",
1013+
"size" : 64
1014+
},
1015+
"ref" : false,
1016+
"annotation" : "description of arg1 formal param"
1017+
}
1018+
],
1019+
"id" : 1284,
1020+
"format" : "Arg1 is {}",
1021+
"annotation" : "Event with throttle and timeout",
1022+
"throttle" : {
1023+
"count" : 10,
1024+
"every" : {
1025+
"seconds" : 10,
1026+
"useconds" : 0
1027+
}
1028+
}
1029+
},
9811030
{
9821031
"name" : "Module1.mySecondC2.Event1",
9831032
"severity" : "WARNING_LO",

compiler/tools/fpp-to-dict/test/top/multipleTops.fpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ module Module1 {
132132
severity activity high \
133133
format "Arg1 is {f}"
134134

135+
@ Event with throttle
136+
event Event4(
137+
arg1: F64 @< description of arg1 formal param
138+
) \
139+
severity activity high \
140+
format "Arg1 is {}" \
141+
throttle 10
142+
143+
@ Event with throttle and timeout
144+
event Event5(
145+
arg1: F64 @< description of arg1 formal param
146+
) \
147+
severity activity high \
148+
format "Arg1 is {}" \
149+
throttle 10 \
150+
every {seconds=10}
151+
135152

136153
# Telemtry Channels
137154
@ Telemetry channel of type F64 with high and low limits

0 commit comments

Comments
 (0)