forked from joan2937/lg
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rgs.1
3727 lines (2734 loc) · 54.7 KB
/
rgs.1
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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Process this file with
.\" groff -man -Tascii foo.1
.\"
.TH rgs 1 2020-2023 Linux "lg archive"
.SH NAME
rgs - a shell command to manipulate a remote SBC's GPIO.
.SH SYNOPSIS
.B rgpiod &
then
.B rgs {command}+
.SH DESCRIPTION
.ad l
.nh
.br
rgs is a program which allows remote control of the GPIO and
other functions of Linux SBCs running the rgpiod daemon.
.br
The rgpiod daemon must be running on the SBCs you wish to control.
.br
.SS Features
.br
.br
o reading and writing GPIO singly and in groups
.br
o software timed PWM and waves
.br
o GPIO callbacks
.br
o pipe notification of GPIO events
.br
o I2C wrapper
.br
o SPI wrapper
.br
o serial link wrapper
.br
o simple file handling
.br
o creating and running scripts on the rgpiod daemon
.br
.SS Usage
.br
rgs {command}+
.br
rgs will show the result of the command on screen.
.br
The rgs process returns an exit status (which can be displayed with
the command echo $?).
.br
.EX
RGS_OK 0
.br
RGS_CONNECT_ERR 255
.br
RGS_OPTION_ERR 254
.br
RGS_SCRIPT_ERR 253
.br
.br
.br
.EE
.br
If an error was detected a message will have been written to stderr.
This is likely to be more informative than the message returned by rgs.
.br
Several commands may be entered on a line. If present PROC and PARSE must
be the last command on a line.
.br
.SS Notes
.br
rgs does not show the status of successful commands unless the
command itself returns data. The status (0) will be returned to
rgs but will be discarded.
.br
When a command takes a number as a parameter it may be entered as hex
(precede by 0x), octal (precede by 0), or decimal.
.br
E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal.
.br
Some commands can return a variable number of data bytes. By
default this data is displayed as decimal. The rgs -a option
can be used to force the display as ASCII and the rgs -x
option can be used to force the display as hex.
.br
E.g. assuming the transmitted serial data is the letters ABCDEONM
.br
.EX
$ rgs serr 4 100 # assumes serial data available from handle 4
.br
8 65 66 67 68 69 79 78 77
.br
.br
$ rgs -a serr 4 100
.br
8 ABCDEONM
.br
.br
$ rgs -x serr 4 100
.br
8 41 42 43 44 45 4f 4e 4d
.br
.EE
.br
.SS Permissions
.br
Generally objects created on the rgpiod daemon exist for the duration of the
socket connection.
.br
For a Python script this will be for the duration of the script. For a
program linked with rgpio this will be for the duration of the program.
.br
For rgs it is the command line.
.br
This means that the following command will achieve little
.br
.EX
rgs go 0 # get handle to gpiochip 0
.br
.EE
.br
The daemon will delete the handle as soon as the rgs command has finished.
.br
To preserve the handle it must be shared.
.br
A lot of the examples will show the command c 1 (use share id 1).
This means the handle is preserved and may be used in subsequent commands.
.br
.EX
rgs c 1 go 0 # get and preserve handle to gpiochip 0
.br
.EE
.br
If the LG_SHARE environment variable exists that share will be
automatically used in rgs commands.
.br
E.g. \fBexport LG_SHARE=12\fP will automatically use share id 12.
.br
If a command is privileged it is indicated in the notes for the
command. The examples given here assume the daemon access control
system is not active (so any user can use privileged commands).
.br
If the LG_USER environment variable exists that user will be
automatically used in rgs commands. This only has an effect if
the rgpiod daemon is running with access control enabled.
.br
E.g. \fBexport LG_USER=joan\fP will automatically use user joan.
.br
.SH OVERVIEW
.SS FILES
.B FO file mode
File open
.P
.B FC h
File close
.P
.B FR h num
File read
.P
.B FW h bvs
File write
.P
.B FS h num from
File seek
.P
.B FL pat num
File list
.P
.SS GPIO
.br
.B GO gc
gpiochip open device
.P
.B GC h
gpiochip close device
.P
.B GIC h
gpiochip information
.P
.B GIL h g
gpiochip line information
.P
.B GMODE h g
GPIO get mode
.P
.B GSI h g
GPIO claim for input (simple)
.P
.B GSIX h lf g
GPIO claim for input
.P
.B GSO h g
GPIO claim for output (simple)
.P
.B GSOX h lf g v
GPIO claim for output
.P
.B GSA h g nfyh
GPIO claim for alerts (simple)
.P
.B GSAX h lf ef g nfyh
GPIO claim for alerts
.P
.B GSF h g
GPIO free
.P
.B GSGI h g*
GPIO group claim for inputs (simple)
.P
.B GSGIX h lf g*
GPIO group claim for inputs
.P
.B GSGO h g*
GPIO group claim for outputs (simple)
.P
.B GSGOX h lf g* v*
GPIO group claim for outputs
.P
.B GSGF h g
GPIO group free
.P
.B GR h g
GPIO read
.P
.B GW h g v
GPIO write
.P
.B GGR h g
GPIO group read
.P
.B GGW h g gbits
GPIO group write (simple)
.P
.B GGWX h g gbits gmask
GPIO group write
.P
.B GP h g mon moff
GPIO tx pulse (simple)
.P
.B GPX h g mon moff off cyc
GPIO tx pulse
.P
.B P h g pf pdc
GPIO tx PWM (simple)
.P
.B PX h g pf pdc off cyc
GPIO tx PWM
.P
.B S h g spw
GPIO tx servo pulses (simple)
.P
.B SX h g spw sf off cyc
GPIO tx servo pulses
.P
.B GWAVE h g p*
GPIO group tx wave
.P
.B GBUSY h g k
GPIO or group tx busy
.P
.B GROOM h g k
GPIO or group tx entries
.P
.B GDEB h g us
GPIO debounce time
.P
.B GWDOG h g us
GPIO watchdog time
.P
.SS I2C
.B I2CO ib id if
I2C open device
.P
.B I2CC h
I2C close device
.P
.B I2CWQ h bit
SMB Write Quick: write bit
.P
.B I2CRS h
SMB Read Byte: read byte
.P
.B I2CWS h bv
SMB Write Byte: write byte
.P
.B I2CRB h r
SMB Read Byte Data: read byte from register
.P
.B I2CWB h r bv
SMB Write Byte Data: write byte to register
.P
.B I2CRW h r
SMB Read Word Data: read word from register
.P
.B I2CWW h r wv
SMB Write Word Data: write word to register
.P
.B I2CRK h r
SMB Read Block Data: read data from register
.P
.B I2CWK h r bvs
SMB Write Block Data: write data to register
.P
.B I2CWI h r bvs
SMB Write I2C Block Data
.P
.B I2CRI h r num
SMB Read I2C Block Data: read bytes from register
.P
.B I2CRD h num
I2C read device
.P
.B I2CWD h bvs
I2C write device
.P
.B I2CPC h r wv
SMB Process Call: exchange register with word
.P
.B I2CPK h r bvs
SMB Block Process Call: exchange data bytes with register
.P
.B I2CZ h bvs
I2C zip
.P
.SS NOTIFICATIONS
.B NO
Notification open
.P
.B NC h
Notification close
.P
.B NP h
Notification pause
.P
.B NR h
Notification resume
.P
.SS SCRIPTS
.B PROC t
Script store
.P
.B PROCR h pars
Script run
.P
.B PROCU h pars
Script update parameters
.P
.B PROCP h
Script get status and parameters
.P
.B PROCS h
Script stop
.P
.B PROCD h
Script delete
.P
.B PARSE t
Script validate
.P
.SS SERIAL
.B SERO dev b sef
Serial open device
.P
.B SERC h
Serial close device
.P
.B SERRB
Serial read byte
.P
.B SERWB h bv
Serial write byte
.P
.B SERR h num
Serial read bytes
.P
.B SERW h bvs
Serial write bytes
.P
.B SERDA h
Serial data available
.P
.SS SHELL
.B SHELL name str
Execute a shell command
.P
.SS SPI
.B SPIO spd spc b spf
SPI open device
.P
.B SPIC h
SPI close device
.P
.B SPIR h num
SPI read bytes
.P
.B SPIW h bvs
SPI write bytes
.P
.B SPIX h bvs
SPI transfer bytes
.P
.SS UTILITIES
.B LGV
Get lg library version
.P
.B SBC
Get SBC's host name
.P
.B CGI cid
Get internal configuration setting
.P
.B CSI cid v
Set internal configuration setting
.P
.B T/TICK
Get nanoseconds since the epoch
.P
.B MICS v
Microseconds delay
.P
.B MILS v
Milliseconds delay
.P
.B U/USER
Set user
.P
.B C/SHARE
Set share
.P
.B LCFG
Reload permits configuration file
.P
.B PCD
Print daemon configuration directory
.P
.B PWD
Print daemon working directory
.P
.SH COMMANDS
.br
.SS FILES
.br
.IP "\fBFO file mode\fP - File open"
.IP "" 4
This is a privileged command. See \fBpermits\fP.
.br
This function returns a handle to a file opened in a specified mode.
.br
Upon success a handle (>=0) is returned. On error a negative status code
will be returned.
.br
The mode may have the following values.
.br
.EX
Value Meaning
READ 1 open file for reading
WRITE 2 open file for writing
RW 3 open file for reading and writing
.EE
.br
The following values may be or'd into the mode.
.br
.EX
Value Meaning
APPEND 4 All writes append data to the end of the file
CREATE 8 The file is created if it doesn't exist
TRUNC 16 The file is truncated
.EE
.br
Newly created files are owned by the user that launched the daemon
with permissions owner read and write.
.br
\fBExample\fP
.br
.EX
ls /ram/*.c
.br
/ram/q.c /ram/qdhtxx.c /ram/q-errcod.c /ram/q_t1.c
.br
/ram/q-c1.c /ram/Q-err.c /ram/q-group.c /ram/q_t2.c
.br
.br
$ rgs c 1 fo /ram/q.c 1 # read access
.br
1
.br
.br
$ rgs c 1 fo /ram/new.c 1 # file does not exist
.br
-58
.br
ERROR: file open failed
.br
.br
$rgs c 1 fo /ram/new.c 9 # can not create file
.br
-67
.br
ERROR: no permission to access file
.br
.EE
.br
.IP "\fBFC h\fP - File close"
.IP "" 4
This command closes a file previously opened by \fBFO\fP.
.br
Upon success nothing is returned. On error a negative status code
will be returned.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 fc 1 # First close okay.
.br
.br
$ rgs c 1 fc 1 # Second fails.
.br
-5
.br
ERROR: unknown handle
.br
.EE
.br
.br
.IP "\fBFR h num\fP - File read"
.IP "" 4
This command returns up to \fBnum\fP bytes of data read from the file.
.br
Upon success the count of returned bytes followed by the bytes themselves
is returned. On error a negative status code will be returned.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 fr 0 10
.br
5 48 49 128 144 255
.br
.br
$ rgs c 1 fr 0 10
.br
0
.br
.EE
.br
.IP "\fBFW h bvs\fP - File write"
.IP "" 4
This command writes \fBbvs\fP bytes to the file.
.br
Upon success nothing is returned. On error a negative status code
will be returned.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 fw 0 23 45 67 89
.br
.EE
.br
.IP "\fBFS h num from\fP - File seek"
.IP "" 4
This command seeks to a position within the file.
.br
The number of bytes to move is \fBnum\fP. Positive offsets
move forward, negative offsets backwards. The move start
position is determined by \fBfrom\fP as follows.
.br
.EX
From
0 start
1 current position
2 end
.EE
.br
Upon success the new byte position within the file (>=0) is
returned. On error a negative status code will be returned.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 fs 0 200 0 # Seek to start of file plus 200
.br
200
.br
.br
$ rgs c 1 fs 0 0 1 # Return current position
.br
200
.br
.br
$ rgs c 1 fs 0 0 2 # Seek to end of file, return size
.br
296235
.br
.EE
.br
.IP "\fBFL pat num\fP - File list"
.IP "" 4
This command returns a list of the files matching \fBpat\fP. Up
to \fBnum\fP bytes may be returned.
.br
Upon success the count of returned bytes followed by the matching
files is returned. On error a negative status code will be returned.
.br
A newline (0x0a) character separates each file name.
.br
This is a privileged command. See \fBpermits\fP.
.br
\fBExample\fP
.br
.EX
$ rgs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000
.br
90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave
.br
/sys/bus/w1/devices/28-001414abbeff/w1_slave
.br
.br
$ rgs -a fl "/sys/bus/*" 5000
.br
ERROR: no permission to access file
.br
-67
.br
.EE
.br
.SS GPIO
.br
.IP "\fBGO gc\fP - gpiochip open device"
.IP "" 4
.br
This is a privileged command. See \fBpermits\fP.
.br
This command opens a gpiochip.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 go 0 # open /dev/gpiochip0
.br
1
.br
$ rgs c 1 go 23 # try to open /dev/gpiochip23
.br
-78
.br
ERROR: can not open gpiochip
.br
.EE
.br
.IP "\fBGC h\fP - gpiochip close device"
.IP "" 4
.br
This command closes a gpiochip previously opened by \fBGO\fP.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 gc 1 # first close ok
.br
$ rgs c 1 gc 1 # already closed
.br
-5
.br
ERROR: unknown handle
.br
.EE
.br
.IP "\fBGIC h\fP - gpiochip information"
.IP "" 4
.br
This command gets information for an opened gpiochip. In particular
it gets the number of GPIO on the gpiochip, its name, and its usage.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 gic 1
.br
54 "gpiochip0" "pinctrl-bcm2835"
.br
.EE
.br
.IP "\fBGIL h g\fP - gpiochip line information"
.IP "" 4
.br
This command gets information for GPIO \fBg\fP of an opened gpiochip.
In particular it gets the GPIO number, line flags, its user,
and its purpose.
.br
The meaning of the line flags bits are as given for the mode by \fBGMODE\fP.
.br
The user and purpose fields are filled in by the software which has
claimed the GPIO and may be blank.
.br
\fBExample\fP
.br
.EX
$ for ((i=2; i<10; i++)); do rgs c 1 gil 1 $i; done
.br
2 65536 "SDA1" ""
.br
3 65536 "SCL1" ""
.br
4 65536 "GPIO_GCLK" ""
.br
5 65536 "GPIO5" ""
.br
6 65536 "GPIO6" ""
.br
7 7 "SPI_CE1_N" "spi0 CS1"
.br
8 7 "SPI_CE0_N" "spi0 CS0"
.br
9 65536 "SPI_MISO" ""
.br
.EE
.br
.IP "\fBGMODE h g\fP - GPIO get mode"
.IP "" 4
.br
This command gets the mode for GPIO \fBg\fP of an opened gpiochip.
.br
.EX
Bit Value Meaning
0 1 Kernel: In use by the kernel
1 2 Kernel: Output
2 4 Kernel: Active low
3 8 Kernel: Open drain
4 16 Kernel: Open source
5 32 Kernel: Pull up set
6 64 Kernel: Pull down set
7 128 Kernel: Pulls off set
8 256 LG: Input
9 512 LG: Output
10 1024 LG: Alert
11 2048 LG: Group
12 4096 LG: ---
13 8192 LG: ---
14 16384 LG: ---
15 32768 LG: ---
16 65536 Kernel: Input
17 1<<17 Kernel: Rising edge alert
18 1<<18 Kernel: Falling edge alert
19 1<<19 Kernel: Realtime clock alert
.EE
.br
The LG bits are only set if the query was made by the process that
owns the GPIO.
.br
.IP "\fBGSI h g\fP - GPIO claim for input (simple)"
.IP "" 4
.br
This command claims GPIO \fBg\fP for input.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 gsi 1 23 # claim GPIO 23 for input.
.br
.EE
.br
.IP "\fBGSIX h lf g\fP - GPIO claim for input"
.IP "" 4
.br
This command claims GPIO \fBg\fP for input.
.br
The line flags \fBlf\fP may be used to set the GPIO
as active low, open drain, open source,
pull up, pull down, pull off.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 gsi 1 0 23 # claim GPIO 23 for input.
.br
.EE
.br
.IP "\fBGSO h g\fP - GPIO claim for output (simple)"
.IP "" 4
.br
This command claims GPIO \fBg\fP for output.
.br
.br
The GPIO will be initialised low.
.br
\fBExample\fP
.br
.EX
$ rgs c 1 gso 1 25 # claim GPIO 25 for low output.
.br
.EE
.br
.IP "\fBGSOX h lf g v\fP - GPIO claim for output"
.IP "" 4
.br
This command claims GPIO \fBg\fP for output.
.br
The line flags \fBlf\fP may be used to set the GPIO
as active low, open drain, open source,
pull up, pull down, pull off.
.br
If \fBv\fP is zero the GPIO will be initialised low. If any other
value is used the GPIO will be initialised high.
.br