Bonjour,
J'utilise un Pic Microchip avec controleur Ethernet pour renvoyer vers une page Web des états ou données collectés par le Pic.
Le code suivant ( fonctionne bien ) me permet de faire afficher sur une page web l'etat : "1" ou "0" de plusieurs entrées du Pic.
1 2 3 4 5
|
#define VAR_LED0 (0x00)
#define VAR_ETAT_DIN1 (0x0F)
#define VAR_ETAT_DIN2 (0x1A)
#define VAR_ETAT_DIN3 (0x1B) |
...
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
|
/******************************************************************************
* Function: WORD HTTPGetVar(BYTE var, WORD ref, BYTE* val)
* PreCondition: None
* Input: var - Variable Identifier
* ref - Current callback reference with
* respect to 'var' variable.
* val - Buffer for value storage.
* Output: Variable reference as required by application.
* Side Effects: None
* Overview: This is a callback function from HTTPServer
* Whenever a variable substitution is required on any html
* pages, HTTPServer calls this function 8-bit variable
* identifier, variable reference, which indicates whether
* this is a first call or not. Application should return
* one character at a time as a variable value.
* Note: Since this function only allows one character to be
* returned at a time as part of variable value, HTTPServer()
* calls this function multiple times until
* indicates that there is no more value left for this
* variable.
* On begining, HTTPGetVar() is called with
* ref = HTTP_START_OF_VAR to indicate that this is a first
* call. Application should use this reference to start the
* variable value extraction and return updated reference.
* If there is no more values left for this variable
* application should send HTTP_END_OF_VAR. If there are any
* bytes to send, application should return other than
* HTTP_START_OF_VAR and HTTP_END_OF_VAR reference.
*
* THIS IS AN EXAMPLE CALLBACK.
* MODIFY THIS AS PER YOUR REQUIREMENTS.
******************************************************************************/
WORD HTTPGetVar(BYTE var, WORD ref, BYTE* val)
{
// Temporary variables designated for storage of a whole return result
// to simplify logic needed since one byte must be returned at a time.
static BYTE VarString[32];
// Lit l'etats des ports :
// Identify variable
switch(var)
{
case VAR_LED0:
*val = LED0_IO ? '1':'0';
break;
case VAR_ETAT_DIN1:
*val = ETAT_DIN1 ? '1':'0';
break;
case VAR_ETAT_DIN2:
*val = ETAT_DIN2 ? '1':'0';
break;
case VAR_ETAT_DIN3:
*val = ETAT_DIN3 ? '1':'0';
break; |
Sur le même principe je voudrais que lorsque mon Pic envoi via son port série la valeur 0x40 qu'un message définit soit affiché sur ma page Web.
Cependant, le code suivant, ne fonctionne pas, pourriez vous me dire ce qui est faux, ou ce qu'il faudrait modifier ?
#define VAR_TEST_MESSAGE (0x46)
...
1 2 3 4 5 6 7 8 9 10
|
case VAR_TEST_MESSAGE:
if (ref == HTTP_START_OF_VAR )
if (UART_TXREG == 0x40)
strcpypgm2ram(VarString, "0x40 envoyé sur le port série");
else
strcpypgm2ram(VarString, "En attente d'envoi");
break; |
Partager