Browse Source

refine telnet object

Signed-off-by: surenyi <surenyi82@qq.com>
master
surenyi 6 years ago
parent
commit
48c14628d6
  1. 39
      packages/vsky/libdsp/lua/lualib/kit.c
  2. 3
      packages/vsky/libdsp/package.bld
  3. 2
      progs/emifwriter/writer.c
  4. 2
      progs/sbl/.cproject
  5. 2
      progs/sbl/main.c
  6. 80
      samples/telnet/script.c
  7. 3
      samples/telnet/telnet.c

39
packages/vsky/libdsp/lua/lualib/kit.c

@ -42,6 +42,20 @@ static int __nor_write(lua_State *L)
return 1; return 1;
} }
static int __nor_copy(lua_State *L)
{
int r;
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1);
nor_flash_t nf = *ud;
unsigned int to = luaL_checkinteger(L, 2);
unsigned int from = luaL_checkinteger(L, 3);
size_t len = luaL_checkinteger(L, 4);
r = nor_flash_write(nf, (const void *)from, to, len);
lua_pushboolean(L, r == 0);
return 1;
}
static int __nor_erase(lua_State *L) static int __nor_erase(lua_State *L)
{ {
int r; int r;
@ -117,15 +131,16 @@ static int __nor_close(lua_State *L)
} }
static struct luaL_Reg __nor_methods[] = { static struct luaL_Reg __nor_methods[] = {
{"erase", __nor_erase}, {"erase", __nor_erase},
{"write", __nor_write}, {"write", __nor_write},
{"read", __nor_read}, {"copy", __nor_copy},
{"size", __nor_size}, {"read", __nor_read},
{"sectors", __nor_sectors}, {"size", __nor_size},
{"sectors", __nor_sectors},
{"sectorSize", __nor_sec_size}, {"sectorSize", __nor_sec_size},
{"close", __nor_close}, {"close", __nor_close},
{"__gc", __nor_close}, {"__gc", __nor_close},
{"__tostring", auxiliar_tostring}, {"__tostring", auxiliar_tostring},
{NULL, NULL} {NULL, NULL}
}; };
@ -273,8 +288,8 @@ static struct luaL_Reg uart_meths[] = {
{"setDatabits", __uart_meth_set_databits}, {"setDatabits", __uart_meth_set_databits},
{"setStopbits", __uart_meth_set_stopbits}, {"setStopbits", __uart_meth_set_stopbits},
{"setParity", __uart_meth_set_parity}, {"setParity", __uart_meth_set_parity},
{"__gc", __uart_meth_close}, {"__gc", __uart_meth_close},
{"__tostring", auxiliar_tostring}, {"__tostring", auxiliar_tostring},
{NULL, NULL} {NULL, NULL}
}; };
@ -356,9 +371,9 @@ static int __gpio_direction(lua_State *L)
int r = 0; int r = 0;
if (strcasecmp(s, "in") == 0) { if (strcasecmp(s, "in") == 0) {
gpio_direction_input(io); gpio_direction_input(io);
} else if (strcasecmp(s, "out") == 0) { } else if (strcasecmp(s, "out") == 0) {
gpio_direction_output(io); gpio_direction_output(io);
} else { } else {
r = -1; r = -1;
} }

3
packages/vsky/libdsp/package.bld

@ -130,7 +130,8 @@ for (var i = 0; i < Build.targets.length; i++) {
lib.addObjects(objFiles); lib.addObjects(objFiles);
} }
Pkg.attrs.profile = "debug"; //Pkg.attrs.profile = "debug";
Pkg.attrs.profile = "release";
Pkg.attrs.exportSrc = false; Pkg.attrs.exportSrc = false;
Pkg.attrs.exportCfg = true; Pkg.attrs.exportCfg = true;

2
progs/emifwriter/writer.c

