⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb_tools.cpp

📁 LINUX系统下基于ARM处理器的使用GPRS方式通过SOCKET数据包进行煤矿瓦斯监控的程序.这是在黑龙江省现场运行的程序源代码.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "CB_Tools.h"
#include "CB_F1.h"
#include "CB_F3.h"
#include "CB_F4.h"
#include "CB_Freal.h"
#include "CB_String.h"
#include "CB_Profile.h"
#include "CB_Socket.h"
#include "CB_Unit.h"
#include "CB_Split.h"
#include "Afx.h" 
#include <time.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h> 
#include <sys/socket.h> 
#include <sys/ioctl.h>
#include <netinet/in.h> 
#include <net/if.h> 
#include <net/if_arp.h> 
#include <arpa/inet.h> 
#include <errno.h> 
#include <sys/io.h>
#include <unistd.h>



int setSysParam(CB_SysParam *cSysParam,char *argv[])
{
  char *paramFile = argv[1];
  CB_Unit::trim(paramFile);
 
  char pPath[20]; 
  int nReturn;
  CB_Profile cProfile(paramFile);
  
  nReturn = cProfile.getValue("DATATYPE",pPath);
  if(nReturn<0){
    printf("get param error:DATATYPE \n"); 
	return -1;
  }
  cSysParam->setDataType(pPath);
 
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("USER",pPath);
  if(nReturn <0){
    printf("get param error:USER \n"); 
	return -1;
  }
  cSysParam->setUser(pPath);

  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("USERDEST",pPath);
  if(nReturn <0){
    printf("get param error:USERDEST \n"); 
	return -1;
  }
  cSysParam->setUserDest(pPath);
 
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("INIT",pPath);
  if(nReturn <0){
    printf("get param error:INIT \n"); 
	return -1;
  }
  cSysParam->setInit(pPath);
 
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("REAL",pPath);
  if(nReturn <0){
    printf("get param error:REAL \n"); 
	return -1;
  }
  cSysParam->setReal(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("REALDEST",pPath);
  if(nReturn <0){
    printf("get param error:REALDEST \n"); 
	return -1;
  }
  cSysParam->setRealDest(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("SENSOR",pPath);
  if(nReturn <0){
    printf("get param error:SENSOR \n"); 
	return -1;
  }
  cSysParam->setSensor(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("COLLIERY",pPath);
  if(nReturn <0){
    printf("get param error:COLLIERY \n"); 
	return -1;
  }
  cSysParam->setColliery(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("POINT",pPath);
  if(nReturn <0){
    printf("get param error:POINT \n"); 
	return -1;
  }
  cSysParam->setPoint(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("HOST",pPath);
  if(nReturn <0){
    printf("get param error:HOST \n"); 
    return -1;
  }
  cSysParam->setHost(pPath);

  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("PORT",pPath);
  if(nReturn <0){
    printf("get param error:PORT \n"); 
	return -1;
  }
  cSysParam->setPort(pPath);

  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("BAK",pPath);
  if(nReturn <0){
    printf("get param error:BAK \n"); 
	return -1;
  }
  cSysParam->setBak(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("BAKDAY",pPath);
  if(nReturn <0){
    printf("get param error:BAKDAY \n"); 
	return -1;
  }
  cSysParam->setBakDay(pPath);
  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("TEMP",pPath);
  if(nReturn <0){
    printf("get param error:TEMP \n"); 
	return -1;
  }
  cSysParam->setTemp(pPath);

  char param_value[20];
  char type[20];
  //F1  
  CB_Unit::clearBuf(param_value,20);
  strcpy(param_value,"INITDATA_LEN_F1");
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue(param_value,pPath);
  if(nReturn <0){
    printf("get param error:INITDATA_LEN_F1 \n"); 
	return -1;
  }
  CB_Unit::clearBuf(type,20);
  strcpy(type,"F1");
  cSysParam->setInitDataLen(type,atoi(pPath));
  //F3
  CB_Unit::clearBuf(param_value,20);
  strcpy(param_value,"INITDATA_LEN_F3");
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue(param_value,pPath);
  if(nReturn <0){
    printf("get param error:INITDATA_LEN_F3 \n"); 
	return -1;
  }
  CB_Unit::clearBuf(type,20);
  strcpy(type,"F3");
  cSysParam->setInitDataLen(type,atoi(pPath));
  //F4
  CB_Unit::clearBuf(param_value,20);
  strcpy(param_value,"INITDATA_LEN_F4");
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue(param_value,pPath);
  if(nReturn <0){
    printf("get param error:INITDATA_LEN_F4 \n"); 
	return -1;
  }
  CB_Unit::clearBuf(type,20);
  strcpy(type,"F4");
  cSysParam->setInitDataLen(type,atoi(pPath));
  //process  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("PROCESS",pPath);
  if(nReturn <0){
    printf("get param error:PROCESS \n"); 
	return -1;
  }
  cSysParam->setProcess(pPath);
  //delay  
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("DELAY",pPath);
  if(nReturn <0){
    printf("get param error:DELAY \n"); 
	return -1;
  }
  cSysParam->setDelay(atoi(pPath));
  //colliery_name
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("COLLIERY_NAME",pPath);
  if(nReturn <0){
    printf("get param error:COLLIERY_NAME \n"); 
	return -1;
  }
  cSysParam->setCollieryName(pPath);
  //init_jw
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("INIT_JW",pPath);
  if(nReturn <0){
    printf("get param error:INIT_JW \n"); 
	return -1;
  }
  cSysParam->setInitJw(pPath);
  //real_jw
  CB_Unit::clearBuf(pPath,20);
  nReturn = cProfile.getValue("REAL_JW",pPath);
  if(nReturn <0){
    printf("get param error:REAL_JW \n"); 
	return -1;
  }
  cSysParam->setRealJw(pPath);


  return 0;
}

int setUserMsg(CB_SysParam *cSysParam,CB_User *cUser)
{
  cUser->setFileName(cSysParam->getUser());   
  cUser->setDestName(cSysParam->getUserDest());
  if(cUser->instance() <0)
  {
    return -1;
  }
  return 0;
}

int setIP(CB_User *cUser)
{
    
  if(!isSocketEnable)
  {
    printf("can not set the system IP.\n");
	return -1;
  }
  char message[160];
  CB_Unit::clearBuf(message,160);
  
  strcpy(message,"1S+");
  char *p;
  p = cUser->getPerson()->name;
  strcat(message,p);
  strcat(message,"+");
  p =cUser->getPerson()->office;
  strcat(message,p);
  strcat(message,"+");
  p =cUser->getPerson()->area;
  strcat(message,p);
  strcat(message,"+");
  p =cUser->getPerson()->linkman;
  strcat(message,p);
  strcat(message,"+");
  p =cUser->getPerson()->linkway;
  strcat(message,p);
  strcat(message,"+");
  strcat(message,"E");
  CB_Socket cSocket;
  cSocket.initiaze();
  char *rtnBuf = NULL;
  printf("sendData IP:%s\n",message);
  cSocket.send(message,rtnBuf);
  return 0;

}

int convert_jw(CB_SysParam *cSysParam)
{
  struct stat sb;
  stat("/dat/dev.txt",&sb);
  FILE *pFile;
  pFile = fopen("/dat/dev.txt","r");
  char *buf_all = new char[sb.st_size];
  fread(buf_all,sb.st_size,1,pFile);
  fclose(pFile);
  CB_Split *cSplit_temp = new CB_Split(buf_all,'\n');
  int lineCount =0;
  while(1==1){
   char *pStr;
   pStr = cSplit_temp->getNext();
   if(pStr == NULL){
      break;
   }
   lineCount +=1;
  }
  lineCount = 1+(lineCount-1)*2;
  char (*buf_dest)[128]; 
  buf_dest= new char[lineCount][128];
  CB_Split cSplit(buf_all,'\n');
  char buf_init[128];
  CB_Unit::clearBuf(buf_init,128); 
  char sensor[20];
  int i = 0;
  while(1==1)
  {
    char *buf;   
    buf = cSplit.getNext();
	if(buf == NULL)
	{
      break;   
	}
    CB_Unit::lineToStr(buf);
    CB_Unit::trim(buf);
    char chPosition[10];
	char chType[10];
	if(i==0){
	   CB_String str;
	   str.split(buf,',');
	   char *pStr;
       strcpy(buf_init,buf); 
	   pStr = str.getNext();
       if(pStr == NULL)
         continue;
	   CB_Unit::trim(pStr);
	   strcpy(buf_dest[0],"F1");
       strcat(buf_dest[0],",");
	   strcat(buf_dest[0],"30000");
	   strcat(buf_dest[0],",");
	   strcat(buf_dest[0],cSysParam->getCollieryName());
       strcat(buf_dest[0],",");
	   strcat(buf_dest[0],cSysParam->getDataType());
	   strcat(buf_dest[0],",");
	   pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[0],pStr);
	   strcat(buf_dest[0],"\r\n");
	}else{
       CB_String cStr_init;
	   cStr_init.split(buf_init,',');
	   char *pStr_init;
	   strcpy(buf_dest[i],"F3");
       strcat(buf_dest[i],",");
	   pStr_init = cStr_init.getNext();
       strcat(buf_dest[i],"30000");
       strcat(buf_dest[i],",");
	   CB_String str;
	   str.split(buf,',');
	   char *pStr;
       pStr = str.getNext();
       if(pStr == NULL)
         continue;
       strcpy(chPosition,pStr);
       CB_Unit::trim(chPosition);
	   CB_Unit::clearBuf(sensor,20);
	   pStr = str.getNext();
 	   CB_Unit::trim(pStr);
	   strcpy(sensor,pStr);
	   strcat(buf_dest[i],pStr);
	   strcat(buf_dest[i],",");
	   str.getNext(); 
	   pStr = str.getNext(); 
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr);    
       strcat(buf_dest[i],",");
	   pStr = str.getNext(); 
	   strcpy(chType,pStr);
       CB_Unit::trim(chType);
	   char pUnit[20]; 
	   CB_Unit::clearBuf(pUnit,20);
	   pStr = str.getNext();
	   CB_Unit::trim(pStr);
	   strcpy(pUnit,pStr);
	   pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr);
 	   strcat(buf_dest[i],",");
       pStr = str.getNext();
	   CB_Unit::trim(pStr);
	   strcat(buf_dest[i],pStr);
       strcat(buf_dest[i],",");
       strcat(buf_dest[i],pUnit);
       strcat(buf_dest[i],",");
       pStr = cStr_init.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr);
	   strcat(buf_dest[i],",");
       strcat(buf_dest[i],chPosition);
       strcat(buf_dest[i],",");
       strcat(buf_dest[i],chType);
   	   strcat(buf_dest[i],"\r\n");
	}
 
    i+=1;
  }
  int k=0; 
  cSplit.setStr(buf_all);
  cSplit.setSplitChar('\n');
  while(1==1)
  {
    char chPosition[10];
    char chType[10];
    char *buf;   
    buf = cSplit.getNext();
	if(buf == NULL)
	{
      break;   
	}
    CB_Unit::lineToStr(buf);
    CB_Unit::trim(buf);
	if(k==0){
	  k+=1;
	  continue;
	}else{
	   CB_String str;
	   str.split(buf,',');
	   char *pStr;
       CB_String cStr_init;
	   cStr_init.split(buf_init,',');
	   char *pStr_init;
       strcpy(buf_dest[i],"F4");
 	   strcat(buf_dest[i],",");
       cStr_init.split(buf_init,',');
	   pStr_init = cStr_init.getNext();
	   strcat(buf_dest[i],"30000");
       strcat(buf_dest[i],",");
	   str.split(buf,',');
  	   pStr = str.getNext(); 
 	   CB_Unit::trim(pStr);
       strcpy(chPosition,pStr);
	   CB_Unit::trim(pStr);
       pStr = str.getNext();
	   CB_Unit::trim(pStr);
       char point[10];
	   char point_temp[10];
	   int len = strlen(chPosition);
	   if(len == 1){
         strcpy(point,"0");
         strcat(point,chPosition);     
	   }else{
         strcpy(point,chPosition);     
	   }
  	   len = strlen(pStr);
       if(len == 1){
         strcat(point,"0");
         strcat(point,pStr);     
	   }else{
         len = len -2;
		 if(len == 2)
		 {
	       strcat(point,pStr);     
		 }else{
           strcat(point,pStr+len);  
		 }
	   }
	   CB_Unit::trim(point);
       strcat(buf_dest[i],point);
   	   strcat(buf_dest[i],",");
       strcat(buf_dest[i],pStr); 
       strcat(buf_dest[i],",");
       pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr); 
       strcat(buf_dest[i],",");
       str.getNext();
	   str.getNext();
	   str.getNext();
	   str.getNext();
	   str.getNext();
	   pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr); 
       strcat(buf_dest[i],",");
	   pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr); 
       strcat(buf_dest[i],",");
       pStr = str.getNext();
	   CB_Unit::trim(pStr);
       strcat(buf_dest[i],pStr); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -