TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
103 stars 32 forks source link

Double not supported in the arduino compiler #23

Closed brice-morin closed 9 years ago

brice-morin commented 12 years ago

It seems Double is not support by the Arduino compiler.

The following ThingML code: message report_rotation(t : Double)//report the angle in radians

Compiles to the following Arduino code: // Enqueue of messages SensorsDisplay::RemoteControl::report_rotation void enqueue_SensorsDisplay_send_RemoteControl_report_rotation(struct SensorsDisplay_Instance *_instance, double t){ if ( fifo_byte_available() > 8 ) {

_fifo_enqueue( (19 >> 8) & 0xFF );
_fifo_enqueue( 19 & 0xFF );

// ID of the source instance
_fifo_enqueue( (_instance->id >> 8) & 0xFF );
_fifo_enqueue( _instance->id & 0xFF );

// parameter t
_fifo_enqueue( (t>>24) & 0xFF );//error: invalid operands of types 'double' and 'int' to binary 'operator>>
_fifo_enqueue( (t>>16) & 0xFF );//error: invalid operands of types 'double' and 'int' to binary 'operator>>
_fifo_enqueue( (t>>8) & 0xFF );//error: invalid operands of types 'double' and 'int' to binary 'operator>>
_fifo_enqueue( t & 0xFF );//error: invalid operands of types 'double' and 'int' to binary 'operator>>

} }

nharrand commented 9 years ago

Here is a simple fix: (read the double as a long with a pointer to enable bit to bit operations)

long * myLong = (long *) &t;

// ID of the source instance _fifo_enqueue( (_instance->id >> 8) & 0xFF ); _fifo_enqueue( _instance->id & 0xFF );

// parameter t read with myLong _fifo_enqueue((_myLong>>24) & 0xFF); _fifo_enqueue((_myLong>>16) & 0xFF); _fifo_enqueue((_myLong>>8) & 0xFF); _fifo_enqueue(_myLong & 0xFF);