예제 #1
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LoadUnitConfig(void)
{
	GetRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);

	// Check if the Unit Config is uninitialized
	if (g_unitConfig.validationKey != 0xA5A5)
	{
		// Set defaults in Unit Config
		debugWarn("Unit Config: Not found.\r\n");
#if EXTENDED_DEBUG
		debug("Loading Unit Config Defaults\r\n");
#endif

		LoadUnitConfigDefaults((UNIT_CONFIG_STRUCT*)&g_unitConfig);
		SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);
	}
	else
	{
		// Unit Config is valid
#if EXTENDED_DEBUG
		debug("Unit Config record is valid\r\n");
#endif

		if ((g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_QUARTER_SEC_DIV) && (g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_HALF_SEC_DIV) &&
			(g_unitConfig.pretrigBufferDivider != PRETRIGGER_BUFFER_FULL_SEC_DIV))
		{
			g_unitConfig.pretrigBufferDivider = PRETRIGGER_BUFFER_QUARTER_SEC_DIV;
			SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);
		}

#if 1 // Forcing flash wrapping to be disabled
		g_unitConfig.flashWrapping = NO;
#endif

#if 0 // Moved this init to the hardware section to allow for the saved Baud rate to be established from the start
		// Set the baud rate to the user stored baud rate setting (initialized to 115200)
		switch (g_unitConfig.baudRate)
		{
			case BAUD_RATE_57600: rs232Options.baudrate = 57600; break;
			case BAUD_RATE_38400: rs232Options.baudrate = 38400; break;
			case BAUD_RATE_19200: rs232Options.baudrate = 19200; break;
			case BAUD_RATE_9600: rs232Options.baudrate = 9600; break;
		}

		if (g_unitConfig.baudRate != BAUD_RATE_115200)
		{
			// Re-Initialize the RS232 with the stored baud rate
			usart_init_rs232(&AVR32_USART1, &rs232Options, FOSC0);
		}
