FireBirdLib - Topfield TMS PVR TAP Programming Library
FlashTransponderTablesAdd.c
Go to the documentation of this file.
1#include <string.h>
2#include "FBLib_flash.h"
3
4int FlashTransponderTablesAdd(int SatNum, tFlashTransponderTable *TransponderTable)
5{
7
8 //SatNum out of range
9 if((SatNum < 0) || (SatNum >= FlashSatTablesGetTotal()))
10 {
11 TRACEEXIT();
12 return -1;
13 }
14
15 //TransponderTable is NULL
16 if(!TransponderTable)
17 {
18 TRACEEXIT();
19 return -1;
20 }
21
22 switch(GetSystemType())
23 {
24 //Unknown and old 5k/6k systems are not supported
25 case ST_UNKNOWN:
26 case ST_S:
27 case ST_ST:
28 case ST_T:
29 case ST_C:
30 case ST_CT:
31 case ST_T5700:
32 case ST_T5800:
33 case ST_TF7k7HDPVR:
34 {
35 TRACEEXIT();
36 return -1;
37 }
38
39 case ST_TMSS:
40 {
41 TYPE_TpInfo_TMSS *pTransp, *pTranspEnd;
43 int i, TPIdx, NrSats;
44 dword *NrTransponders;
45
47 if(!pSat)
48 {
49 TRACEEXIT();
50 return -1;
51 }
52
53 NrSats = FlashSatTablesGetTotal();
54
55 pTransp = (TYPE_TpInfo_TMSS*)(FIS_vFlashBlockTransponderInfo());
56 if(!pTransp)
57 {
58 TRACEEXIT();
59 return -1;
60 }
61
62 //Find the end of the transponder list
63 pTranspEnd = pTransp;
64 for(i = 0; i <= NrSats; i++)
65 {
66 pTranspEnd += (pSat->NrOfTransponders);
67 pSat++;
68 }
69
70 //Find the location where to insert the new transponder
71 TPIdx = 0;
73 for(i = 0; i <= SatNum; i++)
74 {
75 TPIdx += pSat->NrOfTransponders;
76 pSat++;
77 }
78 pSat--;
79 pTransp += TPIdx;
80
81 //Create a hole for the new transponder
82 while(pTranspEnd > pTransp)
83 {
84 memcpy(pTranspEnd, pTranspEnd - 1, sizeof(TYPE_TpInfo_TMSS));
85 pTranspEnd--;
86 }
87
88 //Write the new transponder
89 if(FlashTransponderTablesEncode(pTransp, TransponderTable))
90 {
91 //Increment the number of transponders
92 NrTransponders = (dword*)(FIS_vFlashBlockTransponderInfo() - 4);
93 *NrTransponders = *NrTransponders + 1;
94 pSat->NrOfTransponders++;
95
96 TRACEEXIT();
97 return pSat->NrOfTransponders - 1;
98 }
99
100 TRACEEXIT();
101 return -1;
102 }
103
104 case ST_TMST:
105 {
106 TYPE_TpInfo_TMST *pTransp;
107 TYPE_SatInfo_TMST *pSat;
108 dword *NrTransponders;
109
111 if(!pSat)
112 {
113 TRACEEXIT();
114 return -1;
115 }
116
117 pTransp = (TYPE_TpInfo_TMST*)(FIS_vFlashBlockTransponderInfo());
118 if(!pTransp)
119 {
120 TRACEEXIT();
121 return -1;
122 }
123
124 //Find the location where to insert the new transponder
125 pTransp += pSat->NrOfTransponders;
126
127 //Write the new transponder
128 if(FlashTransponderTablesEncode(pTransp, TransponderTable))
129 {
130 //Increment number of transponders
131 NrTransponders = (dword*)(FIS_vFlashBlockTransponderInfo() - 4);
132 *NrTransponders = *NrTransponders + 1;
133 pSat->NrOfTransponders++;
134
135 TRACEEXIT();
136 return pSat->NrOfTransponders - 1;
137 }
138
139 TRACEEXIT();
140 return -1;
141 }
142
143 case ST_TMSC:
144 {
145 TYPE_TpInfo_TMSC *pTransp;
146 TYPE_SatInfo_TMSC *pSat;
147 dword *NrTransponders;
148
150 if(!pSat)
151 {
152 TRACEEXIT();
153 return -1;
154 }
155
156 pTransp = (TYPE_TpInfo_TMSC*)(FIS_vFlashBlockTransponderInfo());
157 if(!pTransp)
158 {
159 TRACEEXIT();
160 return -1;
161 }
162
163 //Find the location where to insert the new transponder
164 pTransp += pSat->NrOfTransponders;
165
166 //Write the new transponder
167 if(FlashTransponderTablesEncode(pTransp, TransponderTable))
168 {
169 //Increment number of transponders
170 NrTransponders = (dword*)(FIS_vFlashBlockTransponderInfo() - 4);
171 *NrTransponders = *NrTransponders + 1;
172 pSat->NrOfTransponders++;
173
174 TRACEEXIT();
175 return pSat->NrOfTransponders - 1;
176 }
177
178 TRACEEXIT();
179 return -1;
180 }
181
182 case ST_NRTYPES: break;
183 }
184
185 TRACEEXIT();
186 return -1;
187}
dword FIS_vFlashBlockSatInfo(void)
dword FIS_vFlashBlockTransponderInfo(void)
int FlashSatTablesGetTotal(void)
int FlashTransponderTablesAdd(int SatNum, tFlashTransponderTable *TransponderTable)
bool FlashTransponderTablesEncode(void *Data, tFlashTransponderTable *TransponderTable)
SYSTEM_TYPE GetSystemType(void)
Definition: GetSystemType.c:3
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
@ ST_CT
Definition: libFireBird.h:77
@ ST_T
Definition: libFireBird.h:69
@ ST_TMSC
Definition: libFireBird.h:74
@ ST_UNKNOWN
Definition: libFireBird.h:67
@ ST_T5700
Definition: libFireBird.h:71
@ ST_TMST
Definition: libFireBird.h:73
@ ST_T5800
Definition: libFireBird.h:75
@ ST_TMSS
Definition: libFireBird.h:72
@ ST_ST
Definition: libFireBird.h:76
@ ST_NRTYPES
Definition: libFireBird.h:79
@ ST_TF7k7HDPVR
Definition: libFireBird.h:78
@ ST_S
Definition: libFireBird.h:68
@ ST_C
Definition: libFireBird.h:70