@ -10,7 +10,7 @@
* *
* eg: * eg:
* *
* loadProg('e:/dsp/libdsp/progs/emifwriter/Debug/emifwriter.out', new Array('emifwriter.out', '0x20000', 'e:/ether.out')) * loadProg('e:/dsp/libdsp/progs/emifwriter/Debug/emifwriter.out', new Array('emifwriter.out', '0x40000', 'e:/telnet.out'))
*/ */
#define BINARY_FILE "e:\\dsp\\libdsp\\progs\\spl\\spl.bin" #define BINARY_FILE "e:\\dsp\\libdsp\\progs\\spl\\spl.bin"

2
progs/sbl/.cproject

@ -82,7 +82,7 @@
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="out" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.C6000.Release.1094283561" name="Release" parent="com.ti.ccstudio.buildDefinitions.C6000.Release"> <configuration artifactExtension="out" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.C6000.Release.1094283561" name="Release" parent="com.ti.ccstudio.buildDefinitions.C6000.Release" postannouncebuildStep="build rom image" postbuildStep="..\bin\tobin.bat">
<folderInfo id="com.ti.ccstudio.buildDefinitions.C6000.Release.1094283561." name="/" resourcePath=""> <folderInfo id="com.ti.ccstudio.buildDefinitions.C6000.Release.1094283561." name="/" resourcePath="">
<toolChain id="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.ReleaseToolchain.2032259694" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.ReleaseToolchain" targetTool="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.linkerRelease.539421910"> <toolChain id="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.ReleaseToolchain.2032259694" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.ReleaseToolchain" targetTool="com.ti.ccstudio.buildDefinitions.C6000_7.4.exe.linkerRelease.539421910">
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1663162913" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList"> <option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1663162913" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">

2
progs/sbl/main.c

@ -10,7 +10,7 @@
#include "elfloader.h" #include "elfloader.h"
#define NOR_CS 0 #define NOR_CS 0
#define OFFSET (0x20000) #define OFFSET (0x40000)
uart_t uart; uart_t uart;
#pragma DATA_ALIGN (dbgbuf, 128); #pragma DATA_ALIGN (dbgbuf, 128);

80
samples/telnet/script.c

