function get_cmds,hk
;+
;	extracts the commands from the housekeeping stream
;	into a sequence:
;	hk is an array containing all of the housekeeping packets
;
;	word 
;	0	obt byte 1
;	1	obt byte 2
;	2	obt byte 3
;	3	obt byte 4
;	4	obt byte 5
;	5	obt byte 6
;	6	good / bad flag (0=good, 1=bad)
;	7	command counter
;	8	command code
;	9	command destination code
;	10	command sequence number
;	11	command error code
;
;   modified for hk in bytes or words   20 mar 1996, RAH
;
; @(#)get_cmds.pro	1.1 01/23/98 :LASCO IDL LIBRARY
;
;-
hk3=gethkn(hk,3)
s = size(hk3)
if (s(s(0)+1) eq 1) then begin
   byteflag=0 
   offset = 12
   w=where(hk3(offset+2*(12+1-2),*) ne 'ff'x)
endif else begin
   byteflag=1
   offset = 15
   w=where(hk3(27,*) ne 'ffff'x)
endelse
hk3=hk3(*,w)
npckt=n_elements(w)
if (byteflag eq 1) then ctr=tmpoint(hk3,16,'ff00'x) $
                   else ctr=fix(hk3(offset+2*(2+1-2),*))
w=where(ctr ne 0,nw)
if nw gt 0 then w0=w(0) else w0=0
lastseq=-1
lastctr=-1
ncmd=-1
cmds=intarr(12,20000)
for i=w0,npckt-1 do begin			; loop on packets
    if lastctr ne ctr(i) then begin		; has a new cmd been received
	delctr = ctr(i)-lastctr		; get number of new commands
	if delctr lt -100 then delctr=10
        if (lastctr eq -1) then delctr=0
	delctr = delctr>0
	delctr = delctr<10
	for j=delctr,0,-1 do begin		; process all command TM points
            if (byteflag eq 1) then seq=hk3(28+2*j,i) and '00ff'x $
                               else seq=fix(hk3(offset+2*(13+1-2)+1+4*j,i))
	    if seq ne lastseq then begin
                if (byteflag eq 1) then cod= hk3(27+2*j,i) and 'ff'x $
                                   else cod= fix(hk3(offset+2*(12+1-2)+1+4*j,i))
		if cod ne 255 then begin
                   if (byteflag eq 1) then begin
		      obt1 = ishft(hk3(12,i),-8) and 'ff'x
		      obt2 = hk3(12,i) and 'ff'x
		      obt3 = ishft(hk3(13,i),-8) and 'ff'x
		      obt4 = hk3(13,i) and 'ff'x
		      obt5 = ishft(hk3(14,i),-8) and 'ff'x
		      obt6 = hk3(14,i) and 'ff'x
		      des  = ishft(hk3(27+2*j,i),-8) and 'ff'x
		      err  = ishft(hk3(28+2*j,i),-8) and 'ff'x
                   endif else begin
		      obt1 = fix(hk3(offset-6,i))
		      obt2 = fix(hk3(offset-5,i))
		      obt3 = fix(hk3(offset-4,i))
		      obt4 = fix(hk3(offset-3,i))
		      obt5 = fix(hk3(offset-2,i))
		      obt6 = fix(hk3(offset-1,i))
		      des  = fix(hk3(offset+2*(12+1-2)+4*j,i))
		      err  = fix(hk3(offset+2*(13+1-2)+4*j,i))
                   endelse
		   c=[obt1,obt2,obt3,obt4,obt5,obt6,0,ctr(i),cod,des,seq,err]
		   ncmd=ncmd+1
		   cmds(0,ncmd)=c
		   lastseq=seq
		   lastctr=ctr(i)
		endif
	    endif
	endfor
    endif
endfor
return,cmds(*,0:ncmd)
end
