nodeAccess.h

Go to the documentation of this file.
00001 #ifndef NODE_ACCESS_H
00002 #define NODE_ACCESS_H
00003 
00014 enum {
00015   WAIT_PACKET_HEADER,
00016   HEADER_RECEIVED,
00017   PACKET_RECEIVED,
00018 
00019   NODE_INFO_MAX = 8,
00020 };
00021 
00022 
00026 typedef struct {
00027   int num;
00028   unsigned char *address[NODE_INFO_MAX];
00029   long target_id[NODE_INFO_MAX];
00030 } nodeInfo_t;
00031 
00032 
00036 typedef struct {
00037   unsigned char *top;
00038   unsigned char *buffer;
00039   unsigned char *data_top;
00040   long first_tag;
00041   unsigned long length;
00042   long target_id;
00043   long unique_id;
00044   unsigned char type;
00045   unsigned char reply;
00046   unsigned char header_checksum;
00047   unsigned short data_num;
00048   unsigned char packet_checksum;
00049 } packetInfo_t;
00050 
00051 
00052 enum {
00053   NODE_ACCESS_RETRY_TIMES = 3,
00054   NODE_ACCESS_PACKET_HEADER_SIZE = 16,
00055 
00056   PACKET_UNKNOWN = -1,
00057   PACKET_WRITE_REQUEST = 0x1,
00058   PACKET_WRITE_RESPONSE = 0x2,
00059   PACKET_READ_REQUEST = 0x4,
00060   PACKET_READ_RESPONSE = 0x6,
00061 
00062   PACKET_FIRST_TAG = 0x42f27b,
00063 };
00064 
00065 
00066 #define ADD_PACKET_DATA(A, B) addPacketData(A,(unsigned char *)&(B),sizeof(B))
00067 #define ADD_WRITE_PACKET_DATA(A, B, C) { B = C; addPacketData(A,(unsigned char *)&(B),sizeof(B)); }
00068 
00069 
00070 #include "cpp_extern_macro.h"
00071 BEGIN_C_DECLS;
00072 
00073 extern void initNodeInfo(nodeInfo_t *node);
00074 extern int registerStructInfo(nodeInfo_t *node,
00075                               unsigned char *top, long target_id);
00076 extern long getStructId(nodeInfo_t *node, unsigned char *top);
00077 extern void initPacketInfo(packetInfo_t *pa, unsigned char *buffer,
00078                            unsigned char *top,
00079                            unsigned char type, long target_id, long unique_id);
00080 extern int terminatePacketInfo(packetInfo_t *pa);
00081 extern char getPacketType(unsigned char *packet_data);
00082 extern long getPacketLength(unsigned char *packet_data);
00083 extern long getPacketUniqueId(unsigned char *packet_data);
00084 extern void writeFromPacketData(unsigned char *packet_data,
00085                                                 unsigned char *top);
00086 extern void addPacketData(packetInfo_t *na, unsigned char *offset,
00087                           unsigned char size);
00088 extern void setPacketReply(packetInfo_t *na, unsigned char reply);
00089 extern int checkHeaderFormat(unsigned char *buffer);
00090 extern int checkFirstTag(unsigned char *buffer);
00091 extern int checkPacketFormat(unsigned char *buffer, int length);
00092 extern long createReadResponsePacket(unsigned char *buffer,
00093                                      unsigned char *top);
00094 extern long createWriteResponsePacket(unsigned char *buffer,
00095                                       unsigned char *top);
00096 extern int removeInvalidPacketHeader(unsigned char *recv_buffer, int filled);
00097 
00098 END_C_DECLS;
00099 #endif /* !NODE_ACCESS_H */
00100 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1