Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 01_git/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# makefile of scissors-paper game project
#

HEADERS = scissors.h
OBJECTS = scissors.o

scissors: ${OBJECTS}
gcc -o scissors ${OBJECTS}

scissors.o: scissors.c $(HEADERS)
gcc -c scissors.c

.PHONY: clean

clean:
rm $(OBJECTS)
116 changes: 116 additions & 0 deletions 01_git/scissors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Main file of scissors-paper project
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "scissors.h"
#include <time.h>

//
// Return name of material chose by gamer
//
char* getmaterial(char gamersymb)
{
switch(gamersymb)
{
case SYMB_ROCK:
return STR_ROCK;;
case SYMB_PAPER:
return STR_PAPER;
case SYMB_SCISSORS:
return STR_SCISSORS;
}
}

//
// Calculate who is winner of game
//
int getwinner(char gamer1, char gamer2)
{
int ret = WINNER_NO;

if(gamer1==gamer2) return WINNER_NO;
switch(gamer1)
{
case SYMB_PAPER:
if(SYMB_ROCK==gamer2) ret = WINNER_1;
else ret = WINNER_2;
break;
case SYMB_ROCK:
if(SYMB_PAPER==gamer2) ret = WINNER_2;
else ret = WINNER_1;
break;
case SYMB_SCISSORS:
if(SYMB_ROCK==gamer2) ret = WINNER_2;
else ret = WINNER_1;
break;
default:
ret = WINNER_ERR;
break;
}
return ret;
}

int main()
{
char sgamer[256],gamer,computer,winner;

gamer = computer = winner = 0;
srand(time(NULL)); //Initialisation of random function

for(;;){
// Get user choise
for(;;){
printf("\n\tPlease, choose rock (%c) - paper(%c) - scissors(%c) exit - (%c)\n\t",\
SYMB_ROCK,SYMB_PAPER,SYMB_SCISSORS,SYMB_EXIT);

if(NULL==fgets((char*)sgamer,sizeof(sgamer),stdin)){
printf("\n\tInput error");
return 1;
}
if(2<strlen((char*)sgamer)){
printf("\n\t too much symbols (%li) %s",strlen((char*)sgamer)-1,sgamer);
continue;
}
gamer = sgamer[0];
if(SYMB_EXIT==gamer) return 0;
if((SYMB_PAPER==gamer)||(SYMB_ROCK==gamer)||(SYMB_SCISSORS==gamer)) break;
printf("\n\tWrong choise - (%c)\n\t",gamer);
}

//Get computer choise
computer = rand()%3;
switch(computer){
default:
case 0:
computer = SYMB_ROCK;
break;
case 1:
computer = SYMB_PAPER;
break;
case 2:
computer = SYMB_SCISSORS;
break;
}

// Get winner of game
winner = getwinner(gamer,computer);
if(WINNER_ERR==winner){
printf("\n\tgetwinner error\n\t");
return 1;
}
if(WINNER_NO==winner){
printf("\n\tNo sides!\n\t");
}
else{
if(WINNER_1==winner){
printf("\n\tYou won: %s beats %s",getmaterial(gamer),getmaterial(computer));
}
else{
printf("\n\tI won: %s beats %s",getmaterial(computer),getmaterial(gamer));
}
}
}
return 0;
}
22 changes: 22 additions & 0 deletions 01_git/scissors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __SCISSORS_H__
#define __SCISSORS_H__

/*
* Header file with configuration of
* scissors-paper project
*/
#define SYMB_EXIT 'e'
#define SYMB_PAPER 'p'
#define SYMB_ROCK 'r'
#define SYMB_SCISSORS 's'

#define STR_PAPER "paper"
#define STR_ROCK "rock"
#define STR_SCISSORS "scissors"

#define WINNER_1 1
#define WINNER_2 2
#define WINNER_NO 0
#define WINNER_ERR -1

#endif
66 changes: 66 additions & 0 deletions 02_bash/hwdetect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# delete temporary files
cleanup() {
rm udev.txt
rm udev_new.txt
rm i2cdev.txt
rm i2cdev_new.txt
echo "cleaning up..."
exit
}

