LoRa 디바이스 개발하기(KEIL_MDK)
Parameter Setting
Set_class type
Set_class 함수에서는 get을 우선적으로 진행 후 set을 진행합니다. Get_cls를 통해 class를 get하고 현재 setting 되어있는 class 값과 비교 후 적용(Set)합니다. 이후 Join하는 단계로 설계되어 있습니다
개발가이드 설명
Function |
set_class(unit8_t cls); |
Param |
0: Class A 2: Class C |
Returns |
get_cls |
Description |
- Configuration LoRaWAN Class set_class(0); set_class(2); |
Default |
Class A |
|
state_ret_t set_class(uint8_t cls)
{
state_ret_t ret;
char get_cls, buf[30];
ret = send_and_check_command(LORA_GET_CLASS, LORA_GET_CLASS_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
get_cls = lora_cmd.lora_rsp_buffer[sizeof(LORA_GET_CLASS_RSP)-1];
if ((cls == 0 && get_cls == 'A') || (cls == 2 && get_cls == 'C'))
{
PRINTF("[DEBUG]Same_class %c\r\n", get_cls);
ret = send_and_check_command(NULL, LORA_JOINED , NULL, 0);
while(!(lora_cli_loop() == RET_OK));
}
else
{
sprintf(buf, LORA_SET_CLASS, cls);
ret = send_and_check_command(buf, LORA_JOINED , NULL, 0);
while(!(lora_cli_loop() == RET_OK));
}
PRINTF("[DEBUG]JOIN Completed\r\n");
HAL_Delay(1000);
lora_cmd.proceeding_flag = 0;
return ret;
}
|
Set ADR status
해당 함수를 통해 ADR을 설정해줍니다. Get_adr에 현재 설정되어 있는 ADR값을 가져옵니다. 그 다음 비교구문을 이용하여 같은 값이면 모니터링만을, 다른 값이면 parameter에 설정한 값과 같은 값을 Setting해줍니다.
개발가이드 설명
Function |
set_adr(unit8_t adr); |
Param |
0: Off (Non-activate) 1: On (Activate) |
Returns |
get_adr |
Description |
- Set Adaptive data rate 기능 set_adr(0); set_adr(1); |
Default |
ON(0) |
|
state_ret_t set_adr(uint8_t adr)
{
state_ret_t ret;
char get_adr[6], buf[30];
ret = send_and_check_command(LORA_GET_ADR, LORA_GET_ADR_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
strcpy(get_adr, &lora_cmd.lora_rsp_buffer[sizeof(LORA_GET_ADR_RSP)-1]);
PRINTF("[DEBUG]%s\r\n", get_adr);
if ((adr ==1 && !(strcmp(get_adr, "ON"))) || (adr ==0 && !(strcmp(get_adr, "OFF"))))
{
PRINTF("[DEBUG]Same_ADR %s\r\n", get_adr);
}
else
{
if (adr == 1)
{
sprintf(buf, LORA_SET_ADR, "on");
}
else
{
sprintf(buf, LORA_SET_ADR, "off");
}
ret = send_and_check_command(buf, LORA_CMD_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
}
PRINTF("[DEBUG]SET ADR Completed\r\n");
lora_cmd.proceeding_flag = 0;
return ret;
}
|
Set Data Rate
Data rate를 설정해줍니다. Get_dr에 현재 datarate의 값을 넣어주고, 비교구문을 이용하여 Parameter에 입력한 값과 비교합니다. 이후 같으면 모니터링 후 종료, 다른 값이면 Parameter에 설정한 값과 동일하게 변경 후 종료합니다.
- LoRa 네트워크를 이용하기 위해서 DR0로 설정 해줘야 합니다.
개발가이드 설명
Function |
set_dr(unit8_t dr); |
Param |
0: Spread factor 12
1: Spread factor 11
2: Spread factor 10
3: Spread factor 9
4: Spread factor 8
5: Spread factor 7
|
Returns |
get_dr |
Description |
- Configuration Date rate
set_dr(0);
set_dr(1);
set_dr(2);
set_dr(3);
set_dr(4);
set_dr(5);
|
Default |
0 : SF12/125KHz |
|
state_ret_t set_dr(uint8_t dr)
{
state_ret_t ret;
char get_dr, buf[30];
ret = send_and_check_command(LORA_GET_DR, LORA_GET_DR_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
get_dr = lora_cmd.lora_rsp_buffer[sizeof(LORA_GET_DR_RSP)-1];
get_dr -= 0x30;
PRINTF("[DEBUG]DR %d\r\n", get_dr);
if (dr == get_dr)
{
PRINTF("[DEBUG]Same_DR %d\r\n", get_dr);
}
else
{
sprintf(buf, LORA_SET_DR, dr);
ret = send_and_check_command(buf, LORA_CMD_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
}
PRINTF("[DEBUG]SET DR Completed\r\n");
lora_cmd.proceeding_flag = 0;
return ret;
}
|
Set Retransmission
현재 모듈에 설정되어있는 Retransmission 값을 가져옵니다. 이후 비교구문을 이용하여 기존 Setting 값과 Parameter에 적은 값에 대한 비교를 진행, 동일하면 모니터링 후 종료, 값이 다르다면 Parameter 값으로 setting 한 후에 종료합니다.
개발가이드 설명
Function |
set_con_retrans(unit8_t retrans); |
Param |
1~8 |
Returns |
get_retrans |
Description |
Configuration Re-transmission number |
Default |
8 |
|
state_ret_t set_con_retrans (uint8_t retrans)
{
state_ret_t ret;
char get_retrans, buf[30];
ret = send_and_check_command(LORA_GET_CON_RETRANS, LORA_GET_CON_RETRANS_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
get_retrans = lora_cmd.lora_rsp_buffer[sizeof(LORA_GET_CON_RETRANS_RSP)-1];
get_retrans -= 0x30;
PRINTF("[DEBUG]Con_retrans %d\r\n", get_retrans);
if (retrans == get_retrans)
{
PRINTF("[DEBUG]Same_Con_Retrans %d\r\n", get_retrans);
}
else
{
sprintf(buf, LORA_SET_CON_RETRANS, retrans);
ret = send_and_check_command(buf, LORA_CMD_RSP , LORA_CMD_BUSY_RSP, 0);
while(!(lora_cli_loop() == RET_OK));
}
PRINTF("[DEBUG]SET Con_Retrans Completed\r\n");
lora_cmd.proceeding_flag = 0;
return ret;
}
|