IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
message_interface_common.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file message_interface_common.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.6
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief Common functions for the message generator and the message interpreter.
9 *
10 * @verbatim
11  ===============================================================================
12  ##### Description #####
13  ===============================================================================
14  [..]
15  Routines to access channel_id mapping into physical sensors populated on the board
16  given
17  +-----+-----+-----+-----+-----+ which assigns a unique Id to each channel
18  | ch | u1 | u2 | u3 | u4 | a logic is implemented to manage the mapping
19  +-----+-----+-----+-----+-----+ into the IRPyro API
20  | 0 |0x01 |0x06 |0x0b |0x10 |
21  +-----+-----+-----+-----+-----+
22  | 1 |0x02 |0x07 |0x0c |0x11 |
23  +-----+-----+-----+-----+-----+
24  | 2 |0x03 |0x08 |0x0d |0x12 |
25  +-----+-----+-----+-----+-----+
26  | 3 |0x04 |0x09 |0x0e |0x13 |
27  +-----+-----+-----+-----+-----+
28  | 4 |0x05 |0x0a |0x0f |0x14 |
29  +-----+-----+-----+-----+-----+
30  [..]
31  @endverbatim
32  ******************************************************************************
33  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
34  @verbatim
35  Copyright (c) 2018, _KEMET, Ltd
36  All rights reserved.
37 
38  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
39  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
42  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  @endverbatim
49  ******************************************************************************
50  */
51 /* Includes ------------------------------------------------------------------*/
53 
54 /** @defgroup message_interface_common Message Interface Common
55  * @ingroup message_interface
56  * @brief Functions common to Message Generator and Message Interpreter
57  * @verbatim
58  *
59  * @endverbatim
60  * @note
61  * @{
62  */
63 /**
64 * @brief check for channels. returns an array with the channels and count
65 */
66 static uint8_t channel_collect(uint8_t *channel_id)
67 {
68  uint8_t channel_count;
69  uint8_t channels_available;
70  for(channel_count = 0, channels_available=0; channels_available < NUMBER_OF_SCOPES_IN_THE_GUI; ++channels_available)
71  {
72  if (ChannelConfiguration[channels_available])
73  {
74  channel_id[channel_count] = ChannelConfiguration[channels_available];
75  ++ channel_count;
76  }
77  }
78  return channel_count;
79 }
80 /**
81 * @brief looks for a given channel id on the list of active channels
82 * @note returns the channel ordinal not the array index: 1st, 2nd, etc
83 */
84 static uint8_t channel_locate(const uint8_t *channels)
85 {
86  uint8_t op_result;
87  uint8_t *channel_found = NULL;
88  if (sensor_destination != 0x2A)
89  {
91  }
92  if (channel_found != NULL)
93  {
94  op_result = channel_found - channels +1;
95  }
96  else
97  {
98  op_result = 0;
99  }
100  return op_result;
101 }
102 /**
103  * @brief validation logic for available channels, sensor selected and channel location
104  */
105 static uint8_t channel_validate(uint8_t *idx, uint8_t *channel_count, uint8_t sensor_selected, uint8_t channel_location)
106 {
107  uint8_t op_result;
108  if (*channel_count)
109  {
110  if (sensor_selected == 0x2a)
111  {
112  *idx = 0;
113  op_result = 1;
114  }
115  else
116  {
117  if(channel_location)
118  {
119  op_result = 1;
120  -- channel_location; // decrement to use as array index
121  *idx = channel_location;
122  *channel_count = 1;
123  }
124  else
125  {
126  op_result = 0;
127  }
128  }
129  }
130  else
131  {
132  op_result = 0;
133  }
134  return op_result;
135 }
136 /**
137  * @brief configures for loop for single or multiple sensor operations
138  */
139 void process_parms_load(uint8_t *idx, uint8_t *num_sensors_to_process)
140 {
141  if (sensor_destination == 0x2A)
142  {
143  *idx =0;
144  *num_sensors_to_process = num_of_IRPyro_on_demo_board;
145  }
146  else
147  {
148  *idx = sensor_destination;
149  *num_sensors_to_process = 1;
150  }
151 }
152 /**
153  * @struct channel_configuration_map message_interface_common.c
154  * @brief assign a unique consecutive number to each channel on a maximum of four sensors
155  *
156  * The eevt gui has a maximum of four scopes to receive collected data from a configured
157  * channel. In order to present
158 */
160 {
161  uint8_t index;
164 };
165 const struct channel_configuration_map on_board[] =
166 {
167  {0x00,0,0},
168  {0x01,0,0},{0x02,0,1},{0x03,0,2},{0x04,0,3},{0x05,0,4},
169  {0x06,1,0},{0x07,1,1},{0x08,1,2},{0x09,1,3},{0x0A,1,4},
170  {0x0B,2,0},{0x0C,2,1},{0x0D,2,2},{0x0E,2,3},{0x0F,2,4},
171  {0x10,3,0},{0x11,3,1},{0x12,3,2},{0x13,3,3},{0x14,3,4}
172 };
173 static uint8_t channels[NUMBER_OF_SCOPES_IN_THE_GUI] = {0};
174 static uint8_t channel_processing_index = 0;
175 /**
176  * @brief prepares for channel_id requests
177  */
178 uint8_t channel_processing(uint8_t *channel_count)
179 {
180  uint8_t channel_location = 0;
181  uint8_t channel_ok = 0;
183  memset(channels, 0x00, NUMBER_OF_SCOPES_IN_THE_GUI);
184 
185  *channel_count = channel_collect(channels);
186  channel_location = channel_locate(channels);
187  channel_ok = channel_validate(&channel_processing_index, channel_count, sensor_destination, channel_location);
188 
189  return channel_ok;
190 }
191 /**
192  * @brief maps the GUI scope channel_id to physical sensor
193  */
194 uint8_t channel_id_to_sensor(void)
195 {
197  return op_result;
198 }
199 /**
200  * @brief maps the GUI scope channel_id to physical channel on the sensor
201  */
203 {
205  return op_result;
206 }
207 /**
208  * @brief increments the channel index
209  */
210 void channel_id_next(void)
211 {
213 }
214 /**
215 * @}
216 */
217 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
channel_processing_index
static uint8_t channel_processing_index
Definition: message_interface_common.c:174
channel_validate
static uint8_t channel_validate(uint8_t *idx, uint8_t *channel_count, uint8_t sensor_selected, uint8_t channel_location)
validation logic for available channels, sensor selected and channel location
Definition: message_interface_common.c:105
channel_configuration_map
assign a unique consecutive number to each channel on a maximum of four sensors
Definition: message_interface_common.c:160
channel_processing
uint8_t channel_processing(uint8_t *channel_count)
prepares for channel_id requests
Definition: message_interface_common.c:178
ChannelConfiguration
uint8_t ChannelConfiguration[NUMBER_OF_SCOPES_IN_THE_GUI]
Definition: main.c:79
channel_id_to_channel
uint8_t channel_id_to_channel(void)
maps the GUI scope channel_id to physical channel on the sensor
Definition: message_interface_common.c:202
sensor_destination
uint8_t sensor_destination
Definition: main.c:297
channel_configuration_map::map_channel_selected
uint8_t map_channel_selected
Definition: message_interface_common.c:163
channel_id_to_sensor
uint8_t channel_id_to_sensor(void)
maps the GUI scope channel_id to physical sensor
Definition: message_interface_common.c:194
channel_locate
static uint8_t channel_locate(const uint8_t *channels)
looks for a given channel id on the list of active channels
Definition: message_interface_common.c:84
channel_configuration_map::index
uint8_t index
Definition: message_interface_common.c:161
num_of_IRPyro_on_demo_board
uint8_t num_of_IRPyro_on_demo_board
Definition: main.c:74
on_board
const struct channel_configuration_map on_board[]
Definition: message_interface_common.c:165
op_result
decode_result_type op_result
Definition: message_unpack.c:153
channel_id_next
void channel_id_next(void)
increments the channel index
Definition: message_interface_common.c:210
sensor_selected
uint8_t sensor_selected
Definition: message_generator.c:52
NUMBER_OF_SCOPES_IN_THE_GUI
#define NUMBER_OF_SCOPES_IN_THE_GUI
Definition: externals.h:30
channel_configuration_map::map_sensor_selected
uint8_t map_sensor_selected
Definition: message_interface_common.c:162
channel_collect
static uint8_t channel_collect(uint8_t *channel_id)
check for channels. returns an array with the channels and count
Definition: message_interface_common.c:66
process_parms_load
void process_parms_load(uint8_t *idx, uint8_t *num_sensors_to_process)
configures for loop for single or multiple sensor operations
Definition: message_interface_common.c:139
channels
static uint8_t channels[NUMBER_OF_SCOPES_IN_THE_GUI]
Definition: message_interface_common.c:173
message_interface_common.h