chg: enhanced rtrim for command prompt.

This commit is contained in:
iceman1001 2017-12-21 10:08:07 +01:00
commit c2725bfa99
4 changed files with 14 additions and 13 deletions

View file

@ -37,10 +37,10 @@ int CmdsParse(const command_t Commands[], const char *Cmd) {
dumpCommandsRecursive(Commands, 1);
return 0;
}
char cmd_name[64];
char cmd_name[128];
int len = 0;
memset(cmd_name, 0, sizeof(cmd_name));
sscanf(Cmd, "%63s%n", cmd_name, &len);
sscanf(Cmd, "%127s%n", cmd_name, &len);
str_lower(cmd_name);
int i = 0;
while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))

View file

@ -59,7 +59,7 @@ void SendCommand(UsbCommand *c) {
or disconnected. The main console thread is alive, but comm thread just spins here.
Not good.../holiman
**/
while(txcmd_pending);
while (txcmd_pending);
txcmd = *c;
__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
@ -84,7 +84,7 @@ static void showBanner(void){
}
#endif
static bool hookUpPM3() {
bool hookUpPM3() {
bool ret = false;
sp = uart_open( comport );
if (sp == INVALID_SERIAL_PORT) {
@ -104,7 +104,7 @@ static bool hookUpPM3() {
}
// (iceman) if uart_receiver fails a command three times, we conside the device to be offline.
static void *uart_receiver(void *targ) {
void *uart_receiver(void *targ) {
struct receiver_arg *arg = (struct receiver_arg*)targ;
size_t rxlen;
bool tmpsignal;
@ -249,10 +249,11 @@ void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
// execute command
if (cmd) {
if (strlen(cmd) > 0) {
while(cmd[strlen(cmd) - 1] == ' ')
cmd[strlen(cmd) - 1] = 0x00;
}
// rtrim
size_t l = strlen(cmd);
if ( l > 0 && isspace(cmd[l - 1]))
cmd[l-1] = 0x00;
if (cmd[0] != 0x00) {
int ret = CommandReceived(cmd);

View file

@ -25,6 +25,9 @@ const char *get_my_executable_path(void);
const char *get_my_executable_directory(void);
void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present);
bool hookUpPM3(void);
void *uart_receiver(void *targ);
#ifdef __cplusplus
}
#endif

View file

@ -20,7 +20,6 @@
static int l_SendCommand(lua_State *L){
/*
*
The SendCommand (native) expects the following structure:
typedef struct {
@ -34,11 +33,9 @@ static int l_SendCommand(lua_State *L){
==> A 544 byte buffer will do.
**/
//Pop cmd
size_t size;
const char *data = luaL_checklstring(L, 1, &size);
if(size != sizeof(UsbCommand))
{
if (size != sizeof(UsbCommand)) {
printf("Got data size %d, expected %d" , (int) size,(int) sizeof(UsbCommand));
lua_pushstring(L,"Wrong data size");
return 1;