Exemple #1
0
static int
rtc_ricoh_rx5c348_get_alm_time(struct rtc_time *alm_tm)
{	
	u8 alm_time[2];
  
	rtc_read_burst(0xb, alm_time, sizeof(alm_time));
  
	alm_tm->tm_hour = BcdToDec(alm_time[1]);
	alm_tm->tm_min  = BcdToDec(alm_time[0]);

#ifdef DEBUG
	printk(KERN_INFO "rtc_ricoh_rx5c348_get_alm_time: %02d:%02d\n",
					alm_tm->tm_hour, alm_tm->tm_min);
#endif
	return 0;
}
Exemple #2
0
static unsigned long
rtc_ricoh_rx5c348_get_time(void)
{	
	u8 date[7];
	unsigned int year, month, day, hour, minute, second;
  
	rtc_read_burst(0, date, sizeof(date));
  
	year   = BcdToDec(date[6]) + (date[5] & 0x80 ? 2000 : 1900);
	month  = BcdToDec(date[5] & 0x1f);
	day    = BcdToDec(date[4]);
	hour   = BcdToDec(date[2]);
	minute = BcdToDec(date[1]);
	second = BcdToDec(date[0]);

#ifdef DEBUG
	printk(KERN_INFO "rtc_ricoh_rx5c348_get_time: %d/%02d/%02d %02d:%02d:%02d\n",
	year, month, day, hour, minute, second);
#endif
	return mktime(year, month, day, hour, minute, second);
}
// ****************************************************************************
// *** Main Function **********************************************************
// ****************************************************************************
void main(void)
{
    	initialization();
        sendTextMessage("What Hath God Wrought? Number 1");

        while(1){
//            sendTextMessage("What Hath God Wrought \r\n");
//            int angleForMessage = getHandleAngle();
//            char angleMessage[20];
//            angleMessage[0]=0;
//            longToString(angleForMessage, angleMessage);
//
//            concat(angleMessage, "\r \n");
//            sendMessage("angle: ");
//            sendMessage(angleMessage);
        }


	waterPrimeTimeOut /= upstrokeInterval;
	leakRateTimeOut /= upstrokeInterval;
	//timeBetweenUpstrokes /= upstrokeInterval;

	// Do all of these values need to be reset each time around the loop? Or at the end of the day? 06-16-2014
	int handleMovement = 0; // Either 1 or no 0 if the handle moving upward
	int timeOutStatus = 0; // Used to keep track of the water prime timeout
	int hour = 0; // Hour of day
	float angleCurrent = 0; // Stores the current angle of the pump handle
	float anglePrevious = 0; // Stores the last recoreded angle of the pump handle
	float angleDelta = 0; // Stores the difference between the current and previous angles
	float upStroke = 0; // 0 if there is no upstroke, otherwise stores the delta angle
	float upStrokePrime = 0; // Stores the sum of the upstrokes for calculating the prime
	float upStrokeExtract = 0; // Stores the sum of the upstrokes for calculating volume
	float volumeEvent = 0; // Stores the volume extracted
        float leakRatePrevious = 0; // Stores the previous Leak Rate incase if someone stats to pump before leakage can be measured
        //float extractionStartTime = 0; // The time of day (in seconds) when the extraction started
	//float extractionEndTime = 0; // The time of day (in seconds) when the extraction ended
	//float extractionDuration = 0; // The difference between the extraction start and end times
	long leakTimeCounter = 0; // Used to keep track of the leak time timeout
	float upStrokePrimeMeters = 0; // Stores the upstroke in meters
	float leakRate = 0; // Rate at which water is leaking from the rising main
//	float leakTime = 0; // The number of milliseconds from when the user stops pumping until there is no water (min: 0, max: 10 minutes)
//	long upStrokeDelayCounter = 0;
//        int currentHour;
        int currentDay;
        int currentHourDepthSensor;

        float deltaAverage;

	while (1)
	{ //MAIN LOOP; repeats indefinitely
		////////////////////////////////////////////////////////////
		// Idle Handle Monitor Loop
		// 2 axis of the accelerometer are constantly polled for
		// motion in the upward direction by comparing angles
		////////////////////////////////////////////////////////////
		// Get the angle of the pump handle to measure against
		anglePrevious = getHandleAngle();
		float previousAverage = 0;
		// Set the handle movement to 0 (handle is not moving)
		handleMovement = 0;
		// Loop until the handle starts moving
                float angleAccumulated=0;
		while (handleMovement == 0)
		{
                          currentDay = getDateI2C();
			if ( prevDay != currentDay){ //(prevDay != getDateI2C()){// it's a new day so send midNightMessage();
                                batteryFloat = batteryLevel();
				midnightMessage();
			}
                          if (depthSensorInUse == 1){ // if the Depth sensor is present
                              delayMs(1000);
                              int currentDayDepthSensor = BcdToDec(getDateI2C());
                              delayMs(1000);
                          if ((BcdToDec(getHourI2C() == 12) && (prevDayDepthSensor != currentDayDepthSensor)));
                          midDayDepthRead();
                          }

			delayMs(upstrokeInterval); // Delay for a short time
                        float newAngle = getHandleAngle();
                        float deltaAngle = abs(newAngle - anglePrevious);
                        anglePrevious = newAngle;
                        if (deltaAngle > 2){ // prevents floating accelerometer values when it's not actually moving
                        angleAccumulated += deltaAngle;
                        }
			// If the angle has changed, set the handleMovement flag
			if (angleAccumulated > 5) //05-30-14 Test for small delta's used to be angleDeltaThreshold
			{
				handleMovement = 1;
			}
		}
                /////////////////////////////////////////////////////////
		// Priming Loop
		// The total amount of upstroke is recorded while the
		// upper water sensor is checked to determine if the
		// pump has been primed
		/////////////////////////////////////////////////////////
		timeOutStatus = 0; // prepares timeoutstatus for new event
		// Get the angle of the pump handle to measure against
		anglePrevious = getHandleAngle();
		upStrokePrime = 0; // gets the variable ready for a new event
                upStroke = 0; // gets variable ready for new event

                // averaging angle Code 9/17/2015
                initializeQueue(anglePrevious);
		previousAverage = queueAverage();
                // Averaging angle code

		while ((timeOutStatus < waterPrimeTimeOut) && !readWaterSensor())
		{
			delayMs(upstrokeInterval);  // delay a short time (10ms)

                        // averaging angle Code 9/17/2015
                        pushToQueue(getHandleAngle()); //get Current angle of the pump handle
                        deltaAverage = queueAverage() - previousAverage();
                        previousAverage = queueAverage();
                        
                        
                        // end averaging angle Code

                        angleCurrent = getHandleAngle(); // Get the current angle of the pump handle
			angleDelta = angleCurrent - anglePrevious; // Calculate the change in angle of the pump handle
                        //if(angleDelta > 5){
                        if (deltaAverage > 5){ // averaging angle code 9/17/2015
                            upStroke + = deltaAverage; // angle Code 9/17/2015
                           // upStroke += angleDelta;
                            upStrokePrime += degToRad(upStroke); // Update the upStrokePrime
                            timeOutStatus=0;
                        // upstroke and current angle
			}
                        else{
                        timeOutStatus++;}
			anglePrevious = angleCurrent; // Update the previous angle for the next calculation
			}
BOOL ReadTOCFull(
	PEXT_ARG pExtArg,
	PDEVICE pDevice,
	PDISC pDisc,
	FILE* fpCcd
	)
{
	CDB::_READ_TOC cdb = { 0 };
	cdb.OperationCode = SCSIOP_READ_TOC;
	cdb.LogicalUnitNumber = pDevice->address.Lun;
	cdb.Format2 = CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
	cdb.StartingTrack = 1;
	WORD wSize = sizeof(CDROM_TOC_FULL_TOC_DATA);
	REVERSE_BYTES_SHORT(&cdb.AllocationLength, &wSize);

	_declspec(align(4)) CDROM_TOC_FULL_TOC_DATA fullToc = { 0 };
#ifdef _DEBUG
	OutputString(_T("fullToc address: %p\n"), &fullToc);
#endif
	LPBYTE pBuf = NULL;
	LPBYTE lpBuf = NULL;
	BYTE lpCmd[CDB12GENERIC_LENGTH] = { 0 };
	INT nOfs = 0;
	BYTE byMode = DATA_BLOCK_MODE0;
	BYTE bySessionNum = 0;
	BYTE byScsiStatus = 0;
	if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB10GENERIC_LENGTH
		, &fullToc,	wSize, &byScsiStatus, _T(__FUNCTION__), __LINE__)
		|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
		if (!ReadCDForCheckingSubQAdrFirst(
			pExtArg, pDevice, pDisc, &pBuf, &lpBuf, lpCmd, &nOfs)) {
			return FALSE;
		}
		for (BYTE i = 0; i < pDisc->SCSI.toc.LastTrack; i++) {
			if (!ReadCDForCheckingSubQAdr(pExtArg
				, pDevice, pDisc, lpCmd, lpBuf, nOfs, i, &byMode, 1, fpCcd)) {
				return FALSE;
			}
			if (bySessionNum < 1) {
				WriteCcdForSession(1, byMode, fpCcd);
				bySessionNum++;
			}
			OutputString(
				_T("\rChecking SubQ adr (Track) %2u/%2u"), i + 1, pDisc->SCSI.toc.LastTrack);
		}
		OutputString(_T("\n"));
		pDevice->bySuccessReadTocFull = FALSE;
		return TRUE;
	}
	WORD wFullTocLen = MAKEWORD(fullToc.Length[1], fullToc.Length[0]);
	WORD wTocEntriesAll = wFullTocLen - sizeof(fullToc.Length);
	WORD wTocEntries = wTocEntriesAll / sizeof(CDROM_TOC_FULL_TOC_DATA_BLOCK);

	if (fpCcd) {
		WriteCcdForDisc(wTocEntries, fullToc.LastCompleteSession, fpCcd);
		if (pDevice->FEATURE.byCanCDText) {
			ReadTOCText(pExtArg, pDevice, pDisc, fpCcd);
		}
	}

	WORD wFullTocLenFix = wTocEntriesAll + sizeof(CDROM_TOC_FULL_TOC_DATA);
	// 4 byte padding
	if (wFullTocLenFix % 4) {
		wFullTocLenFix = (WORD)((wFullTocLenFix / 4 + 1) * 4);
	}
	LPBYTE pPFullToc = NULL;
	LPBYTE pFullToc = NULL;
	if (!GetAlignedCallocatedBuffer(pDevice, &pPFullToc,
		wFullTocLenFix, &pFullToc, _T(__FUNCTION__), __LINE__)) {
		return FALSE;
	}
#ifdef _DEBUG
	OutputDiscLogA(
		"FullTocLen: %u, TocEntriesAll: %u, TocEntries: %u, FullTocLenFix: %u\n",
		wFullTocLen, wTocEntriesAll, wTocEntries, wFullTocLenFix);
	OutputString(_T("pPFullToc address: %p\n"), &pPFullToc);
	OutputString(_T("pFullToc address: %p\n"), &pFullToc);
#endif
	REVERSE_BYTES_SHORT(&cdb.AllocationLength, &wFullTocLenFix);
	BOOL bRet = TRUE;
	try {
		if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB10GENERIC_LENGTH
			, pFullToc,	wFullTocLenFix, &byScsiStatus, _T(__FUNCTION__), __LINE__)
			|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
			throw FALSE;
		}
		PCDROM_TOC_FULL_TOC_DATA_BLOCK pTocData =
			((PCDROM_TOC_FULL_TOC_DATA)pFullToc)->Descriptors;
		if (!ReadCDForCheckingSubQAdrFirst(pExtArg
			, pDevice, pDisc, &pBuf, &lpBuf, lpCmd, &nOfs)) {
			throw FALSE;
		}
		for (WORD i = 0; i < wTocEntries; i++) {
			if (pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX40TS) {
				// Somehow Ultraplex seems to get the fulltoc data as "hexadecimal"
				pTocData[i].Msf[0] = BcdToDec(pTocData[i].Msf[0]);
				pTocData[i].Msf[1] = BcdToDec(pTocData[i].Msf[1]);
				pTocData[i].Msf[2] = BcdToDec(pTocData[i].Msf[2]);
				pTocData[i].MsfExtra[0] = BcdToDec(pTocData[i].MsfExtra[0]);
				pTocData[i].MsfExtra[1] = BcdToDec(pTocData[i].MsfExtra[1]);
				pTocData[i].MsfExtra[2] = BcdToDec(pTocData[i].MsfExtra[2]);
				if (pTocData[i].Point < 0xa0) {
					pTocData[i].Point = BcdToDec(pTocData[i].Point);
				}
			}
			if (pTocData[i].Point < 100) {
				if (!ReadCDForCheckingSubQAdr(pExtArg, pDevice, pDisc, lpCmd, lpBuf, nOfs
					, (BYTE)(pTocData[i].Point - 1), &byMode, pTocData[i].SessionNumber, fpCcd)) {
					throw FALSE;
				}
				if (bySessionNum < pTocData[i].SessionNumber) {
					WriteCcdForSession(pTocData[i].SessionNumber, byMode, fpCcd);
					bySessionNum++;
				}
				OutputString(
					_T("\rChecking SubQ adr (Track) %2u/%2u"), pTocData[i].Point, pDisc->SCSI.toc.LastTrack);
			}
		}
		OutputString(_T("\n"));
		SetAndOutputTocFull(pDisc, &fullToc, pTocData, wTocEntries, fpCcd);
	}
	catch (BOOL ret) {
		bRet = ret;
	}
	pDevice->bySuccessReadTocFull = TRUE;
	FreeAndNull(pPFullToc);
	FreeAndNull(pBuf);
	return bRet;
}