fix all board compile for v3.0

fix all board compile for v3.0
This commit is contained in:
supowang
2021-08-11 16:30:15 +08:00
parent 1f694e2156
commit 8253a953bd
615 changed files with 96466 additions and 80894 deletions

36
devices/l610/Makefile Normal file
View File

@@ -0,0 +1,36 @@
###################################################################
#automatic detection QTOP and LOCALDIR
CUR_DIR := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
TRYQTOP := $(shell if [ -n "$$QTOP" ] ; then\
echo $$QTOP;\
else\
cd $(CUR_DIR); while /usr/bin/test ! -d qmk ; do \
dir=`cd ../;pwd`; \
if [ "$$dir" = "/" ] ; then \
echo Cannot find QTOP in $(firstword $(MAKEFILE_LIST)) 1>&2; \
exit 1; \
fi ; \
cd $$dir; \
done ; \
pwd; \
fi)
QTOP ?= $(realpath ${TRYQTOP})
ifeq ($(QTOP),)
$(error Please run this in a tree)
endif
LOCALDIR = $(patsubst %/,%,$(subst $(realpath $(QTOP))/,,$(CUR_DIR)))
####################################################################
TREE_LIB_ENABLE=0
lib=
subdirs=
CFGFLAGS += -I$(QTOP)/net/at/include
CFGFLAGS += -I$(QTOP)/net/sal_module_wrapper
include ${QTOP}/qmk/generic/Make.tpl

645
devices/l610/l610.c Normal file
View File

