diff --git a/Makefile b/Makefile index 2a34d96ddb..294068a846 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ DL_PROTOCOL_H=$(STATICINCLUDE)/dl_protocol.h DL_PROTOCOL2_H=$(STATICINCLUDE)/dl_protocol2.h ABI_MESSAGES_H=$(STATICINCLUDE)/abi_messages.h -GEN_HEADERS = $(MESSAGES_H) $(MESSAGES2_H) $(UBX_PROTOCOL_H) $(MTK_PROTOCOL_H) $(XSENS_PROTOCOL_H) $(DL_PROTOCOL_H) $(DL_PROTOCOL2_H) $(ABI_MESSAGES_H) +GEN_HEADERS = $(MESSAGES_H) $(UBX_PROTOCOL_H) $(MTK_PROTOCOL_H) $(XSENS_PROTOCOL_H) $(DL_PROTOCOL_H) $(ABI_MESSAGES_H) all: ground_segment ext lpctools diff --git a/sw/airborne/arch/sim/ivy_transport.h b/sw/airborne/arch/sim/ivy_transport.h index 219e6cafa9..948e68cfc6 100644 --- a/sw/airborne/arch/sim/ivy_transport.h +++ b/sw/airborne/arch/sim/ivy_transport.h @@ -18,15 +18,19 @@ extern char* ivy_p; #define Space() ivy_p += sprintf(ivy_p, " "); #define Comma() ivy_p += sprintf(ivy_p, ","); +#define IvyTransportPutcByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%c", *x); +#define IvyTransportPutCharByAddr(_dev,x) IvyTransportPutcByAddr(_dev,x) Space() #define IvyTransportPutUintByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%u", *x); #define IvyTransportPutUint8ByAddr(_dev,x) IvyTransportPutUintByAddr(_dev,x) Space() #define IvyTransportPutUint16ByAddr(_dev,x) IvyTransportPutUintByAddr(_dev,x) Space() #define IvyTransportPutUint32ByAddr(_dev,x) IvyTransportPutUintByAddr(_dev,x) Space() +#define IvyTransportPutUint64ByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%llu", *x); Space() #define IvyTransportPutIntByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%d", *x); #define IvyTransportPutInt8ByAddr(_dev,x) IvyTransportPutIntByAddr(_dev,x) Space() #define IvyTransportPutInt16ByAddr(_dev,x) IvyTransportPutIntByAddr(_dev,x) Space() #define IvyTransportPutInt32ByAddr(_dev,x) IvyTransportPutIntByAddr(_dev,x) Space() +#define IvyTransportPutInt64ByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%lld", *x); Space() #define IvyTransportPutOneFloatByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%f", *x); #define IvyTransportPutFloatByAddr(_dev,x) IvyTransportPutOneFloatByAddr(_dev,x) Space() @@ -37,12 +41,29 @@ extern char* ivy_p; for(__i = 0; __i < _n; __i++) { \ _put(_dev,&_x[__i]); \ Comma(); \ - } \ + } Space() \ } +#define IvyTransportPutInt8Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) #define IvyTransportPutUint8Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutCharArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutcByAddr, _n, _x) #define IvyTransportPutInt16Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) #define IvyTransportPutUint16Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) #define IvyTransportPutUint32Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutInt32Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) +#define IvyTransportPutUint64Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutInt64Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) #define IvyTransportPutFloatArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutOneFloatByAddr, _n, _x) #define IvyTransportPutDoubleArray(_dev,_n, _x) IvyTransportPutFloatArray(_dev,_n, _x) + +#define IvyTransportPutInt8FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) +#define IvyTransportPutUint8FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutCharFixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutcByAddr, _n, _x) +#define IvyTransportPutInt16FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) +#define IvyTransportPutUint16FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutUint32FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutInt32FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) +#define IvyTransportPutUint64FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutUintByAddr, _n, _x) +#define IvyTransportPutInt64FixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x) +#define IvyTransportPutFloatFixedArray(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutOneFloatByAddr, _n, _x) +#define IvyTransportPutDoubleFixedArray(_dev,_n, _x) IvyTransportPutFloatArray(_dev,_n, _x) diff --git a/sw/airborne/subsystems/datalink/downlink.h b/sw/airborne/subsystems/datalink/downlink.h index f6da42088c..38db001cc9 100644 --- a/sw/airborne/subsystems/datalink/downlink.h +++ b/sw/airborne/subsystems/datalink/downlink.h @@ -110,6 +110,9 @@ extern uint16_t downlink_nb_msgs; #define DownlinkPutFloatByAddr(_trans, _dev, _x) Transport(_trans, PutFloatByAddr(_dev, _x)) #define DownlinkPutDoubleByAddr(_trans, _dev, _x) Transport(_trans, PutDoubleByAddr(_dev, _x)) +#define DownlinkPutUint64ByAddr(_trans, _dev, _x) Transport(_trans, PutUint64ByAddr(_dev, _x)) +#define DownlinkPutInt64ByAddr(_trans, _dev, _x) Transport(_trans, PutInt64ByAddr(_dev, _x)) +#define DownlinkPutCharByAddr(_trans, _dev, _x) Transport(_trans, PutCharByAddr(_dev, _x)) #define DownlinkPutFloatArray(_trans, _dev, _n, _x) Transport(_trans, PutFloatArray(_dev, _n, _x)) #define DownlinkPutDoubleArray(_trans, _dev, _n, _x) Transport(_trans, PutDoubleArray(_dev, _n, _x)) @@ -117,7 +120,23 @@ extern uint16_t downlink_nb_msgs; #define DownlinkPutUint16Array(_trans, _dev, _n, _x) Transport(_trans, PutUint16Array(_dev, _n, _x)) #define DownlinkPutInt32Array(_trans, _dev, _n, _x) Transport(_trans, PutInt32Array(_dev, _n, _x)) #define DownlinkPutUint32Array(_trans, _dev, _n, _x) Transport(_trans, PutUint32Array(_dev, _n, _x)) +#define DownlinkPutInt64Array(_trans, _dev, _n, _x) Transport(_trans, PutInt64Array(_dev, _n, _x)) +#define DownlinkPutUint64Array(_trans, _dev, _n, _x) Transport(_trans, PutUint64Array(_dev, _n, _x)) +#define DownlinkPutInt8Array(_trans, _dev, _n, _x) Transport(_trans, PutInt8Array(_dev, _n, _x)) #define DownlinkPutUint8Array(_trans, _dev, _n, _x) Transport(_trans, PutUint8Array(_dev, _n, _x)) +#define DownlinkPutCharArray(_trans, _dev, _n, _x) Transport(_trans, PutCharArray(_dev, _n, _x)) + +#define DownlinkPutFloatFixedArray(_trans, _dev, _n, _x) Transport(_trans, PutFloatFixedArray(_dev, _n, _x)) +#define DownlinkPutDoubleFixedArray(_trans, _dev, _n, _x) Transport(_trans, PutDoubleFixedArray(_dev, _n, _x)) +#define DownlinkPutInt16FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutInt16FixedArray(_dev, _n, _x)) +#define DownlinkPutUint16FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutUint16FixedArray(_dev, _n, _x)) +#define DownlinkPutInt32FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutInt32FixedArray(_dev, _n, _x)) +#define DownlinkPutUint32FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutUint32FixedArray(_dev, _n, _x)) +#define DownlinkPutInt64FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutInt64FixedArray(_dev, _n, _x)) +#define DownlinkPutUint64FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutUint64FixedArray(_dev, _n, _x)) +#define DownlinkPutInt8FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutInt8FixedArray(_dev, _n, _x)) +#define DownlinkPutUint8FixedArray(_trans, _dev, _n, _x) Transport(_trans, PutUint8FixedArray(_dev, _n, _x)) +#define DownlinkPutCharFixedArray(_trans, _dev, _n, _x) Transport(_trans, PutCharFixedArray(_dev, _n, _x)) #define DownlinkOverrun(_trans, _dev) downlink_nb_ovrn++; #define DownlinkCountBytes(_trans, _dev, _n) downlink_nb_bytes += _n; diff --git a/sw/airborne/subsystems/datalink/pprz_transport.h b/sw/airborne/subsystems/datalink/pprz_transport.h index 502d54ebce..6f3aaa649b 100644 --- a/sw/airborne/subsystems/datalink/pprz_transport.h +++ b/sw/airborne/subsystems/datalink/pprz_transport.h @@ -101,11 +101,27 @@ extern uint8_t ck_a, ck_b; PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ } +#define PprzTransportPutUint64ByAddr(_dev, _byte) { \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } +#define PprzTransportPutInt64ByAddr(_dev, _byte) { \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } #else #define PprzTransportPutDoubleByAddr(_dev, _byte) { \ PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ } +#define PprzTransportPutUint64ByAddr(_dev, _byte) { \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } +#define PprzTransportPutInt64ByAddr(_dev, _byte) { \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } #endif @@ -116,6 +132,7 @@ extern uint8_t ck_a, ck_b; #define PprzTransportPutInt32ByAddr(_dev, _x) PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_x) #define PprzTransportPutUint32ByAddr(_dev, _x) PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_x) #define PprzTransportPutFloatByAddr(_dev, _x) PprzTransportPut4ByteByAddr(_dev, (const uint8_t*)_x) +#define PprzTransportPutCharByAddr(_dev, _x) PprzTransportPut1ByteByAddr(_dev, (const uint8_t*)_x) #define PprzTransportPutArray(_dev, _put, _n, _x) { \ uint8_t _i; \ @@ -125,8 +142,10 @@ extern uint8_t ck_a, ck_b; } \ } -#define PprzTransportPutFloatArray(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutFloatByAddr, _n, _x) -#define PprzTransportPutDoubleArray(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutDoubleByAddr, _n, _x) +#define PprzTransportPutInt8Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutInt8ByAddr, _n, _x) +#define PprzTransportPutUint8Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutUint8ByAddr, _n, _x) + +#define PprzTransportPutCharArray(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutCharByAddr, _n, _x) #define PprzTransportPutInt16Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutInt16ByAddr, _n, _x) #define PprzTransportPutUint16Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutUint16ByAddr, _n, _x) @@ -134,8 +153,37 @@ extern uint8_t ck_a, ck_b; #define PprzTransportPutInt32Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutInt32ByAddr, _n, _x) #define PprzTransportPutUint32Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutUint32ByAddr, _n, _x) -#define PprzTransportPutUint8Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutUint8ByAddr, _n, _x) +#define PprzTransportPutFloatArray(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutFloatByAddr, _n, _x) +#define PprzTransportPutInt64Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutInt64ByAddr, _n, _x) +#define PprzTransportPutUint64Array(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutUint64ByAddr, _n, _x) + +#define PprzTransportPutDoubleArray(_dev, _n, _x) PprzTransportPutArray(_dev, PprzTransportPutDoubleByAddr, _n, _x) + +#define PprzTransportPutFixedArray(_dev, _put, _n, _x) { \ + uint8_t _i; \ + for(_i = 0; _i < _n; _i++) { \ + _put(_dev, &_x[_i]); \ + } \ +} + +#define PprzTransportPutInt8FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutInt8ByAddr, _n, _x) +#define PprzTransportPutUint8FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutUint8ByAddr, _n, _x) + +#define PprzTransportPutCharFixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutCharByAddr, _n, _x) + +#define PprzTransportPutInt16FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutInt16ByAddr, _n, _x) +#define PprzTransportPutUint16FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutUint16ByAddr, _n, _x) + +#define PprzTransportPutInt32FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutInt32ByAddr, _n, _x) +#define PprzTransportPutUint32FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutUint32ByAddr, _n, _x) + +#define PprzTransportPutFloatFixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutFloatByAddr, _n, _x) + +#define PprzTransportPutInt64FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutInt64ByAddr, _n, _x) +#define PprzTransportPutUint64FixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutUint64ByAddr, _n, _x) + +#define PprzTransportPutDoubleFixedArray(_dev, _n, _x) PprzTransportPutFixedArray(_dev, PprzTransportPutDoubleByAddr, _n, _x) /** Receiving pprz messages */ diff --git a/sw/airborne/subsystems/datalink/w5100.h b/sw/airborne/subsystems/datalink/w5100.h index 0d6384c1d7..57a73d37d8 100644 --- a/sw/airborne/subsystems/datalink/w5100.h +++ b/sw/airborne/subsystems/datalink/w5100.h @@ -118,11 +118,27 @@ bool_t w5100_ch_available( void ); W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ } +#define W5100TransportPutUint64ByAddr(_dev, _byte) { \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } +#define W5100TransportPutInt64ByAddr(_dev, _byte) { \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } #else #define W5100TransportPutDoubleByAddr(_dev, _byte) { \ W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ } +#define W5100TransportPutUint64ByAddr(_dev, _byte) { \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } +#define W5100TransportPutInt64ByAddr(_dev, _byte) { \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + W5100TransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } #endif @@ -143,14 +159,51 @@ _put(_dev, &_x[_i]); \ } \ } -#define W5100TransportPutInt16Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutInt16ByAddr, _n, _x) - -#define W5100TransportPutUint16Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutUint16ByAddr, _n, _x) +#define W5100TransportPutInt8Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutInt8ByAddr, _n, _x) #define W5100TransportPutUint8Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutUint8ByAddr, _n, _x) + +#define W5100TransportPutCharArray(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutCharByAddr, _n, _x) + +#define W5100TransportPutInt16Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutInt16ByAddr, _n, _x) +#define W5100TransportPutUint16Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutUint16ByAddr, _n, _x) + +#define W5100TransportPutInt32Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutInt32ByAddr, _n, _x) +#define W5100TransportPutUint32Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutUint32ByAddr, _n, _x) + #define W5100TransportPutFloatArray(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutFloatByAddr, _n, _x) + +#define W5100TransportPutInt64Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutInt64ByAddr, _n, _x) +#define W5100TransportPutUint64Array(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutUint64ByAddr, _n, _x) + #define W5100TransportPutDoubleArray(_dev, _n, _x) W5100TransportPutArray(_dev, W5100TransportPutDoubleByAddr, _n, _x) +#define W5100TransportPutFixedArray(_dev, _put, _n, _x) { \ + uint8_t _i; \ + for(_i = 0; _i < _n; _i++) { \ + _put(_dev, &_x[_i]); \ + } \ +} + +#define W5100TransportPutInt8FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutInt8ByAddr, _n, _x) +#define W5100TransportPutUint8FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutUint8ByAddr, _n, _x) + +#define W5100TransportPutCharFixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutCharByAddr, _n, _x) + +#define W5100TransportPutInt16FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutInt16ByAddr, _n, _x) +#define W5100TransportPutUint16FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutUint16ByAddr, _n, _x) + +#define W5100TransportPutInt32FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutInt32ByAddr, _n, _x) +#define W5100TransportPutUint32FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutUint32ByAddr, _n, _x) + +#define W5100TransportPutFloatFixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutFloatByAddr, _n, _x) + +#define W5100TransportPutInt64FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutInt64ByAddr, _n, _x) +#define W5100TransportPutUint64FixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutUint64ByAddr, _n, _x) + +#define W5100TransportPutDoubleFixedArray(_dev, _n, _x) W5100TransportPutFixedArray(_dev, W5100TransportPutDoubleByAddr, _n, _x) + + #define W5100TransportHeader(_dev, payload_len) { \ W5100TransportPut1Byte(_dev, STX); \ uint8_t msg_len = W5100TransportSizeOf(_dev, payload_len); \ diff --git a/sw/airborne/subsystems/datalink/xbee.h b/sw/airborne/subsystems/datalink/xbee.h index 04e8405226..a0db46f8b3 100644 --- a/sw/airborne/subsystems/datalink/xbee.h +++ b/sw/airborne/subsystems/datalink/xbee.h @@ -89,11 +89,27 @@ void xbee_init( void ); XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ } +#define XBeeTransportPutUint64ByAddr(_dev, _byte) { \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } +#define XBeeTransportPutInt64ByAddr(_dev, _byte) { \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + } #else #define XBeeTransportPutDoubleByAddr(_dev, _byte) { \ XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ } +#define XBeeTransportPutUint64ByAddr(_dev, _byte) { \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } +#define XBeeTransportPutInt64ByAddr(_dev, _byte) { \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte); \ + XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_byte+4); \ + } #endif @@ -105,6 +121,7 @@ void xbee_init( void ); #define XBeeTransportPutUint32ByAddr(_dev, _x) XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_x) #define XBeeTransportPutFloatByAddr(_dev, _x) XBeeTransportPut4ByteByAddr(_dev, (const uint8_t*)_x) #define XBeeTransportPutNamedUint8(_dev, _name, _byte) XBeeTransportPutUint8(_dev, _byte) +#define XBeeTransportPutCharByAddr(_dev, _x) XBeeTransportPut1ByteByAddr(_dev, (const uint8_t*)_x) #define XBeeTransportPutArray(_dev, _put, _n, _x) { \ uint8_t _i; \ @@ -114,14 +131,50 @@ void xbee_init( void ); } \ } -#define XBeeTransportPutInt16Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutInt16ByAddr, _n, _x) - -#define XBeeTransportPutUint16Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutUint16ByAddr, _n, _x) +#define XBeeTransportPutInt8Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutInt8ByAddr, _n, _x) #define XBeeTransportPutUint8Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutUint8ByAddr, _n, _x) + +#define XBeeTransportPutCharArray(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutCharByAddr, _n, _x) + +#define XBeeTransportPutInt16Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutInt16ByAddr, _n, _x) +#define XBeeTransportPutUint16Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutUint16ByAddr, _n, _x) + +#define XBeeTransportPutInt32Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutInt32ByAddr, _n, _x) +#define XBeeTransportPutUint32Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutUint32ByAddr, _n, _x) + #define XBeeTransportPutFloatArray(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutFloatByAddr, _n, _x) + +#define XBeeTransportPutInt64Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutInt64ByAddr, _n, _x) +#define XBeeTransportPutUint64Array(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutUint64ByAddr, _n, _x) + #define XBeeTransportPutDoubleArray(_dev, _n, _x) XBeeTransportPutArray(_dev, XBeeTransportPutDoubleByAddr, _n, _x) +#define XBeeTransportPutFixedArray(_dev, _put, _n, _x) { \ + uint8_t _i; \ + for(_i = 0; _i < _n; _i++) { \ + _put(_dev, &_x[_i]); \ + } \ +} + +#define XBeeTransportPutInt8FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutInt8ByAddr, _n, _x) +#define XBeeTransportPutUint8FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutUint8ByAddr, _n, _x) + +#define XBeeTransportPutCharFixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutCharByAddr, _n, _x) + +#define XBeeTransportPutInt16FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutInt16ByAddr, _n, _x) +#define XBeeTransportPutUint16FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutUint16ByAddr, _n, _x) + +#define XBeeTransportPutInt32FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutInt32ByAddr, _n, _x) +#define XBeeTransportPutUint32FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutUint32ByAddr, _n, _x) + +#define XBeeTransportPutFloatFixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutFloatByAddr, _n, _x) + +#define XBeeTransportPutInt64FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutInt64ByAddr, _n, _x) +#define XBeeTransportPutUint64FixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutUint64ByAddr, _n, _x) + +#define XBeeTransportPutDoubleFixedArray(_dev, _n, _x) XBeeTransportPutFixedArray(_dev, XBeeTransportPutDoubleByAddr, _n, _x) + #define XBeeTransportHeader(_dev, _len) { \ XBeeTransportPut1Byte(_dev, XBEE_START); \ diff --git a/sw/ground_segment/tmtc/link.ml b/sw/ground_segment/tmtc/link.ml index 4f74518199..4ccacfc1c3 100644 --- a/sw/ground_segment/tmtc/link.ml +++ b/sw/ground_segment/tmtc/link.ml @@ -309,7 +309,7 @@ let send = fun ac_id device payload _priority -> udp_send device.fd payload peername | _ -> match device.transport with - Pprz -> + Pprz | Pprz2 -> let o = Unix.out_channel_of_descr device.fd in let buf = Pprz.Transport.packet payload in Printf.fprintf o "%s" buf; flush o; diff --git a/sw/lib/ocaml/convert.c b/sw/lib/ocaml/convert.c index 0cfbb3e069..81b470fd6e 100644 --- a/sw/lib/ocaml/convert.c +++ b/sw/lib/ocaml/convert.c @@ -76,7 +76,6 @@ c_double_of_indexed_bytes(value s, value index) return copy_double(*x); } - #endif /* ARCH_ALIGN_DOUBLE */ value @@ -115,6 +114,13 @@ c_sprint_int32(value s, value index, value x) { return Val_unit; } +value +c_sprint_int64(value s, value index, value x) { + int64_t *p = (int64_t*) (String_val(s) + Int_val(index)); + *p = (int64_t)Int64_val(x); + return Val_unit; +} + value c_int16_of_indexed_bytes(value s, value index) { @@ -138,3 +144,26 @@ c_int32_of_indexed_bytes(value s, value index) return copy_int32(*x); } + +#ifdef ARCH_ALIGN_INT64 +value +c_int64_of_indexed_bytes(value s, value index) +{ + char *x = (char *)(String_val(s) + Int_val(index)); + + union { char b[sizeof(int64_t)]; int64_t i; } buffer; + int i; + for (i=0; i < sizeof(int64_t); i++) { + buffer.b[i] = x[i]; + } + return copy_int64(buffer.i); +} +#else +value +c_int64_of_indexed_bytes(value s, value index) +{ + int64_t *x = (int64_t*)(String_val(s) + Int_val(index)); + + return copy_int64(*x); +} +#endif diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index bab82a1fc5..f2de6e2ff8 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -32,8 +32,9 @@ type format = string type _type = Scalar of string | ArrayType of string + | FixedArrayType of string * int type value = - Int of int | Float of float | String of string | Int32 of int32 + Int of int | Float of float | String of string | Int32 of int32 | Char of char | Int64 of int64 | Array of value array type field = { _type : _type; @@ -78,8 +79,10 @@ external double_of_bytes : string -> int -> float = "c_double_of_indexed_bytes" external int32_of_bytes : string -> int -> int32 = "c_int32_of_indexed_bytes" external int8_of_bytes : string -> int -> int = "c_int8_of_indexed_bytes" external int16_of_bytes : string -> int -> int = "c_int16_of_indexed_bytes" +external int64_of_bytes : string -> int -> int64 = "c_int64_of_indexed_bytes" external sprint_float : string -> int -> float -> unit = "c_sprint_float" external sprint_double : string -> int -> float -> unit = "c_sprint_double" +external sprint_int64 : string -> int -> int64 -> unit = "c_sprint_int64" external sprint_int32 : string -> int -> int32 -> unit = "c_sprint_int32" external sprint_int16 : string -> int -> int -> unit = "c_sprint_int16" external sprint_int8 : string -> int -> int -> unit = "c_sprint_int8" @@ -88,12 +91,15 @@ let types = [ ("uint8", { format = "%u"; glib_type = "guint8"; inttype = "uint8_t"; size = 1; value=Int 42 }); ("uint16", { format = "%u"; glib_type = "guint16"; inttype = "uint16_t"; size = 2; value=Int 42 }); ("uint32", { format = "%lu" ; glib_type = "guint32"; inttype = "uint32_t"; size = 4; value=Int 42 }); + ("uint64", { format = "%Lu" ; glib_type = "guint64"; inttype = "uint64_t"; size = 8; value=Int 42 }); ("int8", { format = "%d"; glib_type = "gint8"; inttype = "int8_t"; size = 1; value= Int 42 }); ("int16", { format = "%d"; glib_type = "gint16"; inttype = "int16_t"; size = 2; value= Int 42 }); ("int32", { format = "%ld" ; glib_type = "gint32"; inttype = "int32_t"; size = 4; value=Int 42 }); + ("int64", { format = "%Ld" ; glib_type = "gint64"; inttype = "int64_t"; size = 8; value=Int 42 }); ("float", { format = "%f" ; glib_type = "gfloat"; inttype = "float"; size = 4; value=Float 4.2 }); - ("double", { format = "%f" ; glib_type = "gdouble"; inttype = "double"; size = 8; value=Float 4.2 }); - ("string", { format = "%s" ; glib_type = "gchar*"; inttype = "char*"; size = max_int; value=String "42" }) + ("double", { format = "%f" ; glib_type = "gdouble"; inttype = "double"; size = 8; value=Float 4.2 }); + ("char", { format = "%c" ; glib_type = "gchar"; inttype = "char"; size = 1; value=Char '*' }); + ("string", { format = "%s" ; glib_type = "gchar*"; inttype = "char*"; size = max_int; value=String "42" }) ] let is_array_type = fun s -> @@ -104,6 +110,30 @@ let type_of_array_type = fun s -> let n = String.length s in String.sub s 0 (n-2) +let is_fixed_array_type = fun s -> + let type_parts = Str.full_split (Str.regexp "[][]") s in + match type_parts with + | [Str.Text _; Str.Delim "["; Str.Text _ ; Str.Delim "]"] -> true + | _ -> false + +let type_of_fixed_array_type = fun s -> + try + let type_parts = Str.full_split (Str.regexp "[][]") s in + match type_parts with + | [Str.Text ty; Str.Delim "["; Str.Text len ; Str.Delim "]"] -> begin ignore( int_of_string (len)); ty end + | _ -> failwith("Pprz.type_of_fixed_array_type is not a fixed array type") + with + | Failure str -> failwith(sprintf "Pprz.type_of_fixed_array_type: length is not an integer") + +let length_of_fixed_array_type = fun s -> + try + let type_parts = Str.full_split (Str.regexp "[][]") s in + match type_parts with + | [Str.Text ty; Str.Delim "["; Str.Text len ; Str.Delim "]"] -> begin ignore( int_of_string (len)); len end + | _ -> failwith("Pprz.type_of_fixed_array_type is not a fixed array type") + with + | Failure str -> failwith(sprintf "Pprz.type_of_fixed_array_type: length is not an integer") + let int_of_string = fun x -> try int_of_string x with _ -> failwith (sprintf "Pprz.int_of_string: %s" x) @@ -112,17 +142,23 @@ let rec value = fun t v -> match t with Scalar ("uint8" | "uint16" | "int8" | "int16") -> Int (int_of_string v) | Scalar ("uint32" | "int32") -> Int32 (Int32.of_string v) + | Scalar ("uint64" | "int64") -> Int64 (Int64.of_string v) | Scalar ("float" | "double") -> Float (float_of_string v) | Scalar "string" -> String v + | Scalar "char" -> Char v.[0] | ArrayType t' -> - Array (Array.map (value (Scalar t')) (Array.of_list (split_array v))) + Array (Array.map (value (Scalar t')) (Array.of_list (split_array v))) + | FixedArrayType (t',l') -> + Array (Array.map (value (Scalar t')) (Array.of_list (split_array v))) | Scalar t -> failwith (sprintf "Pprz.value: Unexpected type: %s" t) let rec string_of_value = function -Int x -> string_of_int x + Int x -> string_of_int x | Float x -> string_of_float x | Int32 x -> Int32.to_string x + | Int64 x -> Int64.to_string x + | Char c -> String.make 1 c | String s -> s | Array a -> String.concat separator (Array.to_list (Array.map string_of_value a)) @@ -140,15 +176,16 @@ let sizeof = fun f -> match f with Scalar t -> (List.assoc t types).size | ArrayType t -> failwith "sizeof: Array" + | FixedArrayType (t,l) -> failwith "sizeof: Array" let size_of_field = fun f -> sizeof f._type -let default_format = function -Scalar x | ArrayType x -> +let default_format = function Scalar x | ArrayType x | FixedArrayType (x,_) -> try (List.assoc x types).format with Not_found -> failwith (sprintf "Unknown format '%s'" x) let default_value = fun x -> match x with Scalar t -> (List.assoc t types).value | ArrayType t -> failwith "default_value: Array" + | FixedArrayType (t,l) -> failwith "default_value: Array" let payload_size_of_message = fun message -> List.fold_right @@ -208,7 +245,9 @@ let alt_unit_coef_of_xml = fun ?auto xml -> let pipe_regexp = Str.regexp "|" let field_of_xml = fun xml -> let t = ExtXml.attrib xml "type" in - let t = if is_array_type t then ArrayType (type_of_array_type t) else Scalar t in + let t = if is_array_type t then ArrayType (type_of_array_type t) + else if is_fixed_array_type t then FixedArrayType (type_of_fixed_array_type t, int_of_string(length_of_fixed_array_type t)) + else Scalar t in let f = try Xml.attrib xml "format" with _ -> default_format t in let auc = alt_unit_coef_of_xml xml in let values = try Str.split pipe_regexp (Xml.attrib xml "values") with _ -> [] in @@ -236,6 +275,11 @@ let int_of_value = fun value -> if Int32.compare x (Int32.of_int i) <> 0 then failwith "Pprz.int_assoc: Int32 too large to be converted into an int"; i + | Int64 x -> + let i = Int64.to_int x in + if Int64.compare x (Int64.of_int i) <> 0 then + failwith "Pprz.int_assoc: Int64 too large to be converted into an int"; + i | _ -> invalid_arg "Pprz.int_assoc" let int_assoc = fun (a:string) vs -> @@ -246,8 +290,15 @@ let int32_assoc = fun (a:string) vs -> Int32 x -> x | _ -> invalid_arg "Pprz.int_assoc" +let int64_assoc = fun (a:string) vs -> + match assoc a vs with + Int64 x -> x + | _ -> invalid_arg "Pprz.int_assoc" + let string_assoc = fun (a:string) (vs:values) -> string_of_value (assoc a vs) +let char_assoc = fun (a:string) (vs:values) -> (string_of_value (assoc a vs)).[0] + let link_mode_of_string = function "forwarded" -> Forwarded | "broadcasted" -> Broadcasted @@ -283,12 +334,14 @@ let parse_class = fun xml_class -> let rec value_of_bin = fun buffer index _type -> match _type with Scalar "uint8" -> Int (Char.code buffer.[index]), sizeof _type + | Scalar "char" -> Char (buffer.[index]), sizeof _type | Scalar "int8" -> Int (int8_of_bytes buffer index), sizeof _type | Scalar "uint16" -> Int (Char.code buffer.[index+1] lsl 8 + Char.code buffer.[index]), sizeof _type | Scalar "int16" -> Int (int16_of_bytes buffer index), sizeof _type | Scalar "float" -> Float (float_of_bytes buffer index), sizeof _type | Scalar "double" -> Float (double_of_bytes buffer index), sizeof _type | Scalar ("int32" | "uint32") -> Int32 (int32_of_bytes buffer index), sizeof _type + | Scalar ("int64" | "uint64") -> Int64 (int64_of_bytes buffer index), sizeof _type | ArrayType t -> (** First get the number of values *) let n = int8_of_bytes buffer index in @@ -296,7 +349,15 @@ let rec value_of_bin = fun buffer index _type -> let s = sizeof type_of_elt in let size = 1 + n * s in (Array (Array.init n - (fun i -> fst (value_of_bin buffer (index+1+i*s) type_of_elt))), size) + (fun i -> fst (value_of_bin buffer (index+1+i*s) type_of_elt))), size) + | FixedArrayType (t,l) -> + (** First get the number of values *) + let n = l in + let type_of_elt = Scalar t in + let s = sizeof type_of_elt in + let size = 0 + n * s in + (Array (Array.init n + (fun i -> fst (value_of_bin buffer (index+0+i*s) type_of_elt))), size) | Scalar "string" -> let n = Char.code buffer.[index] in (String (String.sub buffer (index+1) n), (1+n)) @@ -321,6 +382,7 @@ let rec sprint_value = fun buf i _type v -> | Scalar "float", Float f -> sprint_float buf i f; sizeof _type | Scalar "double", Float f -> sprint_double buf i f; sizeof _type | Scalar ("int32"|"uint32"), Int32 x -> sprint_int32 buf i x; sizeof _type + | Scalar ("int64"|"uint64"), Int64 x -> sprint_int64 buf i x; sizeof _type | Scalar "int16", Int x -> sprint_int16 buf i x; sizeof _type | Scalar ("int32" | "uint32"), Int value -> assert (_type <> Scalar "uint32" || value >= 0); @@ -329,6 +391,17 @@ let rec sprint_value = fun buf i _type v -> buf.[i+1] <- byte (value lsr 8); buf.[i+0] <- byte value; sizeof _type + | Scalar ("int64" | "uint64"), Int value -> + assert (_type <> Scalar "uint64" || value >= 0); + buf.[i+7] <- byte (value asr 56); + buf.[i+6] <- byte (value lsr 48); + buf.[i+5] <- byte (value lsr 40); + buf.[i+4] <- byte (value lsr 32); + buf.[i+3] <- byte (value lsr 24); + buf.[i+2] <- byte (value lsr 16); + buf.[i+1] <- byte (value lsr 8); + buf.[i+0] <- byte value; + sizeof _type | Scalar "uint16", Int value -> assert (value >= 0); buf.[i+1] <- byte (value lsr 8); @@ -342,8 +415,17 @@ let rec sprint_value = fun buf i _type v -> let s = sizeof type_of_elt in for j = 0 to n - 1 do ignore (sprint_value buf (i+1+j*s) type_of_elt values.(j)) - done; - 1 + n * s + done; + 1 + n * s + | FixedArrayType (t,l), Array values -> + (** Put the size first, then the values *) + let n = Array.length values in + let type_of_elt = Scalar t in + let s = sizeof type_of_elt in + for j = 0 to n - 1 do + ignore (sprint_value buf (i+0+j*s) type_of_elt values.(j)) + done; + 0 + n * s | Scalar "string", String s -> let n = String.length s in assert (n < 256); @@ -353,7 +435,10 @@ let rec sprint_value = fun buf i _type v -> failwith "Error in sprint_value: message too long"; String.blit s 0 buf (i+1) n; 1 + n + | Scalar "char", Char c -> + buf.[i] <- c; sizeof _type | (Scalar x|ArrayType x), _ -> failwith (sprintf "Pprz.sprint_value (%s)" x) + | FixedArrayType (x,l), _ -> failwith (sprintf "Pprz.sprint_value (%s)" x) diff --git a/sw/lib/ocaml/pprz.mli b/sw/lib/ocaml/pprz.mli index 508b927593..4181035fb0 100644 --- a/sw/lib/ocaml/pprz.mli +++ b/sw/lib/ocaml/pprz.mli @@ -31,8 +31,9 @@ type format = string type _type = Scalar of string | ArrayType of string + | FixedArrayType of string * int type value = - Int of int | Float of float | String of string | Int32 of int32 + Int of int | Float of float | String of string | Int32 of int32 | Char of char | Int64 of int64 | Array of value array type field = { _type : _type; @@ -50,12 +51,14 @@ type message = { external int32_of_bytes : string -> int -> int32 = "c_int32_of_indexed_bytes" +external int64_of_bytes : string -> int -> int64 = "c_int64_of_indexed_bytes" (** [int32_of_bytes buffer offset] *) val separator : string (** Separator in array values *) val is_array_type : string -> bool +val is_fixed_array_type : string -> bool val size_of_field : field -> int val string_of_value : value -> string @@ -79,6 +82,7 @@ val string_assoc : string -> values -> string val float_assoc : string -> values -> float val int_assoc : string -> values -> int val int32_assoc : string -> values -> Int32.t +val int64_assoc : string -> values -> Int64.t (** May raise Not_found or Invalid_argument *) val hex_of_int_array : value -> string diff --git a/sw/logalizer/plot.ml b/sw/logalizer/plot.ml index 915ffb5f2b..9d3726106b 100644 --- a/sw/logalizer/plot.ml +++ b/sw/logalizer/plot.ml @@ -511,7 +511,9 @@ let pprz_float = function Pprz.Int i -> float i | Pprz.Float f -> f | Pprz.Int32 i -> Int32.to_float i + | Pprz.Int64 i -> Int64.to_float i | Pprz.String s -> float_of_string s + | Pprz.Char c -> float_of_string (String.make 1 c) | Pprz.Array _ -> 0. diff --git a/sw/logalizer/plotter.ml b/sw/logalizer/plotter.ml index 50569177f3..977329efe9 100644 --- a/sw/logalizer/plotter.ml +++ b/sw/logalizer/plotter.ml @@ -37,7 +37,9 @@ let pprz_float = function Pprz.Int i -> float i | Pprz.Float f -> f | Pprz.Int32 i -> Int32.to_float i + | Pprz.Int64 i -> Int64.to_float i | Pprz.String s -> float_of_string s + | Pprz.Char c -> float_of_string (String.make 1 c) | Pprz.Array _ -> 0. diff --git a/sw/tools/Makefile b/sw/tools/Makefile index 843326d1e2..b3ed28bbe7 100644 --- a/sw/tools/Makefile +++ b/sw/tools/Makefile @@ -33,15 +33,15 @@ all: gen_common.cmo gen_aircraft.out gen_airframe.out gen_messages2.out gen_mess FP_CMO = fp_proc.cmo gen_flight_plan.cmo ABS_FP = $(FP_CMO:%=$$PAPARAZZI_SRC/sw/tools/%) -gen_flight_plan.out : $(FP_CMO) +gen_flight_plan.out : $(FP_CMO) $(LIBPPRZCMA) @echo OL $@ $(Q)$(OCAMLC) $(INCLUDES) -o $@ $(LINKPKG) $^ -gen_srtm.out : gen_srtm.ml +gen_srtm.out : gen_srtm.ml $(LIBPPRZCMA) @echo OL $@ $(Q)$(OCAMLC) $(INCLUDES) -o $@ $(LINKPKG) $< -%.out : %.ml gen_common.cmo +%.out : %.ml gen_common.cmo $(LIBPPRZCMA) @echo OL $< $(Q)$(OCAMLC) $(INCLUDES) -o $@ $(LINKPKG) gen_common.cmo $< diff --git a/sw/tools/gen_messages.ml b/sw/tools/gen_messages.ml index 76e30e9c91..a2053a7bfa 100644 --- a/sw/tools/gen_messages.ml +++ b/sw/tools/gen_messages.ml @@ -29,6 +29,7 @@ type format = string type _type = Basic of string | Array of string * string + | FixedArray of string * string * int type field = _type * string * format option @@ -44,11 +45,15 @@ type message = { module Syntax = struct (** Parse a type name and returns a _type value *) let parse_type = fun t varname -> - let n = String.length t in - if n >=2 && String.sub t (n-2) 2 = "[]" then - Array (String.sub t 0 (n-2), varname) - else - Basic t + try + let type_parts = Str.full_split (Str.regexp "[][]") t in + match type_parts with + | [Str.Text ty] -> Basic ty + | [Str.Text ty; Str.Delim "["; Str.Delim "]"] -> Array (ty, varname) + | [Str.Text ty; Str.Delim "["; Str.Text len ; Str.Delim "]"] -> FixedArray (ty, varname, int_of_string len) + | _ -> failwith "Gen_messages: not a valid field type" + with + | Failure fail -> failwith("Gen_messages: not a valid array length") let length_name = fun s -> "nb_"^s @@ -62,10 +67,12 @@ module Syntax = struct let rec sizeof = function Basic t -> string_of_int (assoc_types t).Pprz.size | Array (t, varname) -> sprintf "1+%s*%s" (length_name varname) (sizeof (Basic t)) + | FixedArray (t, varname, len) -> sprintf "0+%d*%s" len (sizeof (Basic t)) let rec nameof = function Basic t -> String.capitalize t | Array _ -> failwith "nameof" + | FixedArray _ -> failwith "nameof" (** Translates a "message" XML element into a value of the 'message' type *) let struct_of_xml = fun xml -> @@ -73,14 +80,13 @@ module Syntax = struct and id = ExtXml.int_attrib xml "id" and period = try Some (ExtXml.float_attrib xml "period") with _ -> None and fields = - List.map - (fun field -> - let id = ExtXml.attrib field "name" - and type_name = ExtXml.attrib field "type" - and fmt = try Some (Xml.attrib field "format") with _ -> None in - let _type = parse_type type_name id in - (_type, id, fmt)) - (Xml.children xml) in + List.map (fun field -> + let id = ExtXml.attrib field "name" + and type_name = ExtXml.attrib field "type" + and fmt = try Some (Xml.attrib field "format") with _ -> None in + let _type = parse_type type_name id in + (_type, id, fmt)) + (List.filter (fun t -> compare (Xml.tag t) "field" = 0) (Xml.children xml)) in { id=id; name = name; period = period; fields = fields } let check_single_ids = fun msgs -> @@ -117,9 +123,13 @@ module Gen_onboard = struct | Array (t, varname) -> let _s = Syntax.sizeof (Basic t) in fprintf h "\t DownlinkPut%sArray(_trans, _dev, %s, %s); \\\n" (Syntax.nameof (Basic t)) (Syntax.length_name varname) name + | FixedArray (t, varname, len) -> + let _s = Syntax.sizeof (Basic t) in + fprintf h "\t DownlinkPut%sFixedArray(_trans, _dev, %d, %s); \\\n" (Syntax.nameof (Basic t)) len name let print_parameter h = function - (Array _, s, _) -> fprintf h "%s, %s" (Syntax.length_name s) s + (Array _, s, _) -> fprintf h "%s, %s" (Syntax.length_name s) s + | (FixedArray _, s, _) -> fprintf h "%s" s | (_, s, _) -> fprintf h "%s" s let print_macro_parameters h = function @@ -242,7 +252,13 @@ module Gen_onboard = struct sprintf "({ union { uint64_t u; double f; } _f; _f.u = (uint64_t)(%s); Swap32IfBigEndian(_f.u); _f.f; })" !s | 4 -> sprintf "(%s)(*((uint8_t*)_payload+%d)|*((uint8_t*)_payload+%d+1)<<8|((uint32_t)*((uint8_t*)_payload+%d+2))<<16|((uint32_t)*((uint8_t*)_payload+%d+3))<<24)" pprz_type.Pprz.inttype o o o o - | _ -> failwith "unexpected size in Gen_messages.print_get_macros. Possibly since a Telemetry message was defined with a field type of string." in + | 8 -> + let s = ref (sprintf "(%s)(*((uint8_t*)_payload+%d)" pprz_type.Pprz.inttype o) in + for i = 1 to 7 do + s := !s ^ sprintf "|((uint64_t)*((uint8_t*)_payload+%d+%d))<<%d" o i (8*i) + done; + sprintf "%s)" !s + | _ -> failwith "unexpected size in Gen_messages.print_get_macros" in (** To be an array or not to be an array: *) match _type with @@ -263,6 +279,16 @@ module Gen_onboard = struct fprintf h "#define DL_%s_%s(_payload) ((%s*)(_payload+%d))\n" msg_name field_name pprz_type.Pprz.inttype !offset; offset := -1 (** Mark for no more fields *) + | FixedArray (t, _varname, len) -> + (** The macro to access to the length of the array *) + fprintf h "#define DL_%s_%s_length(_payload) (%d)\n" msg_name field_name len; + (** The macro to access to the array itself *) + let pprz_type = Syntax.assoc_types t in + if check_alignment && !offset mod (min pprz_type.Pprz.size 4) <> 0 then + failwith (sprintf "Wrong alignment of field '%s' in message '%s" field_name msg_name); + + fprintf h "#define DL_%s_%s(_payload) ((%s*)(_payload+%d))\n" msg_name field_name pprz_type.Pprz.inttype !offset; + offset := !offset + (pprz_type.Pprz.size*len) in fprintf h "\n";