[Dsctl-devel] SF.net SVN: dsctl: [140] src
Status: Alpha
Brought to you by:
roger-linux
From: <rog...@us...> - 2007-11-10 21:40:42
|
Revision: 140 http://dsctl.svn.sourceforge.net/dsctl/?rev=140&view=rev Author: roger-linux Date: 2007-11-10 13:40:39 -0800 (Sat, 10 Nov 2007) Log Message: ----------- commands.h/commands.c - Added get_lockout_tgid, get_search_lockout_tgid commands.c - Trivial: Removed not needed variables within functions. Trivial: Improved readability of misc comments. Trivial: Added TODO file. Optimized: Reduced duplicate usage of atoi and made comments within code for aiding anybody else reading the code. Modified Paths: -------------- src/commands.c src/commands.h Added Paths: ----------- TODO Added: TODO =================================================================== --- TODO (rev 0) +++ TODO 2007-11-10 21:40:39 UTC (rev 140) @@ -0,0 +1,63 @@ +1) Implementing the commands according to the BCD996T_Protocol.pdf + is simply the only things left to do besides some bugs + concerning serial communication. Most of the protocol commands, + if not all of them, are located within the commands.c file. + + I've completed almost all the _get_ commands to retrieve data + from the units including some of the _set_ commands to send + data to the unit. To see what I haven't done yet, look at the + commands.h file for commented function declarations. Obviously, + these are the functions (aka scanner commands) needing + implementing. + + It's quite easy really. You can basically copy/paste over most + of the code within the previous functions according to whether + it's a get_ or set_ command. You just need to either read the + returned comma parsed string into the proper varaibles for + printing. If the command is to _set or send data, again, the + string needs to be read in from file and formated properly before + sending the string to the scanner. + + I've even found the commands for uploading firmware. + + The only gotcha, I tried implementing a delay into the serial.c + with hopes of the program detecting a stall and quiting instead + of locking the computer with the system call. You may notice the + delay values somewhere between 10 seconds to 45+ seconds for + downloading or uploading. For loading the firmware, it can take + more then 5 minutes. + + I, or somebody else, might consider re-writing the code once the + functions are implemented for easier reading. Should probably use + structs? + + If you look at the protocol pdf file, I'm also missing APPEND + functions. + + +2) Some sort of frontend is needed for programming this scanner. + There's just too much loose data, requiring specific ranges, etc, + for a simple user to enter by hand. I'm up for ideas here. + Gnome or ncurses based UI??? Well, I do have autoconfig/automake + installed, albeit, roughly. + + One method probably doesn't require much of a frontend, direct + downloading for radioreference.com. However, users generally + still have to fill in TGID's after searching for them on an + APCO based system. + +3) I do have a basic command implemented for Live Streaming via + Icecast. The stream is also updated with the active frequency data. + There's a bug, after a time period of streaming, the + ncurses display will freeze, but it basically works. (Think the + bug/freeze is encountered with certain freq/band is hit.) + +4) Future: + a) Possible rewrite using structs instead of all arrays and + pointers? + b) I'm seeing a lot of repeated code and could easily be + integrated into functions within utils.c. + + These items could significantly shorten code while increase + readability. + Modified: src/commands.c =================================================================== --- src/commands.c 2007-11-06 01:37:19 UTC (rev 139) +++ src/commands.c 2007-11-10 21:40:39 UTC (rev 140) @@ -35,10 +35,14 @@ void get_current_tgid_status(int fd) { /* GID - Current TGID Status - * Uniden's GID & GLG commands only prints out the first unique occurance - * of active TGID info. After the first display, repeated reissues of - * these commands will return null until a different TGID becomes active. - * Save last info and recall it as "Last GID/GID Active:"? */ + * Uniden's GID & GLG commands only prints out the first unique + * occurance of active TGID info. After the first display, repeated + * reissues of these commands will return null until a different TGID + * becomes active. + + * Save last info into temp file and recall it as needed? Think I've + * fixed this. See what data I'm putting into ~/.dsctl/metadata + * file. */ char answer[500]; char *field[100]; @@ -116,7 +120,9 @@ replace_chars(field[8], field[8]); /*printf("Test replace_chars: %s, %i\n\n\n", field[8], strlen(field[8]); */ - //replace_chars(field[10], field[10]); /* replace_chars is omitting Sytems Scan status line, so comment out for now */ + /*replace_chars(field[10], field[10]);*/ /* replace_chars is omitting + Sytems Scan status line, so comment out for now */ + /*printf("Test replace_chars: %s, %i\n\n\n", field[8], strlen(field[8]); */ /* Detect scroll effect of the 6th field SCAN and @@ -296,7 +302,8 @@ check_err(command, answer); - /* TODO: We only check for "OK" and not the "," when a 16 char name remains unchanged */ + /* TODO: We only check for "OK" and not the "," when a 16 char name + remains unchanged */ if (strncmp(answer, "PRG,OK", 6) != 0) { exit_prg_mode(fd); @@ -713,7 +720,6 @@ int get_system_info(int fd, int system_index, char *system_type, char *channel_group_head) { - //get_group_quick_lockout(fd, sys_index); /* This might break things */ char answer[500], command[100]; char *field[100]; @@ -741,16 +747,11 @@ /* Set our starting Group and Site index addresses from SIN info */ /* Pointers are returned from parse_fields, use strncpy for strings. */ - //siteinfo_index = atoi(sys_field[14]); - //trunkinfo_index = sys_index; - //grpinfo_index = atoi(sys_field[14]); - //strncpy(sys_type, sys_field[1], 5); strncpy(system_type, field[1], 5); strncpy(channel_group_head, field[14], 10); - /*sys_type = sys_field[1]; */ - /*printf("systype = %s\n", sys_type); */ - /*printf("trunkinfo_index = %i\n", trunkinfo_index); */ + /*printf("systype = %s\n", system_type); */ + /*printf("sys_index = %i\n", sys_index); */ /* We're using the Forward System Index field for getting the * next System Info address. Set this after we set the above variables. */ @@ -821,16 +822,12 @@ } printf("\n"); - /* We're using the Forward Site Info Index field for - * getting the next Site Info address. - * There is no forward index for this group. Uses sys_field[14]. */ - /*trunkinfo_index = atoi (trunkinfoinfo_field[12]); */ - - /* Reset starting GIN address since we're a Trunked System - * instead of using the SIN address values for starting GIN - * - * We have no map of the internal memory. Linking starting TRN/GIN/TIN addresses - * is guess work because of the poorly proof-read Uniden documentation. */ + /* Since we're a Trunked System, provide an alternative starting + * GIN index instead of using the provided SIN address for starting + * GIN index value. (Flip Flop here for getting the GIN index + * address :-/ Finding starting addresses for TRN/GIN/TIN commands + * is guess work because of the poorly proof-read documentation. + :-/ ) */ group_info_index = atoi(field[21]); return (group_info_index); @@ -1464,6 +1461,108 @@ } /*********************************************************************** +* Get Locked Out TGIDs +***********************************************************************/ +/* TODO - Ensure GLI info is downloading. It seems to work. */ +int get_lockout_tgid(int fd, int system_index) +{ + char answer[100], command[100]; + char *field[100]; + int i, cmd_index = 0; + + memset(answer, 0, 100); + memset(command, 0, 100); + memset(field, 0, 100); + + snprintf(command, 100, "GLI,%i", system_index); + /* printf("\nCommand == %s\n", command); */ + do_command(fd, command, answer); + /* printf("%s\n(%i)\n", answer, strlen(answer)); */ + parse_fields(answer, field); + + cmd_index = atoi(field[1]); + + /* While we have L/O TGIDs, get them. */ + while (cmd_index != -1) + { + do_command(fd, command, answer); + /*printf("%s\n(%i)\n", answer, strlen(answer)); */ + parse_fields(answer, field); + + /* We have 2 parsed fields to print for this command */ + for (i = 0; i <= 1; i++) + { + if (i != 0) + printf(","); + printf("%s", field[i]); + } + printf("\n"); + cmd_index = atoi(field[1]); + } + + return (0); +} + +/*********************************************************************** +* Get Search Lockout TGID +***********************************************************************/ +/* TODO - Ensure SLI info is downloading. It seems to work. */ +int get_search_lockout_tgid(int fd, int system_index) +{ + char answer[100], command[100]; + char *field[100]; + int i, cmd_index = 0; + + memset(answer, 0, 100); + memset(command, 0, 100); + memset(field, 0, 100); + + snprintf(command, 100, "SLI,%i", system_index); + /* printf("\nCommand == %s\n", command); */ + do_command(fd, command, answer); + /* printf("%s\n(%i)\n", answer, strlen(answer)); */ + parse_fields(answer, field); + + cmd_index = atoi(field[1]); + + /* While we have Search L/O TGIDs, get them. */ + while (cmd_index != -1) + { + do_command(fd, command, answer); + /*printf("%s\n(%i)\n", answer, strlen(answer)); */ + parse_fields(answer, field); + + /* We have 2 parsed fields to print for this command */ + for (i = 0; i <= 1; i++) + { + if (i != 0) + printf(","); + printf("%s", field[i]); + } + printf("\n"); + cmd_index = atoi(field[1]); + } + + return (0); +} + +/*********************************************************************** +* Unlock TGID - TODO +***********************************************************************/ +/*int unlock_tgid(int fd, int system_index) +{ + +} */ + +/*********************************************************************** +* Lockout TGID - TODO +***********************************************************************/ +/* int lockout_tgid(int fd, int system_index) +{ + +} */ + +/*********************************************************************** * Get Remains of Memory ***********************************************************************/ int get_remains_memory_block(int fd) @@ -1543,10 +1642,6 @@ /*printf("\n%s\n(%i)\n", answer, strlen(answer)); */ sscanf(answer, "LIH,%i", &loc_indexhead); - /* While we have Location Alert Systems, then print them. - * And once we find the first system, find the next one using - * forward system index field */ - return (loc_indexhead); } @@ -2213,7 +2308,8 @@ /*********************************************************************** * Download BCD memory contents -* TODO: All done. Just need to make things look nice. +* TODO: All done except misc stuff (see commands.h for commented code) +* TODO: Need to also make things look nice. ***********************************************************************/ int dump(int fd, FILE * outfile) { @@ -2221,9 +2317,8 @@ char sys_type[5], site_type[5]; - int sys_index, grpinfo_index, chaninfo_index, trunkinfo_index, - siteinfo_index, motbandplan_index, apcobandplan_index, - trunkfreq_index, tgidinfo_index; + int sys_index, grpinfo_index, chaninfo_index, + siteinfo_index, trunkfreq_index, tgidinfo_index; /* File Version Format */ printf("dsctl version %s\n\n", FFVERSION); @@ -2290,7 +2385,13 @@ get_gps_display_option(fd); - /* Get Scan Settings */ + /* Get Scan Settings + * The "scan data" is organized into two basic trees. One for + * conventional freqs and the other tree organized for trunked freqs. + * I ordered the function calls below into a very particular order + * intended to reduce overhead on the scanner. (ie. We've already + * gotten the data once. Why make a second call to the scanner when we + * already have the data?) */ /* SIN * While we have System Indexes, then print them. @@ -2311,30 +2412,20 @@ /* Continue getting System Info */ char channel_group_head[10]; - int next_system_index = 0; + int next_sys_index = 0; memset(channel_group_head, 0, 10); - next_system_index = + next_sys_index = get_system_info(fd, sys_index, sys_type, channel_group_head); - /* Set our starting Group and Site index addresses from SIN info */ - //siteinfo_index = atoi(sys_field[14]);*/ + /* Set our starting Group and Site index addresses from SIN info - Reduced atoi usage*/ siteinfo_index = atoi(channel_group_head); - trunkinfo_index = sys_index; - //grpinfo_index = atoi(sys_field[14]); - grpinfo_index = atoi(channel_group_head); - //strncpy(sys_type, sys_field[1], 5); + grpinfo_index = siteinfo_index; - /*sys_type = sys_field[1]; */ /*printf("systype = %s\n", sys_type); */ - /*printf("trunkinfo_index = %i\n", trunkinfo_index); */ + /*printf("sys_index = %i\n", sys_index); */ - /* We're using the Forward System Index field for getting the - * next System Info address. Set this after we set the above variables. */ - //sys_index = atoi(sys_field[13]); - sys_index = next_system_index; - /* TRN */ /* While System has Trunked Systems, then print them. * @@ -2343,13 +2434,13 @@ * variable. * * We only get Site Info, as well as trunked frequencies, - * if the system is not conv type */ - /*printf("systype = %s trunkinfo_index = %i\n", sys_type, - trunkinfo_index); */ - /*TODO: trunkinfo_index -- used orig name. Might want to rename it. */ - if (trunkinfo_index != -1 && strncmp(sys_type, "CNV", 3) != 0 + * if the system is not a conventional type */ + /*printf("systype = %s sys_index = %i\n", sys_type, + sys_index); */ + + if (sys_index != -1 && strncmp(sys_type, "CNV", 3) != 0 && strncmp(sys_type, "LTR", 3) != 0) - grpinfo_index = get_trunk_info(fd, trunkinfo_index); + grpinfo_index = get_trunk_info(fd, sys_index); /* GIN */ /* While System has Groups, then print them. @@ -2365,20 +2456,19 @@ next_group_index = get_group_info(fd, grpinfo_index, channel_index); - /* We're using the Forward Group Index field for getting - * the next Group Info address. */ - grpinfo_index = next_group_index; - - /* Set our starting channel address index from GIN info */ + /* Set our starting channel address index from GIN info - Reduced atoi usage. */ chaninfo_index = atoi(channel_index); - tgidinfo_index = atoi(channel_index); + tgidinfo_index = chaninfo_index; /* CIN */ /* While Group has Channels, and System Type is Conventional, then print them. * Else they're treated like Trunk Group ID's. */ /*printf(" (Channel Starting Location: %s Channel Ending Location: %s)\n", grp_field[8], grp_field[9]; */ - /*chaninfo_index = atoi (grp_field[8]); */ int next_channel_index = 0; + + /* We're using the Forward Group Index field for getting + * the next Group Info address. */ + grpinfo_index = next_group_index; while (chaninfo_index != -1 && (strncmp(sys_type, "CNV", 3) == 0 @@ -2390,12 +2480,11 @@ /* We're using the Forward Channel Index field for getting * the next Channel Info address. */ - //chaninfo_index = atoi(chan_field[12]); chaninfo_index = next_channel_index; } /* TIN */ - /* While system is not convention, then get Trunk Group ID info. */ + /* While system is not conventional, then get Trunk Group ID info. */ /*printf(" (TGID Starting Location: %s TGID Ending Location: %s)\n", tgid_field[8], tgid_field[9]; */ /*printf("systype = %s\n", sys_type); */ int next_tgidinfo_index = 0; @@ -2408,9 +2497,16 @@ /* We're using the Forward Trunk Group ID Info Index field for getting * the next Trunk Group ID info address. */ - //tgidinfo_index = atoi(tgid_field[8]); tgidinfo_index = next_tgidinfo_index; } + + /* GLI & SLI */ + /* If a system is not conventional, then get all L/O TGIDs and Search L/O TGIDs for the System */ + if (strncmp(sys_type, "CNV", 3) != 0 && strncmp(sys_type, "LTR", 3) != 0) + { + get_lockout_tgid(fd, sys_index); + get_search_lockout_tgid(fd, sys_index); + } } /* SIF */ @@ -2419,10 +2515,7 @@ * if the System is not Conv Type * * (Site Info shares the first Group's address for some - * odd/undocumented reason - memory layout?) - * - * Set our grpinfo variable before getting site info because - * these are pointers and Site Info will overwrite it's variable! */ + * odd/undocumented reason. Documentation error with index locations?) */ char trunk_freq_index[10]; int next_site_index = 0; @@ -2437,30 +2530,32 @@ /* Set other variables for sub-commands */ trunkfreq_index = atoi(trunk_freq_index); - motbandplan_index = siteinfo_index; - apcobandplan_index = siteinfo_index; - /* We're using the Forward Site Info Index field for - * getting the next Site Info address. */ - siteinfo_index = next_site_index; - /* MBP *Only if it's a trunked MU2 or MV2 site, * and get this info before trunk freqs. */ if (strncmp(site_type, "MU2", 3) == 0 || strncmp(site_type, "MV2", 3) == 0) - get_motorola_band_plan(fd, motbandplan_index); + get_motorola_band_plan(fd, siteinfo_index); /* APB * If trunked MP25 site, get this info. */ if (strncmp(site_type, "MP25", 4) == 0) - get_apco25_band_plan(fd, apcobandplan_index); + get_apco25_band_plan(fd, siteinfo_index); /* TFQ * While Sites has Trunk Frequencies, then print them. */ while (trunkfreq_index != -1) trunkfreq_index = get_trunk_freq_info(fd, trunkfreq_index); + + /* We're using the Forward Site Info Index field for + * getting the next Site Info address. */ + siteinfo_index = next_site_index; } + + /* We're using the Forward System Index field for getting the + * next System Info address. Set this after all other variables get sys_index! */ + sys_index = next_sys_index; } /* Get Location Alert Settings Modified: src/commands.h =================================================================== --- src/commands.h 2007-11-06 01:37:19 UTC (rev 139) +++ src/commands.h 2007-11-10 21:40:39 UTC (rev 140) @@ -109,8 +109,8 @@ /* End Scan Settings Commands */ -/*int get_lockout_tgid(int fd, int system_index);*/ -/*int get_search_lockout_tgid(int fd, int system_index);*/ +int get_lockout_tgid(int fd, int system_index); +int get_search_lockout_tgid(int fd, int system_index); /*int unlock_tgid(int fd, int system_index); int lockout_tgid(int fd, int system_index); int reverse_index(int fd, int index); @@ -177,7 +177,7 @@ int fw_mode_program(int fd); -/* Elongated Functions - Using above lower-level scanner command functions */ +/* Higher Level Functions using above lower level scanner commands */ int dump(int fd, FILE *outfile); int load_firmware(int fd, FILE *infile); int load(int fd, FILE *infile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |