13
0
Fork 1

Lots of cleanups

git-svn-id: https://dedected.org/svn/trunk@61 8d8ab74c-27aa-4a3d-9bde-523a2bc1f624
This commit is contained in:
kaner 2009-02-01 14:57:48 +00:00
parent 6f2a66e8a9
commit 336531070e
2 changed files with 145 additions and 92 deletions

View File

@ -39,6 +39,7 @@ struct dect_data {
DecTable *ctable;
vector<vector <string> > info_vec_fp;
vector<vector <string> > info_vec_pp;
vector<string> sync_station;
int addref;
int numrows;
int mode;
@ -54,16 +55,6 @@ public:
}
~DecTable() {}
void setModePPTable(DecTable *ppt)
{
this->pptable = ppt;
}
void setModeFPTable(DecTable *fpt)
{
this->fptable = fpt;
}
int KeyPress(int in_key)
{
if (visible == 0)
@ -146,8 +137,7 @@ public:
"C - Sort by Channel (descending)\n"
"s - Sort by view count (ascending)\n"
"S - Sort by view count (descending)\n"
"<enter> - In FP mode: Show details of currently selected station\n"
" In PP mode: Sync with selected station and record call\n";
"<enter> - Sync with selected station and dump calls\n";
Kis_ModalAlert_Panel *ma = new Kis_ModalAlert_Panel(globalreg, globalreg->panel_interface);
ma->Position(2, 2, 21, 70);
ma->ConfigureAlert(help_title, help_text);
@ -256,8 +246,6 @@ public:
private:
GlobalRegistry *globalreg;
DecTable *pptable;
DecTable *fptable;
dect_data *ddata;
};
@ -290,7 +278,6 @@ void DectDetailsProtoDECT(CLIPROTO_CB_PARMS)
inf.push_back(buf);
}
// Niceify dates
/*
string f, l;
time_t first, last;
char first_s[30], last_s[30];
@ -300,9 +287,7 @@ void DectDetailsProtoDECT(CLIPROTO_CB_PARMS)
ctime_r(&last, last_s);
inf[3] = first_s;
inf[4] = last_s;
*/
// RFPI is primary key
if (mode == MODE_ASYNC_FP_SCAN) {
vector<vector <string> >::iterator i = ddata->info_vec_fp.begin();
for (int j = 0; i < ddata->info_vec_fp.end(); ++i, ++j) {
@ -336,27 +321,24 @@ void DectDetailsProtoDECT(CLIPROTO_CB_PARMS)
reverse(ddata->info_vec_pp.begin(), ddata->info_vec_pp.end());
}
}
if (mode == MODE_ASYNC_FP_SCAN || mode == MODE_ASYNC_PP_SCAN) {
ddata->ctable->Hide();
ddata->dtable->Clear();
if (mode == MODE_ASYNC_FP_SCAN) {
if (mode == MODE_ASYNC_FP_SCAN) {
ddata->dtable->Clear();
ddata->ctable->Hide();
vector<vector <string> >::iterator i = ddata->info_vec_fp.begin();
for (int j = 0; i < ddata->info_vec_fp.end(); ++i, ++j) {
ddata->dtable->AddRow(j, (*i));
}
} else if (mode == MODE_ASYNC_PP_SCAN) {
ddata->dtable->Show();
ddata->dtable->DrawComponent();
} else if (mode == MODE_ASYNC_PP_SCAN) {
ddata->ctable->Clear();
ddata->dtable->Hide();
vector<vector <string> >::iterator i = ddata->info_vec_pp.begin();
for (int j = 0; i < ddata->info_vec_pp.end(); ++i, ++j) {
ddata->dtable->AddRow(j, (*i));
ddata->ctable->AddRow(j, (*i));
}
}
ddata->dtable->Show();
ddata->dtable->DrawComponent();
} else {
ddata->dtable->Hide();
ddata->ctable->Clear();
ddata->ctable->Show();
ddata->ctable->DrawComponent();
ddata->ctable->Show();
ddata->ctable->DrawComponent();
}
}
@ -370,7 +352,8 @@ void DectCliConfigured(CLICONF_CB_PARMS)
if (kcli->RegisterProtoHandler("DECT", KCLI_DECT_CHANNEL_FIELDS,
DectDetailsProtoDECT, pdata) < 0) {
_MSG("Could not register DECT protocol with remote server", MSGFLAG_ERROR);
_MSG("Could not register DECT protocol with remote server",
MSGFLAG_ERROR);
}
}
@ -402,58 +385,115 @@ int DectListerButtonCB(COMPONENT_CALLBACK_PARMS)
GlobalRegistry *greg = globalreg;
if(!ddata || !greg) {
printf("Fooo!\n");
return 0;
}
if (mode == MODE_ASYNC_FP_SCAN) {
vector<string> data = ddata->dtable->GetSelectedData();
if (data.size() < 1) {
// We got a button event even though the table was empty.
string cmd("DECT 1 0 0");
_MSG(cmd, MSGFLAG_INFO);
if (globalreg &&
globalreg->panel_interface &&
globalreg->panel_interface->FetchFirstNetclient()) {
globalreg->panel_interface->FetchFirstNetclient()->InjectCommand(cmd);
}
return 1;
}
vector<vector<string> >::iterator i = ddata->info_vec_fp.begin();
for (int j = 0; i < ddata->info_vec_fp.end(); ++i, ++j) {
if ((*i)[0] == data[0]) {
time_t first, last;
char first_s[30], last_s[30];
first = atoi((*i)[3].c_str());
last = atoi((*i)[4].c_str());
ctime_r(&first, first_s);
ctime_r(&last, last_s);
string in_title = "Station details";
string in_text = "Station: " + data[0] + "\n" +
"RSSI: " + (*i)[1] + "\n" +
"Channel: " + (*i)[2] + "\n" +
"First seen: " + first_s +
"Last seen: " + last_s +
"Count seen: " + (*i)[5] + "\n";
// XXX: This could be another panel as well
Kis_ModalAlert_Panel *ma = new Kis_ModalAlert_Panel(globalreg, globalreg->panel_interface);
ma->Position((LINES / 2) - 8, (COLS / 2) - 25, 12, 40);
ma->ConfigureAlert(in_title, in_text);
globalreg->panel_interface->AddPanel(ma);
return 1;
}
}
} else if (mode == MODE_ASYNC_PP_SCAN) {
vector<string> data = ddata->dtable->GetSelectedData();
vector<vector<string> >::iterator i = ddata->info_vec_pp.begin();
for (int j = 0; i < ddata->info_vec_pp.end(); ++i, ++j) {
if ((*i)[0] == data[0]) {
ddata->sync_station = (*i);
ddata->ctable->Hide();
ddata->dtable->Clear();
ddata->dtable->AddRow(0, (*i));
ddata->dtable->Show();
ddata->dtable->DrawComponent();
string cmd("DECT 1 2 " + data[2] + " " + data[0]);
printf("%s\n", cmd.c_str());
_MSG(cmd, MSGFLAG_INFO);
if (globalreg &&
globalreg->panel_interface &&
globalreg->panel_interface->FetchFirstNetclient()) {
globalreg->panel_interface->FetchFirstNetclient()->InjectCommand(cmd);
}
Kis_ModalAlert_Panel *ma = new Kis_ModalAlert_Panel(globalreg, globalreg->panel_interface);
ma->Position((LINES / 2) - 8, (COLS / 2) - 25, 12, 50);
ma->ConfigureAlert("", "Syncing to chosen station " + data[0]);
ma->Position((LINES / 2) - 8, (COLS / 2) - 25, 10, 50);
ma->ConfigureAlert("", "Syncing to chosen station " + data[0]
+ "\n\nUse key 'F' to get back to FP scan"
+ "\nUse key 'A' to get back to PP scan");
globalreg->panel_interface->AddPanel(ma);
mode = MODE_SYNC_CALL_SCAN;
}
}
} else {
} else if (mode == MODE_ASYNC_PP_SCAN) {
vector<string> data = ddata->ctable->GetSelectedData();
if (data.size() < 1) {
// We got a button event even though the table was empty.
string cmd("DECT 1 1 0");
_MSG(cmd, MSGFLAG_INFO);
if (globalreg &&
globalreg->panel_interface &&
globalreg->panel_interface->FetchFirstNetclient()) {
globalreg->panel_interface->FetchFirstNetclient()->InjectCommand(cmd);
}
return 1;
}
vector<vector<string> >::iterator i = ddata->info_vec_pp.begin();
for (int j = 0; i < ddata->info_vec_pp.end(); ++i, ++j) {
if ((*i)[0] == data[0]) {
ddata->sync_station = (*i);
ddata->ctable->Hide();
ddata->dtable->Clear();
ddata->dtable->AddRow(0, (*i));
ddata->dtable->Show();
ddata->dtable->DrawComponent();
string cmd("DECT 1 2 " + data[2] + " " + data[0]);
_MSG(cmd, MSGFLAG_INFO);
if (globalreg &&
globalreg->panel_interface &&
globalreg->panel_interface->FetchFirstNetclient()) {
globalreg->panel_interface->FetchFirstNetclient()->InjectCommand(cmd);
}
Kis_ModalAlert_Panel *ma = new Kis_ModalAlert_Panel(globalreg, globalreg->panel_interface);
ma->Position((LINES / 2) - 8, (COLS / 2) - 25, 10, 50);
ma->ConfigureAlert("", "Syncing to chosen station " + data[0]
+ "\n\nUse key 'F' to get back to FP scan"
+ "\nUse key 'A' to get back to PP scan");
globalreg->panel_interface->AddPanel(ma);
mode = MODE_SYNC_CALL_SCAN;
}
}
} else if (mode == MODE_SYNC_CALL_SCAN) {
vector<string> data = ddata->dtable->GetSelectedData();
if (data.size() < 1) {
// We got a button event even though the table was empty.
string cmd("DECT 1 0 0");
_MSG(cmd, MSGFLAG_INFO);
if (globalreg &&
globalreg->panel_interface &&
globalreg->panel_interface->FetchFirstNetclient()) {
globalreg->panel_interface->FetchFirstNetclient()->InjectCommand(cmd);
}
return 1;
}
Kis_ModalAlert_Panel *ma = new Kis_ModalAlert_Panel(globalreg, globalreg->panel_interface);
ma->Position((LINES / 2) - 5, (COLS / 2) - 20, 12, 40);
ma->ConfigureAlert("Warning", "No Mode selected: Use keys 'A' or 'F'");
ma->Position((LINES / 2) - 5, (COLS / 2) - 25, 10, 50);
if (ddata->sync_station.size() < 1) {
_MSG("No synced station recored in sync mode", MSGFLAG_ERROR);
return 1;
}
if (data[0] == ddata->sync_station[0]) {
ma->ConfigureAlert("", "Already synced to station " + data[0]
+ "\n\nUse key 'F' to get back to FP scan"
+ "\nUse key 'A' to get back to PP scan");
} else {
ma->ConfigureAlert("", "Not syncing to station " + data[0]
+ ", already synced to "
+ ddata->sync_station[0]
+ "\n\nUse key 'F' to get back to FP scan"
+ "\nUse key 'A' to get back to PP scan");
}
globalreg->panel_interface->AddPanel(ma);
}
@ -497,14 +537,14 @@ int panel_plugin_init(GlobalRegistry *globalreg, KisPanelPluginData *pdata) {
ti.push_back(t3);
Kis_Scrollable_Table::title_data t4;
t4.width = 16;
t4.width = 20;
t4.draw_width = 8;
t4.title = "First";
t4.alignment = 8;
ti.push_back(t4);
Kis_Scrollable_Table::title_data t5;
t5.width = 16;
t5.width = 20;
t5.draw_width = 8;
t5.title = "Last";
t5.alignment = 8;
@ -522,8 +562,13 @@ int panel_plugin_init(GlobalRegistry *globalreg, KisPanelPluginData *pdata) {
pdata->mainpanel->AddComponentVec(ddata->dtable, (KIS_PANEL_COMP_DRAW |
KIS_PANEL_COMP_TAB |
KIS_PANEL_COMP_EVT));
pdata->mainpanel->AddComponentVec(ddata->ctable, (KIS_PANEL_COMP_DRAW |
KIS_PANEL_COMP_TAB |
KIS_PANEL_COMP_EVT));
pdata->mainpanel->FetchNetBox()->Pack_After_Named("KIS_MAIN_NETLIST",
ddata->dtable, 1, 0);
pdata->mainpanel->FetchNetBox()->Pack_After_Named("KIS_MAIN_NETLIST",
ddata->ctable, 1, 0);
ddata->dtable->Activate(1);
ddata->ctable->Activate(1);
@ -532,6 +577,8 @@ int panel_plugin_init(GlobalRegistry *globalreg, KisPanelPluginData *pdata) {
// Callback shows details on the station list
ddata->dtable->SetCallback(COMPONENT_CBTYPE_ACTIVATED,
DectListerButtonCB, ddata);
ddata->ctable->SetCallback(COMPONENT_CBTYPE_ACTIVATED,
DectListerButtonCB, ddata);
ddata->addref =
pdata->kpinterface->Add_NetCli_AddCli_CB(DectCliAdd, (void *) pdata);

View File

@ -26,6 +26,10 @@
//#include "audioDecode.h"
#define MODE_ASYNC_FP_SCAN 0
#define MODE_ASYNC_PP_SCAN 1
#define MODE_SYNC_CALL_SCAN 2
#define COA_IOCTL_MODE 0xD000
#define COA_IOCTL_CHAN 0xD004
#define COA_IOCTL_SETRFPI 0xD008
@ -56,7 +60,7 @@
// Globals
int dect_comp_datachunk;
static int mode = DECT_SUBCMD_SCAN_FP;
static int mode = MODE_ASYNC_FP_SCAN;
static int switched = 0;
/* This is the 7 bytes we read while scanning */
@ -148,13 +152,17 @@ int dumpfiledectpcap_chain_hook(CHAINCALL_PARMS) {
}
Dumpfile_Dectpcap::Dumpfile_Dectpcap() {
_MSG("FATAL OOPS: Dumpfile_Dectpcap called with no globalreg", MSGFLAG_ERROR);
_MSG("FATAL OOPS: Dumpfile_Dectpcap called with no globalreg",
MSGFLAG_ERROR);
exit(1);
}
Dumpfile_Dectpcap::Dumpfile_Dectpcap(GlobalRegistry *in_globalreg) :
Dumpfile(in_globalreg) {
char ftime[256];
char dfname[512];
time_t rawtime;
struct tm *timeinfo;
char errstr[STATUS_MAX];
globalreg = in_globalreg;
@ -176,17 +184,13 @@ Dumpfile_Dectpcap::Dumpfile_Dectpcap(GlobalRegistry *in_globalreg) :
dectpcapfile = fopen(fname.c_str(), "w");
if (dectpcapfile == NULL) {
snprintf(errstr, STATUS_MAX, "Failed to open dectpcap dump file '%s': %s",
snprintf(errstr, STATUS_MAX,
"Failed to open dectpcap dump file '%s': %s",
fname.c_str(), strerror(errno));
globalreg->fatal_condition = 1;
return;
}
char ftime[256];
char dfname[512];
time_t rawtime;
struct tm *timeinfo;
time (&rawtime);
timeinfo = localtime(&rawtime);
@ -244,8 +248,8 @@ int Dumpfile_Dectpcap::chain_handler(kis_packet *in_pack) {
dect_datachunk *dc = (dect_datachunk *)
in_pack->fetch(dect_comp_datachunk);
// We only want kind "2"
if (!dc || dc->kind != 2) {
// We only want kind MODE_SYNC_CALL_SCAN
if (!dc || dc->kind != MODE_SYNC_CALL_SCAN) {
return 0;
}
@ -318,7 +322,8 @@ public:
virtual PacketSource_Dect *CreateSource(GlobalRegistry *in_globalreg,
string interface,
vector<opt_pair> *in_opts) {
PacketSource_Dect *ref = new PacketSource_Dect(in_globalreg, interface, in_opts);
PacketSource_Dect *ref = new PacketSource_Dect(in_globalreg,
interface, in_opts);
// XXX Hackalert
SetExternal(ref);
return ref;
@ -387,7 +392,7 @@ public:
_MSG("Couldn't ioctl to COA_MODE_SNIFF", MSGFLAG_ERROR);
return;
}
mode = COA_SUBMODE_SNIFF_SCANFP;
mode = MODE_ASYNC_FP_SCAN;
switched = 1;
if (sync) {
_MSG("Sync off.", MSGFLAG_INFO);
@ -407,10 +412,10 @@ public:
_MSG("Couldn't ioctl to COA_MODE_SNIFF", MSGFLAG_ERROR);
return;
}
mode = COA_SUBMODE_SNIFF_SCANFP;
mode = MODE_ASYNC_PP_SCAN;
switched = 1;
if (sync) {
_MSG("Sync off.", MSGFLAG_ERROR);
_MSG("Sync off.", MSGFLAG_INFO);
sync = false;
}
// Remove lock, if there is any, and start scanning at channel 0
@ -433,7 +438,7 @@ public:
_MSG("Couldn't ioctl SETRFPI", MSGFLAG_ERROR);
return;
}
mode = 2;
mode = MODE_SYNC_CALL_SCAN;
if (sync) {
sync = false;
}
@ -472,11 +477,8 @@ public:
kis_packet *newpack = globalreg->packetchain->GeneratePacket();
dect_datachunk *dc = new dect_datachunk;
// Don't remove this, or it's gonna lock your box
usleep(10000);
// Async FP/PP scan read 7 bytes each
if (mode == 0 || mode == 1) {
if (mode == MODE_ASYNC_FP_SCAN || mode == MODE_ASYNC_PP_SCAN) {
if ((rbytes = read(serial_fd, &(dc->sdata), 7)) != 7) {
// Fail
stringstream s;
@ -492,11 +494,11 @@ public:
dc->sdata.RFPI[3],
dc->sdata.RFPI[4]);
_MSG("RFPI: " + string(station), MSGFLAG_INFO);
dc->kind = 0;
dc->kind = mode;
newpack->insert(dect_comp_datachunk, dc);
globalreg->packetchain->ProcessPacket(newpack);
}
} else if (mode == 2) {
} else if (mode == MODE_SYNC_CALL_SCAN) {
if ((rbytes = read(serial_fd,
&(dc->pdata),
sizeof(dc->pdata))) != sizeof(dc->pdata)) {
@ -512,7 +514,7 @@ public:
sync = true;
}
dc->sync = sync;
//dc->kind = 2;
dc->kind = MODE_SYNC_CALL_SCAN;
newpack->insert(dect_comp_datachunk, dc);
globalreg->packetchain->ProcessPacket(newpack);
}
@ -527,6 +529,9 @@ public:
void setLock(bool lock, int arg)
{
if (arg != -1) {
stringstream chan;
chan << arg;
_MSG("Locking to " + chan.str(), MSGFLAG_INFO);
SetChannel(arg);
}
locked = lock;
@ -592,7 +597,7 @@ public:
int currentmode = mode;
// If this packet doesn't have dect info or if it's call data, move
// along.
if (dectinfo == NULL || dectinfo->kind == 2) {
if (dectinfo == NULL || dectinfo->kind == MODE_SYNC_CALL_SCAN) {
return 0;
}
if (switched) {
@ -751,6 +756,7 @@ int dect_cc_callback(CLIENT_PARMS)
rfpi[4]);
_MSG(string(station), MSGFLAG_INFO);
ex_psd->startScanCalls(rfpi, arg);
dtracker->emptyMap();
break;
default:
_MSG("Bad DECT_CMD_SCAN subcommand.", MSGFLAG_ERROR);
@ -867,7 +873,7 @@ int dect_register(GlobalRegistry *globalreg) {
// Add the channels
globalreg->sourcetracker->AddChannelList("DECT:0,1,2,3,4,5,6,7,8,9");
// Hopefully this won't break since we don't know about memory management
// Hopefully this won't break since we don't knw about memory management
// of packetsources
PacketSource_Dect *psd = new PacketSource_Dect(globalreg);
if (!psd) {