-
-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathmain.go
804 lines (658 loc) · 21.2 KB
/
main.go
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].
package main
import (
"context"
"io"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"time"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/rpc/settings"
"google.golang.org/grpc"
)
var (
dataDir string
)
// The main function implements an example workflow to show how to interact
// with the gRPC Api exposed by arduino-cli when running in daemon mode.
func main() {
// Establish a connection with the gRPC server, started with the command:
// arduino-cli daemon
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(100*time.Millisecond))
if err != nil {
log.Fatal("error connecting to arduino-cli rpc server, you can start it by running `arduino-cli daemon`")
}
defer conn.Close()
// To avoid polluting an existing arduino-cli installation, the example
// client uses a temp folder to keep cores, libraries and the likes.
// You can point `dataDir` to a location that better fits your needs.
dataDir, err = ioutil.TempDir("", "arduino-rpc-client")
if err != nil {
log.Fatal(err)
}
dataDir = filepath.ToSlash(dataDir)
defer os.RemoveAll(dataDir)
// Create an instance of the gRPC client.
client := rpc.NewArduinoCoreClient(conn)
settingsClient := settings.NewSettingsClient(conn)
// Now we can call various methods of the API...
// `Version` can be called without any setup or init procedure.
log.Println("calling Version")
callVersion(client)
// Use SetValue to configure the arduino-cli directories.
log.Println("calling SetValue")
callSetValue(settingsClient)
// List all the settings.
log.Println("calling GetAll()")
callGetAll(settingsClient)
// Merge applies multiple settings values at once.
log.Println("calling Merge(`{\"foo\": \"bar\", \"daemon\":{\"port\":\"422\"}}`)")
callMerge(settingsClient)
// Get the value of the foo key.
log.Println("calling GetValue(foo)")
callGetValue(settingsClient)
// Before we can do anything with the CLI, an "instance" must be created.
// We keep a reference to the created instance because we will need it to
// run subsequent commands.
log.Println("calling Init")
instance := initInstance(client)
// With a brand new instance, the first operation should always be updatating
// the index.
log.Println("calling UpdateIndex")
callUpdateIndex(client, instance)
// Let's search for a platform (also known as 'core') called 'samd'.
log.Println("calling PlatformSearch(samd)")
callPlatformSearch(client, instance)
// Install arduino:[email protected]
log.Println("calling PlatformInstall(arduino:[email protected])")
callPlatformInstall(client, instance)
// Now list the installed platforms to double check previous installation
// went right.
log.Println("calling PlatformList()")
callPlatformList(client, instance)
// Upgrade the installed platform to the latest version.
log.Println("calling PlatformUpgrade(arduino:samd)")
callPlatformUpgrade(client, instance)
// Query board details for a mkr1000
log.Println("calling BoardDetails(arduino:samd:mkr1000)")
callBoardsDetails(client, instance)
// Attach a board to a sketch.
// Uncomment if you do have an actual board connected.
// log.Println("calling BoardAttach(serial:///dev/ttyACM0)")
// callBoardAttach(client, instance)
// Compile a sketch
log.Println("calling Compile(arduino:samd:mkr1000, VERBOSE, hello.ino)")
callCompile(client, instance)
// Upload a sketch
// Uncomment if you do have an actual board connected.
// log.Println("calling Upload(arduino:samd:mkr1000, /dev/ttyACM0, VERBOSE, hello.ino)")
// callUpload(client, instance)
// List all boards
log.Println("calling BoardListAll(mkr)")
callListAll(client, instance)
// List connected boards
log.Println("calling BoardList()")
callBoardList(client, instance)
// Uninstall a platform
log.Println("calling PlatformUninstall(arduino:samd)")
callPlatformUnInstall(client, instance)
// Update the Library index
log.Println("calling UpdateLibrariesIndex()")
callUpdateLibraryIndex(client, instance)
// Download a library
log.Println("calling LibraryDownload([email protected])")
callLibDownload(client, instance)
// Install a library
log.Println("calling LibraryInstall([email protected])")
callLibInstall(client, instance, "0.15.1")
// Replace the previous version
log.Println("calling LibraryInstall([email protected])")
callLibInstall(client, instance, "0.15.2")
// Upgrade all libs to latest
log.Println("calling LibraryUpgradeAll()")
callLibUpgradeAll(client, instance)
// Search for a lib using the 'audio' keyword
log.Println("calling LibrarySearch(audio)")
callLibSearch(client, instance)
// List the dependencies of the ArduinoIoTCloud library
log.Println("calling LibraryResolveDependencies(ArduinoIoTCloud)")
callLibraryResolveDependencies(client, instance)
// List installed libraries
log.Println("calling LibraryList")
callLibList(client, instance)
// Uninstall a library
log.Println("calling LibraryUninstall(WiFi101)")
callLibUninstall(client, instance)
}
func callVersion(client rpc.ArduinoCoreClient) {
versionResp, err := client.Version(context.Background(), &rpc.VersionReq{})
if err != nil {
log.Fatalf("Error getting version: %s", err)
}
log.Printf("arduino-cli version: %v", versionResp.GetVersion())
}
func callSetValue(client settings.SettingsClient) {
_, err := client.SetValue(context.Background(),
&settings.Value{
Key: "directories",
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
})
if err != nil {
log.Fatalf("Error setting settings value: %s", err)
}
}
func callMerge(client settings.SettingsClient) {
bulkSettings := `{"foo": "bar", "daemon":{"port":"422"}}`
_, err := client.Merge(context.Background(),
&settings.RawData{
JsonData: bulkSettings,
})
if err != nil {
log.Fatalf("Error merging settings: %s", err)
}
}
func callGetValue(client settings.SettingsClient) {
getValueResp, err := client.GetValue(context.Background(),
&settings.GetValueRequest{
Key: "foo",
})
if err != nil {
log.Fatalf("Error getting settings value: %s", err)
}
log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData())
}
func callGetAll(client settings.SettingsClient) {
getAllResp, err := client.GetAll(context.Background(), &settings.GetAllRequest{})
if err != nil {
log.Fatalf("Error getting settings: %s", err)
}
log.Printf("Settings: %s", getAllResp.GetJsonData())
}
func initInstance(client rpc.ArduinoCoreClient) *rpc.Instance {
// The configuration for this example client only contains the path to
// the data folder.
initRespStream, err := client.Init(context.Background(), &rpc.InitReq{})
if err != nil {
log.Fatalf("Error creating server instance: %s", err)
}
var instance *rpc.Instance
// Loop and consume the server stream until all the setup procedures are done.
for {
initResp, err := initRespStream.Recv()
// The server is done.
if err == io.EOF {
break
}
// There was an error.
if err != nil {
log.Fatalf("Init error: %s", err)
}
// The server sent us a valid instance, let's print its ID.
if initResp.GetInstance() != nil {
instance = initResp.GetInstance()
log.Printf("Got a new instance with ID: %v", instance.GetId())
}
// When a download is ongoing, log the progress
if initResp.GetDownloadProgress() != nil {
log.Printf("DOWNLOAD: %s", initResp.GetDownloadProgress())
}
// When an overall task is ongoing, log the progress
if initResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", initResp.GetTaskProgress())
}
}
return instance
}
func callUpdateIndex(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
uiRespStream, err := client.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
Instance: instance,
})
if err != nil {
log.Fatalf("Error updating index: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
uiResp, err := uiRespStream.Recv()
// the server is done
if err == io.EOF {
log.Print("Update index done")
break
}
// there was an error
if err != nil {
log.Fatalf("Update error: %s", err)
}
// operations in progress
if uiResp.GetDownloadProgress() != nil {
log.Printf("DOWNLOAD: %s", uiResp.GetDownloadProgress())
}
}
}
func callPlatformSearch(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
searchResp, err := client.PlatformSearch(context.Background(), &rpc.PlatformSearchReq{
Instance: instance,
SearchArgs: "samd",
})
if err != nil {
log.Fatalf("Search error: %s", err)
}
platforms := searchResp.GetSearchOutput()
for _, plat := range platforms {
// We only print ID and version of the platforms found but you can look
// at the definition for the rpc.Platform struct for more fields.
log.Printf("Search result: %+v - %+v", plat.GetID(), plat.GetLatest())
}
}
func callPlatformInstall(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
installRespStream, err := client.PlatformInstall(context.Background(),
&rpc.PlatformInstallReq{
Instance: instance,
PlatformPackage: "arduino",
Architecture: "samd",
Version: "1.6.19",
})
if err != nil {
log.Fatalf("Error installing platform: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
installResp, err := installRespStream.Recv()
// The server is done.
if err == io.EOF {
log.Printf("Install done")
break
}
// There was an error.
if err != nil {
log.Fatalf("Install error: %s", err)
}
// When a download is ongoing, log the progress
if installResp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s", installResp.GetProgress())
}
// When an overall task is ongoing, log the progress
if installResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", installResp.GetTaskProgress())
}
}
}
func callPlatformList(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
listResp, err := client.PlatformList(context.Background(),
&rpc.PlatformListReq{Instance: instance})
if err != nil {
log.Fatalf("List error: %s", err)
}
for _, plat := range listResp.GetInstalledPlatform() {
// We only print ID and version of the installed platforms but you can look
// at the definition for the rpc.Platform struct for more fields.
log.Printf("Installed platform: %s - %s", plat.GetID(), plat.GetInstalled())
}
}
func callPlatformUpgrade(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
upgradeRespStream, err := client.PlatformUpgrade(context.Background(),
&rpc.PlatformUpgradeReq{
Instance: instance,
PlatformPackage: "arduino",
Architecture: "samd",
})
if err != nil {
log.Fatalf("Error upgrading platform: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
upgradeResp, err := upgradeRespStream.Recv()
// The server is done.
if err == io.EOF {
log.Printf("Upgrade done")
break
}
// There was an error.
if err != nil {
log.Fatalf("Upgrade error: %s", err)
}
// When a download is ongoing, log the progress
if upgradeResp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s", upgradeResp.GetProgress())
}
// When an overall task is ongoing, log the progress
if upgradeResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", upgradeResp.GetTaskProgress())
}
}
}
func callBoardsDetails(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
details, err := client.BoardDetails(context.Background(),
&rpc.BoardDetailsReq{
Instance: instance,
Fqbn: "arduino:samd:mkr1000",
})
if err != nil {
log.Fatalf("Error getting board data: %s\n", err)
}
log.Printf("Board details for %s", details.GetName())
log.Printf("Required tools: %s", details.GetRequiredTools())
log.Printf("Config options: %s", details.GetConfigOptions())
}
func callBoardAttach(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
currDir, _ := os.Getwd()
boardattachresp, err := client.BoardAttach(context.Background(),
&rpc.BoardAttachReq{
Instance: instance,
BoardUri: "/dev/ttyACM0",
SketchPath: filepath.Join(currDir, "hello.ino"),
})
if err != nil {
log.Fatalf("Attach error: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
attachResp, err := boardattachresp.Recv()
// The server is done.
if err == io.EOF {
log.Print("Attach done")
break
}
// There was an error.
if err != nil {
log.Fatalf("Attach error: %s\n", err)
}
// When an overall task is ongoing, log the progress
if attachResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", attachResp.GetTaskProgress())
}
}
}
func callCompile(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
currDir, _ := os.Getwd()
compRespStream, err := client.Compile(context.Background(),
&rpc.CompileReq{
Instance: instance,
Fqbn: "arduino:samd:mkr1000",
SketchPath: filepath.Join(currDir, "hello.ino"),
Verbose: true,
})
if err != nil {
log.Fatalf("Compile error: %s\n", err)
}
// Loop and consume the server stream until all the operations are done.
for {
compResp, err := compRespStream.Recv()
// The server is done.
if err == io.EOF {
log.Print("Compilation done")
break
}
// There was an error.
if err != nil {
log.Fatalf("Compile error: %s\n", err)
}
// When an operation is ongoing you can get its output
if resp := compResp.GetOutStream(); resp != nil {
log.Printf("STDOUT: %s", resp)
}
if resperr := compResp.GetErrStream(); resperr != nil {
log.Printf("STDERR: %s", resperr)
}
}
}
func callUpload(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
currDir, _ := os.Getwd()
uplRespStream, err := client.Upload(context.Background(),
&rpc.UploadReq{
Instance: instance,
Fqbn: "arduino:samd:mkr1000",
SketchPath: filepath.Join(currDir, "hello.ino"),
Port: "/dev/ttyACM0",
Verbose: true,
})
if err != nil {
log.Fatalf("Upload error: %s\n", err)
}
for {
uplResp, err := uplRespStream.Recv()
if err == io.EOF {
log.Printf("Upload done")
break
}
if err != nil {
log.Fatalf("Upload error: %s", err)
break
}
// When an operation is ongoing you can get its output
if resp := uplResp.GetOutStream(); resp != nil {
log.Printf("STDOUT: %s", resp)
}
if resperr := uplResp.GetErrStream(); resperr != nil {
log.Printf("STDERR: %s", resperr)
}
}
}
func callListAll(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
boardListAllResp, err := client.BoardListAll(context.Background(),
&rpc.BoardListAllReq{
Instance: instance,
SearchArgs: []string{"mkr"},
})
if err != nil {
log.Fatalf("Board list-all error: %s", err)
}
for _, board := range boardListAllResp.GetBoards() {
log.Printf("%s: %s", board.GetName(), board.GetFQBN())
}
}
func callBoardList(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
boardListResp, err := client.BoardList(context.Background(),
&rpc.BoardListReq{Instance: instance})
if err != nil {
log.Fatalf("Board list error: %s\n", err)
}
for _, port := range boardListResp.GetPorts() {
log.Printf("port: %s, boards: %+v\n", port.GetAddress(), port.GetBoards())
}
}
func callPlatformUnInstall(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
uninstallRespStream, err := client.PlatformUninstall(context.Background(),
&rpc.PlatformUninstallReq{
Instance: instance,
PlatformPackage: "arduino",
Architecture: "samd",
})
if err != nil {
log.Fatalf("Uninstall error: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
uninstallResp, err := uninstallRespStream.Recv()
if err == io.EOF {
log.Print("Uninstall done")
break
}
if err != nil {
log.Fatalf("Uninstall error: %s\n", err)
}
if uninstallResp.GetTaskProgress() != nil {
log.Printf("TASK: %s\n", uninstallResp.GetTaskProgress())
}
}
}
func callUpdateLibraryIndex(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libIdxUpdateStream, err := client.UpdateLibrariesIndex(context.Background(),
&rpc.UpdateLibrariesIndexReq{Instance: instance})
if err != nil {
log.Fatalf("Error updating libraries index: %s\n", err)
}
// Loop and consume the server stream until all the operations are done.
for {
resp, err := libIdxUpdateStream.Recv()
if err == io.EOF {
log.Print("Library index update done")
break
}
if err != nil {
log.Fatalf("Error updating libraries index: %s", err)
}
if resp.GetDownloadProgress() != nil {
log.Printf("DOWNLOAD: %s", resp.GetDownloadProgress())
}
}
}
func callLibDownload(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
downloadRespStream, err := client.LibraryDownload(context.Background(),
&rpc.LibraryDownloadReq{
Instance: instance,
Name: "WiFi101",
Version: "0.15.2",
})
if err != nil {
log.Fatalf("Error downloading library: %s", err)
}
// Loop and consume the server stream until all the operations are done.
for {
downloadResp, err := downloadRespStream.Recv()
if err == io.EOF {
log.Print("Lib download done")
break
}
if err != nil {
log.Fatalf("Download error: %s", err)
}
if downloadResp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s", downloadResp.GetProgress())
}
}
}
func callLibInstall(client rpc.ArduinoCoreClient, instance *rpc.Instance, version string) {
installRespStream, err := client.LibraryInstall(context.Background(),
&rpc.LibraryInstallReq{
Instance: instance,
Name: "WiFi101",
Version: version,
})
if err != nil {
log.Fatalf("Error installing library: %s", err)
}
for {
installResp, err := installRespStream.Recv()
if err == io.EOF {
log.Print("Lib install done")
break
}
if err != nil {
log.Fatalf("Install error: %s", err)
}
if installResp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s\n", installResp.GetProgress())
}
if installResp.GetTaskProgress() != nil {
log.Printf("TASK: %s\n", installResp.GetTaskProgress())
}
}
}
func callLibUpgradeAll(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libUpgradeAllRespStream, err := client.LibraryUpgradeAll(context.Background(),
&rpc.LibraryUpgradeAllReq{
Instance: instance,
})
if err != nil {
log.Fatalf("Error upgrading all: %s\n", err)
}
for {
resp, err := libUpgradeAllRespStream.Recv()
if err == io.EOF {
log.Printf("Lib upgrade all done")
break
}
if err != nil {
log.Fatalf("Upgrading error: %s", err)
}
if resp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s\n", resp.GetProgress())
}
if resp.GetTaskProgress() != nil {
log.Printf("TASK: %s\n", resp.GetTaskProgress())
}
}
}
func callLibSearch(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libSearchResp, err := client.LibrarySearch(context.Background(),
&rpc.LibrarySearchReq{
Instance: instance,
Query: "audio",
})
if err != nil {
log.Fatalf("Error searching for library: %s", err)
}
for _, res := range libSearchResp.GetLibraries() {
log.Printf("Result: %s - %s", res.GetName(), res.GetLatest().GetVersion())
}
}
func callLibraryResolveDependencies(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libraryResolveDependenciesResp, err := client.LibraryResolveDependencies(context.Background(),
&rpc.LibraryResolveDependenciesReq{
Instance: instance,
Name: "ArduinoIoTCloud",
})
if err != nil {
log.Fatalf("Error listing library dependencies: %s", err)
}
for _, resp := range libraryResolveDependenciesResp.GetDependencies() {
log.Printf("Dependency Name: %s", resp.GetName())
log.Printf("Version Required: %s", resp.GetVersionRequired())
if resp.GetVersionInstalled() != "" {
log.Printf("Version Installed: %s\n", resp.GetVersionInstalled())
}
}
}
func callLibList(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libLstResp, err := client.LibraryList(context.Background(),
&rpc.LibraryListReq{
Instance: instance,
All: false,
Updatable: false,
})
if err != nil {
log.Fatalf("Error List Library: %s", err)
}
for _, res := range libLstResp.GetInstalledLibrary() {
log.Printf("%s - %s", res.GetLibrary().GetName(), res.GetLibrary().GetVersion())
}
}
func callLibUninstall(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libUninstallRespStream, err := client.LibraryUninstall(context.Background(),
&rpc.LibraryUninstallReq{
Instance: instance,
Name: "WiFi101",
})
if err != nil {
log.Fatalf("Error uninstalling: %s", err)
}
for {
uninstallResp, err := libUninstallRespStream.Recv()
if err == io.EOF {
log.Printf("Lib uninstall done")
break
}
if err != nil {
log.Fatalf("Uninstall error: %s", err)
}
if uninstallResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", uninstallResp.GetTaskProgress())
}
}
}