root/src/testcid.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. my_write_sample
  2. main

   1 #include "private/ftdm_core.h"
   2 
   3 ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data);
   4 
   5 struct helper {
   6         int fd;
   7         int wrote;
   8 };
   9 
  10 ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data)
  11 {
  12         struct helper *foo = (struct helper *) user_data;
  13         size_t len;
  14         len = write(foo->fd, buf, buflen * 2);
  15         if (!len) return FTDM_FAIL;
  16         foo->wrote += buflen * 2;
  17         return FTDM_SUCCESS;
  18 }
  19 
  20 int main(int argc, char *argv[])
  21 {
  22         struct ftdm_fsk_modulator fsk_trans;
  23         ftdm_fsk_data_state_t fsk_data = {0};
  24         int fd = -1;
  25         int16_t buf[160] = {0};
  26         ssize_t len = 0;
  27         size_t type, mlen;
  28         char *sp;
  29         char str[128] = "";
  30         char fbuf[256];
  31         uint8_t databuf[1024] = "";
  32         struct helper foo = {0};
  33         //      int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300;
  34         char time_str[9];
  35         struct tm tm;
  36         time_t now;
  37         
  38         if (argc < 2) {
  39                 int x;
  40                 const char *url = "sip:cool@rad.com";
  41 
  42                 if ((fd = open("tone.raw", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
  43                         fprintf(stderr, "File Error! [%s]\n", strerror(errno));
  44                         exit(-1);
  45                 }
  46 
  47 
  48                 time(&now);
  49                 localtime_r(&now, &tm);
  50                 strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm);
  51 
  52                 ftdm_fsk_data_init(&fsk_data, databuf, sizeof(databuf));
  53 #if 1
  54                 
  55                 ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str));
  56                 //ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8);
  57                 ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7);
  58                 ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10);
  59                 for(x = 0; x < 0; x++)
  60                         ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url));
  61 #else
  62                 ftdm_fsk_data_add_sdmf(&fsk_data, "06061234", "0");
  63                 //ftdm_fsk_data_add_sdmf(&state, "06061234", "5551212");
  64 #endif
  65                 ftdm_fsk_data_add_checksum(&fsk_data);
  66 
  67                 foo.fd = fd;
  68 
  69 
  70                 ftdm_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo);
  71                 ftdm_fsk_modulator_send_all((&fsk_trans));
  72 
  73                 printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes);
  74 
  75                 if (fd > -1) {
  76                         close (fd);
  77                 }
  78 
  79                 return 0;
  80         }
  81 
  82         if (ftdm_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) {
  83                 printf("wtf\n");
  84                 return 0;
  85         }
  86 
  87         if ((fd = open(argv[1], O_RDONLY)) < 0) {
  88                 fprintf(stderr, "cant open file %s\n", argv[1]);
  89                 exit (-1);
  90         }
  91 
  92         while((len = read(fd, buf, sizeof(buf))) > 0) {
  93                 if (ftdm_fsk_demod_feed(&fsk_data, buf, len / 2) != FTDM_SUCCESS) {
  94                         break;
  95                 }
  96         }
  97 
  98         while(ftdm_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == FTDM_SUCCESS) {
  99                 ftdm_copy_string(str, sp, mlen+1);
 100                 *(str+mlen) = '\0';
 101                 ftdm_clean_string(str);
 102                 printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, ftdm_mdmf_type2str(type), (unsigned)mlen, str);
 103         }
 104 
 105         ftdm_fsk_demod_destroy(&fsk_data);
 106 
 107         close(fd);
 108         return 0;
 109 }

/* [<][>][^][v][top][bottom][index][help] */