-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hwdetector #7
Open
Kyryl3231
wants to merge
11
commits into
Kernel-GL-HRK:Kyryl.Krynychnyi
Choose a base branch
from
Kyryl3231:Kyryl.Krynychnyi
base: Kyryl.Krynychnyi
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
hwdetector #7
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5418201
homework: task for hardware detector
yekovalyov 4e96f17
hwdetect: Add an empty bash script
Kyryl3231 ad2786f
hwdetect: Add USB to TTL detector
Kyryl3231 fe4c487
hwdetect: Add USB flash drives detector
Kyryl3231 509969f
hwdetect: Add i2c and SD card detector
Kyryl3231 46d1df2
hwdetect: Create example.md
Kyryl3231 80599fa
hwdetect: Move example.md to hwdetect folder
Kyryl3231 b4d991e
hwdetect: Fix deleting of tmp files after script termination
Kyryl3231 16119fa
hwdetect: Fix declaration of trap
Kyryl3231 3310c1e
hwdetect: Format code according to Linux kernel coding style
Kyryl3231 bd3f7a1
device_tree: Add basic overlay file that adds i2c0 device
Kyryl3231 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Home work hot plugged hardware detector | ||
|
||
Create the script 'hwdetect.sh' which detects connected hardware. | ||
For monitor hardware from user level please use /dev folder, | ||
output from lsusb and i2detect (optional). | ||
Most interesting devices are: | ||
- USB to TTL convertors, | ||
- flash drives, | ||
- SD cards, | ||
- i2c devices. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Hardware that is detected from start | ||
|
||
USB to ttl: | ||
ttyUSB0 | ||
|
||
USB flash drives: | ||
/dev/sda | ||
|
||
I2C devices: | ||
i2c-3 unknown i915 gmbus dpd N/A | ||
i2c-1 unknown i915 gmbus dpc N/A | ||
i2c-4 unknown DPDDC-A N/A | ||
i2c-2 unknown i915 gmbus dpb N/A | ||
i2c-0 unknown SMBus I801 adapter at f040 N/A | ||
i2c-5 unknown DPDDC-C N/A | ||
|
||
SD cards: | ||
mmcblk0 | ||
|
||
Active detector | ||
<disconnected< | ||
ttyUSB0 | ||
|
||
>connected> | ||
ttyUSB0 | ||
|
||
<disconnected< | ||
mmcblk0 | ||
|
||
>connected> | ||
mmcblk0 | ||
|
||
>connected> | ||
/dev/sdb | ||
|
||
<disconnected< | ||
/dev/sdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
|
||
usb0=$(mktemp) | ||
flash0=$(mktemp) | ||
sd0=$(mktemp) | ||
i2c0=$(mktemp) | ||
|
||
usb1=$(mktemp) | ||
flash1=$(mktemp) | ||
sd1=$(mktemp) | ||
i2c1=$(mktemp) | ||
|
||
echo -e "Hardware that is detected from start\n" | ||
echo "USB to ttl:" | ||
ls /dev | grep ttyUSB* > $usb0 | ||
if [[ -n $(cat $usb0) ]]; then | ||
cat $usb0 | ||
else | ||
echo "none" | ||
fi | ||
echo | ||
|
||
echo "USB flash drives:" | ||
ls /dev/sd[a-z] > $flash0 | ||
if [[ -n $(cat $flash0) ]]; then | ||
cat $flash0 | ||
else | ||
echo "none" | ||
fi | ||
echo | ||
|
||
echo "I2C devices: " | ||
i2cdetect -l > $i2c0 | ||
if [[ -n $(cat $i2c0) ]]; then | ||
cat $i2c0 | ||
else | ||
echo "none" | ||
fi | ||
echo | ||
|
||
echo "SD cards: " | ||
ls /dev | grep -E "mmcblk[0-9]+$" > $sd0 | ||
if [[ -n $(cat $sd0) ]]; then | ||
cat $sd0 | ||
else | ||
echo "none" | ||
fi | ||
echo | ||
|
||
echo "Active detector" | ||
while true; do | ||
ls /dev | grep ttyUSB* > $usb1 | ||
usb_to_ttl=$(diff --new-line-format=$'>connected> %l\n' --old-line-format=$'<disconnected< %l\n' --unchanged-group-format='' $usb0 $usb1 ) | ||
|
||
ls /dev/sd[a-z] > $flash1 | ||
flash_drives=$(diff --new-line-format=$'>connected> %l\n' --old-line-format=$'<disconnected< %l\n' --unchanged-group-format='' $flash0 $flash1) | ||
|
||
i2cdetect -l > $i2c1 | ||
i2c_devices=$(diff --new-line-format=$'>connected> %l\n' --old-line-format=$'<disconnected< %l\n' --unchanged-group-format='' $i2c0 $i2c1) | ||
|
||
ls /dev | grep -E "mmcblk[0-9]+$" > $sd1 | ||
sd_cards=$(diff --new-line-format=$'>connected> %l\n' --old-line-format=$'<disconnected< %l\n' --unchanged-group-format='' $sd0 $sd1) | ||
|
||
if [[ -n "$usb_to_ttl" ]]; then | ||
for i in $(echo "$usb_to_ttl"); do | ||
echo "$i" | ||
done | ||
echo | ||
cat $usb1 > $usb0 | ||
fi | ||
|
||
if [[ -n "$flash_drives" ]]; then | ||
for j in $(echo "$flash_drives"); do | ||
echo "$j" | ||
done | ||
echo | ||
cat $flash1 > $flash0 | 2>/dev/null | ||
fi | ||
|
||
if [[ -n "$i2c_devices" ]]; then | ||
for k in $(echo "$i2c_devices"); do | ||
echo "$k" | ||
done | ||
echo | ||
cat $i2c1 > $i2c0 | ||
fi | ||
|
||
if [[ -n "$sd_cards" ]]; then | ||
for l in $(echo "$sd_cards"); do | ||
echo "$l" | ||
done | ||
echo | ||
cat $sd1 > $sd0 | ||
fi | ||
|
||
sleep 1 | ||
trap 'rm -f $usb0 $usb1 $flash0 $flash1 $i2c0 $i2c1 $sd0 $sd1 && echo -e "\n***********Detection ended***********" && exit' 2 3 15 | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it required to configure signal handlers every second? What will happen in case of program break before end of loop?