Europalab Devices produces a LoRaWAN transmitting client node, specialised for higher research of actuator and sensor assisted IoT networks. https://dev.europalab.com/nlnet/20200000/
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

279 linhas
7.5KB

  1. /**
  2. * \file demo_output.c
  3. *
  4. * \brief Demo output Implementation.
  5. *
  6. * Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Subject to your compliance with these terms, you may use Microchip
  13. * software and any derivatives exclusively with Microchip products.
  14. * It is your responsibility to comply with third party license terms applicable
  15. * to your use of third party software (including open source software) that
  16. * may accompany Microchip software.
  17. *
  18. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  19. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  20. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  21. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  22. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  23. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  24. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  25. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  26. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  27. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  28. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  29. *
  30. * \asf_license_stop
  31. *
  32. */
  33. #include "system.h"
  34. #include "miwi_config.h"
  35. #include "miwi_config_p2p.h"
  36. #include "miwi_api.h"
  37. #include "delay.h"
  38. #include "demo_output.h"
  39. #include "sio2host.h"
  40. #include "asf.h"
  41. #define DEBOUNCE_TIME 0x00003FFF
  42. bool PUSH_BUTTON_pressed;
  43. MIWI_TICK PUSH_BUTTON_press_time;
  44. void DemoOutput_Greeting(void)
  45. {
  46. #if defined (ENABLE_LCD)
  47. #if defined(PROTOCOL_P2P)
  48. LCDDisplay((char *)"Sendcomm LoRa P2P Demo on \n SAMR34 Node ", 0, true);
  49. #endif
  50. #endif
  51. #if defined (ENABLE_CONSOLE)
  52. #if defined(PROTOCOL_P2P)
  53. printf("\r\nStarting Node 1 of Sendcomm Demo for LoRa P2P Stack ...");
  54. #endif
  55. #if defined(ENABLE_SLEEP_FEATURE)
  56. printf("\r\nReduced Function Device (RFD) operations") ;
  57. #else
  58. printf("\r\nFull Function Device (FFD) operations") ;
  59. #endif
  60. printf("\r\n RF Transceiver: SX_1276");
  61. printf("\r\n Demo Instruction:");
  62. printf("\r\n Power on the board until LED 1 lights up");
  63. printf("\r\n to indicate connecting with peer.");
  64. printf("\r\n Push Button 1 to broadcast message.");
  65. printf("\r\n LED 1 will be toggled upon receiving messages. ");
  66. printf("\r\n\r\n");
  67. #endif
  68. }
  69. void demo_output_freezer_options(void)
  70. {
  71. #if defined (ENABLE_LCD)
  72. LCDDisplay((char *)"SW: Use Nwk Freezer \nPress in 5 sec", 0, false);
  73. delay_ms(1000);
  74. #endif
  75. }
  76. void DemoOutput_Channel(uint8_t channel, uint8_t Step)
  77. {
  78. if( Step == 0 )
  79. {
  80. #if defined (ENABLE_LCD)
  81. LCDDisplay((char *)"Connecting Peer on \n Channel ", channel, true);
  82. #endif
  83. #if defined (ENABLE_CONSOLE)
  84. #if !defined(MIWIKIT)
  85. printf("\r\nConnecting Peer on Channel ");
  86. printf("%d",channel);
  87. printf("\r\n");
  88. #endif
  89. #endif
  90. }
  91. else
  92. {
  93. #if defined (ENABLE_LCD)
  94. LCDDisplay((char *)"Connected Peer on \n Channel ", channel, true);
  95. #endif
  96. #if defined (ENABLE_CONSOLE)
  97. #if !defined(MIWIKIT)
  98. printf("\r\nConnected Peer on Channel ");
  99. printf("%d",channel);
  100. printf("\r\n");
  101. #endif
  102. #endif
  103. }
  104. }
  105. void DemoOutput_Instruction(void)
  106. {
  107. #if defined (ENABLE_LCD)
  108. #if defined (EXT_BOARD_OLED1_XPLAINED_PRO)
  109. LCDDisplay((char *)"SW : Broadcast \nBUTTON1: Unicast", 0, false);
  110. #else
  111. LCDDisplay((char *)"SW: Broadcast", 0, false);
  112. #endif
  113. #endif
  114. }
  115. void DemoOutput_HandleMessage(void)
  116. {
  117. uint8_t i;
  118. if( rxMessage.flags.bits.secEn )
  119. {
  120. sio2host_tx((uint8_t *)"Secured ", sizeof("Secured "));
  121. }
  122. if( rxMessage.flags.bits.broadcast )
  123. {
  124. sio2host_tx((uint8_t *)"Broadcast Packet with RSSI ", sizeof("Broadcast Packet with RSSI "));
  125. }
  126. else
  127. {
  128. sio2host_tx((uint8_t *)"Unicast Packet with RSSI ",sizeof("Unicast Packet with RSSI "));
  129. }
  130. printf("%02x", rxMessage.PacketRSSI);
  131. if( rxMessage.flags.bits.srcPrsnt )
  132. {
  133. sio2host_tx((uint8_t *)" from ", sizeof(" from "));
  134. if( rxMessage.flags.bits.altSrcAddr )
  135. {
  136. printf( "%x", rxMessage.SourceAddress[1]);
  137. printf( "%x", rxMessage.SourceAddress[0]);
  138. }
  139. else
  140. {
  141. for(i = 0; i < MY_ADDRESS_LENGTH; i++)
  142. {
  143. printf("%x", rxMessage.SourceAddress[MY_ADDRESS_LENGTH-1-i]);
  144. }
  145. }
  146. }
  147. sio2host_tx((uint8_t *)": ",sizeof(": "));
  148. for(i = 0; i < rxMessage.PayloadSize; i++)
  149. {
  150. sio2host_putchar(rxMessage.Payload[i]);
  151. }
  152. printf("\r\n");
  153. }
  154. void DemoOutput_UpdateTxRx(uint8_t TxNum, uint8_t RxNum)
  155. {
  156. #if defined (ENABLE_LCD)
  157. LCDTRXCount(TxNum, RxNum);
  158. #endif
  159. }
  160. void DemoOutput_ChannelError(uint8_t channel)
  161. {
  162. #if defined (ENABLE_CONSOLE)
  163. printf("\r\nSelection of channel ");
  164. printf("%d", channel);
  165. printf(" is not supported in current configuration.\r\n");
  166. #endif
  167. }
  168. void DemoOutput_UnicastFail(void)
  169. {
  170. #if defined (ENABLE_CONSOLE)
  171. printf("\r\nUnicast Failed\r\n");
  172. #endif
  173. #if defined (ENABLE_LCD)
  174. LCDDisplay((char *)" Unicast Failed", 0, true);
  175. #endif
  176. }
  177. void DemoOutput_BroadcastFail(void)
  178. {
  179. #if defined (ENABLE_CONSOLE)
  180. printf("\r\nBroadcast Failed\r\n");
  181. #endif
  182. #if defined (ENABLE_LCD)
  183. LCDDisplay((char *)" Broadcast Failed", 0, true);
  184. #endif
  185. }
  186. /*********************************************************************
  187. * Function: uint8_t ButtonPressed(void)
  188. *
  189. * PreCondition: None
  190. *
  191. * Input: None
  192. *
  193. * Output: Return value to indicate which button has been pressed.
  194. * Return 0 if no button pressed.
  195. *
  196. * Side Effects:
  197. *
  198. * Overview: This function check if any button has been pressed
  199. *
  200. * Note:
  201. ********************************************************************/
  202. uint8_t ButtonPressed(void)
  203. {
  204. MIWI_TICK tickDifference;
  205. if(!port_pin_get_input_level(BUTTON_0_PIN))
  206. {
  207. //if the button was previously not pressed
  208. if(PUSH_BUTTON_pressed == false)
  209. {
  210. PUSH_BUTTON_pressed = true;
  211. PUSH_BUTTON_press_time.Val = MiWi_TickGet();
  212. return 1;
  213. }
  214. }
  215. #if defined (EXT_BOARD_OLED1_XPLAINED_PRO)
  216. else if(!port_pin_get_input_level(WING_BUTTON_1))
  217. {
  218. //if the button was previously not pressed
  219. if(PUSH_BUTTON_pressed == false)
  220. {
  221. PUSH_BUTTON_pressed = true;
  222. PUSH_BUTTON_press_time.Val = MiWi_TickGet();
  223. return 2;
  224. }
  225. }
  226. #endif
  227. else
  228. {
  229. //get the current time
  230. MIWI_TICK t;
  231. t.Val = MiWi_TickGet();
  232. //if the button has been released long enough
  233. tickDifference.Val = MiWi_TickGetDiff(t,PUSH_BUTTON_press_time);
  234. //then we can mark it as not pressed
  235. if(tickDifference.Val > DEBOUNCE_TIME)
  236. {
  237. PUSH_BUTTON_pressed = false;
  238. }
  239. }
  240. return 0;
  241. }
  242. #if (defined EXT_BOARD_OLED1_XPLAINED_PRO)
  243. /**
  244. * \brief Configures buttons
  245. */
  246. void Buttons_init(void)
  247. {
  248. struct port_config conf;
  249. port_get_config_defaults(&conf);
  250. conf.direction = PORT_PIN_DIR_INPUT;
  251. conf.input_pull = PORT_PIN_PULL_UP;
  252. /* Configure all three buttons as inputs */
  253. port_pin_set_config(WING_BUTTON_1, &conf);
  254. port_pin_set_config(WING_BUTTON_2, &conf);
  255. port_pin_set_config(WING_BUTTON_3, &conf);
  256. }
  257. #endif