18 changed files with 362 additions and 176 deletions
@ -0,0 +1,43 @@ |
|||||
|
/*
|
||||
|
* ads_converter.cpp |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#include "ads_converter.h" |
||||
|
#include "double_buffer.h" |
||||
|
#include "helper_structs.h" |
||||
|
namespace rijnfel { |
||||
|
|
||||
|
cAdsConverter::cAdsConverter(cADC<ads::ads_sample_t, int32_t> & i_adc) : |
||||
|
m_adc(i_adc), m_rawSamples(this) { |
||||
|
// TODO Auto-generated constructor stub
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
cAdsConverter::~cAdsConverter() { |
||||
|
// TODO Auto-generated destructor stub
|
||||
|
} |
||||
|
|
||||
|
void cAdsConverter::ReceiveCallback(void* i_data, cDataReceiver* i_provider) { |
||||
|
//We dont car for the provider
|
||||
|
cDoubleBuffer<ads::ads_sample_t> * i_adcBuffer = static_cast<cDoubleBuffer<ads::ads_sample_t>*>(i_data); |
||||
|
ads::ads_sample_t * buf = &i_adcBuffer->GetReadyBuffer()[0]; |
||||
|
if (buf != NULL) { |
||||
|
sSizedArray arr; |
||||
|
int pos = buf->mux - ads::eInputMux::AIN_0; |
||||
|
int64_t average = 0; |
||||
|
int size = i_adcBuffer->GetSize(); |
||||
|
arr.size = size; |
||||
|
arr.array = new uint32_t[size]; |
||||
|
for (int i = 0; i < size; i++) { |
||||
|
arr.array[i] = m_adc.ConvertSample(buf[i]); |
||||
|
} |
||||
|
m_convertedSamples[pos].Push(static_cast<void *>(&arr)); |
||||
|
delete arr.array; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} /* namespace rijnfel */ |
||||
|
|
@ -0,0 +1,31 @@ |
|||||
|
/*
|
||||
|
* ads_converter.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_ADS_CONVERTER_H_ |
||||
|
#define APP_ADS_CONVERTER_H_ |
||||
|
|
||||
|
#include "data_receiver.h" |
||||
|
#include "data_provider.h" |
||||
|
#include "ads101x.h" |
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
class cAdsConverter: public cDataSink { |
||||
|
public: |
||||
|
cAdsConverter(cADC<ads::ads_sample_t, int32_t> & i_adc); |
||||
|
virtual void ReceiveCallback(void * i_data, cDataReceiver * i_provider); |
||||
|
// Every channel has its own provider, after this we can not distinguish anymore
|
||||
|
cDataProvider m_convertedSamples[4]; |
||||
|
cDataReceiver m_rawSamples; |
||||
|
virtual ~cAdsConverter(); |
||||
|
private: |
||||
|
cADC<ads::ads_sample_t, int32_t> & m_adc; |
||||
|
}; |
||||
|
|
||||
|
} /* namespace rijnfel */ |
||||
|
|
||||
|
#endif /* APP_ADS_CONVERTER_H_ */ |
@ -0,0 +1,44 @@ |
|||||
|
/*
|
||||
|
* data_provider.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_DATA_PROVIDER_H_ |
||||
|
#define APP_DATA_PROVIDER_H_ |
||||
|
|
||||
|
#include <vector> |
||||
|
#include <stddef.h> |
||||
|
|
||||
|
#include "data_receiver.h" |
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
class cDataProvider { |
||||
|
public: |
||||
|
void Connect(cDataReceiver * i_receiver) { |
||||
|
m_receivers.push_back(i_receiver); |
||||
|
} |
||||
|
void Push(void * i_data) { |
||||
|
typedef std::vector<cDataReceiver*>::iterator Iterator; |
||||
|
for (Iterator it = m_receivers.begin(), it_e = m_receivers.end(); it != it_e; ++it) { |
||||
|
(*it)->Receive(i_data); |
||||
|
} |
||||
|
} |
||||
|
~cDataProvider() { |
||||
|
//
|
||||
|
//typedef std::vector<cDataReceiver>::iterator Iterator;
|
||||
|
//for (Iterator it = receivers.begin(), it_e = receivers.end(); it != it_e; ++it) {
|
||||
|
// if ((*it) != NULL) {
|
||||
|
// delete (*it);
|
||||
|
// }
|
||||
|
//}
|
||||
|
} |
||||
|
private: |
||||
|
std::vector<cDataReceiver*> m_receivers; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif /* APP_DATA_PROVIDER_H_ */ |
@ -0,0 +1,29 @@ |
|||||
|
/*
|
||||
|
* data_receiver.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_DATA_RECEIVER_H_ |
||||
|
#define APP_DATA_RECEIVER_H_ |
||||
|
|
||||
|
#include "data_sink.h" |
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
class cDataReceiver { |
||||
|
public: |
||||
|
cDataReceiver(cDataSink * i_sink) { |
||||
|
m_sink = i_sink; |
||||
|
} |
||||
|
void Receive(void * i_data) { |
||||
|
m_sink->ReceiveCallback(i_data, this); |
||||
|
} |
||||
|
private: |
||||
|
cDataSink * m_sink; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#endif /* APP_DATA_RECEIVER_H_ */ |
@ -0,0 +1,26 @@ |
|||||
|
/*
|
||||
|
* data_sink.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_DATA_SINK_H_ |
||||
|
#define APP_DATA_SINK_H_ |
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
class cDataReceiver; |
||||
|
|
||||
|
class cDataSink { |
||||
|
public: |
||||
|
virtual void ReceiveCallback(void * i_data, cDataReceiver * i_receiver); |
||||
|
protected: |
||||
|
cDataSink() { |
||||
|
} |
||||
|
virtual ~cDataSink() { |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
#endif /* APP_DATA_SINK_H_ */ |
@ -0,0 +1,22 @@ |
|||||
|
/*
|
||||
|
* helper_structs.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_HELPER_STRUCTS_H_ |
||||
|
#define APP_HELPER_STRUCTS_H_ |
||||
|
|
||||
|
namespace rijnfel{ |
||||
|
|
||||
|
struct sSizedArray{ |
||||
|
size_t size; |
||||
|
uint32_t * array; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif /* APP_HELPER_STRUCTS_H_ */ |
@ -0,0 +1,38 @@ |
|||||
|
/*
|
||||
|
* signal_process.cpp |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#include "signal_process.h" |
||||
|
#include "helper_structs.h" |
||||
|
#include <stddef.h> |
||||
|
//TODO remove this
|
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
cSignalProcess::cSignalProcess() : |
||||
|
m_incommingData(this) { |
||||
|
m_currentIndex = 0; |
||||
|
m_currentMaxIndex = 0; |
||||
|
m_currentBuffer = NULL; |
||||
|
// TODO Auto-generated constructor stub
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
cSignalProcess::~cSignalProcess() { |
||||
|
// TODO Auto-generated destructor stub
|
||||
|
} |
||||
|
|
||||
|
void cSignalProcess::ReceiveCallback(void* i_data, cDataReceiver* i_provider) { |
||||
|
sSizedArray * arr = static_cast<sSizedArray*>(i_data); |
||||
|
process(arr->array, arr->size); |
||||
|
m_processedData.Push(i_data); |
||||
|
} |
||||
|
|
||||
|
void cSignalProcess::process(uint32_t* io_array, size_t size) { |
||||
|
//Do whatever here really
|
||||
|
} |
||||
|
|
||||
|
} /* namespace rijnfel */ |
@ -0,0 +1,31 @@ |
|||||
|
/*
|
||||
|
* signal_process.h |
||||
|
* |
||||
|
* Created on: Aug 22, 2017 |
||||
|
* Author: Elmar |
||||
|
*/ |
||||
|
|
||||
|
#ifndef APP_SIGNAL_PROCESS_H_ |
||||
|
#define APP_SIGNAL_PROCESS_H_ |
||||
|
#include "data_receiver.h" |
||||
|
#include "data_provider.h" |
||||
|
|
||||
|
namespace rijnfel { |
||||
|
|
||||
|
class cSignalProcess: public cDataSink { |
||||
|
public: |
||||
|
cSignalProcess(); |
||||
|
virtual ~cSignalProcess(); |
||||
|
void ReceiveCallback(void * i_data, cDataReceiver * i_provider); |
||||
|
cDataReceiver m_incommingData; |
||||
|
cDataProvider m_processedData; |
||||
|
protected: |
||||
|
void process(uint32_t * io_array, size_t size); |
||||
|
uint32_t * m_currentBuffer; |
||||
|
uint32_t m_currentIndex; |
||||
|
uint32_t m_currentMaxIndex; |
||||
|
}; |
||||
|
|
||||
|
} /* namespace rijnfel */ |
||||
|
|
||||
|
#endif /* APP_SIGNAL_PROCESS_H_ */ |
@ -1,44 +0,0 @@ |
|||||
//----------------------------------------------------------------------------------------------------------------------------
|
|
||||
// Project: Uppsense
|
|
||||
// Name: signal_processor.cpp
|
|
||||
// Author: Maximilian Stiefel
|
|
||||
// Date: 22.08.2017
|
|
||||
//
|
|
||||
// Description:
|
|
||||
//
|
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
|
||||
|
|
||||
//-------------------------------------Libraries------------------------------------------------------------------------------
|
|
||||
#include "signal_processor.h" |
|
||||
#include <SmingCore/SmingCore.h> |
|
||||
|
|
||||
//-------------------------------------Namespaces-----------------------------------------------------------------------------
|
|
||||
namespace rijnfel { |
|
||||
|
|
||||
cSignalProcessor* cSignalProcessor::s_instance = NULL; |
|
||||
|
|
||||
//-------------------------------------GetInstance----------------------------------------------------------------------------
|
|
||||
cSignalProcessor* cSignalProcessor::GetInstance() |
|
||||
{ |
|
||||
if(s_instance == NULL) |
|
||||
s_instance = new cSignalProcessor; |
|
||||
return s_instance; |
|
||||
} |
|
||||
|
|
||||
//-------------------------------------receiveADCValues-----------------------------------------------------------------------
|
|
||||
void cSignalProcessor::receiveADCValues(cADC<ads::ads_sample_t, int32_t> & i_adc, cDoubleBuffer<ads::ads_sample_t>& i_adcBuffer) { |
|
||||
ads::ads_sample_t * buf = &i_adcBuffer.GetReadyBuffer()[0]; |
|
||||
if (buf != NULL) { |
|
||||
int pos = buf->mux - ads::eInputMux::AIN_0; |
|
||||
int64_t average = 0; |
|
||||
int size = i_adcBuffer.GetSize(); |
|
||||
for (int i = 0; i < size; i++) { |
|
||||
average += i_adc.ConvertSample(buf[i]); |
|
||||
} |
|
||||
if (size != 0) { |
|
||||
average /= size; |
|
||||
} |
|
||||
Serial.printf("Average: %d/n/r", average); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,66 +0,0 @@ |
|||||
//----------------------------------------------------------------------------------------------------------------------------
|
|
||||
// Project: Uppsense
|
|
||||
// Name: signal_processor.h
|
|
||||
// Author: Maximilian Stiefel
|
|
||||
// Date: 22.08.2017
|
|
||||
//
|
|
||||
// Description:
|
|
||||
//
|
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
|
||||
|
|
||||
#ifndef APP_SIGNAL_PROCESSOR_H_ |
|
||||
#define APP_SIGNAL_PROCESSOR_H_ |
|
||||
|
|
||||
//-------------------------------------Libraries------------------------------------------------------------------------------
|
|
||||
#include <stdint.h> |
|
||||
#include "defines.h" |
|
||||
#include "double_buffer.h" |
|
||||
#include "adc.h" |
|
||||
#include "ads101x.h" |
|
||||
|
|
||||
//-------------------------------------Defines--------------------------------------------------------------------------------
|
|
||||
|
|
||||
//-------------------------------------Namespaces-----------------------------------------------------------------------------
|
|
||||
namespace rijnfel { |
|
||||
|
|
||||
//-------------------------------------Enums----------------------------------------------------------------------------------
|
|
||||
|
|
||||
//-------------------------------------cDAC101085-----------------------------------------------------------------------------
|
|
||||
/** Small simple driver for the TI DAC101C085.
|
|
||||
*/ |
|
||||
class cSignalProcessor |
|
||||
{ |
|
||||
|
|
||||
public: |
|
||||
/**
|
|
||||
* @brief Returns the global cSignalProcessor instance. |
|
||||
* Only one webserver should ever be running |
|
||||
* @return global cSignalProcessor instance |
|
||||
* */ |
|
||||
static cSignalProcessor *GetInstance(); |
|
||||
public: |
|
||||
/**
|
|
||||
* @brief Notifies object that new samples are available. |
|
||||
* @param i_adc Instance of the adc sensor. |
|
||||
* @param i_adcBuffer Buffer containing the raw adc values. |
|
||||
* */ |
|
||||
void receiveADCValues(cADC<ads::ads_sample_t, int32_t> & i_adc, cDoubleBuffer<ads::ads_sample_t> & i_adcBuffer); |
|
||||
|
|
||||
private: |
|
||||
// Singleton instance
|
|
||||
static cSignalProcessor *s_instance; |
|
||||
/**
|
|
||||
* @brief Constructor is private, so it can not be called. |
|
||||
*/ |
|
||||
cSignalProcessor(){}; |
|
||||
/**
|
|
||||
* @brief Copy constructor is private, so it can not be called. |
|
||||
*/ |
|
||||
cSignalProcessor(cSignalProcessor const&){}; |
|
||||
/**
|
|
||||
* @brief Assignment operator is private, so it can not be used. |
|
||||
*/ |
|
||||
cSignalProcessor& operator=(cSignalProcessor const&){}; |
|
||||
}; |
|
||||
} |
|
||||
#endif /* APP_SIGNAL_PROCESSOR_H_ */ |
|
Loading…
Reference in new issue