DESCRIPTION: How to implement lock indicators and PRN selection

AUTHOR:     Stephan Esterhuizen

DATE:       5 February 2004

--------------------------------------------------------------------------------

---------------
Lock Indicators
---------------

Frequency lock
Code lock

----------------------
PRN Selection Skeleton
----------------------

- Keep track of average power
- If avg power drops below threshold
  	- switch to other prn?
	- re-acquire?
	- coast?

- switch PRN should be generic, return PRN from a list or PRN from almanac
   - list should have
	 [PRNa] [time1<t<time2] 
	 	[doppler_win,doppler_bin_size,integ_time,threshhold,n,m,repeatAmount]
	 [PRNb] [time1<t<time2] [doppler_win,doppler_bin_size]
	 [PRNc] [time2<t<time3] [doppler_win,doppler_bin_size]
	 [PRNd] [time3<t<time4] [doppler_win,doppler_bin_size]

	 Thus if time is between 1 and 2, select either PRNa or PRNb

===============

If re-acquire, at which doppler?
Try varying integration times?

===============

Could generate table/linked-list of these entries.

Perhaps add: startup: 
- cold (random prn)
- list (read from list)
- warm (read from almanac)

format of this file:

@ ch[0]
PRN1,-5000,+5000,500,1,300000,7,10,2 TIME1:TIME2
PRN2,-4000,+1000,150,3,900000,7,10,2 TIME1:TIME2

@ ch[1]
PRN4,-5000,+5000,500,1,300000,7,10,2 TIME1:TIME2
PRN8,-4000,+1000,150,3,900000,7,10,2 TIME1:TIME2

Actually, let's add this into channels.txt file


ACQUIRE_LIST 10 # the next 10 lines is a list of PRNs
PRN4,-5000,+5000,500,1,300000,7,10,2 TIME1:TIME2
PRN8,-4000,+1000,150,3,900000,7,10,2 TIME1:TIME2
...
.
.
.
etc

-------------------
Things I need to do
-------------------

- For lock indicator, keep track of last 20ms avg power
- CommandTask needs to receive messages from either code task or carrier task to
  tell whether lock has been lost
   - question: which task should be lock indicator?
- Perhaps implement Beyerle's PLL

Loss can be indicated by survey, code, or carrier
if survey
 - start where stopped previously (not too important)

if code/carrier
 - try re-acquisition
   if fail
   	- select new PRN

The select new prn function must take care of warm/list/soft-starts...

If no PRN available, suspend cmdTask for x-seconds.

---------------------------------
select_prn (with list or random)
---------------------------------

 - Read list from file, each node has entry
    PRN,reserved for channel, doppwinmax, doppwinmin, doppbinsize, 
	m,n, thresh, integ_time, time_window_valid

	The Linked list is arranged according to time_window_valid, if no valid
	time is specified, the entry is 0 - 0.

	A channel would cycle through this list and make sure that
	ch==-1 (not reserved) or ch==mychannel && time==0 or within the clock's
	time. If these conditions are reached, the node will be removed from the
	linked-list for processing. During this time the linked list must be locked
	to all other tasks.

	The node data will then be loaded into the correct structures, and survey
	task will be sent a message to wake up and initialise with the new settings.

	If lock is lost (and cannot be reacquired), the node will be put back into
	the linked list if and only if time=0 or timeMax > currentTime.

	Use semaphore to lock linked list.

	If no list is given in input file, then generate a linked list with 32
	entires of all 32 PRN's with ch=-1

----------
misc notes
----------

This structure (of linked lists) can also be used for warmstart from almanac, a
new linked list can be generated every 1 minute containing the current PRN's in
view with az/el information.

---------
Questions
---------

Should this be implemented on the real-time side or user-side?
User-side is easier to debug -> and no sharing conflicts will occur (since only
one task runs on the user-side).

Once the user-side decides which satellite to select next, this information has
to be conveyed to the the real-time side, and channels need to be
re-initialized.

Ah! It is reasonable to assume that each surveyTask is responsible for channel
initialisation.

Problems:
	1) What if CH1 is slaved to CH0?
	 -A] If CH1 doesn't have a survey task, then fine, ch0 will use the multi_*
	 commands to make sure that other slaved channels are also initialised
	 -B] If CH1 is slaved in, say carrier freq, but free to move code phase
	 around then:
	 	+ Only initialise
