mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
make all kernal files to be single ascii
This commit is contained in:
parent
71670cd395
commit
a3a3d8fb75
@ -136,14 +136,12 @@ int32_t dictToStrEachHandle(PikaObj* self,
|
||||
void* context) {
|
||||
DictToStrContext* ctx = (DictToStrContext*)context;
|
||||
|
||||
// 判断是否需要在字符串前添加逗号
|
||||
if (!ctx->isFirst) {
|
||||
ctx->buf = arg_strAppend(ctx->buf, ", ");
|
||||
} else {
|
||||
ctx->isFirst = 0;
|
||||
}
|
||||
|
||||
// 将键值对添加到字符串
|
||||
ctx->buf = arg_strAppend(ctx->buf, "'");
|
||||
ctx->buf = arg_strAppend(ctx->buf, builtins_str(self, keyEach));
|
||||
ctx->buf = arg_strAppend(ctx->buf, "'");
|
||||
@ -160,15 +158,12 @@ int32_t dictToStrEachHandle(PikaObj* self,
|
||||
}
|
||||
|
||||
char* PikaStdData_Dict___str__(PikaObj* self) {
|
||||
// 初始化上下文
|
||||
DictToStrContext context;
|
||||
context.buf = arg_newStr("{");
|
||||
context.isFirst = 1;
|
||||
|
||||
// 使用 objDict_forEach 遍历字典
|
||||
objDict_forEach(self, dictToStrEachHandle, &context);
|
||||
|
||||
// 将字符串添加到结果中并返回
|
||||
context.buf = arg_strAppend(context.buf, "}");
|
||||
obj_setStr(self, "_buf", arg_getStr(context.buf));
|
||||
arg_deinit(context.buf);
|
||||
|
@ -241,9 +241,7 @@ PikaObj* PikaStdData_String_split(PikaObj* self, PikaTuple* s_) {
|
||||
} else {
|
||||
s = pikaTuple_getStr(s_, 0);
|
||||
}
|
||||
/* 创建 list 对象 */
|
||||
PikaObj* list = newNormalObj(New_PikaStdData_List);
|
||||
/* 初始化 list */
|
||||
PikaStdData_List___init__(list);
|
||||
|
||||
Args buffs = {0};
|
||||
|
@ -1,11 +1,39 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import codecs
|
||||
|
||||
|
||||
def format_file(filepath):
|
||||
try:
|
||||
subprocess.run(['clang-format', '-i', str(filepath)], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f'Error formatting file: {filepath}. Error message: {str(e)}')
|
||||
|
||||
non_ascii_lines = []
|
||||
|
||||
with codecs.open(filepath, 'r', 'utf-8-sig') as file:
|
||||
lines = file.readlines()
|
||||
for i, line in enumerate(lines):
|
||||
if filepath.suffix != '.cpp':
|
||||
if not line.isascii():
|
||||
non_ascii_lines.append((i + 1, line))
|
||||
|
||||
if lines and not lines[-1].endswith('\n'):
|
||||
lines.append('\n')
|
||||
print(f'Added newline to file: {filepath}')
|
||||
|
||||
with codecs.open(filepath, 'w', 'utf-8') as file:
|
||||
file.writelines(lines)
|
||||
|
||||
if non_ascii_lines:
|
||||
# print with yellow color
|
||||
print(f'\033[33mFound non-ASCII lines in file: {filepath}\033[0m')
|
||||
for line_no, line in non_ascii_lines:
|
||||
print(f'Line {filepath}:{line_no}: {line}')
|
||||
|
||||
|
||||
def format_files_in_dir(dir_path, dir_skip):
|
||||
# 遍历目录及其子目录中的所有文件
|
||||
for filepath in dir_path.rglob('*'):
|
||||
# Skip if the current file's directory or any of its parents are in dir_skip
|
||||
if any(str(filepath).startswith(dir) for dir in dir_skip):
|
||||
@ -13,22 +41,7 @@ def format_files_in_dir(dir_path, dir_skip):
|
||||
|
||||
# 只处理.c, .h, .cpp文件
|
||||
if filepath.suffix in ['.c', '.h', '.cpp']:
|
||||
try:
|
||||
# 使用clang-format命令格式化文件
|
||||
subprocess.run(
|
||||
['clang-format', '-i', str(filepath)], check=True)
|
||||
print(f'Formatted file: {filepath}')
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(
|
||||
f'Error formatting file: {filepath}. Error message: {str(e)}')
|
||||
|
||||
# 确保文件最后一行是空行
|
||||
with open(filepath, 'r+', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
if lines and not lines[-1].endswith('\n'):
|
||||
# 如果最后一行不是空行,添加一个
|
||||
file.write('\n')
|
||||
print(f'Added newline to file: {filepath}')
|
||||
format_file(filepath)
|
||||
|
||||
|
||||
# 从命令行参数获取目录列表
|
||||
@ -40,7 +53,10 @@ if len(dirs) == 0:
|
||||
'package/pikascript/pikascript-core', 'test']
|
||||
|
||||
dir_skip = ['package/pikascript/pikascript-lib/re',
|
||||
'package/pikascript/pikascript-lib/PikaNN']
|
||||
'package/pikascript/pikascript-lib/PikaNN',
|
||||
'package/pikascript/pikascript-lib/modbus',
|
||||
'package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h'
|
||||
]
|
||||
|
||||
# 对每个目录进行处理
|
||||
for dir_path_str in dirs:
|
||||
|
@ -1,20 +1,19 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __PROTECTED_LOW_OVERHEAD_OBJECT_ORIENTED_C_H__
|
||||
#define __PROTECTED_LOW_OVERHEAD_OBJECT_ORIENTED_C_H__
|
||||
|
||||
@ -75,7 +74,8 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ MACROFIED FUNCTIONS
|
||||
* ===========================*/
|
||||
|
||||
/*! \note add which macro to support multiple inheriting and implementations
|
||||
*!
|
||||
@ -274,7 +274,8 @@ extern "C" {
|
||||
#define this_interface(__INTERFACE) convert_obj_as(this, __INTERFACE)
|
||||
#define base_obj(__type) convert_obj_as(this, __type)
|
||||
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ TYPES
|
||||
* =========================================*/
|
||||
|
||||
//! \name interface: u32_property_t
|
||||
//! @{
|
||||
@ -340,9 +341,12 @@ bool (*Disable)(void);
|
||||
end_def_interface(en_property_t)
|
||||
//! @}
|
||||
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ GLOBAL VARIABLES
|
||||
* ==============================*/
|
||||
/*============================ LOCAL VARIABLES
|
||||
* ===============================*/
|
||||
/*============================ PROTOTYPES
|
||||
* ====================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,22 +1,21 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> *
|
||||
* with support from HenryLong<henry_long@163.com> *
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> * with
|
||||
*support from HenryLong<henry_long@163.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus) || defined(__OOC_CPP__)
|
||||
#undef __PLOOC_CLASS_USE_STRICT_TEMPLATE__
|
||||
#undef PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION___
|
||||
|
@ -1,20 +1,19 @@
|
||||
/****************************************************************************
|
||||
* Copyright 2017 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
|
||||
* Copyright 2017 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
/*============================ INCLUDES ======================================*/
|
||||
//#include <stdint.h>
|
||||
//#include <stdbool.h>
|
||||
@ -38,7 +37,8 @@ extern "C" {
|
||||
#undef __end_extern_class
|
||||
#undef class
|
||||
#undef __class
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ MACROFIED FUNCTIONS
|
||||
* ===========================*/
|
||||
|
||||
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||
|
||||
@ -183,7 +183,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*
|
||||
* new standard (lower case) *
|
||||
* new standard (lower case) *
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#undef __class_internal
|
||||
@ -211,11 +211,15 @@ extern "C" {
|
||||
#undef which
|
||||
#define which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ TYPES
|
||||
* =========================================*/
|
||||
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ GLOBAL VARIABLES
|
||||
* ==============================*/
|
||||
/*============================ LOCAL VARIABLES
|
||||
* ===============================*/
|
||||
/*============================ PROTOTYPES
|
||||
* ====================================*/
|
||||
|
||||
#undef __PLOOC_CLASS_IMPLEMENT__
|
||||
#undef __PLOOC_CLASS_INHERIT__
|
||||
|
@ -1,22 +1,21 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> *
|
||||
* with support from HenryLong<henry_long@163.com> *
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> * with
|
||||
*support from HenryLong<henry_long@163.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* HOW TO USE *
|
||||
******************************************************************************/
|
||||
@ -44,7 +43,8 @@ extern "C" {
|
||||
#undef protected_member
|
||||
#undef public_member
|
||||
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ MACROFIED FUNCTIONS
|
||||
* ===========================*/
|
||||
|
||||
#ifndef __PLOOC_CLASS_SIMPLE_H__
|
||||
#define __PLOOC_CLASS_SIMPLE_H__
|
||||
@ -201,10 +201,14 @@ extern "C" {
|
||||
#undef __PLOOC_CLASS_INHERIT__
|
||||
#undef __PLOOC_CLASS_IMPLEMENT
|
||||
#undef __PLOOC_CLASS_INHERIT
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ TYPES
|
||||
* =========================================*/
|
||||
/*============================ GLOBAL VARIABLES
|
||||
* ==============================*/
|
||||
/*============================ LOCAL VARIABLES
|
||||
* ===============================*/
|
||||
/*============================ PROTOTYPES
|
||||
* ====================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,22 +1,21 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> *
|
||||
* with support from HenryLong<henry_long@163.com> *
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* and SimonQian<simonqian@simonqian.com> * with
|
||||
*support from HenryLong<henry_long@163.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* HOW TO USE *
|
||||
******************************************************************************/
|
||||
@ -44,7 +43,8 @@ extern "C" {
|
||||
#undef protected_member
|
||||
#undef public_member
|
||||
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ MACROFIED FUNCTIONS
|
||||
* ===========================*/
|
||||
|
||||
#ifndef __PLOOC_CLASS_SIMPLE_C90_H__
|
||||
#define __PLOOC_CLASS_SIMPLE_C90_H__
|
||||
@ -152,10 +152,14 @@ extern "C" {
|
||||
#undef __PLOOC_CLASS_IMPLEMENT
|
||||
#undef __PLOOC_CLASS_INHERIT
|
||||
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ TYPES
|
||||
* =========================================*/
|
||||
/*============================ GLOBAL VARIABLES
|
||||
* ==============================*/
|
||||
/*============================ LOCAL VARIABLES
|
||||
* ===============================*/
|
||||
/*============================ PROTOTYPES
|
||||
* ====================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); * you may
|
||||
*not use this file except in compliance with the License. * You may
|
||||
*obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* 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. *
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
//#ifndef __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
|
||||
//#define __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
|
||||
|
||||
@ -61,7 +60,8 @@ extern "C" {
|
||||
#undef end_extern_class
|
||||
#undef __end_extern_class
|
||||
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ MACROFIED FUNCTIONS
|
||||
* ===========================*/
|
||||
|
||||
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||
|
||||
@ -446,10 +446,14 @@ extern "C" {
|
||||
#undef __PLOOC_CLASS_INHERIT__
|
||||
#undef __PLOOC_CLASS_IMPLEMENT
|
||||
#undef __PLOOC_CLASS_INHERIT
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ TYPES
|
||||
* =========================================*/
|
||||
/*============================ GLOBAL VARIABLES
|
||||
* ==============================*/
|
||||
/*============================ LOCAL VARIABLES
|
||||
* ===============================*/
|
||||
/*============================ PROTOTYPES
|
||||
* ====================================*/
|
||||
|
||||
//#endif /* deliberately comment this out! */
|
||||
|
||||
|
@ -70,11 +70,11 @@ struct JDEC {
|
||||
uint32_t wreg; /* Working shift register */
|
||||
uint8_t marker; /* Detected marker (0:None) */
|
||||
#if JD_FASTDECODE == 2
|
||||
uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */
|
||||
uint16_t*
|
||||
hufflut_ac[2]; /* Fast huffman decode tables for AC short code [id] */
|
||||
uint8_t*
|
||||
hufflut_dc[2]; /* Fast huffman decode tables for DC short code [id] */
|
||||
uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */
|
||||
uint16_t* hufflut_ac[2]; /* Fast huffman decode tables for AC short code
|
||||
[id] */
|
||||
uint8_t* hufflut_dc[2]; /* Fast huffman decode tables for DC short code
|
||||
[id] */
|
||||
#endif
|
||||
#endif
|
||||
void* workbuf; /* Working buffer for IDCT and RGB output */
|
||||
|
@ -27,5 +27,6 @@ KB of code size. / 0: Disable / 1: Enable
|
||||
/* Optimization level
|
||||
/ 0: Basic optimization. Suitable for 8/16-bit MCUs.
|
||||
/ 1: + 32-bit barrel shifter. Suitable for 32-bit MCUs.
|
||||
/ 2: + Table conversion for huffman decoding (wants 6 << HUFF_BIT bytes of RAM)
|
||||
/ 2: + Table conversion for huffman decoding (wants 6 << HUFF_BIT bytes of
|
||||
RAM)
|
||||
*/
|
||||
|
@ -2,8 +2,8 @@
|
||||
#include "PikaCV_Transforms.h"
|
||||
#include "PikaCV_common.h"
|
||||
|
||||
/* Session identifier for input/output functions (name, members and usage are as
|
||||
user defined) */
|
||||
/* Session identifier for input/output functions (name, members and usage
|
||||
are as user defined) */
|
||||
typedef struct {
|
||||
uint8_t* input_ptr; /* Pointer to input data */
|
||||
size_t input_offset; /* Offset of input data */
|
||||
@ -339,7 +339,6 @@ void PikaCV_Converter_toBMP(PikaObj* self, PikaObj* image) {
|
||||
int width = img->width;
|
||||
int height = img->height;
|
||||
|
||||
// bmp的每行数据的长度要4字节对齐
|
||||
row_align = align(width * 3, 4);
|
||||
|
||||
/* convert to BMP */
|
||||
|
@ -407,9 +407,7 @@ PikaObj* PikaCV_Image_split(PikaObj* self) {
|
||||
PikaCV_Image___init__(img);
|
||||
PikaCV_Image_loadGray(img, src->width, src->height, RGB[i]);
|
||||
Arg* token_arg = arg_newObj(img);
|
||||
/* 添加到 list 对象 */
|
||||
PikaStdData_List_append(list, token_arg);
|
||||
/* 销毁 arg */
|
||||
arg_deinit(token_arg);
|
||||
}
|
||||
|
||||
|
@ -281,9 +281,9 @@ void PikaCV_Transforms_adaptiveThreshold(PikaObj* self,
|
||||
memcpy(src_copy, src_data, size);
|
||||
|
||||
if (method == 0) {
|
||||
PikaCV_Filter_meanFilter(self, image, subsize, subsize); //均值滤波
|
||||
PikaCV_Filter_meanFilter(self, image, subsize, subsize);
|
||||
} else if (method == 1) {
|
||||
PikaCV_Filter_medianFilter(self, image); //中值滤波
|
||||
PikaCV_Filter_medianFilter(self, image);
|
||||
} else {
|
||||
free(src_copy);
|
||||
return;
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#define PI (3.141592653589793115997963468544185161590576171875l)
|
||||
#define E (2.718281828459045090795598298427648842334747314453125l)
|
||||
//初始化,填入π和e的值
|
||||
void PikaMath_Math___init__(PikaObj* self) {
|
||||
obj_setFloat(self, "pi", PI);
|
||||
obj_setFloat(self, "e", E);
|
||||
|
@ -264,9 +264,7 @@ PikaObj* PikaMath_Quaternion_toEuler(PikaObj* self) {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Arg* token_arg = arg_newFloat(rpy[i]);
|
||||
/* 添加到 list 对象 */
|
||||
PikaStdData_List_append(list, token_arg);
|
||||
/* 销毁 arg */
|
||||
arg_deinit(token_arg);
|
||||
}
|
||||
|
||||
|
@ -65,17 +65,16 @@ static pika_bool _IIC_SendByte(pika_hal_SOFT_IIC_config* cfg, uint8_t byte) {
|
||||
byte <<= 1;
|
||||
}
|
||||
|
||||
// 在发送完字节后检查ACK信号
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
_IIC_Delay();
|
||||
_IIC_SDA_input(cfg); // 设置SDA为输入
|
||||
_GPIO_write(cfg->SCL, 1); // 将SCL线设置为高,让从设备发送ACK信号
|
||||
_IIC_SDA_input(cfg);
|
||||
_GPIO_write(cfg->SCL, 1);
|
||||
|
||||
int timeout = 1000;
|
||||
uint32_t ack = 0;
|
||||
do {
|
||||
_IIC_Delay();
|
||||
ack = !_GPIO_read(cfg->SDA); // 如果从设备发送了ACK信号,SDA线会被拉低
|
||||
ack = !_GPIO_read(cfg->SDA);
|
||||
} while (ack == 0 && timeout-- > 0);
|
||||
|
||||
// pika_debug("ack timeout:%d", timeout);
|
||||
@ -83,28 +82,28 @@ static pika_bool _IIC_SendByte(pika_hal_SOFT_IIC_config* cfg, uint8_t byte) {
|
||||
pika_platform_printf("Error: IIC write byte timeout\r\n");
|
||||
}
|
||||
|
||||
_GPIO_write(cfg->SCL, 0); // 将SCL线设置为低,完成一个I2C周期
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
return ack;
|
||||
}
|
||||
|
||||
static void _IIC_Ack(pika_hal_SOFT_IIC_config* cfg) {
|
||||
_GPIO_write(cfg->SCL, 0); // 拉低时钟线
|
||||
_IIC_SDA_output(cfg); // 设置SDA为输出
|
||||
_GPIO_write(cfg->SDA, 0); // 拉低数据线
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
_IIC_SDA_output(cfg);
|
||||
_GPIO_write(cfg->SDA, 0);
|
||||
_IIC_Delay();
|
||||
_GPIO_write(cfg->SCL, 1); // 产生时钟
|
||||
_GPIO_write(cfg->SCL, 1);
|
||||
_IIC_Delay();
|
||||
_GPIO_write(cfg->SCL, 0); // 拉低时钟线
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
}
|
||||
|
||||
static void _IIC_NAck(pika_hal_SOFT_IIC_config* cfg) {
|
||||
_GPIO_write(cfg->SCL, 0); // 拉低时钟线
|
||||
_IIC_SDA_output(cfg); // 设置SDA为输出
|
||||
_GPIO_write(cfg->SDA, 1); // 数据线拉高
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
_IIC_SDA_output(cfg);
|
||||
_GPIO_write(cfg->SDA, 1);
|
||||
_IIC_Delay();
|
||||
_GPIO_write(cfg->SCL, 1); // 产生时钟
|
||||
_GPIO_write(cfg->SCL, 1);
|
||||
_IIC_Delay();
|
||||
_GPIO_write(cfg->SCL, 0); // 拉低时钟线
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
}
|
||||
|
||||
static uint8_t _IIC_ReadByte(pika_hal_SOFT_IIC_config* cfg, uint8_t ack) {
|
||||
@ -120,11 +119,10 @@ static uint8_t _IIC_ReadByte(pika_hal_SOFT_IIC_config* cfg, uint8_t ack) {
|
||||
_GPIO_write(cfg->SCL, 0);
|
||||
_IIC_Delay();
|
||||
}
|
||||
// 在读取完一个字节后发送ACK信号
|
||||
if (ack) {
|
||||
_IIC_Ack(cfg); // 如果ack为真,发送ACK信号
|
||||
_IIC_Ack(cfg);
|
||||
} else {
|
||||
_IIC_NAck(cfg); // 如果ack为假,发送NACK信号
|
||||
_IIC_NAck(cfg);
|
||||
}
|
||||
pika_debug(" - iic read: 0x%02X", byte);
|
||||
return byte;
|
||||
@ -136,11 +134,10 @@ int pika_hal_platform_SOFT_IIC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
uint8_t* data = (uint8_t*)buf;
|
||||
|
||||
_IIC_Start(iic_cfg);
|
||||
uint8_t addr_write = (iic_cfg->slave_addr << 1) | 0x00; // 方向位为0代表写
|
||||
uint8_t addr_write = (iic_cfg->slave_addr << 1) | 0x00;
|
||||
// pika_debug("iic addr_write: 0x%02X", addr_write);
|
||||
_IIC_SendByte(iic_cfg, addr_write); // 方向位为0代表写
|
||||
_IIC_SendByte(iic_cfg, addr_write);
|
||||
|
||||
// 如果启用了mem_addr_ena,将设备地址和内存地址发送到I2C总线
|
||||
if (iic_cfg->mem_addr_ena == PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE) {
|
||||
if (iic_cfg->mem_addr_size == PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT) {
|
||||
_IIC_SendByte(iic_cfg, iic_cfg->mem_addr & 0xFF);
|
||||
@ -164,12 +161,10 @@ int pika_hal_platform_SOFT_IIC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
|
||||
_IIC_Start(iic_cfg);
|
||||
|
||||
// 如果启用了mem_addr_ena,先写设备地址和内存地址
|
||||
if (iic_cfg->mem_addr_ena == PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE) {
|
||||
uint8_t addr_write =
|
||||
(iic_cfg->slave_addr << 1) | 0x00; // 方向位为0代表写
|
||||
uint8_t addr_write = (iic_cfg->slave_addr << 1) | 0x00;
|
||||
// pika_debug("iic addr_write: 0x%02X", addr_write);
|
||||
_IIC_SendByte(iic_cfg, addr_write); // 方向位为0代表写
|
||||
_IIC_SendByte(iic_cfg, addr_write);
|
||||
if (iic_cfg->mem_addr_size == PIKA_HAL_IIC_MEM_ADDR_SIZE_8BIT) {
|
||||
_IIC_SendByte(iic_cfg, iic_cfg->mem_addr & 0xFF);
|
||||
} else if (iic_cfg->mem_addr_size == PIKA_HAL_IIC_MEM_ADDR_SIZE_16BIT) {
|
||||
@ -179,9 +174,9 @@ int pika_hal_platform_SOFT_IIC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
_IIC_Start(iic_cfg);
|
||||
}
|
||||
|
||||
uint8_t addr_read = (iic_cfg->slave_addr << 1) | 0x01; // 方向位为1代表读
|
||||
uint8_t addr_read = (iic_cfg->slave_addr << 1) | 0x01;
|
||||
// pika_debug("iic addr_read: 0x%02X", addr_read);
|
||||
_IIC_SendByte(iic_cfg, addr_read); // 方向位为1代表读
|
||||
_IIC_SendByte(iic_cfg, addr_read);
|
||||
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
// data[i] = _IIC_ReadByte(iic_cfg, 1);
|
||||
@ -215,7 +210,6 @@ int pika_hal_platform_SOFT_IIC_ioctl_config(pika_dev* dev,
|
||||
"Error: SOFT IIC config error, SDA and SCL must be set\r\n");
|
||||
return -1;
|
||||
}
|
||||
// 检查软件IIC配置项是否正确
|
||||
if (cfg->master_or_slave != PIKA_HAL_IIC_MASTER &&
|
||||
cfg->master_or_slave != PIKA_HAL_IIC_SLAVE) {
|
||||
__platform_printf(
|
||||
@ -240,7 +234,6 @@ int pika_hal_platform_SOFT_IIC_ioctl_config(pika_dev* dev,
|
||||
"Error: SOFT IIC config error, mem_addr_size must be set\r\n");
|
||||
return -1;
|
||||
}
|
||||
// 在这里,我们暂时不检查speed和timeout,因为软件模拟的I2C可能无法精确控制速度和超时。
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -136,14 +136,12 @@ int32_t dictToStrEachHandle(PikaObj* self,
|
||||
void* context) {
|
||||
DictToStrContext* ctx = (DictToStrContext*)context;
|
||||
|
||||
// 判断是否需要在字符串前添加逗号
|
||||
if (!ctx->isFirst) {
|
||||
ctx->buf = arg_strAppend(ctx->buf, ", ");
|
||||
} else {
|
||||
ctx->isFirst = 0;
|
||||
}
|
||||
|
||||
// 将键值对添加到字符串
|
||||
ctx->buf = arg_strAppend(ctx->buf, "'");
|
||||
ctx->buf = arg_strAppend(ctx->buf, builtins_str(self, keyEach));
|
||||
ctx->buf = arg_strAppend(ctx->buf, "'");
|
||||
@ -160,15 +158,12 @@ int32_t dictToStrEachHandle(PikaObj* self,
|
||||
}
|
||||
|
||||
char* PikaStdData_Dict___str__(PikaObj* self) {
|
||||
// 初始化上下文
|
||||
DictToStrContext context;
|
||||
context.buf = arg_newStr("{");
|
||||
context.isFirst = 1;
|
||||
|
||||
// 使用 objDict_forEach 遍历字典
|
||||
objDict_forEach(self, dictToStrEachHandle, &context);
|
||||
|
||||
// 将字符串添加到结果中并返回
|
||||
context.buf = arg_strAppend(context.buf, "}");
|
||||
obj_setStr(self, "_buf", arg_getStr(context.buf));
|
||||
arg_deinit(context.buf);
|
||||
|
@ -241,9 +241,7 @@ PikaObj* PikaStdData_String_split(PikaObj* self, PikaTuple* s_) {
|
||||
} else {
|
||||
s = pikaTuple_getStr(s_, 0);
|
||||
}
|
||||
/* 创建 list 对象 */
|
||||
PikaObj* list = newNormalObj(New_PikaStdData_List);
|
||||
/* 初始化 list */
|
||||
PikaStdData_List___init__(list);
|
||||
|
||||
Args buffs = {0};
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "_base64.h"
|
||||
|
||||
#include "mbedtls/base64.h"
|
||||
|
||||
Arg* _base64_b64decode(PikaObj* self, Arg* s) {
|
||||
|
@ -19,7 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* cJSON */
|
||||
/* JSON parser in C. */
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef pika_cJSON__h
|
||||
#define pika_cJSON__h
|
||||
|
||||
@ -34,14 +33,14 @@ extern "C" {
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid
|
||||
issues where we are being called from a project with a different default calling
|
||||
convention. For windows you have 3 define options:
|
||||
/* When compiling for windows, we specify a specific calling convention to
|
||||
avoid issues where we are being called from a project with a different
|
||||
default calling convention. For windows you have 3 define options:
|
||||
|
||||
pika_cJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever
|
||||
dllexport symbols pika_cJSON_EXPORT_SYMBOLS - Define this on library build when
|
||||
you want to dllexport symbols (default) pika_cJSON_IMPORT_SYMBOLS - Define this
|
||||
if you want to dllimport symbol
|
||||
pika_cJSON_HIDE_SYMBOLS - Define this in the case where you don't want to
|
||||
ever dllexport symbols pika_cJSON_EXPORT_SYMBOLS - Define this on library
|
||||
build when you want to dllexport symbols (default) pika_cJSON_IMPORT_SYMBOLS
|
||||
- Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar
|
||||
behavior by
|
||||
@ -52,8 +51,8 @@ or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the pika_cJSON_API_VISIBILITY flag to "export" the same symbols the
|
||||
way pika_cJSON_EXPORT_SYMBOLS does
|
||||
then using the pika_cJSON_API_VISIBILITY flag to "export" the same symbols
|
||||
the way pika_cJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
@ -113,24 +112,26 @@ typedef struct cJSON {
|
||||
* GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON* next;
|
||||
struct cJSON* prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of
|
||||
* the items in the array/object. */
|
||||
/* An array or object item will have a child pointer pointing to a chain
|
||||
* of the items in the array/object. */
|
||||
struct cJSON* child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==pika_cJSON_String and type == pika_cJSON_Raw
|
||||
/* The item's string, if type==pika_cJSON_String and type ==
|
||||
* pika_cJSON_Raw
|
||||
*/
|
||||
char* valuestring;
|
||||
/* writing to valueint is DEPRECATED, use pika_cJSON_SetNumberValue instead
|
||||
/* writing to valueint is DEPRECATED, use pika_cJSON_SetNumberValue
|
||||
* instead
|
||||
*/
|
||||
int valueint;
|
||||
/* The item's number, if type==pika_cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list
|
||||
* of subitems of an object. */
|
||||
/* The item's name string, if this item is the child of, or is in the
|
||||
* list of subitems of an object. */
|
||||
char* string;
|
||||
} cJSON;
|
||||
|
||||
@ -156,13 +157,14 @@ pika_cJSON_PUBLIC(const char*) pika_cJSON_Version(void);
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
pika_cJSON_PUBLIC(void) pika_cJSON_InitHooks(pika_cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from
|
||||
* all variants of pika_cJSON_Parse (with pika_cJSON_Delete) and
|
||||
/* Memory Management: the caller is always responsible to free the results
|
||||
* from all variants of pika_cJSON_Parse (with pika_cJSON_Delete) and
|
||||
* pika_cJSON_Print (with stdlib free, pika_cJSON_Hooks.free_fn, or
|
||||
* pika_cJSON_free as appropriate). The exception is
|
||||
* pika_cJSON_PrintPreallocated, where the caller has full responsibility of the
|
||||
* buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate.
|
||||
* pika_cJSON_PrintPreallocated, where the caller has full responsibility of
|
||||
* the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can
|
||||
* interrogate.
|
||||
*/
|
||||
pika_cJSON_PUBLIC(cJSON*) pika_cJSON_Parse(const char* value);
|
||||
pika_cJSON_PUBLIC(cJSON*)
|
||||
@ -184,18 +186,19 @@ pika_cJSON_PUBLIC(cJSON*)
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
pika_cJSON_PUBLIC(char*) pika_cJSON_Print(const cJSON* item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
/* Render a cJSON entity to text for transfer/storage without any
|
||||
* formatting. */
|
||||
pika_cJSON_PUBLIC(char*) pika_cJSON_PrintUnformatted(const cJSON* item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
|
||||
* at the final size. guessing well reduces reallocation. fmt=0 gives
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a
|
||||
* guess at the final size. guessing well reduces reallocation. fmt=0 gives
|
||||
* unformatted, =1 gives formatted */
|
||||
pika_cJSON_PUBLIC(char*) pika_cJSON_PrintBuffered(const cJSON* item,
|
||||
int prebuffer,
|
||||
pika_cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with
|
||||
* given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will
|
||||
* use, so to be safe allocate 5 bytes more than you actually need */
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory
|
||||
* with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it
|
||||
* will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_PrintPreallocated(cJSON* item,
|
||||
char* buffer,
|
||||
@ -219,8 +222,9 @@ pika_cJSON_PUBLIC(cJSON*)
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_HasObjectItem(const cJSON* object, const char* string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error.
|
||||
* You'll probably need to look a few chars back to make sense of it. Defined
|
||||
* when pika_cJSON_Parse() returns 0. 0 when pika_cJSON_Parse() succeeds. */
|
||||
* You'll probably need to look a few chars back to make sense of it.
|
||||
* Defined when pika_cJSON_Parse() returns 0. 0 when pika_cJSON_Parse()
|
||||
* succeeds. */
|
||||
pika_cJSON_PUBLIC(const char*) pika_cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
@ -277,17 +281,17 @@ pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_AddItemToArray(cJSON* array, cJSON* item);
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_AddItemToObject(cJSON* object, const char* string, cJSON* item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and
|
||||
* will definitely survive the cJSON object. WARNING: When this function was
|
||||
* used, make sure to always check that (item->type & pika_cJSON_StringIsConst)
|
||||
* is zero before writing to `item->string` */
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as),
|
||||
* and will definitely survive the cJSON object. WARNING: When this function
|
||||
* was used, make sure to always check that (item->type &
|
||||
* pika_cJSON_StringIsConst) is zero before writing to `item->string` */
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_AddItemToObjectCS(cJSON* object,
|
||||
const char* string,
|
||||
cJSON* item);
|
||||
/* Append reference to item to the specified array/object. Use this when you
|
||||
* want to add an existing cJSON to a new cJSON, but don't want to corrupt your
|
||||
* existing cJSON. */
|
||||
* want to add an existing cJSON to a new cJSON, but don't want to corrupt
|
||||
* your existing cJSON. */
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_AddItemReferenceToArray(cJSON* array, cJSON* item);
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
@ -335,26 +339,27 @@ pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
/* Duplicate a cJSON item */
|
||||
pika_cJSON_PUBLIC(cJSON*)
|
||||
pika_cJSON_Duplicate(const cJSON* item, pika_cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new
|
||||
* memory that will need to be released. With recurse!=0, it will duplicate any
|
||||
* children connected to the item. The item->next and ->prev pointers are always
|
||||
* zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or
|
||||
* invalid, they will be considered unequal. case_sensitive determines if object
|
||||
* keys are treated case sensitive (1) or case insensitive (0) */
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in
|
||||
* new memory that will need to be released. With recurse!=0, it will
|
||||
* duplicate any children connected to the item. The item->next and ->prev
|
||||
* pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is
|
||||
* NULL or invalid, they will be considered unequal. case_sensitive
|
||||
* determines if object keys are treated case sensitive (1) or case
|
||||
* insensitive (0) */
|
||||
pika_cJSON_PUBLIC(pika_cJSON_bool)
|
||||
pika_cJSON_Compare(const cJSON* const a,
|
||||
const cJSON* const b,
|
||||
const pika_cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from
|
||||
* strings. The input pointer json cannot point to a read-only address area,
|
||||
* such as a string constant, but should point to a readable and writable
|
||||
* address area. */
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n')
|
||||
* from strings. The input pointer json cannot point to a read-only address
|
||||
* area, such as a string constant, but should point to a readable and
|
||||
* writable address area. */
|
||||
pika_cJSON_PUBLIC(void) pika_cJSON_Minify(char* json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
/* Helper functions for creating and adding items to an object at the same
|
||||
* time. They return the added item or NULL on failure. */
|
||||
pika_cJSON_PUBLIC(cJSON*)
|
||||
pika_cJSON_AddNullToObject(cJSON* const object, const char* const name);
|
||||
pika_cJSON_PUBLIC(cJSON*)
|
||||
@ -391,8 +396,8 @@ pika_cJSON_PUBLIC(double)
|
||||
#define pika_cJSON_SetNumberValue(object, number) \
|
||||
((object != NULL) ? pika_cJSON_SetNumberHelper(object, (double)number) \
|
||||
: (number))
|
||||
/* Change the valuestring of a pika_cJSON_String object, only takes effect when
|
||||
* type of object is pika_cJSON_String */
|
||||
/* Change the valuestring of a pika_cJSON_String object, only takes effect
|
||||
* when type of object is pika_cJSON_String */
|
||||
pika_cJSON_PUBLIC(char*)
|
||||
pika_cJSON_SetValuestring(cJSON* object, const char* valuestring);
|
||||
|
||||
@ -401,8 +406,8 @@ pika_cJSON_PUBLIC(char*)
|
||||
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
|
||||
element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with
|
||||
* pika_cJSON_InitHooks */
|
||||
/* malloc/free objects using the malloc/free functions that have been set
|
||||
* with pika_cJSON_InitHooks */
|
||||
pika_cJSON_PUBLIC(void*) pika_cJSON_malloc(size_t size);
|
||||
pika_cJSON_PUBLIC(void) pika_cJSON_free(void* object);
|
||||
|
||||
|
@ -3,23 +3,23 @@
|
||||
*
|
||||
* Copyright (c) 2010 Serge Zaitsev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef JSMN_H
|
||||
#define JSMN_H
|
||||
@ -94,9 +94,8 @@ typedef struct jsmn_parser {
|
||||
JSMN_API void jsmn_init(jsmn_parser* parser);
|
||||
|
||||
/**
|
||||
* Run JSON parser. It parses a JSON data string into and array of tokens, each
|
||||
* describing
|
||||
* a single JSON object.
|
||||
* Run JSON parser. It parses a JSON data string into and array of tokens,
|
||||
* each describing a single JSON object.
|
||||
*/
|
||||
JSMN_API int jsmn_parse(jsmn_parser* parser,
|
||||
const char* js,
|
||||
@ -153,7 +152,8 @@ static int jsmn_parse_primitive(jsmn_parser* parser,
|
||||
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
|
||||
switch (js[parser->pos]) {
|
||||
#ifndef JSMN_STRICT
|
||||
/* In strict mode primitive must be followed by "," or "}" or "]" */
|
||||
/* In strict mode primitive must be followed by "," or "}" or
|
||||
* "]" */
|
||||
case ':':
|
||||
#endif
|
||||
case '\t':
|
||||
@ -310,7 +310,8 @@ JSMN_API int jsmn_parse(jsmn_parser* parser,
|
||||
if (parser->toksuper != -1) {
|
||||
jsmntok_t* t = &tokens[parser->toksuper];
|
||||
#ifdef JSMN_STRICT
|
||||
/* In strict mode an object or array can't become a key */
|
||||
/* In strict mode an object or array can't become a key
|
||||
*/
|
||||
if (t->type == JSMN_OBJECT) {
|
||||
return JSMN_ERROR_INVAL;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#define PI (3.141592653589793115997963468544185161590576171875l)
|
||||
#define E (2.718281828459045090795598298427648842334747314453125l)
|
||||
//初始化,填入π和e的值
|
||||
void _math___init__(PikaObj* self) {
|
||||
obj_setFloat(self, "pi", PI);
|
||||
obj_setFloat(self, "e", E);
|
||||
|
@ -38,7 +38,6 @@
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "agile_modbus.h"
|
||||
#include <string.h>
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PKG_AGILE_MODBUS_H
|
||||
#define __PKG_AGILE_MODBUS_H
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PKG_AGILE_MODBUS_RTU_H
|
||||
#define __PKG_AGILE_MODBUS_RTU_H
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "agile_modbus.h"
|
||||
#include "agile_modbus_tcp.h"
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PKG_AGILE_MODBUS_TCP_H
|
||||
#define __PKG_AGILE_MODBUS_TCP_H
|
||||
|
||||
|
@ -11,10 +11,10 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - add connack return code definitions
|
||||
* Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
* Ian Craggs - fix for issue #64, bit order in connack response
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Ian Craggs - add connack return code definitions Xiang Rong -
|
||||
*442039 Add makefile to Embedded C client Ian Craggs - fix for issue #64,
|
||||
*bit order in connack response
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MQTTCONNECT_H_
|
||||
|
@ -11,20 +11,20 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Determines the length of the MQTT connect packet that would be produced using
|
||||
* the supplied connect options.
|
||||
* Determines the length of the MQTT connect packet that would be produced
|
||||
* using the supplied connect options.
|
||||
* @param options the options to be used to build the connect packet
|
||||
* @return the length of buffer needed to contain the serialized version of the
|
||||
* packet
|
||||
* @return the length of buffer needed to contain the serialized version of
|
||||
* the packet
|
||||
*/
|
||||
int MQTTSerialize_connectLength(MQTTPacket_connectData* options) {
|
||||
int len = 0;
|
||||
|
@ -11,9 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
@ -11,9 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
@ -11,7 +11,8 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
|
@ -11,7 +11,8 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#if !defined(MQTTFORMAT_H)
|
||||
|
@ -11,11 +11,10 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Sergio R. Caprile - non-blocking packet read functions for stream
|
||||
*transport
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Sergio R. Caprile - non-blocking packet read functions for
|
||||
*stream transport
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
|
@ -11,10 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MQTTPACKET_H_
|
||||
#define MQTTPACKET_H_
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MQTTPUBLISH_H_
|
||||
|
@ -11,23 +11,23 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=453144
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Ian Craggs - fix for
|
||||
*https://bugs.eclipse.org/bugs/show_bug.cgi?id=453144
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Determines the length of the MQTT publish packet that would be produced using
|
||||
* the supplied parameters
|
||||
* Determines the length of the MQTT publish packet that would be produced
|
||||
* using the supplied parameters
|
||||
* @param qos the MQTT QoS of the publish (packetid is omitted for QoS 0)
|
||||
* @param topicName the topic name to be used in the publish
|
||||
* @param payloadlen the length of the payload to be sent
|
||||
* @return the length of buffer needed to contain the serialized version of the
|
||||
* packet
|
||||
* @return the length of buffer needed to contain the serialized version of
|
||||
* the packet
|
||||
*/
|
||||
int MQTTSerialize_publishLength(int qos, MQTTString topicName, int payloadlen) {
|
||||
int len = 0;
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 20:15:32
|
||||
* @LastEditTime: 2019-12-20 20:37:31
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 IBM Corp.
|
||||
|
@ -11,9 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
@ -25,8 +25,8 @@
|
||||
* @param count the number of topic filter strings in topicFilters
|
||||
* @param topicFilters the array of topic filter strings to be used in the
|
||||
* publish
|
||||
* @return the length of buffer needed to contain the serialized version of the
|
||||
* packet
|
||||
* @return the length of buffer needed to contain the serialized version of
|
||||
* the packet
|
||||
*/
|
||||
int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[]) {
|
||||
int i;
|
||||
|
@ -11,9 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
* Deserializes the supplied (wire) buffer into subscribe data
|
||||
* @param dup integer returned - the MQTT dup flag
|
||||
* @param packetid integer returned - the MQTT packet identifier
|
||||
* @param maxcount - the maximum number of members allowed in the topicFilters
|
||||
* and requestedQoSs arrays
|
||||
* @param count - number of members in the topicFilters and requestedQoSs arrays
|
||||
* @param maxcount - the maximum number of members allowed in the
|
||||
* topicFilters and requestedQoSs arrays
|
||||
* @param count - number of members in the topicFilters and requestedQoSs
|
||||
* arrays
|
||||
* @param topicFilters - array of topic filter names
|
||||
* @param requestedQoSs - array of requested QoS
|
||||
* @param buf the raw buffer data, of the correct length determined by the
|
||||
|
@ -11,8 +11,8 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Xiang Rong - 442039 Add makefile to Embedded C client
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MQTTUNSUBSCRIBE_H_
|
||||
|
@ -11,22 +11,22 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Determines the length of the MQTT unsubscribe packet that would be produced
|
||||
* using the supplied parameters
|
||||
* Determines the length of the MQTT unsubscribe packet that would be
|
||||
* produced using the supplied parameters
|
||||
* @param count the number of topic filter strings in topicFilters
|
||||
* @param topicFilters the array of topic filter strings to be used in the
|
||||
* publish
|
||||
* @return the length of buffer needed to contain the serialized version of the
|
||||
* packet
|
||||
* @return the length of buffer needed to contain the serialized version of
|
||||
* the packet
|
||||
*/
|
||||
int MQTTSerialize_unsubscribeLength(int count, MQTTString topicFilters[]) {
|
||||
int i;
|
||||
|
@ -11,9 +11,9 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
* Deserializes the supplied (wire) buffer into unsubscribe data
|
||||
* @param dup integer returned - the MQTT dup flag
|
||||
* @param packetid integer returned - the MQTT packet identifier
|
||||
* @param maxcount - the maximum number of members allowed in the topicFilters
|
||||
* and requestedQoSs arrays
|
||||
* @param count - number of members in the topicFilters and requestedQoSs arrays
|
||||
* @param maxcount - the maximum number of members allowed in the
|
||||
* topicFilters and requestedQoSs arrays
|
||||
* @param count - number of members in the topicFilters and requestedQoSs
|
||||
* arrays
|
||||
* @param topicFilters - array of topic filter names
|
||||
* @param buf the raw buffer data, of the correct length determined by the
|
||||
* remaining length field
|
||||
|
@ -11,8 +11,8 @@
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs - initial API and implementation and/or initial documentation
|
||||
* Ian Craggs - fix for bug #434081
|
||||
* Ian Craggs - initial API and implementation and/or initial
|
||||
*documentation Ian Craggs - fix for bug #434081
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef STACKTRACE_H_
|
||||
|
@ -14,12 +14,6 @@ void Subscribe_Handler(void* client, message_data_t* msg);
|
||||
|
||||
const uint32_t MQTT_RECONNECTION_EVENT_ID = 0xFFAA0088;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT___init__
|
||||
// 功能说明:对象初始化
|
||||
// 输入参数:
|
||||
// 返 回 值:无
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void _mqtt__MQTT___init__(PikaObj* self,
|
||||
char* ip,
|
||||
int port,
|
||||
@ -92,17 +86,10 @@ void _mqtt__MQTT___init__(PikaObj* self,
|
||||
|
||||
mqtt_set_clean_session(_client, 1);
|
||||
|
||||
obj_setPtr(self, "_client",
|
||||
_client); // 这里要再保存一次mqtt结构体的内容到python环境
|
||||
obj_setPtr(self, "_client", _client);
|
||||
// __platform_printf("Mqtt_Lib buildtime:%s-%s\r\n", __DATE__, __TIME__);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT___del__
|
||||
// 功能说明:释放对象资源
|
||||
// 输入参数:
|
||||
// 返 回 值:无
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void _mqtt__MQTT___del__(PikaObj* self) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
if (NULL == _client) {
|
||||
@ -117,12 +104,6 @@ void _mqtt__MQTT___del__(PikaObj* self) {
|
||||
mqtt_release_free(_client);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_connect
|
||||
// 功能说明:连接mqtt的服务端
|
||||
// 输入参数:无
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_connect(PikaObj* self) {
|
||||
int ret;
|
||||
obj_setInt(self, "_connected", 1);
|
||||
@ -137,12 +118,6 @@ int _mqtt__MQTT_connect(PikaObj* self) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_disconnect
|
||||
// 功能说明:断开 mqtt的连接
|
||||
// 输入参数:无
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_disconnect(PikaObj* self) {
|
||||
int ret;
|
||||
obj_setInt(self, "_connected", 0);
|
||||
@ -157,12 +132,6 @@ int _mqtt__MQTT_disconnect(PikaObj* self) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_listSubscribeTopic
|
||||
// 功能说明:罗列出当前订阅的主题
|
||||
// 输入参数:无
|
||||
// 返 回 值:对象指针
|
||||
///////////////////////////////////////////////////////////////////
|
||||
PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
// int i = 0;
|
||||
@ -180,9 +149,7 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 创建 list 对象 */
|
||||
list = newNormalObj(New_PikaStdData_List);
|
||||
/* 初始化 list */
|
||||
PikaStdData_List___init__(list);
|
||||
|
||||
LIST_FOR_EACH_SAFE(curr, next, &_client->mqtt_msg_handler_list) {
|
||||
@ -194,9 +161,7 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) {
|
||||
__LINE__, __FUNCTION__, ++i, msg_handler->topic_filter);
|
||||
// __platform_printf("[%d]subscribe topic: %s\n",++i,
|
||||
// msg_handler->topic_filter);
|
||||
/* 用 arg_new<type> 的 api 创建 arg */
|
||||
Arg* str_arg1 = arg_newStr((char*)msg_handler->topic_filter);
|
||||
/* 添加到 list 对象 */
|
||||
PikaStdData_List_append(list, str_arg1);
|
||||
arg_deinit(str_arg1);
|
||||
}
|
||||
@ -204,12 +169,6 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) {
|
||||
return list;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_publish
|
||||
// 功能说明:发布主题消息
|
||||
// 输入参数:主题名称,有效数据
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_publish(PikaObj* self, char* topic, char* payload, int qos) {
|
||||
int ret;
|
||||
mqtt_message_t msg;
|
||||
@ -233,8 +192,7 @@ int _mqtt__MQTT_publish(PikaObj* self, char* topic, char* payload, int qos) {
|
||||
|
||||
msg.payload = (void*)payload;
|
||||
msg.qos = qos;
|
||||
__platform_printf("msg.qos:%d\r\n",
|
||||
msg.qos); // 这里为了防止被优化,导致运行异常
|
||||
__platform_printf("msg.qos:%d\r\n", msg.qos);
|
||||
ret = mqtt_publish(_client, topic, &msg);
|
||||
if (ret == 0) {
|
||||
// __platform_printf("MQTT_publish OK\r\n");
|
||||
@ -243,12 +201,6 @@ int _mqtt__MQTT_publish(PikaObj* self, char* topic, char* payload, int qos) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setCa
|
||||
// 功能说明:设置ca值
|
||||
// 输入参数:ca值
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setCa(PikaObj* self, char* ca) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
@ -268,12 +220,6 @@ int _mqtt__MQTT_setCa(PikaObj* self, char* ca) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setClientID
|
||||
// 功能说明:设置mqtt客户端的id
|
||||
// 输入参数:id 字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setClientID(PikaObj* self, char* id) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
@ -293,12 +239,6 @@ int _mqtt__MQTT_setClientID(PikaObj* self, char* id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setHost
|
||||
// 功能说明:设置mqtt客户端,连接主机的ip或者url
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setHost(PikaObj* self, char* host_url) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
@ -311,23 +251,13 @@ int _mqtt__MQTT_setHost(PikaObj* self, char* host_url) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
obj_setStr(self, "host_str",
|
||||
host_url); // python 环境创建一个全局变量存放 host
|
||||
mqtt_set_host(
|
||||
_client,
|
||||
obj_getStr(self,
|
||||
"host_str")); // 从python环境中取出 host的指针 赋值给结构体
|
||||
obj_setStr(self, "host_str", host_url);
|
||||
mqtt_set_host(_client, obj_getStr(self, "host_str"));
|
||||
// __platform_printf("MQTT_setHost :%s\r\n", host_url);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setKeepAlive
|
||||
// 功能说明:设置mqtt客户端的 心跳包发送间隔
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setKeepAlive(PikaObj* self, int time) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
int tmp;
|
||||
@ -345,12 +275,6 @@ int _mqtt__MQTT_setKeepAlive(PikaObj* self, int time) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setPassword
|
||||
// 功能说明:设置mqtt客户端的 密码
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setPassword(PikaObj* self, char* passwd) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
@ -370,12 +294,6 @@ int _mqtt__MQTT_setPassword(PikaObj* self, char* passwd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setPort
|
||||
// 功能说明:设置mqtt客户端,连接主机的端口号
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setPort(PikaObj* self, int port) {
|
||||
char port_str[10] = {0};
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
@ -394,12 +312,6 @@ int _mqtt__MQTT_setPort(PikaObj* self, int port) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setUsername
|
||||
// 功能说明:设置mqtt客户端的用户名
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setUsername(PikaObj* self, char* name) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
@ -419,12 +331,6 @@ int _mqtt__MQTT_setUsername(PikaObj* self, char* name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setVersion
|
||||
// 功能说明:设置mqtt 协议版本
|
||||
// 输入参数:字符串格式
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setVersion(PikaObj* self, char* version) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
// int tmp;
|
||||
@ -447,12 +353,6 @@ int _mqtt__MQTT_setVersion(PikaObj* self, char* version) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setWill
|
||||
// 功能说明:设置遗嘱消息,异常断连时会发送这个消息
|
||||
// 输入参数:
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setWill(PikaObj* self,
|
||||
char* topic,
|
||||
char* payload,
|
||||
@ -488,7 +388,6 @@ int _mqtt__MQTT_setWill(PikaObj* self,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 必须转换成python环境的变量,否则函数退出后,topic里的是个空指针
|
||||
memset(topic_str, 0, sizeof(topic_str));
|
||||
sprintf(topic_str, "%s", topic);
|
||||
obj_setStr(self, topic_str, topic);
|
||||
@ -513,12 +412,6 @@ int _mqtt__MQTT_setWill(PikaObj* self,
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_subscribe
|
||||
// 功能说明:设置mqtt 订阅主题
|
||||
// 输入参数:
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_subscribe(PikaObj* self, char* topic, Arg* cb, int qos) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
int ret;
|
||||
@ -541,7 +434,6 @@ int _mqtt__MQTT_subscribe(PikaObj* self, char* topic, Arg* cb, int qos) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
// 必须转换成python环境的变量,否则函数退出后,topic里的是个空指针
|
||||
memset(topic_str, 0, sizeof(topic_str));
|
||||
sprintf(topic_str, "%s", topic);
|
||||
obj_setStr(self, topic_str, topic);
|
||||
@ -551,13 +443,11 @@ int _mqtt__MQTT_subscribe(PikaObj* self, char* topic, Arg* cb, int qos) {
|
||||
if (ret == 0) {
|
||||
// __platform_printf("MQTT_subscribe Topic :%s Qos:%d OK\r\n",
|
||||
// topic,qos);
|
||||
// 注册mqtt订阅主题的 回调函数
|
||||
if (cb != NULL) {
|
||||
char hash_str[32] = {0};
|
||||
memset(hash_str, 0, sizeof(hash_str));
|
||||
sprintf(hash_str, "C%d", hash_time33(topic_str));
|
||||
obj_newDirectObj(self, hash_str,
|
||||
New_TinyObj); // 新建一个对象来放CB
|
||||
obj_newDirectObj(self, hash_str, New_TinyObj);
|
||||
PikaObj* eventHandler = obj_getPtr(self, hash_str);
|
||||
obj_setArg(eventHandler, "eventCallBack", cb);
|
||||
/* init event_listener for the first time */
|
||||
@ -577,12 +467,6 @@ int _mqtt__MQTT_subscribe(PikaObj* self, char* topic, Arg* cb, int qos) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_unsubscribe
|
||||
// 功能说明:取消mqtt 订阅主题
|
||||
// 输入参数:
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_unsubscribe(PikaObj* self, char* topic) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
int ret;
|
||||
@ -601,12 +485,6 @@ int _mqtt__MQTT_unsubscribe(PikaObj* self, char* topic) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:Subscribe_Handler
|
||||
// 功能说明:mqtt 订阅主题 的回调函数
|
||||
// 输入参数:
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Subscribe_Handler(void* client, message_data_t* msg) {
|
||||
char topic_str[MQTT_TOPIC_LEN_MAX + 24];
|
||||
|
||||
@ -624,7 +502,6 @@ void Subscribe_Handler(void* client, message_data_t* msg) {
|
||||
obj_setStr(evt_obj, "msg", (char*)msg->message->payload);
|
||||
obj_setInt(evt_obj, "qos", msg->message->qos);
|
||||
|
||||
// 存好数据后,再发送事件信号,防止信号收到了但是需要传输的数据没准备好
|
||||
pika_eventListener_send(g_mqtt_event_listener, hash_time33(msg->topic_name),
|
||||
evt_obj_arg);
|
||||
|
||||
@ -646,59 +523,37 @@ void _mqtt__MQTT__fakeMsg(PikaObj* self, char* topic, int qos, char* msg) {
|
||||
Subscribe_Handler(NULL, &msg_data);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt___del__
|
||||
// 功能说明:释放事件处理器
|
||||
// 输入参数:
|
||||
// 返 回 值:
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void _mqtt___del__(PikaObj* self) {
|
||||
if (NULL != g_mqtt_event_listener) {
|
||||
pika_eventListener_deinit(&g_mqtt_event_listener);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:Reconnect_Handler
|
||||
// 功能说明:mqtt 断开连接后
|
||||
// 的回调函数,这里使用mqttclient库函数的,断线重连接口,提示发生了mqtt断连的事件
|
||||
// 输入参数:
|
||||
// 返 回 值:0=成功;非0=错误码
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Reconnect_Handler(void* client, void* reconnect_date) {
|
||||
// PikaObj* self = ((mqtt_client_t*)client)->user_data;
|
||||
// __platform_printf("Reconnect_Handler\r\n");
|
||||
|
||||
if (((mqtt_client_t*)client)->mqtt_client_state != CLIENT_STATE_CONNECTED) {
|
||||
// 发送事件信号
|
||||
pika_eventListener_sendSignal(g_mqtt_event_listener,
|
||||
MQTT_RECONNECTION_EVENT_ID, 1);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 函 数 名:_mqtt__MQTT_setDisconnectHandler
|
||||
// 功能说明:设置断开连接的回调函数
|
||||
// 输入参数:
|
||||
// 返 回 值:
|
||||
///////////////////////////////////////////////////////////////////
|
||||
int _mqtt__MQTT_setDisconnectHandler(PikaObj* self, Arg* cb) {
|
||||
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
||||
|
||||
// __platform_printf("_mqtt__MQTT_setDisconnectHandler\r\n");
|
||||
|
||||
// 注册到c库中
|
||||
mqtt_set_reconnect_handler(_client, Reconnect_Handler);
|
||||
|
||||
// char hash_str[32] = {0};
|
||||
// memset(hash_str,0,sizeof(hash_str));
|
||||
// sprintf(hash_str,"C%d",hash_time33(topic_str));
|
||||
// obj_newDirectObj(self,hash_str,New_TinyObj);//新建一个对象来放CB
|
||||
// obj_newDirectObj(self,hash_str,New_TinyObj);
|
||||
// PikaObj* eventHandler = obj_getPtr(self,hash_str);
|
||||
// obj_setArg(eventHandler, "eventCallBack", cb);
|
||||
|
||||
obj_setArg(self, "eventCallBack",
|
||||
cb); // 重连回调是唯一的,就直接用self对象
|
||||
obj_setArg(self, "eventCallBack", cb);
|
||||
/* init event_listener for the first time */
|
||||
if (NULL == g_mqtt_event_listener) {
|
||||
pika_eventListener_init(&g_mqtt_event_listener);
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @LastEditTime: 2020-06-17 19:31:41
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTT_CONFIG_H_
|
||||
#define _MQTT_CONFIG_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 00:42:16
|
||||
* @LastEditTime: 2020-10-17 14:16:15
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTT_ERROR_H_
|
||||
#define _MQTT_ERROR_H_
|
||||
|
@ -3,10 +3,9 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 22:46:33
|
||||
* @LastEditTime: 2020-04-27 23:28:12
|
||||
* @Description: the following code references TencentOS tiny, please keep the
|
||||
* author information and source code according to the license.
|
||||
* @Description: the following code references TencentOS tiny, please keep
|
||||
* the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
#include "mqtt_list.h"
|
||||
|
||||
static void _mqtt_list_add(mqtt_list_t* node,
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 22:47:55
|
||||
* @LastEditTime: 2020-10-17 14:18:02
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTT_LIST_H_
|
||||
#define _MQTT_LIST_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-27 03:25:58
|
||||
* @LastEditTime: 2020-10-17 14:15:55
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTT_LOG_H_
|
||||
#define _MQTT_LOG_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 21:31:25
|
||||
* @LastEditTime : 2022-06-12 17:39:43
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "mqttclient.h"
|
||||
|
||||
@ -1172,7 +1172,7 @@ static uint32_t mqtt_read_buf_malloc(mqtt_client_t* c, uint32_t size) {
|
||||
__LINE__, __FUNCTION__);
|
||||
RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
|
||||
}
|
||||
memset(c->mqtt_read_buf, 0, c->mqtt_read_buf_size); // 清空申请的内存
|
||||
memset(c->mqtt_read_buf, 0, c->mqtt_read_buf_size);
|
||||
return c->mqtt_read_buf_size;
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 21:31:25
|
||||
* @LastEditTime : 2022-06-11 22:45:02
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTTCLIENT_H_
|
||||
#define _MQTTCLIENT_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 13:38:52
|
||||
* @LastEditTime: 2020-05-25 10:13:41
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "nettype_tcp.h"
|
||||
#include "mqtt_log.h"
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 13:39:00
|
||||
* @LastEditTime: 2020-10-17 14:17:10
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _NETTYPE_TCP_H_
|
||||
#define _NETTYPE_TCP_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-11 19:45:35
|
||||
* @LastEditTime: 2020-09-20 14:29:06
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "nettype_tls.h"
|
||||
#include "platform_memory.h"
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 21:30:54
|
||||
* @LastEditTime: 2020-06-05 17:17:48
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "nettype_tcp.h"
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 21:31:02
|
||||
* @LastEditTime: 2020-10-17 14:14:41
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _NETWORK_H_
|
||||
#define _NETWORK_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-14 22:02:07
|
||||
* @LastEditTime: 2020-02-19 20:26:04
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "platform_memory.h"
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-14 22:06:35
|
||||
* @LastEditTime: 2020-10-17 14:17:24
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_MEMORY_H_
|
||||
#define _PLATFORM_MEMORY_H_
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-10 23:45:59
|
||||
* @LastEditTime: 2020-06-05 17:13:00
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "platform_net_socket.h"
|
||||
#include "mqtt_error.h"
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 13:39:00
|
||||
* @LastEditTime: 2020-10-17 14:17:45
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_NET_SOCKET_H_
|
||||
#define _PLATFORM_NET_SOCKET_H_
|
||||
|
@ -8,7 +8,6 @@
|
||||
* Copyright (c) 2022 jiejie, All Rights Reserved. Please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
|
||||
#ifndef _RANDOM_H_
|
||||
#define _RANDOM_H_
|
||||
|
||||
|
@ -20,49 +20,41 @@
|
||||
|
||||
#define IS_PATH_SEP(ch) ((ch) == '/' || (ch) == '\\')
|
||||
|
||||
// 返回指定路径的绝对路径
|
||||
char* os_path_abspath(PikaObj* self, char* path) {
|
||||
char* abs_path = NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD size = GetFullPathNameA(path, 0, NULL, NULL);
|
||||
if (size == 0) {
|
||||
// 获取绝对路径失败
|
||||
return NULL;
|
||||
}
|
||||
|
||||
abs_path = (char*)malloc(size * sizeof(char));
|
||||
if (abs_path == NULL) {
|
||||
// 内存分配失败
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DWORD ret_size = GetFullPathNameA(path, size, abs_path, NULL);
|
||||
if (ret_size == 0 || ret_size > size) {
|
||||
// 获取绝对路径失败
|
||||
free(abs_path);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
char* cwd = getcwd(NULL, 0);
|
||||
if (cwd == NULL) {
|
||||
// 获取当前工作目录失败
|
||||
return NULL;
|
||||
}
|
||||
|
||||
abs_path = realpath(path, NULL);
|
||||
if (abs_path == NULL) {
|
||||
// 获取绝对路径失败
|
||||
free(cwd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 如果路径不是绝对路径,则将其转换为绝对路径
|
||||
if (abs_path[0] != '/') {
|
||||
char* temp_path =
|
||||
(char*)malloc((strlen(cwd) + strlen(abs_path) + 2) * sizeof(char));
|
||||
if (temp_path == NULL) {
|
||||
// 内存分配失败
|
||||
free(cwd);
|
||||
free(abs_path);
|
||||
return NULL;
|
||||
@ -83,12 +75,10 @@ char* os_path_abspath(PikaObj* self, char* path) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// 判断指定路径是否存在
|
||||
PIKA_BOOL os_path_exists(PikaObj* self, char* path) {
|
||||
#ifdef _WIN32
|
||||
DWORD attr = GetFileAttributesA(path);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) {
|
||||
// 获取文件属性失败
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
|
||||
@ -96,7 +86,6 @@ PIKA_BOOL os_path_exists(PikaObj* self, char* path) {
|
||||
#else
|
||||
struct stat statbuf;
|
||||
if (stat(path, &statbuf) == -1) {
|
||||
// 获取文件状态失败
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
|
||||
@ -104,7 +93,6 @@ PIKA_BOOL os_path_exists(PikaObj* self, char* path) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// 判断指定路径是否为绝对路径
|
||||
PIKA_BOOL os_path_isabs(PikaObj* self, char* path) {
|
||||
#ifdef _WIN32
|
||||
if (path[0] == '\\' || path[0] == '/') {
|
||||
@ -231,16 +219,13 @@ int _os_path_split(char* path, char** folder, char** file) {
|
||||
}
|
||||
char* p = strrchr(path, PATH_SEPARATOR);
|
||||
if (p) {
|
||||
/* 字符串最后一个路径分隔符的位置 */
|
||||
size_t idx = p - path;
|
||||
/* 获取最后一个路径分隔符之前的路径 */
|
||||
*folder = pika_platform_malloc(idx + 2);
|
||||
if (*folder == NULL) {
|
||||
return -1;
|
||||
}
|
||||
strncpy(*folder, path, idx + 1);
|
||||
(*folder)[idx] = '\0';
|
||||
/* 获取最后一个路径分隔符之后的文件名 */
|
||||
*file = strdup(p + 1);
|
||||
if (*file == NULL) {
|
||||
pika_platform_free(*folder);
|
||||
@ -249,7 +234,6 @@ int _os_path_split(char* path, char** folder, char** file) {
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
/* 如果路径没有分隔符,则返回路径本身和空字符串 */
|
||||
*folder = strdup(path);
|
||||
if (*folder == NULL) {
|
||||
return -1;
|
||||
@ -267,35 +251,27 @@ int _os_path_split(char* path, char** folder, char** file) {
|
||||
int _os_path_splitext(char* path, char** file, char** ext) {
|
||||
char* p = strrchr(path, '.');
|
||||
if (p) {
|
||||
/* 字符串最后一个点的位置 */
|
||||
size_t idx = p - path;
|
||||
/* 获取点之前的路径 */
|
||||
*file = malloc(idx + 1);
|
||||
if (!(*file)) {
|
||||
/* 内存分配失败 */
|
||||
return -1;
|
||||
}
|
||||
strncpy(*file, path, idx);
|
||||
(*file)[idx] = '\0';
|
||||
/* 获取点之后的扩展名 */
|
||||
*ext = strdup(p);
|
||||
if (!(*ext)) {
|
||||
/* 内存分配失败 */
|
||||
pika_platform_free(*file);
|
||||
*file = NULL;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
/* 如果没有扩展名,则返回路径本身和空字符串 */
|
||||
*file = strdup(path);
|
||||
if (!(*file)) {
|
||||
/* 内存分配失败 */
|
||||
return -1;
|
||||
}
|
||||
*ext = strdup("");
|
||||
if (!(*ext)) {
|
||||
/* 内存分配失败 */
|
||||
free(*file);
|
||||
*file = NULL;
|
||||
return -1;
|
||||
@ -310,7 +286,7 @@ PikaObj* os_path_split(PikaObj* self, char* path) {
|
||||
PikaObj* tuple = NULL;
|
||||
|
||||
if (0 != _os_path_split(path, &folder, &file)) {
|
||||
goto __exit; // 发生错误,跳转到 __exit 处做资源回收
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
tuple = objTuple_new(arg_newStr(folder), arg_newStr(file));
|
||||
@ -339,7 +315,7 @@ PikaObj* os_path_splitext(PikaObj* self, char* path) {
|
||||
Arg* aExt = NULL;
|
||||
|
||||
if (0 != _os_path_splitext(path, &file, &ext)) {
|
||||
goto __exit; // 发生错误,跳转到 __exit 处做资源回收
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
tuple = newNormalObj(New_PikaStdData_Tuple);
|
||||
|
@ -58,7 +58,6 @@ char* os_read_platform(PikaObj* self, PikaObj* fd, int len) {
|
||||
size = fread(buf, 1, len, fp);
|
||||
|
||||
if (size > 0) {
|
||||
//转换成
|
||||
obj_setStr(self, "os_file_read", buf);
|
||||
free(buf);
|
||||
return obj_getStr(self, "os_file_read");
|
||||
@ -122,7 +121,6 @@ PikaObj* os_listdir_platform(char* path) {
|
||||
PikaStdData_List___init__(list);
|
||||
|
||||
handle = _findfirst(dirpath, &fb);
|
||||
//找到第一个匹配的文件
|
||||
if (handle != -1L) {
|
||||
if (memcmp(fb.name, ".", 1) != 0) {
|
||||
Arg* arg = arg_setStr(NULL, "", fb.name);
|
||||
|
@ -19,7 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* cJSON */
|
||||
/* JSON parser in C. */
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
@ -34,14 +33,14 @@ extern "C" {
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid
|
||||
issues where we are being called from a project with a different default calling
|
||||
convention. For windows you have 3 define options:
|
||||
/* When compiling for windows, we specify a specific calling convention to
|
||||
avoid issues where we are being called from a project with a different
|
||||
default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever
|
||||
dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you
|
||||
want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you
|
||||
want to dllimport symbol
|
||||
dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when
|
||||
you want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this
|
||||
if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar
|
||||
behavior by
|
||||
@ -52,8 +51,8 @@ or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way
|
||||
CJSON_EXPORT_SYMBOLS does
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the
|
||||
way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
@ -113,8 +112,8 @@ typedef struct cJSON {
|
||||
* GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON* next;
|
||||
struct cJSON* prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of
|
||||
* the items in the array/object. */
|
||||
/* An array or object item will have a child pointer pointing to a chain
|
||||
* of the items in the array/object. */
|
||||
struct cJSON* child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
@ -122,13 +121,14 @@ typedef struct cJSON {
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char* valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead
|
||||
*/
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list
|
||||
* of subitems of an object. */
|
||||
/* The item's name string, if this item is the child of, or is in the
|
||||
* list of subitems of an object. */
|
||||
char* string;
|
||||
} cJSON;
|
||||
|
||||
@ -154,12 +154,13 @@ CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from
|
||||
* all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib
|
||||
* free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is
|
||||
* cJSON_PrintPreallocated, where the caller has full responsibility of the
|
||||
* buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate.
|
||||
/* Memory Management: the caller is always responsible to free the results
|
||||
* from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print
|
||||
* (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate).
|
||||
* The exception is cJSON_PrintPreallocated, where the caller has full
|
||||
* responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can
|
||||
* interrogate.
|
||||
*/
|
||||
CJSON_PUBLIC(cJSON*) cJSON_Parse(const char* value);
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
@ -181,17 +182,18 @@ cJSON_ParseWithLengthOpts(const char* value,
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char*) cJSON_Print(const cJSON* item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
/* Render a cJSON entity to text for transfer/storage without any
|
||||
* formatting. */
|
||||
CJSON_PUBLIC(char*) cJSON_PrintUnformatted(const cJSON* item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
|
||||
* at the final size. guessing well reduces reallocation. fmt=0 gives
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a
|
||||
* guess at the final size. guessing well reduces reallocation. fmt=0 gives
|
||||
* unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char*)
|
||||
cJSON_PrintBuffered(const cJSON* item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with
|
||||
* given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will
|
||||
* use, so to be safe allocate 5 bytes more than you actually need */
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory
|
||||
* with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it
|
||||
* will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_PrintPreallocated(cJSON* item,
|
||||
char* buffer,
|
||||
@ -214,8 +216,8 @@ cJSON_GetObjectItemCaseSensitive(const cJSON* const object,
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_HasObjectItem(const cJSON* object, const char* string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error.
|
||||
* You'll probably need to look a few chars back to make sense of it. Defined
|
||||
* when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
* You'll probably need to look a few chars back to make sense of it.
|
||||
* Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char*) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
@ -258,8 +260,10 @@ CJSON_PUBLIC(cJSON*) cJSON_CreateArrayReference(const cJSON* child);
|
||||
* The parameter count cannot be greater than the number of elements in the
|
||||
* number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON*) cJSON_CreateIntArray(const int* numbers, int count);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_CreateFloatArray(const double* numbers, int count);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_CreateDoubleArray(const double* numbers, int count);
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
cJSON_CreateFloatArray(const double* numbers, int count);
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
cJSON_CreateDoubleArray(const double* numbers, int count);
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
cJSON_CreateStringArray(const char* const* strings, int count);
|
||||
|
||||
@ -267,15 +271,15 @@ cJSON_CreateStringArray(const char* const* strings, int count);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON* array, cJSON* item);
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_AddItemToObject(cJSON* object, const char* string, cJSON* item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and
|
||||
* will definitely survive the cJSON object. WARNING: When this function was
|
||||
* used, make sure to always check that (item->type & cJSON_StringIsConst) is
|
||||
* zero before writing to `item->string` */
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as),
|
||||
* and will definitely survive the cJSON object. WARNING: When this function
|
||||
* was used, make sure to always check that (item->type &
|
||||
* cJSON_StringIsConst) is zero before writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_AddItemToObjectCS(cJSON* object, const char* string, cJSON* item);
|
||||
/* Append reference to item to the specified array/object. Use this when you
|
||||
* want to add an existing cJSON to a new cJSON, but don't want to corrupt your
|
||||
* existing cJSON. */
|
||||
* want to add an existing cJSON to a new cJSON, but don't want to corrupt
|
||||
* your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_AddItemReferenceToArray(cJSON* array, cJSON* item);
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
@ -316,26 +320,27 @@ cJSON_ReplaceItemInObjectCaseSensitive(cJSON* object,
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_Duplicate(const cJSON* item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new
|
||||
* memory that will need to be released. With recurse!=0, it will duplicate any
|
||||
* children connected to the item. The item->next and ->prev pointers are always
|
||||
* zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or
|
||||
* invalid, they will be considered unequal. case_sensitive determines if object
|
||||
* keys are treated case sensitive (1) or case insensitive (0) */
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in
|
||||
* new memory that will need to be released. With recurse!=0, it will
|
||||
* duplicate any children connected to the item. The item->next and ->prev
|
||||
* pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is
|
||||
* NULL or invalid, they will be considered unequal. case_sensitive
|
||||
* determines if object keys are treated case sensitive (1) or case
|
||||
* insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool)
|
||||
cJSON_Compare(const cJSON* const a,
|
||||
const cJSON* const b,
|
||||
const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from
|
||||
* strings. The input pointer json cannot point to a read-only address area,
|
||||
* such as a string constant, but should point to a readable and writable
|
||||
* address area. */
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n')
|
||||
* from strings. The input pointer json cannot point to a read-only address
|
||||
* area, such as a string constant, but should point to a readable and
|
||||
* writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char* json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
/* Helper functions for creating and adding items to an object at the same
|
||||
* time. They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
cJSON_AddNullToObject(cJSON* const object, const char* const name);
|
||||
CJSON_PUBLIC(cJSON*)
|
||||
@ -373,8 +378,8 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON* object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) \
|
||||
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) \
|
||||
: (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type
|
||||
* of object is cJSON_String */
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when
|
||||
* type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*)
|
||||
cJSON_SetValuestring(cJSON* object, const char* valuestring);
|
||||
|
||||
@ -383,8 +388,8 @@ cJSON_SetValuestring(cJSON* object, const char* valuestring);
|
||||
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \
|
||||
element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with
|
||||
* cJSON_InitHooks */
|
||||
/* malloc/free objects using the malloc/free functions that have been set
|
||||
* with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void*) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void* object);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -112,6 +112,6 @@ __exit:
|
||||
|
||||
void _pika_lua___del__(PikaObj* self) {
|
||||
pika_debug("lua close!\r\n");
|
||||
lua_close(g_pika_L); // 关闭 Lua 状态机,释放所有关联的资源
|
||||
lua_close(g_pika_L);
|
||||
g_pika_L = NULL;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "PikaPlatform_socket.h"
|
||||
#include "PikaPlatform_socket.h"
|
||||
/*
|
||||
The functinos start with PIKA_WEAK are weak functions,
|
||||
you need to override them in your platform.
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "PikaObj.h"
|
||||
#include "PikaObj.h"
|
||||
#ifdef __linux__
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "PikaPlatform_socket.h"
|
||||
#include "PikaPlatform_socket.h"
|
||||
#include "_socket_socket.h"
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 12, 0)
|
||||
|
@ -7,25 +7,24 @@
|
||||
* Copyright (c) 2014 Paul Sokolovsky
|
||||
* Copyright (c) 2023 Lyon
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "_struct.h"
|
||||
#include "pika_adapter_mpy.h"
|
||||
|
||||
|
@ -42,8 +42,6 @@ void _time_platformGetTick(PikaObj* self) {
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
|
||||
// 结构体时间类型定义(来源c标准库corect_wtime.h)
|
||||
// 无论是16位整数还是32位整数都满足需求
|
||||
typedef struct _tm {
|
||||
int tm_sec; // seconds after the minute - [0, 60] including leap second
|
||||
int tm_min; // minutes after the hour - [0, 59]
|
||||
@ -56,16 +54,11 @@ typedef struct _tm {
|
||||
int tm_isdst; // daylight savings time flag
|
||||
} _tm;
|
||||
|
||||
// 时间戳时间类型定义(来源c标准库time.h)
|
||||
// 直接支持64位秒数时间,附加时间精度为ns,根据设备决定,需要1GHz及以上时钟频率才能支持1ns级别时间精度
|
||||
// 内部时间比对数据类型,传递给外界的时候会使用浮点数,所以精度会降低
|
||||
// 但内部使用复合数据类型比对,以实现平台支持的最小时间精度比较
|
||||
typedef struct {
|
||||
int64_t tv_sec; // Seconds - >= 0
|
||||
int32_t tv_nsec; // Nanoseconds - [0, 999999999]
|
||||
} _timespec;
|
||||
|
||||
// 错误处理
|
||||
typedef int status;
|
||||
|
||||
#define TIME_OK 0
|
||||
@ -77,9 +70,7 @@ typedef int status;
|
||||
#define TIME_LESS_THAN_1970 5
|
||||
#define TIME_ERROR_STRUCT_TIME 6
|
||||
|
||||
// 错误状态处理函数
|
||||
void status_deal(status s) {
|
||||
// 输出异常信息
|
||||
#define time_printf(...) __platform_printf(__VA_ARGS__)
|
||||
|
||||
time_printf("\n[Error-info]Checking a exception : ");
|
||||
@ -111,59 +102,46 @@ void status_deal(status s) {
|
||||
time_printf("\n");
|
||||
}
|
||||
|
||||
// 获取硬件平台的Unix时间戳,时间精度为1s级别,
|
||||
status time_get_unix_time(PikaObj* self, _timespec* this_timespec) {
|
||||
this_timespec->tv_sec = (int64_t)(obj_getInt(self, "tick") / 1000);
|
||||
return TIME_OK;
|
||||
}
|
||||
|
||||
// 获取硬件平台的Tick时间,时间精度为1s级别以下
|
||||
// 即1s的小数部分
|
||||
status time_get_tick_ns(PikaObj* self, _timespec* this_timespec) {
|
||||
this_timespec->tv_nsec = (obj_getInt(self, "tick") % 1000) * 1000000;
|
||||
return TIME_OK;
|
||||
}
|
||||
|
||||
// 标准time()方法,返回以浮点数表示的从 epoch 开始的秒数的时间值。
|
||||
// epoch 是 1970 年 1 月 1 日 00:00:00 (UTC),
|
||||
pika_float time_time(PikaObj* self) {
|
||||
status res = 0; // 状态响应
|
||||
status res = 0;
|
||||
_timespec temp_timespec = {0};
|
||||
// 调用硬件平台函数,获取当前时间
|
||||
res = time_get_unix_time(self, &temp_timespec);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
} // 异常处理
|
||||
}
|
||||
res = time_get_tick_ns(self, &temp_timespec);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
} // 异常处理
|
||||
// 以浮点数返回时间,float
|
||||
}
|
||||
return temp_timespec.tv_sec +
|
||||
(pika_float)temp_timespec.tv_nsec / 1000000000;
|
||||
}
|
||||
|
||||
// 标准time_ns()方法,返回以整数表示的从 epoch 开始的纳秒数的时间值。
|
||||
// epoch 是 1970 年 1 月 1 日 00:00:00 (UTC),
|
||||
int64_t time_time_ns(PikaObj* self) {
|
||||
status res = 0; // 状态响应
|
||||
status res = 0;
|
||||
_timespec temp_timespec = {0};
|
||||
// 调用硬件平台函数,获取当前时间
|
||||
res = time_get_unix_time(self, &temp_timespec);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
} // 异常处理
|
||||
}
|
||||
res = time_get_tick_ns(self, &temp_timespec);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
} // 异常处理
|
||||
// 以浮点数返回时间,float
|
||||
}
|
||||
return temp_timespec.tv_sec * 1000000000 + temp_timespec.tv_nsec;
|
||||
}
|
||||
|
||||
// 利用基姆拉尔森计算公式计算星期
|
||||
int time_get_week(const _tm* this_tm) {
|
||||
// 月份要+1
|
||||
int month = this_tm->tm_mon + 1;
|
||||
int year = this_tm->tm_year;
|
||||
int day = this_tm->tm_mday;
|
||||
@ -172,195 +150,131 @@ int time_get_week(const _tm* this_tm) {
|
||||
month += 12;
|
||||
year -= 1;
|
||||
w = day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 -
|
||||
year / 100 + year / 400 + 1; // 0~6,星期日 ~ 星期六
|
||||
year / 100 + year / 400 + 1; //
|
||||
w = w % 7;
|
||||
} else {
|
||||
w = day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 -
|
||||
year / 100 + year / 400 + 1; // 0~6,星期日 ~ 星期六
|
||||
year / 100 + year / 400 + 1; //
|
||||
w = w % 7;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
// 由Unix时间戳计算标准UTC时间
|
||||
status unix_time_to_utc_struct_time(_tm* this_tm, int64_t unix_time) {
|
||||
int32_t total_day;
|
||||
int32_t extra_second;
|
||||
int year_400, year_100, year_4, year_1;
|
||||
int february_offset, temp; // 二月偏移量,零时变量
|
||||
int february_offset, temp;
|
||||
|
||||
// 判断是否输入小于0的时间戳
|
||||
if (unix_time < 0) {
|
||||
// 暂不支持小于0的时间戳
|
||||
return TIME_LESS_THAN_ZERO;
|
||||
}
|
||||
|
||||
// Unix时间戳每天秒数是固定的 62*60*24
|
||||
#define DAY_SECOND (86400)
|
||||
|
||||
total_day = unix_time / DAY_SECOND;
|
||||
extra_second = unix_time - total_day * DAY_SECOND;
|
||||
|
||||
// 为了减少额外闰年判断,把时间往前推到1600年,即闰年最大的一次公倍数开始计算判断
|
||||
// 1970-1600 = 370 年 ,370/4 -(370/100-1)=90 个闰年
|
||||
// 1600 DAY_OFFSET 365*(1970-1600)+90 = 135140,7为修正天数
|
||||
#define YEAR_START (1600) // 初始年份
|
||||
#define DAY_OFFSET (135140) // 时间偏移量
|
||||
#define YEAR_START (1600)
|
||||
#define DAY_OFFSET (135140)
|
||||
|
||||
total_day += DAY_OFFSET;
|
||||
|
||||
// 从1600年到3200年有1600/4-(1600/100-1600/400)=388个闰年
|
||||
// 即 MAX_DAY 1600*365+388=584388 day
|
||||
#define MAX_DAY (584388) // 最大可判断时间天数
|
||||
#define MAX_DAY (584388)
|
||||
|
||||
if (total_day > MAX_DAY) {
|
||||
// 超过3200年的换算暂不支持
|
||||
return TIME_OVER_3200;
|
||||
} else {
|
||||
// 从1600年开始,天数都要多减一天,因为1600年是闰年
|
||||
// 但是由于日期不包含当天时间,即2月2号,实际是2月1号+时:分:秒
|
||||
// 所以算出来的日期要加上一天
|
||||
// 两者配合,无需加减
|
||||
|
||||
// 从400年,100年,4年逐渐缩小范围
|
||||
// 400个公历年天数为365*400+97=146097天
|
||||
// 400年内的100个公历年天数为365*100+24=36524天
|
||||
// 100年内的4年365*4+1=1461天
|
||||
#define DAY_OF_400Y (146097)
|
||||
#define DAY_OF_100Y (36524)
|
||||
#define DAY_OF_4Y (1461)
|
||||
#define DAY_OF_1Y (365)
|
||||
// 400年也要注意,要实际401年才可
|
||||
year_400 = (total_day - 366) / DAY_OF_400Y;
|
||||
total_day -= year_400 * DAY_OF_400Y;
|
||||
// 计算400年内的情况
|
||||
year_100 = (total_day - 1) / DAY_OF_100Y;
|
||||
total_day -= year_100 * DAY_OF_100Y;
|
||||
// 计算100年内的情况,要到第二年的第一天才算,即365+1
|
||||
year_4 = (total_day - 366) / DAY_OF_4Y;
|
||||
// 计算4年,需要格外注意0-5-8年,才会计算一个闰年,因为它才包含了4这个闰年,但并不包含8
|
||||
total_day -= year_4 * DAY_OF_4Y;
|
||||
// 计算4年内的情况
|
||||
// 需要减去1天,因为当天是不存在的
|
||||
// 需要注意闰年会多一天
|
||||
// 所有闰年都放在这里来考虑,即只要当前是闰年,那么这里就会剩下第一年闰年和第四年闰年两种情况
|
||||
if (year_100 == 4) {
|
||||
// 第一年是闰年,此时为400*n+1年内
|
||||
year_1 = 0;
|
||||
february_offset = 1;
|
||||
} else if (total_day <= DAY_OF_1Y * 4) {
|
||||
// 100*n+(4,8,...96)+1年,都是从第二年算起,非闰年
|
||||
// 非闰年,需要减去1天,因为当天是不存在的
|
||||
year_1 = (total_day - 1) / DAY_OF_1Y;
|
||||
total_day -= year_1 * DAY_OF_1Y;
|
||||
february_offset = 0;
|
||||
} else {
|
||||
// 第四年是闰年
|
||||
year_1 = 4;
|
||||
total_day -= year_1 * DAY_OF_1Y;
|
||||
february_offset = 1;
|
||||
}
|
||||
|
||||
// 计算出当前年份
|
||||
this_tm->tm_year =
|
||||
(year_400 * 400 + year_100 * 100 + year_4 * 4 + year_1) +
|
||||
YEAR_START;
|
||||
// 保存一年的天数
|
||||
this_tm->tm_yday = total_day;
|
||||
|
||||
// 剩下的天数为1年内的天数,直接计算月和日
|
||||
// 根据当前是否为闰年设置二月偏移量是否为1
|
||||
// 能被4整除且不被100整除或者能被400整除
|
||||
|
||||
// 闰年需要减去一天再计算
|
||||
total_day -= february_offset;
|
||||
// 使用二分法快速定位月份,使用平年计算,在月份确定到2月时,再考虑闰年
|
||||
// 判断是否在1-6月里面
|
||||
// 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
if (total_day <= 181) {
|
||||
// 判断是否在1-3月里面
|
||||
if (total_day <= 90) {
|
||||
// 判断是否在1-2月里面
|
||||
if (total_day <= 59) {
|
||||
total_day += february_offset; // 去掉二月的偏置
|
||||
total_day += february_offset;
|
||||
if (total_day <= 31) {
|
||||
// 1月
|
||||
temp = 0;
|
||||
} else {
|
||||
total_day -= 31;
|
||||
// 2月
|
||||
temp = 1;
|
||||
}
|
||||
} else {
|
||||
total_day -= 59;
|
||||
// 3月
|
||||
temp = 2;
|
||||
}
|
||||
} else {
|
||||
// 4-6月
|
||||
total_day -= 90;
|
||||
// 是否在4月里面
|
||||
if (total_day <= 30) {
|
||||
// 4月
|
||||
temp = 3;
|
||||
} else {
|
||||
// 5-6月
|
||||
total_day -= 30;
|
||||
if (total_day <= 31) {
|
||||
// 5月
|
||||
temp = 4;
|
||||
} else {
|
||||
total_day -= 31;
|
||||
// 6月
|
||||
temp = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
total_day -= 181;
|
||||
// 判断是否在7-9月里面
|
||||
if (total_day <= 92) {
|
||||
// 是否在7-8月
|
||||
if (total_day <= 62) {
|
||||
if (total_day <= 31) {
|
||||
// 7月
|
||||
temp = 6;
|
||||
} else {
|
||||
total_day -= 31;
|
||||
// 8月
|
||||
temp = 7;
|
||||
}
|
||||
} else {
|
||||
// 9月
|
||||
total_day -= 62;
|
||||
temp = 8;
|
||||
}
|
||||
} else {
|
||||
// 10-12月
|
||||
total_day -= 92;
|
||||
// 是否在10-11月
|
||||
if (total_day <= 61) {
|
||||
if (total_day <= 31) {
|
||||
// 10月
|
||||
temp = 9;
|
||||
} else {
|
||||
// 11 月
|
||||
total_day -= 31;
|
||||
temp = 10;
|
||||
}
|
||||
} else {
|
||||
// 12月
|
||||
total_day -= 61;
|
||||
temp = 11;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 记录当前月份和天数
|
||||
this_tm->tm_mon = temp; // 月份 [0,11]
|
||||
this_tm->tm_mday = total_day; // 天数
|
||||
this_tm->tm_mon = temp;
|
||||
this_tm->tm_mday = total_day;
|
||||
|
||||
// 利用额外秒数计算时-分-秒
|
||||
temp = extra_second / 3600;
|
||||
this_tm->tm_hour = temp;
|
||||
extra_second = extra_second - temp * 3600;
|
||||
@ -371,70 +285,47 @@ status unix_time_to_utc_struct_time(_tm* this_tm, int64_t unix_time) {
|
||||
|
||||
this_tm->tm_sec = extra_second;
|
||||
|
||||
// 计算出当前日期的星期数
|
||||
this_tm->tm_wday = time_get_week(this_tm);
|
||||
|
||||
// 夏令时不明
|
||||
this_tm->tm_isdst = -1;
|
||||
}
|
||||
return TIME_OK;
|
||||
}
|
||||
|
||||
// 由标准UTC时间生成Unix时间戳
|
||||
status utc_struct_time_to_unix_time(const _tm* this_tm, int64_t* unix_time) {
|
||||
int32_t total_day, total_leap_year, dyear;
|
||||
int february_offset; // 二月偏移量,零时变量
|
||||
int february_offset;
|
||||
// 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
// 每个月份对应前面所有月的天数
|
||||
const int month_day[] = {0, 31, 59, 90, 120, 151,
|
||||
181, 212, 243, 273, 304, 334};
|
||||
|
||||
// 每天总秒数一定,将UTC时间(年月)转换成天数
|
||||
// 为了减少额外闰年判断,把时间往前推到1600年,即闰年最大的一次公倍数开始计算判断
|
||||
// 1970-1600 = 370 年 ,370/4 -(370/100-1)=90 个闰年
|
||||
// 1600 DAY_OFFSET 365*(1970-1600)+90 = 135140,7为修正天数
|
||||
|
||||
if (this_tm->tm_year < 1970) {
|
||||
// 暂不支持1970之前的时间
|
||||
*unix_time = 0;
|
||||
return TIME_LESS_THAN_1970;
|
||||
}
|
||||
if (this_tm->tm_year >= 3200) {
|
||||
// 暂不支持3200及以后的时间
|
||||
*unix_time = 0;
|
||||
return TIME_OVER_3200;
|
||||
}
|
||||
|
||||
// 计算总年数要去掉尾巴,如年数20年,那么实际应该4个闰年,因为20这一年没有包含在里面
|
||||
// 要减去一年来算闰年次数
|
||||
// 先计算到相对1600年的天数,再转换到1970年
|
||||
dyear = this_tm->tm_year - YEAR_START - 1;
|
||||
total_leap_year = dyear / 4 - (dyear / 100 - dyear / 400 - 1);
|
||||
// 恢复减去的一年
|
||||
dyear += 1;
|
||||
total_day = dyear * 365 + total_leap_year;
|
||||
|
||||
// 减去1970到1600的总天数
|
||||
total_day -= DAY_OFFSET;
|
||||
|
||||
// 增加月和日的总天数
|
||||
// 判断是否是闰年
|
||||
// 能被4整除且不被100整除或者能被400整除
|
||||
if (((dyear % 4 == 0) && (dyear % 100 != 0)) || (dyear % 400 == 0)) {
|
||||
// 闰年
|
||||
february_offset = 1;
|
||||
} else {
|
||||
february_offset = 0;
|
||||
}
|
||||
|
||||
// 计算含月和日的总天数,日期要减去当天
|
||||
total_day += month_day[this_tm->tm_mon] + this_tm->tm_mday - 1;
|
||||
// 二月以上需要加上偏移量
|
||||
if (this_tm->tm_mon > 1) {
|
||||
total_day += february_offset;
|
||||
}
|
||||
|
||||
// 根据天数以及时分秒计算Unix时间戳
|
||||
*unix_time = (int64_t)total_day * DAY_SECOND + this_tm->tm_hour * 3600 +
|
||||
this_tm->tm_min * 60 + this_tm->tm_sec;
|
||||
|
||||
@ -450,41 +341,30 @@ void time_struct_format(const _tm* this_tm, char* str) {
|
||||
this_tm->tm_wday, this_tm->tm_yday, this_tm->tm_isdst);
|
||||
}
|
||||
|
||||
// 标准库函数gmtime,将以自 epoch 开始的秒数表示的时间转换为 UTC 的 struct_time
|
||||
void time_gmtime(pika_float unix_time, _tm* this_tm) {
|
||||
status res;
|
||||
// 转化时间
|
||||
res = unix_time_to_utc_struct_time(this_tm, (int64_t)unix_time);
|
||||
if (res) {
|
||||
status_deal(res); // 异常情况处理
|
||||
// 返回默认值
|
||||
// note: 异常情况返回默认时间起始点
|
||||
status_deal(res);
|
||||
unix_time_to_utc_struct_time(this_tm, (int64_t)0);
|
||||
}
|
||||
}
|
||||
|
||||
// 标准库函数localtime,将以自 epoch 开始的秒数表示的时间转换为当地时间的
|
||||
// struct_time
|
||||
void time_localtime(pika_float unix_time, _tm* this_tm, int locale) {
|
||||
status res;
|
||||
int local_offset;
|
||||
|
||||
// 获取本地时间偏移量(小时)
|
||||
local_offset = locale * 60 * 60;
|
||||
|
||||
// 转化时间
|
||||
res = unix_time_to_utc_struct_time(this_tm,
|
||||
(int64_t)unix_time + local_offset);
|
||||
if (res) {
|
||||
status_deal(res); // 异常情况处理
|
||||
// 这里处理的策略和标准库不同,标准库最初始的时间是1970-1-1,00:00:00,对于不同时区来说,其值是不一样的
|
||||
// 但本函数是要求各时区的起始时间不超过1970-1-1,00:00:00,实际上UTC时间可以更前,可靠的最早时间可到1600年
|
||||
// 对于西时区来说,时间会缺失
|
||||
status_deal(res);
|
||||
unix_time_to_utc_struct_time(this_tm, (int64_t)0);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测结构体时间是否在合适的范围内,但不检查它的正确性
|
||||
status time_check_struct_time(const _tm* this_tm) {
|
||||
if (this_tm->tm_sec < 0 || this_tm->tm_sec > 60) {
|
||||
return TIME_ERROR_STRUCT_TIME;
|
||||
@ -510,47 +390,33 @@ status time_check_struct_time(const _tm* this_tm) {
|
||||
return TIME_OK;
|
||||
}
|
||||
|
||||
// 标准库函数mktime(t),将当地时间的
|
||||
// struct_time转换为以自epoch开始的秒数表示的时间
|
||||
int64_t time_mktime(const _tm* this_tm, int locale) {
|
||||
status res;
|
||||
int local_offset;
|
||||
int64_t unix_time;
|
||||
|
||||
// 获取本地时间偏移量(小时)
|
||||
local_offset = locale * 60 * 60;
|
||||
|
||||
// 检测时间结构体范围正确性
|
||||
res = time_check_struct_time(this_tm);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
return 0;
|
||||
} // 异常情况返回时间零点
|
||||
}
|
||||
|
||||
// 转化时间
|
||||
res = utc_struct_time_to_unix_time(this_tm, &unix_time);
|
||||
if (res) {
|
||||
status_deal(res);
|
||||
return 0;
|
||||
} // 异常情况返回时间零点
|
||||
// 减去本地偏移时间
|
||||
// 可能出现负数,严格来说,这不影响什么!
|
||||
}
|
||||
unix_time -= local_offset;
|
||||
|
||||
// 显示出来
|
||||
// time_printf("%I64d\n",unix_time);
|
||||
|
||||
// 返回数据
|
||||
return unix_time;
|
||||
}
|
||||
|
||||
// 标准库函数asctime()
|
||||
// 把结构化时间struct_time元组表示为以下形式的字符串: `'Sun Jun 20 23:21:05
|
||||
// 1993'`。
|
||||
void time_asctime(const _tm* this_tm) {
|
||||
// 星期缩写,python标准库是三个字母,这里并不相同
|
||||
const char* week[] = {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
|
||||
// 月份缩写
|
||||
const char* month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
|
||||
|
||||
@ -616,9 +482,7 @@ void _time_gmtime(PikaObj* self, pika_float unix_time) {
|
||||
char str[200];
|
||||
time_gmtime(unix_time, &this_tm);
|
||||
time_set_tm_value(self, &this_tm);
|
||||
// 格式化字符
|
||||
time_struct_format(&this_tm, str);
|
||||
// 显示出来
|
||||
time_printf("%s\n", str);
|
||||
#endif
|
||||
}
|
||||
@ -634,9 +498,7 @@ void _time_localtime(PikaObj* self, pika_float unix_time) {
|
||||
int locale = g_pika_local_timezone;
|
||||
time_localtime(unix_time, &this_tm, locale);
|
||||
time_set_tm_value(self, &this_tm);
|
||||
// 格式化字符
|
||||
time_struct_format(&this_tm, str);
|
||||
// 显示出来
|
||||
time_printf("%s\n", str);
|
||||
#endif
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "fastlz.h"
|
||||
#include "PikaObj.h"
|
||||
#include <stdint.h>
|
||||
|
@ -20,7 +20,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef FASTLZ_H
|
||||
#define FASTLZ_H
|
||||
|
||||
@ -87,8 +86,8 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
This is similar to fastlz_compress_level above, but with the level
|
||||
automatically chosen.
|
||||
|
||||
This function is deprecated and it will be completely removed in some future
|
||||
version.
|
||||
This function is deprecated and it will be completely removed in some
|
||||
future version.
|
||||
*/
|
||||
|
||||
int fastlz_compress(const void* input, int length, void* output);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
|
||||
TEST(PikaCV, test1) {
|
||||
/* init */
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
|
||||
|
||||
TEST(PikaNN, test1) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_SYNTAX_SLICE_ENABLE
|
||||
TEST(ctypes, test1) {
|
||||
/* init */
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if !PIKA_NANO_ENABLE
|
||||
TEST_RUN_SINGLE_FILE_PASS(json, loads, "test/python/json/json_loads.py")
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_POOL_ENABLE
|
||||
TEST(bitmap, init) {
|
||||
uint8_t* bitmap = bitmap_init(10);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
|
||||
TEST(module, cmodule_import) {
|
||||
/* init */
|
||||
|
@ -3,8 +3,8 @@
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 21:53:07
|
||||
* @LastEditTime: 2020-06-08 20:38:41
|
||||
* @Description: the code belongs to jiejie, please keep the author information
|
||||
* and source code according to the license.
|
||||
* @Description: the code belongs to jiejie, please keep the author
|
||||
* information and source code according to the license.
|
||||
*/
|
||||
#include "test_common.h"
|
||||
extern "C" {
|
||||
@ -46,12 +46,14 @@ static const char* test_baidu_ca_crt = {
|
||||
static void topic1_handler(void* client, message_data_t* msg) {
|
||||
(void)client;
|
||||
MQTT_LOG_I(
|
||||
"----------------------------------------------------------------------"
|
||||
"------------------------------------------------------------------"
|
||||
"----"
|
||||
"-------------");
|
||||
MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__,
|
||||
__FUNCTION__, msg->topic_name, (char*)msg->message->payload);
|
||||
MQTT_LOG_I(
|
||||
"----------------------------------------------------------------------"
|
||||
"------------------------------------------------------------------"
|
||||
"----"
|
||||
"-------------");
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#include "PikaCompiler.h"
|
||||
// TEST(packtool, unpack) {
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_GC_MARK_SWEEP_ENABLE
|
||||
|
||||
TEST(pikaui, page) {
|
||||
|
@ -4,89 +4,406 @@ TEST_START
|
||||
#if !PIKA_NANO_ENABLE
|
||||
TEST_RUN_SINGLE_FILE(thread, test2, "test/python/_thread/test2.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, test1, "test/python/eventloop/test1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, test2, "test/python/eventloop/test2.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop,
|
||||
test2,
|
||||
"test/python/"
|
||||
"eventloop/"
|
||||
"test2.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, test3, "test/python/eventloop/test3.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, delay1, "test/python/eventloop/delay1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, once1, "test/python/eventloop/once1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop, once2, "test/python/eventloop/once2.py")
|
||||
TEST_RUN_SINGLE_FILE(fsm, test1, "test/python/fsm/test1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop,
|
||||
once1,
|
||||
"test/"
|
||||
"python/"
|
||||
"eventloop/"
|
||||
"once1.py")
|
||||
TEST_RUN_SINGLE_FILE(eventloop,
|
||||
once2,
|
||||
"test/python/eventloop/"
|
||||
"once2.py")
|
||||
TEST_RUN_SINGLE_FILE(fsm,
|
||||
test1,
|
||||
"test/"
|
||||
"python/"
|
||||
"fsm/"
|
||||
"test1."
|
||||
"py")
|
||||
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
list_tuple_equ,
|
||||
"test/python/builtins/list_tuple_equ.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
fn_default1,
|
||||
"test/python/builtins/fn_default1.py")
|
||||
"te"
|
||||
"st"
|
||||
"/p"
|
||||
"yt"
|
||||
"ho"
|
||||
"n/"
|
||||
"bu"
|
||||
"il"
|
||||
"ti"
|
||||
"ns"
|
||||
"/f"
|
||||
"n_"
|
||||
"de"
|
||||
"fa"
|
||||
"ul"
|
||||
"t1"
|
||||
".p"
|
||||
"y")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
fn_default_tuple,
|
||||
"test/python/builtins/fn_default_tuple.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin, max_min, "test/python/builtins/max_min.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin, split, "test/python/builtins/split.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
max_min,
|
||||
"test"
|
||||
"/pyt"
|
||||
"hon/"
|
||||
"buil"
|
||||
"tins"
|
||||
"/max"
|
||||
"_min"
|
||||
".py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
split,
|
||||
"test/"
|
||||
"python/"
|
||||
"builtins/"
|
||||
"split.py")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
|
||||
split_slice,
|
||||
"'test'.split('e')[0]",
|
||||
"'t'\r\n")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
|
||||
split_slice_1,
|
||||
"'test'.split('e')[1]",
|
||||
"'st'\r\n")
|
||||
"'test'"
|
||||
".split"
|
||||
"('e')["
|
||||
"1]",
|
||||
"'st'"
|
||||
"\r\n")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
|
||||
replace_split_0,
|
||||
"'a b c d'.replace(' ', ',').split(',')[0]",
|
||||
"'a b c "
|
||||
"d'.replace(' ', "
|
||||
"',').split(',')["
|
||||
"0]",
|
||||
"'a'\r\n")
|
||||
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin,
|
||||
class_script,
|
||||
"test/python/builtins/class_script.py",
|
||||
"Obj1.test\r\n")
|
||||
"test"
|
||||
"/pyt"
|
||||
"hon/"
|
||||
"buil"
|
||||
"tins"
|
||||
"/cla"
|
||||
"ss_"
|
||||
"scri"
|
||||
"pt."
|
||||
"py",
|
||||
"Obj1"
|
||||
".tes"
|
||||
"t\r"
|
||||
"\n")
|
||||
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin,
|
||||
class_hint,
|
||||
"test/python/builtins/class_hint.py",
|
||||
"test/"
|
||||
"python/"
|
||||
"builtins/"
|
||||
"class_"
|
||||
"hint.py",
|
||||
"1\r\n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
isinstance,
|
||||
"test/python/builtins/isinstance.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin, getitem, "test/python/builtins/getitem.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(lua, eval, "test/python/pika_lua/eval.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(lua, require, "test/python/pika_lua/require.py")
|
||||
"tes"
|
||||
"t/"
|
||||
"pyt"
|
||||
"hon"
|
||||
"/bu"
|
||||
"ilt"
|
||||
"ins"
|
||||
"/is"
|
||||
"ins"
|
||||
"tan"
|
||||
"ce."
|
||||
"py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(builtin,
|
||||
getitem,
|
||||
"test/python/"
|
||||
"builtins/"
|
||||
"getitem.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(lua,
|
||||
eval,
|
||||
"te"
|
||||
"st"
|
||||
"/p"
|
||||
"yt"
|
||||
"ho"
|
||||
"n/"
|
||||
"pi"
|
||||
"ka"
|
||||
"_l"
|
||||
"ua"
|
||||
"/e"
|
||||
"va"
|
||||
"l."
|
||||
"p"
|
||||
"y")
|
||||
TEST_RUN_SINGLE_FILE_PASS(lua,
|
||||
require,
|
||||
"test/python/"
|
||||
"pika_lua/"
|
||||
"require.py")
|
||||
|
||||
TEST_RUN_LINES(vm, dot_issue, ".")
|
||||
TEST_RUN_LINES(vm, char_issue1, "~")
|
||||
TEST_RUN_LINES(vm, char_issue2, "/")
|
||||
TEST_RUN_LINES(vm, char_issue3, "%")
|
||||
TEST_RUN_LINES(vm, char_issue4, "=")
|
||||
TEST_RUN_SINGLE_FILE(vm,
|
||||
issue_star_dict,
|
||||
"test/python/issue/issue_star_dict.py")
|
||||
TEST_RUN_SINGLE_FILE_PASS(vm, proxy2, "test/python/proxy/proxy2.py")
|
||||
TEST_RUN_LINES(vm, abs_none, "abs(None)")
|
||||
TEST_RUN_LINES(vm, abs_str, "abs('test')")
|
||||
TEST_RUN_SINGLE_FILE_PASS(datastruct,
|
||||
circlequeue,
|
||||
"test/python/datastruct/circlequeue.py")
|
||||
TEST_RUN_LINES(vm, char_issue2, "/") TEST_RUN_LINES(vm, char_issue3, "%")
|
||||
TEST_RUN_LINES(vm, char_issue4, "=") TEST_RUN_SINGLE_FILE(
|
||||
vm,
|
||||
issue_star_dict,
|
||||
"test/"
|
||||
"python/"
|
||||
"issue/"
|
||||
"issue_"
|
||||
"star_"
|
||||
"dict.py") TEST_RUN_SINGLE_FILE_PASS(vm,
|
||||
proxy2,
|
||||
"t"
|
||||
"e"
|
||||
"s"
|
||||
"t"
|
||||
"/"
|
||||
"p"
|
||||
"y"
|
||||
"t"
|
||||
"h"
|
||||
"o"
|
||||
"n"
|
||||
"/"
|
||||
"p"
|
||||
"r"
|
||||
"o"
|
||||
"x"
|
||||
"y"
|
||||
"/"
|
||||
"p"
|
||||
"r"
|
||||
"o"
|
||||
"x"
|
||||
"y"
|
||||
"2"
|
||||
"."
|
||||
"p"
|
||||
"y") TEST_RUN_LINES(vm,
|
||||
abs_none,
|
||||
"ab"
|
||||
"s("
|
||||
"No"
|
||||
"ne"
|
||||
")")
|
||||
TEST_RUN_LINES(vm,
|
||||
abs_str,
|
||||
"ab"
|
||||
"s("
|
||||
"'t"
|
||||
"es"
|
||||
"t'"
|
||||
")") TEST_RUN_SINGLE_FILE_PASS(datastruct,
|
||||
circlequeue,
|
||||
"test/python/datastruct/"
|
||||
"circlequeue.py")
|
||||
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(vm, single_tuple, "(1,)", "(1,)\r\n")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(vm, single_tuple_str, "('test',)", "('test',)\r\n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(vm, is_not, "test/python/builtins/is_not.py")
|
||||
TEST_RUN_LINES(vm,
|
||||
var_global,
|
||||
"import PikaStdLib\n"
|
||||
"mem = PikaStdLib.MemChecker()\n"
|
||||
"mem.clear\n")
|
||||
TEST_RUN_LINES(vm,
|
||||
var_global_run,
|
||||
"import PikaStdLib\n"
|
||||
"mem = PikaStdLib.MemChecker()\n"
|
||||
"mem.clear()\n")
|
||||
TEST_RUN_LINES(vm,
|
||||
var_global_module,
|
||||
"import configparser\n"
|
||||
"configparser.clear\n")
|
||||
TEST_RUN_LINES(vm, import_void, "import \n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(vm, fn_fn, "test/python/builtins/fn_fn.py")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(vm, isinstance, "isinstance(1, int)\n", "True\r\n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(except,
|
||||
try_while_return,
|
||||
"test/python/except/try_while_return.py");
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(vm, single_tuple, "(1,)", "(1,)\r\n")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(
|
||||
vm,
|
||||
single_tuple_str,
|
||||
"('test',)",
|
||||
"('test',)"
|
||||
"\r\n") TEST_RUN_SINGLE_FILE_PASS(vm,
|
||||
is_not,
|
||||
"test"
|
||||
"/pyt"
|
||||
"hon/"
|
||||
"buil"
|
||||
"tins"
|
||||
"/"
|
||||
"is_"
|
||||
"not."
|
||||
"py")
|
||||
TEST_RUN_LINES(vm,
|
||||
var_global,
|
||||
"im"
|
||||
"po"
|
||||
"rt"
|
||||
" P"
|
||||
"ik"
|
||||
"aS"
|
||||
"td"
|
||||
"Li"
|
||||
"b"
|
||||
"\n"
|
||||
"me"
|
||||
"m "
|
||||
"= "
|
||||
"Pi"
|
||||
"ka"
|
||||
"St"
|
||||
"dL"
|
||||
"ib"
|
||||
"."
|
||||
"Me"
|
||||
"mC"
|
||||
"he"
|
||||
"ck"
|
||||
"er"
|
||||
"()"
|
||||
"\n"
|
||||
"me"
|
||||
"m."
|
||||
"cl"
|
||||
"ea"
|
||||
"r"
|
||||
"\n") TEST_RUN_LINES(vm,
|
||||
var_global_run,
|
||||
"i"
|
||||
"m"
|
||||
"p"
|
||||
"o"
|
||||
"r"
|
||||
"t"
|
||||
" "
|
||||
"P"
|
||||
"i"
|
||||
"k"
|
||||
"a"
|
||||
"S"
|
||||
"t"
|
||||
"d"
|
||||
"L"
|
||||
"i"
|
||||
"b"
|
||||
"\n"
|
||||
"m"
|
||||
"e"
|
||||
"m"
|
||||
" "
|
||||
"="
|
||||
" "
|
||||
"P"
|
||||
"i"
|
||||
"k"
|
||||
"a"
|
||||
"S"
|
||||
"t"
|
||||
"d"
|
||||
"L"
|
||||
"i"
|
||||
"b"
|
||||
"."
|
||||
"M"
|
||||
"e"
|
||||
"m"
|
||||
"C"
|
||||
"h"
|
||||
"e"
|
||||
"c"
|
||||
"k"
|
||||
"e"
|
||||
"r"
|
||||
"("
|
||||
")"
|
||||
"\n"
|
||||
"m"
|
||||
"e"
|
||||
"m"
|
||||
"."
|
||||
"c"
|
||||
"l"
|
||||
"e"
|
||||
"a"
|
||||
"r"
|
||||
"("
|
||||
")"
|
||||
"\n")
|
||||
TEST_RUN_LINES(vm,
|
||||
var_global_module,
|
||||
"im"
|
||||
"po"
|
||||
"rt"
|
||||
" c"
|
||||
"on"
|
||||
"fi"
|
||||
"gp"
|
||||
"ar"
|
||||
"se"
|
||||
"r"
|
||||
"\n"
|
||||
"co"
|
||||
"nf"
|
||||
"ig"
|
||||
"pa"
|
||||
"rs"
|
||||
"er"
|
||||
".c"
|
||||
"le"
|
||||
"ar"
|
||||
"\n") TEST_RUN_LINES(vm,
|
||||
import_void,
|
||||
"i"
|
||||
"m"
|
||||
"p"
|
||||
"o"
|
||||
"r"
|
||||
"t"
|
||||
" "
|
||||
"\n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(vm,
|
||||
fn_fn,
|
||||
"test/"
|
||||
"python"
|
||||
"/built"
|
||||
"ins/"
|
||||
"fn_fn."
|
||||
"py")
|
||||
TEST_RUN_LINES_EXCEPT_OUTPUT(vm,
|
||||
isinstance,
|
||||
"is"
|
||||
"in"
|
||||
"st"
|
||||
"an"
|
||||
"ce"
|
||||
"(1"
|
||||
", "
|
||||
"in"
|
||||
"t)"
|
||||
"\n",
|
||||
"Tr"
|
||||
"ue"
|
||||
"\r"
|
||||
"\n")
|
||||
TEST_RUN_SINGLE_FILE_PASS(except,
|
||||
try_while_return,
|
||||
"te"
|
||||
"st"
|
||||
"/p"
|
||||
"yt"
|
||||
"ho"
|
||||
"n/"
|
||||
"ex"
|
||||
"ce"
|
||||
"pt"
|
||||
"/t"
|
||||
"ry"
|
||||
"_w"
|
||||
"hi"
|
||||
"le"
|
||||
"_r"
|
||||
"et"
|
||||
"ur"
|
||||
"n."
|
||||
"p"
|
||||
"y");
|
||||
TEST_RUN_SINGLE_FILE_PASS(except,
|
||||
isinstance,
|
||||
"test/python/except/except_isinstance.py");
|
||||
|
@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "../pikascript-lib/requests/webclient.h"
|
||||
|
||||
#define GET_HEADER_BUFSZ 1024
|
||||
@ -18,8 +17,8 @@ extern "C" {
|
||||
|
||||
#define GET_LOCAL_URI "http://www.rt-thread.com/service/rt-thread.txt"
|
||||
|
||||
/* send HTTP GET request by common request interface, it used to receive longer
|
||||
* data */
|
||||
/* send HTTP GET request by common request interface, it used to receive
|
||||
* longer data */
|
||||
static int webclient_get_comm(const char* uri) {
|
||||
struct webclient_session* session = RT_NULL;
|
||||
unsigned char* buffer = RT_NULL;
|
||||
@ -175,7 +174,8 @@ int webclient_get_test(int argc, char** argv) {
|
||||
} else {
|
||||
rt_kprintf("web_get_test [URI] - webclient GET request test.\n");
|
||||
rt_kprintf(
|
||||
"web_get_test -s [URI] - webclient simplify GET request test.\n");
|
||||
"web_get_test -s [URI] - webclient simplify GET request "
|
||||
"test.\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_SYNTAX_SLICE_ENABLE
|
||||
TEST(stddata, test1) {
|
||||
/* init */
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
|
||||
#if PIKA_SYNTAX_FORMAT_ENABLE
|
||||
TEST(string, cformat) {
|
||||
/* init */
|
||||
|
@ -4,25 +4,25 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "BaseObj.h"
|
||||
|
@ -4,27 +4,26 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -4,25 +4,25 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "PikaCompiler.h"
|
||||
#include "BaseObj.h"
|
||||
@ -311,8 +311,7 @@ int LibObj_staticLinkFile_New(LibObj* self, char* input_file_name, char* path) {
|
||||
pika_platform_printf("error: can't open file %s\r\n", input_file_name);
|
||||
return -1;
|
||||
}
|
||||
char* module_name = strsGetLastToken(
|
||||
&buffs, input_file_name, '/'); /*找到最后一个 / 出现的位置的下一个地址*/
|
||||
char* module_name = strsGetLastToken(&buffs, input_file_name, '/');
|
||||
|
||||
size_t module_name_len = strlen(module_name);
|
||||
|
||||
@ -437,10 +436,6 @@ static int32_t __foreach_handler_selectBlockSize(Arg* argEach,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 这里包括文件内容大小,文件信息所占的大小(文件名和文件大小)
|
||||
* 一个unit 的组成包括: Namelen(4 bytes)+ Name (strlen("namelen") + 1) \
|
||||
* + fileSize (4 bytes)
|
||||
*/
|
||||
static int32_t __foreach_handler_libSumSize(Arg* argEach, PikaLinker* linker) {
|
||||
if (arg_isObject(argEach)) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
@ -566,14 +561,10 @@ static PIKA_RES _loadModuleDataWithIndex(uint8_t* library_bytes,
|
||||
char** name_p,
|
||||
uint8_t** addr_p,
|
||||
size_t* size) {
|
||||
/*两个指针,一个指向文件信息部分,一个指向文件内容部分 */
|
||||
uint32_t block_size =
|
||||
*(uint32_t*)(library_bytes +
|
||||
4 * sizeof(uint32_t)); /* 每个文件信息大小的总和 */
|
||||
uint32_t block_size = *(uint32_t*)(library_bytes + 4 * sizeof(uint32_t));
|
||||
uint8_t* file_info_block_start = library_bytes + block_size;
|
||||
uint8_t* bytecode_ptr = file_info_block_start + block_size * module_num;
|
||||
uint8_t* bytecode_ptr_next = bytecode_ptr;
|
||||
/* 每一个模块的信息 */
|
||||
uint32_t module_size = 0;
|
||||
char* module_name = NULL;
|
||||
uintptr_t offset = 0;
|
||||
@ -624,8 +615,7 @@ PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
|
||||
size_t size = 0;
|
||||
_loadModuleDataWithIndex(library_bytes, module_num, i, &name, &addr,
|
||||
&size);
|
||||
name = strsGetLastToken(&buffs, name,
|
||||
'/'); /*找到最后一个 / 出现的位置的下一个地址*/
|
||||
name = strsGetLastToken(&buffs, name, '/');
|
||||
|
||||
if (strEqu(module_name, name)) {
|
||||
*addr_p = addr;
|
||||
@ -638,16 +628,6 @@ PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打开 .pack 文件,并返回Arg 对象,里面包含这个pack 文件的library_bytes
|
||||
*
|
||||
* @param
|
||||
* @param char* pack_name pack 文件的名字
|
||||
* @return Arg* arg, a pointer to an Arg object, which point to the
|
||||
* library_bytes of the pack file.
|
||||
* @note
|
||||
*
|
||||
*/
|
||||
Arg* _getPack_libraryBytes(char* pack_name) {
|
||||
if (NULL == pack_name) {
|
||||
pika_platform_printf(
|
||||
@ -728,7 +708,7 @@ int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
|
||||
*/
|
||||
PIKA_RES pikafs_unpack_files(char* pack_name, char* out_path) {
|
||||
PIKA_RES stat = PIKA_RES_OK;
|
||||
Arg* file_arg = NULL; /* file_arg 存在的意义就是获取文件的 library_bytes*/
|
||||
Arg* file_arg = NULL;
|
||||
uint8_t* library_bytes = NULL;
|
||||
pikafs_FILE* fptr = NULL;
|
||||
if (NULL == out_path) {
|
||||
@ -758,8 +738,7 @@ PIKA_RES pikafs_unpack_files(char* pack_name, char* out_path) {
|
||||
size = 0;
|
||||
stat = _loadModuleDataWithIndex(library_bytes, module_num, i, &name,
|
||||
&addr, &size);
|
||||
name = strsGetLastToken(&buffs, name,
|
||||
'/'); /*找到最后一个 / 出现的位置的下一个地址*/
|
||||
name = strsGetLastToken(&buffs, name, '/');
|
||||
output_file_path = strsPathJoin(&buffs, out_path, name);
|
||||
pika_platform_printf("output_file_path: %s\r\n", output_file_path);
|
||||
new_fp = pika_platform_fopen(output_file_path, "wb+");
|
||||
@ -1189,7 +1168,7 @@ PIKA_RES pikaMaker_linkRaw(PikaMaker* self, char* file_path) {
|
||||
PIKA_RES pikaMaker_linkRaw_New(PikaMaker* self,
|
||||
char* file_path,
|
||||
char* pack_path) {
|
||||
LibObj* lib = obj_getPtr(self, "lib"); /* self 下面的lib 对象 */
|
||||
LibObj* lib = obj_getPtr(self, "lib");
|
||||
PIKA_RES ret = LibObj_staticLinkFile_New(lib, file_path, pack_path);
|
||||
return ret;
|
||||
}
|
||||
@ -1203,22 +1182,22 @@ PIKA_RES pikaMaker_linkRaw_New(PikaMaker* self,
|
||||
pikafs_FILE* pikafs_fopen(char* file_name, char* mode) {
|
||||
pikafs_FILE* f = (pikafs_FILE*)pikaMalloc(sizeof(pikafs_FILE));
|
||||
if (NULL == f) {
|
||||
return NULL; // 避免空指针
|
||||
return NULL;
|
||||
}
|
||||
memset(f, 0, sizeof(pikafs_FILE));
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
|
||||
if (NULL == library_bytes) {
|
||||
goto __error; // 如果library_bytes为NULL,则跳转到__error
|
||||
goto __error;
|
||||
}
|
||||
if (PIKA_RES_OK !=
|
||||
_loadModuleDataWithName(library_bytes, file_name, &f->addr, &f->size)) {
|
||||
goto __error; // 如果_loadModuleDataWithName的结果不是PIKA_RES_OK,则跳转到__error
|
||||
goto __error;
|
||||
}
|
||||
return f;
|
||||
|
||||
__error:
|
||||
pikaFree(f, sizeof(pikafs_FILE)); // 释放内存
|
||||
pikaFree(f, sizeof(pikafs_FILE));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1249,8 +1228,7 @@ pikafs_FILE* pikafs_fopen_pack(char* pack_name, char* file_name) {
|
||||
}
|
||||
|
||||
f->farg = file_arg;
|
||||
// arg_deinit(file_arg); /* file_arg 被释放以后,library_bytes
|
||||
// 就是个野指针了 */
|
||||
// arg_deinit(file_arg); /* file_arg
|
||||
return f;
|
||||
|
||||
__exit:
|
||||
|
@ -4,26 +4,26 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "PikaObj.h"
|
||||
@ -677,8 +677,6 @@ PikaObj* newNormalObj(NewFun newObjFun) {
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||
// 函数set_disp_mode用于控制是否开启输入回显功能
|
||||
// 如果option为0,则关闭回显,为1则打开回显
|
||||
static int set_disp_mode(int fd, int option) {
|
||||
int err;
|
||||
struct termios term;
|
||||
@ -707,14 +705,14 @@ struct termios original_termios;
|
||||
static void enable_raw_mode(void) {
|
||||
struct termios raw;
|
||||
|
||||
tcgetattr(STDIN_FILENO, &original_termios); // 获取当前终端属性
|
||||
tcgetattr(STDIN_FILENO, &original_termios);
|
||||
raw = original_termios;
|
||||
raw.c_lflag &= ~(ECHO | ICANON); // 禁用回显和规范模式
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); // 设置终端属性
|
||||
raw.c_lflag &= ~(ECHO | ICANON);
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
|
||||
}
|
||||
|
||||
static void disable_raw_mode(void) {
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &original_termios); // 恢复原始终端属性
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &original_termios);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -743,10 +741,9 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
||||
mem_pool_init();
|
||||
#endif
|
||||
#ifdef __linux
|
||||
signal(SIGINT, signal_handler); // 捕获 SIGINT 信号(Ctrl+C)
|
||||
signal(SIGTERM, signal_handler); // 捕获 SIGTERM 信号
|
||||
signal(SIGHUP, signal_handler); // 捕获 SIGHUP 信号
|
||||
signal(SIGSEGV, signal_handler); // 捕获 SIGHUP 信号
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGHUP, signal_handler);
|
||||
signal(SIGSEGV, signal_handler);
|
||||
signal(SIGABRT, signal_handler);
|
||||
signal(SIGQUIT, signal_handler);
|
||||
signal(SIGTRAP, signal_handler);
|
||||
|
@ -4,26 +4,26 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
* Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
@ -434,8 +434,8 @@ Arg* obj_newObjInPackage(NewFun newObjFun);
|
||||
* arguments (of type Arg*) to it. */
|
||||
PikaObj* _pika_tuple_new(int num_args, ...);
|
||||
|
||||
/* A helper function to create a new list PikaObj and append the given arguments
|
||||
* (of type Arg*) to it. */
|
||||
/* A helper function to create a new list PikaObj and append the given
|
||||
* arguments (of type Arg*) to it. */
|
||||
PikaObj* _pika_list_new(int num_args, ...);
|
||||
PikaObj* _pika_dict_new(int num_args, ...);
|
||||
|
||||
@ -449,7 +449,8 @@ PikaObj* _pika_dict_new(int num_args, ...);
|
||||
#define objList_new(...) \
|
||||
_pika_list_new(sizeof((Arg*[]){__VA_ARGS__}) / sizeof(Arg*), __VA_ARGS__)
|
||||
|
||||
/* Macro to create a new dict PikaObj with the given arguments (of type Arg*).
|
||||
/* Macro to create a new dict PikaObj with the given arguments (of type
|
||||
* Arg*).
|
||||
*/
|
||||
|
||||
#define objDict_new(...) \
|
||||
|
@ -4,25 +4,25 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "PikaParser.h"
|
||||
|
@ -4,25 +4,25 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
/*
|
||||
* This file is part of the PikaPython project.
|
||||
* http://github.com/pikastech/pikapython
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "PikaPlatform.h"
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
/*
|
||||
* This file is part of the PikaPython project.
|
||||
* http://github.com/pikastech/pikapython
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -143,9 +143,8 @@ typedef enum {
|
||||
|
||||
/*
|
||||
[Note]:
|
||||
Create a pika_config.c to override the following weak functions to config
|
||||
PikaScript. [Example]:
|
||||
1.
|
||||
Create a pika_config.c to override the following weak functions to
|
||||
config PikaScript. [Example]: 1.
|
||||
https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32G030Booter/pika_config.c
|
||||
2.
|
||||
https://gitee.com/Lyon1998/pikascript/blob/master/package/pikaRTBooter/pika_config.c
|
||||
|
24
src/PikaVM.c
24
src/PikaVM.c
@ -4,25 +4,25 @@
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
|
||||
* Copyright (c) 2021 lyon liang6516@outlook.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "PikaVM.h"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user