/* Copyright (C) Trampas Stern name of author This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "command.h" #include #include "vpw.h" #include "codes.h" #include "vag.h" #include "firmware.h" //for address to flash firmware //typedef UINT (*PtrComdFunc)(UINT , CHAR *[]); UINT CommandParse(CHAR *str); //DAMN CSS Compiler does not support pointer to functions //Therefore we have to be more "creative" UINT CommandExit=0; /* PtrComdFunc ptrCommands[]={ }; */ UBYTE ascii2hex(UBYTE *str) { UBYTE j; UBYTE temp,t2,shift; temp=0; for (j=0; j<2; j++) { t2=str[j]; shift=0; if (j==0) shift=4; if (t2>='a') { temp=temp | ((t2-'a'+10)<='A') { temp=temp | ((t2-'A'+10)<='0') { temp=temp | ((t2-'0')<0) CommandParse(buffer); printf("\n\r"); printf(CMD_PROMPT); buffIndex=0; buffer[buffIndex]=0; } if (data != 0x0A && data !=0x0D) { buffer[buffIndex++]=data; buffer[buffIndex]=0; } if (buffIndex>=(MAX_STRING-1)) { printf("\n\rERROR: Command buffer overflow\n\r"); buffIndex=0; buffer[0]=0; printf(CMD_PROMPT); } } } return 0; } /******************************************************************* * FUNCTION: CommandParse * AUTHOR = TRAMPAS STERN * FILE = command.c * DATE = 1/25/2004 4:03:03 PM * * PARAMETERS: Takes the command line string * * DESCRIPTION: parses the command line and returns Command ID * * RETURNS: Command ID, and * * *******************************************************************/ UINT CommandParse(CHAR *str) { CHAR *ptr; CHAR *ptr2; UINT i; CHAR cmd[MAX_STRING]; CHAR buff[MAX_CMD_LENGTH]; CHAR argv[MAX_ARGS][MAX_ARG_LENGTH]; //CHAR *ptrArgv[MAX_ARGS]; UINT numArgs; //first we need find command and arguments ptr=strchr(str,' '); //find first char if (ptr==0) { //we have two options, frist whole thing is command //second bad command if(strlen(str)>0) ptr=str+strlen(str); else return 0; //bad command } //copy string to command buffer. i=0; ptr2=str; while(ptr!=0 && ptr!=ptr2 && i<(MAX_CMD_LENGTH-1)) { buff[i++]=*ptr2++; } buff[i]=0; //now buff contains the command let's get the args numArgs=0; while(*ptr!=0 && *ptr==' ') ptr++; //increment pointer past ' ' if (*ptr!=0) { ptr2=strchr(ptr,' '); if (ptr2==0) { //we have two options, frist whole thing is command //second bad command if(strlen(ptr)>0) ptr2=ptr+strlen(ptr); } while(ptr2!=0 && numArgs0) ptr2=ptr+strlen(ptr); } } } } /* for(i=0; i>8); i<(FLASH_MAX_PAGES>>8); i++) { //sprintf(temp,"%lu",i); //LCD_print2(temp,2); //printf("Erasing Page %lu\n\r",i); if (flash_erase_page(i)!=0) return 1; } printf("Start Xmodem download to unit of Firmware"); delay_ms(250); Flash_serial_program(FIRM_FLASH_START); delay_ms(250); printf("Checking Firmware\n\r"); if (FirmwareCheck(FIRM_FLASH_START)==0) { printf("Updating Firmware\n\r"); FirmwareUpdate(FIRM_FLASH_START); }else { printf("Firmware not correct, try reloading\n\r"); } } sprintf(cmd,"isobaud"); if (strcmp(buff,cmd)==0) { printf("bps=%ld\n\r",iso_Baud()); } sprintf(cmd,"firmcheck"); if (strcmp(buff,cmd)==0) { printf("Checking Firmware\n\r"); if (FirmwareCheck(FIRM_FLASH_START)==0) { printf("Updating Firmware\n\r"); FirmwareUpdate(FIRM_FLASH_START); }else { printf("Firmware not correct, try reloading\n\r"); } } /* sprintf(cmd,"printcode"); if (strcmp(buff,cmd)==0) { UDWORD code; code=atoi32(argv[0]); PcodePrint(code); } */ sprintf(cmd,"exit"); if (strcmp(buff,cmd)==0) { return 0; } /* sprintf(cmd,"codes"); if (strcmp(buff,cmd)==0) { obdII_codes(); } sprintf(cmd,"clearcodes"); if (strcmp(buff,cmd)==0) { obdII_clear_codes(); } sprintf(cmd,"knob"); if (strcmp(buff,cmd)==0) { printf("Knob is %d\n\r",knob); } */ return 0; //unknown command }