-- CONFIDENTIAL AND PROPRIETARY. © 2006 NetStreams,Inc. This software code -- contains proprietary trade secrets of NetStreams and is also protected by -- U.S. and other copyright laws and applicable international treaties. Any -- use, compilation, modification, distribution, reproduction, performance, -- display, or disclosure ("Use") of this software code is subject to the -- terms and conditions of your written agreement with NetStreams. If you -- do not have such an agreement, then any Use of this material is strictly -- prohibited. Unauthorized Use of this software code, or any portion of it, -- will result in civil liability and/or criminal penalties. By modifying -- this software code, you agree to assign any and all intellectual property -- rights related in any way to your modification to NetStreams pursuant to -- your written agreement with NetStreams. -- -- $Version: 1 $ -- Denon_DBP-2012UDCI.lua -- driver for Denon_DBP 2012 UDCI BD player -- Seema Nikam 06/2011- 07/2011 -- -- Commands: -- sent to device are in the following format: -- STX: 02h denotes the Start of Text -- CC: Command Code -- PC0,PC1,....PCn: Parameter codes (defined for each command) -- ETX: 03h denotes the End of Text -- BCC: Block Check Character (Checksum) -- {e.g -- ...... -- <02><20><00><00><00><00><00><00><03><--><--> -- BCC= 23 (Exclude STX and add from CC to ETX) -- BCCL= 2 is 32 (in Hex) -- BCCH= 3 is 33 (in Hex) -- } -- {BCCH, BCCL} -- Answer: -- STX: 02h denotes the Start of Text -- RC: Reply Code (i.e. CC=Command Code) -- AC: Answer Code -- PC0,PC1,....PCn: Parameter Codes -- ETX: 03h denotes the End of Text -- BCC: Block Check Character (Checksum) -- This script reads data from the associated serial -- port and sends them to device as ascii commands -- local NSTimer = require("NSTimer") local NSStream = require("NSStream") local NSAsciiCommand = require("NSAsciiCommand") -- uncomment the next line for any hope of debugging startup issues --setDebug('all', 'on') setDebug('error', 'on') setDebug('warning', 'on') --setDebug('command','on') --setDebug('data','on') --setDebug('verbose', 'on') --setDebug('stream', 'on') debug("verbose","Driver loading") local STX = "%02" -- start of Text local ETX = "%03" -- end of Text local NAK = "%15" -- error check NG local busy = false local currentCommand = "" local newInputBuffer = "" local statusInputBuffer = "" cmdCode = nil -- Command Code ansCode = nil -- Answer Code rplCode = nil -- Reply Code inSetup = false -- checks whether device entered in Setup inDisp = false -- checks whether device entered in Display -------------Other variables------------ nakFlag = false; Stream = nil InputBuffer = "" nLastCommand = -1 -- previously sent command nLastCommandCount = 0 -- how many times it was sent DeviceModel = " DBP-2012UDCI " -- returned model name defaults = { port = "comm://default;baud=9600;parity=even;bits=8;stop=1", } Constants = { PortDefault = "comm://default;baud=9600;parity=even;bits=8;stop=1", -- Time BETWEEN the start of command transmission AND the end of the command transmission PollInterval = 100, -- Time BETWEEN the completion of command AND the start of the answer back ReplyTimeout = 5000, -- When no answer from device, restransmit command after 6 sec, -- This unit cannot receive any commands for about 5 Sec after the Power switch is turned on PowerOnRetries = 5000, PowerOnTimeout = 5000, -- 3xh: status of entire system -- 4xh: status of each action mode DeviceStatus = { PWR_ON = "20", PWR_OFF= "21", -- Status of the entire system StandBy = "30", DiscLoading = "31", TrayOpening = "33", TrayClosing = "34", -- Status of each action mode NoDisc = "41", Stop = "42", Play = "43", Pause = "44", ScanPlay = "45", SlowSearchPlay = "46", Setup = "47", ResumeStop = "49", Menu = "4A", HomeMenu = "4B", }, } BDCommands = { PowerOn = STX.."%20%00%00%00%00%00"..ETX.."%32%33", PowerStdBy = STX.."%21%00%00%00%00%00"..ETX.."%32%34", -- Request System Status: returns state of player StatusInfo = STX .."%30%00%00%00%00%00"..ETX.."%33%33", -- CPU version number VersionInfo = STX.."%31%00%00%00%00%00"..ETX.."%33%34", Play = STX.."%40%00%00%00%00%00"..ETX.."%34%33", Stop = STX.."%41%00%00%00%00%00"..ETX.."%34%34", Pause = STX.."%42%00%00%00%00%00"..ETX.."%34%35", -- *Following commands are valid only if STATUS DATA(StatusCodes) is Play (E) or Pause (F) -- Skip: selects previous and next track Next = STX.."%43%2B%00%00%00%00"..ETX.."%37%31", Prev = STX.."%43%2D%00%00%00%00"..ETX.."%37%33", -- Slow/Search FwdScan = STX.."%44%2B%00%00%00%00"..ETX.."%37%32", RevScan = STX.."%44%2D%00%00%00%00"..ETX.."%37%34", -- Setup: *Valid only when the status is Stop(B) Setup = STX.."%45%00%00%00%00%00"..ETX.."%34%38", -- Menu Commands: TopMenu = STX.."%46%00%00%00%00%00"..ETX.."%34%39", Menu = STX.."%47%00%00%00%00%00"..ETX.."%34%41", Return = STX.."%48%00%00%00%00%00"..ETX.."%34%42", -- Audio: Selects dialog in the BD/DVD disc Audio = { Primary = STX.."%49%2B%2B%00%00%00"..ETX.."%41%32", Secondary = STX.."%49%2B%2D%00%00%00"..ETX.."%41%34", }, Angle = STX.."%4B%2B%00%00%00%00"..ETX.."%37%39", Cursor = { LT = STX.."%4D%31%00%00%00%00"..ETX.."%38%31", UP = STX.."%4D%32%00%00%00%00"..ETX.."%38%32", RT = STX.."%4D%33%00%00%00%00"..ETX.."%38%33", DN = STX.."%4D%34%00%00%00%00"..ETX.."%38%34", }, Enter = STX.."%4E%00%00%00%00%00"..ETX.."%35%31", Display = STX.."%68%00%00%00%00%00"..ETX.."%36%42", AnswerCodes = { Cmd_OK = "20", Cmd_Invalid = "30", }, DiscTypes = { DVD_VIDEO = "31", DVD_AUDIO = "32", Reserved = "33", CD_DA = "34", CD_ROM = "35", unknown = "36", SACD = "37", DVD_VR= "38", BDMV = "39", BDAV = "3A", AVCHD = "3B", Web_stream = "3C", DLNA = "3D", AVCREC = "3E", External_memory = "3F", }, } CurrentStatus = { nAlbumNo = -1, -- album (folder) for MP3, title for DVD, nothing for regular CDs nTrackNo = -1, -- file in folder for MP3, chapter for DVD, track for regular CDs nFirstTrack = -1, -- note that for MP3 and DVD type discs, these are folders/albums and not tracks nLastTrack = -1, DiscType = "", AudioFormat = "", AudioChannel = "", Dialog = "", SubTitle = "", Angle = "", Status = "", GroupOrTitle = "", TrackOrChapter="", TimeMode = "", ElapsedTime = "", strDevState = Constants.DeviceStatus[Constants.DeviceStatus.PWR_ON], -- current device state } ---------------------------------------Functions-------------------------------------- -- Queue implementation to process given commands in order Queue = {} function Queue.new() return {first = 0, last = -1} end function Queue.push(list, value) local last = list.last + 1 list.last = last list[last] = value end function Queue.pop(list) local first = list.first if first > list.last then return nil else local value = list[first] list[first] = nil list.first = first + 1 return value end end local list = Queue.new() start = function() debug("verbose", "Start: > ") Initialize() collectgarbage("collect") debug("Memory in use after driver load: "..collectgarbage("count").."K") debug.enableWatchdog() end stop = function() debug("verbose","Driver stopped") end -- function Intialize() -- initialize the driver, create socket connection Initialize = function() debug("verbose","Initialize: 239: Denon_DBP-2012UDCI driver loading") -- Check to see if the COM port has been overridden by Dealer Setup if (config == nil) then config = {} end -- If COM port doesn't exist, setup the default -- As in config_current.xml, config.port in not nil and it takes "none" as a parity there, -- force it to take the connection string specified in PortDefault --[[ if (config.port == nil) then config.port = Constants.PortDefault end ]]-- config.port = Constants.PortDefault -- Open the serial port and ready it for writing Stream = NSStream.create(config.port) if (Stream == nil) then debug("error", "Unable to open stream \""..config.port.."\"") return end -- the stream does not open immediately, so delay all operations that need to read or write the stream Stream.onOpen = function() debug("verbose","Initialize: Stream is opened") -- power on the device: No need to handle it as -- assumed case is that device is always on -- create our timer to read incoming messages and process the information debug("verbose","Initialize: Called OnTimer") createTimer(Constants.PollInterval, OnTimer) end debug("verbose","Initialize: Denon_DBP-2012UDCI driver loaded") end -- function OnTimer(timer) -- timer handler to poll the stream for incoming messages OnTimer = function(timer) debug("verbose","OnTimer>") local val = "" if(busy == false) then debug("verbose","OnTimer: Popping command") val = Queue.pop(list) end if(val ~= nil) then busy = true debug("verbose","OnTimer: Sending command") SendCommand(val) end return Constants.PollInterval end -- function WriteMessage(message, throttle) -- Decode string and write to the stream (serial port) WriteMessage= function(message) local msg = message debug("verbose", "WriteMessage: Sending on port ", msg) -- call decodeString() to convert %XX to actual ASCII values local xmitMessage = decodeString(msg) for i = 1, xmitMessage:len() do Stream:write(xmitMessage:sub(i, i)) end end -- Hexify = function(data, prefix, postfix) -- format a data string as hex values; default prefix is "0x", default postfix is " " Hexify = function(data, prefix, postfix) prefix = prefix or "0x" postfix = postfix or " " data = data or "" return string.format(string.rep(prefix.."%02X"..postfix, #data), string.byte(data, 1, -1)) end -- function SendCommand(message) -- write command to the port when perticular conditions are satisfied SendCommand = function(message) local timeStart = 0 debug("verbose","SendCommand>") if(#message==0) then busy=false debug("error","SendCommand: Received empty message as command") return end debug("verbose","SendCommand: Current command: ", message) cmdCode = string.sub(message,5,6) debug("verbose","SendCommand: Current command code: ", cmdCode) -- To check if device is going to Setup mode if(cmdCode == "45") then inSetup = false end -- To check if device is going to Display if(cmdCode == "68") then inDisp = false end -- local sendCount = 0 local found = false while (sendCount < 5) do -- Require to check message in case of multiple command send and NAK received if(#message==0) then busy=false debug("error","Command can not be resent now") break end -- Write message WriteMessage(message) timeStart = os.uptime() debug("verbose","SendCommand: waiting time: ",timeStart) InputBuffer = "" while(Constants.ReplyTimeout > (os.uptime() - timeStart) and nakFlag == false) do AccumulateInput() if(#InputBuffer>0) then --debug("verbose","SendCommand: After AccumulateInput: received buffer is: ",InputBuffer) --debug("verbose","SendCommand: Calling ProcessBuffer") ProcessBuffer() --debug("verbose","SendCommand: Calling ProcessBufferForStatusInfo") ProcessBufferForStatusInfo() else debug("error","SendCommand: Empty InputBuffer") end --if(#InputBuffer>0) -- if(#statusInputBuffer>0) then debug("verbose","SendCommand: Received statusInputBuffer is : ",statusInputBuffer) ProcessStatusReply() else debug("warning","SendCommand: Received empty statusInputBuffer") end --if(#statusInputBuffer>0) -- if(#newInputBuffer>0) then debug("verbose","SendCommand: Received newInputBuffer is : ",newInputBuffer) local rplCode = string.format("%02X",string.byte(string.sub(newInputBuffer,2,2))) if(rplCode == cmdCode) then debug("verbose","SendCommand: rplCode & cmdCode matched so calling ProcessCmdReply") ProcessCmdReply() busy = false break end else debug("warning","SendCommand: Received empty newInputBuffer") end --if(#newInputBuffer>0) end --inner while sendCount = sendCount+1 if(busy==false)then break end end --outer while end -- function AccumulateInput() -- Collect all the information from the stream AccumulateInput = function () local response = nil local nakPos = false local nSTXPos = 0 local cmdPos = 0 debug("verbose","AccumulateInput>") -- clear buffer is everything is there if(InputBuffer) then InputBuffer = "" end os.sleep(80) -- Take all available data from a stream while(Stream:available() >0 ) do response = Stream:read() end debug("verbose","AccumulateInput: read response from device is : ", response) --debug("verbose","AccumulateInput: Hexify response from device : ", Hexify(response)) -- if(response) then nakFlag = false local length = response:len() for i=1, length do if(string.byte(response,i,i)== 21) then nakPos= true else nakPos= false end end --debug("verbose","AccumulateInput: This is nakPos: ",nakPos) -- if(nakPos==true) then nakFlag = true debug("verbose","AccumulateInput: nakFlag is true") debug("error", "AccumulateInput: NAK received in message") else nakFlag = false InputBuffer = response debug("verbose","AccumulateInput: nakFlag is False") debug("verbose","AccumulateInput: Received response without NAK") debug("verbose","AccumulateInput: Hexify response from device : ", Hexify(InputBuffer)) end else InputBuffer = "" --debug("verbose","AccumulateInput: Recieved no response from device") end end -- function ProcessBuffer() -- Process an accumulated buffer to seperate out command reply coming from a device ProcessBuffer = function() newInputBuffer = "" debug("verbose","ProcessBuffer: Received InputBuffer is: ",InputBuffer) --debug("verbose","ProcessBuffer: Hexified InputBuffer: ",Hexify(InputBuffer)) local len = InputBuffer:len() local start = -1 for i=1, len do if(string.byte(InputBuffer,i,i)== 2) then if(string.byte(InputBuffer,i+1,i+1) ~= 48) then start = i end if(string.byte(InputBuffer,i+1,i+1) == 48) then if(start ~= -1) then newInputBuffer = string.sub(InputBuffer,start,i-1) for j=i, len do if(string.byte(InputBuffer, j, j)== 3) then start = j+3 i = j+3 end end end end end -- if (string.byte(InputBuffer,i,i)== 3 and start ~= -1) then newInputBuffer =newInputBuffer..string.sub(InputBuffer,start,i) break end end --debug("verbose","ProcessBuffer: newInputBuffer is: ",newInputBuffer) --debug("verbose","ProcessBuffer: hexify: newInputBuffer is: ",Hexify(newInputBuffer)) end -- function ProcessBufferForStatusInfo() -- Process an accumulated buffer to seperate out statusInfo ProcessBufferForStatusInfo = function() statusInputBuffer = "" debug("verbose","ProcessBufferForStatusInfo: Received InputBuffer is: ",InputBuffer) local len = InputBuffer:len() local start = -1 for i=1, len do if(string.byte(InputBuffer,i,i)== 2) then if(string.byte(InputBuffer,i+1,i+1)== 48) then start = i end -- if(string.byte(InputBuffer,i+1,i+1)~= 48) then if(start ~= -1) then statusInputBuffer = string.sub(InputBuffer,start,i-1) for j=i, len do if(string.byte(InputBuffer, j, j)== 3) then start = j+3 i = j+3 end end end end end -- if (string.byte(InputBuffer,i,i)== 3 and start ~= -1) then statusInputBuffer =statusInputBuffer..string.sub(InputBuffer,start,i) break end end --debug("verbose","ProcessBufferForStatusInfo: statusInputBuffer is: ",statusInputBuffer) --debug("verbose","ProcessBufferForStatusInfo: hexify: statusInputBuffer is: ",Hexify(statusInputBuffer)) end -- function ProcessCmdReply() -- Process cmdReply received from ProcessBuffer ProcessCmdReply = function() local codePos = false local hexInputBuffer = 0 debug("verbose","ProcessCmdReply>") debug("verbose","ProcessCmdReply: newInputBuffer: ", newInputBuffer) -- codePos= string.find(newInputBuffer,cmdCode,1,true) --debug("verbose","ProcessCmdReply: Found same cmdCode in response which is rplCode: At position: ",codePos) rplCode = string.format("%02X",string.byte(string.sub(newInputBuffer,2,2))) ansCode = string.format("%02X",string.byte(string.sub(newInputBuffer,3,3))) debug("verbose","ProcessCmdReply: answer code: ",ansCode) debug("verbose","ProcessCmdReply: rplCode is: ", rplCode) debug("verbose","ProcessCmdReply: cmdCode is: ", cmdCode) -- hexInputBuffer = Hexify(newInputBuffer) --debug("verbose","ProcessCmdReply: This is hexify newInputBuffer: ", hexInputBuffer) -- if(#newInputBuffer > 0) then if(ansCode == "30") then debug("error","Answer code returned for sent command is invalid") debug("error","This command can not be processed at this time") return elseif (ansCode == "20") then debug("verbose","ProcessCmdReply: answer code returned for sent command is ok") else debug("error","ProcessCmdReply: answer code returned is unknown") end if(rplCode == cmdCode) then debug("verbose","ProcessCmdReply: rplCode and cmdCode match: call functions") CallFunctions() end end end -- function ProcessStatusReply() -- Process statusReply received from ProcessBufferForStatusInfo ProcessStatusReply = function() local codePos = false local hexInputBuffer = 0 -- debug("verbose","ProcessStatusReply>") debug("verbose","ProcessStatusReply: statusInputBuffer: ", statusInputBuffer) -- codePos= string.find(statusInputBuffer,cmdCode,1,true) --debug("verbose","ProcessStatusReply: Found same cmdCode in response which is rplCode: At position: ",codePos) rplCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,2,2))) ansCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,3,3))) debug("verbose","ProcessStatusReply: answer code: ",ansCode) -- hexInputBuffer = Hexify(statusInputBuffer) --debug("verbose","ProcessStatusReply: This is hexify input buffer: ", statusInputBuffer) -- if(#statusInputBuffer > 0) then if(ansCode == "30") then debug("error","ProcessStatusReply: answer code recieved in status reply is invalid") return elseif (ansCode == "20") then debug("verbose","ProcessStatusReply: answer code recieved in status reply is ok") else debug("error","ProcessStatusReply: answer code recieved in status reply is unknown") end debug("verbose","ProcessStatusReply: rplCode in received status is: ", rplCode) if(rplCode == "30") then debug("verbose","ProcessStatusReply: rplCode denotes its a StatusInfo so call systemStatusHandler") systemStatusHandler() end end end -- function CallFunctions() -- Handle necessary actions when perticular rplCode is received CallFunctions = function() debug("verbose", "CallFunctions>") debug("verbose","CallFunctions: rplCode is: ",rplCode) if(rplCode == "40") then debug("verbose","CallFunctions: Play command successful: ") CurrentStatus.strDevState = Constants.DeviceStatus.Play debug("verbose","CallFunctions: Device status after Play Command: ", (CurrentStatus.strDevState)) -- elseif(rplCode == "41") then debug("verbose","CallFunctions: Stop command successful: ") CurrentStatus.strDevState = Constants.DeviceStatus.Stop debug("verbose","CallFunctions: Device status after Stop Command: ", (CurrentStatus.strDevState)) -- elseif(rplCode == "42") then debug("verbose","CallFunctions: Pause command successful: ") CurrentStatus.strDevState = Constants.DeviceStatus.Pause debug("verbose","CallFunctions: Device status after Pause Command: ", (CurrentStatus.strDevState)) -- elseif(rplCode == "43") then skipHandler() -- elseif(rplCode == "45") then inSetup = true elseif(rplCode == "68") then inDisp = true end end -- function systemStatusHandler() -- Seperate out the bytes in received statusInputBuffer for later use systemStatusHandler = function() debug("verbose","systemStatusHandler: status information received is: ", statusInputBuffer) local discTypeCode = 0 local audioFormatCode = 0 local audioChannelCode = 0 local dialogCode = 0 local subtitleCode = 0 local angleCode = 0 local statusCode = 0 local playModeCode = 0 local GrpOrTitle = 0 local TrackOrChapter = 0 local TimeMode = 0 local ElapsedTime = 0 discTypeCode= string.format("%02X",string.byte(string.sub(statusInputBuffer,4,4))) debug("data","This is Disc Type: ", discTypeCode) audioFormatCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,5,5))) audioChannelCode= string.format("%02X",string.byte(string.sub(statusInputBuffer,6,6))) debug("data","Audio Format: "..audioFormatCode.." Audio Channel: "..audioChannelCode) dialogCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,7,7))) subtitleCode= string.format("%02X",string.byte(string.sub(statusInputBuffer,8,8))) debug("data","Dialog: "..dialogCode.." Subtitle: "..subtitleCode) angleCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,9,9))) statusCode= string.format("%02X",string.byte(string.sub(statusInputBuffer,10,10))) playModeCode = string.format("%02X",string.byte(string.sub(statusInputBuffer,11,11))) debug("data","Angle: "..angleCode.." Status: "..statusCode.." Play Mode: "..playModeCode) local GT1 = string.format("%02X",string.byte(string.sub(statusInputBuffer,12,12))) local GT2 = string.format("%02X",string.byte(string.sub(statusInputBuffer,13,13))) local GT3 = string.format("%02X",string.byte(string.sub(statusInputBuffer,14,14))) GrpOrTitle= (GT1*100) + (GT2*10) + GT3 debug("data","Group or Title: "..GrpOrTitle) local TC1 = string.format("%02X",string.byte(string.sub(statusInputBuffer,15,15))) local TC2 = string.format("%02X",string.byte(string.sub(statusInputBuffer,16,16))) local TC3 = string.format("%02X",string.byte(string.sub(statusInputBuffer,17,17))) local TC4 = string.format("%02X",string.byte(string.sub(statusInputBuffer,18,18))) TrackOrChapter = (TC1*1000) + (TC2*100) + (TC3*10) + TC4 debug("data","Track Or Chapter: "..TrackOrChapter) TimeMode= string.format("%02X",string.byte(string.sub(statusInputBuffer,19,19))) debug("data","Time Mode: "..TimeMode) local ETHR1 = string.format("%02X",string.byte(string.sub(statusInputBuffer,20,20))) local ETHR2 = string.format("%02X",string.byte(string.sub(statusInputBuffer,21,21))) local ETMIN1 = string.format("%02X",string.byte(string.sub(statusInputBuffer,22,22))) local ETMIN2 = string.format("%02X",string.byte(string.sub(statusInputBuffer,23,23))) local ETSEC1 = string.format("%02X",string.byte(string.sub(statusInputBuffer,24,24))) local ETSEC2 = string.format("%02X",string.byte(string.sub(statusInputBuffer,25,25))) ElapsedTime = (ETHR1 +ETHR2)..":"..(ETMIN1 + ETMIN2)..":"..(ETSEC1 + ETSEC2) debug("data","Elapsed Time: "..ElapsedTime) end skipHandler = function() debug("verbose","Recieved skip command reply is: ",newInputBuffer) local SkipGT1 = string.format("%02X",string.byte(string.sub(newInputBuffer,4,4))) local SkipGT2 = string.format("%02X",string.byte(string.sub(newInputBuffer,5,5))) local SkipGT3 = string.format("%02X",string.byte(string.sub(newInputBuffer,6,6))) GrpOrTitle= (SkipGT1*100) + (SkipGT2*10) + SkipGT3 debug("data","Group or Title: "..GrpOrTitle) local SkipTC1 = string.format("%02X",string.byte(string.sub(newInputBuffer,7,7))) local SkipTC2 = string.format("%02X",string.byte(string.sub(newInputBuffer,8,8))) local SkipTC3 = string.format("%02X",string.byte(string.sub(newInputBuffer,9,9))) local SkipTC4 = string.format("%02X",string.byte(string.sub(newInputBuffer,10,10))) TrackOrChapter = (SkipTC1*1000) + (SkipTC2*100) + (SkipTC3*10) + SkipTC4 debug("data","Track Or Chapter: "..TrackOrChapter) end ---------------------------------------------------------------------------------------------------------------- -- function handle_(command) -- simple # handlers -- No need to handle Power on and off commands: after the discussion with Dan -- Assumption: Device is always on --handle_active = function ( command ) --[[ local active = command.params[1]:upper() debug("command", "handle_active ", active) if( active == "ON" ) then SendCommand(BDCommands.PowerOn) elseif ( active == "OFF" ) then SendCommand(BDCommands.PowerStdBy) else debug( "error", "Unknown Parameter : ",active) return end end ]]-- handle_play = function(command) Queue.push(list,BDCommands.Play) end handle_stop = function(command) Queue.push(list,BDCommands.Stop) end handle_pause = function(command) Queue.push(list,BDCommands.Pause) end handle_prev = function(command) debug("verbose","Check for current device status",CurrentStatus.strDevState) if(CurrentStatus.strDevState == Constants.DeviceStatus.Play) or (CurrentStatus.strDevState == Constants.DeviceStatus.Pause) then Queue.push(list,BDCommands.Prev) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_next = function(command) debug("verbose","Check for current device status",CurrentStatus.strDevState) if(CurrentStatus.strDevState == Constants.DeviceStatus.Play) or (CurrentStatus.strDevState == Constants.DeviceStatus.Pause) then Queue.push(list,BDCommands.Next) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_rev = function(command) debug("verbose","Check for current device status",CurrentStatus.strDevState) if(CurrentStatus.strDevState == Constants.DeviceStatus.Play) or (CurrentStatus.strDevState == Constants.DeviceStatus.Pause) then Queue.push(list,BDCommands.RevScan) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_fwd = function(command) debug("verbose","Check for current device status",CurrentStatus.strDevState) if(CurrentStatus.strDevState == Constants.DeviceStatus.Play) or (CurrentStatus.strDevState == Constants.DeviceStatus.Pause) then Queue.push(list,BDCommands.FwdScan) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_setup = function(command) -- Command is only valid when Status Mode is STOP or Setup debug("verbose","Check for current device status",CurrentStatus.strDevState) if(CurrentStatus.strDevState == Constants.DeviceStatus.Stop or inSetup == true) then Queue.push(list,BDCommands.Setup) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_display = function(command) Queue.push(list,BDCommands.Display) end handle_topmenu = function(command) Queue.push(list,BDCommands.TopMenu) end handle_menu = function(command) Queue.push(list,BDCommands.Menu) end handle_return = function(command) -- Command is only valid when Setup Menu or Display Menu is displayed if(inSetup == true or inDisp==true) then Queue.push(list,BDCommands.Return) else debug("error","Command can not be processed in this device state OR") default_handle_command(command) end end handle_angle = function(command) Queue.push(list,BDCommands.Angle) end --Cursor: 16,17,18,19 handle_nav = function(command) -- param: UP, DN, LT, RT local dir = command.params[1]:upper() debug("command","Cursor: dir: ", dir) if(dir == "UP") then Queue.push(list,BDCommands.Cursor.UP) elseif(dir == "DN") then Queue.push(list,BDCommands.Cursor.DN) elseif(dir == "RT") then Queue.push(list,BDCommands.Cursor.RT) elseif(dir == "LT") then Queue.push(list,BDCommands.Cursor.LT) else default_handle_command(command) end end handle_enter = function(command) Queue.push(list,BDCommands.Enter) end handle_select = function(command) handle_enter() -- there is no separate "select" button end ---------------------------------------------------------- ------------------ Not implemented ------------------- ---------------------------------------------------------- handle_key = function(command) -- param: 0-9, TEN_PLUS, HUNDRED_PLUS, F1, F2 if (BDCommands.NumKey[command.params[1]:upper()]) then SendCommand(BDCommands.NumKey[command.params[1]:upper()]) else default_handle_command(command) end end --if command received is unhandled by a program default_handle_command = function(command) debug("error", "Unhandled command received: ", command) end -- function handle_user(command) -- handler for #USER nCommand, nParam1, ... -- send a raw command directly to the device -- command may be given as number or name (see Constants.BDCommands), params can be numbers or strings handle_user = function(command) debug("verbose", "#USER command received: ", command.params) if (not tonumber(command.params[1])) then for name, cmd in pairs(BDCommands) do if (type(cmd) == "number" and string.upper(name) == string.upper(command.params[1])) then command.params[1] = cmd break end end end if (tonumber(command.params[1])) then SendCommand(command.params, false) end end