📄 c_manage.c
字号:
/************主要完成各种资源的管理和处理************/
#pragma CODE DEBUG SYMBOLS OBJECTEXTEND
#include <reg51.h>
#include <absacc.h>
#include "Const.h"
#include "Extern.h"
extern delay_time(unsigned int subtime);//延时子函数
extern read_warn();//读取告警信息
extern interface_init();//接口初始化
extern sig_req(unsigned char para1, unsigned char para2);//发送线路信令
void connect(unsigned char in_slot,unsigned char o_slot)//用于连接两个时隙
{
unsigned char i1;
XBYTE[CON_REG] = 0xb4;
i1 = o_slot >> 5;
o_slot = (o_slot & 0x1f);
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x18 + i1;
XBYTE[PORT_B] = 0;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 1;
XBYTE[PORT_B] = 0x20 + o_slot;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x10 + i1 ;
XBYTE[PORT_B] = 0x00;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = in_slot;
XBYTE[PORT_B] = 0x20 + o_slot;
XBYTE[CON_REG] = 0xb4;
}
no_sound(unsigned char o_slot)//无音处理
{
unsigned char i1;
XBYTE[CON_REG] = 0xb4;
i1 = o_slot >> 5;
o_slot = o_slot & 0x1f;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x10 + i1;
XBYTE[PORT_B] = 0;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x55;
XBYTE[PORT_B] = 0x20 + o_slot;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x18 + i1;
XBYTE[PORT_B] = 0;
XBYTE[CON_REG] = 0x0c;
XBYTE[WR_8980] = 0x05;
XBYTE[PORT_B] = 0x20 + o_slot;
}
i_net()//初始化为无音
{
unsigned int i;
for(i = 0; i < 256;i++)
{
no_sound(i);
}
}
user_e1_init()//数字中继用户初始化
{
unsigned char xdata temp,user_num;
user_monitor_num = IDLE;
user_test_num = IDLE;
for(user_num = 0;user_num < TRK_MAX;user_num++)
{
user_e1[user_num].type = CALL_CLOSE;
user_e1[user_num].mfc = IDLE;
user_e1[user_num].dtmf = IDLE;
user_e1[user_num].opp_num = IDLE;
user_e1[user_num].wait = 0;
user_e1[user_num].false = 0;
user_e1[user_num].backward_signal = RSD_IDLE;//闭塞、主叫挂机
user_e1[user_num].forward_signal = 0xbb;
user_e1[user_num].flag = LEISURE;
user_e1[user_num].back_flag = 0;
user_e1[user_num].user_age = IDLE;
user_e1[user_num].opp_age = IDLE;
user_e1[user_num].user_sex = MAN;
user_e1[user_num].opp_sex = WOMAN;
for(temp = 0;temp < 32;temp++)
{
user_e1[user_num].telephone[temp] = IDLE;
}
for(temp = 0;temp < 6;temp++)
{
user_e1[user_num].password[temp] = IDLE;
user_e1[user_num].number_chat[temp] = IDLE;
}
user_e1[user_num].first_select = IDLE;
user_e1[user_num].user_index = 0;
user_e1[user_num].a6_flag = 0;
user_e1[user_num].kd = 0;
user_e1[user_num].lc_state = 0;
user_e1[user_num].mfc_state = IDLE;
user_e1[user_num].user_state = IDLE;
user_e1[user_num].sub_status = IDLE;
user_e1[user_num].mfc_count = 0;
user_e1[user_num].delay = 0;
user_e1[user_num].chat_num = IDLE;
user_e1[user_num].chat_type = IDLE;
user_e1[user_num].user_mix = IDLE;
user_e1[user_num].user_num = IDLE;
user_e1[user_num].yukong_num = IDLE;
}
}
void init_back()//初始化回呼用户
{
unsigned char xdata temp,i;
for(temp = 0;temp < 64;temp++)
{
chat_number[temp].user_num = IDLE;
chat_number[temp].user_sex = IDLE;
chat_number[temp].user_age = IDLE;
chat_number[temp].call_flag = 0;
for(i = 0;i < 6;i++)
{
chat_number[temp].telephone[i] = IDLE;
}
}
for(temp = 0;temp < 128;temp++)
{
user_back[temp].user_num = IDLE;
user_back[temp].user_sex = IDLE;
user_back[temp].user_age = IDLE;
user_back[temp].opp_sex = IDLE;
user_back[temp].opp_age = IDLE;
user_back[temp].chat_type = IDLE;
for(i = 0;i < 6;i++)
{
user_back[temp].telephone[i] = IDLE;
user_back[temp].password[i] = IDLE;
}
user_back[temp].call_flag = 0;
}
}
void command(unsigned char x,unsigned char y,unsigned char z,unsigned char i,unsigned char j,unsigned char k,unsigned char l,unsigned char m,
unsigned char n,unsigned char o,unsigned char p,unsigned char q,unsigned char r,unsigned char s,unsigned char t,unsigned char u)
{ //往后台发的命令字
unsigned int xdata word_tmp;
EA=0;
word_tmp = sdbt;
sdbuf[word_tmp] = x;
word_tmp++;
sdbuf[word_tmp] = y;
word_tmp++;
sdbuf[word_tmp] = z;
word_tmp++;
sdbuf[word_tmp] = i;
word_tmp++;
sdbuf[word_tmp] = j;
word_tmp++;
sdbuf[word_tmp] = k;
word_tmp++;
sdbuf[word_tmp] = l;
word_tmp++;
sdbuf[word_tmp] = m;
word_tmp++;
sdbuf[word_tmp] = n;
word_tmp++;
sdbuf[word_tmp] = o;
word_tmp++;
sdbuf[word_tmp] = p;
word_tmp++;
sdbuf[word_tmp] = q;
word_tmp++;
sdbuf[word_tmp] = r;
word_tmp++;
sdbuf[word_tmp] = s;
word_tmp++;
sdbuf[word_tmp] = t;
word_tmp++;
sdbuf[word_tmp] = u;
word_tmp++;
sdbt = (sdbt + 16) & 0x7f8;
EA = 1;
}
void yukong_init()//语控资源初始化
{
unsigned char xdata temp;
yukong_count = 0;
for(temp = 0;temp < AUDIO_MAX;temp++)
{
yukong_resource[temp].flag = IDLE;
yukong_resource[temp].slot = IDLE;
yukong_resource[temp].addr = IDLE;
yukong_resource[temp].user = IDLE;
yukong_resource[temp].count = 0;
yukong_resource[temp].state = AUDIO_NO;
}
}
unsigned char yukong_req(unsigned char user_num)//语控资源申请
{
unsigned char xdata temp;
if(yukong_count == 0)
{
return(IDLE);
}
else
{
for(temp = 0;temp < AUDIO_MAX;temp++)
{
if(yukong_resource[temp].flag == LEISURE)
{
yukong_count--;
command(8,2,yukong_count,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE);
user_e1[user_num].yukong_num = temp;
yukong_resource[temp].flag = OCCUPY;
yukong_resource[temp].user = user_num;
yukong_resource[temp].count = 0;
yukong_resource[temp].state = AUDIO_NO;
connect(user_num,yukong_resource[temp].slot);
return(temp);
}
}
}
}
void yukong_release(unsigned char yukong_num)//语控资源释放
{
if((yukong_num != IDLE) && (yukong_resource[yukong_num].flag == OCCUPY))
{
yukong_count++;
command(8,2,yukong_count,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE);
user_e1[yukong_resource[yukong_num].user].yukong_num = IDLE;
yukong_resource[yukong_num].flag = LEISURE;
yukong_resource[yukong_num].user = IDLE;
yukong_resource[yukong_num].count = 0;
yukong_resource[yukong_num].state = AUDIO_NO;
no_sound(yukong_resource[yukong_num].slot);
}
}
void chat_common_init()//公共聊天室初始化
{
unsigned char xdata i,temp;
chat_common_count = 8;
for(i = 0;i < GRP_MAX;i++)
{
chat_common_resource[i].flag = LEISURE;
chat_common_resource[i].user_count = 0;
chat_common_resource[i].type = IDLE;
for(temp = 0;temp < 4;temp++)
{
chat_common_resource[i].mt8924_slot[temp] = 0xe0 + i * 4 + temp;
chat_common_resource[i].mt8924_user[temp] = IDLE;
XBYTE[M_NET1] = 0x10 | (i + 1);
XBYTE[M_NET1] = i * 4 + temp;
XBYTE[M_NET2] = tone_set;
}
for(temp = 0;temp < 16;temp++)
{
chat_common_resource[i].user_num[temp] = IDLE;
}
for(temp = 0;temp < 6;temp++)
{
chat_common_resource[i].password[temp] = IDLE;
}
}
}
unsigned char chat_common_req(unsigned char user_num,unsigned char password[6],unsigned char chat_type)//申请公共聊天室资源
{
unsigned char xdata temp,i;
if(chat_common_count == 0)//如果没有资源
{
return(IDLE);
}
else//还有空闲资源
{
for(temp = 0;temp < GRP_MAX;temp++)
{
if(chat_common_resource[temp].flag == LEISURE)//寻找空闲资源
{
//往后台回应聊天室状态
command(6,0,0,temp,chat_type,password[0],password[1],password[2],password[3],password[4],password[5],IDLE,IDLE,IDLE,IDLE,IDLE);
//王后台回应用户状态
command(7,0,0,temp,chat_type,((password[0] << 4) & 0xf0) + (password[1] & 0x0f),((password[2] << 4) & 0xf0) + (password[3] & 0x0f),((password[4] << 4) & 0xf0) + (password[5] & 0x0f),user_e1[user_num].telephone[0],user_e1[user_num].telephone[1],user_e1[user_num].telephone[2],user_e1[user_num].telephone[3],user_e1[user_num].telephone[4],user_e1[user_num].telephone[5],IDLE,IDLE);
chat_common_count--;//剩余资源减1
chat_common_resource[temp].flag = OCCUPY;//置占用标志
chat_common_resource[temp].type = chat_type;//置聊天室类型
chat_common_resource[temp].user_num[chat_common_resource[temp].user_count] = user_num;//置用户号
user_e1[user_num].user_num = chat_common_resource[temp].user_count;//置用户对应聊天室中的号码号
user_e1[user_num].chat_num = 0x80 + temp;//置用户聊天室号
chat_common_resource[temp].user_count++;//聊天室中的人数加1
for(i = 0;i < 6;i++)
{
chat_common_resource[temp].password[i] = password[i];//置聊天室密码
}
chat_common_resource[temp].mt8924_user[0] = user_num;//MT8924混合时隙占用标志
user_e1[user_num].user_mix = chat_common_resource[temp].mt8924_slot[0];
for(i = 1;i < 4;i++)
{
chat_common_resource[temp].mt8924_user[i] = IDLE;
}
return(temp);
}
}
}
}
void huiying_houtai()
{
unsigned char xdata temp_i,temp_j,user_num,password[6];
for(temp_i = 0;temp_i < GRP_MAX;temp_i++)
{
if(chat_common_resource[temp_i].flag == OCCUPY)
{
//往后台回应聊天室状态
for(temp_j = 0;temp_j < 6;temp_j++)
{
password[temp_j] = chat_common_resource[temp_i].password[temp_j];
}
command(6,0,0,temp_i,chat_common_resource[temp_i].type,password[0],password[1],password[2],password[3],password[4],password[5],IDLE,IDLE,IDLE,IDLE,IDLE);
for(temp_j = 0;temp_j < 16;temp_j++)
{
user_num = chat_common_resource[temp_i].user_num[temp_j];
if(user_num != IDLE)
{
command(7,0,0,temp_i,chat_common_resource[temp_i].type,((password[0] << 4) & 0xf0) + (password[1] & 0x0f),((password[2] << 4) & 0xf0) + (password[3] & 0x0f),((password[4] << 4) & 0xf0) + (password[5] & 0x0f),user_e1[user_num].telephone[0],user_e1[user_num].telephone[1],user_e1[user_num].telephone[2],user_e1[user_num].telephone[3],user_e1[user_num].telephone[4],user_e1[user_num].telephone[5],IDLE,IDLE);
}
}
}
}
for(temp_i = 0;temp_i < 64;temp_i++)
{
if(chat_private_resource[temp_i].flag == OCCUPY)
{
command(6,1,0,temp_i,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE,IDLE);
for(temp_j = 0;temp_j < 2;temp_j++)
{
user_num = chat_private_resource[temp_i].user_num[temp_j];
if(user_num != IDLE)
{
command(7,1,user_e1[user_num].user_sex,user_e1[user_num].user_age,user_e1[user_num].opp_sex,user_e1[user_num].opp_age,0,temp_i,user_e1[user_num].telephone[0],user_e1[user_num].telephone[1],user_e1[user_num].telephone[2],user_e1[user_num].telephone[3],user_e1[user_num].telephone[4],user_e1[user_num].telephone[5],IDLE,IDLE);
}
}
}
}
}
unsigned char judge_password(unsigned char chat_num,unsigned char password[6])//判断密码是否相符
{
unsigned char xdata temp;
for(temp = 0;temp < 6;temp++)
{
if(password[temp] != chat_common_resource[chat_num].password[temp])
{
return(0);//不符
}
}
return(1);//相符
}
unsigned char ask_common(unsigned char chat_type,unsigned char password[6])//查询是否有此公共聊天室
{
unsigned char xdata i;
if(chat_type != PASSWORD)//如果为非密码聊天室
{
for(i = 0;i < GRP_MAX;i++)
{
if(chat_common_resource[i].flag == OCCUPY)//聊天室是否分配
{
if((chat_common_resource[i].type == chat_type) && (chat_common_resource[i].user_count < 16))//是否是此类聊天室
{
return(i);
}
}
}
return(IDLE);
}
else
{
for(i = 0;i < GRP_MAX;i++)
{
if(chat_common_resource[i].flag == OCCUPY)//聊天室是否分配
{
if((chat_common_resource[i].type == chat_type) && (judge_password(i,password)))//是否是密码聊天室
{
if(chat_common_resource[i].user_count < 16)//是则判断有没有满
{
return(i);
}
else
{
return(8);
}
}
}
}
return(IDLE);
}
}
unsigned char assign_common_num(unsigned char chat_num)//分配聊天室中用户的号码
{
unsigned char xdata temp;
for(temp = 0;temp < 16;temp++)
{
if(chat_common_resource[chat_num].user_num[temp] == IDLE)//聊天室中此号码是否分配
{
return(temp);
}
}
}
unsigned char mt8924_req(unsigned char user_num,unsigned char chat_num,unsigned char type)//将该用户加入语音混合
{
unsigned char xdata temp,i;
if(type == 0)//非语控下混合时隙申请
{
for(temp = 0;temp < 4;temp++)
{
if(chat_common_resource[chat_num].mt8924_user[temp] == IDLE)//寻找空闲时隙
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -