Check-in [af9ab33ec7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Removed extraneous test file for dbusclient. The thunder.test file is specific to having a particular board.
Timelines: family | ancestors | descendants | both | dbusclient-develop
Files: files | file ages | folders
SHA1:af9ab33ec7cf9ba0dea8c5bab23a355dd436916b
User & Date: andrewm 2019-03-01 11:38:38
Context
2019-03-01
11:45
Merging dbusclient develop onto the trunk and releasing the package as version 1.0 check-in: d72d1d5123 user: andrewm tags: trunk
11:40
Adding missing file for dbusclient package. Leaf check-in: 61f26e36e0 user: andrewm tags: dbusclient-develop
11:38
Removed extraneous test file for dbusclient. The thunder.test file is specific to having a particular board. check-in: af9ab33ec7 user: andrewm tags: dbusclient-develop
11:36
Clean up of dbusclient in preparation for 1.0 release. check-in: 35b7b72ecd user: andrewm tags: dbusclient-develop
Changes

Deleted dbusclient/test/thunder.test.

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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env tclsh
#
# This software is copyrighted 2019 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors and
# need not follow the licensing terms described here, provided that the
# new terms are clearly indicated on the first page of each file where
# they apply.
# 
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
# THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# 
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
# OR MODIFICATIONS.
# 
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense,
# the software shall be classified as "Commercial Computer Software"
# and the Government shall have only "Restricted Rights" as defined in
# Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing,
# the authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.
#

package require Tcl 8.6
package require cmdline
package require logger
package require logger::utils
package require logger::appender
package require control

# source ../code/dbusclient.tcl
package require dbusclient

# Add custom arguments here.
set optlist {
    {level.arg notice {Log debug level}}
    {name.arg {Thunder*} {Device name to look for}}
    {nodelete {Don't delete device when done}}
}

try {
    array set options [::cmdline::getoptions argv $optlist]
} on error {result} {
    puts -nonewline stderr $result
    exit 1
}

control::control assert enabled true

logger::setlevel $options(level)
set logger [::logger::init thunder]
::logger::utils::applyAppender -appender colorConsole -serviceCmd $logger\
        -appenderArgs {-conversionPattern {\[%c\] \[%p\] '%m'}}

namespace eval ::thunder {
    namespace import ::dbusclient::*
    namespace import ::ral::*
    namespace import ::ralutil::*
    namespace import ::control::assert

    deserializeFromFile ./gattdb.ral

    proc propSync {status path interface property value} {
        set [namespace current]::done [dict create\
            status $status path $path interface $interface property $property\
            value $value]
    }

    ::logger::import -all -force -namespace log thunder
    log::info "testing dbusclient version: [package require dbusclient]"

    log::info "connecting to org.bluez on the system bus"
    Connection create ::sysBus system
    Service create org.bluez org.bluez ::sysBus

    set path [org.bluez findPathsByPropertyValue org.bluez.Device1\
            Name {[string match $::options(name) $Value]}]
    log::debug "paths matching $::options(name) : \"$path\""

    if {[llength $path] == 0} {
        log::notice "starting discovery"
        set discovering [org.bluez waitForProperty org.bluez.Adapter1\
                Discovering /org/bluez/hci0\
                {org.bluez call /org/bluez/hci0\
                    org.bluez.Adapter1 StartDiscovery}]
        assert {[dict get $discovering value] == 1} "Discovering property is not 1"

        while {true} {
            try {
                set newName [org.bluez waitForProperty org.bluez.Device1\
                    Name /org/bluez/hci0/dev* {} 10000]
                if {[string match $::options(name) [dict get $newName value]]} {
                    set path [dict get $newName path]
                    break
                }
            } on error {result} {
                log::error $result
                return
            } finally {
                log::notice "stopping discovery"
                set discovering [org.bluez waitForProperty org.bluez.Adapter1 Discovering\
                    /org/bluez/hci0 {org.bluez call /org/bluez/hci0\
                        org.bluez.Adapter1 StopDiscovery}]
                assert {[dict get $discovering value] == 0} "Discovering property is not 0"
            }
        }
    }

    log::notice "connecting to $path"
    set connected [org.bluez waitForProperty org.bluez.Device1 Connected $path\
            {org.bluez call $path org.bluez.Device1 Connect} 10000]
    assert {[dict get $connected value] == 1} "Connected property is not 1"
    log::notice "connected to $path"

    set svcres [org.bluez waitForProperty org.bluez.Device1 ServicesResolved $path {}]
    assert {[dict get $svcres value] == 1} "ServicesResolved property is not 1"
    log::info "services resolved"

    log::notice "waiting for settling time"
    after 3000

    set props [org.bluez pathProperties $path org.bluez.Device1]
    puts "Properties for $path"
    foreach prop $props {
        try {
            set value [org.bluez property $path org.bluez.Device1 $prop]
            puts "    $prop = $value"
        } on error {result} {
            log::error $result
            log::info "cannot get $prop value"
        }
    }

    set uuids [org.bluez property $path org.bluez.Device1 UUIDs]
    puts "services for $path"
    foreach uuid $uuids {
        set svcEntity [relvar restrictone Entity UUID $uuid]
        set name [expr {[relation isempty $svcEntity] ?\
                "unknown" : [relation extract $svcEntity Name]}]

        set svcpath [org.bluez findPathsByPropertyValue org.bluez.GattService1\
                UUID {$uuid eq $Value}]

        puts "Service: $name ==> $uuid, on path $svcpath"

        set charpaths [org.bluez findPathsByPropertyValue org.bluez.GattCharacteristic1\
                Service {$svcpath eq $Value}]
        puts "    Characteristics:"
        foreach charpath $charpaths {
            set cuuid [org.bluez property $charpath org.bluez.GattCharacteristic1 UUID]
            set chEntity [relvar restrictone Entity UUID $cuuid]
            set cname [expr {[relation isempty $chEntity] ?\
                    "unknown" : [relation extract $chEntity Name]}]

            set flags [org.bluez property $charpath\
                    org.bluez.GattCharacteristic1 Flags]
            if {"read" in $flags} {
                set value [org.bluez call $charpath\
                        org.bluez.GattCharacteristic1 ReadValue {}]
            } else {
                set value "not readable"
            }
            puts "    $cname ==> $value\n        UUID ==> $cuuid,\
                    Path ==> $charpath"

            set descpaths [org.bluez findPathsByPropertyValue\
                    org.bluez.GattDescriptor1\
                    Characteristic {$charpath eq $Value}]
            foreach descpath $descpaths {
                set duuid [org.bluez property $descpath\
                        org.bluez.GattDescriptor1 UUID]
                set dvalue [org.bluez call $descpath\
                        org.bluez.GattDescriptor1 ReadValue {}]

                puts "        Descriptor: UUID = $duuid, Value = $dvalue"
            }
        }
        puts {}
    }

    log::notice "disconnecting from $path"
    set connected [org.bluez waitForProperty org.bluez.Device1 Connected $path\
            {org.bluez call $path org.bluez.Device1 Disconnect}]
    assert {[dict get $connected value] == 0} "Connected property is not 0"

    if {!$::options(nodelete)} {
        log::notice "deleting path $path"
        set rmpath [org.bluez waitForPath $path\
                {org.bluez call /org/bluez/hci0 org.bluez.Adapter1 RemoveDevice $path}]
        assert {[dict get $rmpath status] eq "removed" &&\
                [dict get $rmpath path] eq $path} "$path not removed"
    }
}

# vim :set syntax=tcl:
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<