Paritally working
This commit is contained in:
parent
06becd1e8a
commit
69405ce183
|
@ -412,6 +412,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
// -1 is the services list
|
// -1 is the services list
|
||||||
int nc = 0;
|
int nc = 0;
|
||||||
for (int i = 1; i <= ns; i++) {
|
for (int i = 1; i <= ns; i++) {
|
||||||
|
MODLOG_DFLT(INFO, "Counting -- service %d (top %d)\n", i, lua_gettop(L));
|
||||||
lua_geti(L, -1, i);
|
lua_geti(L, -1, i);
|
||||||
// -1 is now the service which should be a table. It must have a uuid
|
// -1 is now the service which should be a table. It must have a uuid
|
||||||
if (lua_type(L, -1) != LUA_TTABLE) {
|
if (lua_type(L, -1) != LUA_TTABLE) {
|
||||||
|
@ -427,6 +428,8 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MODLOG_DFLT(INFO, "Discovered %d services with %d characteristics\n", ns, nc);
|
||||||
|
|
||||||
int size = (ns + 1) * sizeof(struct ble_gatt_svc_def) + (nc + ns) * sizeof(struct ble_gatt_chr_def) + (ns + nc) * sizeof(ble_uuid_any_t);
|
int size = (ns + 1) * sizeof(struct ble_gatt_svc_def) + (nc + ns) * sizeof(struct ble_gatt_chr_def) + (ns + nc) * sizeof(ble_uuid_any_t);
|
||||||
|
|
||||||
|
|
||||||
|
@ -444,6 +447,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
// Now fill out the data structure
|
// Now fill out the data structure
|
||||||
// -1 is the services list
|
// -1 is the services list
|
||||||
for (int i = 1; i <= ns; i++) {
|
for (int i = 1; i <= ns; i++) {
|
||||||
|
MODLOG_DFLT(INFO, "Processing service %d (top %d)\n", i, lua_gettop(L));
|
||||||
struct ble_gatt_svc_def *svc = svcs++;
|
struct ble_gatt_svc_def *svc = svcs++;
|
||||||
lua_geti(L, -1, i);
|
lua_geti(L, -1, i);
|
||||||
// -1 is now the service which should be a table. It must have a uuid
|
// -1 is now the service which should be a table. It must have a uuid
|
||||||
|
@ -457,9 +461,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
free_gatt_svcs(L, result);
|
free_gatt_svcs(L, result);
|
||||||
return luaL_error(L, "Unable to convert UUID: %s", lua_tostring(L, -1));
|
return luaL_error(L, "Unable to convert UUID: %s", lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
if (i == 1) {
|
|
||||||
svc->type = BLE_GATT_SVC_TYPE_PRIMARY;
|
svc->type = BLE_GATT_SVC_TYPE_PRIMARY;
|
||||||
}
|
|
||||||
svc->uuid = (ble_uuid_t *) uuids++;
|
svc->uuid = (ble_uuid_t *) uuids++;
|
||||||
svc->characteristics = chrs;
|
svc->characteristics = chrs;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
@ -467,6 +469,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
lua_getfield(L, -1, "characteristics");
|
lua_getfield(L, -1, "characteristics");
|
||||||
int nc = lua_rawlen(L, -1);
|
int nc = lua_rawlen(L, -1);
|
||||||
for (int j = 1; j <= nc; j++) {
|
for (int j = 1; j <= nc; j++) {
|
||||||
|
MODLOG_DFLT(INFO, "Processing characteristic %d (top %d)\n", j, lua_gettop(L));
|
||||||
struct ble_gatt_chr_def *chr = chrs++;
|
struct ble_gatt_chr_def *chr = chrs++;
|
||||||
lua_geti(L, -1, j);
|
lua_geti(L, -1, j);
|
||||||
|
|
||||||
|
@ -488,13 +491,13 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
chr->flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE;
|
chr->flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE;
|
||||||
lua_pop(L, 1); // pop off value
|
lua_pop(L, 1); // pop off value
|
||||||
} else {
|
} else {
|
||||||
lua_getfield(L, -1, "read");
|
lua_getfield(L, -2, "read");
|
||||||
if (!lua_isnoneornil (L, -1)) {
|
if (!lua_isnoneornil (L, -1)) {
|
||||||
luaL_checkfunction (L, -1);
|
luaL_checkfunction (L, -1);
|
||||||
chr->flags |= BLE_GATT_CHR_F_READ;
|
chr->flags |= BLE_GATT_CHR_F_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_getfield(L, -1, "write");
|
lua_getfield(L, -3, "write");
|
||||||
if (!lua_isnoneornil (L, -1)) {
|
if (!lua_isnoneornil (L, -1)) {
|
||||||
luaL_checkfunction (L, -1);
|
luaL_checkfunction (L, -1);
|
||||||
chr->flags |= BLE_GATT_CHR_F_WRITE;
|
chr->flags |= BLE_GATT_CHR_F_WRITE;
|
||||||
|
@ -508,6 +511,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp) {
|
||||||
chr->access_cb = lble_access_cb;
|
chr->access_cb = lble_access_cb;
|
||||||
}
|
}
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
|
chrs++; // terminate the list of characteristics for this service
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
|
|
@ -534,6 +534,58 @@ static int file_fsinfo( lua_State* L )
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lua: getfile(filename)
|
||||||
|
static int file_getfile( lua_State* L )
|
||||||
|
{
|
||||||
|
// Warning this code C calls other file_* routines to avoid duplication code. These
|
||||||
|
// use Lua stack addressing of arguments, so this does Lua stack maniplation to
|
||||||
|
// align these
|
||||||
|
int ret_cnt = 0;
|
||||||
|
lua_settop(L ,1);
|
||||||
|
// Stack [1] = FD
|
||||||
|
file_open(L);
|
||||||
|
// Stack [1] = filename; [2] = FD or nil
|
||||||
|
if (!lua_isnil(L, -1)) {
|
||||||
|
lua_remove(L, 1); // dump filename, so [1] = FD
|
||||||
|
file_fd_ud *ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj");
|
||||||
|
ret_cnt = file_g_read(L, LUAI_MAXINT32, EOF, ud->fd);
|
||||||
|
// Stack [1] = FD; [2] = contents if ret_cnt = 1;
|
||||||
|
file_close(L); // leaves Stack unchanged if [1] = FD
|
||||||
|
lua_remove(L, 1); // Dump FD leaving contents as [1] / ToS
|
||||||
|
}
|
||||||
|
return ret_cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lua: getfile(filename)
|
||||||
|
static int file_putfile( lua_State* L )
|
||||||
|
{
|
||||||
|
// Warning this code C calls other file_* routines to avoid duplication code. These
|
||||||
|
// use Lua stack addressing of arguments, so this does Lua stack maniplation to
|
||||||
|
// align these
|
||||||
|
int ret_cnt = 0;
|
||||||
|
lua_settop(L, 2);
|
||||||
|
lua_pushvalue(L, 2); //dup contents onto the ToS [3]
|
||||||
|
lua_pushliteral(L, "w+");
|
||||||
|
lua_replace(L, 2);
|
||||||
|
// Stack [1] = filename; [2] "w+" [3] contents;
|
||||||
|
file_open(L);
|
||||||
|
// Stack [1] = filename; [2] "w+" [3] contents; [4] FD or nil
|
||||||
|
|
||||||
|
if (!lua_isnil(L, -1)) {
|
||||||
|
lua_remove(L, 2); //dump "w+" attribute literal
|
||||||
|
lua_replace(L, 1);
|
||||||
|
// Stack [1] = FD; [2] contents
|
||||||
|
file_write(L);
|
||||||
|
// Stack [1] = FD; [2] contents; [3] result status
|
||||||
|
lua_remove(L, 2); //dump contents
|
||||||
|
file_close(L);
|
||||||
|
lua_remove(L, 1); // Dump FD leaving status as ToS
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
vfs_vol *vol;
|
vfs_vol *vol;
|
||||||
} volume_type;
|
} volume_type;
|
||||||
|
@ -570,6 +622,8 @@ LROT_BEGIN(file, NULL, 0)
|
||||||
LROT_FUNCENTRY( writeline, file_writeline )
|
LROT_FUNCENTRY( writeline, file_writeline )
|
||||||
LROT_FUNCENTRY( read, file_read )
|
LROT_FUNCENTRY( read, file_read )
|
||||||
LROT_FUNCENTRY( readline, file_readline )
|
LROT_FUNCENTRY( readline, file_readline )
|
||||||
|
LROT_FUNCENTRY( getcontents, file_getfile )
|
||||||
|
LROT_FUNCENTRY( putcontents, file_putfile )
|
||||||
#ifdef CONFIG_NODEMCU_BUILD_SPIFFS
|
#ifdef CONFIG_NODEMCU_BUILD_SPIFFS
|
||||||
LROT_FUNCENTRY( format, file_format )
|
LROT_FUNCENTRY( format, file_format )
|
||||||
LROT_FUNCENTRY( fscfg, file_fscfg )
|
LROT_FUNCENTRY( fscfg, file_fscfg )
|
||||||
|
|
Loading…
Reference in New Issue