Skip to content
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

correction Q6 prog #43

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
correction Q6
Louis Cardinaux committed Nov 19, 2024
commit 9b2581e85f703334c9157cc9dfc20185ab789eb8
35 changes: 21 additions & 14 deletions SourcesPourCorrections/demoCode_frameCutting.c
Original file line number Diff line number Diff line change
@@ -76,16 +76,6 @@ int AssembyDatas(int8_t voltageData, int8_t currentData, int8_t powerData, int8_
middleFrame = resistorData & 0x000000FF;
frame = frame | middleFrame; // update datas with voltage, current, power, resistor

//-- variante 2) LSB on left
/*
frame = (resistorData << 24) & 0xFF000000; // unwrapping and masking -> MSB part
middleFrame = (powerData << 16) & 0x00FF0000;
frame = frame | middleFrame; // update datas with voltage and cuurent
middleFrame = (currentData << 8) & 0x0000FF00;
frame = frame | middleFrame; // update datas with voltage, current and power
middleFrame = voltageData & 0x000000FF;
frame = frame | middleFrame; // update datas with voltage, current, power, resistor
*/

return frame;
}
@@ -104,10 +94,27 @@ int AssembyDatas(int8_t voltageData, int8_t currentData, int8_t powerData, int8_
----------------------------------------------------------------------------------- */
void DatasCutting(int frame)
{
// D�clare une variable de type int8_t et extrait les 8 premiers bits de "frame"
int8_t resistance = frame & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 8 positions vers la droite
int8_t puissance = frame >> 8;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
puissance = puissance & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 16 positions vers la droite
int8_t courant = frame >> 16;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
courant = courant & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 24 positions vers la droite
int8_t tension = frame >> 24;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
tension = tension & 0x000000FF;

//-- display the different frame value --//
printf("-- valeur voltage : \n", );
printf("-- valeur current : \n", );
printf("-- valeur power : \n", );
printf("-- valeur resistor : \n", );
printf("-- valeur voltage : %d \n", tension); //affiche la valeur de tension
printf("-- valeur current : %d \n", courant); //affiche la valeur de courant
printf("-- valeur power : %d \n", puissance); //affiche la valeur de puissance
printf("-- valeur resistor : %d \n", resistance); //affiche la valeur de resistance
}
120 changes: 120 additions & 0 deletions correction Q3/demoCode_frameCutting.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------------- -//
// Projet Name : SolusQ6_decoupageInfo
// File Name : demoCode_franeCutting.c
// Creation Date : 30.10.2024
// Modification Date : 12.11.2024
//
// Author : Philou (Ph. Bovey)
//
// Version : 0.3
//
// Description : source file including the function declaration to the Q6
// test
//
// Remarks : complet programm
//----------------------------------------------------------------------------------*/
//-- Standard libraries delcaration--//
#include <stdint.h> //-- standard library of integer
#include <stdio.h> //-- for the Input-Ouput system

//-- personnal librairies declaration --//
#include "testFunctions.h"

/* -----------------------------------------------------------------------------------
* Function Name : ClearBufferKeyBoard
* Input - Ouput - I/O parameters : =>
=> integer
=> N/A
* Description : clear the Buffer KeyBoard
* Modification Date : 08.11.2024
* Notes : https://www.tutorialspoint.com/c_standard_library/c_function_getchar.htm
----------------------------------------------------------------------------------- */
int8_t ClearBufferKeyBoard()
{
//-- variable declarations --//
char receiveCharcter;

//-- loop to clear the buffer linked at the keyboard --//
do
{
//-- keyboard buffer reading --//
receiveCharcter = getchar();
} while (receiveCharcter != '\n');

return(0); //-> 0 indicates that the buffer is empty
}


/* -----------------------------------------------------------------------------------
* Function Name : AssembyDatas
* Input - Ouput - I/O parameters : => 4x input :
* voltageData (Integer - 1bytes)
* currentData (Integer - 1bytes)
* powerData (Integer - 1bytes)
* resistorData (Integer - 1bytes)
=> 1x ouput :
frame (Integer - 4bytes)
=> N/A
* Description : Q6 solution, assembly of 4 bytes in an only
variable
* Modification Date : 12.11.2024
* Notes : there may be two variants for this function
* only one of which is implemend
----------------------------------------------------------------------------------- */
int AssembyDatas(int8_t voltageData, int8_t currentData, int8_t powerData, int8_t resistorData)
{
//-- variable declarations --//
int frame, middleFrame;

//-- preparation of frame --//
//-- variant 1) LSB on right
frame = (voltageData << 24) & 0xFF000000; // unwrapping of 24bits and masking -> MSB part
middleFrame = (currentData << 16) & 0x00FF0000;
frame = frame | middleFrame; // update datas with voltage and cuurent
middleFrame = (powerData << 8) & 0x0000FF00;
frame = frame | middleFrame; // update datas with voltage, current and power
middleFrame = resistorData & 0x000000FF;
frame = frame | middleFrame; // update datas with voltage, current, power, resistor


return frame;
}


/* -----------------------------------------------------------------------------------
* Function Name : DatasCutting
* Input - Ouput - I/O parameters : => 1x input :
frame (Integer - 4bytes)
=> 0 output :
=> N/A
* Description : Q6 solution, divinding frame into 4 parts
* Modification Date : 14.11.2024
* Notes : there may be two variants for this function
* only one of which is implemend
----------------------------------------------------------------------------------- */
void DatasCutting(int frame)
{
// D�clare une variable de type int8_t et extrait les 8 premiers bits de "frame"
int8_t resistance = frame & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 8 positions vers la droite
int8_t puissance = frame >> 8;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
puissance = puissance & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 16 positions vers la droite
int8_t courant = frame >> 16;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
courant = courant & 0x000000FF;

// D�clare une variable de type int8_t et extrait les 8 bits de "frame" en d�calant les bits de 24 positions vers la droite
int8_t tension = frame >> 24;
// Masque les bits sup�rieurs pour ne garder que les 8 premiers bits
tension = tension & 0x000000FF;

//-- display the different frame value --//
printf("-- valeur voltage : %d \n", tension); //affiche la valeur de tension
printf("-- valeur current : %d \n", courant); //affiche la valeur de courant
printf("-- valeur power : %d \n", puissance); //affiche la valeur de puissance
printf("-- valeur resistor : %d \n", resistance); //affiche la valeur de resistance
}
81 changes: 81 additions & 0 deletions correction Q3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------- -//
// Projet Name : SolusQ6_decoupageInfo
// File Name : main.c
// Creation Date : 31.10.2024
// Modification Date : 12.11.2024
//
// Author : Philou (Ph. Bovey)
//
// Version : 0.2
//
// Description : main programm to use the "demoCode.." source file
//
// Remarks : complet programm
//----------------------------------------------------------------------------------*/
//-- preprocessor directive to delete warnings --//
#pragma warning(disable : 4996) //-- the number corresponds at the warning linked with the scanf function

//-- standard library declaration --//
#include <stdio.h> // for the Input-Ouput system
#include <stdlib.h> // to use the OS commands

//-- personnal library declaration --//
#include "testFunctions.h"

//-- main programm --//
void main()
{
//-- variable declarations --//
char voltage, current, power, resistor;
char bufferInfoTb[4], iteration = 0;

int assembledFrame;

//-- welcome message to the user --//
printf("Solution Complete pour la question %d - TEST%d - Classe %s - Annee : %d \n", NUMBER_QUESTION, VERSION, CLASS, YEAR);

//-- loop to manage the keyboard buffer --//
do
{
//-- user's message and data recovery --//
printf("\ninserer une valeur de tension : ");
scanf("%d", (int*)&voltage);

//-- clear buffer --//
bufferInfoTb[iteration] = ClearBufferKeyBoard();
iteration += 1;

//-- user's message and data recovery --//
printf("\ninserer une valeur de courant : ");
scanf("%d", (int*)&current);

//-- clear buffer --//
bufferInfoTb[iteration] = ClearBufferKeyBoard();
iteration += 1;

//-- user's message and data recovery --//
printf("\ninserer une valeur de puissance : ");
scanf("%d", (int*)&power);

//-- clear buffer --//
bufferInfoTb[iteration] = ClearBufferKeyBoard();
iteration += 1;

//-- user's message and data recovery --//
printf("\ninserer une valeur de resistance : ");
scanf("%d", (int*)&resistor);

//-- clear buffer --//
bufferInfoTb[iteration] = ClearBufferKeyBoard();

} while (!((bufferInfoTb[0] == 0) && (bufferInfoTb[1] == 0) && (bufferInfoTb[2] == 0) && (bufferInfoTb[3] == 0)));

//-- function call --//
assembledFrame = AssembyDatas(voltage, current, power, resistor);

DatasCutting(assembledFrame);

//-- pausing --//
system("pause");

}
35 changes: 35 additions & 0 deletions correction Q3/testFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------------- -//
// Projet Name : SolusQ6_decoupageInfo
// File Name : testFunction.h
// Creation Date : 31.10.2024
// Modification Date : 12.11.2024
//
// Author : Philou (Ph. Bovey)
//
// Version : 0.3
//
// Description : headerfile to implement different protoype
//
// Remarks : complet programm
//----------------------------------------------------------------------------------*/
//-- Standard libraries delcaration--//
#include <stdint.h> //-- standard library of integer

#ifndef TESTS_FUNCTIONS_H
#define TESTS_FUNCTIONS_H

//-- declaration of constants or definitions --//
#define CLASS "SLO1"
#define NUMBER_QUESTION 6
#define YEAR 2024
#define VERSION 01

//-- prototype declaration --//
int8_t ClearBufferKeyBoard(); // clear the Buffer KeyBoard
int AssembyDatas(int8_t voltageData, int8_t currentData, int8_t powerData, int8_t resistorData); // assembly of 4 bytes in an only variable
void DatasCutting(int frame); // divinding frame into 4 parts



#endif // !TESTS_FUNCTIONS_H