浏览代码

update: 整理一波api文档

Wendal Chen 5 年之前
父节点
当前提交
ff5b1f7a76

+ 10 - 0
luat/include/luat_crypto.h

@@ -1,6 +1,16 @@
 
 #include "luat_base.h"
 
+#define LUAT_CRYPTO_AES_ECB 1
+#define LUAT_CRYPTO_AES_CBC 2
+#define LUAT_CRYPTO_AES_CTR 3
+#define LUAT_CRYPTO_AES_CFB 4
+#define LUAT_CRYPTO_AES_OFB 5
+
+#define LUAT_CRYPTO_AES_PAD_ZERO 1
+#define LUAT_CRYPTO_AES_PAD_5 2
+#define LUAT_CRYPTO_AES_PAD_7 3
+
 int luat_crypto_md5_simple(const char* str, size_t str_size, void* out_ptr);
 int luat_crypto_hmac_md5_simple(const char* str, size_t str_size, const char* mac, size_t mac_size, void* out_ptr);
 

+ 3 - 3
luat/modules/luat_lib_adc.c

@@ -10,7 +10,7 @@
 
 /**
 打开adc通道
-@function adc.open(id)
+@api adc.open(id)
 @int 通道id,与具体设备有关,通常从0开始
 @return boolean 打开结果
 @usage
@@ -32,7 +32,7 @@ static int l_adc_open(lua_State *L) {
 
 /**
 读取adc通道
-@function adc.read(id)
+@api adc.read(id)
 @int 通道id,与具体设备有关,通常从0开始
 @return int 原始值
 @return int 计算后的值
@@ -59,7 +59,7 @@ static int l_adc_read(lua_State *L) {
 
 /**
 关闭adc通道
-@function adc.close(id)
+@api adc.close(id)
 @usage
 -- 打开adc通道2,并读取
 if adc.open(2) then

+ 21 - 4
luat/modules/luat_lib_crypto.c

@@ -20,7 +20,7 @@ static void fixhex(const char* source, char* dst, size_t len) {
 
 /**
 计算md5值
-@function crypto.md5(str)
+@api crypto.md5(str)
 @string 需要计算的字符串
 @return string 计算得出的md5值的hex字符串
 @usage
@@ -42,7 +42,7 @@ static int l_crypto_md5(lua_State *L) {
 
 /**
 计算hmac_md5值
-@function crypto.hmac_md5(str, key)
+@api crypto.hmac_md5(str, key)
 @string 需要计算的字符串
 @string 密钥
 @return string 计算得出的hmac_md5值的hex字符串
@@ -67,7 +67,7 @@ static int l_crypto_hmac_md5(lua_State *L) {
 
 /**
 计算sha1值
-@function crypto.sha1(str)
+@api crypto.sha1(str)
 @string 需要计算的字符串
 @return string 计算得出的sha1值的hex字符串
 @usage
@@ -89,7 +89,7 @@ static int l_crypto_sha1(lua_State *L) {
 
 /**
 计算hmac_sha1值
-@function crypto.hmac_sha1(str, key)
+@api crypto.hmac_sha1(str, key)
 @string 需要计算的字符串
 @string 密钥
 @return string 计算得出的hmac_sha1值的hex字符串
@@ -112,6 +112,21 @@ static int l_crypto_hmac_sha1(lua_State *L) {
     return 0;
 }
 
+static int aes_encrypt(lua_State *L) {
+    size_t mode_size = 0;
+    size_t pad_size = 0;
+    size_t str_size = 0;
+    size_t key_size = 0;
+    const char* mode = luaL_checklstring(L, 1, &mode_size);
+    const char* pad = luaL_checklstring(L, 2, &pad_size);
+    const char* str = luaL_checklstring(L, 3, &str_size);
+    const char* key = luaL_checklstring(L, 4, &key_size);
+    
+
+
+    return 0;
+}
+
 #include "rotable.h"
 static const rotable_Reg reg_crypto[] =
 {
@@ -119,6 +134,8 @@ static const rotable_Reg reg_crypto[] =
     { "hmac_md5" ,      l_crypto_hmac_md5   ,0},
     { "sha1" ,          l_crypto_sha1       ,0},
     { "hmac_sha1" ,     l_crypto_hmac_sha1  ,0},
+    // { "aes_encrypt" ,   l_crypto_aes_encrypt,0},
+    // { "aes_decrypt" ,   l_crypto_aes_decrypt,0},
 	{ NULL,             NULL                ,0}
 };
 

+ 14 - 10
luat/modules/luat_lib_disp.c

@@ -19,7 +19,7 @@ static u8g2_t* u8g2;
 static int u8g2_lua_ref;
 /*
 显示屏初始化
-@function disp.init(conf)
+@api disp.init(conf)
 @table 配置信息
 @return int 正常初始化1,已经初始化过2,内存不够3,初始化失败返回4
 @usage
@@ -116,8 +116,7 @@ static int l_disp_init(lua_State *L) {
 
 /*
 关闭显示屏
-@function disp.close(id) 
-@int 显示器id, 默认值0, 当前只支持0,单个显示屏
+@api disp.close() 
 @usage
 disp.close()
 */