echo "Device conecting monitor"
echo "For exit press Ctrl-C"

# detect usb devices
lsusb > udev.txt

# detect i2c devices
i2cdetect -l >i2cdev.txt

while true
do
# create new list of usb devices
lsusb > udev_new.txt
# create new list of i2c devices
i2cdetect -l >i2cdev_new.txt

# look for differences in usb devices list
diffresult=$(diff udev.txt udev_new.txt)
size=$(wc -c < udev.txt)
size_new=$(wc -c < udev_new.txt)
# show differences
if [ $size -ne $size_new ]
then
if [ $size -gt $size_new ]
then
echo "Disconnected USB devices:"
else
echo "Connected USB devices:"
fi
echo $diffresult
mv -f udev_new.txt udev.txt
fi

# look for differences in i2c devices list
diffresult=$(diff i2cdev.txt i2cdev_new.txt)
size=$(wc -c < i2cdev.txt)
size_new=$(wc -c < i2cdev_new.txt)
# show differences
if [ $size -ne $size_new ]
then
if [ $size -gt $size_new ]
then
echo "Disconnected i2c devices:"
else
echo "Connected i2c devices:"
fi
echo $diffresult
mv -f i2cdev_new.txt i2cdev.txt
fi

sleep 1
# check if Ctrl-C pressed and exit
trap 'cleanup' INT
done
9 changes: 9 additions & 0 deletions 03_module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KERNELDIR ?= ../output/build/linux-5.10.7/ #WARNING relative path

obj-m := prmmod.o

all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
18 changes: 18 additions & 0 deletions 03_module/dump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# cd /home/user
# insmod prmmod.ko fprm=10 sprm=20
prmmod: loading out-of-tree module taints kernel.
prmmod: module license 'unspecified' taints kernel.
Disabling lock debugging due to kernel taint
Module with parameters fprm=10 sprm=20 initialisation!
The sum of parameters fprm and sprm is 30
# rmmod prmmod.ko
Module with parameters fprm=10 sprm=20 initialisation!
The substraction of parameters fprm and sprm is -10
Bye Bye...
# insmod prmmod.ko
Module with parameters fprm=1 sprm=2 initialisation!
The sum of parameters fprm and sprm is 3
# rmmod prmmod.ko
Module with parameters fprm=1 sprm=2 initialisation!
The substraction of parameters fprm and sprm is -1
Bye Bye...
33 changes: 33 additions & 0 deletions 03_module/prmmod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Simple module as example of usage modules with parameters
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/module.h>
#include <linux/init.h>

//first parameter initialisation
static int fprm = 1;
module_param(fprm,int,0660);

//second parameter initialisation
static int sprm = 2;
module_param(sprm,int,0660);


int prmmod_init(void)
{
printk(KERN_INFO "Module with parameters fprm=%d sprm=%d initialisation!\n",fprm,sprm);
printk(KERN_INFO "The sum of parameters fprm and sprm is %d\n",fprm+sprm);
return 0;
}


void prmmod_exit(void) {
printk(KERN_INFO "Module with parameters fprm=%d sprm=%d initialisation!\n",fprm,sprm);
printk(KERN_INFO "The substraction of parameters fprm and sprm is %d\n",fprm-sprm);
printk(KERN_INFO "Bye Bye...\n");
}

module_init(prmmod_init);
module_exit(prmmod_exit);
9 changes: 9 additions & 0 deletions 04_basic_struct/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KERNELDIR ?= ../output/build/linux-5.10.7/ #WARNING relative path

obj-m := recv_msg.o

all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
10 changes: 10 additions & 0 deletions 04_basic_struct/dump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# insmod /home/user/recv_msg.ko
# echo message1 > /sys/kernel/recv_msg/list
# echo message2 > /sys/kernel/recv_msg/list
# echo message3 > /sys/kernel/recv_msg/list
# cat /sys/kernel/recv_msg/list
message1
message2
message3
# rmmod /home/user/recv_msg.ko
#
Loading