@ -6,12 +6,14 @@
#include <vsky/libdsp/lua/5.3.5/lauxlib.h> #include <vsky/libdsp/lua/5.3.5/lauxlib.h>
#include <vsky/libdsp/lua/5.3.5/lualib.h> #include <vsky/libdsp/lua/5.3.5/lualib.h>
#include <ti/ndk/inc/netmain.h>
#include <ti/ndk/inc/nettools/inc/tftpif.h>
#include <ti/ndk/inc/nettools/inc/inet.h>
#include "script.h" #include "script.h"
#if !defined(LUA_PROMPT)
#define LUA_PROMPT "> " #define LUA_PROMPT "> "
#define LUA_PROMPT2 ">> " #define LUA_PROMPT2 ">> "
#endif
#define LUA_MAXINPUT 512 #define LUA_MAXINPUT 512
@ -155,10 +157,8 @@ static int docall (lua_State *L, int narg, int nres) {
** Prints an error message, adding the program name in front of it ** Prints an error message, adding the program name in front of it
** (if present) ** (if present)
*/ */
static void l_message (const char *pname, const char *msg, struct client *sock) static void l_message (const char *msg, struct client *sock)
{ {
if (pname)
con_printf(sock, "%s: ", pname);
con_printf(sock, "%s\n", msg); con_printf(sock, "%s\n", msg);
} }
@ -173,11 +173,20 @@ static void l_print (lua_State *L, struct client *sock)
lua_getglobal(L, "print"); lua_getglobal(L, "print");
lua_insert(L, 1); lua_insert(L, 1);
if (lua_pcall(L, n, 0, 0) != LUA_OK) if (lua_pcall(L, n, 0, 0) != LUA_OK)
l_message("lua", lua_pushfstring(L, "error calling 'print' (%s)", l_message(lua_pushfstring(L, "error calling 'print' (%s)",
lua_tostring(L, -1)), sock); lua_tostring(L, -1)), sock);
} }
} }
static int report (lua_State *L, int status, struct client *sock) {
if (status != LUA_OK) {
const char *msg = lua_tostring(L, -1);
l_message( msg, sock);
lua_pop(L, 1); /* remove message */
}
return status;
}
static int __do_print(lua_State *L) static int __do_print(lua_State *L)
{ {
struct client *sock = lua_touserdata(L, lua_upvalueindex(1)); struct client *sock = lua_touserdata(L, lua_upvalueindex(1));
@ -211,28 +220,49 @@ static int __byebye(lua_State *L)
return 1; return 1;
} }
int script_repl(lua_State *L, struct client *client) static int __tftp(lua_State *L)
{ {
int status; unsigned int addr = luaL_checkinteger(L, 1);
static struct luaL_Reg meths[] = { const char *file = luaL_checkstring(L, 2);
const char *ip = luaL_checkstring(L, 3);
unsigned int uip, sz = 0;
unsigned short code;
if (lua_gettop(L) >= 4)
sz = luaL_checkinteger(L, 4);
uip = inet_addr(ip);
if (NtTftpRecv(uip, (char *)file, (void *)addr, &sz, &code) >= 0) {
lua_pushboolean(L, 1);
lua_pushinteger(L, sz);
} else {
lua_pushboolean(L, 0);
lua_pushinteger(L, code);
}
return 2;
}
static __add_builtins(lua_State *L, struct client *sock)
{
static struct luaL_Reg meth[] = {
{"print", __do_print}, {"print", __do_print},
{"bye", __byebye}, {"bye", __byebye},
{"logout", __byebye}, {"tftp", __tftp},
{NULL, NULL} {NULL, NULL}
}; };
const luaL_Reg *lib;
lua_pushlightuserdata(L, client);
lua_pushcclosure(L, __do_print, 1); for (lib = meth; lib->func; ++lib) {
lua_setglobal(L, "print"); lua_pushlightuserdata(L, sock);
lua_pushcclosure(L, lib->func, 1);
lua_setglobal(L, lib->name);
}
}
lua_pushlightuserdata(L, client); int script_repl(lua_State *L, struct client *client)
lua_pushcclosure(L, __byebye, 1); {
lua_setglobal(L, "bye"); int status;
lua_newtable(L); __add_builtins(L, client);
lua_pushlightuserdata(L, client);
luaL_setfuncs(L, meths, 1);
lua_setglobal(L, "telnet");
do { do {
status = loadline(L, client); status = loadline(L, client);
@ -241,8 +271,10 @@ int script_repl(lua_State *L, struct client *client)
status = docall(L, 0, LUA_MULTRET); status = docall(L, 0, LUA_MULTRET);
if (status == LUA_OK) if (status == LUA_OK)
l_print(L, client); l_print(L, client);
else else {
report(L, status, client);
con_printf(client, "\r\n"); con_printf(client, "\r\n");
}
} while (!con_bye(client)); } while (!con_bye(client));

3
samples/telnet/telnet.c

@ -27,7 +27,7 @@
#define OUT_OF_MEMORY "\nError: out of memory.\n\n" #define OUT_OF_MEMORY "\nError: out of memory.\n\n"
#define THREAD_ERROR "\nError: create thread failed.\n\n" #define THREAD_ERROR "\nError: create thread failed.\n\n"
#define WELCOME "\nWelcome to login.\n\n" #define WELCOME "\nWelcome to you.\n\n"
#define TELNET_CLIENT_MAX (2) #define TELNET_CLIENT_MAX (2)
#define IN_MAX (32) #define IN_MAX (32)
@ -219,6 +219,7 @@ int con_bye(struct client *c)
return c->stop; return c->stop;
} }
static void console(struct client *c) static void console(struct client *c)
{ {
lua_State *L; lua_State *L;

Loading…
Cancel
Save