« clib/dvb_ts_lib/descriptors/parse_desc_service.c
↑ Summary
clib/dvb_ts_lib/descriptors/parse_desc_service_list.c »
| 1 | /* | ||||||||||||||
| 2 | * parse_desc_service_availability.c | ||||||||||||||
| 3 | * | ||||||||||||||
| 4 | * Created by: si_desc.pl | ||||||||||||||
| 5 | * Created on: 20-May-2011 | ||||||||||||||
| 6 | * Author: sdprice1 | ||||||||||||||
| 7 | */ | ||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | // VERSION = 1.00 | ||||||||||||||
| 11 | |||||||||||||||
| 12 | /*=============================================================================================*/ | ||||||||||||||
| 13 | // USES | ||||||||||||||
| 14 | /*=============================================================================================*/ | ||||||||||||||
| 15 | |||||||||||||||
| 16 | #include <stdio.h> | ||||||||||||||
| 17 | #include <stdlib.h> | ||||||||||||||
| 18 | #include <unistd.h> | ||||||||||||||
| 19 | #include <string.h> | ||||||||||||||
| 20 | #include <errno.h> | ||||||||||||||
| 21 | #include <ctype.h> | ||||||||||||||
| 22 | #include <fcntl.h> | ||||||||||||||
| 23 | #include <inttypes.h> | ||||||||||||||
| 24 | |||||||||||||||
| 25 | #include "parse_desc_service_availability.h" | ||||||||||||||
| 26 | #include "descriptors/parse_desc.h" | ||||||||||||||
| 27 | |||||||||||||||
| 28 | /*=============================================================================================*/ | ||||||||||||||
| 29 | // CONSTANTS | ||||||||||||||
| 30 | /*=============================================================================================*/ | ||||||||||||||
| 31 | |||||||||||||||
| 32 | /*=============================================================================================*/ | ||||||||||||||
| 33 | // MACROS | ||||||||||||||
| 34 | /*=============================================================================================*/ | ||||||||||||||
| 35 | |||||||||||||||
| 36 | /*=============================================================================================*/ | ||||||||||||||
| 37 | // FUNCTIONS | ||||||||||||||
| 38 | /*=============================================================================================*/ | ||||||||||||||
| 39 | |||||||||||||||
| 40 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 41 | // | ||||||||||||||
| 42 | // service_availability_descriptor(){ | ||||||||||||||
| 43 | // descriptor_tag 8 uimsbf | ||||||||||||||
| 44 | // descriptor_length 8 uimsbf | ||||||||||||||
| 45 | // availability_flag 1 bslbf | ||||||||||||||
| 46 | // reserved 7 bslbf | ||||||||||||||
| 47 | // for (i=0;i<N;i++) { | ||||||||||||||
| 48 | // cell_id 16 uimsbf | ||||||||||||||
| 49 | // } | ||||||||||||||
| 50 | // } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | |||||||||||||||
| 53 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 54 | 0 | void print_service_availability(struct Descriptor_service_availability *sad, int level) | |||||||||||||
| 55 | { | ||||||||||||||
| 56 | struct list_head *item, *safe; | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | printf(" Descriptor: service_availability [0x%02x]\n", sad->descriptor_tag) ; | |||||||||||||
| 59 | 0 | printf(" Length: %d\n", sad->descriptor_length) ; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | printf(" availability_flag = %d\n", sad->availability_flag) ; | |||||||||||||
| 62 | 0 | bits_dump("cell_id", sad->cell_id, sad->descriptor_length, 2) ; | |||||||||||||
| 63 | 0 | } | |||||||||||||
| 64 | |||||||||||||||
| 65 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 66 | 0 | struct Descriptor *parse_service_availability(struct TS_bits *bits, unsigned tag, unsigned len) | |||||||||||||
| 67 | { | ||||||||||||||
| 68 | struct Descriptor_service_availability *sad ; | ||||||||||||||
| 69 | unsigned byte ; | ||||||||||||||
| 70 | int end_buff_len ; | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | sad = (struct Descriptor_service_availability *)malloc( sizeof(*sad) ) ; | |||||||||||||
| 73 | 0 | memset(sad,0,sizeof(*sad)); | |||||||||||||
| 74 | |||||||||||||||
| 75 | //== Parse data == | ||||||||||||||
| 76 | 0 | INIT_LIST_HEAD(&sad->next); | |||||||||||||
| 77 | 0 | sad->descriptor_tag = tag ; // already extracted by parse_desc() | |||||||||||||
| 78 | 0 | sad->descriptor_length = len ; // already extracted by parse_desc() | |||||||||||||
| 79 | 0 | sad->availability_flag = bits_get(bits, 1) ; | |||||||||||||
| 80 | 0 | bits_skip(bits, 7) ; | |||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | end_buff_len = bits_len_calc(bits, -(sad->descriptor_length - 1)) ; | |||||||||||||
| 83 | 0 | sad->cell_id[0] = 0 ; | |||||||||||||
| 84 | 0 | ▶ | for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_CELL_ID_LEN); ++byte) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 85 | { | ||||||||||||||
| 86 | 0 | sad->cell_id[byte] = bits_get(bits, 8) ; | |||||||||||||
| 87 | 0 | sad->cell_id[byte+1] = 0 ; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | return (struct Descriptor *)sad ; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 95 | 0 | void free_service_availability(struct Descriptor_service_availability *sad) | |||||||||||||
| 96 | { | ||||||||||||||
| 97 | struct list_head *item, *safe; | ||||||||||||||
| 98 | |||||||||||||||
| 99 | 0 | free(sad) ; | |||||||||||||
| 100 | 0 | } | |||||||||||||