Alex Pirciu
/
BFMC
a
include/Examples/Sensors/sensorpublisher.inl@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | namespace examples{ |
alexpirciu | 1:ceee5a608e7c | 2 | namespace sensors{ |
alexpirciu | 1:ceee5a608e7c | 3 | /** \brief Constructor for the CEncoderFilter class |
alexpirciu | 1:ceee5a608e7c | 4 | * |
alexpirciu | 1:ceee5a608e7c | 5 | * Constructor method |
alexpirciu | 1:ceee5a608e7c | 6 | * |
alexpirciu | 1:ceee5a608e7c | 7 | * @param f_period period value |
alexpirciu | 1:ceee5a608e7c | 8 | * @param f_sensors sensor array |
alexpirciu | 1:ceee5a608e7c | 9 | * @param f_serial reference to the serial object |
alexpirciu | 1:ceee5a608e7c | 10 | */ |
alexpirciu | 1:ceee5a608e7c | 11 | template <class C_Sensor,uint Nr_Senrsor> |
alexpirciu | 1:ceee5a608e7c | 12 | ProximityPublisher<C_Sensor,Nr_Senrsor>::ProximityPublisher(uint32_t f_period |
alexpirciu | 1:ceee5a608e7c | 13 | ,SensorArrayT f_sensors |
alexpirciu | 1:ceee5a608e7c | 14 | ,Serial& f_serial) |
alexpirciu | 1:ceee5a608e7c | 15 | :CTask(f_period) |
alexpirciu | 1:ceee5a608e7c | 16 | ,m_sensors(f_sensors) |
alexpirciu | 1:ceee5a608e7c | 17 | ,m_serial(f_serial) |
alexpirciu | 1:ceee5a608e7c | 18 | ,m_isActivate(false) |
alexpirciu | 1:ceee5a608e7c | 19 | { |
alexpirciu | 1:ceee5a608e7c | 20 | } |
alexpirciu | 1:ceee5a608e7c | 21 | |
alexpirciu | 1:ceee5a608e7c | 22 | /** \brief Serial callback method |
alexpirciu | 1:ceee5a608e7c | 23 | * |
alexpirciu | 1:ceee5a608e7c | 24 | * Serial callback attaching serial callback to controller object |
alexpirciu | 1:ceee5a608e7c | 25 | * |
alexpirciu | 1:ceee5a608e7c | 26 | * @param obj PID controller object |
alexpirciu | 1:ceee5a608e7c | 27 | * @param a string to read data from |
alexpirciu | 1:ceee5a608e7c | 28 | * @param b string to write data to |
alexpirciu | 1:ceee5a608e7c | 29 | * |
alexpirciu | 1:ceee5a608e7c | 30 | */ |
alexpirciu | 1:ceee5a608e7c | 31 | template <class C_Sensor,uint Nr_Senrsor> |
alexpirciu | 1:ceee5a608e7c | 32 | void ProximityPublisher<C_Sensor,Nr_Senrsor>::staticSerialCallback(void* obj,char const * a, char * b) |
alexpirciu | 1:ceee5a608e7c | 33 | { |
alexpirciu | 1:ceee5a608e7c | 34 | ProximityPublisher* self = static_cast<ProximityPublisher*>(obj); |
alexpirciu | 1:ceee5a608e7c | 35 | self->serialCallback(a,b); |
alexpirciu | 1:ceee5a608e7c | 36 | } |
alexpirciu | 1:ceee5a608e7c | 37 | |
alexpirciu | 1:ceee5a608e7c | 38 | /** \brief Serial callback actions |
alexpirciu | 1:ceee5a608e7c | 39 | * |
alexpirciu | 1:ceee5a608e7c | 40 | * Serial callback |
alexpirciu | 1:ceee5a608e7c | 41 | * |
alexpirciu | 1:ceee5a608e7c | 42 | * @param a string to read data from |
alexpirciu | 1:ceee5a608e7c | 43 | * @param b string to write data to |
alexpirciu | 1:ceee5a608e7c | 44 | * |
alexpirciu | 1:ceee5a608e7c | 45 | */ |
alexpirciu | 1:ceee5a608e7c | 46 | template <class C_Sensor,uint Nr_Senrsor> |
alexpirciu | 1:ceee5a608e7c | 47 | void ProximityPublisher<C_Sensor,Nr_Senrsor>::serialCallback(char const * a, char * b){ |
alexpirciu | 1:ceee5a608e7c | 48 | int l_isActivate=0; |
alexpirciu | 1:ceee5a608e7c | 49 | uint32_t l_res = sscanf(a,"%d",&l_isActivate); |
alexpirciu | 1:ceee5a608e7c | 50 | if(l_res==1){ |
alexpirciu | 1:ceee5a608e7c | 51 | m_isActivate=(l_isActivate>=1); |
alexpirciu | 1:ceee5a608e7c | 52 | sprintf(b,"ack;;"); |
alexpirciu | 1:ceee5a608e7c | 53 | }else{ |
alexpirciu | 1:ceee5a608e7c | 54 | sprintf(b,"sintax error;;"); |
alexpirciu | 1:ceee5a608e7c | 55 | } |
alexpirciu | 1:ceee5a608e7c | 56 | } |
alexpirciu | 1:ceee5a608e7c | 57 | |
alexpirciu | 1:ceee5a608e7c | 58 | /** \brief Method called each f_period |
alexpirciu | 1:ceee5a608e7c | 59 | * |
alexpirciu | 1:ceee5a608e7c | 60 | * |
alexpirciu | 1:ceee5a608e7c | 61 | * |
alexpirciu | 1:ceee5a608e7c | 62 | */ |
alexpirciu | 1:ceee5a608e7c | 63 | template <class C_Sensor,uint Nr_Senrsor> |
alexpirciu | 1:ceee5a608e7c | 64 | void ProximityPublisher<C_Sensor,Nr_Senrsor>::_run(){ |
alexpirciu | 1:ceee5a608e7c | 65 | if(!m_isActivate) return; |
alexpirciu | 1:ceee5a608e7c | 66 | char l_buf[100]; |
alexpirciu | 1:ceee5a608e7c | 67 | sprintf(l_buf,"@DSPB:"); |
alexpirciu | 1:ceee5a608e7c | 68 | for(uint8_t i=0;i<Nr_Senrsor;++i){ |
alexpirciu | 1:ceee5a608e7c | 69 | |
alexpirciu | 1:ceee5a608e7c | 70 | sprintf(l_buf,"%s%2.2f;",l_buf,m_sensors[i]->getValue()); |
alexpirciu | 1:ceee5a608e7c | 71 | } |
alexpirciu | 1:ceee5a608e7c | 72 | sprintf(l_buf,"%s;\n\r",l_buf); |
alexpirciu | 1:ceee5a608e7c | 73 | m_serial.printf("%s",l_buf); |
alexpirciu | 1:ceee5a608e7c | 74 | |
alexpirciu | 1:ceee5a608e7c | 75 | } |
alexpirciu | 1:ceee5a608e7c | 76 | }; // namespace sensors |
alexpirciu | 1:ceee5a608e7c | 77 | }; // namespace examples |
alexpirciu | 1:ceee5a608e7c | 78 |