Esempio n. 1
0
// This function handles extended codes (EXT1 + code), from the extended sets
// G2 (20-7F) => Mostly unmapped, except for a few characters.
// G3 (A0-FF) => A0 is the CC symbol, everything else reserved for future expansion in EIA708-B
// C2 (00-1F) => Reserved for future extended misc. control and captions command codes
//! @todo This code is completely untested due to lack of samples. Just following specs!
// Returns number of used bytes, usually 1 (since EXT1 is not counted).
int handle_708_extended_char (cc708_service_decoder *decoder, unsigned char *data, int data_length)
{
  int used;
  unsigned char c=0x20; // Default to space
  unsigned char code=data[0];
  if (/* data[i]>=0x00 && */ code<=0x1F) // Comment to silence warning
  {
    used=handle_708_C2 (decoder, data, data_length);
  }
  // Group G2 - Extended Miscellaneous Characters
  else if (code>=0x20 && code<=0x7F)
  {
    c=get_internal_from_G2 (code);
    used=1;
    process_character (decoder, c);
  }
  // Group C3
  else if (code>=0x80 && code<=0x9F)
  {
    used=handle_708_C3 (decoder, data, data_length);
    //! @todo Something
  }
  // Group G3
  else
  {
    c=get_internal_from_G3 (code);
    used=1;
    process_character (decoder, c);
  }
  return used;
}
Esempio n. 2
0
// G0 - Code Set - ASCII printable characters
int handle_708_G0 (cc708_service_decoder *decoder, unsigned char *data, int data_length)
{
  //! @todo Substitution of the music note character for the ASCII DEL character
  unsigned char c=get_internal_from_G0 (data[0]);
  process_character (decoder, c);
  return 1;
}
Esempio n. 3
0
File: 708.cpp Progetto: MrMdR/julapy
int handle_708_G1 (cc708_service_decoder *decoder, unsigned char *data, int data_length)
{
    printf ("G1: [%02X]  (%c)\n",data[0],data[0]);
    unsigned char c=get_internal_from_G1 (data[0]);
    process_character (decoder, c);
    return 1;
}
Esempio n. 4
0
File: 708.cpp Progetto: MrMdR/julapy
void handle_708_extended_char (cc708_service_decoder *decoder, unsigned char code)
{
    printf ("In handle_708_extended_char: [%c]\n",code);
    unsigned char c=0x20; // Default to space
    if ((code>=0x20 && code<=0x3F) || 
        (code>=0x80 && code<=0x9F))
        c=get_internal_from_G2 (code);
    else if (code==0xa0)
        c=get_internal_from_G3 (code);
    process_character (decoder, c);
}
Esempio n. 5
0
//this function can be run in other thread for TCP/IP to enable do ... loops  (usefull for websites)
void thread_func (void * param){
    thread_read_index=0;
    if (debug) printf("Enter thread %d,%d,%d.\n", thread_running,thread_read_index,thread_write_index);
    while (thread_running){
        char c = thread_data[thread_read_index];
        //if(debug) printf("Process char %c %d\n", c, thread_read_index);
        process_character(c);
        thread_read_index++;
        if (thread_read_index>=thread_write_index) break; //exit loop if we are at the end of the file
    }
    thread_running=0;
    if (debug) printf("Exit thread.\n");
    pthread_exit(NULL); //exit the tread
}
Esempio n. 6
0
/* process_new_data: [fdwatch thread]
 *  Process new data arriving in the keyboard's fd.
 */
static void process_new_data(void *unused)
{
   _al_event_source_lock(&the_keyboard.parent.es);
   {
      unsigned char buf[128];
      size_t bytes_read;
      unsigned int ch;

      bytes_read = read(the_keyboard.fd, &buf, sizeof(buf));
      for (ch = 0; ch < bytes_read; ch++)
         process_character(buf[ch]);
   }
   _al_event_source_unlock(&the_keyboard.parent.es);

   (void)unused;
}
Esempio n. 7
0
// G1 Code Set - ISO 8859-1 LATIN-1 Character Set
int handle_708_G1 (cc708_service_decoder *decoder, unsigned char *data, int data_length)
{
  unsigned char c=get_internal_from_G1 (data[0]);
  process_character (decoder, c);
  return 1;
}
Esempio n. 8
0
//main routine
int main(int argc, char *argv[]){
    int ret = 0;
	int i;
	int index=0;

	ledstring.device=NULL;
	command_line = NULL;
    named_pipe_file=NULL;
	malloc_command_line(DEFAULT_COMMAND_LINE_SIZE);

    setup_handlers();

    input_file = stdin; //by default we read from console, stdin
    mode = MODE_STDIN;
    
	if (argc>1){
        if (strcmp(argv[1], "-p")==0){ //use a named pipe, creates a file (by default in /dev/ws281x) which you can write commands to: echo "command..." > /dev/ws281x
            if (argc>2){
                named_pipe_file = malloc(strlen(argv[2]+1));
                strcpy(named_pipe_file,argv[2]);
            }else{
                named_pipe_file = malloc(strlen(DEFAULT_DEVICE_FILE)+1);
                strcpy(named_pipe_file, DEFAULT_DEVICE_FILE);
            }
            printf ("Opening %s as named pipe.", named_pipe_file);
            remove(named_pipe_file);
            mkfifo(named_pipe_file,0777);
            chmod(named_pipe_file,0777);
            input_file = fopen(named_pipe_file, "r");
            mode  = MODE_NAMED_PIPE;
        }else if (strcmp(argv[1], "-f")==0){ //read commands / data from text file
            if (argc>2){
                input_file = fopen(argv[2], "r");
                printf("Opening %s.", argv[2]);
            }else{
                printf("Error you must enter a file name after -f option\n");
                exit(1);
            }
            mode = MODE_FILE;
        }else if (strcmp(argv[1], "-tcp")==0){ //open up tcp ip port and read commands from there
            if (argc>2){
                int port = atoi(argv[2]);
                if (port==0) port=9999;
                printf("Listening on %d.\n", port);
                start_tcpip(port);
            }else{
                printf("You must enter a port after -tcp option\n");
                exit(1);
            }
            mode = MODE_TCP;
        }
	}
	
	if ((mode == MODE_FILE || mode == MODE_NAMED_PIPE) && input_file==NULL){
		perror("Error opening file!");
		exit(1);
	}
	
    int c;
	
	while (exit_program==0) {
        if (mode==MODE_TCP){
            c = 0;
            if (read(active_socket, (void *) & c, 1)<=0) c = EOF; //returns 0 if connection is closed, -1 if no more data available and >0 if data read
        }else{
            c = fgetc (input_file); //doesn't work with tcp
        }
        
	  if (c!=EOF){
        process_character(c);
	  }else{
        //end of file or read error
		switch (mode){
            case MODE_TCP:
                if (!exit_program){
                    tcp_wait_connection(); //go back to wait for connection
                }
                break;
            case MODE_NAMED_PIPE:
            case MODE_STDIN:
                usleep(10000);
                break;
            case MODE_FILE:
                exit_program=1;
                break;
        }
	  }
    }
	
    if (mode==MODE_TCP){
        shutdown(active_socket,SHUT_RDWR);
        shutdown(sockfd,SHUT_RDWR);
        close(active_socket);
        close(sockfd);
    }else{
        fclose(input_file);
    }
        
    if (named_pipe_file!=NULL){
        remove(named_pipe_file);
        free(named_pipe_file);
    }
	free(command_line);
    if (thread_data!=NULL) free(thread_data);
    if (ledstring.device!=NULL) ws2811_fini(&ledstring);

    return ret;
}