Guest User

Untitled

a guest
Jan 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include "wiring_private.h"
  3. #include <Wire.h>
  4.  
  5. void Set_Config1 (void);
  6. void SERCOM1_Handler (void);
  7. void Serial2_String_Write (char *s);
  8. void Set_ConfigABP_C (void);
  9.  
  10. Uart Serial2(&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
  11.  
  12. void SERCOM1_Handler(void)
  13. {
  14. Serial2.IrqHandler();
  15. }
  16.  
  17. void Set_Config1(void)
  18. {
  19. String str1 = "";
  20. //*********************************************************************
  21. Serial2_String_Write("mac set_ch_freq 0 923200000");//0
  22. str1 = "";
  23. delay(100);
  24. str1 = Serial2.readString();
  25. Serial.print("set_ch_freq 0");
  26. Serial.println(str1);
  27.  
  28. //*********************************************************************
  29. Serial2_String_Write("mac set_ch_freq 1 923400000");//1
  30. str1 = "";
  31. delay(100);
  32. str1 = Serial2.readString();
  33. Serial.print("set_ch_freq 1");
  34. Serial.println(str1);
  35.  
  36. //*********************************************************************
  37. Serial2_String_Write("mac set_ch_freq 2 922000000");//2
  38. str1 = "";
  39. delay(100);
  40. str1 = Serial2.readString();
  41. Serial.print("set_ch_freq 2");
  42. Serial.println(str1);
  43.  
  44. //*********************************************************************
  45. Serial2_String_Write("mac set_ch_freq 3 922200000");//3
  46. str1 = "";
  47. delay(100);
  48. str1 = Serial2.readString();
  49. Serial.print("set_ch_freq 3");
  50. Serial.println(str1);
  51.  
  52. //*********************************************************************
  53. Serial2_String_Write("mac set_ch_freq 4 922400000");//4
  54. str1 = "";
  55. delay(100);
  56. str1 = Serial2.readString();
  57. Serial.print("set_ch_freq 4");
  58. Serial.println(str1);
  59.  
  60. //*********************************************************************
  61. Serial2_String_Write("mac set_ch_freq 5 922600000");//5
  62. str1 = "";
  63. delay(100);
  64. str1 = Serial2.readString();
  65. Serial.print("set_ch_freq 5");
  66. Serial.println(str1);
  67.  
  68. //*********************************************************************
  69. Serial2_String_Write("mac set_ch_freq 6 922800000");//6
  70. str1 = "";
  71. delay(100);
  72. str1 = Serial2.readString();
  73. Serial.print("set_ch_freq 6");
  74. Serial.println(str1);
  75.  
  76. //*********************************************************************
  77. Serial2_String_Write("mac set_ch_freq 7 923000000");//7
  78. str1 = "";
  79. delay(100);
  80. str1 = Serial2.readString();
  81. Serial.print("set_ch_freq 7");
  82. Serial.println(str1);
  83.  
  84. //*********************************************************************
  85. Serial2_String_Write("mac set_rx2 2 923200000");//8
  86. str1 = "";
  87. delay(100);
  88. str1 = Serial2.readString();
  89. Serial.print("set_rx2 2");
  90. Serial.println(str1);
  91.  
  92. //*********************************************************************
  93. Serial2_String_Write("mac save");//8
  94. str1 = "";
  95. delay(3000);
  96. str1 = Serial2.readString();
  97. Serial.print("mac save");
  98. Serial.println(str1);
  99. }
  100.  
  101. /********************************************************
  102. Function Name : Serial2_String_Write
  103. Description :
  104. Input :
  105. Return :
  106. ********************************************************/
  107. void Serial2_String_Write(char *s)
  108. {
  109. while (*s)
  110. {
  111. Serial2.write(*s++);
  112. }
  113. }
  114.  
  115. /********************************************************
  116. Function Name : Set_ConfigABP_c
  117. Description :
  118. Input :
  119. Return :
  120. ********************************************************/
  121.  
  122. void Set_ConfigABP_C(void)
  123. {
  124. String str1 = "";
  125. //*********************************************************************
  126. Serial2_String_Write("mac set_class C");
  127. str1 = "";
  128. delay(250);
  129. str1 = Serial2.readString();
  130. Serial.print("set_class C");
  131. Serial.println(str1);
  132.  
  133. //*********************************************************************
  134. Serial2_String_Write("mac set_deveui xxxxxxxxxxxxxxx");
  135. str1 = "";
  136. delay(250);
  137. str1 = Serial2.readString();
  138.  
  139. Serial.print("set_deveui");
  140. Serial.println(str1);
  141.  
  142. //*********************************************************************
  143. Serial2_String_Write("mac set_devaddr xxxxxxxxx");
  144. str1 = "";
  145. delay(250);
  146. str1 = Serial2.readString();
  147. Serial.print("set_devaddr");
  148. Serial.println(str1);
  149.  
  150. //*********************************************************************
  151. Serial2_String_Write("mac set_nwkskey 28AED22B7E1516A609CFABF715884F3C");
  152. str1 = "";
  153. delay(250);
  154. str1 = Serial2.readString();
  155. Serial.print("set_nwkskey");
  156. Serial.println(str1);
  157.  
  158. //*********************************************************************
  159. Serial2_String_Write("mac set_appskey 1628AE2B7E15D2A6ABF7CF4F3C158809");
  160. str1 = "";
  161. delay(250);
  162. str1 = Serial2.readString();
  163. Serial.print("set_appskey");
  164. Serial.println(str1);
  165.  
  166. //*********************************************************************
  167. Serial2_String_Write("mac save");
  168. str1 = "";
  169. delay(3000);
  170. str1 = Serial2.readString();
  171. Serial.print("mac save");
  172. Serial.println(str1);
  173.  
  174. //*********************************************************************
  175. Serial2_String_Write("mac join abp");
  176. str1 = "";
  177. delay(250);
  178. str1 = Serial2.readString();
  179. Serial.print("mac join abp");
  180. Serial.println(str1);
  181. }
  182.  
  183. unsigned long startMillis;
  184. unsigned long currentMillis;
  185. const unsigned long period = 10000;
  186.  
  187. /********************************************************
  188. Function Name : setup
  189. Description :
  190. Input :
  191. Return :
  192. ********************************************************/
  193. void setup()
  194. {
  195. Serial.begin(115200);
  196. Serial2.begin(115200);
  197. pinPeripheral(10, PIO_SERCOM);
  198. pinPeripheral(11, PIO_SERCOM);
  199.  
  200. Serial.println("START");
  201. delay(5000);
  202. if (Serial2.available())
  203. {
  204. Serial.print(Serial2.readString());
  205. }
  206. delay(1000);
  207. Set_Config1();
  208. Set_ConfigABP_C();
  209.  
  210. delay(250);
  211. Wire.begin();
  212.  
  213. String str1 = "";
  214. str1 = Serial2.readString();
  215. Serial.println(str1);
  216. startMillis = millis();
  217. }
  218. void loop() {
  219. //=============================================================================
  220.  
  221. String str4 = "";
  222. currentMillis = millis();
  223. // SEND INTERVAL 15 SECOND --> EDIT PARAMETER preiod TO CHANGE TIME INTERVAL LINE 259
  224. if (currentMillis - startMillis >= period)
  225. {
  226. // SEND UPLINK DATA
  227. Serial2_String_Write("mac tx ucnf 15 ABCDEF");
  228. startMillis = currentMillis;
  229. }
  230. // COUNT FOR SEND UPLINK
  231. if ((currentMillis - startMillis) / 1000 > 0)
  232. str4 = Serial2.readString();
  233. Serial.println(str4);
  234. }
Add Comment
Please, Sign In to add comment