コード例 #1
0
ファイル: sp5K_tkCmd.c プロジェクト: spymovil/sp5K
//------------------------------------------------------------------------------------
void sp5K_stackFunction(void)
{
	// Funcion de debug que muestra el estado de los stacks de c/tarea.

	if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) {
		vt100ClearScreen(CMD_UART);
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("Control: [%lu | %d]\r\n\0"), tkControl_uxHighWaterMark, tkControl_STACK_SIZE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("Digital: [%lu | %d]\r\n\0"), tkDigitalIn_uxHighWaterMark, tkDigitalIn_STACK_SIZE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("Data: [%lu | %d]\r\n\0"), tkData_uxHighWaterMark, tkData_STACK_SIZE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("Cmd: [%lu | %d]\r\n\0"), tkCmd_uxHighWaterMark, tkCmd_STACK_SIZE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("Gprs: [%lu | %d]\r\n\0"),tkGprs_uxHighWaterMark, tkGprs_STACK_SIZE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		xSemaphoreGive( sem_CmdUart );
	}


}
コード例 #2
0
void uartTest(void)
{
    int c;

    // print a little intro message so we know things are working
    rprintfStr("\r\n\n\nWelcome to the uart library test program!\r\n");
    rprintfStr("Press any key...\r\n");

    // read in serial port traffic from UART1
    // and echo it back in hex and/or ascii format as appropriate
    while(1)
    {
        if((c = uart1GetByte()) != -1)
        {
            // we got a byte
            rprintf("Ascii code: 0x%x ", c);
            // see if it's printable
            if((c >= 0x20) && (c < 0x7F))
            {
                uart1SendByte(c);
            }
            rprintfStr("\r\n");
        }
    }
}
コード例 #3
0
ファイル: cmdlinetest.c プロジェクト: 46nori/avr-liberty
void dumpArgsStr(void)
{
	rprintfCRLF();
	rprintf("Dump arguments as strings\r\n");

	rprintfProgStrM("Arg0: "); rprintfStr(cmdlineGetArgStr(0)); rprintfCRLF();
	rprintfProgStrM("Arg1: "); rprintfStr(cmdlineGetArgStr(1)); rprintfCRLF();
	rprintfProgStrM("Arg2: "); rprintfStr(cmdlineGetArgStr(2)); rprintfCRLF();
	rprintfProgStrM("Arg3: "); rprintfStr(cmdlineGetArgStr(3)); rprintfCRLF();
	rprintfCRLF();
}
コード例 #4
0
ファイル: mitelgps.c プロジェクト: 46nori/avr-liberty
void mitelgpsProcessNAVDATAGND(u08* packet)
{
	// process "F00" report packets - Navigation Data (Ground)
	char* endptr;

	if(debug & MITELGPS_DEBUG_EXTRACT)
	{
		rprintf("MITELGPS: ");
		rprintfStr(packet);
		rprintfCRLF();
	}

	// start parsing just after "F00"
	// get latitude [sdd.dddddd]
	GpsInfo.PosLLA.lat.f = strtod(&packet[3], &endptr);
	// get longitude [sddd.dddddd]
	GpsInfo.PosLLA.lon.f = strtod(&packet[3+10], &endptr);
	// get altitude [sxxxxxx.x]
	GpsInfo.PosLLA.alt.f = strtod(&packet[3+10+11], &endptr);
	// get speed [sxxx.xx]
	GpsInfo.VelHS.speed.f = strtod(&packet[3+10+11+9], &endptr);
	// get heading [ddd]
	GpsInfo.VelHS.heading.f = strtod(&packet[3+10+11+9+7], &endptr);

	// get # of SVs tracked [xx]
	GpsInfo.numSVs = atoi(&packet[3+10+11+9+7+5+7+5+5+5]);
}
コード例 #5
0
ファイル: ata.c プロジェクト: 46nori/avr-liberty
void ataDriveInit(void)
{
	u08 i;
	unsigned char* buffer = (unsigned char*) SECTOR_BUFFER_ADDR;

	// read drive identity
	rprintfProgStrM("\r\nScanning IDE interface...\r\n");
	// Wait for drive to be ready
	ataStatusWait(ATA_SR_BSY, ATA_SR_BSY);
	// issue identify command
	ataWriteByte(ATA_REG_CMDSTATUS1, 0xEC);
	// wait for drive to request data transfer
	ataStatusWait(ATA_SR_DRQ, ATA_SR_DRQ);
	timerPause(200);
	// read in the data
	ataReadDataBuffer(buffer, 512);

	// set local drive info parameters
	ataDriveInfo.cylinders =		*( ((unsigned int*) buffer) + ATA_IDENT_CYLINDERS );
	ataDriveInfo.heads =			*( ((unsigned int*) buffer) + ATA_IDENT_HEADS );
	ataDriveInfo.sectors =			*( ((unsigned int*) buffer) + ATA_IDENT_SECTORS );
	ataDriveInfo.LBAsupport =		*( ((unsigned int*) buffer) + ATA_IDENT_FIELDVALID );
	ataDriveInfo.sizeinsectors =	*( (unsigned long*) (buffer + ATA_IDENT_LBASECTORS*2) );
	// copy model string
	for(i=0; i<40; i+=2)
	{
		// correct for byte order
		ataDriveInfo.model[i  ] = buffer[(ATA_IDENT_MODEL*2) + i + 1];
		ataDriveInfo.model[i+1] = buffer[(ATA_IDENT_MODEL*2) + i    ];
	}
	// terminate string
	ataDriveInfo.model[40] = 0;

	// process and print info
	if(ataDriveInfo.LBAsupport)
	{
		// LBA support
		rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) );
		rprintf("LBA mode -- MODEL: ");
	}
	else
	{
		// CHS, no LBA support
		// calculate drive size
		ataDriveInfo.sizeinsectors = (unsigned long) ataDriveInfo.cylinders*
												ataDriveInfo.heads*ataDriveInfo.sectors;
		rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) );
		rprintf("CHS mode C=%d H=%d S=%d -- MODEL: ", ataDriveInfo.cylinders, ataDriveInfo.heads, ataDriveInfo.sectors );
	}
	// print model information	
	rprintfStr(ataDriveInfo.model); rprintfCRLF();

	// initialize local disk parameters
	//ataDriveInfo.cylinders = ATA_DISKPARM_CLYS;
	//ataDriveInfo.heads = ATA_DISKPARM_HEADS;
	//ataDriveInfo.sectors = ATA_DISKPARM_SECTORS;

}
コード例 #6
0
ファイル: nmea.c プロジェクト: lanwan/avrlib2
void nmeaProcessGPVTG(uint8_t* packet)
{
	uint8_t i;
	char* endptr;

	#ifdef NMEA_DEBUG_VTG
	rprintf("NMEA: ");
	rprintfStr(packet);
	rprintfCRLF();
	#endif

	// start parsing just after "GPVTG,"
	i = 6;
	// attempt to reject empty packets right away
	if(packet[i]==',' && packet[i+1]==',')
		return;

	// get course (true north ref) in degrees [ddd.dd]
	GpsInfo.VelHS.heading.f = strtod(&packet[i], &endptr);
	while(packet[i++] != ',');				// next field: 'T'
	while(packet[i++] != ',');				// next field: course (magnetic north)

	// get course (magnetic north ref) in degrees [ddd.dd]
	//GpsInfo.VelHS.heading.f = strtod(&packet[i], &endptr);
	while(packet[i++] != ',');				// next field: 'M'
	while(packet[i++] != ',');				// next field: speed (knots)

	// get speed in knots
	//GpsInfo.VelHS.speed.f = strtod(&packet[i], &endptr);
	while(packet[i++] != ',');				// next field: 'N'
	while(packet[i++] != ',');				// next field: speed (km/h)

	// get speed in km/h
	GpsInfo.VelHS.speed.f = strtod(&packet[i], &endptr);
	while(packet[i++] != ',');				// next field: 'K'
	while(packet[i++] != '*');				// next field: checksum

	GpsInfo.VelHS.updates++;
}
コード例 #7
0
ファイル: sp5K_tkCmd.c プロジェクト: spymovil/sp5K
void sp5K_writeFunction(void)
{

u08 dateTimeStr[11];
char tmp[3];
RtcTimeType rtcDateTime;
char *p;
u08 devId, address, regValue;
u08 value = 0;
s08 retS = FALSE;
u08  mcp_address = 0;
u08 length = 0;
u08 *nro = NULL;
u08 *msg = NULL;
u08 timeout;
char phase;
u08 chip;
u16 sleepTime;

	memset( cmd_printfBuff, NULL, CHAR128);
	makeargv();

	// Parametros:
	if (!strcmp_P( strupr(argv[1]), PSTR("PARAM\0")))
	{

		// PASSWD
		if (!strcmp_P( strupr(argv[2]), PSTR("PASSWD\0"))) {
			memset(systemVars.passwd, '\0', sizeof(systemVars.passwd));
			memcpy(systemVars.passwd, argv[3], sizeof(systemVars.passwd));
			systemVars.passwd[PASSWD_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// APN
		if (!strcmp_P( strupr(argv[2]), PSTR("APN\0"))) {
			memset(systemVars.apn, '\0', sizeof(systemVars.apn));
			memcpy(systemVars.apn, argv[3], sizeof(systemVars.apn));
			systemVars.apn[APN_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER PORT
		if (!strcmp_P( strupr(argv[2]), PSTR("PORT\0"))) {
			memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort));
			memcpy(systemVars.serverPort, argv[3], sizeof(systemVars.serverPort));
			systemVars.serverPort[PORT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER IP
		if (!strcmp_P( strupr(argv[2]), PSTR("IP\0"))) {
			memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress));
			memcpy(systemVars.serverAddress, argv[3], sizeof(systemVars.serverAddress));
			systemVars.serverAddress[IP_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER SCRIPT
		// write param script cgi-bin/oseApp/scripts/oseSp5K001.pl
		if (!strcmp_P( strupr(argv[2]), PSTR("SCRIPT\0"))) {
			memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript));
			memcpy(systemVars.serverScript, argv[3], sizeof(systemVars.serverScript));
			systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// MagP ( magnitud  por pulso )
		if (!strcmp_P( strupr(argv[2]), PSTR("MAGP\0"))) {
			retS = setParamMagP(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dname X ( digital name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("DNAME\0"))) {
			retS = setParamDname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// aname X ( analog name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("ANAME\0"))) {
			retS = setParamAname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imin X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMIN\0"))) {
			retS = setParamImin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imax X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMAX\0"))) {
			retS = setParamImax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMIN\0"))) {
			retS = setParamMmin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMAX\0"))) {
			retS = setParamMmax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMIN\0"))) {
			retS = setParamOffset(0,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMAX\0"))) {
			retS = setParamOffset(1,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* DebugLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("DEBUGLEVEL\0"))) {
			retS = setParamDebugLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* LogLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("LOGLEVEL\0"))) {
			retS = setParamLogLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dlgId
		if (!strcmp_P( strupr(argv[2]), PSTR("DLGID\0"))) {
			memcpy(systemVars.dlgId, argv[3], sizeof(systemVars.dlgId));
			systemVars.dlgId[DLGID_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		/* TimerPoll */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERPOLL\0"))) {
			retS = setParamTimerPoll(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* TimerDial */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERDIAL\0"))) {
			retS = setParamTimerDial(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Wrkmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("WRKMODE\0"))) {
			retS = setParamWrkMode(argv[3],argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Pwrmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("PWRMODE\0"))) {
			retS = setParamPwrMode(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

/*		// MONITOR
		// write param monitor [sqe|frame]
		if (!strcmp_P( strupr(argv[2]), PSTR("MONITOR\0"))) {
			retS = setParamMonitor(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}
*/


	}

	// CONSIGNA
	if (!strcmp_P( strupr(argv[2]), PSTR("CONSIGNA\0"))) {
		retS = setParamConsigna(argv[3], argv[4]);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// ALL SystemVars ( save )
	if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) {
		retS = saveSystemParamsInEE( &systemVars );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// RTC
	if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) {
		/* YYMMDDhhmm */
		memcpy(dateTimeStr, argv[2], 10);
		// year
		tmp[0] = dateTimeStr[0]; tmp[1] = dateTimeStr[1];	tmp[2] = '\0';
		rtcDateTime.year = atoi(tmp);
		// month
		tmp[0] = dateTimeStr[2]; tmp[1] = dateTimeStr[3];	tmp[2] = '\0';
		rtcDateTime.month = atoi(tmp);
		// day of month
		tmp[0] = dateTimeStr[4]; tmp[1] = dateTimeStr[5];	tmp[2] = '\0';
		rtcDateTime.day = atoi(tmp);
		// hour
		tmp[0] = dateTimeStr[6]; tmp[1] = dateTimeStr[7];	tmp[2] = '\0';
		rtcDateTime.hour = atoi(tmp);
		// minute
		tmp[0] = dateTimeStr[8]; tmp[1] = dateTimeStr[9];	tmp[2] = '\0';
		rtcDateTime.min = atoi(tmp);

		retS = rtcSetTime(&rtcDateTime);

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Si no estoy en modo service no puedo hacer estas tareas administrativas.

	if ( systemVars.wrkMode != WK_SERVICE) {
		snprintf_P( &cmd_printfBuff,CHAR128,PSTR("WARNING: Debe pasar a modo SERVICE !!!\r\n\0"));
		sp5K_printStr(&cmd_printfBuff);
		return;
	}

	// MCP
	// write mcp 0|1|2 addr value
	if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0"))) {
		devId = atoi(argv[2]);
		address = atoi(argv[3]);
		regValue = strtol(argv[4],NULL,2);

		if ( devId == 0 ) { mcp_address = MCP_ADDR0; }
		if ( devId == 1 ) { mcp_address = MCP_ADDR1; }
		if ( devId == 2 ) { mcp_address = MCP_ADDR2; }

		retS = MCP_write( address,  mcp_address, 1, &regValue);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// EEPROM
	if (!strcmp_P( strupr(argv[1]), PSTR("EE\0"))) {
		address = atoi(argv[2]);
		p = argv[3];
		while (*p != NULL) {
			p++;
			length++;
			if (length > CMDLINE_BUFFERSIZE )
				break;
		}

		retS = EE_write( address, length, argv[3] );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// LED
	// write led 0|1
	if (!strcmp_P( strupr(argv[1]), PSTR("LED\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setLed( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsSW
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsSw( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// termPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("TERMPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setTermPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// sensorPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("SENSORPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setSensorPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// analogPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("ANALOGPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setAnalogPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// SMS
	if (!strcmp_P(argv[1], PSTR("SMS\0"))) {
		nro = argv[2];
		msg = cmdlineGetArgStr(3);

		rprintfStr(GPRS_UART, "AT+CMGS=\"+\0" );
		rprintfStr(GPRS_UART, nro );
		rprintfStr(GPRS_UART, "\r\0");

		// Espero el prompt > para enviar el mensaje.
		timeout = 10;
		xUartQueueFlush(GPRS_UART);
		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			if (strstr( &xUart0RxedCharsBuffer.buffer, ">") != NULL) {
				break;
			}
			timeout--;
		}
		rprintfStr(GPRS_UART, msg );
		rprintfStr(GPRS_UART, "\r");

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		rprintfStr(GPRS_UART, "\032");

		return;
	}

	// ATCMD
	if (!strcmp_P(argv[1], PSTR("ATCMD\0"))) {
		msg = argv[2];
		timeout = atoi(argv[3]);
		if (timeout == 0)
			timeout = 1;

		xUartQueueFlush(GPRS_UART);
		rprintfStr(GPRS_UART, msg);
		rprintfStr(GPRS_UART, "\r\0");

		rprintfStr(CMD_UART, "sent>\0");
		rprintfStr(CMD_UART, msg);
		rprintfCRLF(CMD_UART);

		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			timeout--;
		}

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		return;
	}

#ifdef CHANNELS_3

	// Valves: Phase
	// write ph A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("PH\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesPhase(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Enable
	// write en A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("EN\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesEnable(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Reset
	if (!strcmp_P( strupr(argv[1]), PSTR("VRESET\0"))) {

		value = atoi(argv[2]);

		retS = setValvesReset( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Sleep
	if (!strcmp_P( strupr(argv[1]), PSTR("VSLEEP\0"))) {

		value = atoi(argv[2]);

		retS = setValvesSleep( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Pulse [A/B][1/2] {+|-} {ms}
	if (!strcmp_P( strupr(argv[1]), PSTR("VPULSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;
		value = toupper( argv[3][0]  );
		sleepTime = atol(argv[4]);

		if ( sleepTime > 5000 ) {
			sleepTime = 5000;
		}

		retS = setValvesPulse( phase, chip, value, sleepTime );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: OPEN
	if (!strcmp_P( strupr(argv[1]), PSTR("OPEN\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesOpen( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: CLOSE
	if (!strcmp_P( strupr(argv[1]), PSTR("CLOSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesClose( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: Consigna
	if (!strcmp_P( strupr(argv[1]), PSTR("CONSIGNA\0"))) {

		if (!strcmp_P( strupr(argv[2]), PSTR("DIA\0"))) {
			retS = setConsignaDia();
		}

		if (!strcmp_P( strupr(argv[2]), PSTR("NOCHE\0"))) {
			retS = setConsignaNoche();
		}

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}
#endif

	// CMD NOT FOUND
	if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) {
		rprintfProgStrM(CMD_UART, "ERROR\r\n");
		rprintfProgStrM(CMD_UART, "CMD NOT DEFINED\r\n");
		xSemaphoreGive( sem_CmdUart );
	}
	return;

}
コード例 #8
0
ファイル: sp5K_tkCmd.c プロジェクト: spymovil/sp5K
void SP5K_statusFunction(void)
{

RtcTimeType rtcDateTime;
u08 pos, channel;
u16 dialTimer;
u08 mStatus;
frameDataType frame;
u08 gprsState, gprsSubState, dataState;

	rtcGetTime(&rtcDateTime);
	getDataFrame(&frame);
	dialTimer = getTimeToNextDial();

	memset( &cmd_printfBuff, '\0', CHAR128);

	if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) {

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("\r\nSpymovil %s %s\0"), SP5K_MODELO, SP5K_VERSION);
		rprintfStr(CMD_UART, cmd_printfBuff );
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(" %d-%s-%s\0"), NRO_CHANNELS, EE_TYPE, FTYPE);
		rprintfStr(CMD_UART, cmd_printfBuff );
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(" %s %s\r\n\0"), SP5K_REV, SP5K_DATE );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* DlgId */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("dlgid: %s\r\n\0"), systemVars.dlgId );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* Fecha y Hora */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("rtc: %02d/%02d/%04d \0"),rtcDateTime.day,rtcDateTime.month, rtcDateTime.year );
		rprintfStr(CMD_UART, cmd_printfBuff );
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("%02d:%02d:%02d\r\n\0"),rtcDateTime.hour,rtcDateTime.min, rtcDateTime.sec );
		rprintfStr(CMD_UART, cmd_printfBuff );

		// SERVER ---------------------------------------------------------------------------------------
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Server:\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* APN */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  apn: %s\r\n\0"), systemVars.apn );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* SERVER IP:SERVER PORT */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  server ip:port: %s:%s\r\n\0"), systemVars.serverAddress,systemVars.serverPort );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* SERVER SCRIPT */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  server script: %s\r\n\0"), systemVars.serverScript );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* SERVER PASSWD */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  passwd: %s\r\n\0"), systemVars.passwd );
		rprintfStr(CMD_UART, cmd_printfBuff );

		// MODEM ---------------------------------------------------------------------------------------
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Modem:\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* Modem status */
		mStatus = getModemStatus();
		switch (mStatus) {
		case M_OFF:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  modem: OFF\r\n\0"));
			break;
		case M_OFF_IDLE:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  modem: OFF Idle\r\n\0"));
			break;
		case M_ON_CONFIG:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  modem: ON & configurating.\r\n\0"));
			break;
		case M_ON_READY:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  modem: ON & ready(apn,ip).\r\n\0"));
			break;
		default:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  modem: ERROR\r\n\0"));
			break;
		}
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* DLGIP */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  dlg ip: %s\r\n\0"), systemVars.dlgIp );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* CSQ */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  signalQ: csq=%d, dBm=%d\r\n\0"), systemVars.csq, systemVars.dbm );
		rprintfStr(CMD_UART, cmd_printfBuff );

		// DCD/RI/TERMSW
		if ( systemVars.dcd == 0 ) { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  pines: dcd=ON,\0")); }
		if ( systemVars.dcd == 1 ) { pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  pines: dcd=OFF,\0"));}
		if ( systemVars.ri == 0 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("ri=ON,\0")); }
		if ( systemVars.ri == 1 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("ri=OFF,\0"));}
		if ( systemVars.termsw == 1 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("term=ON\r\n\0")); }
		if ( systemVars.termsw == 0 ) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("term=OFF\r\n\0"));}
		rprintfStr(CMD_UART, cmd_printfBuff );

		// SYSTEM ---------------------------------------------------------------------------------------
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(">System:\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* Memoria */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  memory: wrPtr=%d, rdPtr=%d, usedRec=%d, freeRecs=%d\r\n\0"), BD_getWRptr(), BD_getRDptr(), BD_getRcsUsed(), BD_getRcsFree() );
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* WRK mode (NORMAL / SERVICE) */
		switch (systemVars.wrkMode) {
		case WK_NORMAL:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  wrkmode: normal\r\n\0"));
			break;
		case WK_SERVICE:
			snprintf_P( &cmd_printfBuff,CHAR128,PSTR("  wrkmode: service\r\n\0"));
			break;
		case WK_MONITOR:
			snprintf_P( &cmd_printfBuff,CHAR128,PSTR("  wrkmode: monitor\r\n\0"));
			break;
		default:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  wrkmode: ERROR\r\n\0"));
			break;
		}
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* PWR mode (CONTINUO / DISCRETO) */
		switch (systemVars.pwrMode) {
		case PWR_CONTINUO:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  pwrmode: continuo\r\n\0"));
			break;
		case PWR_DISCRETO:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  pwrmode: discreto\r\n\0"));
			break;
		default:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  pwrmode: ERROR\r\n\0"));

			break;
		}
		rprintfStr(CMD_UART, cmd_printfBuff );

#ifdef CHANNELS_3
		/* Consigna */
		switch (systemVars.consigna.tipo) {
		case CONS_NONE:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  consigna: none\r\n\0"));
			break;
		case CONS_DOBLE:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  consigna: doble (dia->%02d:%02d, noche->%02d:%02d)\r\n\0"), systemVars.consigna.hh_A,systemVars.consigna.mm_A,systemVars.consigna.hh_B,systemVars.consigna.mm_B );
			break;
		default:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  consigna: ERROR\r\n\0"));
			break;
		}
		rprintfStr(CMD_UART, cmd_printfBuff );
#endif

		/* Timers */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  timerPoll: %d/%d\r\n\0"),systemVars.timerPoll, getTimeToNextPoll() );
		rprintfStr(CMD_UART, cmd_printfBuff );

		if (systemVars.pwrMode == PWR_CONTINUO ) {
			pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  timerDial: -1(%d)/\0"),systemVars.timerDial );
		} else {
			pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  timerDial: %d/\0"),systemVars.timerDial );
		}
		pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("%d\r\n\0"), dialTimer );
		rprintfStr(CMD_UART, cmd_printfBuff );

		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  khTimer: %d\r\n\0"),houseKeepingTimer );
		rprintfStr(CMD_UART, cmd_printfBuff );

		// Debug Options.
		pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  debugLevel: \0"));
		if ( systemVars.debugLevel == D_NONE) {
    		pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("none") );
    	} else {
    		if ( (systemVars.debugLevel & D_DATA) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+data")); }
    		if ( (systemVars.debugLevel & D_GPRS) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+gprs")); }
    		if ( (systemVars.debugLevel & D_BD) != 0)   { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+bd")); }
    		if ( (systemVars.debugLevel & D_I2C) != 0)  { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+i2c")); }
    		if ( (systemVars.debugLevel & D_DIGITAL) != 0)  { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("+digital")); }
    	}
		snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		// Log Options
		pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  logLevel: \0"));
		if ( systemVars.logLevel == LOG_NONE) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("none")); }
		if ( systemVars.logLevel == LOG_INFO) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("info")); }
		if ( systemVars.logLevel == LOG_WARN) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("warn")); }
		if ( systemVars.logLevel == LOG_ALERT) { pos += snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("alert")); }
		snprintf_P( &cmd_printfBuff[pos],CHAR128,PSTR("\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		getStatusGprsSM( &gprsState, &gprsSubState);
		getStatusDataSM( &dataState );
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  tkGprs:%d/%d, tkData:%d\r\n\0"), gprsState, gprsSubState, dataState);
		rprintfStr(CMD_UART, cmd_printfBuff );

		// CONFIG ---------------------------------------------------------------------------------------
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Config:\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		/* Configuracion del sistema */
		switch (mcpDevice) {
		case MCP23008:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  analog=%d, digital=2.\r\n\0"),NRO_CHANNELS);
			break;
		case MCP23018:
			pos = snprintf_P( cmd_printfBuff,CHAR128,PSTR("  analog=%d, digital=2, valves=4.\r\n\0"),NRO_CHANNELS);
			break;
		default:
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("ERROR !! No analog system detected\r\n\0"));
			break;
		}
		rprintfStr(CMD_UART, cmd_printfBuff );

#ifdef CHANNELS_3
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  batt{0-15V}\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );
#endif

		for ( channel = 0; channel < NRO_CHANNELS; channel++) {
			snprintf_P( cmd_printfBuff,CHAR128,PSTR("  a%d{%d-%dmA/%d-%d, %.2f/%.2f}(%s)\r\n\0"),channel, systemVars.Imin[channel],systemVars.Imax[channel],systemVars.Mmin[channel],systemVars.Mmax[channel], systemVars.offmmin[channel], systemVars.offmmax[channel], systemVars. aChName[channel] );
			rprintfStr(CMD_UART, cmd_printfBuff );
		}
		/* Configuracion de canales digitales */
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  d0{%.2f p/p} (%s)\r\n\0"), systemVars.magPP[0],systemVars.dChName[0]);
		rprintfStr(CMD_UART, cmd_printfBuff );
		snprintf_P( cmd_printfBuff,CHAR128,PSTR("  d1{%.2f p/p} (%s)\r\n\0"), systemVars.magPP[1],systemVars.dChName[1]);
		rprintfStr(CMD_UART, cmd_printfBuff );

		// VALUES ---------------------------------------------------------------------------------------
		snprintf_P( cmd_printfBuff,CHAR128,PSTR(">Values:\r\n\0"));
		rprintfStr(CMD_UART, cmd_printfBuff );

		pos = 0;
		// Armo el frame
		memset( &cmd_printfBuff, NULL, CHAR128);
		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR( "  %04d%02d%02d,"),frame.rtc.year,frame.rtc.month, frame.rtc.day );
		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%02d%02d%02d,"),frame.rtc.hour,frame.rtc.min, frame.rtc.sec );
		// Valores analogicos
		for ( channel = 0; channel < NRO_CHANNELS; channel++) {
			pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%s=%.2f,"),systemVars.aChName[channel],frame.analogIn[channel] );
		}
		// Valores digitales.
		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR("%sP=%.2f,"),systemVars.dChName[0], frame.din0_pCount );
		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR( "%sP=%.2f"),  systemVars.dChName[1], frame.din1_pCount );

#ifdef CHANNELS_3
		// Bateria
		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128, PSTR(",bt=%.2f%"),frame.batt );
