Country_Code.c
12.5 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// /**
// 方案一:调用该文件中的对外函数输入参数国家码,可能需要更改获取序列号中地区码的部分代码,等待返回值即可,返回值:0 表明国家码与地区码一致。
// 方案二:调用该文件中的对外函数输入参数国家码、序列号中的地区码,等待返回值即可。
// */
// #include "FreeRTOS.h"
// #include "task.h"
// #include "Country_Code.h"
// #include "myflash.h"
// #include "dji_logger.h"
// /*____________________________________________________ Country code array module ____________________________________________________*/
// #if 1 //国家码
// //4个有效数据
// uint16_t CN[] = { //中国
// 156, //中国大陆
// 344, //香港
// 446, //澳门
// 158, //台湾
// };
// //37个有效数据(国家码)
// uint16_t NA[] = { //美洲
// 3, //0; 国家码的百位为0~2的数据的位置<_*_*_>
// 17, //1; 国家码的百位为3~5的数据的位置<_*_*_>
// 32, //2; 国家码的百位为6~8的数据的位置<_*_*_>
// 13, //3; 国家码的百位为0~2的数据的数量<_*_*_>
// 28, //4; 安提瓜和巴布达
// 44, //5; 巴哈马
// 52, //6; 巴巴多斯
// 60, //7; 百慕大(英国)
// 84, //8; 伯利兹
// 92, //9; 英属维尔京群岛
// 124, //10; 加拿大
// 136, //11; 开曼群岛(英国)
// 188, //12; 哥斯达黎加
// 192, //13; 古巴
// 212, //14; 多米尼克
// 214, //15; 多米尼加
// 222, //16; 萨尔瓦多
// 14, //17; 国家码的百位为3~4的数据的数量<_*_*_>
// 304, //18; 格陵兰(丹麦)
// 308, //19; 格林纳达
// 312, //20; 瓜德罗普(法国)
// 320, //21; 危地马拉
// 332, //22; 海地
// 340, //23; 洪都拉斯
// 388, //24; 牙买加
// 474, //25; 马提尼克(法国)
// 484, //26; 墨西哥
// 500, //27; 蒙特塞拉特(英国)
// 530, //28; 荷属安的列斯
// 533, //29; 阿鲁巴(荷兰)
// 558, //30; 尼加拉瓜
// 591, //31; 巴拿马
// 10, //32; 国家码的百位为6~8的数据的数量<_*_*_>
// 630, //33; 波多黎各(美国)
// 659, //34; 圣基茨和尼维斯
// 660, //35; 安圭拉(英国)
// 662, //36; 圣卢西亚
// 666, //37; 圣皮埃尔和密克隆(法国)
// 670, //38; 圣文森特和格林纳丁斯
// 780, //39; 特立尼达和多巴哥
// 796, //40; 特克斯和凯科斯群岛(英国)
// 840, //41; 美国
// 850, //42; 美属维尔京群岛
// };
// //45个数据
// uint16_t EU[] = { //欧洲
// 3, //0; 国家码的百位为0~2的数据的位置<_*_*_>
// 19, //1; 国家码的百位为3~5的数据的位置<_*_*_>
// 36, //2; 国家码的百位为6~8的数据的位置<_*_*_>
// 15, //3; 国家码的百位为0~2的数据的数量<_*_*_>
// 8, //4; 阿尔巴尼亚
// 20, //5; 安道尔
// 40, //6; 奥地利
// 56, //7; 比利时
// 100, //8; 保加利亚
// 112, //9; 白俄罗斯
// 191, //10; 克罗地亚
// 203, //11; 捷克
// 208, //12; 丹麦
// 233, //13; 爱沙尼亚
// 234, //14; 法罗群岛(丹麦)
// 246, //15; 芬兰
// 250, //16; 法国
// 276, //17; 德国
// 292, //18; 直布罗陀
// 16, //19; 国家码的百位为3~5的数据的数量<_*_*_>
// 300, //20; 希腊
// 336, //21; 梵蒂冈
// 348, //22; 匈牙利
// 352, //23; 冰岛
// 372, //24; 爱尔兰
// 380, //25; 意大利
// 428, //26; 拉脱维亚
// 438, //27; 列支敦士登
// 440, //28; 立陶宛
// 442, //29; 卢森堡
// 470, //30; 马耳他
// 492, //31; 摩纳哥
// 498, //32; 摩尔多瓦
// 499, //33; 黑山
// 528, //34; 荷兰
// 578, //35; 挪威
// 14, //36; 国家码的百位为6~8的数据的数量<_*_*_>
// 616, //37; 波兰
// 620, //38; 葡萄牙
// 642, //39; 罗马尼亚
// 643, //40; 俄罗斯联邦
// 674, //41; 圣马力诺
// 688, //42; 塞尔维亚
// 703, //43; 斯洛伐克
// 705, //44; 斯洛文尼亚
// 724, //45; 西班牙
// 752, //46; 瑞典
// 756, //47; 瑞士
// 792, //48; 土耳其欧洲部分
// 804, //49; 乌克兰
// 826, //50; 英国
// };
// /*
// uint16_t AF[] = { //非洲
// };
// uint16_t OC[] = { //大洋洲
// };
// */
// #endif
// /*____________________________________________________ Country code array module ____________________________________________________*/
// //变量定义
// T_country_code_param country_code_Param[] = {
// {.name = "CN", .name_address = CN,},
// {.name = "NA", .name_address = NA,},
// {.name = "EU", .name_address = EU,},//新增区域时,在此处新增对应的区域名字符串,以及对应的国家码数组
// };
// /*____________________________________________________ Country Code func module ____________________________________________________*/
// #if 1 //国家码比对函数模块
// /**
// @brief: 传入国家码结构体,判断是否与传入的国家码一致(返回0),不一致返回1
// @Param: code 国家码参数结构体
// @Param: CountryCode 国家码
// @return:no
// */
// static uint8_t IF_Country_Code(T_country_code_param * code , uint16_t CountryCode)
// {
// uint8_t i = 0;
// uint8_t hundred = 0;//存储传进参数的百位的值
// uint8_t hundred_address = 0;//存储传进参数的百位处在第X个元素的位置
// uint8_t number = 0;
// hundred = CountryCode / 100;//取传进参数的百位在数组中的位置
// if(hundred <= 2)
// {
// hundred = 0;//存放国家码百位为0~2的数据所在位置的数组的第X个元素
// }else if(hundred >=3 && hundred <= 5)
// {
// hundred = 1;
// }else if(hundred >=6 && hundred <= 8)
// {
// hundred = 2;
// }
// hundred_address = code->name_address[hundred];//取国家码百位在X~X+2的数据的位置
// number = code->name_address[hundred_address];//取国家码百位在X~X+2的数据的数量
// for(i = 0;i<number;i++)
// {
// if(CountryCode == code->name_address[hundred_address+(1+i)])//判断这些数据是否与传进参数一致
// {
// return 0;//对比成功,数组中存在该元素
// }else
// {
// }
// }
// return 1;//对比失败,数组中未存在该元素
// }
// /**
// @brief: 输入的国家码与序列号中的地区码相同即返回0;否返回1
// @Param: CountryCode 国家码
// @Param: xarea 序列号中的国家码(地区位)
// @return:0/1 成功/失败
// */
// #if 1 //方案二
// uint8_t Country_Code_handle(uint16_t CountryCode , char * xarea)
// {
// if(strcmp(xarea,country_code_Param[0].name) == 0)//中国地区
// {
// if(CountryCode == country_code_Param[0].name_address[0]
// || CountryCode == country_code_Param[0].name_address[1]
// || CountryCode == country_code_Param[0].name_address[2]
// || CountryCode == country_code_Param[0].name_address[3])//if(CountryCode == 156 || CountryCode == 344 || CountryCode == 446 || CountryCode == 158)
// {
// return 0;//返回成功
// }else
// {
// return 1;//返回不成功
// }
// }
// else if(strcmp(xarea,country_code_Param[1].name) == 0)//美洲地区
// {
// return IF_Country_Code(&country_code_Param[1],CountryCode);
// }
// else if(strcmp(xarea,country_code_Param[2].name) == 0)//欧洲地区
// {
// return IF_Country_Code(&country_code_Param[2],CountryCode);
// }
// else
// {
// }
// return 1;//返回不成功
// }
// #else //方案一
// uint8_t Country_Code_handle(uint16_t CountryCode)
// {
// uint8_t SN_Code[SN_LEN+2] = {0}; //暂时存储序列号
// char area[3] = {0};//保存序列号中的地区码
// Read_SN_FromFlash(SN_Code,SN_LEN); //获取序列号
// SN_Code[16] = '\0';
// area[0] = SN_Code[4];
// area[1] = SN_Code[5];
// area[2] = '\0';
// if(strcmp(area,country_code_Param[0].name) == 0)//
// {
// if(CountryCode == country_code_Param[0].name_address[0]
// || CountryCode == country_code_Param[0].name_address[0]
// || CountryCode == country_code_Param[0].name_address[0]
// || CountryCode == country_code_Param[0].name_address[0])//if(CountryCode == 156 || CountryCode == 344 || CountryCode == 446 || CountryCode == 158)
// {
// return 0;//返回成功
// }else
// {
// return 1;//返回不成功
// }
// }
// else if(strcmp(area,country_code_Param[1].name) == 0)
// {
// return IF_Country_Code(&country_code_Param[1],CountryCode);
// }
// else if(strcmp(area,country_code_Param[2].name) == 0)
// {
// return IF_Country_Code(&country_code_Param[2],CountryCode);
// }
// else
// {
// }
// return 1;//返回不成功
// }
// #endif
// #endif
// /*____________________________________________________ Country Code func module ____________________________________________________*/
// /*____________________________________________________ "Country_Code_handle()" External call module ____________________________________________________*/
// #if 0 //国家码函数调用例子
// static void Country_Code_init(void)//方案二
// {
// uint8_t SN_Code[SN_LEN+2] = {0}; //暂时存储序列号
// char area[3] = {0};//保存序列号中的地区码
// uint8_t activate_flag = 0;//激活标志位,该处位局部变量真正工程中需变为全局变量或其它操作
// uint8_t Country_Code = 156;//假如从飞机获取的国家码是156,真正工程中需变为全局变量或其它操作
// Read_SN_FromFlash(SN_Code,SN_LEN); //获取序列号,需更改为工程的对应的获取序列号的函数
// SN_Code[16] = '\0';
// area[0] = SN_Code[4];
// area[1] = SN_Code[5];
// area[2] = '\0';
// activate_flag = Get_Active_State(); //获取激活状态,需更改为工程的对应的获取激活状态的函数
// if(activate_flag == 0x01)//激活后才需要判断国家码与序列号的码是否一致,app_activate_flag == 0x01
// {
// USER_LOG_INFO("SN = %s,activate = %x,CountryCode = %d,area = %s\r\n",SN_Code,activate_flag,Country_Code,area);//输出序列号,国家码,
// activate_flag = Country_Code_handle(Country_Code,area);//获取国家码比对结果。
// USER_LOG_INFO("app_country_flag = %d\r\n",activate_flag);
// if(activate_flag == 0)//国家码与序列号地区码比对一致
// {
// }else
// {
// activate_flag = 0;//非法地区,禁止使用
// }
// }
// }
// #endif
// /*____________________________________________________ "Country_Code_handle()" External call module ____________________________________________________*/
// /*____________________________________________________ Country code test module ____________________________________________________*/
// #if COUNTRY_CODE_TEST //测试国家码是否能对应查找以及对比成功
// /**
// @brief: 传入国家码结构体,判断是否与传入的国家码一致(返回0),不一致返回1
// @Param: code 国家码参数结构体
// @Param: CountryCode 国家码
// @return:no
// */
// uint8_t TEST_IF_Country_Code(T_country_code_param * code , uint16_t CountryCode)
// {
// uint8_t i = 0;
// uint8_t hundred = 0;//存储传进参数的百位的值
// uint8_t hundred_address = 0;//存储传进参数的百位处在第X个元素的位置
// uint8_t number = 0;
// uint8_t state = 1;//返回检查状态
// hundred = CountryCode / 100;//取传进参数的百位在数组中的位置
// if(hundred <= 2)
// {
// hundred = 0;//存放国家码百位为0~2的数据所在位置的数组的第X个元素
// }else if(hundred >=3 && hundred <= 5)
// {
// hundred = 1;
// }else if(hundred >=6 && hundred <= 8)
// {
// hundred = 2;
// }
// hundred_address = code->name_address[hundred];//取国家码百位在X~X+2的数据的位置
// number = code->name_address[hundred_address];//取国家码百位在X~X+2的数据的数量
// for(i = 0;i<number;i++)
// {
// if(CountryCode == code->name_address[hundred_address+(1+i)])//判断这些数据是否与传进参数一致
// {
// state = 0;
// }else
// {
// USER_LOG_INFO("CountryCode = %d\n",code->name_address[hundred_address+(1+i)]); //输出
// vTaskDelay(pdMS_TO_TICKS(2));
// }
// }
// return state;//对比成功,数组中存在该元素
// }
// /**
// @brief: 输入的国家码与序列号中的地区码相同即返回0;否返回1
// @Param: CountryCode 国家码
// @Param: xarea 序列号中的国家码(地区位)
// @return:0/1 成功/失败
// */
// uint8_t TEST_Country_Code_handle(uint16_t CountryCode , char * xarea)
// {
// USER_LOG_INFO("CountryCode = %d,%s\n",CountryCode,xarea); //输出
// if(strcmp(xarea,country_code_Param[0].name) == 0)//
// {
// if(CountryCode == 156 || CountryCode == 344 || CountryCode == 446 || CountryCode == 158)
// {
// return 0;//返回成功
// }else
// {
// return 1;//返回不成功
// }
// }
// else if(strcmp(xarea,country_code_Param[1].name) == 0)
// {
// return TEST_IF_Country_Code(&country_code_Param[1],CountryCode);
// }
// else if(strcmp(xarea,country_code_Param[2].name) == 0)
// {
// return TEST_IF_Country_Code(&country_code_Param[2],CountryCode);
// }
// else
// {
// }
// return 1;//返回不成功
// }
// /**
// @brief: 测试国家码
// @Param: no
// @return:no
// */
// void TEST_guojiama(void)
// {
// char area[5] = {0};//保存序列号中的地区码
// uint8_t state = 2;
// area[0] = 'C';
// area[1] = 'N';
// area[2] = '\0';
// state = TEST_Country_Code_handle(156,area);
// USER_LOG_INFO("%d\r\n",state);//国家码比对结果返回
// vTaskDelay(pdMS_TO_TICKS(500));
// area[0] = 'N';
// area[1] = 'A';
// area[2] = '\0';
// state = TEST_Country_Code_handle(8,area);
// USER_LOG_INFO("%d\r\n",state);
// vTaskDelay(pdMS_TO_TICKS(500));
// area[0] = 'E';
// area[1] = 'U';
// area[2] = '\0';
// state = TEST_Country_Code_handle(800,area);
// USER_LOG_INFO("%d\r\n",state);
// vTaskDelay(pdMS_TO_TICKS(500));
// }
// #endif
// /*____________________________________________________ Country code test module ____________________________________________________*/