📄 icu.h
字号:
#ifndef __ICU_H
#define __ICU_H
//
// TITLE:
//
// DESCRIPTION:
// definination of the icu
// current version based on mcu6 ver4.1
// REFER to "SiTracs system design.doc"
//
// FILENAME:
// icu.h
//
// AUTHOR(S):
// Andrew Dai(mailto:andrew.x.dai@gmail.com )
//
// CREATION DATE:
// date from: 2007-5-8
//
// MODIFICATION HISTORY:
//
//
//
#include <stdio.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <string.h>
#include <netinet/udp.h>
#include <stdlib.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <linux/if_ether.h>
#include <errno.h>
#include <sys/syslog.h>
#include <stdarg.h>
#include <netdb.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
//#include <sys/socket.h>
//#include <netinet/in.h>
//#include <netinet/tcp.h>
//#include <signal.h>
//#include <sys/stat.h>
//#include <fcntl.h>
#pragma pack(1) /* ensure data in structure beginning at either odd or even offset */
#define PROGRAM_RUN_LEVEL 2 /* 0=normal(running without info), 1=info, 2=warning, 3=error */
#define LEVEL(n) (PROGRAM_RUN_LEVEL>=n)
#define NIC_SCOOT "eth0"
#define PCNUM 1 /* "PC001" */
#define TCCNUM 0
#define MAJORVERSION 7 /* major_version in TC12_acknowledgement_message_type */
#define MINORVERSION 4 /* minor_version in TC12_acknowledgement_message_type */
//#define SN 129573690768EED8B62BBFA5CA88C731
//#define MYMAC 0
#define PROGRAM_NAME "ICU"
#define MAXLINE 4096 /* max text line length */
#define ISDEBUG -1 /* programme in debug state */
#define TRUE -1
#define FALSE 0
#define SCOOTMRK 0x3231
#define UDP_PORT_FOR_MCU6 5051 /* udp port to link with mcu6 */
#define UDP_PORT_FOR_MCU6_REMOTE 5050 /* remote udp port to link with mcu6 */
#define SIZE_OF_ICU_TO_MCU6 22
#define SA struct sockaddr
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
typedef unsigned char size_1;
typedef unsigned short size_2;
typedef unsigned int size_4;
void sys_log(const char *, ...);
typedef struct
{
size_1 MARK;
size_1 REMOTE_TYPE;
size_1 COUNTER;
size_1 CONFIRMNO;
size_1 MODEMNO;
size_1 ADDRESSNO;
size_1 IDONNOTKNOW; /* ??? there sames a byte here */
size_1 GBYTE[2];
size_1 SDBYTE[2];
size_1 STATUS;
size_1 RUNMODE[8];
size_1 CURRENTSTAGE[8];
size_1 PLANNO[8];
size_1 PHASESTAGE[32];
size_1 VALID;
size_1 IODATA[96];
size_1 PHASECURRENT[32];
size_1 VOLTAGE;
size_1 TEMPERATURE;
} MCU6_TO_ICU;
typedef struct
{
size_1 MARK;
size_1 REMOTE_TYPE;
size_1 HOST_TYPE;
size_1 COUNTER;
size_1 FBYTE[1];
size_1 DBYTE[1];
size_1 YEAR;
size_1 MONTH;
size_1 DAY;
size_1 HOUR;
size_1 MINUTE;
size_1 SECOND;
size_1 COMMAND[7];
} ICU_TO_MCU6;
typedef struct
{
size_2 RLen;
size_1 Rbytes[32];
size_1 Handsetcmd[81];
size_1 HandSetRet[81];
size_1 Cbytes[3];
size_2 Ttl;
size_4 Ip;
size_2 Port;
size_1 Ccnt;
size_1 Rcnt;
size_2 Index;
size_1 HandSetReturn;
size_4 NetCount;
size_1 Type_of_OTU; /* 0-ST800 1-MPC */
} OTUType;
typedef struct
{
size_1 Modem;
size_1 Address;
} OTUListType;
typedef struct
{
size_1 Modem;
size_1 Address;
size_1 DataType;
size_1 Index;
} DataFilterType;
typedef struct
{
size_1 UserName[16];
size_4 Ip;
size_2 Port;
size_2 Ttl;
size_1 Level;
size_1 PacketNum;
size_2 DataFilterCnt;
size_2 DataBufSize;
DataFilterType DataFilter[8192];
} UserType;
typedef struct
{
size_1 SMAC[6];
size_1 DMAC[6];
size_1 DATA[2000];
size_1 PTYPE;
} CaptureType;
int packet_fd, udp_mcu6_fd, udp_terminal_fd, nready, maxfdp1;
fd_set rset;
ssize_t bytes_received; /* length of received data from socket*/
ssize_t bytes_tosend; /* length of data to be sent to socket*/
socklen_t socket_addr_len; /* length of address */
struct sockaddr_in packet_addr;
struct sockaddr_in udp_mcu6_cli_addr, udp_mcu6_serv_addr;
struct sockaddr_in udp_terminal_cli_addr, udp_terminal_serv_addr;
char packet_r_buf[MAXLINE];
char packet_s_buf[MAXLINE];
char packet_buf[MAXLINE];
char udp_mcu6_buf[MAXLINE];
char udp_terminal_buf[MAXLINE];
struct ethhdr * peth;
struct iphdr * pip;
struct tcphdr * ptcp;
struct udphdr * pudp;
/*add more protocol head here....*/
struct MCU6_TO_ICU * pmcu6_to_icu;
struct ICU_TO_MCU6 * picu_to_mcu6;
char buffer_to_send[SIZE_OF_ICU_TO_MCU6];
char *ptemp;
char ss[32], dd[32];
OTUListType OTUList[512];
OTUType OTUData[64][8];
UserType UserList[16];
CaptureType ScootData;
size_1 ScootMac[6];
size_1 MyMac[6];
short TC12_MessageCounter;
char tmpstr[256];
int
create_timer (int seconds, int id);
void
showOTUmessage(MCU6_TO_ICU *p);
int
verifyMCU6 (unsigned char buf[], ssize_t len);
void
fillupOTUmessage(MCU6_TO_ICU *, SA *);
void
printHex(unsigned char *, unsigned short , char *);
void *
myStrcpy(size_1 *d,size_1 *s, size_4 len);
size_1
myStrcmp(size_1 *d,size_1 *s, size_4 len);
void
showPacket();
int
checkupPacket();
int
onPacket();
int
checkDestInList();
void
generatePacketHeader();
void
sendTC12_acknowledgement();
void
sendR2();
struct tm *
getDateTime();
#endif /* __ICU_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -