hello,
maybe the better way is to use a buffer and RX interrupt
2 cases : you have a terminator character at the end of your command (sended by PC terminal Keyboard)
like a <CR> ( code =13 = 0x0D)
or you don't have it ,but you know what is the maximum lenght of your command.
case 1 :
see details in firts part of example.c.txt
use string comparaison :
form of the commande like this : CONS1=xxxx<CR>
CR as terminator
then xxxx value is extract in the code.
Code: Select all
if(DataReady1==1)
{
*(Buffer1+12)=0; // limite taille
CPrint("\r\nRec=");
Print(Buffer1);
p0=strstr(Buffer1,"CONS");
// test cdes CONS1=xxxx<CR> CONS2=xxxx<CR>
if (p0>0) // action to do
{
... etc ....
.... etc ......
case 2 :
see second part in example.c.txt
The buffer is filled with incomming data
and you check individual character inside the buffer to recognize a command
Code: Select all
if (Flag_Buffer1==1) // c'est donc une Interrupt UART
{
p1=Buffer1;
if((*(p1)=='H') && (*(p1+3)=='p')) //Help<CR>
{
UART1_Write_CText("\r\n Help : Help<CR> \r\n");
UART1_Write_CText(" RTC Update: U;14;05;18;15;36;02#<CR>\r\n");
UART1_Write_CText(" exemple pour :14 Mai 2018 02(Lundi) 15H36\r\n");
UART1_Write_CText(" Plage Luminosité Minimale PLM=18:06<CR>\r\n");
UART1_Write_CText(" Aff=1=Affiche Trame en binaire sur terminal sinon, Aff=0 sur Matrices <CR>\r\n");
UART1_Write_CText(" Seepd=xx vitesse de defilement xx de 01 à 99 <CR>\r\n");
UART1_Write_CText(" Msg=x...x de 8 à 40 caracteres Affiche le message x...x pendant 1 mn <CR>\r\n");
UART1_Write_CText(" et affichage Date reduit et pas de temperatures pendant le Msg Affiché <CR>\r\n");
// UART1_Write_CText(" Message à afficher <32 cars : Msg=blabla<CR>\r\n");
CRLF1();
p1=0;
}
if((*(p1)=='U') && (*(p1+20)=='#')) //U;12;05;18;15;36;02;#<CR>
{
UART1_Write_CText(" Cde RTC Update : ");
UART1_Write_Text(Buffer1);
CRLF1();
MAJ_RTC();
.... etc ......
.... etc ......
Case 3 :
NO CR at the end of command
just test individual caractere from the 1rst position in the Buffer1
by systematique pooling ... after RAZ buffer and a little delay to permit the receiving data
(a time window is necessary to detect interrupt and fill the buffer !)