示例#1
0
文件: main.c 项目: WeiY/mihini-repo
void MAIN_StartAppTimerHandler(u8 id, void* pContext) {
    wm_sprintf(ltsc_Temp, "\r\n Main application started beautifully");
    adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);

    // init modbustack
    SerialConfig serialConfig;
    serialConfig.identity = SERIAL_UART2;
    serialConfig.baudrate = SERIAL_UART_BAUDRATE_19200;
    serialConfig.parity = SERIAL_UART_ODD_PARITY;
    serialConfig.data = SERIAL_UART_DATA_8;
    serialConfig.stop = SERIAL_UART_STOP_1;
    serialConfig.flowControl = SERIAL_UART_FC_NONE;
    serialConfig.timeout = 10;
    serialConfig.retry = 0;
    modbusData.allocated = NULL;
    if (SWI_STATUS_SERIAL_INIT_STACK_READY == SRLFWK_ADP_InitAdapter(&(modbusData.pSerialContext), &serialConfig, ModbusHandler, MODBUS_SER_InitSerializer, (void*) MODBUS_RTU, &modbusData)) {
        wm_sprintf(ltsc_Temp, "\r\nOK Stack initialized");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);

        //        if (SWI_STATUS_OK == SRLFWK_ADP_EnableHardwareSwitch(pSerialContext, 12, MODBUS_GPIO_HIGH)) {
        //            wm_sprintf(ltsc_Temp, "\r\nOK GPIO online");
        //            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp) ;
        //        } else {
        //            wm_sprintf(ltsc_Temp, "\r\nERROR failed to get GPIO");
        //            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp) ;
        //        }
        adl_tmrSubscribeExt(TRUE, 30, ADL_TMR_TYPE_100MS, MAIN_PollingTimerHandler, &modbusData, TRUE);
    } else {
        wm_sprintf(ltsc_Temp, "\r\nERROR Failed to initialize stack");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    }
}
示例#2
0
文件: main.c 项目: WeiY/mihini-repo
void adl_main(adl_InitType_e initType) {
    s8 flashHandle = -1;
    u8 counter = 1;

    flashHandle = adl_flhSubscribe(PERSISTENT_COUNTER, 1);
    if (adl_flhExist(PERSISTENT_COUNTER, 0) == 0) {
        adl_flhWrite(PERSISTENT_COUNTER, 0, sizeof(counter), &counter);
    } else {
        adl_flhRead(PERSISTENT_COUNTER, 0, sizeof(counter), &counter);
        counter++;
        adl_flhWrite(PERSISTENT_COUNTER, 0, sizeof(counter), &counter);
    }

    if (initType == ADL_INIT_REBOOT_FROM_EXCEPTION) {
        wm_sprintf(ltsc_Temp, "\r\nA Fatal Error Occurred Test is restarting (%d)", counter);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    } else {
        wm_sprintf(ltsc_Temp, "\r\nTest modbus starting(%d) in 15s...'%d'", counter, initType);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    }

    UART_Init();

    // The application will switch the UART to data mode n seconds later, so the user has 15s to enter
    adl_tmrSubscribe(FALSE, 150, ADL_TMR_TYPE_100MS, MAIN_StartAppTimerHandler);
}
示例#3
0
/** @brief Check the current coordinate
 *
 * @par
 * This is what triggers the geofence system. Everytime we get a fix we need to check if we are violating any geofences.
 *
 * @return void
 */
static void CheckCoord(void)
{
	UINT8 current_fence_stat;
	int fence_num;

	adl_rtcTimeStamp_t TimeStamp0, TimeStamp1;
	adl_rtcTimeStamp_t DeltaTimeStamp;

	// If we are in dog walk mode,
    if (GetDogWalkMode() == DOGWALK_ENABLED)
	{
		DumpMessage("Dog walk mode\r\n");
		return;
	}

	GetConvertTime(&TimeStamp0);
	current_fence_stat = eval_fix(&fence_num, GPS_FIX_REASON);
	GetConvertTime(&TimeStamp1);

	wm_sprintf(g_traceBuf, "Fence Number = %d\r\n", fence_num);
	DumpMessage(g_traceBuf);

	if (adl_rtcDiffTime(&TimeStamp1, &TimeStamp0, &DeltaTimeStamp) < 0)
	{
		DisplayErrorCode("adl_rtcConvertTime", __FILE__, __LINE__, -1);
	}

	wm_sprintf(g_traceBuf, "Calc time %d:%d\r\n", (int )DeltaTimeStamp.TimeStamp, (int)ADL_RTC_GET_TIMESTAMP_MS(DeltaTimeStamp));
	DumpMessage(g_traceBuf);
	wm_sprintf(g_traceBuf, "current_fence_stat = %c\r\n", current_fence_stat);
	DumpMessage(g_traceBuf);
}
示例#4
0
/*
 * Gibt eine Information auf der externen Applikation aus
 */
void info(ascii * Message)
{
	// Benötigter Speicher für die Formatierungen
	const static u8 overhead = 12;

	// Speicher für die Ausgabe der Nachricht
	ascii * buffer =
		(ascii *) adl_memGet(
			wm_strlen(Message)
			+ overhead
		);

	// Formatierung der Nachricht für die Ausgabe
	wm_sprintf(
		buffer,
		"\r\n+INFO: %s\r\n",
		Message
	);

	// Ausgabe der Nachricht
	adl_atSendUnsoResponse(
		ADL_PORT_UART1,
		buffer,
		FALSE
	);

	// Freigabe des Speichers
	adl_memRelease(buffer);
}
示例#5
0
/*
 * Verarbeitet die Daten des GPS Empfängers
 */
