--[[
ģƣͨ
ģ鹦ܣԺ
ģ޸ʱ䣺2017.02.23
]]

module(...,package.seeall)
require"cc"
require"audio"
require"common"

--[[
print
  ӡӿڣļедӡtestǰ׺
  
ֵ
]]
local function print(...)
	_G.print("test",...)
end

--[[
connected
  ͨѽϢ
  
ֵ
]]
local function connected()
	print("connected")
	--5󲥷TTSԶˣײ֧TTS
	sys.timer_start(audio.play,5000,0,"TTSCC",common.binstohexs(common.gb2312toucs2("ͨвTTS")),audiocore.VOL7)
	--50֮ͨ
	sys.timer_start(cc.hangup,50000,"AUTO_DISCONNECT")
end

--[[
disconnected
  ͨѽϢ
  
		paraͨԭֵ
			  "LOCAL_HANG_UP"ûcc.hangupӿڹҶͨ
			  "CALL_FAILED"ûcc.dialӿںatִʧ
			  "NO CARRIER"Ӧ
			  "BUSY"ռ
			  "NO ANSWER"Ӧ
ֵ
]]
local function disconnected(para)
	print("disconnected:"..(para or "nil"))
	sys.timer_stop(cc.hangup,"AUTO_DISCONNECT")
end

--[[
incoming
  硱Ϣ
  
		numstringͣ
ֵ
]]
local function incoming(num)
	print("incoming:"..num)
	--
	cc.accept()
end

--[[
ready
  ͨģ׼Ϣ
  
ֵ
]]
local function ready()
	print("ready")
	--10086
	cc.dial("10086")
end

--[[
dtmfdetected
  ͨյԷDTMFϢ
  
		dtmfstringͣյDTMFַ
ֵ
]]
local function dtmfdetected(dtmf)
	print("dtmfdetected",dtmf)
end

--[[
alerting
  йյԷ塱Ϣ
  
ֵ
]]
local function alerting()
	print("alerting")
end

--עϢûص
cc.regcb("READY",ready,"INCOMING",incoming,"CONNECTED",connected,"DISCONNECTED",disconnected,"DTMF",dtmfdetected,"ALERTING",alerting)
