25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

106 satır
2.5 KiB

  1. /**********************************************************************
  2. Project: Automatic cat feeder
  3. Date: march 19 2006
  4. Author: Jean-Fran�ois Martel
  5. Target: PIC 18F252
  6. Compiler: Microchip mcc18
  7. Filename: Protocol.h
  8. File description: Communication protocol implementation.
  9. jean-francois.martel@polymtl.ca
  10. **********************************************************************/
  11. #ifndef BOOTLOADERINTERFACE_H
  12. #define BOOTLOADERINTERFACE_H
  13. #ifndef NETWORKPROTOCOL_H
  14. #define NETWORKPROTOCOL_H
  15. //Protocol buffer specific definitions
  16. #include "ProtocolDefs.h"
  17. #define MASTER_ADDRESS 0x01
  18. #define MY_DEVICE_ADDRESS 0x01
  19. #define ADDRESS 0x01
  20. enum eProtocolUser
  21. {
  22. NETWORK_PROTOCOL_USER_AUDIO_CONSOLE_IF,
  23. NETWORK_PROTOCOL_USER_MASTER_CTRL_IF
  24. };
  25. //State Machine states
  26. enum States
  27. {
  28. Initialization,
  29. RxHeader,
  30. RxAdd,
  31. RxID,
  32. RxMyID,
  33. RxMyAddress,
  34. RxFlags,
  35. RxCMD,
  36. RxSize1,
  37. RxSize2,
  38. RxSize3,
  39. RxSize4,
  40. RxData,
  41. RxCRC
  42. };
  43. //enum DEVICES_IDS
  44. //{
  45. // ID_MASTER, //Master Controller
  46. // ID_CONSOLE, //LCD Console
  47. // ID_PC, //PC
  48. // ID_AV_MUX, //Audio Video Multiplexer
  49. // ID_IR_REMOTE,
  50. // ID_DEADBOLT
  51. //};
  52. //enum MESSAGE_IDS
  53. //{
  54. // TX_NETWORK_ACK = 1,
  55. // RX_GET_STATUS,
  56. // TX_DEADBOLT_STATUS,
  57. //
  58. // MAX_NETWORK_CMD
  59. //};
  60. //State machine states definition
  61. typedef struct stProtocolData
  62. {
  63. unsigned char mRxData[MAX_MESSAGE_SIZE+10];
  64. unsigned char mTxData[MAX_MESSAGE_SIZE+10];
  65. unsigned int DataSize;
  66. unsigned int DataCtr;
  67. unsigned int BufPtr;
  68. unsigned char RxPtr;
  69. unsigned char Command;
  70. unsigned char State;
  71. unsigned char CRC;
  72. unsigned char SenderID;
  73. unsigned char SenderAddress;
  74. unsigned char Flags;
  75. unsigned char IsUpdating;
  76. unsigned char *BmpDataPtr;
  77. }ProtocolData_t;
  78. void ProtocolInit(int User);
  79. void StateMachine(unsigned char STATE, ProtocolData_t *ProtocolData);
  80. void ProtocolAnalyzeNewData(unsigned char RxByte, int User);
  81. void ProtocolAnalyzeBuffer(unsigned char *Data, int size, int User);
  82. void ResetStateMachine(ProtocolData_t *ProtocolData);
  83. void ProtocolExecCmd(void);
  84. void ProtocolAcknowledge(unsigned char Answer,unsigned char Cmd, unsigned char Data);
  85. unsigned char* ProtocolGetFrame(unsigned char DestDevice,unsigned char DestAddress, unsigned char SenderDevice, unsigned char Cmd, unsigned char *Data,unsigned int Size,unsigned char Flags, int *FrameSize);
  86. unsigned char ProtocolCalcCrc(unsigned char* Buffer,unsigned char size);
  87. unsigned char ProtocolIsReceiving(void);
  88. unsigned char *ProtocolMsgDataPtr(ProtocolData_t *ProtocolData);
  89. #endif
  90. #endif