bool gps_fcm_data_handler(u16 length, u8 *data)
{
	u16   index = 0;
	ascii buffer_in[256];
	ascii buffer_out[256];

	for (index = 0 ; index < length; index++)
		buffer_in[index] = (ascii)data[index];

	if(wm_strncmp(buffer_in, "$GPRMC,", 7) == 0)
	{
		for(index = 7; index < wm_strlen(buffer_in) && buffer_in[index] != '\r'; index++)
			buffer_in[index - 7] = buffer_in[index];
		buffer_in[index - 7] = '\0';
		wm_sprintf(buffer_out, "%s", buffer_in);
		gps_data = buffer_out;
	}

	return TRUE;
}
示例#6
0
static void http_ClientTestDataHandler ( wip_event_t *ev, void *ctx )
{
    ascii tmpbuf [ 256 ];
    ascii Ptr_OnTrace [ 240 ];
    int len, tmplen;
    s32 status;
    http_ClientTestCtx_t *pHttpClientCtx = ( http_ClientTestCtx_t * ) &http_ClientTestCtx;

    switch ( ev->kind )
    {
        case WIP_CEV_OPEN:
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: WIP_CEV_OPEN" ) );
            adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Start\r\n" );
            /* ready for getting response data  */
            pHttpClientCtx->dataLength = 0;
            break;
        }

        case WIP_CEV_READ:
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: WIP_CEV_READ" ) );
            /* we must read all available data to trigger WIP_CEV_READ again    */
            tmplen = 0;
            while ( ( len = wip_read ( ev->channel, tmpbuf, sizeof ( tmpbuf ) - 1 ) ) > 0 )
            {
                tmpbuf [ len ] = 0;
                //adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
                tmplen += len;
            }
            TRACE(( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: read %d bytes", tmplen ));
            /* compute total length of response */
            pHttpClientCtx->dataLength += tmplen;
            break;
        }

        case WIP_CEV_PEER_CLOSE:
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE" ) );
            adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Done\r\n" );

            /* end of data  */
            /* show response information    */
            if ( wip_getOpts ( ev->channel,
                               WIP_COPT_HTTP_STATUS_CODE, &status,
                               WIP_COPT_HTTP_STATUS_REASON, tmpbuf, sizeof ( tmpbuf ),
                               WIP_COPT_END ) == OK )
            {
                ascii sbuf [ 16 ];
                adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Status=" );
                wm_sprintf ( sbuf, "%d", ( s16 ) status );
                adl_atSendResponse ( ADL_AT_UNS, sbuf );
                adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Reason=\"" );
                adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
                adl_atSendResponse ( ADL_AT_UNS, "\"\r\n" );
                TRACE ( ( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: Status=%d", status ) );
                wm_sprintf ( Ptr_OnTrace, "http_ClientTestDataHandler: Reason=\"%s\"", tmpbuf );
                TRACE ( ( NORMAL_TRACE_LEVEL, Ptr_OnTrace ) );
            }

            if ( wip_getOpts ( ev->channel,
                               WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof ( tmpbuf ),
                               WIP_COPT_END ) == OK )
            {
                wm_sprintf ( Ptr_OnTrace, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf );
                TRACE ( ( NORMAL_TRACE_LEVEL, Ptr_OnTrace ) );
            }
            TRACE ( ( NORMAL_TRACE_LEVEL, "http_ClientTestDataHandler: Response Length=%d bytes", pHttpClientCtx->dataLength ) );

            /* data channel must be closed*/
            wip_close( ev->channel );

            break;
        }

        case WIP_CEV_ERROR:
        {
            TRACE ( ( ERROR_TRACE_LEVEL, "http_ClientTestDataHandler: WIP_CEV_ERROR %d", ev->content.error.errnum ) );
            adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
            /* connection to server broken  */
            wip_close( ev->channel);
            break;
        }

        default:
        {
            TRACE ( ( ERROR_TRACE_LEVEL, "http_ClientTestDataHandler: unexpected event: %d", ev->kind ) );
            break;
        }
    }
}
/** @brief callback method for +CSQ unsolicted messages
 *
 * @par
 * Handler function which handles the +CSQ indicaiton.
 * This handler provides the signal strength.
 *
 * @param paras
 *
 * @return FALSE
 */
