Showing posts with label Remote. Show all posts
Showing posts with label Remote. Show all posts

C Program to Client That Calls The Remote Procedure

Write a C Program to Client That Calls The Remote Procedure ?


Solution:

//La Spada Cristina 0000669010


/* RPC_Client.c: client che chiama la procedura remota */

#include <stdio.h>
#include <rpc/rpc.h>
#include "RPC_xFile.h"

#define COMMAND_SIZE 20

main(int argc, char *argv[]){

CLIENT *cl;
int num;
char *server, *stringa_op1;
char buffer[COMMAND_SIZE], c;
int *risultato_op2; //serve come risultato della funzione in .x che mi restituisce un int

Struttura1 *struttura1;

if (argc < 2) {
fprintf(stderr, "Usage: %s <serverhost>\n", argv[0]);
exit(1);
}
server = argv[1];


cl = clnt_create(server, FILEX, FILEVERS, "udp");

if (cl == NULL) {
clnt_pcreateerror(server);
exit(2);
}

stringa_op1 = (char *)malloc(strlen(buffer) + 1);

do{
printf("\nChe operazione vuoi fare? (A:visualizza dettagli volo, B: elimina volo o uscire) "); 
gets(buffer);


if (buffer == NULL) {
break;
}
else if (strcmp(buffer, "A") == 0) {
printf("inserire id volo: \n");
gets(stringa_op1);
struttura1 = visualizza_dati_1(&stringa_op1, cl); 

if (struttura1->error == -1)
{
printf("l'id non esiste\n");
exit(3);
}
else
{
printf("Trovato volo: \nid: %s\nnumero: %s\norario: %s\npasseggero: %s\ngate: %s\n\n", struttura1->id, struttura1->numero, struttura1->ora, struttura1->nome, struttura1->gate);
}//operazione1

else if (strcmp(buffer, "A") == 0) {
printf("Inserisci id volo da cancellare: ");
gets(stringa_op1);

risultato_op2 = elimina_volo_1(&stringa_op1, cl);
if (risultato_op2== -1)
{
printf("errore nella eliminazione\n");
exit(4);

}
else
{
printf("Eliminazione effettuata correttamente\n");
}
}//operazione2
}while(buffer != NULL && strcmp(buffer, "uscire") != 0);


// Libero le risorse distruggendo il gestore di trasporto
free(stringa_op1);

clnt_destroy(cl);
printf("\nRPC_Client Termino...\n");
exit(0);
}

C Program IR Remote

How to write a C Program IR Remote in C programming Language ?


  1. #include <IRremote.h>
  2. int timing = 5;
  3. int mode = 0;
  4. int rp = 6;
  5. int rv = 0;
  6. int gp = 10;
  7. int gv = 0;
  8. int bp = 9;
  9. int bv = 0;
  10. int RECV_PIN = 11;
  11. int resetpin = 8;
  12. IRrecv irrecv(RECV_PIN);
  13. decode_results results;
  14.  
  15. void setup() {
  16.   irrecv.enableIRIn();
  17. }
  18.  
  19. void loop() {
  20.   if (mode == 1) {
  21.     fading();
  22.   }
  23.   if (mode == 0){
  24.     if (irrecv.decode(&results)){
  25.       if (results.value == 1) {
  26.         if (rv == 0) {
  27.           rv = 255;
  28.         }
  29.         else {
  30.           rv = 0;
  31.         }
  32.       }
  33.       if (results.value == 2) {
  34.         if (gv == 0) {
  35.           gv = 255;
  36.         }
  37.         else {
  38.           gv = 0;
  39.         }
  40.       }
  41.       if (results.value == 3) {
  42.         if (bv == 0) {
  43.           bv = 255;
  44.         }
  45.         else {
  46.           bv = 0;
  47.         }
  48.       }
  49.       if (results.value == 9767) {
  50.         mode = 1;
  51.         rv = 0;
  52.         bv = 0;
  53.         gv = 0;
  54.       }
  55.       irrecv.resume();
  56.       analogWrite(rp, rv);
  57.       analogWrite(bp, bv);
  58.       analogWrite(gp, gv);
  59.     }
  60.   }
  61. }
  62.  
  63. void fading() {
  64.   if (mode == 1) {
  65.     if (rv == 0 && bv == 0 && gv ==0){
  66.       for (rv == 0; rv <= 254; rv++){
  67.         analogWrite(rp, rv);
  68.         delay(timing);
  69.       }
  70.     }
  71.   }
  72.   if (mode == 1) {
  73.     if (rv == 255 && bv == 0 && gv ==0){
  74.       for (bv == 0; bv <= 254; bv++){
  75.         analogWrite(bp, bv);
  76.         delay(timing);
  77.       }
  78.     }
  79.   }
  80.   if (mode == 1) {
  81.     if (rv == 255 && bv == 255 && gv ==0){
  82.       for (rv == 255; rv >= 1; rv--){
  83.         analogWrite(rp, rv);
  84.         delay(timing);
  85.       }
  86.     }
  87.   }
  88.   if (mode == 1) {
  89.     if (rv == 0 && bv == 255 && gv ==0){
  90.       for (gv == 0; gv <= 254; gv++){
  91.         analogWrite(gp, gv);
  92.         delay(timing);
  93.       }
  94.     }
  95.   }
  96.   if (mode == 1) {
  97.     if (rv == 0 && bv == 255 && gv ==255){
  98.       for (bv == 255; bv >= 1; bv--){
  99.         analogWrite(bp, bv);
  100.         delay(timing);
  101.       }
  102.     }
  103.   }
  104.   if (mode == 1) {
  105.     if (rv == 0 && bv == 0 && gv ==255){
  106.       for (rv == 0; rv <=254; rv++){
  107.         analogWrite(rp, rv);
  108.         delay(timing);
  109.       }
  110.     }
  111.   }
  112.   if (mode == 1) {
  113.     if (rv == 255 && bv == 0 && gv ==255){
  114.       for (bv == 0; bv <=254; bv++){
  115.         analogWrite(bp, bv);
  116.         delay(timing);
  117.       }
  118.     }
  119.   }
  120.   if (mode == 1) {
  121.     if (rv == 255 && bv == 255 && gv ==255){
  122.       for (bv == 255; bv >= 1; bv--){
  123.         rv--;
  124.         gv--;
  125.         analogWrite(rp, rv);
  126.         analogWrite(bp, bv);
  127.         analogWrite(gp, gv);
  128.         delay(timing);
  129.       }
  130.     }
  131.   }
  132. }
  133.  
  134. void ircheck() {
  135.   if (irrecv.decode(&results)) {
  136.     if (results.value == 9767) {
  137.       mode = 0;
  138.       irrecv.resume();
  139.       pinMode(8, OUTPUT);
  140.     }
  141.   }
  142. }