support aliyun sdk on TencentOS tiny
sample: examples\aliyun_iotkit_csdk_mqtt project: board\TencentOS_tiny_EVB_MX_Plus\KEIL\aliyun_iotkit_csdk_mqtt
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is
|
||||
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tos.h"
|
||||
|
||||
#include "infra_defs.h"
|
||||
|
||||
#ifdef DYNAMIC_REGISTER
|
||||
char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1ZETBPbycq";
|
||||
char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "L68wCVXYUaNg1Ey9";
|
||||
char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "example1";
|
||||
char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "";
|
||||
#else
|
||||
#ifdef DEVICE_MODEL_ENABLED
|
||||
char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1RIsMLz2BJ";
|
||||
char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "fSAF0hle6xL0oRWd";
|
||||
char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "example1";
|
||||
char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "RDXf67itLqZCwdMCRrw0N5FHbv5D7jrE";
|
||||
#else
|
||||
char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1MZxOdcBnO";
|
||||
char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "h4I4dneEFp7EImTv";
|
||||
char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "test_01";
|
||||
char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "t9GmMf2jb3LgWfXBaZD2r3aJrfVWBv56";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void *HAL_Malloc(uint32_t size);
|
||||
void HAL_Free(void *ptr);
|
||||
void HAL_Printf(const char *fmt, ...);
|
||||
|
||||
void HAL_Printf(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vsnprintf(str, len, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int HAL_Vsnprintf(char *str, const int len, const char *format, va_list ap)
|
||||
{
|
||||
return vsnprintf(str, len, format, ap);
|
||||
}
|
||||
|
||||
int HAL_GetModuleID(char *mid_str)
|
||||
{
|
||||
memset(mid_str, 0x0, IOTX_MODULE_ID_LEN);
|
||||
strcpy(mid_str, "c-sdk-2.3.0-mid");
|
||||
return strlen(mid_str);
|
||||
}
|
||||
|
||||
int HAL_SetProductKey(char *product_key)
|
||||
{
|
||||
int len = strlen(product_key);
|
||||
|
||||
if (len > IOTX_PRODUCT_KEY_LEN) {
|
||||
return -1;
|
||||
}
|
||||
memset(_product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
|
||||
strncpy(_product_key, product_key, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int HAL_SetDeviceName(char *device_name)
|
||||
{
|
||||
int len = strlen(device_name);
|
||||
|
||||
if (len > IOTX_DEVICE_NAME_LEN) {
|
||||
return -1;
|
||||
}
|
||||
memset(_device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
|
||||
strncpy(_device_name, device_name, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_SetProductSecret(char *product_secret)
|
||||
{
|
||||
int len = strlen(product_secret);
|
||||
|
||||
if (len > IOTX_PRODUCT_SECRET_LEN) {
|
||||
return -1;
|
||||
}
|
||||
memset(_product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
|
||||
strncpy(_product_secret, product_secret, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_SetDeviceSecret(char *device_secret)
|
||||
{
|
||||
int len = strlen(device_secret);
|
||||
|
||||
if (len > IOTX_DEVICE_SECRET_LEN) {
|
||||
return -1;
|
||||
}
|
||||
memset(_device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
|
||||
strncpy(_device_secret, device_secret, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1])
|
||||
{
|
||||
int len = strlen(_product_key);
|
||||
memset(product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
|
||||
|
||||
strncpy(product_key, _product_key, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_GetProductSecret(char product_secret[IOTX_PRODUCT_SECRET_LEN + 1])
|
||||
{
|
||||
int len = strlen(_product_secret);
|
||||
memset(product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
|
||||
|
||||
strncpy(product_secret, _product_secret, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1])
|
||||
{
|
||||
int len = strlen(_device_name);
|
||||
memset(device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
|
||||
|
||||
strncpy(device_name, _device_name, len);
|
||||
|
||||
return strlen(device_name);
|
||||
}
|
||||
|
||||
int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN + 1])
|
||||
{
|
||||
int len = strlen(_device_secret);
|
||||
memset(device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
|
||||
|
||||
strncpy(device_secret, _device_secret, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int HAL_GetFirmwareVersion(char *version)
|
||||
{
|
||||
char *ver = "app-1.0.0-20180101.1000";
|
||||
int len = strlen(ver);
|
||||
memset(version, 0x0, IOTX_FIRMWARE_VER_LEN);
|
||||
strncpy(version, ver, IOTX_FIRMWARE_VER_LEN);
|
||||
version[len] = '\0';
|
||||
return strlen(version);
|
||||
}
|
||||
|
||||
void *HAL_MutexCreate(void)
|
||||
{
|
||||
k_mutex_t *mutex;
|
||||
|
||||
mutex = (k_mutex_t *)HAL_Malloc(sizeof(k_mutex_t));
|
||||
tos_mutex_create(mutex);
|
||||
|
||||
return (void *)mutex;
|
||||
}
|
||||
|
||||
void HAL_MutexDestroy(void *mutex)
|
||||
{
|
||||
k_err_t ret;
|
||||
|
||||
if (K_ERR_NONE != (ret = tos_mutex_destroy((k_mutex_t *)mutex))) {
|
||||
HAL_Printf("osal_mutex_destroy err, err:%d\n\r", ret);
|
||||
} else {
|
||||
HAL_Free((void *)mutex);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_MutexLock(void *mutex)
|
||||
{
|
||||
k_err_t ret;
|
||||
|
||||
if (K_ERR_NONE != (ret = tos_mutex_pend((k_mutex_t *)mutex))) {
|
||||
HAL_Printf("osal_mutex_lock err, err:%d\n\r", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_MutexUnlock(void *mutex)
|
||||
{
|
||||
k_err_t ret;
|
||||
|
||||
if (K_ERR_NONE != (ret = tos_mutex_post((k_mutex_t *)mutex))) {
|
||||
HAL_Printf("osal_mutex_unlock err, err:%d\n\r", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void *HAL_Malloc(uint32_t size)
|
||||
{
|
||||
return tos_mmheap_alloc(size);
|
||||
}
|
||||
|
||||
void HAL_Free(void *ptr)
|
||||
{
|
||||
tos_mmheap_free(ptr);
|
||||
}
|
||||
|
||||
void HAL_SleepMs(uint32_t ms)
|
||||
{
|
||||
(void)tos_sleep_hmsm(0,0,0, ms);
|
||||
}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is
|
||||
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "tos.h"
|
||||
#include "sal_module_wrapper.h"
|
||||
|
||||
#define PORT_BUFF_LEN 16
|
||||
|
||||
int HAL_TCP_Establish(const char *host, uint16_t port)
|
||||
{
|
||||
int fd;
|
||||
char port_str[PORT_BUFF_LEN];
|
||||
|
||||
memset(port_str, 0, PORT_BUFF_LEN);
|
||||
snprintf(port_str, PORT_BUFF_LEN, "%u", port);
|
||||
printf("osal_tcp_connect entry, host=%s port=%d(%s)", host , port, port_str);
|
||||
|
||||
fd = tos_sal_module_connect(host, port_str, TOS_SAL_PROTO_TCP);
|
||||
if (fd < 0) {
|
||||
printf("net connect fail\n\r");
|
||||
if (0 == tos_sal_module_init()) {
|
||||
printf("net reinit success\n\r");
|
||||
fd = tos_sal_module_connect(host, port_str, TOS_SAL_PROTO_TCP);
|
||||
if (fd < 0) {
|
||||
printf("net connect fail\n\r");
|
||||
return NULL;
|
||||
} else {
|
||||
printf("net connect success, fd=%d\n\r", fd);
|
||||
}
|
||||
} else {
|
||||
printf("net reinit fail\n\r");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int HAL_TCP_Destroy(int fd)
|
||||
{
|
||||
(void)tos_sal_module_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_TCP_Write(int fd, const void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_sal_module_send(fd, buf, len);
|
||||
}
|
||||
|
||||
int32_t HAL_TCP_Read(int fd, void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_sal_module_recv_timeout(fd, buf, len, timeout);
|
||||
}
|
||||
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is
|
||||
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <tos.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tos.h"
|
||||
|
||||
uint32_t HAL_UptimeMs(void)
|
||||
{
|
||||
#if (TOS_CFG_CPU_TICK_PER_SECOND == 1000)
|
||||
return (uint32_t)tos_systick_get();
|
||||
#else
|
||||
k_tick_t tick = 0u;
|
||||
|
||||
tick = tos_systick_get() * 1000;
|
||||
return (uint32_t)((tick + TOS_CFG_CPU_TICK_PER_SECOND - 1) / TOS_CFG_CPU_TICK_PER_SECOND);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user