bool CSQHandler(adl_atUnsolicited_t *paras)
{
	ascii rssi[10];

	int rssi_int;
	static char GSMAlarmGenerated = 0;

	wm_strGetParameterString(rssi, paras->StrData, 1);
	rssi_int = atoi(rssi);

	// rssi has a range from 0 - 31.
	// we have 6 ranges. Use the defines to define the 0-5 signal.
	if (rssi_int < RSSI_0)
	{
		g_status.GSMSignalStrength = '0';
	}
	else if (rssi_int < RSSI_1)
	{
		g_status.GSMSignalStrength = '1';
	}
	else if (rssi_int < RSSI_2)
	{
		g_status.GSMSignalStrength = '2';
	}
	else if (rssi_int < RSSI_3)
	{
		g_status.GSMSignalStrength = '3';
	}
	else if (rssi_int < RSSI_4)
	{
		g_status.GSMSignalStrength = '4';
	}
	else if (rssi_int == RSSI_ERROR)
	{
		g_status.GSMSignalStrength = '0';
	}
	else
	{
		g_status.GSMSignalStrength = '5';
	}

	wm_sprintf(g_traceBuf, "Sig strength = %c\r\n", g_status.GSMSignalStrength);
	DumpMessage(g_traceBuf);

	if (g_config.GSMAlertThresh != 'N')
	{
		if ((g_status.GSMSignalStrength <= g_config.GSMAlertThresh) && !GSMAlarmGenerated)
		{
			g_status.GSMAlarm = 'Y';
			GSMAlarmGenerated = 1;
			alarm_suppress_set_alarm_time(GSM_ALARM_SUP);
		}
		else if ((g_status.GSMSignalStrength > g_config.GSMAlertThresh) && (alarm_suppress_status(GSM_ALARM_SUP) == ALARM_EXPIRED))
		{
			GSMAlarmGenerated = 0;
		}
	}
	else
	{
		GSMAlarmGenerated = 0;
	}

	return FALSE;
}
/** @brief Handler of the SIM events
 *
 * @par
 * Handles events generated from the SIM operation
 *
 * @param Event
 * @return void
 */