@@ -134,10 +133,9 @@ static int l_disp_close(lua_State *L) {
     return 0;
 }
 /*
-@function disp.clear(id) 清屏
-@int 显示器id, 默认值0, 当前只支持0,单个显示屏
+@api disp.clear() 清屏
 @usage
-disp.clear(0)
+disp.clear()
 */
 static int l_disp_clear(lua_State *L) {
     if (u8g2 == NULL) return 0;
@@ -146,10 +144,9 @@ static int l_disp_clear(lua_State *L) {
 }
 /*
 把显示数据更新到屏幕
-@function disp.update(id)
-@int 显示器id, 默认值0, 当前只支持0,单个显示屏
+@api disp.update()
 @usage
-disp.update(0)
+disp.update()
 */
 static int l_disp_update(lua_State *L) {
     if (u8g2 == NULL) return 0;
@@ -160,7 +157,7 @@ static int l_disp_update(lua_State *L) {
 
 /*
 在显示屏上画一段文字,要调用disp.update才会更新到屏幕
-@function disp.drawStr(content, x, y) 
+@api disp.drawStr(content, x, y) 
 @string 文件内容
 @int 横坐标
 @int 竖坐标
@@ -187,6 +184,13 @@ static int l_disp_draw_text(lua_State *L) {
 #include "u8g2_wqy.h"
 #endif
 
+/*
+设置字体
+@api disp.setFont(fontId) 
+@int 字体id, 默认0,纯英文8x8字节. 如果支持中文支持, 那么1代表12x12的中文字体.
+@usage
+disp.setFont(1)
+*/
 static int l_disp_set_font(lua_State *L) {
     if (u8g2 == NULL) {
         LLOGI("disp not init yet!!!");

+ 4 - 4
luat/modules/luat_lib_gpio.c

@@ -45,7 +45,7 @@ int l_gpio_handler(lua_State *L, void* ptr) {
 
 /*
 设置管脚功能
-@function gpio.setup(pin, mode, pull)
+@api gpio.setup(pin, mode, pull)
 @int pin 针脚编号,必须是数值
 @any mode 输入输出模式. 数字0/1代表输出模式,nil代表输入模式,function代表中断模式
 @int pull 上拉下列模式, 可以是gpio.PULLUP 或 gpio.PULLDOWN, 需要根据实际硬件选用
@@ -127,7 +127,7 @@ static int l_gpio_setup(lua_State *L) {
 
 /*
 设置管脚电平
-@function gpio.set(pin, value)
+@api gpio.set(pin, value)
 @int pin 针脚编号,必须是数值
 @int value 电平, 可以是 高电平gpio.HIGH, 低电平gpio.LOW, 或者直接写数值1或0
 @return nil
@@ -145,7 +145,7 @@ static int l_gpio_set(lua_State *L) {
 
 /*
 获取管脚电平
-@function gpio.get(pin)
+@api gpio.get(pin)
 @int pin 针脚编号,必须是数值
 @return value 电平, 高电平gpio.HIGH, 低电平gpio.LOW, 对应数值1和0
 @usage 
@@ -162,7 +162,7 @@ static int l_gpio_get(lua_State *L) {
 
 /*
 关闭管脚功能(高阻输入态),关掉中断
-@function gpio.close(pin)
+@api gpio.close(pin)
 @int pin 针脚编号,必须是数值
 @return nil 无返回值,总是执行成功
 @usage

+ 9 - 9
luat/modules/luat_lib_libcoap.c

@@ -105,7 +105,7 @@ static void addopt(luat_lib_libcoap_t* _coap, uint8_t opt_type, const char* valu
 
 /**
 创建一个coap数据包
-@function libcoap.new(code, uri, headers, payload)
+@api libcoap.new(code, uri, headers, payload)
 @int coap的code, 例如libcoap.GET/libcoap.POST/libcoap.PUT/libcoap.DELETE
 @string 目标URI,必须填写, 不需要加上/开头
 @table 请求头,类似于http的headers,可选
@@ -163,7 +163,7 @@ static int l_libcoap_new(lua_State* L) {
 
 /**
 解析coap数据包
-@function libcoap.parse(str)
+@api libcoap.parse(str)
 @string coap数据包
 @return userdata coap数据包,如果解析失败会返回nil
 @usage
@@ -244,7 +244,7 @@ static int l_libcoap_parse(lua_State* L) {
 
 /**
 获取coap数据包的msgid
-@function coapdata:msgid()
+@api coapdata:msgid()
 @return int coap数据包的msgid
 @usage
 -- 解析服务器传入的数据包
@@ -265,7 +265,7 @@ static int libcoap_msgid(lua_State *L) {
 
 /**
 获取coap数据包的token
-@function coapdata:token()
+@api coapdata:token()
 @return string coap数据包的token
 @usage
 -- 解析服务器传入的数据包
@@ -287,7 +287,7 @@ static int libcoap_token(lua_State *L) {
 
 /**
 获取coap数据包的二进制数据,用于发送到服务器
-@function coapdata:rawdata()
+@api coapdata:rawdata()
 @return string coap数据包的二进制数据
 @usage
 -- 解析服务器传入的数据包
@@ -343,7 +343,7 @@ static int libcoap_rawdata(lua_State *L) {
 
 /**
 获取coap数据包的code
-@function coapdata:code()
+@api coapdata:code()
 @return int coap数据包的code
 @usage
 -- 解析服务器传入的数据包
@@ -364,7 +364,7 @@ static int libcoap_code(lua_State *L) {
 
 /**
 获取coap数据包的http code, 比coap原始的code要友好
-@function coapdata:hcode()
+@api coapdata:hcode()
 @return int coap数据包的http code,例如200,205,404
 @usage
 -- 解析服务器传入的数据包
@@ -385,7 +385,7 @@ static int libcoap_httpcode(lua_State *L) {
 
 /**
 获取coap数据包的type, 例如libcoap.CON/NON/ACK/RST
-@function coapdata:type(t)
+@api coapdata:type(t)
 @int 新的type值,可选
 @return int coap数据包的type
 @usage
@@ -410,7 +410,7 @@ static int libcoap_type(lua_State *L) {
 
 /**
 获取coap数据包的data
-@function coapdata:data()
+@api coapdata:data()
 @return string coap数据包的data
 @usage
 -- 解析服务器传入的数据包

+ 5 - 5
luat/modules/luat_lib_libgnss.c

@@ -65,8 +65,8 @@ static int parse_nmea(const char* line) {
 
 /**
 处理nmea数据
-@function libgnss.parse(str)
-@string nmea数据
+@api libgnss.parse(str)
+@string 原始nmea数据
 @usage
 -- 解析nmea
 libgnss.parse(indata)
@@ -101,7 +101,7 @@ static int l_libgnss_parse(lua_State *L) {
 
 /**
 当前是否已经定位成功
-@function libgnss.isFix()
+@api libgnss.isFix()
 @return boolean 定位成功与否
 @usage
 -- 解析nmea
@@ -115,7 +115,7 @@ static int l_libgnss_is_fix(lua_State *L) {
 
 /**
 获取位置信息
-@function libgnss.getIntLocation()
+@api libgnss.getIntLocation()
 @return int lat数据, 格式为 ddmmmmmmm
 @return int lng数据, 格式为 ddmmmmmmm
 @return int speed数据
@@ -139,7 +139,7 @@ static int l_libgnss_get_int_location(lua_State *L) {
 
 /**
 获取原始RMC位置信息
-@function libgnss.getRmc()
+@api libgnss.getRmc()
 @return table 原始rmc数据
 @usage
 -- 解析nmea

+ 6 - 6
luat/modules/luat_lib_log.c

@@ -12,7 +12,7 @@
 
 /*
 设置日志级别
-@function   log.setLevel("INFO") 
+@api   log.setLevel(level) 
 @string  level 日志级别,可用字符串或数值, 字符串为(SILENT,DEBUG,INFO,WARN,ERROR,FATAL), 数值为(0,1,2,3,4,5)
 @return nil 无返回值
 @usage  
@@ -51,7 +51,7 @@ static int l_log_set_level(lua_State *L) {
 
 /*
 获取日志级别
-@function   log.getLevel()
+@api   log.getLevel()
 @return  int   日志级别对应0,1,2,3,4,5
 @usage  
 -- 得到日志级别
@@ -81,7 +81,7 @@ static int l_log_2_log(lua_State *L) {
 
 /*
 输出日志,级别debug
-@function    log.debug(tag, val, val2, val3, ...)
+@api    log.debug(tag, val, val2, val3, ...)
 @string  tag         日志标识,必须是字符串
 @any  ...         需打印的参数
 @return nil
@@ -98,7 +98,7 @@ static int l_log_debug(lua_State *L) {
 
 /*
 输出日志,级别info
-@function    log.info(tag, val, val2, val3, ...)
+@api    log.info(tag, val, val2, val3, ...)
 @string  tag         日志标识,必须是字符串
 @any  ...         需打印的参数
 @return nil
@@ -115,7 +115,7 @@ static int l_log_info(lua_State *L) {
 
 /*
 输出日志,级别warn
-@function    log.warn(tag, val, val2, val3, ...)
+@api    log.warn(tag, val, val2, val3, ...)
 @string  tag         日志标识,必须是字符串
 @any  ...         需打印的参数
 @return nil
@@ -132,7 +132,7 @@ static int l_log_warn(lua_State *L) {
 
 /*
 输出日志,级别error
-@function    log.error(tag, val, val2, val3, ...)
+@api    log.error(tag, val, val2, val3, ...)
 @string  tag         日志标识,必须是字符串
 @any  ...         需打印的参数
 @return nil

+ 0 - 90
luat/modules/luat_lib_mqtt.c

@@ -1,90 +0,0 @@
-/*
-@module  mqtt
-@summary mqtt操作库
-@version 1.0
-@date    2020.03.30
-*/
-#include "luat_base.h"
-#include "luat_log.h"
-#include "luat_timer.h"
-#include "luat_malloc.h"
-#include "luat_msgbus.h"
-#include "luat_socket.h"
-#include "rotable.h"
-
-#include "netclient.h"
-
-#define LUAT_MQTT_HANDLE "mqtt"
-
-static int l_mqtt_new(lua_State *L) {
-    return 0;
-};
-
-static int mqtt_id(lua_State *L) {
-    return 0;
-};
-static int mqtt_host(lua_State *L) {
-    return 0;
-};
-static int mqtt_port(lua_State *L) {
-    return 0;
-};
-static int mqtt_start(lua_State *L) {
-    return 0;
-};
-static int mqtt_close(lua_State *L) {
-    return 0;
-};
-static int mqtt_subscribe(lua_State *L) {
-    return 0;
-};
-static int mqtt_unsubscribe(lua_State *L) {
-    return 0;
-};
-static int mqtt_publish(lua_State *L) {
-    return 0;
-};
-static int mqtt_clean(lua_State *L) {
-    return 0;
-};
-static int mqtt_gc(lua_State *L) {
-    return 0;
-};
-static int mqtt_tostring(lua_State *L) {
-    return 0;
-};
-
-static const luaL_Reg lib_mqtt[] = {
-    {"id",          mqtt_id},
-    {"host",        mqtt_host},
-    {"port",        mqtt_port},
-    {"start",       mqtt_start},
-    {"close",       mqtt_close},
-    {"subscribe",   mqtt_subscribe},
-    {"unsubscribe", mqtt_unsubscribe},
-    {"publish",     mqtt_publish},
-    {"clean",       mqtt_clean},
-    {"__gc",        mqtt_gc},
-    {"__tostring",  mqtt_tostring},
-    {NULL, NULL}
-};
-
-
-static void createmeta (lua_State *L) {
-  luaL_newmetatable(L, LUAT_MQTT_HANDLE);  /* create metatable for file handles */
-  lua_pushvalue(L, -1);  /* push metatable */
-  lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
-  luaL_setfuncs(L, lib_mqtt, 0);  /* add file methods to new metatable */
-  lua_pop(L, 1);  /* pop new metatable */
-}
-
-static const rotable_Reg reg_mqtt[] =
-{
-    { "new", l_mqtt_new, 0},
-	{ NULL, NULL, 0}
-};
-
-LUAMOD_API int luaopen_mqtt( lua_State *L ) {
-    rotable_newlib(L, reg_mqtt);
-    return 1;
-}

+ 1 - 281
luat/modules/luat_lib_mqttcore.c

@@ -1,6 +1,6 @@
 /*
 @module  libmqtt
-@summary mqtt协议处理
+@summary mqtt协议处理,供mqtt.lua使用
 @version 1.0
 @date    2020.07.03
 */
@@ -38,29 +38,6 @@ const char* MQTTPacket_name(int ptype)
 	return (ptype >= 0 && ptype <= AUTH) ? packet_names[ptype] : "UNKNOWN";
 }
 
-/**
- * Array of functions to build packets, indexed according to packet code
- */
-// pf new_packets[] =
-// {
-// 	NULL,	/**< reserved */
-// 	NULL,	/**< MQTTPacket_connect*/
-// 	MQTTPacket_connack, /**< CONNACK */
-// 	MQTTPacket_publish,	/**< PUBLISH */
-// 	MQTTPacket_ack, /**< PUBACK */
-// 	MQTTPacket_ack, /**< PUBREC */
-// 	MQTTPacket_ack, /**< PUBREL */
-// 	MQTTPacket_ack, /**< PUBCOMP */
-// 	NULL, /**< MQTTPacket_subscribe*/
-// 	MQTTPacket_suback, /**< SUBACK */
-// 	NULL, /**< MQTTPacket_unsubscribe*/
-// 	MQTTPacket_unsuback, /**< UNSUBACK */
-// 	MQTTPacket_header_only, /**< PINGREQ */
-// 	MQTTPacket_header_only, /**< PINGRESP */
-// 	MQTTPacket_ack,  /**< DISCONNECT */
-// 	MQTTPacket_ack   /**< AUTH */
-// };
-
 /**
  * Encodes the message length according to the MQTT algorithm
  * @param buf the buffer into which the encoded data is written
@@ -88,263 +65,6 @@ int MQTTPacket_encode(char* buf, size_t length)
 	return rc;
 }
 
-// /**
-//  * Calculates an integer from two bytes read from the input buffer
-//  * @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
-//  * @return the integer value calculated
-//  */
-// int readInt(char** pptr)
-// {
-// 	char* ptr = *pptr;
-// 	int len = 256*((unsigned char)(*ptr)) + (unsigned char)(*(ptr+1));
-// 	*pptr += 2;
-// 	return len;
-// }
-
-// /**
-//  * Reads a "UTF" string from the input buffer.  UTF as in the MQTT v3 spec which really means
-//  * a length delimited string.  So it reads the two byte length then the data according to
-//  * that length.  The end of the buffer is provided too, so we can prevent buffer overruns caused
-//  * by an incorrect length.
-//  * @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
-//  * @param enddata pointer to the end of the buffer not to be read beyond
-//  * @param len returns the calculcated value of the length bytes read
-//  * @return an allocated C string holding the characters read, or NULL if the length read would
-//  * have caused an overrun.
-//  *
-//  */
-// static char* readUTFlen(char** pptr, char* enddata, int* len)
-// {
-// 	char* string = NULL;
-
-// 	//FUNC_ENTRY;
-// 	if (enddata - (*pptr) > 1) /* enough length to read the integer? */
-// 	{
-// 		*len = readInt(pptr);
-// 		if (&(*pptr)[*len] <= enddata)
-// 		{
-// 			if ((string = malloc(*len+1)) == NULL)
-// 				goto exit;
-// 			memcpy(string, *pptr, *len);
-// 			string[*len] = '\0';
-// 			*pptr += *len;
-// 		}
-// 	}
-// exit:
-// 	//FUNC_EXIT;
-// 	return string;
-// }
-
-// /**
-//  * Reads a "UTF" string from the input buffer.  UTF as in the MQTT v3 spec which really means
-//  * a length delimited string.  So it reads the two byte length then the data according to
-//  * that length.  The end of the buffer is provided too, so we can prevent buffer overruns caused
-//  * by an incorrect length.
-//  * @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
-//  * @param enddata pointer to the end of the buffer not to be read beyond
-//  * @return an allocated C string holding the characters read, or NULL if the length read would
-//  * have caused an overrun.
-//  */
-// char* readUTF(char** pptr, char* enddata)
-// {
-// 	int len;
-// 	return readUTFlen(pptr, enddata, &len);
-// }
-
-// /**
-//  * Reads one character from the input buffer.
-//  * @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
-//  * @return the character read
-//  */
-// unsigned char readChar(char** pptr)
-// {
-// 	unsigned char c = **pptr;
-// 	(*pptr)++;
-// 	return c;
-// }
-
-// /**
-//  * Writes one character to an output buffer.
-//  * @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
-//  * @param c the character to write
-//  */
-// void writeChar(char** pptr, char c)
-// {
-// 	**pptr = c;
-// 	(*pptr)++;
-// }
-
-// /**
-//  * Writes an integer as 2 bytes to an output buffer.
-//  * @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
-//  * @param anInt the integer to write
-//  */
-// void writeInt(char** pptr, int anInt)
-// {
-// 	**pptr = (char)(anInt / 256);
-// 	(*pptr)++;
-// 	**pptr = (char)(anInt % 256);
-// 	(*pptr)++;
-// }
-
-// /**
-//  * Writes a "UTF" string to an output buffer.  Converts C string to length-delimited.
-//  * @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
-//  * @param string the C string to write
-//  */
-// void writeUTF(char** pptr, const char* string)
-// {
-// 	size_t len = strlen(string);
-// 	writeInt(pptr, (int)len);
-// 	memcpy(*pptr, string, len);
-// 	*pptr += len;
-// }
-
-// /**
-//  * Writes length delimited data to an output buffer
-//  * @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
-//  * @param data the data to write
-//  * @param datalen the length of the data to write
-//  */
-// void writeData(char** pptr, const void* data, int datalen)
-// {
-// 	writeInt(pptr, datalen);
-// 	memcpy(*pptr, data, datalen);
-// 	*pptr += datalen;
-// }
-
-// /**
-//  * Function used in the new packets table to create packets which have only a header.
-//  * @param MQTTVersion the version of MQTT
-//  * @param aHeader the MQTT header byte
-//  * @param data the rest of the packet
-//  * @param datalen the length of the rest of the packet
-//  * @return pointer to the packet structure
-//  */
-// void* MQTTPacket_header_only(int MQTTVersion, unsigned char aHeader, char* data, size_t datalen)
-// {
-// 	static unsigned char header = 0;
-// 	header = aHeader;
-// 	return &header;
-// }
-
-// /**
-//  * Writes an integer as 4 bytes to an output buffer.
-//  * @param pptr pointer to the output buffer - incremented by the number of bytes used & returned
-//  * @param anInt the integer to write
-//  */
-// void writeInt4(char** pptr, int anInt)
-// {
-//   **pptr = (char)(anInt / 16777216);
-//   (*pptr)++;
-//   anInt %= 16777216;
-//   **pptr = (char)(anInt / 65536);
-//   (*pptr)++;
-//   anInt %= 65536;
-// 	**pptr = (char)(anInt / 256);
-// 	(*pptr)++;
-// 	**pptr = (char)(anInt % 256);
-// 	(*pptr)++;
-// }
-
-// /**
-//  * Calculates an integer from two bytes read from the input buffer
-//  * @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
-//  * @return the integer value calculated
-//  */
-// int readInt4(char** pptr)
-// {
-// 	unsigned char* ptr = (unsigned char*)*pptr;
-// 	int value = 16777216*(*ptr) + 65536*(*(ptr+1)) + 256*(*(ptr+2)) + (*(ptr+3));
-// 	*pptr += 4;
-// 	return value;
-// }
-
-// void writeMQTTLenString(char** pptr, MQTTLenString lenstring)
-// {
-//   writeInt(pptr, lenstring.len);
-//   memcpy(*pptr, lenstring.data, lenstring.len);
-//   *pptr += lenstring.len;
-// }
-
-
-// int MQTTLenStringRead(MQTTLenString* lenstring, char** pptr, char* enddata)
-// {
-// 	int len = 0;
-
-// 	/* the first two bytes are the length of the string */
-// 	if (enddata - (*pptr) > 1) /* enough length to read the integer? */
-// 	{
-// 		lenstring->len = readInt(pptr); /* increments pptr to point past length */
-// 		if (&(*pptr)[lenstring->len] <= enddata)
-// 		{
-// 			lenstring->data = (char*)*pptr;
-// 			*pptr += lenstring->len;
-// 			len = 2 + lenstring->len;
-// 		}
-// 	}
-// 	return len;
-// }
-
-// /*
-// if (prop->value.integer4 >= 0 && prop->value.integer4 <= 127)
-//   len = 1;
-// else if (prop->value.integer4 >= 128 && prop->value.integer4 <= 16383)
-//   len = 2;
-// else if (prop->value.integer4 >= 16384 && prop->value.integer4 < 2097151)
-//   len = 3;
-// else if (prop->value.integer4 >= 2097152 && prop->value.integer4 < 268435455)
-//   len = 4;
-// */
-// int MQTTPacket_VBIlen(int rem_len)
-// {
-// 	int rc = 0;
-
-// 	if (rem_len < 128)
-// 		rc = 1;
-// 	else if (rem_len < 16384)
-// 		rc = 2;
-// 	else if (rem_len < 2097152)
-// 		rc = 3;
-// 	else
-// 		rc = 4;
-//   return rc;
-// }
-
-
-// /**
-//  * Decodes the message length according to the MQTT algorithm
-//  * @param getcharfn pointer to function to read the next character from the data source
-//  * @param value the decoded length returned
-//  * @return the number of bytes read from the socket
-//  */
-// int MQTTPacket_VBIdecode(int (*getcharfn)(char*, int), unsigned int* value)
-// {
-// 	char c;
-// 	int multiplier = 1;
-// 	int len = 0;
-// #define MAX_NO_OF_REMAINING_LENGTH_BYTES 4
-
-// 	*value = 0;
-// 	do
-// 	{
-// 		int rc = MQTTPACKET_READ_ERROR;
-
-// 		if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES)
-// 		{
-// 			rc = MQTTPACKET_READ_ERROR;	/* bad data */
-// 			goto exit;
-// 		}
-// 		rc = (*getcharfn)(&c, 1);
-// 		if (rc != 1)
-// 			goto exit;
-// 		*value += (c & 127) * multiplier;
-// 		multiplier *= 128;
-// 	} while ((c & 128) != 0);
-// exit:
-// 	return len;
-// }
-
 
 static int l_mqttcore_encodeLen(lua_State *L) {
     size_t len = 0;

+ 6 - 6
luat/modules/luat_lib_pm.c

@@ -15,7 +15,7 @@ static int lua_event_cb = 0;
 
 /**
 请求进入指定的休眠模式
-@function pm.request(mode)
+@api pm.request(mode)
 @int 休眠模式,例如pm.IDLE/LIGHT/DEEP/HIB
 @return boolean 处理结果,即使返回成功,也不一定会进入, 也不会马上进入
 @usage
@@ -42,7 +42,7 @@ static int l_pm_request(lua_State *L) {
 
 /**
 启动底层定时器,在休眠模式下依然生效. 只触发一次
-@function pm.dtimerStart(id, timeout)
+@api pm.dtimerStart(id, timeout)
 @int 定时器id,通常是0-3
 @int 定时时长,单位毫秒
 @return boolean 处理结果
@@ -64,7 +64,7 @@ static int l_pm_dtimer_start(lua_State *L) {
 
 /**
 关闭底层定时器
-@function pm.dtimerStop(id)
+@api pm.dtimerStop(id)
 @int 定时器id
 @usage
 -- 添加底层定时器
@@ -91,7 +91,7 @@ static int l_pm_on(lua_State *L) {
 
 /**
 开机原因,用于判断是从休眠模块开机,还是电源/复位开机
-@function pm.request(mode)
+@api pm.request(mode)
 @int 休眠模式,例如pm.IDLE/LIGHT/DEEP/HIB
 @return boolean 处理结果,即使返回成功,也不一定会进入, 也不会马上进入
 @usage
@@ -105,7 +105,7 @@ static int l_pm_last_reson(lua_State *L) {
 
 /**
 强制进入指定的休眠模式
-@function pm.force(mode)
+@api pm.force(mode)
 @int 休眠模式,仅pm.DEEP/HIB
 @return boolean 处理结果,若返回成功,大概率会马上进入该休眠模式
 @usage
@@ -119,7 +119,7 @@ static int l_pm_force(lua_State *L) {
 
 /**
 检查休眠状态
-@function pm.check()
+@api pm.check()
 @return boolean 处理结果,如果能顺利进入休眠,返回true,否则返回false
 @usage
 -- 请求进入休眠模式,然后检查是否能真的休眠

+ 20 - 1
luat/modules/luat_lib_pwm.c

@@ -7,6 +7,17 @@
 #include "luat_base.h"
 #include "luat_pwm.h"
 
+/**
+开启指定的PWM通道
+@api pwm.open(channel, period, pulse)
+@int PWM通道
+@int 频率, 1-1000000hz
+@int 占空比 0-100
+@return boolean 处理结果,成功返回true,失败返回false
+@usage
+-- 打开PWM5, 频率1kHz, 占空比50%
+pwm.open(5, 1000, 50)
+ */
 static int l_pwm_open(lua_State *L) {
     int channel = luaL_checkinteger(L, 1);
     size_t period = luaL_checkinteger(L, 2);
@@ -20,7 +31,15 @@ static int l_pwm_open(lua_State *L) {
     return 1;
 }
 
-
+/**
+关闭指定的PWM通道
+@api pwm.close(channel)
+@int PWM通道
+@return nil 无处理结果
+@usage
+-- 关闭PWM5
+pwm.close(5)
+ */
 static int l_pwm_close(lua_State *L) {
     luat_pwm_close(luaL_checkinteger(L, 1));
     return 0;

+ 20 - 8
luat/modules/luat_lib_rtos.c

@@ -15,7 +15,7 @@
 
 /*
 接受并处理底层消息队列.
-@function    rtos.receive(timeout)   
+@api    rtos.receive(timeout)   
 @int  超时时长,通常是-1,永久等待
 @return msgid          如果是定时器消息,会返回定时器消息id及附加信息, 其他消息由底层决定,不向lua层进行任何保证.
 --  本方法通过sys.run()调用, 普通用户不要使用
@@ -57,7 +57,7 @@ static int l_timer_handler(lua_State *L, void* ptr) {
 
 /*
 启动一个定时器
-@function    rtos.timer_start(id,timeout,_repeat)   
+@api    rtos.timer_start(id,timeout,_repeat)   
 @int  定时器id
 @int  超时时长,单位毫秒
 @int  重复次数,默认是0
@@ -97,7 +97,7 @@ static int l_rtos_timer_start(lua_State *L) {
 
 /*
 关闭并释放一个定时器
-@function    rtos.timer_stop(id)   
+@api    rtos.timer_stop(id)   
 @int  定时器id
 @return nil            无返回值
 @usage
@@ -121,7 +121,7 @@ static int l_rtos_timer_stop(lua_State *L) {
 
 /*
 设备重启
-@function    rtos.reboot()   
+@api    rtos.reboot()   
 @return nil          无返回值
 -- 立即重启设备
 rtos.reboot()
@@ -135,7 +135,7 @@ static int l_rtos_reboot(lua_State *L) {
 
 /*
 获取固件编译日期
-@function    rtos.buildDate()
+@api    rtos.buildDate()
 @return string 固件编译日期
 @usage
 -- 获取编译日期
@@ -148,7 +148,7 @@ static int l_rtos_build_date(lua_State *L) {
 
 /*
 获取硬件bsp型号
-@function    rtos.bsp()
+@api    rtos.bsp()
 @return string 硬件bsp型号
 @usage
 -- 获取编译日期
@@ -161,7 +161,7 @@ static int l_rtos_bsp(lua_State *L) {
 
 /*
  获取固件版本号
-@function    rtos.version()        
+@api    rtos.version()        
 @return string  固件版本号,例如"1.0.2"
 @usage
 -- 读取版本号
@@ -174,7 +174,7 @@ static int l_rtos_version(lua_State *L) {
 
 /*
 进入待机模式(部分设备可用,例如w60x)
-@function    rtos.standy(timeout)
+@api    rtos.standy(timeout)
 @int    休眠时长,单位毫秒     
 @return nil  无返回值
 @usage
@@ -187,6 +187,18 @@ static int l_rtos_standy(lua_State *L) {
     return 0;
 }
 
+/*
+获取内存信息
+@api    rtos.meminfo(type)
+@type   "sys"系统内存, "lua"虚拟机内存, 默认为lua虚拟机内存     
+@return int 总内存大小,单位字节
+@return int 当前使用的内存大小,单位字节
+@return int 最大使用的内存大小,单位字节
+@usage
+-- 打印内存占用
+log.info("mem.lua", rtos.meminfo())
+log.info("mem.sys", rtos.meminfo("sys"))
+*/
 static int l_rtos_meminfo(lua_State *L) {
     size_t len = 0;
     size_t total = 0;

+ 1 - 1
luat/modules/luat_lib_sensor.c

@@ -173,7 +173,7 @@ static int32_t ds18b20_get_temperature(int pin, int32_t *val)
 
 /*
 获取DS18B20的温度数据
-@function    sensor.ds18b20(pin)
+@api    sensor.ds18b20(pin)
 @int  gpio端口号
 @return int 温度数据
 @return boolean 成功返回true,否则返回false

+ 14 - 14
luat/modules/luat_lib_socket.c

@@ -17,7 +17,7 @@
 
 /*
 ntp时间同步
-@function    socket.ntpSync(server)
+@api    socket.ntpSync(server)
 @string ntp服务器域名,默认值ntp1.aliyun.com
 @return int 启动成功返回0, 失败返回1或者2
 --  如果读取失败,会返回nil
@@ -35,7 +35,7 @@ static int socket_ntp_sync(lua_State *L) {
 
 /*
 直接向地址发送一段数据
-@function    socket.tsend(host, port, data)
+@api    socket.tsend(host, port, data)
 @string 服务器域名或者ip
 @int    服务器端口号
 @string 待发送的数据
@@ -53,7 +53,7 @@ static int sal_tls_test(lua_State *L)
 
 /*
 网络是否就绪
-@function    socket.isReady()
+@api    socket.isReady()
 @return boolean 已联网返回true,否则返回false
 */
 static int l_socket_is_ready(lua_State *L) {
@@ -63,7 +63,7 @@ static int l_socket_is_ready(lua_State *L) {
 
 /*
 获取自身ip,通常是内网ip
-@function    socket.ip()
+@api    socket.ip()
 @return string 已联网返回ip地址,否则返回nil
 */
 static int l_socket_selfip(lua_State *L) {
@@ -150,7 +150,7 @@ static int luat_lib_socket_ent_handler(netc_ent_t* ent) {
 //----------------------------------------------------------------
 /*
 新建一个tcp socket
-@function    socket.tcp()
+@api    socket.tcp()
 @return object socket对象,如果创建失败会返回nil
 --  如果读取失败,会返回nil
 local so = socket.tcp()
@@ -177,7 +177,7 @@ static int luat_lib_socket_tcp(lua_State* L) {
 }
 /*
 新建一个udp socket
-@function    socket.udp()
+@api    socket.udp()
 @return nil 暂不支持
 */
 static int luat_lib_socket_udp(lua_State* L) {
@@ -225,7 +225,7 @@ static int luat_lib_socket_new(lua_State* L, int netc_type) {
 
 /*
 启动socket线程
-@function    so:start(host, port)
+@api    so:start(host, port)
 @string 服务器域名或ip,如果已经使用so:host和so:port配置,就不需要传参数了
 @port 服务器端口,如果已经使用so:host和so:port配置,就不需要传参数了
 @return int 成功返回1,失败返回0
@@ -267,7 +267,7 @@ static int netc_connect(lua_State *L) {
 
 /*
 关闭socket对象
-@function    so:close()
+@api    so:close()
 @return nil 总会成功
 -- 参考socket.tcp的说明, 并查阅demo
 */
@@ -281,7 +281,7 @@ static int netc_close(lua_State *L) {
 
 /*
 通过socket对象发送数据
-@function    so:send(data)
+@api    so:send(data)
 @string 待发送数据
 @return boolean 发送成功返回true,否则返回false
 -- 参考socket.tcp的说明, 并查阅demo
@@ -333,7 +333,7 @@ static int netc_tostring(lua_State *L) {
 
 /*
 获取socket对象的id
-@function    so:id()
+@api    so:id()
 @return string 对象id,全局唯一
 -- 参考socket.tcp的说明, 并查阅demo
 */
@@ -345,7 +345,7 @@ static int netc_id(lua_State *L) {
 
 /*
 设置服务器域名或ip
-@function    so:host(host)
+@api    so:host(host)
 @string 服务器域名或ip
 @return nil 无返回值
 -- 参考socket.tcp的说明, 并查阅demo
@@ -374,7 +374,7 @@ static int netc_host(lua_State *L) {
 
 /*
 设置服务器端口
-@function    so:port(port)
+@api    so:port(port)
 @int 服务器端口
 @return nil 无返回值
 -- 参考socket.tcp的说明, 并查阅demo
@@ -391,7 +391,7 @@ static int netc_port(lua_State *L) {
 
 /*
 清理socket关联的资源,socket对象在废弃前必须调用
-@function    so:clean(0)
+@api    so:clean(0)
 @return nil 无返回值
 -- 参考socket.tcp的说明, 并查阅demo
 */
@@ -425,7 +425,7 @@ static int netc_clean(lua_State *L) {
 
 /*
 设置socket的事件回调
-@function    so:port(event, func)
+@api    so:port(event, func)
 @string 事件名称
 @function 回调方法
 @return nil 无返回值

+ 1 - 1
luat/modules/luat_lib_timer.c

@@ -11,7 +11,7 @@
 
 /*
 硬阻塞指定时长,期间没有任何luat代码会执行,包括底层消息处理机制
-@function    timer.mdelay(timeout)
+@api    timer.mdelay(timeout)
 @int 阻塞时长
 @return nil 无返回值
 -- 本方法通常不会使用,除非你很清楚会发生什么

+ 5 - 5
luat/modules/luat_lib_uart.c

@@ -65,7 +65,7 @@ int l_uart_handler(lua_State *L, void* ptr) {
 
 /*
 配置串口参数
-@function    uart.setup(id, baud_rate, data_bits, stop_bits, partiy, bit_order, buff_size)
+@api    uart.setup(id, baud_rate, data_bits, stop_bits, partiy, bit_order, buff_size)
 @int 串口id, uart0写0, uart1写1
 @int 波特率 9600~115200
 @int 数据位 7或8, 一般是8
@@ -99,7 +99,7 @@ static int l_uart_setup(lua_State *L)
 
 /*
 写串口
-@function    uart.write(id, data)
+@api    uart.write(id, data)
 @int 串口id, uart0写0, uart1写1
 @string 待写入的数据
 @return int 成功的数据长度
@@ -120,7 +120,7 @@ static int l_uart_write(lua_State *L)
 
 /*
 读串口
-@function    uart.read(id, len)
+@api    uart.read(id, len)
 @int 串口id, uart0写0, uart1写1
 @int 读取长度
 @return string 读取到的数据
@@ -155,7 +155,7 @@ static int l_uart_read(lua_State *L)
 
 /*
 关闭串口
-@function    uart.close(id)
+@api    uart.close(id)
 @int 串口id, uart0写0, uart1写1
 @return nil 无返回值
 @usage
@@ -170,7 +170,7 @@ static int l_uart_close(lua_State *L)
 
 /*
 注册串口事件回调
-@function    uart.on(id, event, func)
+@api    uart.on(id, event, func)
 @int 串口id, uart0写0, uart1写1
 @string 事件名称
 @function 回调方法