mirror of
				https://github.com/brmlab/osmo-tetra.git
				synced 2025-10-30 23:14:00 +01:00 
			
		
		
		
	float2bits migrated to tetra-rx
- compatible to old mode - new streaming mode (option -s) - buffer size adjusted
This commit is contained in:
		
							parent
							
								
									d19275b5a8
								
							
						
					
					
						commit
						d03677065f
					
				
					 1 changed files with 110 additions and 21 deletions
				
			
		
							
								
								
									
										125
									
								
								src/tetra-rx.c
									
										
									
									
									
								
							
							
						
						
									
										125
									
								
								src/tetra-rx.c
									
										
									
									
									
								
							|  | @ -34,23 +34,79 @@ | ||||||
| #include <phy/tetra_burst_sync.h> | #include <phy/tetra_burst_sync.h> | ||||||
| #include "tetra_gsmtap.h" | #include "tetra_gsmtap.h" | ||||||
| 
 | 
 | ||||||
|  | // size of IO buffers (number of elements)
 | ||||||
|  | #define BUF_SIZE 256 | ||||||
|  | 
 | ||||||
| void *tetra_tall_ctx; | void *tetra_tall_ctx; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | static int process_sym_fl(float fl) | ||||||
|  | { | ||||||
|  | 	int ret; | ||||||
|  | 
 | ||||||
|  | 	/* very simplistic scheme */ | ||||||
|  | 	if (fl > 2) | ||||||
|  | 		ret = 3; | ||||||
|  | 	else if (fl > 0) | ||||||
|  | 		ret = 1; | ||||||
|  | 	else if (fl < -2) | ||||||
|  | 		ret = -3; | ||||||
|  | 	else | ||||||
|  | 		ret = -1; | ||||||
|  | 
 | ||||||
|  | 	return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void sym_int2bits(int sym, uint8_t *ret) | ||||||
|  | { | ||||||
|  | 	switch (sym) { | ||||||
|  | 	case -3: | ||||||
|  | 		ret[0] = 1; | ||||||
|  | 		ret[1] = 1; | ||||||
|  | 		break; | ||||||
|  | 	case 1: | ||||||
|  | 		ret[0] = 0; | ||||||
|  | 		ret[1] = 0; | ||||||
|  | 		break; | ||||||
|  | 	case 3: | ||||||
|  | 		ret[0] = 0; | ||||||
|  | 		ret[1] = 1; | ||||||
|  | 		break; | ||||||
|  | 	case -1: | ||||||
|  | 		ret[0] = 1; | ||||||
|  | 		ret[1] = 0; | ||||||
|  | 		break; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||||
| { | { | ||||||
| 	int fd; | 	int fd; | ||||||
|  | 	int opt; | ||||||
|  | 	int streaming   = 0; | ||||||
|  | 	int opt_verbose = 0; | ||||||
|  | 	 | ||||||
| 	struct tetra_rx_state *trs; | 	struct tetra_rx_state *trs; | ||||||
| 	struct tetra_mac_state *tms; | 	struct tetra_mac_state *tms; | ||||||
| 
 | 
 | ||||||
| 	if (argc < 2) { | 	while ((opt = getopt(argc, argv, "sv")) != -1) { | ||||||
| 		fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]); | 		switch (opt) { | ||||||
| 		exit(1); | 		case 's': | ||||||
|  | 			streaming = 1; | ||||||
|  | 			break; | ||||||
|  | 		case 'v': | ||||||
|  | 			opt_verbose = 1; | ||||||
|  | 			break; | ||||||
|  | 
 | ||||||
|  | 		default: | ||||||
|  | 			exit(2); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	fd = open(argv[1], O_RDONLY); | 	if (argc <= optind) { | ||||||
| 	if (fd < 0) { | 		fprintf(stderr, "Usage: %s -s [-v] <filestream>\n", argv[0]); | ||||||
| 		perror("open"); | 		fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]); | ||||||
| 		exit(2); | 		exit(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	tetra_gsmtap_init("localhost", 0); | 	tetra_gsmtap_init("localhost", 0); | ||||||
|  | @ -61,19 +117,52 @@ int main(int argc, char **argv) | ||||||
| 	trs = talloc_zero(tetra_tall_ctx, struct tetra_rx_state); | 	trs = talloc_zero(tetra_tall_ctx, struct tetra_rx_state); | ||||||
| 	trs->burst_cb_priv = tms; | 	trs->burst_cb_priv = tms; | ||||||
| 	 | 	 | ||||||
| 	while (1) { | 	fd = open(argv[optind], O_RDONLY); | ||||||
| 		uint8_t buf[64]; | 	if (fd < 0) { | ||||||
| 		int len; | 		perror("open"); | ||||||
|  | 		exit(2); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 		len = read(fd, buf, sizeof(buf)); | 	// use old mode which uses files with 1 byte per bit
 | ||||||
| 		if (len < 0) { | 	if(streaming == 0) { | ||||||
| 			perror("read"); | 		while (1) { | ||||||
| 			exit(1); | 			uint8_t buf[64]; | ||||||
| 		} else if (len == 0) { | 			int len; | ||||||
| 			printf("EOF"); | 
 | ||||||
| 			break; | 			len = read(fd, buf, sizeof(buf)); | ||||||
|  | 			if (len < 0) { | ||||||
|  | 				perror("read"); | ||||||
|  | 				exit(1); | ||||||
|  | 			} else if (len == 0) { | ||||||
|  | 				printf("EOF"); | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 			tetra_burst_sync_in(trs, buf, len); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	else { // new fast mode - we will decode the incoming file ourself
 | ||||||
|  | 		while (1) { | ||||||
|  | 			int rc; | ||||||
|  | 			float fl[BUF_SIZE]; | ||||||
|  | 			uint8_t bits[2*BUF_SIZE]; | ||||||
|  | 			rc = read(fd, fl, sizeof(*fl) * BUF_SIZE); | ||||||
|  | 			if (rc < 0) { | ||||||
|  | 				perror("read"); | ||||||
|  | 				exit(1); | ||||||
|  | 			} else if (rc == 0) { | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 			rc /= sizeof(*fl); | ||||||
|  | 			int i; | ||||||
|  | 			for (i = 0; i < rc; ++i) { | ||||||
|  | 				int sym = process_sym_fl(fl[i]); | ||||||
|  | 				sym_int2bits(sym, bits + i*2); | ||||||
|  | 				if (opt_verbose) { | ||||||
|  | 					printf("%1u%1u", bits[2*i + 0], bits[2*i + 1]); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			tetra_burst_sync_in(trs, bits, rc * 2); | ||||||
| 		} | 		} | ||||||
| 		tetra_burst_sync_in(trs, buf, len); |  | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	talloc_free(trs); | 	talloc_free(trs); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 luckyhacky
						luckyhacky