void evhSimHandler(u8 Event)
{
//	s8 retCode = -1;

	TRACE((1, "Inside Sim_Handler"));
	adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1, "Inside Sim_Handler\n");

	switch (Event)
	{
	case ADL_SIM_STATE_INIT:
		TRACE((1, "SIM ADL_SIM_STATE_INIT"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_INIT\n");
		break;

	case ADL_SIM_STATE_REMOVED:
		TRACE((1, "SIM ADL_SIM_STATE_REMOVED"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_REMOVED\n");
		break;

	case ADL_SIM_STATE_INSERTED:
		TRACE((1, "SIM ADL_SIM_STATE_INSERTED"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_INSERTED\n");
		break;

	case ADL_SIM_STATE_PIN_ERROR:
		TRACE((1, "SIM ADL_SIM_STATE_PIN_ERROR"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_PIN_ERROR\n");
		break;

	case ADL_SIM_STATE_PIN_OK:
		TRACE((1, "SIM ADL_SIM_STATE_PIN_OK"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_PIN_OK\n");
		break;

	case ADL_SIM_STATE_PIN_WAIT:
		TRACE((1, "SIM ADL_SIM_STATE_PIN_WAIT"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_PIN_WAIT\n");
		break;

	case ADL_SIM_STATE_FULL_INIT:
		TRACE((1, "SIM ADL_SIM_STATE_FULL_INIT"));
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1
		                       , "\r\nSIM ADL_SIM_STATE_FULL_INIT\r\n");

		g_sim_full_init_stat = 1;
		SimInit = 1;
		break;

	default:
		wm_sprintf(g_traceBuf, "\r\nSIM Event return Value: %d\r\n", Event);
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_UART1, g_traceBuf);
		TRACE((1, g_traceBuf));
		break;
	}
}
示例#9
0
文件: main.c 项目: WeiY/mihini-repo
void ModbusHandler(SerialContext* pSerialContext, swi_status_t status, void* pUserData) {
    u8* pduBuff = NULL;
    u16 bufferLength = 0;
    int index;
    ModbusSpecifics* pSpecifics = SRLFWK_ADP_GetProtocolData(pSerialContext);
    ModbusUserData* pModbusData = (ModbusUserData*) pUserData;

    if (/*status != SWI_STATUS_SERIAL_RESPONSE_TIMEOUT*/1) {
        wm_sprintf(ltsc_Temp, "\r\n >>>>");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        SRLFWK_ADP_GetRequestPDU(pSerialContext, &pduBuff, &bufferLength);
        for (index = 0; index < bufferLength; index++) {
            wm_sprintf(ltsc_Temp, " %02X ", pduBuff[index]);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        }

        bufferLength = 0;
        pduBuff = NULL;
        wm_sprintf(ltsc_Temp, "\r\n <<<<");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        if (status != SWI_STATUS_SERIAL_RESPONSE_TIMEOUT) {
            SRLFWK_ADP_GetResponsePDU(pSerialContext, &pduBuff, &bufferLength);
            for (index = 0; index < bufferLength; index++) {
                wm_sprintf(ltsc_Temp, " %02X ", pduBuff[index]);
                adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            }
        }
    }

    switch (status) {
    case SWI_STATUS_OK:
        switch (pSpecifics->response.function) {
        case MODBUS_FUNC_READ_COILS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< READ COILS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK '%d' coil(s) read on '%d' bytes starting at '%d'", pSpecifics->response.numberOfObjects, pSpecifics->response.byteCount,
                    pSpecifics->response.startingAddress);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            for (index = 0; index < pSpecifics->response.byteCount; index++) {
                wm_sprintf(ltsc_Temp, "\r\n byte '%d' : %02X", index, ((u8*) (pSpecifics->response.value.pValues))[index]);
                adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            }
            break;

        case MODBUS_FUNC_READ_DISCRETE_INPUTS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< READ DISCRETE INPUTS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK '%d' discrete input(s) read on '%d' bytes starting at '%d'", pSpecifics->response.numberOfObjects, pSpecifics->response.byteCount,
                    pSpecifics->response.startingAddress);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            for (index = 0; index < pSpecifics->response.byteCount; index++) {
                wm_sprintf(ltsc_Temp, "\r\n byte '%d' : %02X", index, ((u8*) (pSpecifics->response.value.pValues))[index]);
                adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            }
            break;

        case MODBUS_FUNC_READ_HOLDING_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< READ HOLDING REGISTERS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);

            wm_sprintf(ltsc_Temp, " ---> OK '%d' holding register(s) read", pSpecifics->response.numberOfObjects);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            for (index = 0; index < pSpecifics->response.numberOfObjects; index++) {
                wm_sprintf(ltsc_Temp, "\r\n value '%d' : %d", index, ((u16*) (pSpecifics->response.value.pValues))[index]);
                adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            }
            break;

        case MODBUS_FUNC_READ_INPUT_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< READ INPUT REGISTERS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK '%d' input register(s) read", pSpecifics->response.numberOfObjects);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            for (index = 0; index < pSpecifics->response.numberOfObjects; index++) {
                wm_sprintf(ltsc_Temp, "\r\n value '%d' : %d", index, ((u16*) (pSpecifics->response.value.pValues))[index]);
                adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            }
            break;

        case MODBUS_FUNC_WRITE_SINGLE_COIL:
            wm_sprintf(ltsc_Temp, "\r\n <<<< WRITE COILS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK address: %d - value: %d", pSpecifics->response.startingAddress, (int) pSpecifics->response.value.pValues);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_SINGLE_REGISTER:
            wm_sprintf(ltsc_Temp, "\r\n <<<< WRITE REGISTER");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK address: %d - value: %d", pSpecifics->response.startingAddress, (int) pSpecifics->response.value.pValues);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_MULTIPLE_COILS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< WRITE MULTIPLE COILS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK address: %d - number: %d", pSpecifics->response.startingAddress, pSpecifics->response.numberOfObjects);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_MULTIPLE_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< WRITE MULTIPLE REGISTERS");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            wm_sprintf(ltsc_Temp, " ---> OK address: %d - number: %d", pSpecifics->response.startingAddress, pSpecifics->response.numberOfObjects);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        default:
            wm_sprintf(ltsc_Temp, "\r\n <<<< UNKNOWN FUNCTION");
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;
        }
        break;

    case SWI_STATUS_SERIAL_RESPONSE_TIMEOUT:
        wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR TIMEOUT");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case SWI_STATUS_SERIAL_RESPONSE_EXCEPTION:
        switch (pSpecifics->response.function) {
        case MODBUS_FUNC_READ_COILS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR READ COILS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_READ_DISCRETE_INPUTS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR READ DISCRETE INPUTS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_READ_HOLDING_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR READ HOLDING REGISTERS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_READ_INPUT_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR READ INPUT REGISTERS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_SINGLE_COIL:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR WRITE COILS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_SINGLE_REGISTER:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR WRITE REGISTER  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_MULTIPLE_COILS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR WRITE MULTIPLE COILS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        case MODBUS_FUNC_WRITE_MULTIPLE_REGISTERS:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR WRITE MULTIPLE REGISTERS  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;

        default:
            wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR UNKNOWN FUNCTION  - exception '%02X'", pSpecifics->response.exception);
            adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
            break;
        }
        break;

    case SWI_STATUS_SERIAL_RESPONSE_BAD_CHECKSUM:
        wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR CHECKSUM BAD");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    default:
    case SWI_STATUS_SERIAL_RESPONSE_INVALID_FRAME:
        wm_sprintf(ltsc_Temp, "\r\n <<<< ERROR INVALID FRAME");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    }

    wm_sprintf(ltsc_Temp, "\r\n ------------------------------------------------------------------------------");
    adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);

    // free user result buffer
    if (pModbusData->allocated != NULL) {
        adl_memRelease(pModbusData->allocated);
        pModbusData->allocated = NULL;
    }
}
示例#10
0
文件: main.c 项目: WeiY/mihini-repo
s16 UART_DummyAtCmdRespHandler(adl_atResponse_t* apu_Rsp) {
    wm_sprintf(ltsc_Temp, "\r\nUART2 closed");
    adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    return TRUE;
}
示例#11
0
文件: main.c 项目: WeiY/mihini-repo
void MAIN_PollingTimerHandler(u8 id, void* pContext) {
    swi_status_t result = SWI_STATUS_SERIAL_ERROR;
    ModbusUserData* pModbusData = (ModbusUserData*) pContext;
    pModbusData->request.slaveId = 1;

    int index = 0;
    u8 value = 0xFF;

    wm_sprintf(ltsc_Temp, "\r\n ------------------------------------------------------------------------------");
    adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);

    switch (choice) {
    case 0: // write single coil
        pModbusData->request.function = MODBUS_FUNC_WRITE_SINGLE_COIL;
        pModbusData->request.startingAddress = 0x0002;
        pModbusData->request.value.iValue = (uint32_t) MODBUS_SINGLE_COIL_ON;

        wm_sprintf(ltsc_Temp, "\r\n >>>> WRITE SINGLE COIL at '%04X' ON SLAVE '%d'", pModbusData->request.startingAddress, pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 1: //read input registers
        pModbusData->request.function = MODBUS_FUNC_READ_INPUT_REGISTERS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 16;
        pModbusData->allocated = adl_memGet(pModbusData->request.numberOfObjects * sizeof(u16));
        pModbusData->request.value.pValues = pModbusData->allocated;

        wm_sprintf(ltsc_Temp, "\r\n >>>> READ '%d' INPUT REGISTERS starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.startingAddress,
                pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 2: // read coils
        pModbusData->request.function = MODBUS_FUNC_READ_COILS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 120;
        pModbusData->request.byteCount = ((pModbusData->request.numberOfObjects / 8) + (((pModbusData->request.numberOfObjects % 8) != 0) ? 1 : 0));
        pModbusData->allocated = adl_memGet(pModbusData->request.byteCount * sizeof(u8));
        pModbusData->request.value.pValues = pModbusData->allocated;

        wm_sprintf(ltsc_Temp, "\r\n >>>> READ '%d' COILS ('%d' bytes) starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.byteCount,
                pModbusData->request.startingAddress, pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 3: // read holding registers
        pModbusData->request.function = MODBUS_FUNC_READ_HOLDING_REGISTERS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 10;
        pModbusData->allocated = adl_memGet(pModbusData->request.numberOfObjects * sizeof(u16));
        pModbusData->request.value.pValues = pModbusData->allocated;

        wm_sprintf(ltsc_Temp, "\r\n >>>> READ '%d' HOLDING REGISTERS starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.startingAddress,
                pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 4: // write single register
        pModbusData->request.function = MODBUS_FUNC_WRITE_SINGLE_REGISTER;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.value.iValue = (uint32_t) 1;

        wm_sprintf(ltsc_Temp, "\r\n >>>> WRITE SINGLE REGISTER at '%04X' ON SLAVE '%d'", pModbusData->request.startingAddress, pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 5: // write multiple coils
        pModbusData->request.function = MODBUS_FUNC_WRITE_MULTIPLE_COILS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 120;
        pModbusData->request.byteCount = ((pModbusData->request.numberOfObjects / 8) + (((pModbusData->request.numberOfObjects % 8) != 0) ? 1 : 0));
        pModbusData->allocated = adl_memGet(pModbusData->request.byteCount * sizeof(u8));
        pModbusData->request.value.pValues = pModbusData->allocated;
        for (index = 0; index < pModbusData->request.byteCount; index++) {
            value = value ^ 0xFF;
            ((u8*) pModbusData->request.value.pValues)[index] = value;
        }

        wm_sprintf(ltsc_Temp, "\r\n >>>> WRITE '%d' COILS starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.startingAddress, pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 6: // write multiple registers
        pModbusData->request.function = MODBUS_FUNC_WRITE_MULTIPLE_REGISTERS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 120;
        pModbusData->allocated = adl_memGet(pModbusData->request.numberOfObjects * sizeof(u16));
        pModbusData->request.value.pValues = pModbusData->allocated;
        for (index = 0; index < pModbusData->request.numberOfObjects; index++) {
            ((u16*) pModbusData->request.value.pValues)[index] = 2 * index + 1;
        }

        wm_sprintf(ltsc_Temp, "\r\n >>>> WRITE MULTIPLE '%d' REGISTERS starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.startingAddress,
                pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    case 7: // read discrete input
        pModbusData->request.function = MODBUS_FUNC_READ_DISCRETE_INPUTS;
        pModbusData->request.startingAddress = 0x0000;
        pModbusData->request.numberOfObjects = 120;
        pModbusData->request.byteCount = ((pModbusData->request.numberOfObjects / 8) + (((pModbusData->request.numberOfObjects % 8) != 0) ? 1 : 0));
        pModbusData->allocated = adl_memGet(pModbusData->request.byteCount * sizeof(u8));
        pModbusData->request.value.pValues = pModbusData->allocated;

        wm_sprintf(ltsc_Temp, "\r\n >>>> READ '%d' DISCRETE INPUTS ('%d' bytes) starting at '%04X' ON SLAVE '%d'", pModbusData->request.numberOfObjects, pModbusData->request.byteCount,
                pModbusData->request.startingAddress, pModbusData->request.slaveId);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        break;

    default:
        wm_sprintf(ltsc_Temp, "\r\n >>>> ???");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        return;
    }

    result = SRLFWK_ADP_Request(pModbusData->pSerialContext, &pModbusData->request);
    if (result == SWI_STATUS_OK) {
        // print pModbusData->request
        wm_sprintf(ltsc_Temp, "\r\n >>>> polling DONE '%d'", result);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    } else {
        if (pModbusData->allocated != NULL) {
            adl_memRelease(pModbusData->allocated);
            pModbusData->allocated = NULL;
        }
        wm_sprintf(ltsc_Temp, "\r\n >>>> ERROR polling '%d'", result);
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
        wm_sprintf(ltsc_Temp, "\r\n ------------------------------------------------------------------------------");
        adl_atSendResponse(ADL_AT_UNS, ltsc_Temp);
    }

    choice = (choice + 1) % 8;
}
示例#12
0
/** @brief Process the GPS fix
 *
 * @return void
 */
static void ProcFix(FIX_QUALITY fix_quality)
{
	int sv, strong, weak;
	ascii buffer[8];
	ascii satBuf[1];
	double SpeedMPH = 0.0;
	static u8 OverSpeedAlarmGenerated = 0;
	adl_rtcTimeStamp_t GPSTimeStamp;
	adl_rtcTime_t GPSTime;
	static bool RTC_Update = 1;
	s32 sReturn=0;

	DumpMessage("processing proc fix\n\r");

	if ((TrackingMode == DOG_PARK_TRACKING_MODE) && FirstDogParkFix)
	{
		g_DogParkFence.posts[0].lat_32 = g_GGAInfo.Latitude;
		g_DogParkFence.posts[0].long_32 = g_GGAInfo.Longitude;
		// these are "dummy" posts since we only support >=2.
		// The dog park radius is handled in fence.c
		g_DogParkFence.posts[1].lat_32 = g_GGAInfo.Latitude;
		g_DogParkFence.posts[1].long_32 = g_GGAInfo.Longitude;
		Config_SetMode(DOG_PARK_MODE, 0, &g_DogParkFence, TRUE); // TODO add dog park fence.
		FirstDogParkFix = 0;
	}

	g_current_fix_32.lat_32 = g_GGAInfo.Latitude;
	g_current_fix_32.long_32 = g_GGAInfo.Longitude;

	// Signal strength.
	GetSV_SRN(&sv, &strong, &weak);
	g_status.GPSSignalStrength1 = '0' + strong;
	g_status.GPSSignalStrength2 = '0' + weak;

	wm_sprintf(g_traceBuf, "sig strong = %c sig weak = %c\r\n", g_status.GPSSignalStrength1, g_status.GPSSignalStrength2);
	DumpMessage(g_traceBuf);

	// Time.
	wm_itohexa((ascii *)&buffer, g_GGAInfo.Time, 8);
	memcpy(&g_current_fix.utc, &buffer, 8);

	if(RTC_Update == 1 && fix_quality == FIX_3D)
	{
		//Update RTC with GPS time only once on power up
		GPSTimeStamp.TimeStamp = g_GGAInfo.Time;
		GPSTimeStamp.SecondFracPart = 0;
		if ((sReturn = adl_rtcConvertTime(&GPSTime, &GPSTimeStamp, ADL_RTC_CONVERT_FROM_TIMESTAMP)) < 0)
		{
			DisplayErrorCode("adl_rtcConvertTime", __FILE__, __LINE__, sReturn);
		}	
		if(adl_rtcSetTime(&GPSTime) != OK)
			DumpMessage("Error setting RTC time\r\n");
		else
		{
			//Restart accelerometer timer, to avoid sudden slow idle mode, due to change in RTC time.
			//If RTC time jumps up suddenly and if the diff compared to old RTC is more than accel sleep duration, then
			//the device can enter slow idle mode immediately in Track Mode and Low Power full track mode.
			ActivateAccelOnPowerUp();
			wm_sprintf(g_traceBuf,"RTC time udpated with GPS value : 0x%x\r\n",(unsigned int)GPSTimeStamp.TimeStamp);
			DumpMessage(g_traceBuf);
			DumpMessageUSB(g_traceBuf,1);
		}
		RTC_Update = 0;
	}
	// Number of sats
	wm_itohexa((ascii *)&satBuf, g_GGAInfo.NumberOfSatillites, 1);
	memcpy(&g_status.NumBirds, &satBuf, 1);

	// lat and long
	wm_itohexa((ascii *)&buffer, g_GGAInfo.Latitude, 8);
	memcpy(&g_current_fix.lat, &buffer, 8);
	wm_itohexa((ascii *)&buffer, g_GGAInfo.Longitude, 8);
	memcpy(&g_current_fix.longi, &buffer, 8);
	// copy HDOP to where EPE used to be.
	wm_itohexa((ascii *)&buffer, g_GGAInfo.HDOP, 2);
	memcpy(&g_current_fix.epe, &buffer, 2);

	wm_sprintf(g_traceBuf, "HDOP: %c%c\r\n", buffer[1], buffer[0]);
	DumpMessage(g_traceBuf);

	// check the speed. The speed from VTGInfo is in km/hr
	// the speed from the config struct is in miles/hr
	SpeedMPH = (double)g_VTGInfo.Speed * KM_IN_MILES / METERS_IN_KM;

	if (!OverSpeedAlarmGenerated && (SpeedMPH >= (double)g_config.OverSpeedAlertThresh) && (g_config.OverSpeedAlertThresh != 0))
	{
		DumpMessage("over speed alarm detected\n\r");
		g_status.OverSpeedAlarm = 'Y';
		OverSpeedAlarmGenerated = 1;
	}
	else if (SpeedMPH < (double)g_config.OverSpeedAlertThresh)
	{
		DumpMessage("over speed alarm NOT detected\n\r");
		g_status.OverSpeedAlarm = 'N';
		OverSpeedAlarmGenerated = 0;
	}

	// write the waypoint fix to serial flash.
	WriteWaypointFromFix(&g_current_fix, g_VTGInfo.Speed, g_VTGInfo.Course, fix_quality);

	// do not check on the first dog park fix.
	DumpMessage("\r\nCheckCoords\r\n");
	if (((!FirstDogParkFix) && (TrackingMode == DOG_PARK_TRACKING_MODE)) ||
	    (TrackingMode != DOG_PARK_TRACKING_MODE))
	{
		CheckCoord();
	}
}
示例#13
0
void NextFixHandler(u8 timerid, void *context)
{
	(void)timerid;
	(void)context;

	s32 sReturn = -1;

	char prevGPSstat;

	adl_rtcTimeStamp_t CurrentTimeStamp;
	adl_rtcTimeStamp_t DeltaTimeStamp;
	TCP_STATUS status;
	static BOOL AGPSRequested=0;
	static u8 Count=0;   //Count of how many times this function was entered.
	int ret_val;

	prevGPSstat = g_status.GPSStatus;
	TRACE((1, "Next GPS Fix timer triggered"));

	// control the tracking mode state. Process the tracking mode
	// requests from the rest of the system.
	switch (TrackingMode)
	{
	case TRACKING_MODE_OFF:
        if (GetDogParkMode() == DOGPARK_ENABLED)
		{
			TrackingMode = DOG_PARK_TRACKING_MODE;
		}
		else if (AccelTrackingReq == TRACKING_MODE_REQ_ACTIVE)
		{
			TrackingMode = ACCEL_TRIG_TRACKING_MODE;
		}

		else if (TimedWakeupTrackingReq == TRACKING_MODE_REQ_ACTIVE)
		{
			TrackingMode = TIMED_WAKE_TRACKING_MODE;
		}
		else
		{
			TrackingMode = TRACKING_MODE_OFF;
		}
		break;

	case ACCEL_TRIG_TRACKING_MODE:
        if (GetDogParkMode() == DOGPARK_ENABLED)
		{
			TrackingMode = DOG_PARK_TRACKING_MODE;
		}

		else if (AccelTrackingReq == TRACKING_MODE_REQ_RELEASE)
		{
			TrackingMode = TRACKING_MODE_OFF;
		}
		else
		{
			TrackingMode = ACCEL_TRIG_TRACKING_MODE;
		}
		break;

	case DOG_PARK_TRACKING_MODE:
        if (GetDogParkMode() == DOGPARK_DISABLED)
		{
			TrackingMode = TRACKING_MODE_OFF;
		}
		else
		{
			TrackingMode = DOG_PARK_TRACKING_MODE;
		}
		break;

	case TIMED_WAKE_TRACKING_MODE:
		if (TimedWakeupTrackingReq == TRACKING_MODE_REQ_RELEASE)
		{
			TrackingMode = TRACKING_MODE_OFF;
		}
		else
		{
			TrackingMode = TIMED_WAKE_TRACKING_MODE;
		}
		break;

	default:
		DumpMessage("Undefined tracking mode\r\n");
		TrackingMode = TRACKING_MODE_OFF;
		break;
	}

	switch (gps_state)
	{
	// the GPS should be in OFF mode while in this state.
	case GPS_OFF:
		if ((TrackingMode == ACCEL_TRIG_TRACKING_MODE) || (TrackingMode == DOG_PARK_TRACKING_MODE) ||
		    (TrackingMode == TIMED_WAKE_TRACKING_MODE))
		{
			GetConvertTime(&TrackTimeStamp);
			gps_state = GPS_START;
			DumpMessage("GPS START!\r\n");
			//Reset the flag
			AGPSRequested = 0;
		}
		else
		{
			gps_state = GPS_OFF;
		}
		break;

	// attempt to start up the GPS.
	case GPS_START:
		gps_Start();

		if (!HadFix && !AttemptedAGPSNoFix)
		{
			DumpMessage("Never had fix. Going to use AGPS!\r\n");
			//performAGPS(0.0, 0.0, 0.0, 0.0);
			AttemptedAGPSNoFix = 1;
		}
		else if (HadFix)
		{
			GetConvertTime(&CurrentTimeStamp);
			//Request AGPS is last fix is more than 2 hrs old.		
			if((CurrentTimeStamp.TimeStamp - g_AGPSData.LastReqTimeStamp) >= 2*60*60)
			{
				AGPSRequested = 0;
				wm_sprintf(g_traceBuf,"g_AGPSData.LastReqTimeStamp : 0x%x, CurrentTimeStamp: 0x%x\r\n",(unsigned int)g_AGPSData.LastReqTimeStamp,(unsigned int)CurrentTimeStamp.TimeStamp);
				DumpMessage(g_traceBuf);
				DumpMessageUSB(g_traceBuf,1);				
				DumpMessage("AGPS data is old. Request fresh data\r\n");
			}

//			if (adl_rtcDiffTime(&CurrentTimeStamp, &FixTimeStamp, &DeltaTimeStamp) < 0)
//			{
//				DisplayErrorCode("adl_rtcConvertTime", __FILE__, __LINE__, sReturn);
//			}
//			else
//			{
//				wm_sprintf(g_traceBuf,"FixTimeStamp : 0x%x, CurrentTimeStamp: 0x%x\r\n",(unsigned int)FixTimeStamp.TimeStamp,(unsigned int)CurrentTimeStamp.TimeStamp);
//				DumpMessage(g_traceBuf);
//				DumpMessageUSB(g_traceBuf,1);

				//if (DeltaTimeStamp.TimeStamp >= 60 * 60 * 2)
				//{
				//	DumpMessage("Over two hours since last fix, going to use AGPS!\r\n");
				//	performAGPS(0.0, 0.0, 0.0, 0.0);					
				//}
			//}
		}

		gps_state = GPS_GET_FIX;
		DumpMessage("GET FIX!\r\n");
		//}
		break;

	// keep on the GPS until we get a fix. probably add a timeout to this...
	case GPS_GET_FIX:

		//Increment the count to keep a track of how many times this state was entered.
		Count++;
		
		// if tracking mode has been disabled...
		if (TrackingMode == TRACKING_MODE_OFF)
		{
			gps_state = GPS_OFF;
			break;
		}

		GetGGAInfo(&g_GGAInfo);
		GetVGTInfo(&g_VTGInfo);

		//Request AGPS
		GetTCPStatus(&status);

		
		if(!AGPSRequested && status == TCP_CONNECT)
		{					
			//Get the current time
			GetConvertTime(&CurrentTimeStamp);	

			//Compare the times.
			if((CurrentTimeStamp.TimeStamp - g_AGPSData.LastReqTimeStamp) < 2*60*60)  //check for < 2 hours
			{
				wm_sprintf(g_traceBuf,"CurrentTimeStamp.TimeStamp: 0x%x, g_AGPSData.LastReqTimeStamp: 0x%x\r\n", 
										(unsigned int)CurrentTimeStamp.TimeStamp,(unsigned int)g_AGPSData.LastReqTimeStamp);
				DumpMessage(g_traceBuf);
				DumpMessageUSB(g_traceBuf,1);

				//Send the last stored AGPS data to ublox directly.
				if ((ret_val = adl_fcmSendData(ubloxDataFcmHandle, (unsigned char *)g_AGPSData.AGPSData, g_AGPSData.datalen)) != OK)
				{
					wip_debug("ERROR: Could not send data to ublox device: %d\r\n", ret_val);
					wm_sprintf(g_traceBuf,"ERROR: Could not send data to ublox device: %d\r\n", ret_val);
					DumpMessageUSB(g_traceBuf,1);						
					set_agps_status(AGPS_NOT_USED);
				}
				else
				{
					AGPSRequested = 1;
					wm_sprintf(g_traceBuf,"AGPS data sent to ublox (<2 hrs case): %ld bytes\r\n", g_AGPSData.datalen);
					DumpMessage(g_traceBuf);
					DumpMessageUSB(g_traceBuf,1);
				}
					
			}
		}

		// Check if we got a fix.
		if (g_GGAInfo.FixQuality == FIX_3D)
		{
			SetFixStatus(HAD_3D_FIX);

			alarmGenerated = 0;
			GetConvertTime(&FixTimeStamp);
			gps_state = GPS_PROC_FIX;

			if (g_config.WaypointInterval >= GPS_WAYPOINT_SHUTDOWN_INTERVAL)
			{
				gps_Stop();
			}
			// GPS working
			//g_status.GPSStatus = 'W';
			// clear alarm
			if (alarm_suppress_status(GPS_ALARM_SUP) == ALARM_EXPIRED)
			{
				g_status.GPSAlarm = 'N';
				GPSAlarmGenerated = 0;
			}
			gps_state = GPS_PROC_FIX;
			DumpMessage("GPS_PROC_FIX\r\n");
		}
		else
		{
			if (g_GGAInfo.FixQuality == FIX_2D)
			{
				DumpMessage("GOT 2D FIX -- will not use\r\n");
				
				if(status == TCP_CONNECT && !AGPSRequested)
				{					
					//Request AGPS with available 2D fix
					performAGPS((g_GGAInfo.Latitude/1000000.0), (g_GGAInfo.Longitude/1000000.0), 0.0, 0.0);
					AGPSRequested = 1;
						
				}
			}
			else     //this fucntion is called once every 925ms. so 16*925 = 15 secs
			{
				//Check for the validity of WaitTimeout
				if(g_AGPSData.WaitTimeout == 0 || g_AGPSData.WaitTimeout > 99)
					g_AGPSData.WaitTimeout = 15;    //Default to 15 if found out of range
					
				//If 2D fix not received in 15 secs then request AGPS with last valid 3D fix.				
				//Request AGPS with last GPS fix				
				if(Count > g_AGPSData.WaitTimeout && status == TCP_CONNECT && !AGPSRequested )
				{					
					DumpMessage("Request fresh AGPS data\r\n");
					performAGPS(0.0, 0.0, 0.0, 0.0);
					AGPSRequested = 1;
					Count=0;
				}
			}

			g_status.GPSStatus = 'N';
			if (prevGPSstat == 'W')
			{
				TRACE((1, "Lost GPS Signal"));
			}

			gps_state = GPS_GET_FIX;
		}
		break;

	case GPS_PROC_FIX:
		ProcFix(FIX_3D);
		// GPS working
		g_status.GPSStatus = 'W';
		DumpMessage("Got a fix1\r\n");
		adl_atSendResponsePort(ADL_AT_RSP, ADL_PORT_USB, "***GOT_FIX***\r\n");
		gps_state = GPS_WAIT_NEXT_FIX;
		HadFix = 1;
		break;

	case GPS_WAIT_NEXT_FIX:
		DumpMessage("GPS_WAIT_NEXT_FIX\r\n");
		GetConvertTime(&CurrentTimeStamp);

		// time difference between last fix and current time.
		if (adl_rtcDiffTime(&CurrentTimeStamp, &FixTimeStamp, &DeltaTimeStamp) < 0)
		{
			DisplayErrorCode("adl_rtcConvertTime", __FILE__, __LINE__, sReturn);
		}

		// If the tracking interval time has elapsed,
		// go and get another fix or if the trackind mode contoller has disabled tracking,
		// go into the off state.
		if (DeltaTimeStamp.TimeStamp >= g_config.WaypointInterval)
		{
			wm_sprintf(g_traceBuf, "currenttimestamp = 0x%x fix time stamp = 0x%x delta time stamp = 0x%x waypoint interval = %d\r\n", (unsigned int )CurrentTimeStamp.TimeStamp, (unsigned int )FixTimeStamp.TimeStamp, (unsigned int )DeltaTimeStamp.TimeStamp, (int )g_config.WaypointInterval);
			DumpMessage(g_traceBuf);
			gps_state = GPS_START;
		}
		else
		{
			if (TrackingMode == TRACKING_MODE_OFF)
			{
				gps_Stop();
				gps_state = GPS_OFF;
				FirstDogParkFix = 1;
			}
			else
			{
				gps_state = GPS_WAIT_NEXT_FIX;
			}
		}

		break;

	default:
		DumpMessage("Error: Unknown GPS state\r\n");
		break;
	}
}