Skip to content

Commit 74053a8

Browse files
committed
Fix dictionary encoding of event throttles
1 parent c1dbbfb commit 74053a8

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import fpp.compiler.util._
55
import fpp.compiler.analysis._
66
import io.circe._
77
import io.circe.syntax._
8+
import fpp.compiler.analysis.Event.TimeInterval
9+
import fpp.compiler.analysis.Event.Throttle
810

911

1012

@@ -461,6 +463,25 @@ case class DictionaryJsonEncoder(
461463
}
462464
}
463465

466+
/** JSON Encoding for Event.Throttle */
467+
private implicit def eventThrottleEncoder: Encoder[Event.Throttle] = new Encoder[Event.Throttle] {
468+
override def apply(throttle: Throttle): Json = {
469+
throttle match {
470+
case Throttle(count, Some(every)) => Json.obj(
471+
"count" -> count.asJson,
472+
"every" -> Json.obj(
473+
"seconds" -> every.seconds.asJson,
474+
"useconds" -> every.useconds.asJson
475+
)
476+
)
477+
case Throttle(count, None) => Json.obj(
478+
"count" -> count.asJson,
479+
"every" -> Json.Null
480+
)
481+
}
482+
}
483+
}
484+
464485
/** JSON Encoding for TlmChannel.Limits */
465486
private implicit def channelLimitEncoder: Encoder[TlmChannel.Limits] = new Encoder[TlmChannel.Limits] {
466487
override def apply(limits: TlmChannel.Limits): Json = {
@@ -604,6 +625,7 @@ case class DictionaryJsonEncoder(
604625
}
605626
case x: Value => Json.obj(key -> valueAsJson(x)).deepMerge(json)
606627
case x: Ast.QueueFull => Json.obj(key -> x.toString.asJson).deepMerge(json)
628+
case x: Event.Throttle => Json.obj(key -> x.asJson).deepMerge(json)
607629
}
608630
case None => json
609631
}

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\nMultiple lines of annotation\nAnd not used on purpose",
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\nMultiple lines of annotation\nAnd not used on purpose",
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\nMultiple lines of annotation\nAnd not used on purpose",
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\nMultiple lines of annotation\nAnd not used on purpose",
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@ module Module1 {
132132
severity activity high \
133133
format "Arg1 is {f}"
134134

135+
@ Event with throttle
136+
@ Multiple lines of annotation
137+
@ And not used on purpose
138+
event Event4(
139+
arg1: F64 @< description of arg1 formal param
140+
) \
141+
severity activity high \
142+
format "Arg1 is {}" \
143+
throttle 10
144+
145+
@ Event with throttle and timeout
146+
@ Multiple lines of annotation
147+
@ And not used on purpose
148+
event Event5(
149+
arg1: F64 @< description of arg1 formal param
150+
) \
151+
severity activity high \
152+
format "Arg1 is {}" \
153+
throttle 10 \
154+
every {seconds=10}
155+
135156

136157
# Telemtry Channels
137158
@ Telemetry channel of type F64 with high and low limits

0 commit comments

Comments
 (0)