@@ -0,0 +1,645 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "l610.h"
#include "tos_at.h"
#include "tos_hal.h"
#include "sal_module_wrapper.h"
#include <stdio.h>
static int l610_check_ready(void)
{
at_echo_t echo;
int try = 0;
while (++try) {
tos_sleep_ms(2000);
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT\r\n");
if (echo.status == AT_ECHO_STATUS_OK) {
return 0;
}
}
return -1;
}
static int l610_echo_close(void)
{
at_echo_t echo;
int try = 0;
tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
if (echo.status == AT_ECHO_STATUS_OK) {
return 0;
}
tos_sleep_ms(1000);
}
return -1;
}
static int l610_sim_card_check(void)
{
at_echo_t echo;
int try = 0;
char echo_buffer[32];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
if (strstr(echo_buffer, "READY")) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int l610_signal_quality_check(void)
{
int rssi, ber;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CSQ:");
if (!str) {
return -1;
}
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int l610_gsm_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CREG:");
if (!str) {
return -1;
}
sscanf(str, "+CREG:%d,%d", &n, &stat);
if (stat == 1) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int l610_gprs_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CGREG:");
if (!str) {
return -1;
}
sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int l610_set_data_format(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+GTSET=\"IPRFMT\",0\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
return 0;
}
static int l610_check_apn(void)
{
at_echo_t echo;
char buffer[64];
char *str = NULL;
int apn_state;
tos_at_echo_create(&echo, buffer, 64, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(buffer, "+MIPCALL:");
if (str == NULL) {
return -1;
}
sscanf(str+strlen("+MIPCALL: "), "%d", &apn_state);
if (apn_state == 0) {
return 0;
} else if (apn_state == 1) {
return 1;
} else {
return -1;
}
}
static int l610_check_close_apn(void)
{
at_echo_t echo;
char buffer[64];
char *str = NULL;
int apn_state;
apn_state = l610_check_apn();
if (apn_state == -1) {
return -1;
} else if (apn_state == 0) {
return 0;
}
tos_at_echo_create(&echo, buffer, 64, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL=0\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(buffer, "+MIPCALL:");
if (str == NULL) {
return -1;
}
sscanf(str+strlen("+MIPCALL: "), "%d", &apn_state);
if (apn_state == 0) {
return 0;
}
return -1;
}
static int l610_set_apn(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+MIPCALL");
tos_at_cmd_exec_until(&echo, 10000, "AT+MIPCALL=1,\"CMNET\"\r\n");
if (echo.status != AT_ECHO_STATUS_EXPECT) {
return -1;
}
if (l610_check_apn() == 1) {
return 0;
} else {
return -1;
}
}
static int l610_init(void)
{
printf("Init l610 ...\n" );
if (l610_check_ready() != 0) {
printf("wait module ready timeout, please check your module\n");
return -1;
}
if (l610_echo_close() != 0) {
printf("echo close failed,please check your module\n");
return -1;
}
if (l610_sim_card_check() != 0) {
printf("sim card check failed,please insert your card\n");
return -1;
}
if (l610_signal_quality_check() != 0) {
printf("signal quality check status failed\n");
return -1;
}
if (l610_gsm_network_check() != 0) {
printf("GSM network register status check fail\n");
return -1;
}
if (l610_gprs_network_check() != 0) {
printf("GPRS network register status check fail\n");
return -1;
}
if (l610_set_data_format() != 0) {
printf("set data format fail\n");
return -1;
}
if (l610_check_close_apn() != 0) {
printf("close apn failed\n");
return -1;
}
if (l610_set_apn() != 0) {
printf("apn set FAILED\n");
return -1;
}
printf("Init l610 ok\n" );
return 0;
}
static int l610_connect(const char *ip, const char *port, sal_proto_t proto)
{
int id;
at_echo_t echo;
id = tos_at_channel_alloc(ip, port);
if (id == -1) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "+MIPOPEN");
tos_at_cmd_exec_until(&echo, 4000, "AT+MIPOPEN=%d,,\"%s\",%d,%d\r\n",
id + 1, ip, atoi(port), proto == TOS_SAL_PROTO_UDP ? 1 : 0);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_channel_free(id);
return -1;
}
return id;
}
static int l610_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
static int l610_recv(int id, void *buf, size_t len)
{
return l610_recv_timeout(id, buf, len, (uint32_t)4000);
}
int l610_send(int id, const void *buf, size_t len)
{
at_echo_t echo;
if (!tos_at_channel_is_working(id)) {
return -1;
}
if (tos_at_global_lock_pend() != 0) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec_until(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "+MIPSEND");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
int l610_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
int l610_recvfrom(int id, void *buf, size_t len)
{
return l610_recvfrom_timeout(id, buf, len, (uint32_t)4000);
}
int l610_sendto(int id, char *ip, char *port, const void *buf, size_t len)
{
at_echo_t echo;
if (!tos_at_channel_is_working(id)) {
return -1;
}
if (tos_at_global_lock_pend() != 0) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec_until(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "+MIPSEND");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
static void l610_transparent_mode_exit(void)
{
tos_at_cmd_exec(NULL, 500, "+++");
}
static int l610_close(int id)
{
at_echo_t echo;
l610_transparent_mode_exit();
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(NULL, 1000, "AT+MIPCLOSE=%d\r\n", id+1);
tos_at_channel_free(id);
return 0;
}
static int l610_parse_domain(const char *host_name, char *host_ip, size_t host_ip_len)
{
at_echo_t echo;
char echo_buffer[128];
char *str = NULL;
int seg1, seg2, seg3, seg4;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+MIPDNS=\"%s\"\r\n", host_name);
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo_buffer, "+MIPDNS:");
if (str == NULL) {
return -1;
}
sscanf(str + strlen("+MIPDNS: ") + strlen(host_name) + 3, "%d.%d.%d.%d", &seg1, &seg2, &seg3, &seg4);
snprintf(host_ip, host_ip_len, "%d.%d.%d.%d", seg1, seg2, seg3, seg4);
host_ip[host_ip_len - 1] = '\0';
printf("GOT IP: %s\n", host_ip);
return 0;
}
__STATIC__ uint8_t __ascii2hex(char in) {
if (('0' <= in) && (in <= '9')) {
return in - '0';
}
if (('A' <= in) && (in <= 'F')) {
return in - 'A' + 10;
}
if (('a' <= in) && (in <= 'f')) {
return in - 'a' + 10;
}
return (uint8_t)-1;
}
__STATIC__ void __asciistr2hex(char *in, uint8_t *out, int len) {
int i = 0;
for (i = 0; i < len; i += 2) {
out[i / 2] = (__ascii2hex(in[i]) << 4) + __ascii2hex(in[i + 1]);
}
}
__STATIC__ char ascii_stream[1024];
__STATIC__ uint8_t hex_stream[512];
__STATIC__ void l610_tcp_incoming_data_process(void)
{
uint8_t data;
int channel_id = 0, leaf_data_len = 0, read_len;
/*
+MIPRTCP: <socket id>,<leaf length>,<hex string>
*/
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
channel_id = channel_id * 10 + (data - '0');
}
channel_id--;
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
leaf_data_len = leaf_data_len * 10 + (data - '0');
}
read_len = tos_at_uart_readline((uint8_t*)ascii_stream, sizeof(ascii_stream));
read_len -= 2;
ascii_stream[read_len] = '\0';
__asciistr2hex(ascii_stream, hex_stream, read_len);
tos_at_channel_write(channel_id, hex_stream, read_len/2);
return;
}
__STATIC__ void l610_udp_incoming_data_process(void)
{
uint8_t data;
int channel_id = 0, leaf_data_len = 0, read_len;
/*
+MIPRUDP: <src ip>,<src port>, <socket id>,<leaf length>,<hex string>
*/
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
}
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
}
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
channel_id = channel_id * 10 + (data - '0');
}
channel_id--;
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == ',') {
break;
}
leaf_data_len = leaf_data_len * 10 + (data - '0');
}
read_len = tos_at_uart_readline((uint8_t*)ascii_stream, sizeof(ascii_stream));
read_len -= 2;
ascii_stream[read_len] = '\0';
__asciistr2hex(ascii_stream, hex_stream, read_len);
tos_at_channel_write(channel_id, hex_stream, read_len/2);
return;
}
at_event_t l610_at_event[] = {
{ "+MIPRTCP: ", l610_tcp_incoming_data_process},
{ "+MIPRUDP: ", l610_udp_incoming_data_process},
};
sal_module_t sal_module_l610 = {
.init = l610_init,
.connect = l610_connect,
.send = l610_send,
.recv_timeout = l610_recv_timeout,
.recv = l610_recv,
.sendto = l610_sendto,
.recvfrom = l610_recvfrom,
.recvfrom_timeout = l610_recvfrom_timeout,
.close = l610_close,
.parse_domain = l610_parse_domain,
};
int l610_sal_init(hal_uart_port_t uart_port)
{
if (tos_at_init(uart_port, l610_at_event,
sizeof(l610_at_event) / sizeof(l610_at_event[0])) != 0) {
return -1;
}
if (tos_sal_module_register(&sal_module_l610) != 0) {
return -1;
}
if (tos_sal_module_init() != 0) {
return -1;
}
return 0;
}
int l610_sal_deinit()
{
int id = 0;
for (id = 0; id < AT_DATA_CHANNEL_NUM; ++id) {
tos_sal_module_close(id);
}
tos_sal_module_register_default();
tos_at_deinit();
return 0;
}

