HEADS-project / training

Training material to get started with the HEADS technologies
10 stars 16 forks source link

how to write a maths function in thingml and pass the function result into parameter #101

Closed FeltonXuAtECNU closed 8 years ago

FeltonXuAtECNU commented 8 years ago

I'm trying to write a maths function which could generation some kind of distribution, but I don't how to do that in ThingML because there's no example to follow (to write in JAVA or C++ or ...). I Also, I don't how to pass the result of that maths function to the message construction like "sendPort!indoorTemp(5) " . 5 here should be replaced by the result of function.

Could you help me with that syntax in ThingML. Thanks!

brice-morin commented 8 years ago

See https://github.com/HEADS-project/training/blob/master/5.ThingML_CEP/5.Windows/Windows.thingml#L26 for an example of a function. You can just call a function from within a message.

FeltonXuAtECNU commented 8 years ago

Actually, I mean, if I want to use some existing maths library either in Java or C++, can I do that? What should I do? Or I have to do everything like "cos, sin, random" function from scratch.

brice-morin commented 8 years ago

Tutorial 1 e.g. shows how to mix ThingML and Java code. Same applies to you math libs in Java. See https://github.com/HEADS-project/training/blob/master/1.ThingML_Basics/4.Timers/_java/JavaTimer.thingml.

You can store results of Java functions in a thingml variable and then pass it to your message.

1 / Do the tutorials, they typically contain the answer (or good hints) to your questions 2/ Start doing something in ThingML, it will be easier for us to help you fixing some ThingML than providing general support.