pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


ecu-control rai use CPP ADS class, try1
Posted by Anonymous on Thu 4th Oct 2018 17:06
raw | new post

  1. diff --git a/ptxdist/local_src/ecu-control/ecuioanalog.cpp b/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  2. index e3841ef..842b5a2 100644
  3. --- a/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  4. +++ b/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  5. @@ -30,6 +30,7 @@
  6.  
  7.  #include <stdio.h>
  8.  #include <unistd.h>
  9. +#include <errno.h>
  10.  #include <stdlib.h>
  11.  #include <fcntl.h>
  12.  #include <string.h>
  13. @@ -52,6 +53,11 @@
  14.  #include "tle82353sa.h"
  15.  #include "pca9505.h"
  16.  
  17. +#define ADS_USE_LIBCOMMON 1
  18. +#ifdef ADS_USE_LIBCOMMON
  19. +#include "ads7953.h"
  20. +#endif
  21. +
  22.  /*****************************************************************************/
  23.  /*    here: Defines                                                          */
  24.  /*****************************************************************************/
  25. @@ -274,14 +280,68 @@ int EcuIOAnalog::writeOutChannel(const ECuParameter &parameters)
  26.  
  27.  int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  28.  {
  29. +#ifdef ADS_USE_LIBCOMMON
  30. +ulValue = 0xDEADBEEF;
  31. +
  32. +
  33. +       struct ADS7953::ADS_CHANNEL_DATA        ads_data;
  34. +       ADS7953                                 *chip = NULL;
  35. +       int                                     usChannel = -1;
  36. +
  37. +       (void)memset(&ads_data, 0, sizeof(ads_data));
  38. +
  39. +
  40. +       if ((channel > 0) && (channel < 17))
  41. +       {
  42. +               chip = new ADS7953(ADS7953_ADC0_DEVICEPATH);
  43. +               usChannel = channel - 1;
  44. +       }
  45. +       else if ((channel > 16) && (channel < 33)){
  46. +               chip = new ADS7953(ADS7953_ADC1_DEVICEPATH);
  47. +               usChannel = channel - 16 - 1;
  48. +       }
  49. +
  50. +       if (!chip)
  51. +       {
  52. +               (void)fprintf(stderr,
  53. +                       "EcuIOAnalog::readChannelFromADS7953: could not get chip for %d\n",
  54. +                       channel);
  55. +               return RETCODE_GENERAL_ERROR;
  56. +       }
  57. +
  58. +       (void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953: chip at %lx, usChannel=%d\n",
  59. +               (long)chip,
  60. +               (int)usChannel);
  61. +
  62. +       chip->setAuto2MaxChannel(16);
  63. +
  64. +       // fixme: retcode!!
  65. +       if (!chip->readChannels(&ads_data))
  66. +               (void)fprintf(stderr, "readChannels() 1 failed\n");
  67. +
  68. +       for(int cn=0 ; cn < 16 ; cn++)
  69. +       {
  70. +               // fixme: ads_data.mask needs to be honored
  71. +               (void)fprintf(stderr, "cn=%d\tdata=%lx\n", (int)cn, (long)ads_data.data[cn]);
  72. +       }
  73. +
  74. +       ulValue = ads_data.data[usChannel];
  75. +
  76. +       delete chip;
  77. +
  78. +       return RETCODE_OK;
  79. +#else
  80. +ulValue = 0xDEADBEEF;
  81.     int iRet (RETCODE_OK);
  82.     int fd = -1;
  83.     char usChannel=0;
  84.     unsigned short *pUS;
  85. -   unsigned char wr_buf[32];
  86. -   unsigned char rd_buf[64];
  87. +   unsigned char wr_buf[4096];
  88. +   unsigned char rd_buf[4096];
  89.     unsigned short readChannel;
  90.     struct spi_ioc_transfer     xfer;
  91. +   int retSpiNum;
  92. +
  93.     memset(&xfer, 0, sizeof xfer);
  94.     memset(&wr_buf[0], 0, sizeof wr_buf);
  95.     memset(&rd_buf[0], 0, sizeof rd_buf);
  96. @@ -322,26 +382,55 @@ int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  97.         */
  98.  
  99.        /* program the channel */
  100. +#define SIZEOF_MODE0_COMMAND (6)
  101.        pUS = (unsigned short*)&wr_buf[0];
  102. -      xfer.len = 6;
  103. +      xfer.len = SIZEOF_MODE0_COMMAND;
  104.        *pUS = 0x1800 | ( usChannel << 7 );
  105. +#if 1
  106. +      *++pUS = 0x1800 | ( usChannel << 7 );
  107. +      xfer.len += SIZEOF_MODE0_COMMAND;
  108. +#endif
  109.  
  110. -      ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
  111.  
  112. -      pUS = (unsigned short*)&rd_buf[4];
  113. +(void)fprintf(stderr, "wr_buf='");
  114. +for (unsigned int cn=0 ; cn < (xfer.len*2) ; cn++)
  115. +{
  116. +       (void)fprintf(stderr, "%2.2x ", (int)wr_buf[cn]);
  117. +}
  118. +(void)fprintf(stderr, "'\n");
  119. +
  120. +      errno=0;
  121. +      retSpiNum = ioctl(fd, SPI_IOC_MESSAGE(2), &xfer);
  122. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): retSpiNum=%d, should be 2!, strerror=%s\n",
  123. +       (int)retSpiNum,
  124. +       strerror(errno));
  125. +
  126.        readChannel = ( rd_buf[5] >> 4 );
  127. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): readChannel=%d\n, usChannel=%d\n",
  128. +       (int)readChannel,
  129. +       (int)usChannel);
  130. +
  131. +(void)fprintf(stderr, "rd_buf='");
  132. +for (int cn=0 ; cn < retSpiNum ; cn++)
  133. +{
  134. +       (void)fprintf(stderr, "%2.2x ", (int)rd_buf[cn]);
  135. +}
  136. +(void)fprintf(stderr, "'\n");
  137. +
  138.        if( readChannel == usChannel ){
  139.           ulValue = (rd_buf[5] & 0x0f) << 8 | rd_buf[4];
  140.           iRet = RETCODE_OK;
  141. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): OK\n");
  142.        }
  143.        else{
  144.           iRet = RETCODE_GENERAL_ERROR;
  145. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): readChannel == usChannel failed\n");
  146.        }
  147.        close(fd);
  148.     }
  149.  
  150.     return iRet;
  151. -
  152. +#endif /* ADS_USE_LIBCOMMON */
  153.  }
  154.  
  155.  int EcuIOAnalog::readChannelFromMAX11628( int channel, unsigned long &ulValue )

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at