zapit/src/scan.cpp: add CleanAllMaps, SendTransponderInfo helpers, simplify ScanProviders loop - remove and xml usage, WIP

This commit is contained in:
[CST] Focus
2012-04-15 15:36:59 +04:00
parent 7f5780c303
commit 1a3eb0e378
2 changed files with 83 additions and 131 deletions

View File

@@ -66,6 +66,7 @@ class CServiceScan : public OpenThreads::Thread
int flags; int flags;
void * scan_arg; void * scan_arg;
bool satHaveChannels; bool satHaveChannels;
fe_type_t frontendType;
uint32_t fake_tid, fake_nid; uint32_t fake_tid, fake_nid;
uint32_t found_transponders; uint32_t found_transponders;
@@ -81,12 +82,14 @@ class CServiceScan : public OpenThreads::Thread
transponder_list_t scantransponders; // TP list to scan transponder_list_t scantransponders; // TP list to scan
transponder_list_t scanedtransponders; // TP list for current scan transponder_list_t scanedtransponders; // TP list for current scan
transponder_list_t failedtransponders; // TP list for current scan
transponder_list_t nittransponders; transponder_list_t nittransponders;
std::map <t_channel_id, uint8_t> service_types; std::map <t_channel_id, uint8_t> service_types;
bool ScanProvider(t_satellite_position satellitePosition); bool ScanProvider(t_satellite_position satellitePosition);
void Cleanup(const bool success); void Cleanup(const bool success);
bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition); bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition);
void SendTransponderInfo(transponder &t);
bool ReadNitSdt(t_satellite_position satellitePosition); bool ReadNitSdt(t_satellite_position satellitePosition);
void FixServiceTypes(); void FixServiceTypes();
@@ -94,6 +97,7 @@ class CServiceScan : public OpenThreads::Thread
bool ScanTransponder(); bool ScanTransponder();
bool ScanProviders(); bool ScanProviders();
void SaveServices(); void SaveServices();
void CleanAllMaps();
bool ReplaceTransponderParams(freq_id_t freq, t_satellite_position satellitePosition, struct dvb_frontend_parameters * feparams, uint8_t polarization); bool ReplaceTransponderParams(freq_id_t freq, t_satellite_position satellitePosition, struct dvb_frontend_parameters * feparams, uint8_t polarization);
/* fast scan */ /* fast scan */

View File

