-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkefctrl.ps1
127 lines (115 loc) · 2.73 KB
/
kefctrl.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$global:KefServer = $null
$global:KefPort = "50001"
$global:reader=$null
$global:writer=$null
$global:tcpConnection=$null
$global:tcpStream=$null
function SetupConnection {
Try
{
Write-Host "SetupConnection"
$global:tcpConnection = New-Object System.Net.Sockets.TcpClient($global:KefServer, $global:KefPort)
$global:tcpStream = $tcpConnection.GetStream()
$global:reader = New-Object System.IO.BinaryReader($tcpStream)
$global:writer = New-Object System.IO.BinaryWriter($tcpStream)
$return=$true
}
Catch
{
Write-Host "SetupConnection failed : $_.Exception.Message"
$return=$false
}
return $return
}
function CloseConnection {
Try
{
Write-Host "CloseConnection"
$global:reader.Close()
$global:writer.Close()
$global:tcpConnection.Close()
}
Catch
{
Write-Host "CloseConnection failed : $_.Exception.Message"
}
}
function IncreaseVolume {
Try
{
Write-Host "IncreaseVolume"
[byte[]] $cmd_GetVolume = 0x47,0x25,0x80,0x6C
$global:writer.Write($cmd_GetVolume, 0, $cmd_GetVolume.Length)
$buffer=New-Object Byte[] 5
$BytesRead=$global:reader.Read($buffer, 0, 5)
$level=$buffer[3]
[byte[]] $cmd_SetVolume = 0x53,0x25,0x81,0
$MaxMin=[int]$level+[int]$args[0] ;
if ($MaxMin -gt 100) {$MaxMin=100}
if ($MaxMin -lt 0) {$MaxMin=0}
$cmd_SetVolume[3]=$MaxMin
Write-Host "Volume from $level to $MaxMin"
$global:writer.Write($cmd_SetVolume, 0, $cmd_SetVolume.Length)
$return=$true
}
Catch
{
Write-Host "IncreaseVolume failed : $_.Exception.Message"
$return=$false
}
return $return
}
function SetAux {
Try
{
Write-Host "SetAux"
[byte[]] $cmd = 0x53,0x30,0x81,0x1A,0x9B
$global:writer.Write($cmd, 0, $cmd.Length)
$return=$true
}
Catch
{
Write-Host "SetAux failed : $_.Exception.Message"
$return=$false
}
return $return
}
function SetOptical {
Try
{
Write-Host "SetOptical"
[byte[]] $cmd = 0x53,0x30,0x81,0x1B,0x9B
$global:writer.Write($cmd, 0, $cmd.Length)
$return=$true
}
Catch
{
Write-Host "SetOptical failed : $_.Exception.Message"
$return=$false
}
return $return
}
if ($args.count -ne 2)
{
Write-Host "`nsyntax : keyctrl </h:IP> <inc|dec|aux|opt>"
return
}
#for ( $i = 0; $i -lt $args.count; $i++ )
# {
# write-host $args[$i]
# }
#write-host "There are a total of $($args.count) arguments"
$a,$global:KefServer = $args[0].split(':')
if (SetupConnection)
{
for ( $i = 1; $i -lt $args.count; $i++ ) {
switch ( $args[$i] )
{
"inc" { if (IncreaseVolume(10)) {} }
"dec" { if (IncreaseVolume(-10)) {} }
"aux" { if (SetAux) {} }
"opt" { if (SetOptical) {} }
}
}
CloseConnection
}