Making a Crestron Module for HTTP API Control
#1
I'd like to preface this here by saying I'm probably in over my head here and I don't want to waste anyone's time with stupid questions. I have done my best to research this on the forums and on the wiki so be gentle Wink

My first question (of many I'm sure) is regarding the "Action" command. I noticed in the wiki that is says "Be careful of this one since it runs the action on the webserver thread and depending on the action could lock the GUI thread." What actions should I try to stay away from? I noticed while fooling around and sending a few of the action commands that I did seem to lose control of the interface for some time. Is this what they are referring to?

I am currently using the "Action" command only for navigation (up down left right pageup pagedown select). Is there a better way to do this? I also did this with the "SendKey" command pressing a key mapped in Keymap.xml, but this seemed like a roundabout way to do it.

Any and all advice is welcomed!

EDIT: Looks like I found my first one. Action(11) Which is ACTION_SHOW_INFO seems to lock up the interface and the only way to get it back working is to close the info using my computer keyboard. So I guess I fully understand the problem now. I take it when I find these problems my best bet is to work around it with a "SendKey" command?

Also, is this type of thread better suited to the General forum? It seems a little basic compared to what most of you are working on.
Reply
#2
Is this what you're after?

Control.Message(id,message,[windowid])

sends a given message to a control in a given window (or active window if omitted). Messages can be movedown, moveup, pagedown, pageup, click.
Reply
#3
To use that command I would assign it to a keyboard press in Keymap.xml? I'm trying to do as much as I can sending commands directly using HTTP, however I'm not sure that is the best way. I'm doing it that way so I'm not constantly editing two things (My Crestron module and the Keymap.xml file) when I make changes.

Second question. Are there any commands I can run that will let me jump straight to a page (TV Shows, Movies etc.) I know I can do this thru the Keymap.xml file, just wondering if there was a direct way to do it.

EDIT - Got it :
Code:
/xbmcCmds/xbmcHttp?command=ExecBuiltIn(ActivateWindow(videolibrary,tvshowtitles))
That ExecBuiltIn was the piece of the puzzle I was missing!
Reply
#4
Any way I could get a look at the crestron module, I'm just getting my feet wet with modules.
Reply
#5
Please be aware that the current HTTP API will be going away eventually.

See this thread:

http://forum.xbmc.org/showthread.php?tid=68263
I am an expert at acting like an expert ---- WC Fields.

XBMC Web Control Interface - https://github.com/mthiels/webinterface.xrc
Reply
#6
I developed a full Crestron interface.
If you interested I can share it.
Reply
#7
tzya Wrote:I developed a full Crestron interface.
If you interested I can share it.

I'm interested in this module. Can you send it please? Best regards!
Reply
#8
casentis Wrote:I'm interested in this module. Can you send it please? Best regards!

sent you the code in private message
Reply
#9
i'd love a copy of the module. would be great appreciated
Reply
#10
Guys as requested how to integrate to Crestron:

This was tested with Xbmc for Windows and XbmcLive (Ubunutu)



First set Xbmc Settings:
1. Set Xbmc System--Settings--Network--Services--"Allow control via Http"
2. Set the Port to high number (I use 48880)
3. Username and password not used.
4. Set "AllowPrograms on other systems ...

Crestron Simpl+ :

1. Parameter Fields:
STRING_PARAMETER XbmcIp[20], XbmcPort[5], PcMacAddress[17];

2. Services / Sockets:

TCP_CLIENT XbmcTcp[2048];
UDP_SOCKET FbUdp[1024], WolSck[10], EventServerUpd[255];

TcpClient "XbmcTcp" is for the HttpApi
UdpSocket "FbUdp" is for receiving "Xbmc UPD Broadcast"
UdpSocket "WolSck" is for "MagicPacket" to wakeup / turnon the Xbmc host pc
UdpSocket "EventServerUpd" is for Navigation commands thru Event Server


3. "Main" function:

//*******************************************************************************************/
Function Main()
{
WaitForInitializationComplete();

MacId = ""; //Convert MacId to Packet
ValCount = 0;
For(i = 1 to 17)
{
If(i mod 3 <> 0)
{
ValCount = ValCount + 1;
Val[ValCount] = Byte(PcMacAddress,i);
If(Val[ValCount] > 96) Val[ValCount] = Val[ValCount] - 87;
Else
{
If(Val[ValCount] > 64) Val[ValCount] = Val[ValCount] - 55;
Else Val[ValCount] = Val[ValCount] - 48;
}
}
}

For(i = 1 to 11 Step 2)
{
MacId = MacId + Chr((Val[i]*16) + Val[i+1]);
}

WolPacket = "\xFF\xFF\xFF\xFF\xFF\xFF";

For(i = 1 to 16) WolPacket = WolPacket + MacId;

//Startup Sockets
UdpPort = Atoi(XbmcPort)+1;
Makestring(Temp, "SetBroadcast(130;%u)", UdpPort);
Call Connect(Temp, 2);
Status = SocketUDP_Enable(FbUdp, XbmcIp, UdpPort);
Status = SocketUDP_Enable(EventServerUpd, XbmcIp, 9777);
}


4. Http Connect Function:
//*******************************************************************************************/
FUNCTION Connect(String SendInfo, Integer CmdSeq)
{
INTEGER i;
STRING Sbuffer[1024];

// Print("Connect= CurrentSckStatus %u SendInfo %s ,%u\n", CurrentSckStatus, SendInfo, CmdSeq);

CommBusy = 1;
Wait(200, CommBusyWait) { CommBusy = 0; }

CommandToSend = SendInfo;
CurrCmdSeq = CmdSeq;
If(CurrentSckStatus <> 2)
{
SOCKETDISCONNECTCLIENT(XbmcTcp);
i = 0;
SOCKETCONNECTCLIENT(XbmcTcp, XbmcIp, Atoi(XbmcPort), 0);
Do{ Delay(2); i = i + 1; } Until(CurrentSckStatus = 2 || i>100);
}
MAKESTRING(Sbuffer,"GET /xbmcCmds/xbmcHttp?command=%s\x0D\x0A\x0D\x0A", CommandToSend);
If(Enable) SOCKETSEND(XbmcTcp, Sbuffer);
// Print("CommandToSend = %s\n", CommandToSend);

Wait(200, XbmcCloseConnection) { SOCKETDISCONNECTCLIENT(XbmcTcp); CommBusy = 0; BusyTcp = 0;}

}

//*******************************************************************************************/
SOCKETRECEIVE XbmcTcp
{
STRING Sbuffer[16392], CurrInfo[40][40], Fifo[1][10000], UdpTemp[1024];
INTEGER RcvLength, PrevByte, i, j, k, l, Ind[2];

// Print("RcvAction\n");
If(BusyTcp) Terminateevent;
BusyTcp = 1;

IF(len(XbmcTcp.SocketRxBuf) = 0) { BusyTcp = 0; Terminateevent; }
Do { Delay(2); i=i+1; } Until(i>50 || Find("</html>", Right(XbmcTcp.SocketRxBuf, 20)) > 0);

Sbuffer = XbmcTcp.SocketRxBuf;
i=0; j=0; Ind[0] = 1;
ClearBuffer(XbmcTcp.SocketRxBuf);

While(Ind[0])
{
Ind[1] = Find("<li>", Sbuffer, Ind[0]);
If(Ind[1])
{
Ind[2] = Find(":", Sbuffer, Ind[1]);
If(Ind[2])
{
Ind[0] = Find("<", Sbuffer, Ind[2]);
If(Ind[0])
{
CurrInfo[j] = Mid(Sbuffer, Ind[1]+4, (Ind[2]-Ind[1]-4));
If(Byte(Sbuffer, Ind[0]+1) = 47) l=Ind[0]-Ind[2]-1; Else l=Ind[0]-Ind[2]-2;
MakeString(Info[j], "%s", Mid(Sbuffer, Ind[2]+1, l));
j=j+1;
Delay(1);
}
}
Else Ind[0] = 0;
}
Else Ind[0] = 0;
}

CommBusy = 0;
BusyTcp = 0;

//For(i = 1 to 20)
//{
//if(len(Sbuffer)>200) Print("%s\n", Removebylength(200, Sbuffer));
//else i = 20;
//}
//Print("%s\n", Sbuffer);

For(i = 1 to j)
{
If(CurrInfo[i] = "ActiveWindow")
{
ActiveWindow=Atoi(Info[i]);
Print("ActiveWindow = %s\n", Info[i]);
CurrXbmcWindow = ActiveWindow;
If(ActiveWindow = 12005)
{
Switch(CurrType)
{
Case(1): CurrXbmcWindow = 5;
Case(2): CurrXbmcWindow = 6;
Case(3): CurrXbmcWindow = 7;
}
}
}
Else If(CurrInfo[i] = "ControlId")
{
ControlId=Atoi(Info[i]);
Print("ControlId = %s\n", Info[i]);
If(ControlId<>60 && ActiveWindow=10025) VideoNavHighlightFb = 1;
Else If(ControlId=60 && ActiveWindow=10025) VideoNavHighlightFb = 0;
}
Else If(CurrInfo[i] = "PlayStatus") CurrPlay$[1] = Info[i];
Else If(CurrInfo[i] = "Type" && Info[i] <> "Botton") CurrPlay$[2] = Info[i];
Else If(CurrInfo[i] = "Title") CurrPlay$[3] = Info[i];
Else If(CurrInfo[i] = "Genre") CurrPlay$[4] = Info[i];
Else If(CurrInfo[i] = "Studio") CurrPlay$[5] = Info[i];
Else If(CurrInfo[i] = "Director") CurrPlay$[6] = Info[i];
Else If(CurrInfo[i] = "Rating") CurrPlay$[7] = Info[i];
Else If(CurrInfo[i] = "Year") CurrPlay$[8] = Info[i];
Else If(CurrInfo[i] = "Track") CurrPlay$[9] = Info[i];
Else If(CurrInfo[i] = "Album") CurrPlay$[10] = Info[i];
Else If(CurrInfo[i] = "Artist") CurrPlay$[11] = Info[i];
Else If(CurrInfo[i] = "Lyrics")
{
// Print("Lir-%u\n", Len(Info[i]));
SetArray(Fifo, " ");
PrevByte=0; l=0;
For(k = 1 to Len(Info[i]))
{
If(Byte(Info[i],k)<32 || Byte(Info[i],k)>127)
{
If(PrevByte=0)
{
l=l+1; PrevByte=1;
If(Byte(Info[i],k)<32) Setstring("\xFE",l,Fifo[1]);
Else Setstring("'",l,Fifo[1]);
}
}
Else { l=l+1; Setstring(Mid(Info[i],k,1),l,Fifo[1]); PrevByte=0; }
}
Info[i] = Left(Fifo[1],l);
// Print("Lend-%u\n", Len(Info[i]));
LyricsNumOfLines=1;
For(k = 1 to 500)
{
IF(Find("\xFE", Info[i]))
{
Lyrics[LyricsNumOfLines] = Remove("\xFE", Info[i]);
If(len(Lyrics[LyricsNumOfLines])>2)
{
Lyrics[LyricsNumOfLines] = Left(Lyrics[LyricsNumOfLines], Len(Lyrics[LyricsNumOfLines])-1);
LyricsNumOfLines=LyricsNumOfLines+1;
}
}
Else
{
If(len(Info[i])>1)
{
LyricsNumOfLines=LyricsNumOfLines+1; Lyrics[LyricsNumOfLines] = Info[i];
}
k = 500;
}
}
If(LyricsNumOfLines > 2)
{
If(Len(Lyrics[1]) > 0) CurrPlay$[12] = Lyrics[1];
If(Len(Lyrics[2]) > 0) CurrPlay$[13] = Lyrics[2];
If(Len(Lyrics[3]) > 0) CurrPlay$[14] = Lyrics[3];
LyricsIndex = 1;
LyricsXbmcIndex = 1;
}
}
}

SOCKETDISCONNECTCLIENT(XbmcTcp);
CancelWait(XbmcCloseConnection);

Switch(CurrCmdSeq)
{
Case(1): { Call Connect("getGUIStatus", 0); }
Case(2): { Call Connect("SetResponseFormat(WebHeader;False)", 3); }
Case(3): { Call Connect("SetVolume(100)", 4); }
Case(4): { Call Connect("ExecBuiltIn(ActivateWindow(12600))", 5); }
Case(5): { Call Connect("ExecBuiltIn(Action(Stop))", 1); }
}
}
/
/*******************************************************************************************
SOCKETSTATUS XbmcTcp
{
CurrentSckStatus = SOCKETGETSTATUS();
//Print("CurrentSckStatus=%d\n",CurrentSckStatus);
}

//*******************************************************************************************
SOCKETCONNECT XbmcTcp
{
STRING Sbuffer[1024];

ReTimeWait(200, XbmcCloseConnection);

}
Reply
#11
5. Key calls
//*******************************************************************************************/
PUSH Key
{
INTEGER index;
STRING Temp$[255];
SIGNED_INTEGER Status;

If(PcPowerOffWaitFlag) ReTimeWait(300, PcPowerOffWait);
If(CommBusy) Terminateevent;
index = GetLastModifiedArrayIndex();
print("BtnPress=%u\n", index);
Switch(index)
{
Case(1): Call Connect("ExecBuiltIn(Action(Stop))", 0);
Case(2): Call Connect("getGUIStatus", 0);
Case(3): { Call Connect("ExecBuiltIn(Action(Pause))", 0); PlayingSpeed$ = "1x"; }
Case(4):
{
IF(PlaySpeed<1) PlaySpeed=1;
Else PlaySpeed=PlaySpeed*2;
IF(PlaySpeed>32) PlaySpeed=32;
Makestring(Temp$, "SetPlaySpeed(%d)", PlaySpeed);
Makestring(PlayingSpeed$, "%ux", PlaySpeed);
Switch(PlaySpeed)
{
Case(1): TransportIcon=1;
Case(2): TransportIcon=4; Case(4): TransportIcon=5; Case(8): TransportIcon=6; Case(16): TransportIcon=7; Case(32): TransportIcon=8;
Case(-2): TransportIcon=9; Case(-4): TransportIcon=10; Case(-8): TransportIcon=11; Case(-16): TransportIcon=12; Case(-32): TransportIcon=13;
}
Call Connect(Temp$, 0);
}
Case(5):
{
IF(PlaySpeed=0) PlaySpeed=-1;
IF(PlaySpeed=1) PlaySpeed=-1;
IF(PlaySpeed>0) PlaySpeed=1;
Else PlaySpeed=PlaySpeed*2;
IF(PlaySpeed<-32) PlaySpeed=-32;
Makestring(Temp$, "SetPlaySpeed(%d)", PlaySpeed);
Makestring(PlayingSpeed$, "%dx", PlaySpeed);
Switch(PlaySpeed)
{
Case(1): TransportIcon=1;
Case(2): TransportIcon=4; Case(4): TransportIcon=5; Case(8): TransportIcon=6; Case(16): TransportIcon=7; Case(32): TransportIcon=8;
Case(-2): TransportIcon=9; Case(-4): TransportIcon=10; Case(-8): TransportIcon=11; Case(-16): TransportIcon=12; Case(-32): TransportIcon=13;
}
Call Connect(Temp$, 0);
}
Case(6):
{
If(PlayFb) {PlaySpeed=1; Makestring(PlayingSpeed$, "%ux", PlaySpeed); Call Connect("SetPlaySpeed(1)", 0); }
If(PauseFb || StopFb){Call Connect("ExecBuiltIn(Action(Play))", 0); PlayingSpeed$ = "1x"; }
}
Case(7): Call Connect("SendKey(0xF051)", 0); //esc

Case(8): Call SendLyrics(1);
Case(9): Call SendLyrics(2);
Case(10): Call Connect("ExecBuiltIn(Action(AspectRatio))", 0);
Case(11): Call Connect("ExecBuiltIn(Action(PreviousMenu))", 0);
Case(12):
{
If(ActiveWindow=10025)
{
If(VideoNavHighlightFb) Call Connect("ExecBuiltIn(Action(Info))", 0);
Else { Call SendEventServer("up", BtnPress); }
}
Else Call Connect("ExecBuiltIn(Action(Info))", 0);
}
Case(13): Call Connect("ExecBuiltIn(Action(ShowSubtitles))", 0);
Case(14): Call Connect("ExecBuiltIn(Action(NextSubtitle))", 0);//
Case(15): Call Connect("ExecBuiltIn(Action(AudioNextLanguage))", 0);//
Case(16): Call Connect("ExecBuiltIn(Action(AudioDelayPlus))", 0);//
Case(17): Call Connect("ExecBuiltIn(Action(AudioDelayMinus))", 0);//
Case(18): Call Connect("ExecBuiltIn(Action(SubtitleDelayPlus))", 0);//
Case(19): Call Connect("ExecBuiltIn(Action(SubtitleDelayMinus))", 0);//
Case(20): Call SendEventServer("up", BtnPress);
Case(21):
{
If(ActiveWindow=10025)
{
If(VideoNavHighlightFb) Call SendEventServer("down", BtnPress);
}
Else Call SendEventServer("down", BtnPress);
}
Case(22):
{
If(!(ActiveWindow=10502 && ControlId=50) && !(ActiveWindow=10502 && ControlId=506))
{
Call SendEventServer("left", BtnPress);
}
}
Case(23):
{
If(!(ActiveWindow=10502 && ControlId=50) && !(ActiveWindow=10502 && ControlId=506))
{
Call SendEventServer("right", BtnPress);
}
}
Case(24):
{
If(HaltSelect = 0)
{
If(ActiveWindow=10025)
{
If(VideoNavHighlightFb) { Call SendEventServer("return", BtnPress); }
Else { Call SendEventServer("up", BtnPress); }
}
Else { If(ActiveWindow<>12005 && ActiveWindow<>12006) Call SendEventServer("return", BtnPress); }
}
Else Wait(200) {HaltSelect = 0;}
}
Case(25): Call SendEventServer("pageup", BtnPress); //Call Connect("ExecBuiltIn(Action(PageUp))", 0);//
Case(26): Call SendEventServer("pagedown", BtnPress); //Call Connect("ExecBuiltIn(Action(PageDown))", 0);//
Case(27): Call Connect("ExecBuiltIn(Action(Highlight))", 0);//
Case(28): Call Connect("ExecBuiltIn(Action(ParentDir))", 0);//
Case(29): Call Connect("ExecBuiltIn(Action(OSD))", 0);//
Case(30): Call Connect("ExecBuiltIn(Action(ShowVideoMenu))", 0);
Case(31): Call Connect("ExecBuiltIn(Action(ContextMenu))", 0);
Case(32): Call Connect("ExecBuiltIn(Action(NextPicture))", 0);
Case(33): Call Connect("ExecBuiltIn(Action(PreviousPicture))", 0);
Case(34): Call Connect("ExecBuiltIn(Action(ZoomOut))", 0);
Case(35): Call Connect("ExecBuiltIn(Action(ZoomIn))", 0);
Case(36): Call Connect("ExecBuiltIn(Action(ZoomNormal))", 0);
Case(37): Call Connect("ExecBuiltIn(Action(Rotate))", 0);
Case(38): Call Connect("ExecBuiltIn(Action(FullScreen))", 0);
Case(39): Call Connect("ExecBuiltIn(Action(ShowTime))", 0);
Case(40): Call Connect("ExecBuiltIn(Action(NextLetter))", 0);
Case(41): Call Connect("ExecBuiltIn(Action(PrevLetter))", 0);
Case(42): Call Connect("ExecBuiltIn(ActivateWindow(musiclibrary,artists,12600))", 0); //ActivateWindow(10025,movietitles))
Case(43): Call Connect("ExecBuiltIn(ActivateWindow(musiclibrary,albums,12600))", 0);//10502,albums)
Case(44): Call Connect("ExecBuiltIn(ActivateWindow(musiclibrary,genres,12600))", 0); //(10002)
Case(45): Call Connect("ExecBuiltIn(ActivateWindow(Weather, 12600))", 0);//10000)
Case(46): Call Connect("ExecBuiltIn(Action(StepForward))", 0);
Case(47): Call Connect("ExecBuiltIn(Action(StepBack))", 0);
Case(48): Call Connect("ExecBuiltIn(Action(BigStepForward))", 0);
Case(49): Call Connect("ExecBuiltIn(Action(BigStepBack))", 0);
Case(50): Call Connect("ExecBuiltIn(Action(SmallStepBack))", 0);
Case(51): Call Connect("ExecBuiltIn(Action(SkipNext))", 0);
Case(52): Call Connect("ExecBuiltIn(Action(SkipPrevious))", 0);
Case(53): Call Connect("ExecBuiltIn(Action(CodecInfo))", 0);
Case(54): Call Connect("ExecBuiltIn(Action(Number0))", 0);
Case(55): Call Connect("ExecBuiltIn(Action(Number1))", 0);
Case(56): Call Connect("ExecBuiltIn(Action(Number2))", 0);
Case(57): Call Connect("ExecBuiltIn(Action(Number3))", 0);
Case(58): Call Connect("ExecBuiltIn(Action(Number4))", 0);
Case(59): Call Connect("ExecBuiltIn(Action(Number5))", 0);
Case(60): Call Connect("ExecBuiltIn(Action(Number6))", 0);
Case(61): Call Connect("ExecBuiltIn(Action(Number7))", 0);
Case(62): Call Connect("ExecBuiltIn(Action(Number8))", 0);
Case(63): Call Connect("ExecBuiltIn(Action(Number9))", 0);
Case(64): Call Connect("ExecBuiltIn(Action(Play))", 0);
Case(65): Call Connect("ExecBuiltIn(Action(HideSubmenu))", 0);
Case(66): Call Connect("ExecBuiltIn(Action(NextResolution))", 0);
Case(67): Call Connect("ExecBuiltIn(Action(ResetCalibration))", 0);
Case(68): Call Connect("ExecBuiltIn(Action(Close))", 1);
Case(69): Call Connect("SetVolume(75)", 0);
Case(70): Call Connect("SetVolume(100)", 0);
Case(71): Call Connect("ExecBuiltIn(Container.NextViewMode)", 0);
Case(72): Call Connect("ExecBuiltIn(Container.PreviousViewMode)", 0);
Case(73): Call Connect("ExecBuiltIn(Container.NextSortMethod)", 0);
Case(74): Call Connect("ExecBuiltIn(Container.PreviousSortMethod)", 0);
Case(75): Call Connect("ExecBuiltIn(Container.SortDirection)", 0);
Case(76): Call Connect("ExecBuiltIn(EjectTray())", 0);
Case(77): Call Connect("getcurrentlyplaying", 0);
Case(78): Call Connect("ExecBuiltIn(ActivateWindow(videolibrary,tvshowtitles))", 0);
Case(79): Call Connect("Action(142)", 0);
Case(80): Call Connect("Action(143)", 0);
Case(81): Call Connect("Action(144)", 0);
Case(82): Call Connect("Action(145)", 0);
Case(83): Call Connect("Action(146)", 0);
Case(84): Call Connect("Action(147)", 0);
Case(85): Call Connect("Action(148)", 0);
Case(86): Call Connect("Action(149)", 0);
Case(87): Call Connect("ExecBuiltIn(Action(SmallStepForward))", 0);
Case(88):
{
Makestring(Temp$, "ExecBuiltIn(ActivateWindow(10002,%s))", CurrFolderPath[CurrFolder]);
CurrXbmcWindow = 5;
Temp$ = RepleaceSpace(Temp$);
Call Connect(Temp$, 1);
}
Case(89): Call Connect("ExecBuiltIn(PlayerControl(RandomOn))", 0);
Case(90): Call Connect("ExecBuiltIn(PlayerControl(RandomOff))", 0);
Case(91): Call Connect("ExecBuiltIn(PlayerControl(RepeatOne))", 0);
Case(92): Call Connect("ExecBuiltIn(PlayerControl(RepeatAll))", 0);
Case(93): Call Connect("ExecBuiltIn(PlayerControl(RepeatOff))", 0);
Case(94): Call Connect("Action(200)", 0);
Case(95):
{
If(VideoNavHighlightFb=0 && ActiveWindow=10025) { Call SendEventServer("up", BtnPress); Delay(20); }
Call SendEventServer("backspace", BtnPress); //Call Connect("Action(9)", 0);//bkspc
}
Case(96): Call Connect("ExecBuiltIn(ActivateWindow(musiclibrary,lastfm://,12600))", 0);
Case(97): Call Connect("ExecBuiltIn(ActivateWindow(10000))", 1);//home Call SendEventServer("escape", BtnPress); //
}
}
Reply
#12
6. Upd Broadcast
//*******************************************************************************************
SOCKETRECEIVE FbUdp
{
STRING Sbuffer[16392];
INTEGER RcvLength, iEvent, iEventLevel, F[5];

Delay(5);
Sbuffer = FbUdp.SocketRxBuf;
ClearBuffer(FbUdp.SocketRxBuf);
If(Find(XbmcIp, Sbuffer) = 0) Terminateevent;
RcvLength = Len(Sbuffer);
print("\nUdp = %s\n\n", Sbuffer);

If(Find("OnAction", Sbuffer) > 0)
{
F[0] = Find(":", Sbuffer);
F[1] = Find(";", Sbuffer, F[0]);
If(F[1] = 0) F[1] = F[0];
F[2] = Find("<", Sbuffer, F[1]);
iEvent = Atoi(Mid(Sbuffer, F[0]+1, F[1]-F[0]-1));
iEventLevel = Atoi(Mid(Sbuffer, F[1]+1, F[2]-F[1]-1));
// print("iEvent = %u iEventLevel = %u\n", iEvent, iEventLevel);
}

Else If(Find("OnPlayBackStarted", Sbuffer) > 0)
{
PauseFb=0; StopFb=0; PlayFb=1; PlaySpeed=1; TransportIcon=1;
Makestring(PlayingSpeed$, "%ux", PlaySpeed);
Wait(100) { Call Connect("getcurrentlyplaying", 0); }
If(ActiveWindow = 10502) { Wait(150) { Call Connect("ExecBuiltIn(ActivateWindow(12006))", 0); } }
Wait(200) { Call Connect("getGUIStatus", 0); HaltSelect = 0;}
}
Else If(Find("OnPlayBackPaused", Sbuffer) > 0) {StopFb=0; PlayFb=0; PauseFb=1; PlayingSpeed$ = ""; TransportIcon=3; }
Else If(Find("OnPlayBackEnded", Sbuffer) > 0)
{
StopFb=1; PlayFb=0; PauseFb=0; PlayingSpeed$ = ""; TransportIcon=3;
ActiveWindow = 10025;
CurrXbmcWindow = 10025;
Call ClearCurrPlay();
Wait(200) { Call Connect("getGUIStatus", 0); HaltSelect = 0;}
}
Else If(Find("OnPlayBackResumed", Sbuffer) > 0)
{
PauseFb=0; StopFb=0; PlayFb=1; PlaySpeed=1; TransportIcon=1;
Makestring(PlayingSpeed$, "%ux", PlaySpeed);
HaltSelect = 1;
Wait(100) { Call Connect("getcurrentlyplaying", 0); }
If(ActiveWindow = 10502) { Wait(150) { Call Connect("ExecBuiltIn(ActivateWindow(12006))", 0); } }
Wait(200) { Call Connect("getGUIStatus", 0); HaltSelect = 0;}
}
Else If(Find("OnPlayBackStopped", Sbuffer) > 0)
{
PauseFb=0; PlayFb=0; StopFb=1; PlaySpeed=1; PlayingSpeed$ = ""; TransportIcon=2;
ActiveWindow = 10025;
CurrXbmcWindow = 10025;
Call ClearCurrPlay();
Wait(200) { Call Connect("getGUIStatus", 0); HaltSelect = 0;}
}

Else If(Find("StartUp", Sbuffer) > 0)//StartUp
{
Print("XbmcStarted\n");
Delay(300);
Call ClearCurrPlay();
Call Connect("ExecBuiltIn(ActivateWindow(12600))", 5);
}


Switch(iEventLevel)
{
Case(2): ;


}
}
7. Wakeup on Lan:

//*******************************************************************************************
FUNCTION WakeUpPC()
{
If(Enable)
{
If(PcPowerOffWaitFlag = 0)
{
PcPowerOffWaitFlag = 1;
Wait(300, PcPowerOffWait)
{
SocketUDP_Enable(WolSck, "255.255.255.255", 7);
If(Enable) SOCKETSEND(WolSck, WolPacket);
Delay(10);
SocketUDP_Disable(WolSck);
PcPowerOffWaitFlag = 0;
}
}
}
}

8. EventServer

#DEFINE_CONSTANT EventServerHeader "\x58\x42\x4D\x43\x02\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00"
#DEFINE_CONSTANT EventServerMid "\x4C\x17\x04\x91\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
#DEFINE_CONSTANT BtnPress 1
#DEFINE_CONSTANT BtnRelease 2
#DEFINE_CONSTANT ActionCmd 3
#DEFINE_CONSTANT PingCmd 4

//*******************************************************************************************/
Function SendEventServer(String Info, Integer Stat)//KeyboardStat_cpp XBMC-xbmcclient_py.mht
{
String SendBuffer[255];
String sLen[1], sFlag[1];

sLen = Chr(Len(Info)+10);
sFlag = "\x03";

Switch(Stat)
{
Case(BtnPress):
{
Makestring(SendBuffer, "%s%s%s%s\x00\x00KB\x00%s\x00", EventServerHeader, sLen, EventServerMid, sFlag, Info);
SOCKETSEND (EventServerUpd, SendBuffer);
// print("SendEventServer=%s\n",SendBuffer);
Call Connect("getGUIStatus", 0);
Delay(5);
sFlag = "\x05";
Makestring(SendBuffer, "%s%s%s%s\x00\x00KB\x00%s\x00", EventServerHeader, sLen, EventServerMid, sFlag, Info);
SOCKETSEND (EventServerUpd, SendBuffer);
}

}
}
Reply
#13
I'm working to a boxee-crestron module that can be controlled with the same http command like xbmc. Could you send me your module (and a simpl windows program working with)so i can compare its functionality?
Thank you wery much,
Nicola
Reply
#14
Any way someone could PM me the crestron module - I need this for a new project and don't really have time to try and make sense of tzya's code!!! Thanks
Reply
#15
I tried doing this myself as well and ran into the same issues, never even considered all the udp stuff tzya is doing. Thats badass work!! I'm unfamiliar/inexperienced with any UDPSocket stuff as of yet.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Making a Crestron Module for HTTP API Control00