[Dsctl-devel] SF.net SVN: dsctl: [129] src
Status: Alpha
Brought to you by:
roger-linux
|
From: <rog...@us...> - 2007-07-21 06:12:22
|
Revision: 129
http://dsctl.svn.sourceforge.net/dsctl/?rev=129&view=rev
Author: roger-linux
Date: 2007-07-20 23:12:17 -0700 (Fri, 20 Jul 2007)
Log Message:
-----------
get_recept_status:
write_metadata:
This makes for a working Icecast/Ices2 implementation. Example:
./dsctl -i 30653 -n status
(-i [ices pid], -h for more info)
Dsctl currently reports metadata about the current reception hit
to ~/.dsctl/metadata file with or without specifying -i.
key_press:
Fixed bug with press type.
Signed-off-by: Roger <ro...@es...>
Acked-by: Roger <ro...@es...>
Modified Paths:
--------------
src/commands.c
src/commands.h
src/human_commands.c
src/main.c
src/main.h
src/serial.c
src/usage.c
src/utils.c
src/utils.h
Modified: src/commands.c
===================================================================
--- src/commands.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/commands.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -119,61 +119,66 @@
//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]); */
- /* Stop the scroll effect of the 6th field SCANNING.
- * And preserve the effect for daemon_mode & osd mode. */
- if (daemon_mode == 0 || osd == 0)
- {
- char first_half[20];
- char second_half[20];
+ /* Detect scroll effect of the 6th field SCAN and
+ * report it to metadata file.
+ * Preserve the effect for daemon_mode & ncurses osd mode.
+ * TODO: Also catch "Nothing to Scan", "ID SEARCH", "ID SCAN"
+ * and send to write_metadata() */
+ char first_half[20];
+ char second_half[20];
- sscanf(field[6], "%s %s", first_half, second_half);
- strcat(second_half, first_half);
- if (strncmp(first_half, "SCAN", 4) == 0 ||
- strncmp(second_half, "SCAN", 4) == 0)
+ sscanf(field[6], "%s %s", first_half, second_half);
+ strcat(second_half, first_half);
+ if (strncmp(first_half, "SCAN", 4) == 0 ||
+ strncmp(second_half, "SCAN", 4) == 0)
+ {
+ write_metadata(field[4], "SCANNING", "\0");
+ if (daemon_mode == 0 || osd == 0)
strncpy(field[6], "SCANNING\0", 17);
}
+
/*if (daemon_mode == 0 || osd == 0)
- {
- printf("Display Status:\n");
- printf(" %s\n %s\n %s\n %s\n", field[6], field[8], field[10],
- field[12]);
+ {
+ printf("Display Status:\n");
+ printf(" %s\n %s\n %s\n %s\n", field[6], field[8], field[10],
+ field[12]);
- if (atoi(field[14]) == 0)
- printf(" Squelch Status: Closed\n");
- else
- printf(" Squelch Status: Open\n");
- if (atoi(field[15]) == 0)
- printf(" Mute Status: Off\n");
- else
- printf(" Mute Status: ON\n");
- if (atoi(field[17]) == 0)
- printf(" Weather Alert: None\n");
- else
- printf(" Weather Alert: ON for SAME CODE - %s", field[17]);
- if (atoi(field[18]) == 0)
- printf(" Close Call LED: Off\n");
- else
- printf(" Close Call LED: ON\n");
- if (atoi(field[19]) == 0)
- printf(" Alert LED: Off\n");
- else
- printf(" Alert LED: ON\n");
+ if (atoi(field[14]) == 0)
+ printf(" Squelch Status: Closed\n");
+ else
+ printf(" Squelch Status: Open\n");
+ if (atoi(field[15]) == 0)
+ printf(" Mute Status: Off\n");
+ else
+ printf(" Mute Status: ON\n");
+ if (atoi(field[17]) == 0)
+ printf(" Weather Alert: None\n");
+ else
+ printf(" Weather Alert: ON for SAME CODE - %s", field[17]);
+ if (atoi(field[18]) == 0)
+ printf(" Close Call LED: Off\n");
+ else
+ printf(" Close Call LED: ON\n");
+ if (atoi(field[19]) == 0)
+ printf(" Alert LED: Off\n");
+ else
+ printf(" Alert LED: ON\n");
- printf(" Signal Level: %i\n\n", atoi(field[20]));
- }*/
+ printf(" Signal Level: %i\n\n", atoi(field[20]));
+ } */
- if (daemon_mode == 0 || osd == 0)
- printf("Current Display Status:\n");
-
+ if (daemon_mode == 0 || osd == 0)
+ printf("Current Display Status:\n");
+
/* We have 23 parsed fields to print for this command */
- for (i = 0; i <= 22; i++)
- {
- if (i != 0)
- printf(",");
- printf("%s", field[i]);
- }
- printf("\n");
+ for (i = 0; i <= 22; i++)
+ {
+ if (i != 0)
+ printf(",");
+ printf("%s", field[i]);
+ }
+ printf("\n");
}
/***********************************************************************
@@ -195,23 +200,16 @@
if (daemon_mode == 0 || osd == 0)
printf("\nReception Status:\n");
-
- /* Compare just one field to the external metadata variable and if
- * if this field is different, then over metadata file with new data */
- if (strcmp(metadata_title, field[7]) != 0)
- {
- if (debug > 0)
- printf("DEBUG get_reception_status: Data differs. \
- Writing metadata file\n\n\n");
- write_metadata(field[6], field[7]);
- strcpy(metadata_title, field[7]);
- }
+ /* If freqency hit, then write_metadta() */
+ if (strcmp("\0", field[1]) != 0)
+ write_metadata(field[5], field[6], field[7]);
+
/* Send this data to ~/.dsctl/metadata */
//write_metadata(field[6], field[7]);
-
+
/* We have 10 parsed fields to print for this command */
- for (i = 0; i <= 9; i++)
+ for (i = 0; i <= 8; i++)
{
if (i != 0)
printf(",");
Modified: src/commands.h
===================================================================
--- src/commands.h 2007-07-21 03:04:49 UTC (rev 128)
+++ src/commands.h 2007-07-21 06:12:17 UTC (rev 129)
@@ -36,9 +36,6 @@
extern int debug;
extern int osd;
-extern char metadata_artist[1024];
-extern char metadata_title[1024];
-
/***********************************************************************
* Function Declarations
***********************************************************************/
@@ -92,7 +89,7 @@
int append_channel_group(int fd, int system_index);
int append_tgid_group(int fd, int system_index);
- /*int delete_group(int fd, group_index);*//* Use same function for delete_site */
+ /*int delete_group(int fd, group_index); *//* Use same function for delete_site */
int get_group_info(int fd, int group_index, char *channel_index);
int set_group_info(int fd, int group_index, char **parsed_line);
int append_channel_freq(int fd, int group_index); /* Use same function for append_trunk_freq */
Modified: src/human_commands.c
===================================================================
--- src/human_commands.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/human_commands.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -40,8 +40,8 @@
***********************************************************************/
void human_do_dump(int fd, int argc, char **args)
{
- FILE *outfile;
- char errorstr[100];
+ /*FILE *outfile;
+ char errorstr[100]; */
/*if (scannermodel == BCD996T)
{
@@ -50,20 +50,23 @@
} */
/* FIXME: Why is args[0] not NULL??? Commenting out everything
- * for now! */
- //if (args[0] == NULL)
- dump(fd, stdout);
+ * for now! Mixed results for "*args[]", treating like strg else
+ * where or just checking if "== NULL" ... darn pointers!!!
+ *
+ * I give up. Commenting out things for now -- BUG:FIXME!*/
+ //if (strncmp(args[0], "\0", 1) == 0)
+ dump(fd, stdout);
/*else
- {
- if ((outfile = fopen(args[0], "w")) != NULL)
- dump(fd, outfile);
- else
- {
- snprintf(errorstr, 100, "dump to \"%s\" failed", args[1]);
- perror(errorstr);
- return;
- }
- }*/
+ {
+ if ((outfile = fopen(args[0], "w")) != NULL)
+ dump(fd, outfile);
+ else
+ {
+ snprintf(errorstr, 100, "dump to \"%s\" failed", args[1]);
+ perror(errorstr);
+ return;
+ }
+ } */
}
/***********************************************************************
@@ -133,7 +136,7 @@
usage(C_KEY);
/* Get second arg of Key Command */
- if (args[1] == NULL)
+ if (strncmp(args[1], "\0", 1) == 0)
key_mode = 'P';
else if (strncmp(args[1], "p", 1) == 0)
key_mode = 'P';
@@ -198,8 +201,9 @@
char buf2[30];
char *ap = buf2;
char *osd_clear, *osd_clear_line, *osd_up, *osd_cr;
- /*char *osd_invisible, *osd_visible;*/
+ /*char *osd_invisible, *osd_visible; */
+
tgetent(buf, getenv("TERM"));
osd_clear = tgetstr("cl", &ap);
@@ -207,8 +211,8 @@
osd_up = tgetstr("up", &ap);
osd_cr = tgetstr("cr", &ap);
/* FIXME: Why segfault ??? Should also be defined along w/ "vi"! */
- /*osd_invisible = tgetstr("vi", &ap);*/
- /*osd_visible = tgetstr("ve", &ap);*/
+ /*osd_invisible = tgetstr("vi", &ap); */
+ /*osd_visible = tgetstr("ve", &ap); */
while (daemon_mode != 0) /* simple endless loop */
{
@@ -216,21 +220,21 @@
if (debug > 0)
printf("osd value == %i\n", osd);
-
+
fputs(osd_clear_line, stdout);
get_current_status(fd);
printf("\n");
-
+
fputs(osd_clear_line, stdout);
get_reception_status(fd);
printf("\n");
-
+
fputs(osd_clear_line, stdout);
get_current_tgid_status(fd);
/* FIXME: Want cursor to be invisible! Also see leaveok() */
- /*fputs(osd_invisible, stdout);*/
+ /*fputs(osd_invisible, stdout); */
- for (i = 1; i <= 6 ; i ++)
+ for (i = 1; i <= 6; i++)
fputs(osd_up, stdout);
curs_set(0);
Modified: src/main.c
===================================================================
--- src/main.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/main.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -49,13 +49,11 @@
int osd = OSD; /* indicate the user wants ncurses osd */
int ices_pid = 0;
- /* Initialize metadata file variables */
- char metadata_artist[1024];
- char metadata_title[1024];
+/* Initialize metadata file variables */
+char metadata_album[1024];
+char metadata_artist[1024];
+char metadata_title[1024];
-// memset(metadata_artist, 0, 1024);
-// memset(metadata_title, 0, 1024);
-
/***********************************************************************
* the main function. ain't it grand?
***********************************************************************/
@@ -74,14 +72,15 @@
char configline[81];
char errorstr[100];
-
+
memset(serial_port, 0, 20);
memset(configline, 0, 81);
memset(errorstr, 0, 100);
+ memset(metadata_album, 0, 1024);
memset(metadata_artist, 0, 1024);
memset(metadata_title, 0, 1024);
-
+
cmd_loc = 1;
cmd_arg_loc = 2;
@@ -179,7 +178,7 @@
}
/* Remove "/config" from HOME enviroment variable */
reset_env_var("HOME", "/config");
-
+
fclose(configfile);
closedir(configfolder);
@@ -214,12 +213,11 @@
else if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--icespid") == 0) /* daemon mode */
{
ices_pid = atoi(argv[++i]);
-
+
cmd_loc += 2;
cmd_arg_loc += 2;
}
-
else if (strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--ncurses") == 0) /* osd */
{
daemon_mode = 1;
Modified: src/main.h
===================================================================
--- src/main.h 2007-07-21 03:04:49 UTC (rev 128)
+++ src/main.h 2007-07-21 06:12:17 UTC (rev 129)
@@ -24,6 +24,7 @@
#ifndef _MAIN_H_
#define _MAIN_H_
+extern char metadata_album[1024];
extern char metadata_artist[1024];
extern char metadata_title[1024];
Modified: src/serial.c
===================================================================
--- src/serial.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/serial.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -175,12 +175,14 @@
/* Check the serial port for usability */
int retval = 0;
+
while (retval != 1)
{
retval = check_port(fd, string);
if (retval != 1)
- printf("ERROR: read_serial Device disconnected? Incorrect baud rate?\n");
+ printf
+ ("ERROR: read_serial Device disconnected? Incorrect baud rate?\n");
}
/* Everything looks good so let's try reading from the port. */
@@ -216,16 +218,16 @@
tcgetattr(fd, &port);
/* Testing port for DCD, but nothing changes when scanner is connected or
- disconnected :-/
- int status;
- ioctl(fd, TIOCMGET, &status);*/
- /*if (status & TIOCSSOFTCAR )*/
- /*printf("DCD %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i \n", status, TIOCM_LE,TIOCM_DTR, TIOCM_RTS,
- TIOCM_ST ,TIOCM_SR, TIOCM_CTS, TIOCM_CD,TIOCM_RNG,TIOCM_RI ,
- TIOCM_DSR, TIOCM_DTR, TIOCM_CAR, TIOCSSOFTCAR);*/
+ disconnected :-/
+ int status;
+ ioctl(fd, TIOCMGET, &status); */
+ /*if (status & TIOCSSOFTCAR ) */
+ /*printf("DCD %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i \n", status, TIOCM_LE,TIOCM_DTR, TIOCM_RTS,
+ TIOCM_ST ,TIOCM_SR, TIOCM_CTS, TIOCM_CD,TIOCM_RNG,TIOCM_RI ,
+ TIOCM_DSR, TIOCM_DTR, TIOCM_CAR, TIOCSSOFTCAR); */
/*else
- printf("NO DCD %i %i \n", status, TIOCM_CAR);*/
-
+ printf("NO DCD %i %i \n", status, TIOCM_CAR); */
+
switch (baud_rate)
{
case 4800:
@@ -283,18 +285,19 @@
chars = strlen(string);
bytes = write(fd, string, chars);
-
+
/* Check the serial port for usability */
int retval = 0;
+
while (retval != 1)
{
retval = check_port(fd, string);
-
+
if (retval != 1)
- printf("ERROR: write_serial Device disconnected? Incorrect baud rate?\n");
+ printf
+ ("ERROR: write_serial Device disconnected? Incorrect baud rate?\n");
}
-
-
+
/* Everything looks good so let's try writing to the port. */
if (bytes < 0)
{
@@ -326,8 +329,8 @@
timeout.tv_sec = 20;
/*if (debug == 1)
- printf("DEBUG retval: %i timeout.tv_sec: %d \n", retval,
- timeout.tv_sec);*/
+ printf("DEBUG retval: %i timeout.tv_sec: %d \n", retval,
+ timeout.tv_sec); */
retval = (select(maxfd, &set, NULL, NULL, &timeout));
@@ -335,13 +338,13 @@
printf("DEBUG retval: %i\n", retval);
/*if FD_ISSET(fd, &set)
- retval = 1;*/ /* yes. redundant for testing now */
+ retval = 1; *//* yes. redundant for testing now */
if (retval == -1 || retval == 0)
{
errno = ETIME; /* Return the proper error code */
perror("ERROR: returned error code");
}
-
+
return (retval);
}
Modified: src/usage.c
===================================================================
--- src/usage.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/usage.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -71,7 +71,8 @@
fprintf(stderr,
" 4800, 9600, 19200, 38400, 57600, 115200\n\n");
- fprintf(stderr, " -d --daemon Daemon mode. (Experimental)\n\n");
+ fprintf(stderr,
+ " -d --daemon Daemon mode. (Experimental)\n\n");
fprintf(stderr, " -h --help This help text.\n\n");
@@ -80,15 +81,17 @@
fprintf(stderr,
" (bcd models are work in progress and bcd396t needs a tester.)\n\n");
- fprintf(stderr, " -i --icespid Current running Ices's PID. Dsctl will send SIGUSR1 to Ices for\n");
fprintf(stderr,
+ " -i --icespid Current running Ices's PID. Dsctl will send SIGUSR1 to Ices for\n");
+ fprintf(stderr,
" rereading ~/.dsctl/metadata. (This file needs to be stated\n");
fprintf(stderr,
" within your /etc/ices2/ices-alsa.xml.)\n\n");
- fprintf(stderr, " -n --ncurses Ncurses display. Implies daemon mode (Experimental)\n\n");
-
fprintf(stderr,
+ " -n --ncurses Ncurses display. Implies daemon mode (Experimental)\n\n");
+
+ fprintf(stderr,
" -p --port ie. \"-p /dev/ttyS0\" or \"-p /dev/ttyUSB0\"\n\n");
fprintf(stderr, " -v --verbose Verbose output.\n\n");
Modified: src/utils.c
===================================================================
--- src/utils.c 2007-07-21 03:04:49 UTC (rev 128)
+++ src/utils.c 2007-07-21 06:12:17 UTC (rev 129)
@@ -488,46 +488,62 @@
/***********************************************************************
* Write Metadata File
***********************************************************************/
-void write_metadata(char *artist_field, char *title_field)
+void write_metadata(char *album_field, char *artist_field, char *title_field)
{
char *metadataloc;
FILE *metadatafile;
-
+
if (debug > 0)
- printf("DEBUG write_metadata(): \"%s\" \"%s\"\n", artist_field, title_field);
-
- /* Check for $HOME/.dsctl/metadata */
- metadataloc = strcat(getenv("HOME"), "/metadata");
+ printf("DEBUG write_metadata(): \"%s\" \"%s\" \"%s\"\n", album_field,
+ artist_field, title_field);
- if ((metadatafile = fopen(metadataloc, "w")) != NULL)
- {
- fprintf(metadatafile,
- "ARTIST=%s\n", artist_field);
- fprintf(metadatafile,
- "TITLE=%s\n", title_field);
- }
- else /* unable to write a metadata file. if they don't have write permission
+ /* Compare just one field to the external metadata variable and if
+ * this field is different and not NULL, then write metadata file
+ * with new data. */
+ if ((strcmp(metadata_title, title_field) != 0))
+ {
+ if (debug > 0)
+ printf
+ ("DEBUG write_metadata: Data differs. Writing metadata file\n");
+
+ /* Copy char string for comparison on the next call */
+ strcpy(metadata_title, title_field);
+ //printf("metadata_title: %s\n", metadata_title);
+ //printf("title_field: %s\n", title_field);
+
+ /* Check for $HOME/.dsctl/metadata */
+ metadataloc = strcat(getenv("HOME"), "/metadata");
+
+ if ((metadatafile = fopen(metadataloc, "w")) != NULL)
+ {
+ fprintf(metadatafile, "ALBUM=%s\n", album_field);
+ fprintf(metadatafile, "ARTIST=%s\n", artist_field);
+ fprintf(metadatafile, "TITLE=%s\n", title_field);
+ }
+ else /* unable to write a metadata file. if they don't have write permission
on their home directory or something else weird */
- {
- metadataloc = strcat("write to ", metadataloc);
- perror(metadataloc);
- }
-
- reset_env_var("HOME", "/metadata");
- fclose(metadatafile);
+ {
+ metadataloc = strcat("write to ", metadataloc);
+ perror(metadataloc);
+ }
- /* Find ices pid and send Ices SIGUSR1 so Ices rereads metadata*/
- if (ices_pid != 0)
- kill(ices_pid, SIGUSR1);
+ reset_env_var("HOME", "/metadata");
+ fclose(metadatafile);
- return;
+ /* Find ices pid and send Ices SIGUSR1 so Ices rereads metadata */
+ if (ices_pid != 0)
+ kill(ices_pid, SIGUSR1);
+
+ return;
+ }
}
+
/***********************************************************************
* Reset Enviroment Variables
***********************************************************************/
int reset_env_var(char *env_var, char *remove)
{
-
+
char *ptr;
ptr = strstr(getenv(env_var), remove);
Modified: src/utils.h
===================================================================
--- src/utils.h 2007-07-21 03:04:49 UTC (rev 128)
+++ src/utils.h 2007-07-21 06:12:17 UTC (rev 129)
@@ -28,6 +28,10 @@
extern int debug;
extern int ices_pid;
+extern char metadata_album[1024];
+extern char metadata_artist[1024];
+extern char metadata_title[1024];
+
/*
* Uniden's customized Ascii Characters
* If not caught or redefined may bork the console!
@@ -110,7 +114,7 @@
//int do_parse(char *unparsed, char **parsed);
int parse_fields(char *unparsed, char **parsed);
int replace_chars(char *bcd_chars, char *common_chars);
-void write_metadata(char *artist_field, char *title_field);
+void write_metadata(char *album_field, char *artist_field, char *title_field);
int reset_env_var(char *env_var, char *remove);
#endif /* _UTILS_H_ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|