27
devices/l610/l610.h Normal file
View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef __L610_H__
#define __L610_H__
#include "tos_hal.h"
int l610_sal_init(hal_uart_port_t uart_port);
int l610_sal_deinit(void);
#endif /* __L610_H__ */

36
devices/ml302/Makefile Normal file
View File

@@ -0,0 +1,36 @@
###################################################################
#automatic detection QTOP and LOCALDIR
CUR_DIR := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
TRYQTOP := $(shell if [ -n "$$QTOP" ] ; then\
echo $$QTOP;\
else\
cd $(CUR_DIR); while /usr/bin/test ! -d qmk ; do \
dir=`cd ../;pwd`; \
if [ "$$dir" = "/" ] ; then \
echo Cannot find QTOP in $(firstword $(MAKEFILE_LIST)) 1>&2; \
exit 1; \
fi ; \
cd $$dir; \
done ; \
pwd; \
fi)
QTOP ?= $(realpath ${TRYQTOP})
ifeq ($(QTOP),)
$(error Please run this in a tree)
endif
LOCALDIR = $(patsubst %/,%,$(subst $(realpath $(QTOP))/,,$(CUR_DIR)))
####################################################################
TREE_LIB_ENABLE=0
lib=
subdirs=
CFGFLAGS += -I$(QTOP)/net/at/include
CFGFLAGS += -I$(QTOP)/net/sal_module_wrapper
include ${QTOP}/qmk/generic/Make.tpl

517
devices/ml302/ml302.c Normal file
View File

