| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | subroutine genft8(msg,mygrid,bcontest,i3bit,msgsent,msgbits,itone)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Encode an FT8 message, producing array itone().
 | 
					
						
							|  |  |  |   
 | 
					
						
							|  |  |  |   use crc
 | 
					
						
							|  |  |  |   use packjt
 | 
					
						
							|  |  |  |   include 'ft8_params.f90'
 | 
					
						
							| 
									
										
										
										
											2018-08-05 17:40:19 -04:00
										 |  |  |   character*68 alphabet
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   character*22 msg,msgsent
 | 
					
						
							|  |  |  |   character*6 mygrid
 | 
					
						
							|  |  |  |   character*87 cbits
 | 
					
						
							| 
									
										
										
										
											2018-03-05 14:49:51 -05:00
										 |  |  |   logical bcontest,checksumok
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   integer*4 i4Msg6BitWords(12)                !72-bit message as 6-bit words
 | 
					
						
							|  |  |  |   integer*1 msgbits(KK),codeword(3*ND)
 | 
					
						
							|  |  |  |   integer*1, target:: i1Msg8BitBytes(11)
 | 
					
						
							|  |  |  |   integer itone(NN)
 | 
					
						
							|  |  |  |   integer icos7(0:6)
 | 
					
						
							| 
									
										
										
										
											2018-09-19 14:27:28 -04:00
										 |  |  |   data icos7/4,2,5,6,1,3,0/                   !Costas 7x7 tone pattern
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 10:18:11 -04:00
										 |  |  |   alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-+/?.'
 | 
					
						
							|  |  |  |   
 | 
					
						
							| 
									
										
										
										
											2018-08-05 17:40:19 -04:00
										 |  |  |   itype=6
 | 
					
						
							|  |  |  |   do i=1,12
 | 
					
						
							| 
									
										
										
										
											2018-08-06 10:18:11 -04:00
										 |  |  |     v=index(alphabet, msg(i:i))
 | 
					
						
							|  |  |  |     if(v.eq.0) exit
 | 
					
						
							|  |  |  |     i4Msg6BitWords(i)=v - 1
 | 
					
						
							| 
									
										
										
										
											2018-08-05 17:40:19 -04:00
										 |  |  |   enddo
 | 
					
						
							|  |  |  |   msgsent='                      '
 | 
					
						
							|  |  |  |   msgsent(1:12)=msg(1:12)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ! call packmsg(msg,i4Msg6BitWords,itype,bcontest) !Pack into 12 6-bit bytes
 | 
					
						
							|  |  |  |   ! call unpackmsg(i4Msg6BitWords,msgsent,bcontest,mygrid) !Unpack to get msgsent
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   write(cbits,1000) i4Msg6BitWords,32*i3bit
 | 
					
						
							|  |  |  | 1000 format(12b6.6,b8.8)
 | 
					
						
							|  |  |  |   read(cbits,1001) i1Msg8BitBytes(1:10)
 | 
					
						
							|  |  |  | 1001 format(10b8)
 | 
					
						
							| 
									
										
										
										
											2019-03-21 21:14:23 -04:00
										 |  |  |   i1Msg8BitBytes(10)=iand(i1Msg8BitBytes(10),transfer(128+64+32,0_1))
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   i1Msg8BitBytes(11)=0
 | 
					
						
							|  |  |  |   icrc12=crc12(c_loc(i1Msg8BitBytes),11)
 | 
					
						
							| 
									
										
										
										
											2018-10-31 11:56:12 -04:00
										 |  |  |   icrc12=xor(icrc12, 42) ! TODO: jsherer - could change the crc here
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! For reference, here's how to check the CRC
 | 
					
						
							|  |  |  | !  i1Msg8BitBytes(10)=icrc12/256
 | 
					
						
							|  |  |  | !  i1Msg8BitBytes(11)=iand (icrc12,255)
 | 
					
						
							|  |  |  | !  checksumok = crc12_check(c_loc (i1Msg8BitBytes), 11)
 | 
					
						
							|  |  |  | !  if( checksumok ) write(*,*) 'Good checksum'
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   write(cbits,1003) i4Msg6BitWords,i3bit,icrc12
 | 
					
						
							|  |  |  | 1003 format(12b6.6,b3.3,b12.12)
 | 
					
						
							|  |  |  |   read(cbits,1004) msgbits
 | 
					
						
							|  |  |  | 1004 format(87i1)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   call encode174(msgbits,codeword)      !Encode the test message
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Message structure: S7 D29 S7 D29 S7
 | 
					
						
							|  |  |  |   itone(1:7)=icos7
 | 
					
						
							|  |  |  |   itone(36+1:36+7)=icos7
 | 
					
						
							|  |  |  |   itone(NN-6:NN)=icos7
 | 
					
						
							|  |  |  |   k=7
 | 
					
						
							|  |  |  |   do j=1,ND
 | 
					
						
							|  |  |  |      i=3*j -2
 | 
					
						
							|  |  |  |      k=k+1
 | 
					
						
							|  |  |  |      if(j.eq.30) k=k+7
 | 
					
						
							|  |  |  |      itone(k)=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2)
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return
 | 
					
						
							|  |  |  | end subroutine genft8
 |