#endif
	}
}
예제 #2
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LoadDefaultTriggerRecord(void)
{
	GetRecordData(&g_triggerRecord, DEFAULT_RECORD, REC_TRIGGER_USER_MENU_TYPE);

	// Check if the Default Trig Record is uninitialized
	if (g_triggerRecord.validRecord != YES)
	{
		debugWarn("Default Trigger Record: Invalid, loading defaults\r\n");
		LoadTrigRecordDefaults(&g_triggerRecord, WAVEFORM_MODE);
		SaveRecordData(&g_triggerRecord, DEFAULT_RECORD, REC_TRIGGER_USER_MENU_TYPE);
	}
	else
	{
		debug("Default Trigger record is valid\r\n");
	}
}
예제 #3
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LoadModemSetupRecord(void)
{
	GetRecordData(&g_modemSetupRecord, 0, REC_MODEM_SETUP_TYPE);

	// Check if the Modem Setup Record is invalid
	if (g_modemSetupRecord.invalid)
	{
		// Warn the user
		debugWarn("Modem setup record not found.\r\n");

		// Initialize the Modem Setup Record
		LoadModemSetupRecordDefaults();

		// Save the Modem Setup Record
		SaveRecordData(&g_modemSetupRecord, DEFAULT_RECORD, REC_MODEM_SETUP_TYPE);
	}
	else
	{
#if EXTENDED_DEBUG
		debug("Modem Setup record is valid\r\n");
#endif
		ValidateModemSetupParameters();
	}
}
static void DebugWarn (const char* str)
{
    if (debugWarn)
        debugWarn(str);
}
예제 #5
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LoadFactorySetupRecord(void)
{
	DATE_TIME_STRUCT tempTime;
	char buff[50];

	GetRecordData(&g_factorySetupRecord, DEFAULT_RECORD, REC_FACTORY_SETUP_TYPE);

	// Check if the Factory Setup Record is invalid
	if (g_factorySetupRecord.invalid)
	{
		// Warn the user
		debugWarn("Factory setup record not found.\r\n");
		OverlayMessage(getLangText(ERROR_TEXT), getLangText(FACTORY_SETUP_DATA_COULD_NOT_BE_FOUND_TEXT), (2 * SOFT_SECS));

		// Check if the Shadow Factory setup is valid
		if (!SHADOW_FACTORY_SETUP_CLEARED)
		{
			// Warn the user
			debugWarn("Factory setup shadow copy exists.\r\n");
			if (MessageBox(getLangText(CONFIRM_TEXT), getLangText(RESTORE_FACTORY_SETUP_FROM_BACKUP_Q_TEXT), MB_YESNO) == MB_FIRST_CHOICE)
			{
				GetFlashUserPageFactorySetup(&g_factorySetupRecord);
				SaveRecordData(&g_factorySetupRecord, DEFAULT_RECORD, REC_FACTORY_SETUP_TYPE);
			}
		}
	}

	// Check if the Factory Setup Record is valid (in case shadow factory setup was copied over)
	if (!g_factorySetupRecord.invalid)
	{
		if (g_seismicSmartSensorMemory.version & SMART_SENSOR_OVERLAY_KEY)
		{
			g_factorySetupRecord.seismicSensorType = (pow(2, g_seismicSmartSensorMemory.sensorType) * SENSOR_2_5_IN);
		}

		if (g_acousticSmartSensorMemory.version & SMART_SENSOR_OVERLAY_KEY)
		{
			if ((g_acousticSmartSensorMemory.sensorType == SENSOR_MIC_148) || (g_acousticSmartSensorMemory.sensorType == SENSOR_MIC_160))
			{
				g_factorySetupRecord.acousticSensorType = g_acousticSmartSensorMemory.sensorType;
			}
		}

		UpdateWorkingCalibrationDate();

		// Print the Factory Setup Record to the console
		memset(&buff[0], 0, sizeof(buff));
		ConvertCalDatetoDateTime(&tempTime, &g_currentCalibration.date);
		ConvertTimeStampToString(buff, &tempTime, REC_DATE_TYPE);

		if (g_factorySetupRecord.seismicSensorType > SENSOR_ACC_RANGE_DIVIDER) { strcpy((char*)&g_spareBuffer, "Acc"); }
		else { sprintf((char*)&g_spareBuffer, "%3.1f in", (float)g_factorySetupRecord.seismicSensorType / (float)204.8); }

		// Check if an older unit doesn't have the Analog Channel Config set
		if ((g_factorySetupRecord.analogChannelConfig != CHANNELS_R_AND_V_SCHEMATIC) && (g_factorySetupRecord.analogChannelConfig != CHANNELS_R_AND_V_SWAPPED))
		{
			// Set the default
			g_factorySetupRecord.analogChannelConfig = CHANNELS_R_AND_V_SWAPPED;
		}

		debug("Factory Setup: Serial #: %s\r\n", g_factorySetupRecord.unitSerialNumber);
		debug("Factory Setup: Cal Date: %s\r\n", buff);
		debug("Factory Setup: Sensor Type: %s\r\n", (char*)g_spareBuffer);
		debug("Factory Setup: A-Weighting: %s\r\n", (g_factorySetupRecord.aWeightOption == YES) ? "Enabled" : "Disabled");
		debug("Factory Setup: Analog Channel Config: %s\r\n", (g_factorySetupRecord.analogChannelConfig == CHANNELS_R_AND_V_SCHEMATIC) ? "Schematic" : "Swapped");
	}
}
예제 #6
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void MoveManualCalToFile(void)
{
	uint16 i;
	uint16 sample;
	uint16 normalizedData;
	uint16 hiA = 0, hiR = 0, hiV = 0, hiT = 0;
	uint16 lowA = 0xFFFF, lowR = 0xFFFF, lowV = 0xFFFF, lowT = 0xFFFF;
	uint16* startOfEventPtr;
	uint16* endOfEventDataPtr;
	uint32 compressSize;
	int manualCalFileHandle = -1;
	uint16* aManualCalPeakPtr;
	uint16* rManualCalPeakPtr;
	uint16* vManualCalPeakPtr;
	uint16* tManualCalPeakPtr;

	debug("Processing Manual Cal to be saved\r\n");

	if (g_freeEventBuffers < g_maxEventBuffers)
	{
		g_pendingEventRecord.summary.captured.eventTime = GetCurrentTime();

		// Clear out A, R, V, T channel calculated data (in case the pending event record is reused)
		memset(&g_pendingEventRecord.summary.calculated.a, 0, (NUMBER_OF_CHANNELS_DEFAULT * sizeof(CHANNEL_CALCULATED_DATA_STRUCT)));

		startOfEventPtr = g_currentEventStartPtr;
		endOfEventDataPtr = g_currentEventStartPtr + g_wordSizeInCal;
		
		for (i = (uint16)g_samplesInCal; i != 0; i--)
		{
			if (g_bitShiftForAccuracy) AdjustSampleForBitAccuracy();

			//=========================================================
			// First channel - A
			sample = *(g_currentEventSamplePtr + A_CHAN_OFFSET);

			if (sample > hiA) hiA = sample;
			if (sample < lowA) lowA = sample;

			normalizedData = FixDataToZero(sample);

			if (normalizedData > g_pendingEventRecord.summary.calculated.a.peak)
			{
				g_pendingEventRecord.summary.calculated.a.peak = normalizedData;
				aManualCalPeakPtr = (g_currentEventSamplePtr + A_CHAN_OFFSET);
			}

			//=========================================================
			// Second channel - R
			sample = *(g_currentEventSamplePtr + R_CHAN_OFFSET);

			if (sample > hiR) hiR = sample;
			if (sample < lowR) lowR = sample;

			normalizedData = FixDataToZero(sample);

			if (normalizedData > g_pendingEventRecord.summary.calculated.r.peak)
			{
				g_pendingEventRecord.summary.calculated.r.peak = normalizedData;
				rManualCalPeakPtr = (g_currentEventSamplePtr + R_CHAN_OFFSET);
			}

			//=========================================================
			// Third channel - V
			sample = *(g_currentEventSamplePtr + V_CHAN_OFFSET);

			if (sample > hiV) hiV = sample;
			if (sample < lowV) lowV = sample;

			normalizedData = FixDataToZero(sample);

			if (normalizedData > g_pendingEventRecord.summary.calculated.v.peak)
			{
				g_pendingEventRecord.summary.calculated.v.peak = normalizedData;
				vManualCalPeakPtr = (g_currentEventSamplePtr + V_CHAN_OFFSET);
			}

			//=========================================================
			// Fourth channel - T
			sample = *(g_currentEventSamplePtr + T_CHAN_OFFSET);

			if (sample > hiT) hiT = sample;
			if (sample < lowT) lowT = sample;

			normalizedData = FixDataToZero(sample);

			if (normalizedData > g_pendingEventRecord.summary.calculated.t.peak)
			{
				g_pendingEventRecord.summary.calculated.t.peak = normalizedData;
				tManualCalPeakPtr = (g_currentEventSamplePtr + T_CHAN_OFFSET);
			}

			g_currentEventSamplePtr += NUMBER_OF_CHANNELS_DEFAULT;
		}

		g_pendingEventRecord.summary.calculated.a.peak = (uint16)(hiA - lowA + 1);
		g_pendingEventRecord.summary.calculated.r.peak = (uint16)(hiR - lowR + 1);
		g_pendingEventRecord.summary.calculated.v.peak = (uint16)(hiV - lowV + 1);
		g_pendingEventRecord.summary.calculated.t.peak = (uint16)(hiT - lowT + 1);

		g_pendingEventRecord.summary.calculated.a.frequency = CalcSumFreq(aManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr);
		g_pendingEventRecord.summary.calculated.r.frequency = CalcSumFreq(rManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr);
		g_pendingEventRecord.summary.calculated.v.frequency = CalcSumFreq(vManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr);
		g_pendingEventRecord.summary.calculated.t.frequency = CalcSumFreq(tManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr);

		CompleteRamEventSummary();

		CacheResultsEventInfo((EVT_RECORD*)&g_pendingEventRecord);

		if (g_fileAccessLock != AVAILABLE)
		{
			ReportFileSystemAccessProblem("Save Manual Cal");
		}
		else // (g_fileAccessLock == AVAILABLE)
		{
			GetSpi1MutexLock(SDMMC_LOCK);

			nav_select(FS_NAV_ID_DEFAULT);

			// Get new event file handle
			manualCalFileHandle = GetEventFileHandle(g_pendingEventRecord.summary.eventNumber, CREATE_EVENT_FILE);

			if (manualCalFileHandle == -1)
			{
				ReleaseSpi1MutexLock();

				debugErr("Failed to get a new file handle for the Manual Cal event\r\n");
			}
			else // Write the file event to the SD card
			{
				sprintf((char*)g_spareBuffer, "%s %s #%d %s...", getLangText(CALIBRATION_TEXT), getLangText(EVENT_TEXT),
						g_pendingEventRecord.summary.eventNumber, getLangText(BEING_SAVED_TEXT));
				OverlayMessage(getLangText(EVENT_COMPLETE_TEXT), (char*)g_spareBuffer, 0);

				// Write the event record header and summary
				write(manualCalFileHandle, &g_pendingEventRecord, sizeof(EVT_RECORD));

				// Write the event data, containing the Pretrigger, event and cal
				write(manualCalFileHandle, g_currentEventStartPtr, (g_wordSizeInCal * 2));

				SetFileDateTimestamp(FS_DATE_LAST_WRITE);

				// Update the remaining space left
				UpdateSDCardUsageStats(nav_file_lgt());

				// Done writing the event file, close the file handle
				g_testTimeSinceLastFSWrite = g_lifetimeHalfSecondTickCount;
				close(manualCalFileHandle);

				//==========================================================================================================
				// Save compressed data file
				//----------------------------------------------------------------------------------------------------------
				if (g_unitConfig.saveCompressedData != DO_NOT_SAVE_EXTRA_FILE_COMPRESSED_DATA)
				{
					// Get new event file handle
					g_globalFileHandle = GetERDataFileHandle(g_pendingEventRecord.summary.eventNumber, CREATE_EVENT_FILE);

					g_spareBufferIndex = 0;
					compressSize = lzo1x_1_compress((void*)g_currentEventStartPtr, (g_wordSizeInCal * 2), OUT_FILE);

					// Check if any remaining compressed data is queued
					if (g_spareBufferIndex)
					{
						// Finish writing the remaining compressed data
						write(g_globalFileHandle, g_spareBuffer, g_spareBufferIndex);
						g_spareBufferIndex = 0;
					}
					debug("Manual Cal Compressed Data length: %d (Matches file: %s)\r\n", compressSize, (compressSize == nav_file_lgt()) ? "Yes" : "No");

					SetFileDateTimestamp(FS_DATE_LAST_WRITE);

					// Update the remaining space left
					UpdateSDCardUsageStats(nav_file_lgt());

					// Done writing the event file, close the file handle
					g_testTimeSinceLastFSWrite = g_lifetimeHalfSecondTickCount;
					close(g_globalFileHandle);
				}
				//==========================================================================================================

				ReleaseSpi1MutexLock();

				debug("Manual Cal Event file closed\r\n");

				AddEventToSummaryList(&g_pendingEventRecord);

				// Don't log a monitor entry for Manual Cal
				//UpdateMonitorLogEntry();

				// After event numbers have been saved, store current event number in persistent storage.
				StoreCurrentEventNumber();

				// Now store the updated event number in the universal ram storage.
				g_pendingEventRecord.summary.eventNumber = g_nextEventNumberToUse;
			}

			if (++g_eventBufferReadIndex == g_maxEventBuffers)
			{
				g_eventBufferReadIndex = 0;
				g_currentEventSamplePtr = g_startOfEventBufferPtr;
			}
			else
			{
				g_currentEventSamplePtr = g_startOfEventBufferPtr + (g_eventBufferReadIndex * g_wordSizeInEvent);
			}

			clearSystemEventFlag(MANUAL_CAL_EVENT);

			// Set flag to display calibration results if not monitoring or monitoring in waveform
			if ((g_sampleProcessing == IDLE_STATE) || ((g_sampleProcessing == ACTIVE_STATE) && (g_triggerRecord.opMode == WAVEFORM_MODE)))
			{
				// Set printout mode to allow the results menu processing to know this is a manual cal pulse
				raiseMenuEventFlag(RESULTS_MENU_EVENT);
			}

			g_freeEventBuffers++;
		}
	}
	else
	{
		debugWarn("Manual Cal: No free buffers\r\n");

		clearSystemEventFlag(MANUAL_CAL_EVENT);
	}
}