@@ -0,0 +1,517 @@
#include "tos_at.h"
#include "ml302.h"
#include "sal_module_wrapper.h"
#include "main.h"
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
static int ml302_wait_ok(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10)
{
tos_at_cmd_exec(&echo, 1000, "AT\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
}
return -1;
}
static int ml302_echo_close(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
return -1;
}
static int ml302_pin_ready(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+CPIN: READY");
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
return -1;
}
static int ml302_gsm_network_check(void)
{
int stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CFUN?\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
str = strstr(echo.buffer, "+CFUN:");
if (!str)
{
return -1;
}
sscanf(str, "+CFUN:%d", &stat);
if (stat == 1)
{
return 0;
}
}
return -1;
}
static int ml302_signal_quality_check(void)
{
int rssi, ber;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
str = strstr(echo.buffer, "+CSQ:");
if (!str)
{
return -1;
}
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99)
{
return 0;
}
}
return -1;
}
static int ml302_set_gprs_apn(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CGDCONT=1,\"IP\",\"CMIOT\"\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
return -1 ;
}
static int ml302_activate(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 6000, "AT+CGACT=1,1\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
str = strstr(echo.buffer, "+CGACT:");
if (!str)
{
return -1;
}
sscanf(str, "+CGACT:%d,%d", &n, &stat);
if (stat == 1)
{
return 0;
}
}
return -1;
}
static int ml302_connect(const char *ip, const char *port, sal_proto_t proto)
{
int id;
at_echo_t echo;
char except_str[16];
id = tos_at_channel_alloc(ip, port);
if (id == -1)
{
return -1;
}
sprintf(except_str, "%d,CONNECT OK", id);
tos_at_echo_create(&echo, NULL, 0, except_str);
tos_at_cmd_exec_until(&echo, 6000, "AT+MIPOPEN=%d,\"%s\",\"%s\",%d\r\n",
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
if (echo.status != AT_ECHO_STATUS_EXPECT )
{
tos_at_channel_free(id);
return -1;
}
return id;
}
static int ml302_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
static int ml302_recv(int id, void *buf, size_t len)
{
return ml302_recv_timeout(id, buf, len, (uint32_t)4000);
}
int ml302_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
int ml302_recvfrom(int id, void *buf, size_t len)
{
return ml302_recvfrom_timeout(id, buf, len, (uint32_t)4000);
}
int ml302_sendto(int id, char *ip, char *port, const void *buf, size_t len)
{
at_echo_t echo;
if (tos_at_global_lock_pend() != 0)
{
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec_until(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id, len);
if (echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
int ml302_send(int id, const void *buf, size_t len)
{
at_echo_t echo;
if (tos_at_global_lock_pend() != 0)
{
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec(&echo, 1000,
"AT+MIPSEND=%d,%d\r\n",
id, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return 0 ;
}
static void ml302_transparent_mode_exit(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(NULL, 500, "+++");
}
static int ml302_close(int id)
{
at_echo_t echo;
ml302_transparent_mode_exit();
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+MIPCLOSE=%d\r\n", id);
tos_at_channel_free(id);
return 0;
}
static int ml302_parse_domain(const char *host_name, char *host_ip, size_t host_ip_len)
{
char *str;
at_echo_t echo;
char echo_buffer[64];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+MDNSGIP=\"%s\"\r\n", host_name);
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
/*
+MDNSGIP: 0,"www.baidu.com","39.156.66.14","39.156.66.18"
*/
int seg1, seg2, seg3, seg4;
str = strstr(echo.buffer, "+MDNSGIP: 0,");
if (!str)
{
return -1;
}
str += strlen("+MDNSGIP: 0,\"") + strlen(host_name) + 3;
sscanf(str, "%d.%d.%d.%d", &seg1, &seg2, &seg3, &seg4);
snprintf(host_ip, host_ip_len, "%d.%d.%d.%d", seg1, seg2, seg3, seg4);
host_ip[host_ip_len - 1] = '\0';
printf("GOT IP: %s\n", host_ip);
return 0;
}
static int ml302_init(void)
{
printf("Init ML302 ...\n" );
if (ml302_wait_ok() != 0)
{
printf("ml302 start FAILED\n");
return -1;
}
if (ml302_echo_close() != 0)
{
printf("ml302 echo close FAILED\n");
return -1;
}
if (ml302_pin_ready() != 0)
{
printf("ml302 pin not ready\n");
return -1;
}
if(ml302_gsm_network_check() != 0)
{
printf("ml302 GSM network register status check fail\n");
return -1 ;
}
if (ml302_signal_quality_check() != 0)
{
printf("ml302 signal quality check status failed\n");
return -1;
}
if (ml302_set_gprs_apn() != 0)
{
printf("ml302 set gprs_apn failed\n");
return -1;
}
if (ml302_activate())
{
printf("ml302 activate FAILED\n");
return -1;
}
printf("Init ML302 Done\n" );
return 0;
}
__STATIC__ void ml302_incoming_data_process(void)
{
uint8_t data;
int channel_id = 0, data_len = 0, read_len;
uint8_t buffer[128];
/*
+MIPURC: "recv",<sockid>,<datalen>
<data content>
*/
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == ',')
{
break;
}
channel_id = channel_id * 10 + (data - '0');
}
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == '\r')
{
break;
}
data_len = data_len * 10 + (data - '0');
}
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
do
{
#define MIN(a, b) ((a) < (b) ? (a) : (b))
read_len = MIN(data_len, sizeof(buffer));
if (tos_at_uart_read(buffer, read_len) != read_len)
{
return;
}
if (tos_at_channel_write(channel_id, buffer, read_len) <= 0)
{
return;
}
data_len -= read_len;
}
while (data_len > 0);
return;
}
at_event_t ml302_at_event[] =
{
{ "+MIPURC: \"recv\",", ml302_incoming_data_process },
};
sal_module_t sal_module_ml302 =
{
.init = ml302_init,
.connect = ml302_connect,
.send = ml302_send,
.recv = ml302_recv,
.recv_timeout = ml302_recv_timeout,
.sendto = ml302_sendto,
.recvfrom = ml302_recvfrom,
.recvfrom_timeout = ml302_recvfrom_timeout,
.close = ml302_close,
.parse_domain = ml302_parse_domain,
};
int ml302_sal_init(hal_uart_port_t uart_port)
{
if (tos_at_init(uart_port, ml302_at_event,
sizeof(ml302_at_event) / sizeof(ml302_at_event[0])) != 0)
{
return -1;
}
if (tos_sal_module_register(&sal_module_ml302) != 0)
{
return -1;
}
if (tos_sal_module_init() != 0)
{
return -1;
}
return 0;
}

25
devices/ml302/ml302.h Normal file
View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef __ML302_H_
#define __ML302_H_
#include "tos_hal.h"
int ml302_sal_init(hal_uart_port_t uart_port);
#endif /* __ML302_H_ */

594
devices/rhf76_lora/RHF76.c Normal file
View File

@@ -0,0 +1,594 @@
#include "RHF76.h"
#include "tos_hal.h"
static const char RHF76_LOWPOWER_SET[] = {
0xFF,0xFF,0xFF,0xFF,'A','T','+','L','O','W','P','O','W','E','R','=','a','u','t','o','o','f','f','\r','\n'
};
static int rhf76_exit_low_power(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+LOWPOWER: AUTOOFF");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, RHF76_LOWPOWER_SET);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_reset(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+RESET: OK");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, RHF76_ATCMD_RESET);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_id(lora_id_type_t id_type, char *id)
{
char cmd[64] = {0};
int try = 0;
at_echo_t echo;
switch(id_type) {
case LORA_ID_TYPE_DEVADDR:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_ID_DEVADDR, id);
break;
case LORA_ID_TYPE_DEVEUI:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_ID_DEVEUI, id);
break;
case LORA_ID_TYPE_APPEUI:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_ID_DEVAPPEUI, id);
break;
default:
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "+ID: ");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_key(lora_key_type_t key_type, char *key)
{
char cmd[64] = {0};
int try = 0;
at_echo_t echo;
switch (key_type) {
case LORA_KEY_TYPE_APPKEY:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_KEY_TYPE_APPKEY, key);
break;
case LORA_KEY_TYPE_APPSKEY:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_KEY_TYPE_APPSKEY, key);
break;
case LORA_KEY_TYPE_NWKSKEY:
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SET_KEY_TYPE_NWKSKEY, key);
break;
default:
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "+KEY:");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_class(lora_class_t lora_class)
{
char *cmd = NULL, *reply = NULL;
int try = 0;
at_echo_t echo;
switch (lora_class) {
case LORA_CLASS_A:
cmd = RHF76_ATCMD_SET_CLASS_A;
reply = RHF76_ATCMD_REPLY_CLASS_A;
break;
case LORA_CLASS_B:
cmd = RHF76_ATCMD_SET_CLASS_B;
reply = RHF76_ATCMD_REPLY_CLASS_B;
break;
case LORA_CLASS_C:
cmd = RHF76_ATCMD_SET_CLASS_C;
reply = RHF76_ATCMD_REPLY_CLASS_C;
break;
default:
return -1;
}
tos_at_echo_create(&echo, NULL, 0, reply);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_band(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, RHF76_ATCMD_REPLY_BAND_CN470);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, RHF76_ATCMD_SET_BAND_CN470);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_chanel(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+CH: NUM");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, RHF76_ATCMD_SET_CHANNEL);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_set_repeat(uint8_t num)
{
int try = 0;
at_echo_t echo;
char cmd[14] = {0};
char expect[10] = {'\0'};
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_REPT, num);
snprintf(expect, sizeof(expect), "+REPT: %d", num);
tos_at_echo_create(&echo, NULL, 0, expect);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_set_data_rate(uint8_t num)
{
if(num>15) return -1; // num should between [0, 15]
int try = 0;
at_echo_t echo;
char cmd[14] = {0};
char expect[10] = {'\0'};
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_DATA_RATE, num);
snprintf(expect, sizeof(expect), " DR%d", num);
tos_at_echo_fuzzy_matching_create(&echo, NULL, 0, expect);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_set_delay(char *param)
{
int try = 0;
at_echo_t echo;
char cmd[20] = {0};
char expect[20] = {'\0'};
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_DELAY, param);
snprintf(expect, sizeof(expect), "+DELAY %s", param);
tos_at_echo_create(&echo, NULL, 0, expect);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, cmd);
if(strstr(param,"?")!=NULL) return 0;
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_at_cmd_exe(char *cmd)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 8000, cmd);
return 0;
}
static int rhf76_set_adr_off(void)
{
int try = 0;
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "+ADR: OFF");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 3000, RHF76_ATCMD_SET_ADR_OFF);
if (echo.status == AT_ECHO_STATUS_OK|| echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_set_mode(lora_mode_t mode)
{
char *cmd = NULL, *reply = NULL;
int try = 0;
at_echo_t echo;
switch (mode) {
case LORA_MODE_LWOTAA:
cmd = RHF76_ATCMD_SET_MODE_LWOTAA;
reply = RHF76_ATCMD_REPLY_MODE_LWOTAA;
break;
case LORA_MODE_LWABP:
cmd = RHF76_ATCMD_SET_MODE_LWABP;
reply = RHF76_ATCMD_REPLY_MODE_LWABP;
break;
default:
return -1;
}
tos_at_echo_create(&echo, NULL, 0, reply);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 2500, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_join_otaa(const char *deveui, const char *appkey)
{
int try = 0;
at_echo_t echo;
if (rhf76_set_mode(LORA_MODE_LWOTAA) != 0) {
printf("rhf76 set mode FAILED\n");
return -1;
}
if (rhf76_set_id(LORA_ID_TYPE_DEVEUI, (char *)deveui) != 0) {
printf("rhf76 set deveui FAILED\n");
return -1;
}
if (rhf76_set_key(LORA_KEY_TYPE_APPKEY, (char *)appkey) != 0) {
printf("rhf76 set appkey FAILED\n");
return -1;
}
tos_stopwatch_delay_ms(2000);
tos_at_echo_create(&echo, NULL, 0, "+JOIN: Network joined");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 14000, RHF76_ATCMD_JOIN);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
int rhf76_join_abp(const char *deveui, const char *devaddr, const char *nwkskey, const char *appskey)
{
int try = 0;
at_echo_t echo;
if (rhf76_set_mode(LORA_MODE_LWABP) != 0) {
printf("rhf76 set mode FAILED\n");
return -1;
}
if (rhf76_set_id(LORA_ID_TYPE_DEVEUI, (char *)deveui) != 0) {
printf("rhf76 set deveui FAILED\n");
return -1;
}
if (rhf76_set_id(LORA_ID_TYPE_DEVADDR, (char *)devaddr) != 0) {
printf("rhf76 set devaddr FAILED\n");
return -1;
}
if (rhf76_set_key(LORA_KEY_TYPE_NWKSKEY, (char *)nwkskey) != 0) {
printf("rhf76 set nwkskey FAILED\n");
return -1;
}
if (rhf76_set_key(LORA_KEY_TYPE_APPSKEY, (char *)appskey) != 0) {
printf("rhf76 set appskey FAILED\n");
return -1;
}
tos_stopwatch_delay_ms(2000);
tos_at_echo_create(&echo, NULL, 0, "+JOIN: Network joined");
while (try++ < 10) {
tos_at_cmd_exec(&echo, 14000, RHF76_ATCMD_JOIN);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return 0;
}
}
return -1;
}
static int rhf76_init(void)
{
printf("Init RHF76 LoRa ...\n" );
tos_stopwatch_delay_ms(1000);
if (rhf76_exit_low_power() != 0) {
printf("rhf76 reset FAILED\n");
return -1;
}
if (rhf76_reset() != 0) {
printf("rhf76 reset FAILED\n");
return -1;
}
if (rhf76_set_class(LORA_CLASS_A) != 0) {
printf("rhf76 set class FAILED\n");
return -1;
}
if (rhf76_set_band() != 0) {
printf("rhf76 set band FAILED\n");
return -1;
}
if (rhf76_set_chanel() != 0) {
printf("rhf76 set chanel FAILED\n");
return -1;
}
if (rhf76_set_adr_off() != 0) {
printf("rhf76 set adr FAILED\n");
return -1;
}
if(rhf76_set_repeat(1)!=0){
printf("rhf76 set repeat times for unconfirmed message FAILED\n");
return -1;
}
tos_stopwatch_delay_ms(2000);
printf("Init RHF76 LoRa done\n");
/*----------------------------------------------------*/
/*--- the following code is only used for debuging ---*/
/*----------------------------------------------------*/
/*<-- query/set UART Timeout (~TX timeout) -->*/
// rhf76_at_cmd_exe("AT+UART=TIMEOUT, 300\r\n");
// rhf76_at_cmd_exe("AT+UART=TIMEOUT\r\n");
/*<-- query current band config -->*/
// rhf76_at_cmd_exe("AT+DR=SCHEME\r\n");
// rhf76_at_cmd_exe("AT+LW=CDR\r\n");
/*<-- query current data rate and the corresponding max payload size -->*/
rhf76_set_data_rate(0);
// rhf76_at_cmd_exe("at+dr=0\r\n");
// rhf76_at_cmd_exe("AT+DR\r\n");
// rhf76_at_cmd_exe("AT+LW=LEN\r\n");
/*<-- query RX1\RX2\JRX1\JRX2 delay config -->*/
// rhf76_set_delay("?");
/*<-- query RF config -->*/
// rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
// rhf76_at_cmd_exe("AT+TEST=?\r\n");
return 0;
}
__STATIC__ uint8_t __ascii2hex(char in) {
if (('0' <= in) && (in <= '9')) {
return in - '0';
}
if (('A' <= in) && (in <= 'F')) {
return in - 'A' + 10;
}
if (('a' <= in) && (in <= 'f')) {
return in - 'a' + 10;
}
return (uint8_t)-1;
}
__STATIC__ void __asciistr2hex(char *in, uint8_t *out, int len) {
int i = 0;
for (i = 0; i < len; i += 2) {
out[i / 2] = (__ascii2hex(in[i]) << 4) + __ascii2hex(in[i + 1]);
}
}
__STATIC__ char incoming_data_buffer[128];
__STATIC__ uint8_t hex_stream[128];
__STATIC__ void rhf76_incoming_data_process(void)
{
int ret;
uint8_t data;
/*
+CMSG: PORT: 8; RX: "12345678"
RX: prefix
"12345678": data content
*/
while (1) {
ret = tos_at_uart_read(&data, 1);
if (data == '"') {
break;
}
}
ret = 0;
memset(incoming_data_buffer, 0x00, sizeof(incoming_data_buffer));
while (1) {
tos_at_uart_read(&data, 1);
if (data == '"') {
break;
}
if(ret<128)
{
incoming_data_buffer[ret++] = data;
}
else
{
printf(" ERR:incomming data is big ,please give more space for incoming_data_buffer\n");
}
}
printf("rhf76_incoming_data_process %d: %s\n", ret, incoming_data_buffer);
__asciistr2hex(incoming_data_buffer, hex_stream, strlen(incoming_data_buffer));
extern lora_module_t lora_module_rhf76;
if (lora_module_rhf76.recv_callback) {
lora_module_rhf76.recv_callback(hex_stream, strlen(incoming_data_buffer) / 2);
}
}
at_event_t rhf76_at_event[] = {
{ "+CMSGHEX: PORT:", rhf76_incoming_data_process },
{ "+MSGHEX: PORT:", rhf76_incoming_data_process }
};
static char __num2hex(uint8_t num)
{
if (num <= 0x9) {
return num + '0';
}
if ((0xA <= num) && (num <= 0xF)) {
return num - 0xA + 'A';
}
return (char)-1;
}
static void __hex2str(uint8_t *in, char *out, int len)
{
int i = 0;
for (i = 0; i < len; ++i) {
out[i * 2] = __num2hex(in[i] >> 4);
out[i * 2 + 1] = __num2hex(in[i] & 0x0F);
}
out[2 * len] = '\0';
}
static int rhf76_send(const void *buf, size_t len)
{
char *str_buf = NULL;
str_buf = tos_mmheap_calloc(2 * len + 1, sizeof(char));
if (!str_buf) {
return -1;
}
__hex2str((uint8_t *)buf, str_buf, len);
char cmd[100] = {0};
at_echo_t echo;
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_CMSGHEX, str_buf);
cmd[sizeof(cmd) - 1] = '\0';
tos_mmheap_free(str_buf);
tos_at_echo_create(&echo, NULL, 0, "+CMSGHEX: ACK Received");
tos_at_cmd_exec(&echo, 6000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return len;
}
return -1;
}
static int rhf76_send_unconfirmed(const void *buf, size_t len)
{
char *str_buf = NULL;
at_echo_t echo;
str_buf = tos_mmheap_calloc(2 * len + 1, sizeof(char));
if (!str_buf) {
return -1;
}
__hex2str((uint8_t *)buf, str_buf, len);
char cmd[100] = {0};
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_MSGHEX, str_buf);
cmd[sizeof(cmd) - 1] = '\0';
tos_mmheap_free(str_buf);
tos_at_echo_create(&echo, NULL, 0, "+MSGHEX: Done");
tos_at_cmd_exec(&echo, 6000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return len;
}
return -1;
}
static int rhf76_close(void)
{
return 0;
}
lora_module_t lora_module_rhf76 = {
.init = rhf76_init,
.join_otaa = rhf76_join_otaa,
.join_abp = rhf76_join_abp,
.send = rhf76_send,
.send_unconfirmed = rhf76_send_unconfirmed,
.close = rhf76_close,
.recv_callback = K_NULL,
};
int rhf76_lora_init(hal_uart_port_t uart_port)
{
if (tos_at_init(uart_port, rhf76_at_event,
sizeof(rhf76_at_event) / sizeof(rhf76_at_event[0])) != 0) {
return -1;
}
tos_stopwatch_delay_ms(1000);
if (tos_lora_module_register(&lora_module_rhf76) != 0) {
return -1;
}
if (tos_lora_module_init() != 0) {
return -1;
}
return 0;
}

