Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions labs/autotools/project/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ AC_CHECK_HEADER(sys/socket.h, [],
[AC_MSG_ERROR(["Couldn't find sys/socket.h"])])


# AC_CHECK_HEADER(sys/verycool.h, [],
# [AC_MSG_ERROR(["Couldn't find the cool header"])])

# output files
AC_CONFIG_FILES([Makefile
src/Makefile
Expand Down
4 changes: 2 additions & 2 deletions labs/autotools/project/src/miniserver/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in

bin_PROGRAMS = a.out
a_out_SOURCES = miniserver.c
bin_PROGRAMS = miniserver
miniserver_SOURCES = miniserver.c
7 changes: 5 additions & 2 deletions labs/sysprog/gps/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: init libptmx libnmea gps
all: init libptmx libnmea libhook gps

init:
mkdir -p bin lib include
Expand All @@ -12,13 +12,16 @@ libptmx: init
libnmea: init
cd src/lib/nmea && make

libhook: init
cd src/lib/hook && make

clean:
find . -name *.o | xargs rm -f
rm -rf bin
rm -rf lib
rm -rf include

ok: init libptmx libnmea_ok gps
ok: init libptmx libnmea_ok libhook gps

libnmea_ok:
cd src/lib/nmea && make ok
1 change: 1 addition & 0 deletions labs/sysprog/gps/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ SCRIPT=`readlink -f $0`
ROOT_DIR=`dirname $SCRIPT`

export LD_LIBRARY_PATH=$ROOT_DIR/lib
export LD_PRELOAD=$ROOT_DIR/lib/libhook.so
$ROOT_DIR/bin/gps
8 changes: 8 additions & 0 deletions labs/sysprog/gps/src/lib/hook/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SONAME = libhook.so
GCC = gcc

all:
$(GCC) -g -c -fPIC hook.c -o hook.o
$(GCC) -g -shared -Wl,-soname,$(SONAME) -o $(SONAME) hook.o
# cp hook.h ../../../include
mv $(SONAME) ../../../lib
52 changes: 52 additions & 0 deletions labs/sysprog/gps/src/lib/hook/hook.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <signal.h>

#include <stdarg.h>

#define KNOT_TO_KMH 1.852

int iteration = 0;

void signals_handler(int signal_number)
{
printf("Signal caught and being ignored.\n");
}

int knot_to_kmh_str(float not, size_t size, char * format, char * kmh_str)
{
float kmh = KNOT_TO_KMH * not;
snprintf(kmh_str, size, format, kmh);

#ifndef GPS_OK
iteration++;
if (iteration == 2)
{
puts("working");
}
#endif

return kmh;
}

int printf(const char *format, ...)
{
va_list arg;
int done;

// signals handler
struct sigaction action;
action.sa_handler = signals_handler;
sigemptyset(& (action.sa_mask));
action.sa_flags = 0;
sigaction(SIGINT, & action, NULL);

va_start (arg, format);
done = vfprintf (stdout, format, arg);
va_end (arg);

return done;
}
14 changes: 14 additions & 0 deletions tps/autotools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Autotools

* Question 1: The header located in *sys/socket.h* is verified.

* Question 2: Added the following code: *AC_CHECK_HEADER(sys/verycool.h, [],
[AC_MSG_ERROR(["Couldn't find the cool header"])])*

* Question 3: The macro is used in order to be able to create shared libraries.

* Question 4: Makefile.am is a configuration file used by the automake to generate the Makefile.in

* Question 5: One just has to change the a.out values to miniserver inside *src/miniserver/Makefile.am*

* Question 6:
1 change: 1 addition & 0 deletions tps/minicom.cap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.27,N,00748.68,E,151110,A$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.33,N,00748.74,E,151114,A$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.39,N,00748.80,E,151118,A$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.45,N,00748.86,E,151122,A$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.51,N,00748.92,E,151126,A$GPVTG,056.0,T,035.7,M,006.8,012.6,K$GPGLL,4844.57,N,00748.98,E,151130,A
66 changes: 66 additions & 0 deletions tps/rpi3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# RPI3

## Partie 3: Flashage et UBoot

* Question


## Partie 5: GPIO et relais

* Question 1: There are two partition:
- */dev/mmcblk0p1*: The root of the system, with the configuration for the boot of the os.
- */dev/mmcblk0p2*: With the contents of the filesystem, with folder such as /etc of the root, the home and others.

* Question 2: TX is GPIO14 and RX is GPIO15, they are used for serial communication.

* Question 3: It has the following configuration:
- Baud rate: 115200
- Byte rate: 8 bit
-

* Question 4: The IP address of the board is 172.20.10.26. That was found by running the command *ip a* inside the board, after using the serial connection to access it.

* Question 5: The difference between root and user is that root is not configure through the users.table file, as the super user is always created. In order to access the root user from the ssd connection one needs first to connect with the normal user and then use the *su* command, as root access from the connection is not allowed. Another difference is that the root folder is accessible only with the root user.

* Question 6:
- U-Boot fatload loads a binary file from a dos filesystem.
- setenv sets the environment variables.
- boot boots Linux zImage image from memory.


## Partie 6: I2C et BME280

* Question 1:

* Question 2:
- VCC: input
- GND: ground
for the bus:
- SCL: SCK (serial clock)
- SDA: SDI (serial data)

* Question 3: We see the following now:
*0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77*

* Question 4: Page 32, we see that the slave address is 0x77.

* Question 5:
- For the compilation of bme280.c and linux_userspace.c we used docker.
In order to launch it:
`sudo docker start "id of the docker"`
`sudo docker exec -it "id of the docker" /bin/bash`

- For the cross compilation:
`./../buildroot-precompiled-2017.08/output/host/usr/bin/arm-linux-gcc bme 280.c linux_userspace.c -o bme`
The output is called bme.

- In order to call the sensors on the raspberry it was done `./bme dev/ipc-1`
The values appear, but they seem frozen.
11 changes: 11 additions & 0 deletions tps/tp1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TP 1: System programming: part 1

* Question 1: The makefile is used to specify the steps used to build a project, a make system, with the correct order and linkings between libraries, sources, etc. Make is a build tool used for the aforementioned steps, building executables.

* Question 2: The gcc compiler is used here.

* Question 3: A shared library is a library that may be used by multiple executables at the same time. When linked, they are not copied into the executable, but references to the functions and their locations are specified instead.

* Question 4: An example of an executable binary is the gps generated in *bin/gps*, which could be linked with something such as *gcc gps.c -o gps*

* Question 5: An example of shared library is the one generated in *lib/libnmea.so*. Its creation requires some more steps, being first that the object file has to be generated with position independent code, so that the memory addresses are not overlapped by other code being used simultaneously, and can be done for example with *gcc -c -fpic nmea.c -o nmea.o*. Later, the objects have to be linked in order to create the shared library, which also has to be specified, such as with *gcc -shared libnmea.so nmea.so* (in this case only one object is linked).
44 changes: 44 additions & 0 deletions tps/tp2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Compilation, debug et gestionnaire de signaux

## Exercise 1: GDB et fichier core

* Question 1: The process finishes with a segmentation fault and the core is dumped. It can be deduced that its end was involuntary because it accessed a memory that it did not own.

* Question 2: The signal produced was SIGSEGV, as informed by gdb. It can also be seen by using *echo $?*, which will display the error 139, representing segmentation fault error.

* Question 3: The problem happens at the gps code, with the usage of *nmea_vtg(&vtg)* at line 40 of the source, which triggers an error at the nmea library at line 23 with the command *puts(NULL)*, being NULL a faulty parameter for puts, as it attends a points for a string.

* Question 4: It doesn't succeed in running the binary as it cannot find the shared library. If the *LD_LIBRARY_PATH* variable is fixed to point to the local *lib/* folder, then it runs the binary and crashes the same way as before, waiting for a command from the user to continue the interaction.

* Question 5: The command *ldd* is used to see which shared libraries are linked, that being useful as multiple versions of a library may be installed in the same computer.

* Question 6: By correcting the library being used for the commands that fail.

* Question 7: The command n, short for next, executes until the next line of code in the source, as long as there are debugging annotations allowing that. The command s, short for step, does the same thing, but doesn't enter functions as they appear in the code, skipping their execution.

* Question 8: Remote tools like that are useful when the code is being run a computer different from the one being used, such as in servers and robots, where there are multiple pieces of hardware to be managed.


## Exercise 2: LD_PRELOAD et sigaction

* Questions 1, 2, 3: in their source files

* Question 4: It is an user command.

* Question 5: The signal handler is located from the line 93 to 97 in the gps.c file. The handler is first initialized as a function that processes the signals being caught, first by displaying it, then closing the connection to the ptmx and finally exiting the process correctly. Afterwards, the set of signals is initialized with nothing (empty set), and the modifiers to the signals is also set to none (0 as the flag represents no modifiers). In the end, the sigaction function is called, changing the process to behave when receiving SIGINT signal as previously specified by the action (and the handler inside).

* Question 6: In code.

* Question 7: One way is to just kill the process, by finding its PID and using the kill tool, such as in *kill 88783*, or with *pkill gps*, being gps the name of the executable running. Another alternative is to suspend it with ctrl-z.

* Question 8: It compiles the libnmea with GPS_OK=1, making it not execute the code in lines 20-24 in nmea.c. It works by changing a flag used inside the code during compilation.


## Exercise 3: Terminal série (minicom)

* Question 1: Used the command *minicom -p /dev/pts/X*, being X informed when executing gps.

* Question 2: The speed is how many bits per second are transmitted, the parity is used in case any is expected so to have some fault tolerance (it's set to none) and data is the number of bits of each message.

* Question 3: It was used the function "Capture on/off" inside minicom.