JLC test

Dependencies:   PinDetect libmDot mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
tmulrooney
Date:
Wed Jan 27 00:57:12 2016 +0000
Parent:
0:6aa743a332ae
Child:
2:376af6a70e8a
Commit message:
added CLI interface to I2C and SPI

Changed in this revision

commandline.cpp Show annotated file Show diff for this revision Revisions of this file
common.h Show annotated file Show diff for this revision Revisions of this file
globals.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
utilities.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commandline.cpp	Wed Jan 27 00:57:12 2016 +0000
@@ -0,0 +1,1037 @@
+/* ========================================
+ * Filename: commandLine.c
+ *
+ * Description: functions and operations needed for  command line operation
+ *
+ * Copyright J-Factor Embedded Technologies 2015
+ * Copyright TJM Embedded Software 2015
+ * All Rights Reserved
+ * UNPUBLISHED, LICENSED SOFTWARE.
+ *
+ * CONFIDENTIAL AND PROPRIETARY INFORMATION
+ * WHICH IS THE PROPERTY OF J-Factor Embedded Technologies.
+ *
+ * ========================================
+*/
+//#include <project.h>
+#include "mbed.h"
+#include "stdio.h"
+#include "common.h"
+
+/** \file
+ * \brief command line - contains all functions related to the command line.
+ */
+
+/* externals */
+
+/* Globals */
+char line[LINE_SIZE];                       //!< character array read 
+char lastLine[NUM_LINES][LINE_SIZE];        //!< array of previous command lines
+int8 indexNextLineIn = 0;                   //!< index of next position to save current command line
+int8 indexNextLineOut = 0;                  //!< index of next position to read out saved comman dlines
+int8 linesInBuffer = 0;                     //!< number of lines in  command line buffer
+uint8 enableCLI = 1;
+uint8 escapeSeen = 0;                       //!< escape character seen
+int8 charCount;                            //!< number of characters in the current command line
+int8 cursorPosition;                       //!< current cursor position in the current command line
+char TransmitBuffer[TRANSMIT_BUFFER_SIZE];  //!< charaters to be sent to the console
+uint8 ptrCmd = 0;
+uint8 binaryParameter;                      //!< result of any 8 bit integer read operation
+uint16 digitalParameter;                    //!< result of any 16 bit integer read operation
+float analogParameter;                      //!< result of any floating point read operation
+char *validCmds[] = {"help","version","read","readReg","write","writeReg","info","find","run","stop","date","hvstate"};    //!< array of valid commands - case insensitive    
+uint16 regAddress;
+uint16 regLength;
+uint8 regData[MAX_REGISTER_DATA];
+
+/** 
+ * \fn getLine
+ *
+ * \brief Reads characters from UART and retuns a line when new line seen.
+ * if enableCLI == 1 - process input characters<p>
+ * if enableCLI == 0 - return 0<p>
+ *
+ * will call UART_1_CetChar() to get the next character.<p>
+ * if ch == 0 - no character available<p>
+ * if ch != 0 - add ch to line array<p>
+ * features: <p>
+ * up arrow will go through last NUM_LINES commands. <p>
+ * backspace will remove last typed character<p>
+ *
+ * \return uint8 - 0 - no character ready or line not finished, 1 - line complete (CR seen)<p>
+ *
+ */
+uint8 getLine()
+{
+     /* Variable to store UART received character */
+    uint8 ch,i;
+    
+    /* check if CLI enabled */
+    if(enableCLI == 0)
+        return 0;
+    
+    /* Non-blocking call to get the latest data recieved  */
+    if(pc.readable())
+        ch = pc.getc();
+    else
+        ch = '\0';
+        
+    /* Set flags based on UART command */
+    switch(ch)
+    {
+        case 0:
+            /* No new data was recieved */
+            return 0;
+         
+        case 0x1B:                      /* up arrow seen */
+            escapeSeen = 1;
+            break;
+        
+        case '\n':                      /* new line seen */
+        case '\r':
+            pc.printf("\r\n");
+            line[charCount] = '\0';
+            charCount = 0;
+            cursorPosition = charCount;
+            escapeSeen = 0;
+            if(strlen(line) > 0)
+            {
+                strcpy(&lastLine[indexNextLineIn][0],line); /* save current command line in  buffer */
+                if(linesInBuffer < NUM_LINES)
+                    linesInBuffer++;
+                indexNextLineIn++;                          /* point to next free space in command line buffer */
+                if(indexNextLineIn == NUM_LINES - 1)        /* wrap around if past end */
+                    indexNextLineIn = 0;
+                indexNextLineOut = indexNextLineIn;
+            }
+            return 1;
+            
+        default:
+//            sprintf(TransmitBuffer,"char: %02X %c  charCount: %d\r\n",ch,ch,charCount);
+//            UART_1_PutString(TransmitBuffer);
+            if( (escapeSeen == 1) && (ch == '[') )
+            {
+                escapeSeen++;
+                break;
+            }
+            else if( (escapeSeen == 2) && (ch == 'A') )      /* look for up arrow escape sequence */
+            {
+                if(linesInBuffer == 0)
+                    break;
+                indexNextLineOut--;                     /* point to last line in */
+                if(indexNextLineOut < 0)                /* check if wrap around */
+                {
+                    if(linesInBuffer < NUM_LINES)
+                        indexNextLineOut = linesInBuffer -1;
+                    else
+                        indexNextLineOut = NUM_LINES - 1;
+                }
+                strcpy(line,&lastLine[indexNextLineOut][0]); /* copy command line from buffer to command line */
+                charCount = strlen(line);
+                cursorPosition = charCount;
+                escapeSeen = 0;
+                pc.printf("\r");
+                for (i=0;i<sizeof(line);i++)                 /* clear line of last command */
+                    pc.printf(" ");
+                sprintf(TransmitBuffer,"\r%s cmd>%s",time_string,line);    /* restore with selected command */
+                pc.printf(TransmitBuffer);
+                break;
+            }
+            else if( (escapeSeen == 2) && (ch == 'D') )      /* look for left arrow escape sequence */
+            {
+                if( cursorPosition > 0 )
+                {
+                    pc.printf("\b");
+                    cursorPosition--;
+                }
+                escapeSeen = 0;
+                break;
+            }
+            else if( (escapeSeen == 2) && (ch == 'C') )      /* look for right arrow escape sequence */
+            {
+                if( cursorPosition < charCount )
+                {
+                    sprintf(TransmitBuffer,"%c",line[cursorPosition]);
+                    pc.printf(TransmitBuffer);
+                    cursorPosition++;
+                }
+                escapeSeen = 0;
+                break;
+            }
+            else if( (ch == 0x7F) || (ch == '\b') )  /* backspace seen */
+            {
+                if( (charCount > 0) && (charCount == cursorPosition) )
+                {
+                    pc.printf("\b \b");
+                    charCount--;
+                    cursorPosition = charCount;
+                    line[charCount] = '\0';
+                }
+            }
+            else
+            {
+                if(charCount < (LINE_SIZE - 1))
+                {
+                    sprintf(TransmitBuffer,"%c",ch);
+                    pc.printf(TransmitBuffer);
+                    if(charCount != cursorPosition)         /* move characters at cursor up to fit in new character */
+                    {
+                        for(i = charCount ; i > cursorPosition; i--)
+                            line[i] = line[i-1];
+                        line[cursorPosition] = ch;
+                        line[++charCount] = '\0';
+                        for (i=cursorPosition + 1;i<charCount;i++) 
+                        {
+                            sprintf(TransmitBuffer,"%c",line[i]);
+                            pc.printf(TransmitBuffer);
+                        }
+                        cursorPosition = charCount;
+                    }
+                    else
+                    {
+                        line[charCount++] = ch;
+                        cursorPosition = charCount;
+                    }
+                 }
+            }
+            break;    
+    }
+    return 0;
+}
+
+
+/** 
+ * \fn executeCmd
+ *
+ * \brief executes the command in line array.
+ *
+ * calls getCmd to parse command and then switches to proper command handler.
+ * command list kept short for simplicity.<p>
+ * read, write, and info command will read and verify parametsr on  command line.
+ * \return None<p>
+ *
+ */
+void executeCmd()
+{
+    int8 cmd;
+    uint8 type,i;
+    int32 convertFloat1,convertFloat2;
+    float floatValue;
+    int value,num, pos;
+    char str[40] = "", str2[40] = "";
+    uint8 statusRegister;
+    
+    cmd = getCmd();
+//    sprintf(TransmitBuffer,"cmd: %d ptrCmd: %d\r\n",cmd,ptrCmd);
+//    UART_1_PutString(TransmitBuffer);
+    
+    /* execute command */
+    switch (cmd)
+    {
+        case HELP:
+            pc.printf("Valid Commands (case insensitive)\r\n");
+            pc.printf("find [string] - find all parameters or all parameters that contain the string\r\n");
+            pc.printf("help - display list of valid commands\r\n");
+            pc.printf("info [parameter]- display info on all or parameter\r\n");
+            pc.printf("read parameter - read value of parameter\r\n");
+            pc.printf("readReg parameter register length - read N values from parameter registers\r\n");
+            pc.printf("version - display version information\r\n");
+            pc.printf("write parameter register value - write value to parameter register\r\n");
+            pc.printf("writeReg parameter value - write value to parameter\r\n");
+            pc.printf("run - start control running\r\n");
+            pc.printf("stop - stop control running\r\n");
+            pc.printf("date [date string]- display/set current time and date\r\n");
+            pc.printf("hvstate - current HV status\r\n");
+            break;
+           
+        case DATE:
+            num = sscanf(&line[ptrCmd],"%s",str);       /* optional parameter on the command line - date string */
+            if(num > 0)
+            {
+                setDate(&line[ptrCmd]);
+            }
+            date();
+            sprintf(TransmitBuffer,"current time is %s\r\n",c_time_string);
+            pc.printf(TransmitBuffer);
+            break;
+             
+        case VERSION:
+            printVersion();
+//            sprintf(TransmitBuffer,"PSK15-5 CSE: V%d.%02d %s\r\n",VERSION_MAJOR,VERSION_MINOR,VERSION_DATE);
+//            UART_1_PutString(TransmitBuffer);
+//            sprintf(TransmitBuffer,"Built on: %s %s\r\n",__DATE__,__TIME__);
+//            UART_1_PutString(TransmitBuffer);
+            break;
+          
+        case READ:
+            num = sscanf(&line[ptrCmd],"%s",str);       /* expecting one parameter on the command line - parameter name */
+            if(num == 1)
+            {
+                num = getParameter(str);                /* get paramter position in parameters array from paramter name */
+                if (num >= 0)
+                {
+                    type = readParam(num);              /* read paramter value and return parameter type */
+                    if(type == BINARY)
+                    {
+                        sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,binaryParameter,parameters[num].uints);
+                    }
+                    else if(type == DIGITAL)
+                    {
+                        sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,digitalParameter,parameters[num].uints);
+                    }
+                    else if(type == ANALOG)
+                    {
+                        convertFloat1 = analogParameter * 100.0;
+                        sprintf(TransmitBuffer,"%s: %ld.%02ld %s\r\n",parameters[num].name,convertFloat1/100,convertFloat1%100,parameters[num].uints);
+                    }
+                     pc.printf(TransmitBuffer);
+                }
+                else
+                {
+                    sprintf(TransmitBuffer,"Invalid parameter\r\nType help for list of valid parameters\r\n");
+                    pc.printf(TransmitBuffer);
+               }
+            }
+            else
+            {
+                sprintf(TransmitBuffer,"Missing parameter\r\nformat: read parameter\r\n");
+                pc.printf(TransmitBuffer);
+           }
+            break;
+         
+        case READ_REG:
+            num = sscanf(&line[ptrCmd],"%s %X %X",str, &regAddress, &regLength); 
+            if(num < 0)
+            {
+                sprintf(TransmitBuffer,"Missing parameter\r\nformat: read parameter [Reg Address (hex)] [Length (hex)]\r\n");
+                pc.printf(TransmitBuffer);
+                return;
+            }
+            pos = getParameter(str);                /* get paramter position in parameters array from paramter name */
+            if(pos == -1)
+            {
+                sprintf(TransmitBuffer,"Invalid parameter\r\nType help for list of valid parameters\r\n");
+                pc.printf(TransmitBuffer);
+                return;
+           }
+            switch(num)
+            {
+                 case 1:
+                    regAddress = 0;
+                    regLength = 1;
+                    break;
+               
+                case 2:
+                     regLength = 1;
+                    break;
+               
+                case 3:
+                     break;
+           
+            }
+            type = readParam(pos);              /* read paramter value and return parameter type */
+            for(i=0; i< bytesRead; i++)
+            {
+                if( i == 0 )
+                    pc.printf("%04X ",regAddress);
+                else if( (i % 0x10) == 0 )
+                    pc.printf("\r\n%04X ",regAddress + i);
+                pc.printf("%02X ",regData[i]);
+            }
+            pc.printf("\r\n");
+            break;
+ #if 0       
+        case WRITE:
+            floatValue = 0.0;
+            num = sscanf(&line[ptrCmd],"%s %s",str,str2);       /* expecting two parameters on the command line - parameter name and parameter value */
+            if(num == 2)
+            {
+                num = getParameter(str);                        /* get paramter position in parameters array from paramter name */
+                if (num >= 0)
+                {
+                    type = readParam(num);                      /* read paramter value and return parameter type */
+                    if(type == ANALOG)
+                    {
+                        floatValue = strtofloat(str2);          /* paramters name and floating point number */
+                    }
+                    else
+                    {
+                        sscanf(&line[ptrCmd],"%s %d",str,&value);   /* parameters name and integer value */
+                    }
+                    if(type == BINARY)
+                    {
+                        if(value > parameters[num].maxInt)
+                        {
+                           sprintf(TransmitBuffer,"%d exceeds maximum value %d\r\n",value,parameters[num].maxInt);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,binaryParameter,parameters[num].uints);
+                        }
+                    }
+                    else if(type == DIGITAL)
+                    {
+                        if(value > parameters[num].maxInt)
+                        {
+                           sprintf(TransmitBuffer,"%d %s exceeds maximum value %d %s\r\n",value,parameters[num].uints,parameters[num].maxInt,parameters[num].uints);
+                        }
+                        else if(value < parameters[num].minInt)
+                        {
+                           sprintf(TransmitBuffer,"%d %s less than minimum value %d %s\r\n",value,parameters[num].uints,parameters[num].minInt,parameters[num].uints);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,digitalParameter,parameters[num].uints);
+                        }
+                    }
+                    else if(type == ANALOG)
+                    {
+                        if(floatValue > parameters[num].maxFloat)
+                        {
+                            convertFloat1 = floatValue * 100;
+                            convertFloat2 = parameters[num].maxFloat * 100;
+                            sprintf(TransmitBuffer,"%ld.%02ld %s exceeds maximum value %ld.%02ld %s\r\n",convertFloat1/100,convertFloat1%100,parameters[num].uints,convertFloat2/100,convertFloat2%100,parameters[num].uints);
+                        }
+                        else if(floatValue < parameters[num].minFloat)
+                        {
+                            convertFloat1 = floatValue * 100;
+                            convertFloat2 = parameters[num].minFloat * 100;
+                            sprintf(TransmitBuffer,"%ld.%02ld %s is less than value %ld.%02ld %s\r\n",convertFloat1/100,convertFloat1%100,parameters[num].uints,convertFloat2/100,convertFloat2%100,parameters[num].uints);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            convertFloat1 = analogParameter * 100;
+                            sprintf(TransmitBuffer,"%s: %ld.%02ld %s\r\n",parameters[num].name,convertFloat1/100,convertFloat1%100,parameters[num].uints);
+                        }
+                    }
+                     pc.printf(TransmitBuffer);
+                }
+                else
+                {
+                    pc.printf("Invalid parameter\r\nType help for list of valid parameters\r\n");
+                }
+            }
+            else
+            {
+                pc.printf("Missing parameter(s)\r\nformat: write parameter value\r\n");
+            }
+            break;
+ #endif       
+        case WRITE_REG:
+             num = sscanf(&line[ptrCmd],"%s %X %X",str, &regAddress, &regData); 
+            if(num != 3)
+            {
+                pc.printf("Missing parameter\r\nformat: write parameter Reg Address (hex) Value (hex)\r\n");
+                return;
+            }
+            pos = getParameter(str);                /* get paramter position in parameters array from paramter name */
+             if(pos == -1)
+            {
+                sprintf(TransmitBuffer,"Invalid parameter\r\nType help for list of valid parameters\r\n");
+                pc.printf(TransmitBuffer);
+                return;
+           }
+           writeParam(pos,regData);              /* write paramter value and return parameter type */
+            regLength = 1;
+            readParam(pos);
+            for(i=0; i< bytesRead; i++)
+            {
+                if( i == 0 )
+                    pc.printf("%04X ",regAddress);
+                else if( (i % 0x10) == 0 )
+                    pc.printf("\r\n%04X ",regAddress + i);
+                pc.printf("%02X ",regData[i]);
+            }
+            pc.printf("\r\n");
+            break;
+#if 0
+           floatValue = 0.0;
+            num = sscanf(&line[ptrCmd],"%s %s",str,str2);       /* expecting two parameters on the command line - parameter name and parameter value */
+            if(num == 2)
+            {
+                num = getParameter(str);                        /* get paramter position in parameters array from paramter name */
+                if (num >= 0)
+                {
+                    type = readParam(num);                      /* read paramter value and return parameter type */
+                    if(type == ANALOG)
+                    {
+                        floatValue = strtofloat(str2);          /* paramters name and floating point number */
+                    }
+                    else
+                    {
+                        sscanf(&line[ptrCmd],"%s %d",str,&value);   /* parameters name and integer value */
+                    }
+                    if(type == BINARY)
+                    {
+                        if(value > parameters[num].maxInt)
+                        {
+                           sprintf(TransmitBuffer,"%d exceeds maximum value %d\r\n",value,parameters[num].maxInt);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,binaryParameter,parameters[num].uints);
+                        }
+                    }
+                    else if(type == DIGITAL)
+                    {
+                        if(value > parameters[num].maxInt)
+                        {
+                           sprintf(TransmitBuffer,"%d %s exceeds maximum value %d %s\r\n",value,parameters[num].uints,parameters[num].maxInt,parameters[num].uints);
+                        }
+                        else if(value < parameters[num].minInt)
+                        {
+                           sprintf(TransmitBuffer,"%d %s less than minimum value %d %s\r\n",value,parameters[num].uints,parameters[num].minInt,parameters[num].uints);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            sprintf(TransmitBuffer,"%s: %d %s\r\n",parameters[num].name,digitalParameter,parameters[num].uints);
+                        }
+                    }
+                    else if(type == ANALOG)
+                    {
+                        if(floatValue > parameters[num].maxFloat)
+                        {
+                            convertFloat1 = floatValue * 100;
+                            convertFloat2 = parameters[num].maxFloat * 100;
+                            sprintf(TransmitBuffer,"%ld.%02ld %s exceeds maximum value %ld.%02ld %s\r\n",convertFloat1/100,convertFloat1%100,parameters[num].uints,convertFloat2/100,convertFloat2%100,parameters[num].uints);
+                        }
+                        else if(floatValue < parameters[num].minFloat)
+                        {
+                            convertFloat1 = floatValue * 100;
+                            convertFloat2 = parameters[num].minFloat * 100;
+                            sprintf(TransmitBuffer,"%ld.%02ld %s is less than value %ld.%02ld %s\r\n",convertFloat1/100,convertFloat1%100,parameters[num].uints,convertFloat2/100,convertFloat2%100,parameters[num].uints);
+                        }
+                        else
+                        {
+                            writeParam(num,value,floatValue);
+                            type = readParam(num);
+                            convertFloat1 = analogParameter * 100;
+                            sprintf(TransmitBuffer,"%s: %ld.%02ld %s\r\n",parameters[num].name,convertFloat1/100,convertFloat1%100,parameters[num].uints);
+                        }
+                    }
+                     pc.printf(TransmitBuffer);
+                }
+                else
+                {
+                    pc.printf("Invalid parameter\r\nType help for list of valid parameters\r\n");
+                }
+            }
+            else
+            {
+                pc.printf("Missing parameter(s)\r\nformat: write parameter value\r\n");
+            }
+            break;
+#endif
+#if 0       
+        case INFO:
+            num = sscanf(&line[ptrCmd],"%s",str);       /* expecting one parameter on the command line - parameter name */
+            if(num == 1)
+            {
+                num = getParameter(str);                /* get paramter position in parameters array from paramter name */
+                if (num >= 0)
+                {
+         //           type = readParam(num);
+                    displayParameter(num);
+                }
+                else
+                {
+                    UART_1_PutString("Invalid parameter\r\nType help for list of valid parameters\r\n");
+                }
+            }
+            else
+            {
+//                for(i=0;strcmpi(parameters[i].name,"end") != 0;i++)
+                for(i=0;strcasecmp(parameters[i].name,"end") != 0;i++)
+                    displayParameter(i);
+            }
+            break;
+       
+        case FIND:
+            num = sscanf(&line[ptrCmd],"%s",str);       /* expecting one parameter on the command line - parameter name */
+            if(num == 1)
+            {
+                num = findParameter(str);                /* get paramter position in parameters array from paramter name */
+                if (num < 0)
+                {
+                    sprintf(TransmitBuffer,"String %s not found in any parameter name\r\n",str);
+                    UART_1_PutString(TransmitBuffer);
+                }
+            }
+            else
+            {
+                UART_1_PutString("\r\nValid Paramters\r\n");
+    
+                /* print parameter list */
+//                for(i=0;strcmpi(parameters[i].name,"end") != 0;i++)
+                for(i=0;strcasecmp(parameters[i].name,"end") != 0;i++)
+                {
+                    sprintf(TransmitBuffer,"%s\r\n",parameters[i].name);
+                    UART_1_PutString(TransmitBuffer);   
+                }
+            }
+            break;
+            
+        case RUN:
+                if(runStatus == TRUE)
+                {
+                    sprintf(TransmitBuffer,"%s Control already Running\r\n",time_string);
+                    UART_1_PutString(TransmitBuffer);  
+                }
+                else
+                {
+                    runStatus = TRUE;
+                    lampTestStatus = LAMPTESTNOTRUN;
+                    sprintf(TransmitBuffer,"%s Control Running\r\n",time_string);
+                    UART_1_PutString(TransmitBuffer);   
+                }
+                break;
+            
+        case STOP:
+                if(runStatus == FALSE)
+                {
+                    sprintf(TransmitBuffer,"%s Control already Stopped\r\n",time_string);
+                    UART_1_PutString(TransmitBuffer);   
+                }
+                else
+                {
+                    runStatus = FALSE;
+                    sprintf(TransmitBuffer,"%s Control Stopped\r\n",time_string);
+                    UART_1_PutString(TransmitBuffer);   
+                    phaseUV = (PHASE_AB_UV_Read() << 0);
+                    phaseUV |= (PHASE_AC_UV_Read() << 1);
+                    phaseUV |= (PHASE_BC_UV_Read() << 2);
+                    statusRegister = STATUS_REGISTER1_ReadMask();
+                    statusRegister |= (PHASEABUVIN | PHASEBCUVIN | PHASEACUVIN);
+                    STATUS_REGISTER1_INT_ClearPending();
+                    STATUS_REGISTER1_WriteMask(statusRegister);
+                    HVState = HVSTATEOFF;
+                    eStopSeen = FALSE;
+                    outputOCSeen = FALSE;
+                    HVStateMsg = 0;                 /* no messages printed yet */
+                    flashCtrlSys = 0;
+                    tempFailed = FALSE;
+                    pendantTestStatus = 0;
+                    pendantPresent = FALSE;
+                    waitForPowerCycle = FALSE;
+                    PEND_PRESENT_NOT_INT_Stop();
+                    SOFT_START_RELAY_CTRL_Write(0);
+                    PWM_DC_Stop();
+                    statusRegister = STATUS_REGISTER1_ReadMask();
+                    statusRegister &= ~(BRIDGEOCFLAGIN | OUTPUTOCFLAGIN | UTILOCFLAGIN  );
+                    STATUS_REGISTER1_WriteMask(statusRegister);
+                    ENCODER_COUNTER_Stop();
+                    initializeAllParameters();
+writeCurrent0(0.0);                               /* test prurposes only */
+                }
+                break;
+                
+        case HVSTATE:
+            sprintf(TransmitBuffer,"%s HV State: %02X\r\n",time_string,HVState);
+            UART_1_PutString(TransmitBuffer);
+            printHVState();
+            break;
+            #endif
+           
+        default:
+            if(strlen(line) !=0)
+            {
+                sprintf(TransmitBuffer,"Unknown cmd: %s\r\nType help for list of valid commands\r\n",line);
+                pc.printf(TransmitBuffer);
+//                linesInBuffer--;
+//                indexNextLineIn--;
+//                if(linesInBuffer == NUM_LINES)
+//                    indexNextLineIn = NUM_LINES -1;
+            }
+            break;
+     }
+    for(i=0;i < sizeof(line);i++)
+        line[i] = '\0';
+}
+
+/** 
+ * \fn getCmd
+ *
+ * \brief parses command line to find position of command in validCmds array.
+ *
+ * copies line array into cmd array until a space or end of line then
+ * searches cmd array for a match in validCmds array.
+ * \return int8 - position of command in command array if found. -1 if not found<p>
+ *
+ */
+int8 getCmd()
+{
+    uint i;
+    char cmd[40];
+    
+    for(i=0;i<strlen(line);i++)
+    {
+        if(line[i] == ' ')
+        {
+            break;
+        }
+        cmd[i] = line[i];
+    }
+    cmd[i] = '\0';
+    ptrCmd = strlen(cmd) + 1;
+//    sprintf(TransmitBuffer,"cmd: %d %s\r\n",strlen(cmd),cmd);
+//    UART_1_PutString(TransmitBuffer);
+    
+    for(i=0;i< sizeof(validCmds)/sizeof(validCmds[0]);i++)
+    {
+//        if(strcmpi(validCmds[i],cmd) == 0)
+        if(strcasecmp(validCmds[i],cmd) == 0)
+        {
+            return i;
+        }
+    }
+    return -1;
+}
+
+/** 
+ * \fn int8 getParameter(char *param)
+ *
+ * \brief searches parameters array to find position of command in parameters array.
+ *
+ * searches the entire parameters array for a name match with param.
+ *
+ * \param[in] param - pointer to an array containing the parameter name.
+ *
+ * \return int8 - position of command in command array if found. -1 if not found<p>
+ *
+ */
+int8 getParameter(char *param)
+{
+    uint i;
+    
+ //   sprintf(TransmitBuffer,"param: %d %s\r\n",strlen(param),param);
+ //   pc.printf(TransmitBuffer);
+    
+    for(i=0;strcasecmp(parameters[i].name,"end") != 0;i++)
+    {
+        if(strcasecmp(parameters[i].name,param) == 0)
+        {
+            return i;
+        }
+    }
+    return -1;
+}
+
+/** 
+ * \fn int8 findParameter(char *string)
+ *
+ * \brief finds all parameters with string in the name.
+ *
+ * searches the entire parameters array for all names 
+ * that contain string.
+ *
+ * \param[in] string - pointer to a string.
+ *
+ * \return int8 - 0 string found in some names. -1 if string not found in any name<p>
+ *
+ */
+int8 findParameter(char *string)
+{
+    uint i,j;
+    int8 result = -1;
+    char name[40];
+    char string1[40];
+    
+//    sprintf(TransmitBuffer,"param: %d %s\r\n",strlen(param),param);
+//    UART_1_PutString(TransmitBuffer);
+   
+    strcpy(string1,string);
+    for(i=0;i < strlen(string1);i++)
+        string1[i] = tolower((unsigned char)string1[i]);
+        
+//    for(i=0;strcmpi(parameters[i].name,"end") != 0;i++)
+    for(i=0;strcasecmp(parameters[i].name,"end") != 0;i++)
+    {
+        strcpy(name,parameters[i].name);        /* copy parameter name and convert to lower case */
+        for(j=0;j < strlen(name);j++)
+            name[j] = tolower((unsigned char)name[j]);
+        if(strstr(name,string1) != NULL)
+        {
+            sprintf(TransmitBuffer,"%s\r\n",parameters[i].name);
+            pc.printf(TransmitBuffer);
+            result = 0;
+        }
+    }
+    return result;
+}
+
+/** 
+ * \fn uint8 readParam(uint8 paramNum)
+ *
+ * \brief reads in parameter at position paramNum.
+ *
+ * This will only be called if there was a valid parameter match found.
+ * will read correct parameter based on parameter type. This will call the
+ * correct read function specified in the paramter array. A parameter will be
+ * read into one of binaryParameter, digitalParameter, or analogParameter based on type.
+ *
+ * \param[in] paramNum - pointer to a character string containing  parameter name
+ * \return uint8 - type of parameter<p>
+ *
+ */
+uint8 readParam(uint8 paramNum)
+{
+    uint8 type =  parameters[paramNum].type;
+    
+    if(type == BINARY)
+    {
+        if(parameters[paramNum].ptrRead == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL ptrRead parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+            binaryParameter = 0;
+        }
+        else
+            binaryParameter = parameters[paramNum].ptrRead();
+        return type;
+    }
+    if(type == ANALOG)
+    {
+        if(parameters[paramNum].ptrRead == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL ptrRead parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+            analogParameter = 0.0;
+        }
+        else
+            parameters[paramNum].ptrRead();
+        return type;
+    }
+    if(type == DIGITAL)
+    {
+        if(parameters[paramNum].ptrRead == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL ptrRead parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+            digitalParameter = 0;
+        }
+        else
+            parameters[paramNum].ptrRead();
+        return type;
+    }
+    if(type == REGISTER)
+    {
+        bytesRead = 0;
+        if(parameters[paramNum].ptrReadRegLength == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL ptrReadRegLength parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+            digitalParameter = 0;
+        }
+        else
+            bytesRead = parameters[paramNum].ptrReadRegLength(regAddress, regData, regLength);
+        return type;
+    }
+    return type;
+}
+
+/** 
+ * \fn void writeParam(uint8 paramNum,uint16 value, float floatValue)
+ *
+ * \brief reads in parameter at position paramNum.
+ *
+ * This will only be called if there was a valid parameter match found.
+ * will write value to the correct parameter based on parameter type. This will call the
+ * correct write function specified in the paramter array. value will not be written
+ * to read only paramters.
+ *
+ * \param[in] paramNum - pointer to a character string containing the parameter name
+ * \param[in] value - 16 bit value to write to a digital parameter.
+ * \param[in] floatValue - analog value to write to an anlog parameter.
+ * \return uint8 - type of parameter<p>
+ *
+ */
+void writeParam(uint8 paramNum,uint8 *value)
+{   
+    uint8 type =  parameters[paramNum].type;
+     if(parameters[paramNum].mode == READONLY)
+    {
+            sprintf(TransmitBuffer,"%s is a read only parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+            return;
+    }
+   #if 0    
+    if(type == BINARY)
+    {
+        if(parameters[paramNum].ptrWrite8 == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL pteWrite8 parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+        }
+        else
+            parameters[paramNum].ptrWrite8(value);
+    }
+    else if(type == DIGITAL)
+    {
+        if(parameters[paramNum].ptrWrite16 == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL pteWrite16 parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+        }
+        else
+            parameters[paramNum].ptrWrite16(value);
+    }
+    #endif
+    else if(type == REGISTER)
+    {
+        if(parameters[paramNum].ptrWriteReg8 == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL ptrWriteReg8 parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+        }
+        else
+            parameters[paramNum].ptrWriteReg8(regAddress, value);
+    }
+    #if 0
+    else if(type == ANALOG)
+    {
+        if(parameters[paramNum].ptrWriteAnalog == NULL)
+        {
+            sprintf(TransmitBuffer,"%s has a NULL pteWriteAnalog parameter\r\n",parameters[paramNum].name);
+            pc.printf(TransmitBuffer);
+        }
+        else
+            parameters[paramNum].ptrWriteAnalog(floatValue);
+    }
+    #endif
+        return;
+}
+
+/** 
+ * \fn void displayParameter(uint8 num)
+ *
+ * \brief displays information about a parameter
+ *
+ * This routine all of the information in the parameters array
+ * for the selected parameter.
+ *
+ * \param[in] num - 8 bit integer location in the parameters array 
+  * \return uint16 - 16 bit num to the power pow<p>
+ *
+ */
+void displayParameter(uint8 num)
+{
+    char *strType;
+    char *strMode;
+    uint16 convertFloat1,convertFloat2,convertFloat3;
+    
+    switch (parameters[num].type)
+    {
+        case BINARY:
+            strType = "Binary";
+            break;
+          
+        case DIGITAL:
+            strType = "16 Bit";
+            break;
+        
+        case ANALOG:
+            strType = "Analog";
+            break;
+        
+        default:
+            strType = "Unknown";
+            break;
+    }
+    
+    switch (parameters[num].mode)
+    {
+        case READONLY:
+            strMode = "Read Only";
+            break;
+        
+        case READWRITE:
+            strMode = "Read/Write";
+            break;
+        
+        case WRITEONLY:
+            strMode = "Write Only";
+            break;
+        
+        default:
+            strMode = "Unknown";
+            break;
+    }
+    
+    sprintf(TransmitBuffer,"Name:\t'%s' Port: '%s' Connector: '%s' Units: '%s'\r\n",parameters[num].name,parameters[num].port,parameters[num].connector,parameters[num].uints);
+    pc.printf(TransmitBuffer);   
+    sprintf(TransmitBuffer,"\tDescription: '%s'\r\n",parameters[num].description);
+    pc.printf(TransmitBuffer); 
+    
+    if(parameters[num].type != ANALOG)
+    {
+        sprintf(TransmitBuffer,"\tType: '%s' mode: '%s' Initial: %d Min: %d Max: %d\r\n",strType,strMode,parameters[num].initialInt,parameters[num].minInt,parameters[num].maxInt);
+        pc.printf(TransmitBuffer);   
+    }
+    else
+    {
+        convertFloat1 = parameters[num].initialFloat * 100;
+        convertFloat2 = parameters[num].minFloat * 100;
+        convertFloat3 = parameters[num].maxFloat * 100;
+        sprintf(TransmitBuffer,"\tType: '%s' mode: '%s' Initial: %d.%02d Min: %d.%02d Max: %d.%02d\r\n",strType,strMode,convertFloat1/100,convertFloat1%100,convertFloat2/100,convertFloat2%100,convertFloat3/100,convertFloat3%100);
+        pc.printf(TransmitBuffer);   
+    }
+}
+
+uint16 readSPIReg(uint16 regAddress, uint8 *regData, uint16 length)
+{
+    
+//    sprintf(TransmitBuffer,"read SPI %02X %04X\r\n",regAddress, length);
+//    pc.printf(TransmitBuffer); 
+    if(length > MAX_REGISTER_DATA)
+    {
+        sprintf(TransmitBuffer,"Length 0x%X > 0x%X",length,MAX_REGISTER_DATA);
+        pc.printf(TransmitBuffer);   
+      return 0;
+    }  
+    SPIRead(regAddress,regData,length);
+    return(length);
+}
+
+void writeSPIReg(uint16 regAddress, uint8 *regData)
+{
+    sprintf(TransmitBuffer,"write SPI %02X %02X\r\n",regAddress, regData[0]);
+    pc.printf(TransmitBuffer); 
+    SPIWrite(regAddress, regData,1);
+    return;
+}
+
+uint16 readI2CReg(uint16 regAddress, uint8 *regData, uint16 length)
+{
+    
+//    sprintf(TransmitBuffer,"read I2C %02X %04X\r\n",regAddress, length);
+//    pc.printf(TransmitBuffer); 
+    if(length > MAX_REGISTER_DATA)
+    {
+        sprintf(TransmitBuffer,"Length 0x%X > 0x%X",length,MAX_REGISTER_DATA);
+        pc.printf(TransmitBuffer);   
+      return 0;
+    }  
+    I2CRead(regAddress,regData,length);
+    return(length);
+}
+
+
+void writeI2CReg(uint16 regAddress, uint8 *regData)
+{
+    sprintf(TransmitBuffer,"write I2C %02X %02X\r\n",regAddress, regData[0]);
+    pc.printf(TransmitBuffer); 
+    I2CWrite(regAddress, regData,1);
+    return;
+}
+
+/* [] END OF FILE */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common.h	Wed Jan 27 00:57:12 2016 +0000
@@ -0,0 +1,151 @@
+/* ========================================
+ * Filename: common.h
+ *
+ * Description: common defintions and structures
+ *
+ * Copyright J-Factor Embedded Technologies 2015
+ * Copyright TJM Embedded Software 2015
+ * All Rights Reserved
+ * UNPUBLISHED, LICENSED SOFTWARE.
+ *
+ * CONFIDENTIAL AND PROPRIETARY INFORMATION
+ * WHICH IS THE PROPERTY OF J-Factor Embedded Technologies.
+ *
+ * ========================================
+*/
+/** \file
+ * \brief contains constants and prototypes needed by other files.
+ */
+#ifndef COMMON_H
+#define COMMON_H
+ 
+#include <time.h>
+#include "mbed.h"
+ 
+/* Project Defines */
+#define FALSE  0
+#define TRUE   1
+#define TRANSMIT_BUFFER_SIZE  80    //!< maximum number of characters to write to console
+#define LINE_SIZE  80               //!< maximum number of characters to read from console
+#define NUM_LINES 10                //!< number of command lines to save       
+
+/* version history */
+/*
+Version Author  Date        Description
+0.1     TJM     01/24/15    Initial Draft
+0.2     TJM     01/24/166   first with CLI interface
+*/
+ 
+#define VERSION_MAJOR 0
+#define VERSION_MINOR 2
+#define VERSION_DATE "01/26/16"
+
+typedef unsigned char uint8;
+typedef signed char int8;
+typedef unsigned short uint16;
+typedef signed short int16;
+typedef unsigned long uint32;
+typedef signed long int32;
+typedef unsigned int uint;
+  
+/* parameter type */
+#define BINARY  0
+#define DIGITAL 1
+#define REGISTER 2
+#define ANALOG  3
+
+/* command defintions */
+#define HELP        0
+#define VERSION     1
+#define READ        2
+#define READ_REG    3
+#define WRITE       4
+#define WRITE_REG   5
+#define INFO        6
+#define FIND        7
+#define RUN         8
+#define STOP        9
+#define DATE        10
+#define HVSTATE     11
+
+/* mode */
+#define READONLY    0
+#define WRITEONLY   1
+#define READWRITE   2
+
+#define MAX_REGISTER_DATA 128
+
+/* parameter names */
+enum 
+{
+     spi,
+     i2c,
+} ;    
+     
+typedef   uint8 (*Read)(void);                                          //!< read function template to return 8 bit unsigned int
+typedef   uint16 (*ReadRegLength)(uint16 regAddress, uint8 *regData, uint16 length);  //!< read function template to return 8 bit unsigned int
+typedef   void (*Write8)(uint8 value);      //!< write function template to write 8 bit unsigned value
+typedef   void (*WriteReg8)(uint16 regAddress, uint8 *regData);      //!< write function template to write 8 bit unsigned value
+typedef   void (*Write16)(uint16 value);    //!< write function template to write 16 bit unsigned value
+typedef   void (*WriteAnalog)(float fltValue);    //!< write function template to write analog value
+
+/* paramater structure */
+struct parameterInfo                        //!< paramter information structure
+{
+    char *name;                             //!< paramter name
+    char *port;                             //!< port location (if applicable) on device
+    char *connector;                        //!< connector location (if applicable) on board
+    char *description;                      //!< brief parameter function and use
+    uint8 type;                             //!< binary, digital, or analog
+    char *uints;                            //!< parameter units (if applicable)
+    uint8 mode;                             //!< read only, write only, read write
+    uint16 initialInt;                      //!< initial value if binary or digital
+    uint16 minInt;                          //!< minimum value if binary or digital
+    uint16 maxInt;                          //!< maximum value if binary or digital
+    float initialFloat;                     //!< initial value if analog
+    float minFloat;                         //!< minimum value if analog
+    float maxFloat;                         //!< maximum value if analog
+    Read ptrRead;                           //!< read function needed for this parameter  (null if not needed)
+    ReadRegLength ptrReadRegLength;         //!< read function needed for this parameter  (null if not needed)
+    Write8 ptrWrite8;                       //!< 8 bit write function needed for this paramater (null if not needed) 
+    WriteReg8 ptrWriteReg8;                 //!< 8 bit write function needed for this paramater (null if not needed) 
+    Write16 ptrWrite16;                     //!< 16 bit write function needed for this paramater (null if not needed) 
+    WriteAnalog ptrWriteAnalog;             //!< analog write function needed for this paramater (null if not needed) 
+};
+
+
+/* function prototypes */
+void printVersion();
+uint8 getLine(); 
+void executeCmd();
+int8 getCmd();
+void setDate(char *str);
+void date(void);
+int8 getParameter(char *param);
+int8 findParameter(char *string);
+uint8 readParam(uint8 paramNum);
+void writeParam(uint8 paramNum,uint8 *value);
+float strtofloat (char *str);
+uint16 power(uint8 num, uint8 pow);
+void displayParameter(uint8 num);
+uint8 tolower(uint8 c);
+uint16 readSPIReg(uint16 regAddress, uint8 *regData, uint16 length);
+void writeSPIReg(uint16 regAddress, uint8 *regData);
+void SPIRead(uint16 addr, uint8 *data, int length);
+void SPIWrite(uint16 addr, uint8 *data, int length);
+uint16 readI2CReg(uint16 regAddress, uint8 *regData, uint16 length);
+void writeI2CReg(uint16 regAddress, uint8 *regData);
+void I2CRead(uint16 addr, uint8 *data, int length);
+void I2CWrite(uint16 addr, uint8 *data, int length);
+
+/* externals */
+extern Serial pc;
+extern char* c_time_string;
+extern char time_string[];
+extern char TransmitBuffer[TRANSMIT_BUFFER_SIZE];
+extern time_t epoch;
+extern struct parameterInfo parameters[];
+extern uint16 bytesRead;
+
+#endif
+/* [] END OF FILE */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/globals.cpp	Wed Jan 27 00:57:12 2016 +0000
@@ -0,0 +1,181 @@
+/* ========================================
+ * Filename: globals.c
+ *
+ * Description: global variables and structures
+ *
+ * Copyright J-Factor Embedded Technologies 2015
+ * Copyright TJM Embedded Software 2015
+ * All Rights Reserved
+ * UNPUBLISHED, LICENSED SOFTWARE.
+ *
+ * CONFIDENTIAL AND PROPRIETARY INFORMATION
+ * WHICH IS THE PROPERTY OF J-Factor Embedded Technologies.
+ *
+ * ========================================
+*/
+/** \file
+ * \brief global variables needed by other files.
+ */
+//#include <project.h>
+#include <time.h>
+#include "common.h"
+
+/* globals */
+char* c_time_string;            //!< relatine time and date string
+char time_string[10] = "00:00:00"; //!< relatine time only string
+time_t epoch;                   //!< time in seconds since epoch
+int32 iVref;                    //!< voltage across reference resistor
+int32 iVtherm;                  //!<  Voltages across thermistor
+uint32 iRes;                    //!< Resistance of Thermistor
+int32 iTemp;                    //!< Temperature value (x 100) in degrees C
+int32 iCurrent0;                //!< current in AMUX 0
+int32 iCurrent1;                //!< current in AMUX 1
+int32 iCurrent2;                //!< current in AMUX 2
+int32 iCurrent3;                //!< current in AMUX 3
+uint8 lampTestStatus;           //!< lamp test status
+uint16 lampTestTime;            //!< running lamp test time
+uint16 lampTestTimeSet;         //!< reset lamp test time
+uint8 runStatus;                //!< 0 - not running control mode, 1 = running in control mode
+uint8 pendantPresent;           //!< pendant present flag after lamp test
+uint8 checkPendant;             //!< check pendant state inside lamp test
+uint8 pendantTestStatus;        //!< pendant test status
+uint16 pendantTestTime;         //!< running pendant test time
+uint16 pendantTestTimeSet;      //!< reset pendant test time
+uint8 phaseUV;                  //!< phase under voltage bit 0-AB, 1-AC, 2-BC
+uint8 tempFailed;               //!< temperature above set point
+uint8 v5Failed;                 //!< 5 volt failuer
+uint8 v24Failed;                //!< 24 volt failuer
+uint8 HVState;                  //!< high voltage state
+uint32 HVStateMsg;              //!< high voltage state message flags
+uint8 engHVSwitchStatus;        //!< HV engaged switch NO and NC
+float ampsPerVolt;              //!< voltage to current translation
+uint16 tempSampleRate;          //!< running temperature sample rate
+uint16 oneSecond;               //!< running second timer
+uint16 engagedSwitchTimeOn;     //!< running engaged switch time
+uint16 engagedSwitchTimeOff;    //!< running engaged switch time
+uint16 ignitionTestTime;        //!< running ignition test time
+uint16 ignitionTestTimeSet;     //!< reset ignition test time
+uint16 softStartTestTime;       //!< running soft start test time
+uint16 softStartTestTimeSet;    //!< reset soft start test time
+uint16 currentSampleTime;       //!< running current sample time
+uint16 currentSampleTimeSet;    //!< reset current sample test time
+uint16 currentStableTestTime;   //!< running current stable test time
+uint16 currentStableTestTimeSet;//!< reset current stable test time
+uint16 currentStartTestTime;    //!< running current start test time
+uint16 currentStartTestTimeSet; //!< reset current start test time
+uint16 currentMinTestTime;      //!< running current start test time
+uint16 currentMinTestTimeSet;   //!< reset current start test time
+uint16 currentRampRate;         //!< running current ramp rate
+uint16 currentRampRateTerminate;//!< running current ramp rate for termination
+uint16 currentRampRateFoldback; //!< running current ramp rate for foldback
+uint16 currentRampRateEncoder;  //!< running current ramp rate for encoder
+uint16 currentRampRateSet;      //!< reset current ramp rate
+uint8 currentRampMode;          //!< current ramp direction
+uint16 encoderSampleRate;       //!< running encoder sample rate
+uint16 encoderSampleRateSet;    //!< reset encoder sample rate
+uint16 bridgeOCFlagTime;        //!< bridge_oc_flag valid time
+uint16 outputOCFlagTime;        //!< output_oc_flag valid time
+uint16 utilOCFlagTime;          //!< util_oc_flag valid time
+uint16 eStopTime;               //!< E_STOP valid time
+uint8 eStopSeen;                //!< E_STOP seen
+uint16 phaseABFlagTime;         //!< phase_ab_uv valid time
+uint16 phaseBCFlagTime;         //!< phase_bc_uv valid time
+uint16 phaseACFlagTime;         //!< phase_ac_uv valid time
+uint16 contactorTestTime;       //!< output_oc_flag valid time
+uint8 waitForPowerCycle;        //!< wait for power cycle after a failure
+float analogTemp;               //!< analog temperature value
+int16 encoderValue;             //!< last sampled encoder value
+int16 encoderDiff;              //!< last sampled encoder value differnce from current
+uint8 encoderChanged;           //!< encoder value changed since last sample
+uint8 pendantFailed;            //!< pendant failure
+uint16 flashCtrlSys;            //!< CTRL SYS flash rate
+uint8 currentBelowMin;          //!< current below minimum in normal operation
+uint8 outputOCSeen;             //!< output_oc_flag seen
+uint8 lampTestInitFail;         //!< initla tests fail before lamptest
+uint16 initFailType;            //!< initial test failure type
+float currentStableMin;         //!< current stable min
+float currentStableMax;         //!< current stable max
+uint8 utilOCSeen;               //!< util_oc flag change seen
+uint16 currentIndex;            //!< current source index
+uint8 currentOffMaxIndex;       //!< current off max parameter index
+uint8 tempSetIndex;             //!< temperature set index
+uint16 bytesRead;
+
+char *engagedState[] = {"HV Engaged Unknown", "HV Engaged On", "HV Engaged Off", "HV Engaged Unknown"};
+char *autoState[] = {"Neither","Auto","Manual","Both"};
+    
+/** \brief array of structures of valid parameters */
+struct parameterInfo parameters[] = 
+{
+     {"spi","NA","","SPI Register",REGISTER,"C",READWRITE,80,20,80,0.0,0.0,0.0,NULL,readSPIReg,NULL,writeSPIReg,NULL,NULL},
+     {"i2c","NA","","I2C Register",REGISTER,"C",READWRITE,80,20,80,0.0,0.0,0.0,NULL,readI2CReg,NULL,writeI2CReg,NULL,NULL},
+   #if 0
+    {"I5V0_PG","P1.3","NA","5 Volt Power Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,I5V0_PG_Read,NULL,NULL,NULL},
+    {"I24V0_PG","P1.4","J3-1","24 Volt Power Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,I24V0_PG_Read,NULL,NULL,NULL},
+    {"HV_CONTACTOR_CTRL","P15.2","J6-1,2","HV Contactor Control Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,HV_CONTACTOR_CTRL_Read,HV_CONTACTOR_CTRL_Write,NULL,NULL},
+    {"HV_ENABLE","P6.4","J1-9","HV Enable Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,HV_ENABLE_Read,HV_ENABLE_Write,NULL,NULL},
+    {"HV_ENABLE_N","P6.5","J1-8","HV Enable Not Output",BINARY,"",READWRITE,1,0,1,0.0,0.0,0.0,HV_ENABLE_N_Read,HV_ENABLE_N_Write,NULL,NULL},
+    {"TRIAC_IGN_CTRL","P5.2","J2-9","TRIAC Ignition Control Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,TRIAC_IGN_CTRL_Read,TRIAC_IGN_CTRL_Write,NULL,NULL},
+    {"PHASE_AB_UV","P6.7","J2-5","Phase AB Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PHASE_AB_UV_Read_cmd,NULL,NULL,NULL},
+    {"PHASE_AC_UV","P5.1","J2-7","Phase AC Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PHASE_AC_UV_Read_cmd,NULL,NULL,NULL},
+    {"PHASE_BC_UV","P5.0","J2-6","Phase BC Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PHASE_BC_UV_Read_cmd,NULL,NULL,NULL},
+    {"UTIL_OC_FLAG","P6.6","J2-4","Utility Over Current Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,UTIL_OC_FLAG_Read,NULL,NULL,NULL},
+    {"BRIDGE_OC_FLAG","P2.5","J1-2","Bridge Over Current Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,BRIDGE_OC_FLAG_Read,NULL,NULL,NULL},
+    {"OUTPUT_OC_FLAG","P2.6","J1-3","Output Over Current Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,OUTPUT_OC_FLAG_Read,NULL,NULL,NULL},
+    {"HV_ENGAGED","P2.1","J10-1","HV Engaged Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,HV_ENGAGED_Read,HV_ENGAGED_Write,NULL,NULL},
+    {"HV_NOT_ENGAGED","P2.0","J10-1","HV Not Engaged Output",BINARY,"",READWRITE,1,0,1,0.0,0.0,0.0,HV_NOT_ENGAGED_Read,HV_NOT_ENGAGED_Write,NULL,NULL},
+    {"SOFT_START_RELAY_CTRL","P5.3","J2-11","Soft Start Relay Control Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,SOFT_START_RELAY_CTRL_Read,SOFT_START_RELAY_CTRL_Write,NULL,NULL},
+    {"BRIDGE_OC_ER","P5.7","J4-1","Bridge Over Current Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,BRIDGE_OC_ER_Read,BRIDGE_OC_ER_Write,NULL,NULL},
+    {"OUTPUT_OC_ER","P5.6","J4-2","Output Over Current Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,OUTPUT_OC_ER_Read,OUTPUT_OC_ER_Write,NULL,NULL},
+    {"CUS_PERIM_INTLCK","P15.6","J4-3","Customer Perimeter Interlock Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,CUS_PERIM_INTLCK_Read,CUS_PERIM_INTLCK_Write,NULL,NULL},
+    {"CURRENT_FLDBCK_STATUS","P5.5","J4-4","Current Foldback Status Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,CURRENT_FLDBCK_STATUS_Read,CURRENT_FLDBCK_STATUS_Write,NULL,NULL},
+    {"IGN_FAIL_ER","P15.7","J4-5","Ignition Failure Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,IGN_FAIL_ER_Read,IGN_FAIL_ER_Write,NULL,NULL},
+    {"LOW_INP_PHA_VOLT","P5.4","J4-6","Low Input Phase Voltage Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,LOW_INP_PHA_VOLT_Read,LOW_INP_PHA_VOLT_Write,NULL,NULL},
+    {"QUENCH_STATUS","P15.0","J4-7","Quench Status Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,QUENCH_STATUS_Read,QUENCH_STATUS_Write,NULL,NULL},
+    {"E_STOP_FLG","P12.7","J4-8","E Stop Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,E_STOP_FLG_Read,E_STOP_FLG_Write,NULL,NULL},
+    {"CTRL_SYS_FAULT","P15.1","J4-9","Control Sysytem Fault Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,CTRL_SYS_FAULT_Read,CTRL_SYS_FAULT_Write,NULL,NULL},
+    {"DRIVER_BRD_OTEMP","P12.6","J4-10","Driver Board Over Temperature Output",BINARY,"",READWRITE,0,0,1,0.0,0.0,0.0,DRIVER_BRD_OTEMP_Read,DRIVER_BRD_OTEMP_Write,NULL,NULL},
+    {"TEMP","P0-0,1,2","J11-1,2","Thermistor temperature",ANALOG,"C",READONLY,0,0,100,0.0,0.0,0.0,readTemp,NULL,NULL,NULL},
+    {"TEMP_SET","NA","","Thermistor temperature trigger value",DIGITAL,"C",READWRITE,80,20,80,0.0,0.0,0.0,readTempSet,NULL,writeTempSet,NULL},
+    {"PWM_DC","P2.7","J1-6","PWM Duty Cycle Output",DIGITAL,"%",READWRITE,25,0,99,0.0,0.0,0.0,readPWMDC,NULL,writePWMDC,NULL},
+    {"PWM_DC_MIN","P2.7","J1-6","PWM Duty Cycle Minimum Output",DIGITAL,"%",READWRITE,0,0,99,0.0,0.0,0.0,readPWMDCMin,NULL,writePWMDCMin,NULL},
+    {"PWM_DC_MAX","P2.7","J1-6","PWM Duty Maximum Cycle Output",DIGITAL,"%",READWRITE,99,0,99,0.0,0.0,0.0,readPWMDCMax,NULL,writePWMDCMax,NULL},
+    {"CURRENT_SOURCE","Px.x","","Current Source",DIGITAL,"",READWRITE,2,0,3,0.0,0.0,0.0,readCurrentSource,NULL,writeCurrentSource,NULL},
+    {"CURRENT_OFF_MAX","Px.x","","Current OFF Maximum Limit",ANALOG,"A",READWRITE,0,0,0,0.75,0.0,1.0,readCurrentOffMax,NULL,NULL,writeCurrentOffMax},
+    {"CURRENT_STARTUP_MIN","Px.x","","Current Startup Minimum Limit",ANALOG,"A",READWRITE,0,0,0,3.0,1.0,4.0,readCurrentStartupMin,NULL,NULL,writeCurrentStartupMin},
+    {"CURRENT_STABLE_MIN","Px.x","","Current Startup Minimum Limit",ANALOG,"A",READWRITE,0,0,0,2.0,0.5,5.0,readCurrentStableMin,NULL,NULL,writeCurrentStableMin},
+    {"CURRENT_STABLE_MAX","Px.x","","Current Startup Minimum Limit",ANALOG,"A",READWRITE,0,0,0,10.0,1.0,12.0,readCurrentStableMax,NULL,NULL,writeCurrentStableMax},
+    {"CURRENT0","Px.x","","Current 0 command register",ANALOG,"A",READWRITE,0,0,0,0.0,0.0,12.0,readCurrent0,NULL,NULL,writeCurrent0},
+    {"CURRENT1","Px.x","","Current 1 command register",ANALOG,"A",READWRITE,0,0,0,0.0,0.0,12.0,readCurrent1,NULL,NULL,writeCurrent1},
+    {"CURRENT2","P0-5-6","J5-4","Current 2 command register",ANALOG,"A",READONLY,0,0,0,0.0,0.1,1.02,readCurrent2,NULL,NULL,NULL},
+    {"CURRENT3","P0-5-6","J5-5","Current 3 command register",ANALOG,"A",READONLY,0,0,0,0.0,0.1,1.02,readCurrent3,NULL,NULL,NULL},
+    {"CURRENT_SAMPLE_RATE","NA","","current sample rate",DIGITAL,"ms",READWRITE,10,10,60000,0.0,0.0,0.0,readCurrentSampleRate,NULL,writeCurrentSampleRate,NULL},
+    {"AMPS_PER_VOLT","Px.x","","Amps per volt",ANALOG,"Amps/Volt",READWRITE,0,0,0,2.5,1.0,4.5,readAmpsPerVolt,NULL,NULL,writeAmpsPerVolt},
+    {"AUTO_AUTO_MAN_IGN_SELECT","P3.2","J8-1","Auto Ignition Switch Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,AUTO_AUTO_MAN_IGN_SELECT_Read,NULL,NULL,NULL},
+    {"MAN_AUTO_MAN_IGN_SELECT","P3.3","J8-2","Manual Ignition Switch Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,MAN_AUTO_MAN_IGN_SELECT_Read,NULL,NULL,NULL},
+    {"MAN_IGN_CTRL","P3.4","J8-4","Manual Ignition Control Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,MAN_IGN_CTRL_Read,NULL,NULL,NULL},
+    {"E_STOP","P3.5","J8-6","Emergency Stop Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,E_STOP_Read,NULL,NULL,NULL},
+    {"ENG_HV_NO_SW","P3.6","J8-7","Engage HV Normally Open Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,ENG_HV_NO_SW_Read,NULL,NULL,NULL},
+    {"ENG_HV_NC_SW","P3.7","J8-8","Engage HV Normally Closed Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,ENG_HV_NC_SW_Read,NULL,NULL,NULL},
+    {"PEND_INC_CURRENT","P4.2","J9-3","Pendant Increment Current Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_INC_CURRENT_Read_INV,NULL,NULL,NULL},
+    {"PEND_DEC_CURRENT","P4.3","J9-4","Pendant Decrement Current Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_DEC_CURRENT_Read_INV,NULL,NULL,NULL},
+    {"PEND_HV_NO_SW","P4.4","J9-5","Pendant HV Normally Open Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_HV_NO_SW_Read_INV,NULL,NULL,NULL},
+    {"PEND_HV_NC_SW","P4.5","J9-6","Pendant HV Normally Closed Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_HV_NC_SW_Read_INV,NULL,NULL,NULL},
+    {"PEND_DISENGAGE_HV","P4.6","J9-7","Pendant Disengage HV Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_DISENGAGE_HV_Read_INV,NULL,NULL,NULL},
+    {"PEND_PRESENT","P4.7","J9-8","Pendant Present Input",BINARY,"",READONLY,0,0,1,0.0,0.0,0.0,PEND_PRESENT_Read_CMD,NULL,NULL,NULL},
+    {"ENCODER_COUNTER","P3.0,1","J7-2,3","Encoder Counter",DIGITAL,"Counts",READWRITE,0,0,65535,0.0,0.0,0.0,readEncoderCounter,NULL,ENCODER_COUNTER_WriteCounter,NULL},
+    {"LAMP_TEST_TIME","NA","","Lamp Test Time",DIGITAL,"ms",READWRITE,1000,100,60000,0.0,0.0,0.0,readLampTestTime,NULL,writeLampTestTime,NULL},
+    {"PENDANT_TEST_TIME","NA","","Lamp Test Time",DIGITAL,"us x 100",READWRITE,5,5,20,0.0,0.0,0.0,readPendantTestTime,NULL,writePendantTestTime,NULL},
+    {"IGNITION_TIME","NA","","Ignition Time",DIGITAL,"ms",READWRITE,1000,100,3000,0.0,0.0,0.0,readIgnitionTime,NULL,writeIgnitionTime,NULL},
+    {"SOFT_START_TIME","NA","","Ignition Time",DIGITAL,"ms",READWRITE,200,200,2500,0.0,0.0,0.0,readSoftStartTime,NULL,writeSoftStartTime,NULL},
+    {"CURRENT_STABLE_TIME","NA","","Current Stable Time",DIGITAL,"ms",READWRITE,2000,200,3000,0.0,0.0,0.0,readCurrentStableTime,NULL,writeCurrentStableTime,NULL},
+    {"CURRENT_START_TIME","NA","","Current Start Time",DIGITAL,"ms",READWRITE,10,200,3000,0.0,0.0,0.0,readCurrentStartTime,NULL,writeCurrentStartTime,NULL},
+    {"CURRENT_MIN_TIME","NA","","Current Minimum Test Time",DIGITAL,"ms",READWRITE,200,200,3000,0.0,0.0,0.0,readCurrentMinTime,NULL,writeCurrentMinTime,NULL},
+    {"CURRENT_RAMP_RATE_TERMINATE","NA","","Current Ramp Rate for terminate",DIGITAL,"us x 100",READWRITE,5000,200,50000,0.0,0.0,0.0,readCurrentRampRateTerminate,NULL,writeCurrentRampRateTerminate,NULL},
+    {"CURRENT_RAMP_RATE_FOLDBACK","NA","","Current Ramp Rate for foldback",DIGITAL,"us x 100",READWRITE,3000,200,50000,0.0,0.0,0.0,readCurrentRampRateFoldback,NULL,writeCurrentRampRateFoldback,NULL},
+    {"CURRENT_RAMP_RATE_ENCODER","NA","","Current Ramp Rate for encoder",DIGITAL,"us x 100",READWRITE,1000,200,50000,0.0,0.0,0.0,readCurrentRampRateEncoder,NULL,writeCurrentRampRateEncoder,NULL},
+    {"ENCODER_SAMPLE_RATE","NA","","Encoder Sample Rate",DIGITAL,"us x 100",READWRITE,1000,200,30000,0.0,0.0,0.0,readEncoderSampleRate,NULL,writeEncoderSampleRate,NULL},
+#endif
+    {"End","","","",BINARY,"",READONLY,0,0,0,0,0,0,NULL,NULL,NULL,NULL},
+};
+/* [] END OF FILE */
--- a/main.cpp	Fri Jan 22 00:33:38 2016 +0000
+++ b/main.cpp	Wed Jan 27 00:57:12 2016 +0000
@@ -15,6 +15,7 @@
 #include <vector>
 #include <algorithm>
 #include "PinDetect.h"
+#include "common.h"
 
 #define I2C_TIME 5
 #define LED_TIME 1
@@ -53,7 +54,7 @@
 uint8_t lastPowerOn;
 
 //Function prototypes
-void ledWrite();
+void timeOfDay();
 void periodicSendTock();
 void batteryRead();
 void killStatusRead();
@@ -68,14 +69,9 @@
 bool setAck(uint8_t retries);
 bool joinNetwork();
 bool send(const std::string text);
-char latestData[100];
 I2C i2c_mem(PTB3,PTB2);
 //SPI spi_rf(PTD6, PTD7, PTD5, PTD4);
 SPI spi_rf(PTD6, PTD7, PTD5);
-int myI2CWrite(int addr, char *data, int length);
-int myI2CRead(int addr, char *data, int length);
-int mySPIWrite(int addr, char *data, int length);
-int mySPIRead(int addr, char *data, int length);
 
 int i2cAddr = 0xAA;
 char data[0x10];
@@ -104,18 +100,17 @@
     spi_cs = 1;
   
     //Start LED startup sequence
-    ledTimer.attach(&ledWrite, LED_TIME);
+    ledTimer.attach(&timeOfDay, LED_TIME);
  
     pc.baud(115200);
-    pc.printf("\r\n\r\n");
-    pc.printf("=====================================\r\n");
-    pc.printf("I2C Demo \r\n");
-    pc.printf("=====================================\r\n");
+ //   pc.printf("\r\n\r\n");
+ //   pc.printf("=====================================\r\n");
+//    pc.printf("JLC MT Demo \r\n");
+//    pc.printf("=====================================\r\n");
     
     // get the mDot handle
 //     dot = mDot::getInstance();  
-    printVersion();
-/*    dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+ /*    dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
 
     //*******************************************
     // configuration
@@ -160,9 +155,24 @@
 //    batteryTimer.attach(batteryRead, BATTERY_TIME);
 //    killStatusTimer.attach(killStatusRead, KILL_STATUS_TIME);
 //    powerOnTimer.attach(powerOnRead, POWER_ON_TIME);
+    
+    /* initialize time and date */
+    epoch =0;
+    
+     /* Send message to verify UART is connected properly */
+    printVersion();
+    sprintf(TransmitBuffer,"%s cmd>",time_string);
+    pc.printf(TransmitBuffer);
 
     while (1) 
     {
+         if (getLine() == 1)                     /* wait until command line complete */
+        {
+            executeCmd();
+            sprintf(TransmitBuffer,"%s cmd> ",time_string);
+            pc.printf("%s",TransmitBuffer);
+         }
+       #if 0
         // is there anything to send
         if(readyToSendI2C)
         {       
@@ -179,9 +189,9 @@
         #if 1
             // Send 0x8f, the command to read the WHOAMI register
              data[0] = 0x12;
-//           mySPIWrite(0x0A,data,1);
-//            mySPIRead(0x0A,data1,1);
-           mySPIRead(0x42,data1,1);
+           mySPIWrite(0x0A,data,1);
+            mySPIRead(0x0A,data1,1);
+           mySPIRead(0x42,data1,2);
  //            int spiData = spi_rf.write(0x0600 | 0x0000);
             sprintf(latestData,"SPI %02X %02X",data1[0], data1[1]);
             pc.printf("%s\r\n",latestData);
@@ -211,38 +221,41 @@
             send(latestData);
             readyToSendPowerOn = false;
         }
+        #endif
      }
 }
 
-int myI2CWrite(int addr, char *data, int length)
+void I2CWrite(uint16 addr, uint8 *data, int length)
 {   
     int i;
     char bytes[3];
  
     for(i=0; i< length; i++,addr++)
     {
-        bytes[0] = addr << 8;
+        bytes[0] = addr >> 8;
         bytes[1] = addr & 0xFF;
         bytes[2] = data[i];
         i2c_mem.write(i2cAddr, bytes, 3);               /* write address and one byte */
         while(i2c_mem.write(i2cAddr, bytes, 0) != 0);   /* wait till write complete */
     }
-    return 0;
+    return;
 } 
 
-int myI2CRead(int addr, char *data, int length)
+void I2CRead(uint16 addr, uint8 *data, int length)
 {   
     char bytes[2];
  
-    bytes[0] = addr << 8;
+    bytes[0] = addr >> 8;
     bytes[1] = addr & 0xFF;
+//    sprintf(TransmitBuffer,"read I2C %04X %02X %04X\r\n",regAddress, bytes[0], bytes[1]);
+//    pc.printf(TransmitBuffer); 
     i2c_mem.write(i2cAddr, bytes, 2,true);      /* write address with repeated start */
-    i2c_mem.read(i2cAddr, data, length);        /* read all bytes */
-    return 0;
+    i2c_mem.read(i2cAddr, (char *)data, length);        /* read all bytes */
+    return;
 }
 
 
-int mySPIWrite(int addr, char *data, int length)
+void SPIWrite(uint16 addr, uint8 *data, int length)
 {   
     int i;
     
@@ -252,10 +265,9 @@
         data[i] = spi_rf.write( (addr << 8) | data[i] | 0x8000);
         spi_cs = 1;
     }
-    return 0;
 }
 
-int mySPIRead(int addr, char *data, int length)
+void SPIRead(uint16 addr, uint8 *data, int length)
 {   
     int i;
     
@@ -265,11 +277,11 @@
         data[i] = spi_rf.write( (addr << 8) | data[i] | 0x0000);
         spi_cs = 1;
     }
-    return 0;
- }
+  }
 
-void ledWrite()
+void timeOfDay()
 {
+   epoch++;                     /* update time of day */
    led_red = !led_red;
 //    led_green = !led_green;
 //   led_blue = !led_blue;
@@ -294,12 +306,6 @@
     readyToSendPowerOn = true;
  }
 
-void printVersion()
-{
- //   pc.printf("%s Built on: %s %s\r\n\r\n", dot->getId().c_str(),__DATE__,__TIME__);
-   pc.printf("Built on: %s %s\r\n\r\n", __DATE__,__TIME__);
-}
-
 bool setFrequencySubBand(uint8_t subBand)
 {
 /*    int32_t returnCode;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utilities.cpp	Wed Jan 27 00:57:12 2016 +0000
@@ -0,0 +1,201 @@
+/* ========================================
+ * Filename: utilities.c
+ *
+ * Description: functions needed by other files
+ *
+ * Copyright J-Factor Embedded Technologies 2015
+ * Copyright TJM Embedded Software 2015
+ * All Rights Reserved
+ * UNPUBLISHED, LICENSED SOFTWARE.
+ *
+ * CONFIDENTIAL AND PROPRIETARY INFORMATION
+ * WHICH IS THE PROPERTY OF J-Factor Embedded Technologies.
+ *
+ * ========================================
+*/
+/** \file
+ * \brief functions used by other files.
+ */
+#include <time.h>
+#include "stdio.h"
+#include "common.h"
+
+/** 
+ * \fn void date(void)
+ *
+ * \brief gets current time and date.
+ *
+ * gets date current time and date since last  set date command. there is no real time clock in the system so date is relative.
+ * \return None<p>
+ *
+ */
+void date(void)
+{
+    struct tm *epoch_tm = gmtime(&epoch);
+    if(epoch_tm != NULL)
+        c_time_string = asctime(gmtime(&epoch));
+    else
+        c_time_string = "00:00:00";
+}
+
+
+/** 
+ * \fn void setDate(char *str)
+ *
+ * \brief gets current time and date.
+ *
+ * gets date current time and date since last  set date command. there is no real time clock in the system so date is relative.
+ * \return None<p>
+ *
+ */
+void setDate(char *str)
+{
+    struct tm t;
+    int day,month,year,hour,minute,second;
+    int num;
+    time_t tempEpoch;
+    
+    num = sscanf(str,"%d/%d/%d %d:%d:%d",&month,&day,&year,&hour,&minute,&second);       /* get human readable current date */
+    if(num != 6)
+    {
+        pc.printf("Illegal or missing parameters. expected 6 integers\r\nformat: Month Day Year Hour Minute Second\r\n");
+        return;
+    }
+    t.tm_year = year-1900;
+    t.tm_mon = month - 1;           // Month, 0 - jan
+    t.tm_mday = day;          // Day of the month
+    t.tm_hour = hour;     
+    t.tm_min = minute;
+    t.tm_sec = second;
+    t.tm_isdst = -1;        // Is DST on? 1 = yes, 0 = no, -1 = unknown
+    tempEpoch = mktime(&t); 
+    if ( (month > 12) || (day > 31) || (hour > 23) || (minute > 59) || (second > 59) )
+    {
+        pc.printf("Illegal or missing parameters. expected 6 integers\r\nformat: Month/Day/Year Hour:Minute:Second\r\n");
+        return;
+    }
+    epoch = tempEpoch;
+}
+
+void printVersion()
+{
+ //   pc.printf("%s Built on: %s %s\r\n\r\n", dot->getId().c_str(),__DATE__,__TIME__);
+   pc.printf("\r\nJLC MT Demo: V%d.%02d %s Built on: %s %s\r\n",VERSION_MAJOR,VERSION_MINOR,VERSION_DATE, __DATE__,__TIME__);
+}
+
+uint8 tolower(uint8 c)
+{
+    if( (c >= 'A') && (c <= 'Z') )
+        return (c | 0x20);
+    else
+        return c;
+}
+
+/** 
+ * \fn float strtofloat (char *str)
+ *
+ * \brief converts an ASCII string to float.
+ *
+ * This routine converts a floating point number in the form
+ * xx.yy to a floating point number.
+ *
+ * \param[in] str - pointer to a character string containing the floating point number
+ * \return float - converted number<p>
+ *
+ */
+float strtofloat (char *str)
+{
+    float result = 0.0;
+    uint8 intPart[3];
+    uint16 intValue = 0;
+    uint8 floatPart[3];
+    float floatValue = 0.0;
+    uint8 i;
+    char *ptrDecimalPoint = NULL;
+    char *ptrStr = NULL;
+    char ch;
+    uint8 fractionValid = 0;
+    uint8 integerValid = 0;
+    
+    for(i=0;i<sizeof(intPart);i++)      /* clear integer digits */
+        intPart[i] = 0;
+    for(i=0;i<sizeof(floatPart);i++)    /* floating digits */
+        floatPart[i] = 0;
+        
+    ptrDecimalPoint = strchr(str, '.'); /* find the decimal point if any */
+    if (ptrDecimalPoint != NULL)
+    {
+        fractionValid = 1;
+        if(ptrDecimalPoint != str)      /* see if any integer digits */
+            integerValid = 1;
+    }
+    else
+    {
+        integerValid = 1;
+        ptrDecimalPoint = str + strlen(str);
+    }
+    
+    if(integerValid)                    /* get and save all integer digits */
+    {
+        for(i=0, ptrStr = ptrDecimalPoint;ptrStr != str; i++)
+        {
+            ptrStr--;
+            ch = *ptrStr;
+            if( (ch >= '0') && (ch <= '9') )
+            {
+                intPart[i] = ch - '0';
+            }
+            else
+            {
+                fractionValid = 0;
+                break;
+            }
+        }
+        for(i=0;i<sizeof(intPart);i++)
+            intValue += (intPart[i] * power(10,i));
+    }
+    
+    if(fractionValid)                   /* get and save all fraction digits */
+    {
+        for(i=0, ptrStr = ptrDecimalPoint;ptrStr < str + strlen(str); i++)
+        {
+            ptrStr++;
+            ch = *ptrStr;
+            if( (ch >= '0') && (ch <= '9') )
+            {
+                floatPart[i] = ch - '0';
+            }
+            else
+            {
+                break;
+            }
+        }
+        for(i=0;i<sizeof(floatPart);i++)
+            floatValue += (floatPart[i] * (1.0/power(10,i+1)) );
+    }
+    result = intValue + floatValue;
+    return result;
+}
+
+/** 
+ * \fn uint16 power(uint8 num, uint8 pow)
+ *
+ * \brief takes number(num) to power(pow)
+ *
+ * This routine takes an 8 bit integer num and
+ * raises it ot the power pow.
+ *
+ * \param[in] num - 8 bit integer number 
+ * \param[in] pow - 8 bit power to raise num
+ * \return uint16 - 16 bit num to the power pow<p>
+ *
+ */
+uint16 power(uint8 num, uint8 pow)
+{
+    uint8 i;
+    uint16 result = 1;
+    
+    for(i=0;i<pow;i++)
+        result = result * num;
+    return result;  
+}