Exercise: Drone Telemetry Processor
Problem statement
You are developing a telemetry dashboard for racing drones. The drone transmits its current state as a lightweight JSON payload. You need to process this data on the fly and compute derived metrics without defining rigid class structures.
Task requirements
Parse the provided JSON string into a dynamic node.
Extract the
motorSpeedandwindResistancevalues from the JSON data.Create a new expandable object and dynamically assign the extracted values to it as properties.
Attach a method to the expandable object that calculates the estimated horizontal velocity. The formula is
(motorSpeed / 100.0) - windResistance.Execute the dynamic method and print the calculated velocity to the console.
Constraints
Use
JsonNode.Parseand string indexers to extract the JSON values dynamically.Use the
ExpandoObjectclass to create the dynamic telemetry object.Use a
Func<double>delegate to define and attach the dynamic velocity calculation method.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Declare your parsed JSON node using the
dynamickeyword.Use string indexers like
node["motorSpeed"]to retrieve values from the parsed JSON node.When defining the
Func<double>delegate, you can access the properties you just added to theExpandoObjectdirectly inside the lambda expression.
Exercise: Drone Telemetry Processor
Problem statement
You are developing a telemetry dashboard for racing drones. The drone transmits its current state as a lightweight JSON payload. You need to process this data on the fly and compute derived metrics without defining rigid class structures.
Task requirements
Parse the provided JSON string into a dynamic node.
Extract the
motorSpeedandwindResistancevalues from the JSON data.Create a new expandable object and dynamically assign the extracted values to it as properties.
Attach a method to the expandable object that calculates the estimated horizontal velocity. The formula is
(motorSpeed / 100.0) - windResistance.Execute the dynamic method and print the calculated velocity to the console.
Constraints
Use
JsonNode.Parseand string indexers to extract the JSON values dynamically.Use the
ExpandoObjectclass to create the dynamic telemetry object.Use a
Func<double>delegate to define and attach the dynamic velocity calculation method.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Declare your parsed JSON node using the
dynamickeyword.Use string indexers like
node["motorSpeed"]to retrieve values from the parsed JSON node.When defining the
Func<double>delegate, you can access the properties you just added to theExpandoObjectdirectly inside the lambda expression.