151
devices/rhf76_lora/RHF76.h Normal file
View File

@@ -0,0 +1,151 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef __RHF76_H__
#define __RHF76_H__
#include <stdio.h>
#include <string.h>
#include "usart.h"
#include "tos_at.h"
#include "lora_module_wrapper.h"
#define UART_RXBUF_MAXSIZE 256
typedef enum lora_class {
LORA_CLASS_A,
LORA_CLASS_B,
LORA_CLASS_C,
} lora_class_t;
typedef enum lora_mode {
LORA_MODE_LWOTAA,
LORA_MODE_LWABP,
} lora_mode_t;
typedef enum lora_id_type {
LORA_ID_TYPE_DEVADDR,
LORA_ID_TYPE_DEVEUI,
LORA_ID_TYPE_APPEUI,
} lora_id_type_t;
typedef enum lora_key_type {
LORA_KEY_TYPE_APPKEY,
LORA_KEY_TYPE_APPSKEY,
LORA_KEY_TYPE_NWKSKEY,
} lora_key_type_t;
#define RHF76_ATCMD_SET_CLASS_A "AT+CLASS=A\r\n"
#define RHF76_ATCMD_SET_CLASS_B "AT+CLASS=B\r\n"
#define RHF76_ATCMD_SET_CLASS_C "AT+CLASS=C\r\n"
#define RHF76_ATCMD_REPLY_CLASS_A "+CLASS: A"
#define RHF76_ATCMD_REPLY_CLASS_B "+CLASS: B"
#define RHF76_ATCMD_REPLY_CLASS_C "+CLASS: C"
#define RHF76_ATCMD_RESET "AT+RESET\r\n"
#define RHF76_ATCMD_FMT_SET_ID_DEVADDR "AT+ID=\"devaddr\",\"%s\"\r\n"
#define RHF76_ATCMD_FMT_SET_ID_DEVEUI "AT+ID=\"deveui\",\"%s\"\r\n"
#define RHF76_ATCMD_FMT_SET_ID_DEVAPPEUI "AT+ID=\"appeui\",\"%s\"\r\n"
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_APPKEY "AT+KEY=\"appkey\",%s\r\n"
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_APPSKEY "AT+KEY=\"appskey\",%s\r\n"
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_NWKSKEY "AT+KEY=\"nwkskey\",%s\r\n"
#define RHF76_ATCMD_FMT_SEND_CMSGHEX "AT+CMSGHEX=\"%s\"\r\n"
#define RHF76_ATCMD_FMT_SEND_MSGHEX "AT+MSGHEX=\"%s\"\r\n"
#define RHF76_ATCMD_SET_REPT "AT+REPT=%d\r\n"
#define RHF76_ATCMD_SET_DELAY "AT+DELAY=%s\r\n"
#define RHF76_ATCMD_SET_BAND_CN470 "AT+DR=CN470\r\n"
#define RHF76_ATCMD_REPLY_BAND_CN470 "+DR: CN470"
#define RHF76_ATCMD_SET_DATA_RATE "AT+DR=%d\r\n"
#define RHF76_ATCMD_SET_CHANNEL "at+ch=num,80-87\r\n"
#define RHF76_ATCMD_SET_ADR_OFF "at+adr=off\r\n"
#define RHF76_ATCMD_JOIN "AT+join\r\n"
#define RHF76_ATCMD_SET_MODE_LWOTAA "AT+MODE=LWOTAA\r\n"
#define RHF76_ATCMD_SET_MODE_LWABP "AT+MODE=LWABP\r\n"
#define RHF76_ATCMD_REPLY_MODE_LWOTAA "+MODE: LWOTAA"
#define RHF76_ATCMD_REPLY_MODE_LWABP "+MODE: LWABP"
int rhf76_lora_init(hal_uart_port_t uart_port);
/**
* @brief set the delay for RX1,RX2,JRX1,JRX2 OR query current delay config
* @note Examples:
* to set the delay(ms):
* rhf76_set_delay("RX1,2000");
*
* to query current delay config:
* rhf76_set_delay("?");
*
* @param params operation string
*
* @retval int Status
*/
int rhf76_set_delay(char *param);
/**
* @brief set repeat times when sending unconfirmed message
* @note it is equal to sending
* AT+REPT=2
* +REPT: 2
*
* @param num repeat times
*
* @retval int Status
*/
int rhf76_set_repeat(uint8_t num);
/**
* @brief set date rate, which would affect the maximum payload size
* @note this function is for DEBUG purpose only, it allows user to execute
* AT+ commands by passing the AT+ command to the function as an arg-
* ument.
* For example,users can query the RF configuration by following code:
*
* rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
* rhf76_at_cmd_exe("AT+TEST=?\r\n");
*
* @param num data rate
*
* @retval int Status
*/
int rhf76_set_data_rate(uint8_t num);
/**
* @brief execute AT+ commands
* @note this function is for DEBUG purpose only, it allows user to execute
* AT+ commands by passing the AT+ command to the function as an arg-
* ument.
* For example,users can query the RF configuration by following code:
*
* rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
* rhf76_at_cmd_exe("AT+TEST=?\r\n");
*
* @param cmd AT+ commands
*
* @retval int Status
*/
int rhf76_at_cmd_exe(char *cmd);
#endif /* __RHF76_H__ */