int opus_header_to_packet(const OpusHeader *h, unsigned char *packet, int len) { Packet p; unsigned char ch; p.data = packet; p.maxlen = len; p.pos = 0; if (len<19)return 0; if (!write_chars(&p, (const unsigned char*)"OpusHead", 8)) return 0; /* Version is 1 */ ch = 1; if (!write_chars(&p, &ch, 1)) return 0; ch = h->channels; if (!write_chars(&p, &ch, 1)) return 0; if (!write_uint16(&p, h->preskip)) return 0; if (!write_uint32(&p, h->input_sample_rate)) return 0; if (!write_uint16(&p, h->gain)) return 0; ch = h->channel_mapping; if (!write_chars(&p, &ch, 1)) return 0; if (h->channel_mapping != 0) { ch = h->nb_streams; if (!write_chars(&p, &ch, 1)) return 0; ch = h->nb_coupled; if (!write_chars(&p, &ch, 1)) return 0; /* Multi-stream support */ for (int i=0;i<h->channels;i++) { if (!write_chars(&p, &h->stream_map[i], 1)) return 0; } } return p.pos; }
void * AP_CCCI_RX (void* lpParameter) { char buf_ack [BUF_SIZE] = {0}; char buf_log [BUF_SIZE] = {0}; int rd_len=0, wr_len=0; LOGD(TAG "Enter AP_CCCI_RX()\n"); for (;;) { #if 0 #ifdef MTK_ENABLE_MD2 if(g_mdFlag==1) rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); if(g_mdFlag==2) rd_len = read_ack (g_fd_atcmdmd2, buf_ack, BUF_SIZE); #else rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); #endif #endif if(g_mdFlag == 1) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "1")) { #ifndef EVDO_DT_SUPPORT rd_len = read_ack(g_fd_atcmdmd_dt, buf_ack, BUF_SIZE); #endif } else { if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } } #else if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } #endif } else if(g_mdFlag == 2) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "2")) { #ifndef EVDO_DT_SUPPORT rd_len = read_ack(g_fd_atcmdmd_dt, buf_ack, BUF_SIZE); #endif } else { if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } } #else if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } #endif } if (rd_len>0) { memcpy (buf_log, buf_ack, rd_len); buf_log[rd_len] = '\0'; LOGD(TAG "AP_CCCI_RX: %s, rd_len = %d\n", buf_log, rd_len); ACK_Pre_Process(buf_log); wr_len = write_chars (g_fd_uart, buf_ack, rd_len); if (wr_len != rd_len) LOGE(TAG "AP_CCCI_RX: wr_len != rd_len\n"); } } //pthread_exit(NULL); }
void * AP_UART_USB_RX (void* lpParameter) { char buf_cmd [BUF_SIZE] = {0}; int len; int wr_len; char result[64] = {0}; LOGD(TAG "Enter AP_UART_USB_RX()\n"); cmd_handler_init (); for (;;) { len = read_a_line(g_fd_uart, buf_cmd, BUF_SIZE); if (len>0) { buf_cmd[len] = '\0'; LOGD(TAG "AP_UART_USB_RX Command: %s, Len: %d\n" ,buf_cmd, len); AT_Pre_Process (buf_cmd); LOGD("buf_cmd:%s\n", buf_cmd); #if 0 #ifdef MTK_DT_SUPPORT if(g_mdFlag==1) send_at (g_fd_atcmd, buf_cmd); if(g_mdFlag==2) send_at (g_fd_atcmdmd2, buf_cmd); #else send_at (g_fd_atcmd, buf_cmd); #endif #endif CMD_OWENR_ENUM owner = rmmi_cmd_processor(buf_cmd, result); LOGD(TAG "result:%s\n", result); if(owner == CMD_OWENR_AP) { wr_len = write_chars (g_fd_uart, result, strlen(result)); if (wr_len != strlen(result)) LOGE(TAG "AP_CCCI_RX: wr_len != rd_len\n"); } else { if(g_mdFlag == 1) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "1")) { #ifndef EVDO_DT_SUPPORT send_at(g_fd_atcmdmd_dt, buf_cmd); #endif } else{ if(is_support_modem(1)){ send_at(g_fd_atcmd, buf_cmd); }else if(is_support_modem(2)){ send_at(g_fd_atcmdmd2, buf_cmd); } } #else if(is_support_modem(1)){ send_at(g_fd_atcmd, buf_cmd); }else if(is_support_modem(2)){ send_at(g_fd_atcmdmd2, buf_cmd); } #endif } else if(g_mdFlag == 2) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "2")) { #ifndef EVDO_DT_SUPPORT send_at(g_fd_atcmdmd_dt, buf_cmd); #endif }else{ if(is_support_modem(1)){ send_at(g_fd_atcmd, buf_cmd); }else if(is_support_modem(2)){ send_at(g_fd_atcmdmd2, buf_cmd); } } #else if(is_support_modem(1)){ send_at(g_fd_atcmd, buf_cmd); }else if(is_support_modem(2)){ send_at(g_fd_atcmdmd2, buf_cmd); } #endif } } } } //pthread_exit (NULL); }
int AT_Pre_Process (char *buf_cmd) { #if 0 if(!strcmp(buf_cmd, SLEEPMODE)){ LOGD(TAG "SLEEP_MODE"); pret = setSleepMode(fd_atcmd); if(!strcmp(pret, STR_OK)) write_chars(fd_uart, "OK\r",3); else write_chars(fd_uart, "ERROR\r",6); } else if(!strcmp(buf_cmd, EMER_CALL)){ LOGD(TAG "EMERCALL"); pret = dial112(fd_atcmd); if(!strcmp(pret, STR_OK)) write_chars(fd_uart, "OK\r",3); else write_chars(fd_uart, "ERROR\r",6); } else if(!strcmp(buf_cmd, GET_SN)) { LOGD(TAG "GET_SN"); pret = getSN(buf_ret, sizeof(buf_ret), fd_atcmd); if(!strcmp(pret, STR_OK)) write_chars(fd_uart, buf_ret, sizeof(buf_ret)); else write_chars(fd_uart, "ERROR\r",6); } else if(strstr(buf_cmd, SET_SN) || !strcmp(buf_cmd, ATH)) { LOGD(TAG "%s\n", buf_cmd); // Add '\r\n' tp command buf. buf_cmd[len] = '\r'; buf_cmd[len+1] = '\n'; buf_cmd[len+2] = '\0'; pret = at_command_set(buf_cmd, fd_atcmd); if(!strcmp(pret, STR_OK)) write_chars(fd_uart, "OK\r",3); else write_chars(fd_uart, "ERROR\r",6); } else if(!strcmp(buf_cmd, AT) || !strcmp(buf_cmd, ATE0)) { // AT and ATE0 are commands for test command between // ATE tool and target. Just return "OK\r" when receive. LOGD(TAG "%s\n", buf_cmd); write_chars(fd_uart, "OK\r",3); } else{ LOGD(TAG "Unsupported command\n"); write_chars(fd_uart, "ERROR\r",6); } #endif #ifdef MTK_DT_SUPPORT if(!strcmp(buf_cmd, "AT+SWITCH")) { LOGD(TAG "AT+SWITCH"); if(g_mdFlag==1) g_mdFlag=2; else if(g_mdFlag==2) g_mdFlag=1; else LOGD(TAG "Unsupported MD Flag\n"); } #endif return 0; }
int write_creature_basic(FILE *fp, int index, creature *crt) { int i; printf("Writing creature %s\n", crt->name ); /* begin of creature data */ write_int(fp, index); /* creature # */ write_chars(fp, crt->name, sizeof(crt->name)); write_chars(fp, crt->description, sizeof(crt->description)); write_chars(fp, crt->talk, sizeof(crt->talk)); write_chars(fp, crt->password, sizeof(crt->password)); for (i = 0; i != 3; i++) write_chars(fp, crt->key[i], sizeof(crt->key[i])); write_short(fp, crt->fd); write_char(fp, crt->level); write_char(fp, crt->type); write_char(fp, crt->class); write_char(fp, crt->race); write_char(fp, crt->numwander); write_short(fp, crt->alignment); write_char(fp, crt->strength); write_char(fp, crt->dexterity); write_char(fp, crt->constitution); write_char(fp, crt->intelligence); write_char(fp, crt->piety); write_short(fp, crt->hpmax); write_short(fp, crt->hpcur); write_short(fp, crt->mpmax); write_short(fp, crt->mpcur); write_char(fp, crt->armor); write_char(fp, crt->thaco); write_long(fp, crt->experience); write_long(fp, crt->gold); write_short(fp, crt->ndice); write_short(fp, crt->sdice); write_short(fp, crt->pdice); write_short(fp, crt->special); for (i=0; i != 6; i++) write_long(fp, crt->proficiency[i]); for (i=0; i < 8; i++) write_long(fp, crt->realm[i]); write_chars(fp, crt->spells, sizeof(crt->spells)); write_chars(fp, crt->flags, sizeof(crt->flags)); write_chars(fp, crt->quests, sizeof(crt->quests)); write_char(fp, crt->questnum); for (i=0; i != 10; i++) write_short(fp, crt->carry[i]); write_short(fp, crt->rom_num); for (i=0; i != 10; i++) { write_char(fp, crt->daily[i].max); write_char(fp, crt->daily[i].cur); write_long(fp, crt->daily[i].ltime); } for (i=0; i < 45; i++) write_lasttime(fp, crt->lasttime[i]); write_long(fp,crt->bank_balance); write_chars(fp,crt->title, sizeof(crt->title)); for(i=0; i != 5; i++) write_short(fp, crt->misc_stats[i]); write_short(fp,crt->clanindex); write_long(fp,crt->clanexp); write_char(fp,crt->guildtype); write_long(fp,crt->guildexp); write_short(fp,crt->special1); write_long(fp,crt->special2); /* end of creature data */ return(0); }
int write_room(FILE *fp, room *rom) { int i; char perm_only; short cnt; xtag *xp; ctag *cp; otag *op; struct exit_ *exit; perm_only = 0; /* all objects, monsters */ printf("Writing room number %d\n", rom->rom_num ); /* begin of room data */ fprintf(fp, "#begrom\n"); write_short(fp, rom->rom_num); write_chars(fp, rom->name, sizeof(rom->name)); write_char(fp, rom->lolevel); write_char(fp, rom->hilevel); write_short(fp, rom->special); write_char(fp, rom->trap); write_short(fp, rom->trapexit); write_chars(fp, rom->track, sizeof(rom->track)); write_chars(fp, rom->flags, sizeof(rom->flags)); for (i = 0; i != 10; i++) write_short(fp, rom->random[i]); write_char(fp, rom->traffic); for (i = 0; i != 10; i++) write_lasttime(fp, rom->perm_mon[i]); for (i = 0; i != 10; i++) write_lasttime(fp, rom->perm_obj[i]); write_long(fp, rom->beenhere); write_long(fp, rom->established); write_short(fp, rom->death_rom); write_char(fp,rom->zone_type); write_char(fp,rom->zone_subtype); write_char(fp,rom->env_type); write_short(fp,rom->special1); write_long(fp,rom->special2); /* short description */ if(rom->short_desc) { write_short(fp, (short)(strlen(rom->short_desc)+1)); /* # of characters to read in */ write_chars(fp, rom->short_desc, strlen(rom->short_desc)+1); } else { write_short(fp, 0); } /* long description */ if(rom->long_desc) { write_short(fp, (short)(strlen(rom->long_desc)+1)); /* # of characters to read in */ write_chars(fp, rom->long_desc, strlen(rom->long_desc)+1); } else { write_short(fp, 0); } /* object description */ if(rom->obj_desc) { write_short(fp, (short)(strlen(rom->obj_desc)+1)); /* # of characters to read in */ write_chars(fp, rom->obj_desc, strlen(rom->obj_desc)+1); } else { write_short(fp, 0); } /* exits */ cnt = count_ext(rom); write_int(fp, cnt); xp = rom->first_ext; while(xp) { exit = xp->ext; /* write exit structure */ write_chars(fp, exit->name, sizeof(exit->name)); write_short(fp, exit->room); write_chars(fp, exit->flags, sizeof(exit->flags)); write_lasttime(fp, exit->ltime); write_lasttime(fp, exit->random); write_chars(fp, exit->rand_mesg[0], sizeof(exit->rand_mesg[0])); write_chars(fp, exit->rand_mesg[1], sizeof(exit->rand_mesg[1])); write_char(fp, exit->key); /* end exit structure */ xp = xp->next_tag; } /* monsters */ cnt = count_mon(rom, perm_only); write_int(fp, cnt); cp = rom->first_mon; while(cp) { if(!perm_only || (perm_only && cp->crt->flags[0] & 1)) write_creature(fp, -1, cp->crt); cp = cp->next_tag; } /* objects */ cnt = count_ite(rom, perm_only); write_int(fp, cnt); op = rom->first_obj; while(op) { if(!perm_only || (perm_only && op->obj->flags[0] & 1)) write_object(fp, -1, op->obj); op = op->next_tag; } /* end of room data */ fprintf(fp, "#endrom\n"); return(0); }