Studentenversion des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataChannelTestUtility.cc 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "dataChannelTestUtility.h"
  2. #include "../../software/signal_processing/system/data_channel.h"
  3. #include <fstream>
  4. #include <gtest/gtest.h>
  5. void dataChannelRead( uint32_t base, float * data ) {
  6. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  7. data_channel_read( base, reinterpret_cast< uint32_t * >( & data[ i ] ) );
  8. }
  9. }
  10. void dataChannelRead( uint32_t base, uint32_t * data ) {
  11. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  12. data_channel_read( base, & data[ i ] );
  13. }
  14. }
  15. uint32_t dataChannelRead( uint32_t base ) {
  16. uint32_t data;
  17. data_channel_read( base, & data );
  18. return data;
  19. }
  20. void dataChannelCheck( const float * data, const float * expected ) {
  21. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  22. ASSERT_NEAR( data[ i ], expected[ i ], 1e-1 ) << " with i = " << i;
  23. }
  24. }
  25. void dataChannelCheck( const uint32_t * data, const uint32_t * expected ) {
  26. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  27. ASSERT_EQ( data[ i ], expected[ i ] ) << " with i = " << i;
  28. }
  29. }
  30. void dataChannelFill( uint32_t base, const float * data ) {
  31. for ( uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i ) {
  32. data_channel_write( base, * reinterpret_cast< const uint32_t * >( & data[ i ] ) );
  33. }
  34. }
  35. void dataChannelReadAndWriteToFile( const void * data, const char * filename ) {
  36. std::ofstream out;
  37. out.open( filename, std::ios::out );
  38. auto float_data = reinterpret_cast< const float * >( data );
  39. auto u32_data = reinterpret_cast< const uint32_t * >( data );
  40. out << "float_data = [" << std::setprecision(6) << std::fixed << std::scientific << float_data[ 0 ];
  41. for ( uint32_t i = 1; i < DATA_CHANNEL_DEPTH; ++i ) {
  42. out << "," << float_data[ i ];
  43. }
  44. out << "]" << std::endl;
  45. out << "hex_data = [" << std::hex << "0x" << u32_data[ 0 ];
  46. for ( uint32_t i = 1; i < DATA_CHANNEL_DEPTH; ++i ) {
  47. out << ",0x" << u32_data[ i ];
  48. }
  49. out << "]" << std::endl;
  50. out.close();
  51. }
  52. void dataChannelReadAndWriteToFile( uint32_t data, const char * filename ) {
  53. std::ofstream out;
  54. out.open( filename, std::ios::out );
  55. auto float_data = reinterpret_cast< const float * >( & data );
  56. auto u32_data = reinterpret_cast< const uint32_t * >( & data );
  57. out << "float_data = [" << std::setprecision(6) << std::fixed << std::scientific << float_data[ 0 ];
  58. out << "]" << std::endl;
  59. out << "hex_data = [" << std::hex << "0x" << u32_data[ 0 ];
  60. out << "]" << std::endl;
  61. out.close();
  62. }
  63. void dataChannelCheckAndWriteToFile( uint32_t base, const float * expected, const char * filename ) {
  64. float data[ DATA_CHANNEL_DEPTH ];
  65. memset( data, 0.0, sizeof( float ) * DATA_CHANNEL_DEPTH );
  66. dataChannelRead( base, data );
  67. dataChannelReadAndWriteToFile( data, filename );
  68. dataChannelCheck( data, expected );
  69. }
  70. void dataChannelWriteToFile( uint32_t base, const char * filename ) {
  71. float data[ DATA_CHANNEL_DEPTH ];
  72. memset( data, 0.0, sizeof( float ) * DATA_CHANNEL_DEPTH );
  73. dataChannelRead( base, data );
  74. dataChannelReadAndWriteToFile( data, filename );
  75. }
  76. void dataChannelCheckAndWriteToFile( uint32_t base, const uint32_t * expected, const char * filename ) {
  77. uint32_t data[ DATA_CHANNEL_DEPTH ];
  78. memset( data, 0, sizeof( uint32_t ) * DATA_CHANNEL_DEPTH );
  79. dataChannelRead( base, data );
  80. dataChannelReadAndWriteToFile( data, filename );
  81. dataChannelCheck( data, expected );
  82. }
  83. void dataChannelCheck( uint32_t base, uint32_t expected, const char * filename ) {
  84. uint32_t data = dataChannelRead( base );
  85. ASSERT_EQ( data, expected );
  86. }