@@ -96,10 +96,7 @@ void CServiceScan::run()
{ {
running = true; running = true;
scantransponders.clear(); CleanAllMaps();
scanedtransponders.clear();
nittransponders.clear();
service_types.clear();
found_transponders = 0; found_transponders = 0;
processed_transponders = 0; processed_transponders = 0;
@@ -125,6 +122,14 @@ void CServiceScan::run()
} }
} }
void CServiceScan::CleanAllMaps()
{
scantransponders.clear();
scanedtransponders.clear();
nittransponders.clear();
service_types.clear();
}
bool CServiceScan::tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition) bool CServiceScan::tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition)
{ {
frontend->setInput(satellitePosition, feparams->frequency, polarization); frontend->setInput(satellitePosition, feparams->frequency, polarization);
@@ -179,7 +184,7 @@ bool CServiceScan::AddTransponder(transponder_id_t TsidOnid, FrontendParameters
} }
if(tI == scanedtransponders.end()) { if(tI == scanedtransponders.end()) {
DBG("[scan] insert tp-id %llx freq %d rate %d\n", TsidOnid, feparams->frequency, cable? feparams->u.qam.symbol_rate : feparams->u.qpsk.symbol_rate ); DBG("[scan] insert tp-id %llx freq %d rate %d\n", TsidOnid, feparams->frequency, cable? feparams->u.qam.symbol_rate : feparams->u.qpsk.symbol_rate );
transponder t(TsidOnid, *feparams, polarity); transponder t(frontendType, TsidOnid, *feparams, polarity);
if(fromnit) { if(fromnit) {
if(nittransponders.find(TsidOnid) == nittransponders.end()) { if(nittransponders.find(TsidOnid) == nittransponders.end()) {
printf("[scan] insert tp-id %llx freq %d pol %d rate %d\n", TsidOnid, feparams->frequency, polarity, cable? feparams->u.qam.symbol_rate : feparams->u.qpsk.symbol_rate ); printf("[scan] insert tp-id %llx freq %d pol %d rate %d\n", TsidOnid, feparams->frequency, polarity, cable? feparams->u.qam.symbol_rate : feparams->u.qpsk.symbol_rate );
@@ -216,29 +221,25 @@ _repeat:
return false; return false;
printf("[scan] scanning: %llx\n", tI->first); printf("[scan] scanning: %llx\n", tI->first);
SendTransponderInfo(tI->second);
uint32_t actual_freq = tI->second.feparams.frequency;
if (!cable)
actual_freq /= 1000;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY, &actual_freq,sizeof(actual_freq));
processed_transponders++;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, &processed_transponders, sizeof(processed_transponders));
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) " ", 2);
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) " ", 2);
if (!cable) {
uint32_t actual_polarisation = ((tI->second.feparams.u.qpsk.symbol_rate/1000) << 16) | (tI->second.feparams.u.qpsk.fec_inner << 8) | (uint)tI->second.polarization;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCYP, &actual_polarisation,sizeof(actual_polarisation));
}
if (!tuneFrequency(&(tI->second.feparams), tI->second.polarization, satellitePosition)) { if (!tuneFrequency(&(tI->second.feparams), tI->second.polarization, satellitePosition)) {
failed_transponders++; failed_transponders++;
continue; continue;
} }
tI->second.scanned = true;
if(abort_scan) if(abort_scan)
return false; return false;
transponder t(frontendType, tI->first, tI->second.feparams, tI->second.polarization);
for (transponder_list_t::iterator ttI = transponders.begin(); ttI != transponders.end(); ttI++) {
if(t == ttI->second) {
ttI->second.dump("[scan] similar tp, old");
t.dump("[scan] similar tp, new");
ttI->second.feparams = t.feparams;
}
}
freq_id_t freq = CREATE_FREQ_ID(tI->second.feparams.frequency, cable); freq_id_t freq = CREATE_FREQ_ID(tI->second.feparams.frequency, cable);
CNit nit(satellitePosition, freq, cable_nid); CNit nit(satellitePosition, freq, cable_nid);
@@ -282,28 +283,15 @@ _repeat:
transponder_id_t TsidOnid = CREATE_TRANSPONDER_ID64(freq, satellitePosition, transponder_id_t TsidOnid = CREATE_TRANSPONDER_ID64(freq, satellitePosition,
tI->second.original_network_id, tI->second.transport_stream_id); tI->second.original_network_id, tI->second.transport_stream_id);
#if 0 //GetTransponder
{
struct transponder t(TsidOnid, tI->second.feparams, tI->second.polarization);
for (transponder_list_t::iterator ttI = transponders.begin(); ttI != transponders.end(); ttI++) {
if (ttI->second.satellitePosition == satellitePosition) {
if(t == ttI->second) {
printf("[scan] found similar tp:\n");
ttI->second.dump("[scan] old", cable);
t.dump("[scan] new", cable);
}
}
}
}
#endif
stiterator stI = transponders.find(TsidOnid); stiterator stI = transponders.find(TsidOnid);
if(stI == transponders.end()) { if(stI == transponders.end()) {
struct transponder t(TsidOnid, tI->second.feparams, tI->second.polarization); transponder t2(frontendType, TsidOnid, tI->second.feparams, tI->second.polarization);
transponders.insert(transponder_pair_t(TsidOnid, t)); transponders.insert(transponder_pair_t(TsidOnid, t2));
} }
#if 0
else else
stI->second.feparams.u.qpsk.fec_inner = tI->second.feparams.u.qpsk.fec_inner; stI->second.feparams.u.qpsk.fec_inner = tI->second.feparams.u.qpsk.fec_inner;
#endif
printf("[scan] tpid ready: %llx\n", TsidOnid); printf("[scan] tpid ready: %llx\n", TsidOnid);
} }
if(flags & SCAN_NIT) { if(flags & SCAN_NIT) {
@@ -314,13 +302,9 @@ _repeat:
} }
nittransponders.clear(); nittransponders.clear();
printf("\n\n[scan] found %d additional transponders from nit\n", scantransponders.size()); printf("\n\n[scan] found %d additional transponders from nit\n", scantransponders.size());
if(scantransponders.size()) { if(scantransponders.size())
#if 0
CZapit::getInstance()->SendEvent ( CZapitClient::EVT_SCAN_NUM_TRANSPONDERS,
&found_transponders, sizeof(found_transponders));
#endif
goto _repeat; goto _repeat;
}
} }
#ifdef USE_BAT #ifdef USE_BAT
if(flags & SCAN_BAT) { if(flags & SCAN_BAT) {
@@ -438,10 +422,7 @@ void CServiceScan::Cleanup(const bool success)
delete scanBouquetManager; delete scanBouquetManager;
scanBouquetManager = NULL; scanBouquetManager = NULL;
} }
scantransponders.clear(); CleanAllMaps();
scanedtransponders.clear();
nittransponders.clear();
service_types.clear();
} }
bool CServiceScan::SetFrontend(t_satellite_position satellitePosition) bool CServiceScan::SetFrontend(t_satellite_position satellitePosition)
@@ -454,6 +435,8 @@ bool CServiceScan::SetFrontend(t_satellite_position satellitePosition)
frontend = fe; frontend = fe;
CFEManager::getInstance()->setLiveFE(frontend); CFEManager::getInstance()->setLiveFE(frontend);
frontendType = frontend->getInfo()->type;
cable = (frontend->getInfo()->type == FE_QAM);//FIXME
return true; return true;
} }
@@ -494,71 +477,23 @@ void CServiceScan::SaveServices()
bool CServiceScan::ScanProviders() bool CServiceScan::ScanProviders()
{ {
scan_list_iterator_t spI;
char providerName[80] = "";
const char *frontendType;
scanBouquetManager = new CBouquetManager();
bool satfeed = false;
flags = (int) scan_arg; flags = (int) scan_arg;
scanBouquetManager = new CBouquetManager();
curr_sat = 0;
cable = (frontend->getInfo()->type == FE_QAM);//FIXME
if (cable)
frontendType = "cable";
else
frontendType = "sat";
printf("[scan] NIT %s, fta only: %s, satellites %s\n", flags & SCAN_NIT ? "yes" : "no", printf("[scan] NIT %s, fta only: %s, satellites %s\n", flags & SCAN_NIT ? "yes" : "no",
flags & SCAN_FTA ? "yes" : "no", scanProviders.size() == 1 ? "single" : "multi"); flags & SCAN_FTA ? "yes" : "no", scanProviders.size() == 1 ? "single" : "multi");
CZapitClient myZapitClient; for (scan_list_iterator_t spI = scanProviders.begin(); spI != scanProviders.end(); spI++) {
t_satellite_position position = spI->first;
/* get first child */
xmlNodePtr search = xmlDocGetRootElement(CServiceManager::getInstance()->ScanXml())->xmlChildrenNode;
/* read all sat or cable sections */
while ((search = xmlGetNextOccurence(search, frontendType)) != NULL) {
t_satellite_position position = xmlGetSignedNumericAttribute(search, "position", 10);
if(cable) {
strcpy(providerName, xmlGetAttribute(search, "name"));
for (spI = scanProviders.begin(); spI != scanProviders.end(); spI++)
if (!strcmp(spI->second.c_str(), providerName)) {
position = spI->first;
break;
}
} else {
for (spI = scanProviders.begin(); spI != scanProviders.end(); spI++)
if(spI->first == position)
break;
}
/* provider is not wanted - jump to the next one */
if (spI != scanProviders.end()) {
if(!SetFrontend(position)) if(!SetFrontend(position))
break; break;
/* get name of current satellite oder cable provider */
strcpy(providerName, xmlGetAttribute(search, "name"));
if (cable && xmlGetAttribute(search, "satfeed")) { CleanAllMaps();
if (!strcmp(xmlGetAttribute(search, "satfeed"), "true"))
satfeed = true;
}
/* increase sat counter */
curr_sat++;
scantransponders.clear();
scanedtransponders.clear();
nittransponders.clear();
/* set satHaveChannels flag so SDT can mark channels as NEW only if /* set satHaveChannels flag so SDT can mark channels as NEW only if
* this is not first satellite scan */ * this is not first satellite scan */
CheckSatelliteChannels(position); CheckSatelliteChannels(position);
printf("[scan] scanning %s at %d bouquetMode %d\n", providerName, position, bouquetMode); printf("[scan] scanning %s at %d bouquetMode %d\n", spI->second.c_str(), position, bouquetMode);
ScanProvider(position); ScanProvider(position);
if(abort_scan) { if(abort_scan) {
found_channels = 0; found_channels = 0;
@@ -566,19 +501,17 @@ bool CServiceScan::ScanProviders()
} }
if(scanBouquetManager->Bouquets.size() > 0) { if(scanBouquetManager->Bouquets.size() > 0) {
scanBouquetManager->saveBouquets(bouquetMode, providerName); scanBouquetManager->saveBouquets(bouquetMode, spI->second.c_str());
} }
scanBouquetManager->clearAll(); scanBouquetManager->clearAll();
} }
/* go to next satellite */
search = search->xmlNextNode;
}
/* report status */ /* report status */
printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels); printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels);
if (found_channels) { if (found_channels) {
SaveServices(); SaveServices();
Cleanup(true); Cleanup(true);
CZapitClient myZapitClient;
myZapitClient.reloadCurrentServices(); myZapitClient.reloadCurrentServices();
} else { } else {
Cleanup(false); Cleanup(false);
@@ -593,24 +526,21 @@ bool CServiceScan::ScanProviders()
bool CServiceScan::ScanTransponder() bool CServiceScan::ScanTransponder()
{ {
TP_params *TP = (TP_params *) scan_arg; TP_params *TP = (TP_params *) scan_arg;
char providerName[32] = "";
t_satellite_position satellitePosition = 0;
satellitePosition = scanProviders.begin()->first; if(scanProviders.empty() || !SetFrontend(scanProviders.begin()->first)) {
if(!SetFrontend(satellitePosition)) {
Cleanup(false); Cleanup(false);
return false; return false;
} }
t_satellite_position satellitePosition = scanProviders.begin()->first;
std::string providerName = scanProviders.begin()->second.c_str();
CheckSatelliteChannels(satellitePosition); CheckSatelliteChannels(satellitePosition);
scanBouquetManager = new CBouquetManager(); scanBouquetManager = new CBouquetManager();
cable = (frontend->getInfo()->type == FE_QAM);//FIXME printf("[scan] scanning sat %s position %d\n", providerName.c_str(), satellitePosition);
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SATELLITE, providerName.c_str(), providerName.size()+1);
strcpy(providerName, scanProviders.size() > 0 ? scanProviders.begin()->second.c_str() : "unknown provider");
printf("[scan] scanning sat %s position %d\n", providerName, satellitePosition);
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SATELLITE, providerName, strlen(providerName) + 1);
TP->feparams.inversion = INVERSION_AUTO; TP->feparams.inversion = INVERSION_AUTO;
@@ -622,8 +552,8 @@ bool CServiceScan::ScanTransponder()
fake_tid++; fake_nid++; fake_tid++; fake_nid++;
transponder_id_t tid = CREATE_TRANSPONDER_ID64(freq, satellitePosition, fake_nid, fake_tid); transponder_id_t tid = CREATE_TRANSPONDER_ID64(freq, satellitePosition, fake_nid, fake_tid);
struct transponder t(tid, TP->feparams, TP->polarization); transponder t(frontendType, tid, TP->feparams, TP->polarization);
t.dump("[scan]", cable); t.dump("[scan]");
#if 1 #if 1
AddTransponder(tid, &TP->feparams, TP->polarization); AddTransponder(tid, &TP->feparams, TP->polarization);
#else #else
@@ -633,19 +563,19 @@ bool CServiceScan::ScanTransponder()
/* read network information table */ /* read network information table */
ReadNitSdt(satellitePosition); ReadNitSdt(satellitePosition);
#if 0
if (found_channels) if (found_channels)
ReplaceTransponderParams(freq, satellitePosition, &TP->feparams, TP->polarization); ReplaceTransponderParams(freq, satellitePosition, &TP->feparams, TP->polarization);
#endif
printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels); printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels);
if(abort_scan) if(abort_scan)
found_channels = 0; found_channels = 0;
CZapitClient myZapitClient;
if(found_channels) { if(found_channels) {
scanBouquetManager->saveBouquets(bouquetMode, providerName); scanBouquetManager->saveBouquets(bouquetMode, providerName.c_str());
SaveServices(); SaveServices();
Cleanup(true); Cleanup(true);
CZapitClient myZapitClient;
myZapitClient.reloadCurrentServices(); myZapitClient.reloadCurrentServices();
} else { } else {
Cleanup(false); Cleanup(false);
@@ -675,6 +605,24 @@ bool CServiceScan::ReplaceTransponderParams(freq_id_t freq, t_satellite_position
return ret; return ret;
} }
void CServiceScan::SendTransponderInfo(transponder &t)
{
uint32_t actual_freq = t.feparams.frequency;
if (!cable)
actual_freq /= 1000;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY, &actual_freq,sizeof(actual_freq));
processed_transponders++;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, &processed_transponders, sizeof(processed_transponders));
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) " ", 2);
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) " ", 2);
if (!cable) {
uint32_t actual_polarisation = ((t.feparams.u.qpsk.symbol_rate/1000) << 16) | (t.feparams.u.qpsk.fec_inner << 8) | (uint)t.polarization;
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCYP, &actual_polarisation,sizeof(actual_polarisation));
}
}
void CServiceScan::ChannelFound(uint8_t service_type, std::string providerName, std::string serviceName) void CServiceScan::ChannelFound(uint8_t service_type, std::string providerName, std::string serviceName)
{ {
CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) providerName.c_str(), providerName.length() + 1); CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) providerName.c_str(), providerName.length() + 1);