1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| const USHORT TCPPORT = 7; //Port n° 7
int retval;
short sd;
// create the server and client socket
cSocket S, *T = NULL;
// create the SPI Interface
Config_SPI_HW *ItfSPI;
// Open the server socket
retval = S.Opensocket();
if (retval == API_ERROR)
{
printf("(1) API_ERROR\n");
return 0;
}
else
sd = retval;
// Setup the server socket
S.Bind(htons(TCPPORT));
// Init. the SPI interface
ItfSPI= new Config_SPI_HW();
ItfSPI->InitSPIInterface();
unsigned char data[8*3];
unsigned char zz=0x00;
unsigned char wbuffer[8]={zz,zz,zz,zz,zz,zz,zz,zz};
//on applique la méthode Listen à l'objet S
retval = S.Listen();
T = new cSocket();
// Establish a connection
retval = S.Accept(*T);
if (retval == API_ERROR)
{
printf("(2) API_ERROR : %d\n",retval);
return 0;
}
else
sd = retval;
while(1)
{ commande_present=hal_read_pio(PIN_COMMANDE);
if (T->Established() == 1)
{
//etat 0
if((commande_passe==1)&&(commande_present==0)) // front descendant commande active
{
//traitement sur front descendant
ItfSPI->ReadWriteBlock(data,wbuffer);
while(i++<m);
i=0;
ItfSPI->ReadWriteBlock(data+8,wbuffer); //cette lecture se fait avant le CS2
/* // ceu qui genere des erreurs.
while(i++<2*m);
i=0;
ItfSPI->ReadWriteBlock(data+16,wbuffer);
*/
T->Send(data,8*3);
}
/*
else if((commande_passe==0)&&(commande_present==0))
{
//pas de changement d'etat : front bas
}
else if((commande_passe==0)&& commande_present==1))
{
//front montant
commande_passe=1;
}
else if((commande_passe==1)&&(commande_present==1))
{
//niveau hau
} */
commande_passe=commande_present;
}
else
{ cout<<"conectionarrete"<<endl;
delete T;
//on applique la méthode Listen à l'objet S
retval = S.Listen();
T = new cSocket();
// Establish a connection
retval = S.Accept(*T);
if (retval != API_ERROR)
sd = retval;
}
}// while(1)
return 0;
} |
Partager