IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
message_pack.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file message_pack.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.6
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief Sensor data/configuration is packaged to be send to the GUI
9 *
10 * @verbatim
11  ===============================================================================
12  ##### Description #####
13  ===============================================================================
14  [..]
15  [..]
16  @endverbatim
17  ******************************************************************************
18  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
19  @verbatim
20  Copyright (c) 2018, _KEMET, Ltd
21  All rights reserved.
22 
23  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
24  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
27  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  @endverbatim
34 
35  ******************************************************************************
36  */
37 /* Includes ------------------------------------------------------------------*/
38 #ifndef MESSAGE_PACK
39 #include "message_pack.h"
40 #endif
41 extern uint8_t EmitterStatus ; // capture
42 extern uint8_t isStreaming; // capture
43 extern uint8_t status_need_to_send;
44 extern uint8_t mode_sleeping ; // capture
45 extern uint8_t mode_lowPower ; // capture
46 /** @defgroup message_pack Message Pack
47  * @ingroup Message_Handler
48  * @brief Packs a message to the GUI with the adequate frame
49  * @verbatim
50  *
51  * @endverbatim
52  * @note
53  * @{
54  */
55 /**
56 * @brief Puts a byte array into a designated message queue
57 */
58 static void message_pack_block_send(uint8_t const *data, uint16_t size)
59 {
60  do
61  {
62  message_putchar(*data, 0);
63  ++ data;
64  -- size;
65  }
66  while (size); // && (USB_SENT == op_result)
67  message_putchar(0, 1);
68 }
69 /**
70 * @brief Packs collected data for the active channels into the firmware
71 */
72 extern int32_t ConfiguredSensorsSamplingDataToGUI[8];
74 {
75  uint8_t data[32] ;
76 
77  data[0] = 0xFF ; // header
78  data[1] = 0xFF ; // header
79  data[2] = 0xFF ; // header
80  data[3] = 0xFF ; // header
81  for(uint8_t i=0 ; i< 7; i++)
82  {
83  data[4 + i*3] = (uint8_t) (ConfiguredSensorsSamplingDataToGUI[i] >> 16) ; // msb
84  data[5 + i*3] = (uint8_t) (ConfiguredSensorsSamplingDataToGUI[i] >> 8) ;
85  data[6 + i*3] = (uint8_t) ConfiguredSensorsSamplingDataToGUI[i] ; // lsb
86  }
87  data[25] = (uint8_t) (ConfiguredSensorsSamplingDataToGUI[7] >> 8) ; // frame count 1
88  data[26] = (uint8_t) ConfiguredSensorsSamplingDataToGUI[7] ; // frame count 0
89  /* This code reports the current state of the emitter if any.
90  If we are using an external emitter (not controlled by our hardware) we report the state of the
91  pin which has been configured to receive an external state bit (pin 0 of port B).
92  If we are using an internal emitter we report our internal flag corresponding to whether it is
93  currently on or off.
94  If we are not using an emitter the 'emitter on' bit is set to 0 */
95 
96  switch ( EmitterStatus & 3 )
97  {
98  case 0 :
99  // no emitter in use
100  data[27] = 0 ;
101  break ;
102  case 1 :
103  // external emitter in use
104  data[27] = ( 1 == GPIO_ReadInputDataBit(GPIOB,1) ) ? 1 : 0 ;
105  break ;
106  default :
107  // internal emitter in use
108  data[27] = ( 4 == ( EmitterStatus & 4) ) ? 1 : 0 ;
109  break ;
110  }
111  data[28] = 0xFF ; // footer
112  data[29] = 0xFF ; // footer
113  data[30] = 0xFF ; // footer
114  data[31] = 0xFE ; // footer
115  static uint8_t led_ready_value = 0;
116  led_ready_value = (!led_ready_value) & 1;
117  LED_READY(led_ready_value);
118 
119  message_pack_block_send(data, 32) ; // send data
120  led_ready_value = (!led_ready_value) & 1;
121  LED_READY(led_ready_value);
122 
123 }
124 /**
125 * @brief Packs firmware status for the GUI: Streaming and power mode
126 */
128 {
129  uint8_t data[32]= {0};
130 
131  data[0] = 0xFF ; // header
132  data[1] = 0xFF ; // header
133  data[2] = 0xFF ; // header
134  data[3] = 0xFF ; // header
135 
136  data[4] = 0x01 ;
137  data[5] = isStreaming ; // streaming mode
138  if ( mode_sleeping > 0 )
139  {
140  data[6] = 0x00 ; // mode normal
141  data[7] = 0x01 ; // mode sleep
142  }
143  else
144  {
145  data[6] = 0x01 ; // mode normal
146  data[7] = 0x00 ; // mode sleep
147  }
148  data[8] = mode_lowPower ; // mode low power
149  data[28] = 0xFF ; // footer
150  data[29] = 0xFF ; // footer
151  data[30] = 0xFF ; // footer
152  data[31] = 0xFD ; // footer
153 
154  message_pack_block_send(data, 32) ; // send data
156 }
157 /**
158 * @brief selects the correct function to send data to the gui.
159 */
160 void get_bytes_to_GUI(uint8_t packet_function, uint8_t const *bytes_to_gui, uint16_t size)
161 {
162  switch (packet_function)
163  {
164  case 1:
166  break;
167  case 2:
169  break;
170  case 3:
172  break;
173  default:
174  break;
175  }
176 }
177 /** end of message_pack group
178  * @}
179  */
180 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
181 
message_pack_stream_send
void message_pack_stream_send(void)
Definition: message_pack.c:73
message_pack_status_send
void message_pack_status_send(void)
Packs firmware status for the GUI: Streaming and power mode.
Definition: message_pack.c:127
bytes_to_gui
uint8_t bytes_to_gui[BYTES_TO_GUI_SIZE]
Definition: message_generator.c:53
get_bytes_to_GUI
void get_bytes_to_GUI(uint8_t packet_function, uint8_t const *bytes_to_gui, uint16_t size)
selects the correct function to send data to the gui.
Definition: message_pack.c:160
status_need_to_send
uint8_t status_need_to_send
Definition: main.c:72
ConfiguredSensorsSamplingDataToGUI
int32_t ConfiguredSensorsSamplingDataToGUI[8]
Packs collected data for the active channels into the firmware.
Definition: message_generator.c:524
isStreaming
uint8_t isStreaming
Definition: main.c:70
mode_sleeping
uint8_t mode_sleeping
Definition: main.c:53
packet_function
uint8_t packet_function
Definition: message_generator.c:51
EmitterStatus
uint8_t EmitterStatus
Definition: main.c:65
message_putchar
void message_putchar(uint8_t c, uint8_t go_flag)
sends a character to the transmission queue and enables TX interrupt
Definition: queue_handle.c:125
message_pack_block_send
static void message_pack_block_send(uint8_t const *data, uint16_t size)
Puts a byte array into a designated message queue.
Definition: message_pack.c:58
message_pack.h
Packs a message from the sensor to the GUI into the right packet.
mode_lowPower
uint8_t mode_lowPower
Definition: main.c:54