-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathlora_info.c
212 lines (168 loc) · 5.68 KB
/
lora_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
******************************************************************************
* @file lora_info.c
* @author MCD Application Team
* @brief To give info to the application about LoRaWAN configuration
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "LoRaMac.h"
#include "lora_info.h"
#include "app.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
static LoraInfo_t loraInfo = {0, 0};
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Exported variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported functions --------------------------------------------------------*/
void LoraInfo_Init(void)
{
loraInfo.ActivationMode = 0;
loraInfo.Region = 0;
loraInfo.ClassB = 0;
loraInfo.Kms = 0;
/* USER CODE BEGIN LoraInfo_Init_1 */
/* USER CODE END LoraInfo_Init_1 */
#ifdef REGION_AS923
loraInfo.Region |= (1 << LORAMAC_REGION_AS923) ;
#endif /* REGION_AS923 */
#ifdef REGION_AU915
loraInfo.Region |= (1 << LORAMAC_REGION_AU915) ;
#endif /* REGION_AU915 */
#ifdef REGION_CN470
loraInfo.Region |= (1 << LORAMAC_REGION_CN470) ;
#endif /* REGION_CN470 */
#ifdef REGION_CN779
loraInfo.Region |= (1 << LORAMAC_REGION_CN779) ;
#endif /* REGION_CN779 */
#ifdef REGION_EU433
loraInfo.Region |= (1 << LORAMAC_REGION_EU433) ;
#endif /* REGION_EU433 */
#ifdef REGION_EU868
loraInfo.Region |= (1 << LORAMAC_REGION_EU868) ;
#endif /* REGION_EU868 */
#ifdef REGION_KR920
loraInfo.Region |= (1 << LORAMAC_REGION_KR920) ;
#endif /* REGION_KR920 */
#ifdef REGION_IN865
loraInfo.Region |= (1 << LORAMAC_REGION_IN865) ;
#endif /* REGION_IN865 */
#ifdef REGION_US915
loraInfo.Region |= (1 << LORAMAC_REGION_US915) ;
#endif /* REGION_US915 */
#ifdef REGION_RU864
loraInfo.Region |= (1 << LORAMAC_REGION_RU864) ;
#endif /* REGION_RU864 */
if (loraInfo.Region == 0)
{
APP_PRINTF("error: At least one region shall be defined in the MW: check lorawan_conf.h \r\n");
while (1) {} /* At least one region shall be defined */
}
#if ( LORAMAC_CLASSB_ENABLED == 1 )
loraInfo.ClassB = 1;
#elif !defined (LORAMAC_CLASSB_ENABLED)
#error LORAMAC_CLASSB_ENABLED not defined ( shall be <0 or 1> )
#endif /* LORAMAC_CLASSB_ENABLED */
#if (!defined (LORAWAN_KMS) || (LORAWAN_KMS == 0))
loraInfo.Kms = 0;
loraInfo.ActivationMode = 3;
#else /* LORAWAN_KMS == 1 */
loraInfo.Kms = 1;
loraInfo.ActivationMode = ACTIVATION_BY_PERSONALISATION + (OVER_THE_AIR_ACTIVATION << 1);
#endif /* LORAWAN_KMS */
/* USER CODE BEGIN LoraInfo_Init_2 */
/* USER CODE END LoraInfo_Init_2 */
}
LoraInfo_t *LoraInfo_GetPtr(void)
{
/* USER CODE BEGIN LoraInfo_GetPtr */
/* USER CODE END LoraInfo_GetPtr */
return &loraInfo;
}
uint8_t GetBatteryLevel(void)
{
uint8_t batteryLevel = 3; // Dummy value to use in the basic app, user can add desired implementation depending on the board.
APP_LOG(ADV_TRACER_TS_ON, ADV_TRACER_VLEVEL_M, "VDDA= %d (Dummy value)\n\r", batteryLevel);
return batteryLevel;
}
uint16_t GetTemperatureLevel(void)
{
return 20; // Dummy value to use in the basic app, user can add desired implementation depending on the board.
}
void GetUniqueId(uint8_t *id)
{
uint32_t val = 0;
val = LL_FLASH_GetUDN();
if (val == 0xFFFFFFFF) /* Normally this should not happen */
{
uint32_t ID_1_3_val = HAL_GetUIDw0() + HAL_GetUIDw2();
uint32_t ID_2_val = HAL_GetUIDw1();
id[7] = (ID_1_3_val) >> 24;
id[6] = (ID_1_3_val) >> 16;
id[5] = (ID_1_3_val) >> 8;
id[4] = (ID_1_3_val);
id[3] = (ID_2_val) >> 24;
id[2] = (ID_2_val) >> 16;
id[1] = (ID_2_val) >> 8;
id[0] = (ID_2_val);
}
else /* Typical use case */
{
id[7] = val & 0xFF;
id[6] = (val >> 8) & 0xFF;
id[5] = (val >> 16) & 0xFF;
id[4] = (val >> 24) & 0xFF;
val = LL_FLASH_GetDeviceID();
id[3] = val & 0xFF;
val = LL_FLASH_GetSTCompanyID();
id[2] = val & 0xFF;
id[1] = (val >> 8) & 0xFF;
id[0] = (val >> 16) & 0xFF;
}
}
uint32_t GetDevAddr(void)
{
uint32_t val = 0;
val = LL_FLASH_GetUDN();
if (val == 0xFFFFFFFF)
{
val = ((HAL_GetUIDw0()) ^ (HAL_GetUIDw1()) ^ (HAL_GetUIDw2()));
}
return val;
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private functions --------------------------------------------------------*/
/* USER CODE BEGIN PF */
/* USER CODE END PF */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/