#endif

		pos += snprintf_P( &cmd_printfBuff[pos], CHAR128,PSTR("\r\n\0") );
		// Imprimo
		rprintfStr(CMD_UART, &cmd_printfBuff );

		xSemaphoreGive( sem_CmdUart );
	}
}
コード例 #9
0
void ad9854ShowRegisters(void)
{
	// read and print all registers

	rprintfStr("Phase1      :         0x");
	rprintfu08(ad9854Read(AD9854_REG_PHASE1H));
	rprintfu08(ad9854Read(AD9854_REG_PHASE1L));
	rprintfCRLF();

	rprintfStr("Phase2      :         0x");
	rprintfu08(ad9854Read(AD9854_REG_PHASE2H));
	rprintfu08(ad9854Read(AD9854_REG_PHASE2L));
	rprintfCRLF();

	rprintfStr("Freq1       : 0x");
	rprintfu08(ad9854Read(AD9854_REG_FREQ15));
	rprintfu08(ad9854Read(AD9854_REG_FREQ14));
	rprintfu08(ad9854Read(AD9854_REG_FREQ13));
	rprintfu08(ad9854Read(AD9854_REG_FREQ12));
	rprintfu08(ad9854Read(AD9854_REG_FREQ11));
	rprintfu08(ad9854Read(AD9854_REG_FREQ10));
	rprintfCRLF();

	rprintfStr("Freq2       : 0x");
	rprintfu08(ad9854Read(AD9854_REG_FREQ25));
	rprintfu08(ad9854Read(AD9854_REG_FREQ24));
	rprintfu08(ad9854Read(AD9854_REG_FREQ23));
	rprintfu08(ad9854Read(AD9854_REG_FREQ22));
	rprintfu08(ad9854Read(AD9854_REG_FREQ21));
	rprintfu08(ad9854Read(AD9854_REG_FREQ20));
	rprintfCRLF();

	rprintfStr("DeltaFreq   : 0x");
	rprintfu08(ad9854Read(AD9854_REG_DELTA5));
	rprintfu08(ad9854Read(AD9854_REG_DELTA4));
	rprintfu08(ad9854Read(AD9854_REG_DELTA3));
	rprintfu08(ad9854Read(AD9854_REG_DELTA2));
	rprintfu08(ad9854Read(AD9854_REG_DELTA1));
	rprintfu08(ad9854Read(AD9854_REG_DELTA0));
	rprintfCRLF();

	rprintfStr("Update Clock:     0x");
	rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK3));
	rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK2));
	rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK1));
	rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK0));
	rprintfCRLF();

	rprintfStr("Ramp Rate   :       0x");
	rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK2));
	rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK1));
	rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK0));
	rprintfCRLF();

	rprintfStr("Control     :     0x");
	rprintfu08(ad9854Read(AD9854_REG_CTRL3));
	rprintfu08(ad9854Read(AD9854_REG_CTRL2));
	rprintfu08(ad9854Read(AD9854_REG_CTRL1));
	rprintfu08(ad9854Read(AD9854_REG_CTRL0));
	rprintfCRLF();

	rprintfStr("Amplitude I :         0x");
	rprintfu08(ad9854Read(AD9854_REG_AMPLIH));
	rprintfu08(ad9854Read(AD9854_REG_AMPLIL));
	rprintfCRLF();

	rprintfStr("Amplitude Q :         0x");
	rprintfu08(ad9854Read(AD9854_REG_AMPLQH));
	rprintfu08(ad9854Read(AD9854_REG_AMPLQL));
	rprintfCRLF();

}
コード例 #10
0
ファイル: nmea.c プロジェクト: lanwan/avrlib2
void nmeaProcessGPGGA(uint8_t* packet)
{
	uint8_t i;
	char* endptr;
	double degrees, minutesfrac;

	#ifdef NMEA_DEBUG_GGA
	rprintf("NMEA: ");
	rprintfStr(packet);
	rprintfCRLF();
	#endif

	// start parsing just after "GPGGA,"
	i = 6;
	// attempt to reject empty packets right away
	if(packet[i]==',' && packet[i+1]==',')
		return;

	// get UTC time [hhmmss.sss]
	GpsInfo.PosLLA.TimeOfFix.f = strtod(&packet[i], &endptr);
	while(packet[i++] != ',');				// next field: latitude
	
	// get latitude [ddmm.mmmmm]
	GpsInfo.PosLLA.lat.f = strtod(&packet[i], &endptr);
	// convert to pure degrees [dd.dddd] format
	minutesfrac = modf(GpsInfo.PosLLA.lat.f/100, &degrees);
	GpsInfo.PosLLA.lat.f = degrees + (minutesfrac*100)/60;
	// convert to radians
	GpsInfo.PosLLA.lat.f *= (M_PI/180);
	while(packet[i++] != ',');				// next field: N/S indicator
	
	// correct latitute for N/S
	if(packet[i] == 'S') GpsInfo.PosLLA.lat.f = -GpsInfo.PosLLA.lat.f;
	while(packet[i++] != ',');				// next field: longitude
	
	// get longitude [ddmm.mmmmm]
	GpsInfo.PosLLA.lon.f = strtod(&packet[i], &endptr);
	// convert to pure degrees [dd.dddd] format
	minutesfrac = modf(GpsInfo.PosLLA.lon.f/100, &degrees);
	GpsInfo.PosLLA.lon.f = degrees + (minutesfrac*100)/60;
	// convert to radians
	GpsInfo.PosLLA.lon.f *= (M_PI/180);
	while(packet[i++] != ',');				// next field: E/W indicator

	// correct latitute for E/W
	if(packet[i] == 'W') GpsInfo.PosLLA.lon.f = -GpsInfo.PosLLA.lon.f;
	while(packet[i++] != ',');				// next field: position fix status

	// position fix status
	// 0 = Invalid, 1 = Valid SPS, 2 = Valid DGPS, 3 = Valid PPS
	// check for good position fix
	if( (packet[i] != '0') && (packet[i] != ',') )
		GpsInfo.PosLLA.updates++;
	while(packet[i++] != ',');				// next field: satellites used
	
	// get number of satellites used in GPS solution
	GpsInfo.numSVs = atoi(&packet[i]);
	while(packet[i++] != ',');				// next field: HDOP (horizontal dilution of precision)
	while(packet[i++] != ',');				// next field: altitude
	
	// get altitude (in meters)
	GpsInfo.PosLLA.alt.f = strtod(&packet[i], &endptr);

	while(packet[i++] != ',');				// next field: altitude units, always 'M'
	while(packet[i++] != ',');				// next field: geoid seperation
	while(packet[i++] != ',');				// next field: seperation units
	while(packet[i++] != ',');				// next field: DGPS age
	while(packet[i++] != ',');				// next field: DGPS station ID
	while(packet[i++] != '*');				// next field: checksum
}
コード例 #11
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	
	// init a few string variables:
	char *welcome_msg1 = "  LC Meter III  ";
	char *welcome_msg2 = "dansworkshop.com";
	char *cal_message1 = "Switch to Cal/C ";
	char *cal_message2 = "for calibration.";
	char *cal_message3 = "calibrating...  ";
	char *blank_lcd_line = "                ";	

	
	// initialize LCD
	lcdInit();


	// init timers and I/O:
	init();
	sei();  // enable global interrupts
	

	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print vanity message on LCD for a second:
	rprintfStr(welcome_msg1);
	lcdGotoXY(0,1);
	rprintfStr(welcome_msg2);
	_delay_ms(1000);
	
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// print a little intro message so we know things are working
	rprintfStr(welcome_msg1);
	rprintf("\r\nhttp://www.");
	rprintfStr(welcome_msg2);
	rprintf("\r\n");


	// instruct about setting mode switch to C for calibration
	if(bit_is_clear(PIND, 4)) {
		rprintfInit(lcdDataWrite);
		lcdGotoXY(0,0);
		rprintfStr(cal_message1);
		lcdGotoXY(0,1);
		rprintfStr(cal_message2);
		
		rprintfInit(uartSendByte);
		rprintfStr(cal_message1);
		rprintfStr(cal_message2);
		rprintf("\r\n");
	}
	while(bit_is_clear(PIND, 4)) {
		// wait for user to switch mode to C
	}
	
	// send out the calibration message:
	rprintfStr(cal_message3);
	rprintf("\r\n");
	rprintfInit(lcdDataWrite);
	lcdGotoXY(0,0);
	rprintfStr(cal_message3);
	lcdGotoXY(0,1);
	rprintfStr(blank_lcd_line);

	rprintfInit(uartSendByte);

	_delay_ms(1600);
	F1 = running;			// get open frequency
	rprintfNum(10, 10, 0, ' ', F1 * 5);
	rprintf("\r\n");
	sbi(PORTD, PD3); 		// energize relay
	_delay_ms(1000);			// stabilize
	F2 = running;			// get test frequency
	rprintfNum(10, 10, 0, ' ', F2 * 5);
	rprintf("\r\n");
	cbi(PORTD, PD3);		// turn off relay
		
	// do some floating point:
	Cs = square(F2 * 5) * (.00000000092 / (square(F1 * 5) - square(F2 * 5))); // this should fit in a 64-bit value
	Ls = 1 / (4 * square(M_PI) * square(F1 * 5) * Cs);
	
	// everything out of the lcd for now:
	rprintfInit(lcdDataWrite);
	

	// enable  PC5 as output
	sbi(DDRC, PC5);
	while (1) {
		_delay_ms(200);
		lcdGotoXY(0,0);
		if(bit_is_clear(PIND, 4)) { // inductance measurement mode
			if(running < 3) {
				rprintf("Not an inductor                 \r");
			} else {
				Lt = (square(F1 * 5) / (square(running * 5)) - 1) * Ls;
				rprintf("Lx: ");
				if(Lt > .0001) {
					rprintfFloat(4, Lt * 1000);
					rprintf("mH");
				}
				
				else if(Lt > .0000001) {
					rprintfFloat(4, Lt * 1000000);
					rprintf("uH");
				}
					
				else {
					rprintfFloat(4, Lt * 1000000000);
					rprintf("nH");
				}
					
				rprintf("             \r");
			}
		} else {					// capacitance measurement mode
			if(running < 300) {
				rprintf("Not a capacitor                 \r");
			} else {
				Ct = (square(F1 * 5) / (square(running * 5)) - 1) * Cs;
				rprintf("Cx: ");
				if(Ct > .0001) {
					rprintfFloat(4, Ct * 1000);
					rprintf("mF");
				}
				
				else if(Ct > .0000001) {
					rprintfFloat(4, Ct * 1000000);
					rprintf("uF");
				}
					
				else if(Ct > .0000000001){
					rprintfFloat(4, Ct * 1000000000);
					rprintf("nF");
				}

				else {
					rprintfFloat(4, Ct * 1000000000000);
					rprintf("pF");
				}
					
				rprintf("             \r");
			}
		}

		if(bit_is_clear(PIND, 7)) {
			lcdGotoXY(0,0);
			rprintf("zeroed                \r");
			lcdGotoXY(0,1);
			rprintfStr(blank_lcd_line);
			lcdGotoXY(0,0);
			F1 = running;
		}

		while(bit_is_clear(PIND, 7)) {
			// do nothing till the user lets go of the zero button
		}

		// display the 
		lcdGotoXY(0,1);
		rprintfNum(10, 6, 0, ' ', running * 5);
		rprintf("Hz        ");

	}


	return 0;
}
コード例 #12
0
ファイル: i2ctest.c プロジェクト: BackupTheBerlios/rundfunker
void i2cTest(void)
{
	u08 c=0;
	showByte(0x55);

	// initialize i2c function library
	i2cInit();
	// set local device address and allow response to general call
	i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);
	// set the Slave Receive Handler function
	// (this function will run whenever a master somewhere else on the bus
	//  writes data to us as a slave)
	i2cSetSlaveReceiveHandler( i2cSlaveReceiveService );
	// set the Slave Transmit Handler function
	// (this function will run whenever a master somewhere else on the bus
	//  attempts to read data from us as a slave)
	i2cSetSlaveTransmitHandler( i2cSlaveTransmitService );

	timerPause(500);
	showByte(0xAA);

	while(1)
	{
		rprintf("Command>");
		while(!c) uartReceiveByte(&c);
		
		switch(c)
		{
		case 's':
			rprintf("Send: ");
			// get string from terminal
			localBufferLength = 0;
			c = 0;
			while((c != 0x0D) && (localBufferLength < 0x20))
			{
				while(!uartReceiveByte(&c));
				localBuffer[localBufferLength++] = c;
				uartSendByte(c);
			}
			// switch CR to NULL to terminate string
			localBuffer[localBufferLength-1] = 0;
			// send string over I2C
			i2cMasterSend(TARGET_ADDR, localBufferLength, localBuffer);
			//i2cMasterSendNI(TARGET_ADDR, localBufferLength, localBuffer);
			rprintfCRLF();
			break;
		case 'r':
			rprintf("Receive: ");
			// receive string over I2C
			i2cMasterReceive(TARGET_ADDR, 0x10, localBuffer);
			//i2cMasterReceiveNI(TARGET_ADDR, 0x10, localBuffer);
			// format buffer
			localBuffer[0x10] = 0;
			rprintfStr(localBuffer);
			rprintfCRLF();
			break;
		case 'm':
			testI2cMemory();
			break;
		default:
			rprintf("Unknown Command!");
			break;
		}
		c = 0;
		rprintfCRLF();
	}

}
コード例 #13
0
ファイル: i2ctest.c プロジェクト: BackupTheBerlios/rundfunker
void testI2cMemory(void)
{
	u08 i;
	u08 txdata[66];
	u08 rxdata[66];

	rprintfProgStrM("\r\nRunning I2C memory test (24xxyy devices)\r\n");

	// compose address
	txdata[0] = 0;
	txdata[1] = 0;
	// compose data
	for(i=0; i<16; i++)
		txdata[2+i] = localBuffer[i];
	// send address and data
	i2cMasterSendNI(TARGET_ADDR, 18, txdata);
	
	rprintfProgStrM("Stored data: ");
	// null-terminate data
	txdata[18] = 0;
	rprintfStr(&txdata[2]);
	rprintfCRLF();
	
	timerPause(100);

	// send address
	i2cMasterSendNI(TARGET_ADDR, 2, txdata);
	// get data
	i2cMasterReceiveNI(TARGET_ADDR, 16, rxdata);
	// null-terminate received string
	rxdata[16] = 0;

	rprintfProgStrM("Received data: ");
	rprintfStr(rxdata);
	rprintfCRLF();
/*
	u08 c;
	u16 addr=0;

	while(1)
	{
		while(!uartReceiveByte(&c));

		switch(c)
		{
		case '+':
			addr+=64;
			break;
		case '-':
			addr-=64;
			break;
		}
		c = 0;
		txdata[0] = (addr>>8);
		txdata[1] = (addr&0x00FF);
		i2cMasterSendNI(TARGET_ADDR, 2, txdata);
		i2cMasterReceiveNI(TARGET_ADDR, 64, rxdata);
		rprintfProgStrM("Received data at ");
		rprintfu16(addr);
		rprintfProgStrM(":\r\n");
		debugPrintHexTable(64, rxdata);
	}
*/
}
コード例 #14
0
void rprintfTest(void)
{
	u16 val;
	u08 mydata;
	u08 mystring[10];
	float b;
	u08 small;
	u16 medium;
	u32 big;

	// print a little intro message so we know things are working
	rprintf("\r\nThis is my cool program!\r\n");

	
	rprintf("\r\nWelcome to rprintf Test!\r\n");

	// print single characters
	rprintfChar('H');
	rprintfChar('e');
	rprintfChar('l');
	rprintfChar('l');
	rprintfChar('o');
	// print a constant string stored in FLASH
	rprintfProgStrM(" World!");
	// print a carriage return, line feed combination
	rprintfCRLF();
	// note that using rprintfCRLF() is more memory-efficient than
	// using rprintf("\r\n"), especially if you do it repeatedly

	mystring[0] = 'A';
	mystring[1] = ' ';
	mystring[2] = 'S';
	mystring[3] = 't';
	mystring[4] = 'r';
	mystring[5] = 'i';
	mystring[6] = 'n';
	mystring[7] = 'g';
	mystring[8] = '!';
	mystring[9] = 0;	// null termination

	// print a null-terminated string from RAM
	rprintfStr(mystring);
	rprintfCRLF();

	// print a section of a string from RAM
	// - start at index 2
	// - print 6 characters
	rprintfStrLen(mystring, 2, 6);
	rprintfCRLF();


	val = 24060;
	mydata = 'L';

	// print a decimal number
	rprintf("This is a decimal number: %d\r\n", val);

	// print a hex number
	rprintf("This is a hex number: %x\r\n", mydata);
	
	// print a character
	rprintf("This is a character: %c\r\n", mydata);

	// print hex numbers
	small = 0x12;		// a char
	medium = 0x1234;	// a short
	big = 0x12345678;	// a long

	rprintf("This is a 2-digit hex number (char) : ");
	rprintfu08(small);
	rprintfCRLF();

	rprintf("This is a 4-digit hex number (short): ");
	rprintfu16(medium);
	rprintfCRLF();

	rprintf("This is a 8-digit hex number (long) : ");
	rprintfu32(big);
	rprintfCRLF();

	// print a formatted decimal number
	// - use base 10
	// - use 8 characters
	// - the number is signed [TRUE]
	// - pad with '.' periods
	rprintf("This is a formatted decimal number: ");
	rprintfNum(10, 8, TRUE, '.', val);
	rprintfCRLF();

	b = 1.23456;

	// print a floating point number
	// use 10-digit precision
	
	// NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h
	// use the following in your global.h: #define RPRINTF_FLOAT

	//rprintf("This is a floating point number: ");
	//rprintfFloat(8, b);
	//rprintfCRLF();
}
コード例 #15
0
ファイル: main.c プロジェクト: sndae/b3r1
/*******************************************************************
*		rprintf_test
*******************************************************************/
void rprintf_test(void)
{
    u16 val;
    u08 mydata;
    u08 mystring[10];
    double b;
    u08 small;
    u16 medium;
    u32 big;

    // initialize the UART (serial port)
    uartInit();

    // set the baud rate of the UART for our debug/reporting output
    uartSetBaudRate(38400);

    // initialize rprintf system
    // - use uartSendByte as the output for all rprintf statements
    //   this will cause all rprintf library functions to direct their
    //   output to the uart
    // - rprintf can be made to output to any device which takes characters.
    //   You must write a function which takes an unsigned char as an argument
    //   and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
    rprintfInit(uartSendByte);

    // initialize vt100 library
    vt100Init();

    // clear the terminal screen
    vt100ClearScreen();

    while (!(getkey() == 1))		//do the folling block until enter is pressed
    {

        // print a little intro message so we know things are working
        rprintf("\r\nWelcome to rprintf Test!\r\n");

        // print single characters
        rprintfChar('H');
        rprintfChar('e');
        rprintfChar('l');
        rprintfChar('l');
        rprintfChar('o');
        // print a constant string stored in FLASH
        rprintfProgStrM(" World!");
        // print a carriage return, line feed combination
        rprintfCRLF();
        // note that using rprintfCRLF() is more memory-efficient than
        // using rprintf("\r\n"), especially if you do it repeatedly

        mystring[0] = 'A';
        mystring[1] = ' ';
        mystring[2] = 'S';
        mystring[3] = 't';
        mystring[4] = 'r';
        mystring[5] = 'i';
        mystring[6] = 'n';
        mystring[7] = 'g';
        mystring[8] = '!';
        mystring[9] = 0;	// null termination

        // print a null-terminated string from RAM
        rprintfStr(mystring);
        rprintfCRLF();

        // print a section of a string from RAM
        // - start at index 2
        // - print 6 characters
        rprintfStrLen(mystring, 2, 6);
        rprintfCRLF();


        val = 24060;
        mydata = 'L';

        // print a decimal number
        rprintf("This is a decimal number: %d\r\n", val);

        // print a hex number
        rprintf("This is a hex number: %x\r\n", mydata);

        // print a character
        rprintf("This is a character: %c\r\n", mydata);

        // print hex numbers
        small = 0x12;		// a char
        medium = 0x1234;	// a short
        big = 0x12345678;	// a long

        rprintf("This is a 2-digit hex number (char) : ");
        rprintfu08(small);
        rprintfCRLF();

        rprintf("This is a 4-digit hex number (short): ");
        rprintfu16(medium);
        rprintfCRLF();

        rprintf("This is a 8-digit hex number (long) : ");
        rprintfu32(big);
        rprintfCRLF();

        // print a formatted decimal number
        // - use base 10
        // - use 8 characters
        // - the number is signed [TRUE]
        // - pad with '.' periods
        rprintf("This is a formatted decimal number: ");
        rprintfNum(10, 8, TRUE, '.', val);
        rprintfCRLF();

        b = 1.23456;

        // print a floating point number
        // use 10-digit precision

        // NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h
        // use the following in your global.h: #define RPRINTF_FLOAT

        rprintf("This is a floating point number: ");
        rprintfFloat(8, b);
        rprintfCRLF();
    }
}
コード例 #16
0
ファイル: mitelgps.c プロジェクト: 46nori/avr-liberty
u08 mitelgpsProcess(cBuffer* rxBuffer)
{
	u08 foundpacket = FALSE;
	u08 startFlag = FALSE;
	u08 checksum = 0;
	u08 packetType;
	u16 i,j;

	// process the receive buffer
	// go through buffer looking for packets
	while(rxBuffer->datalength > 1)
	{
		// look for a start of Mitel GPS STX/ETX packet
		if(bufferGetAtIndex(rxBuffer,0) == STX)
		{
			// found start
			startFlag = TRUE;
			// done looking for start
			break;
		}
		else
			// not STX, dump character from buffer
			bufferGetFromFront(rxBuffer);
	}
	
	// if we detected a start, look for end of packet
	if(startFlag)
	{
		for(i=1; i<(rxBuffer->datalength); i++)
		{
			// check for end of Mitel GPS STX/ETX packet
			if(bufferGetAtIndex(rxBuffer,i) == ETX)
			{
				// have a packet end
				// dump initial STX
				bufferGetFromFront(rxBuffer);
				// copy data to MitelGpsPacket
				for(j=0; j<(i-1); j++)
				{
					MitelGpsPacket[j] = bufferGetFromFront(rxBuffer);
					checksum ^= MitelGpsPacket[j];
				}
				// null-terminate copied string
				MitelGpsPacket[j] = 0;
				// dump ending ETX
				bufferGetFromFront(rxBuffer);

				// verify checksum
				// undo checksum summing of the checksum itself
				checksum ^= MitelGpsPacket[j-2];
				checksum ^= MitelGpsPacket[j-1];
				if( checksum == convertAsciiHexToInt(&MitelGpsPacket[j-2], 2) )
				{
					// found a good packet
					if(debug & MITELGPS_DEBUG_PKTPARSE)
					{
						rprintf("Rx Mitel GPS packet type: %c%c%c  len: %d\r\n",
							MitelGpsPacket[0], MitelGpsPacket[1], MitelGpsPacket[2], j);
						rprintfStr(MitelGpsPacket);
						rprintfCRLF();
					}
					// done with this processing session
					foundpacket = TRUE;
					break;
				}
				else
				{
					if(debug & MITELGPS_DEBUG_PKTPARSE)
					{
						rprintf("Rx Mitel GPS packet type: %c%c%c len: %d  Bad Checksum Rcvd: 0x%c%c Calc: 0x%x\r\n",
							MitelGpsPacket[0], MitelGpsPacket[1], MitelGpsPacket[2], j, MitelGpsPacket[j-2], MitelGpsPacket[j-1], checksum);
					}
				}
			}
		}
	}

	// handle and direct the received packet
	if(foundpacket)
	{
		// switch on the packet type
		packetType = convertAsciiHexToInt(&MitelGpsPacket[1], 2);
		switch( packetType )
		{
		case MITELTYPE_NAVDATAGND:	mitelgpsProcessNAVDATAGND(MitelGpsPacket); break;
		case MITELTYPE_CHNLSTATGND:	mitelgpsProcessCHNLSTATGND(MitelGpsPacket); break;
		case MITELTYPE_NAVDATA:		mitelgpsProcessNAVDATA(MitelGpsPacket); break;
		case MITELTYPE_RAWDATA:		mitelgpsProcessRAWDATA(MitelGpsPacket); break;
		case MITELTYPE_CHNLSTAT:	mitelgpsProcessCHNLSTAT(MitelGpsPacket); break;
		case MITELTYPE_RELNAVECEF:	break;
		case MITELTYPE_RELNAVRTN:	break;
		default:
			if(debug & MITELGPS_DEBUG_PKTPARSE)
				rprintf("Unhandled Mitel GPS packet type: 0x%x\r\n", packetType);
			break;
		}
	}

	return foundpacket;
}