Exemplo n.º 1
0
/* ---------------------------------------------------------------------- *
 * Public Functions -- Incoming messages
 * ---------------------------------------------------------------------- */
void 
client_handle_message (void)
{
    MsgBuf* msg = &recvbuf;
    if (MSG_OPCODE(msg) >= SERVER_MSG_MIN && 
	MSG_OPCODE(msg) <= SERVER_MSG_MAX) {
	printf ("Client -- handling message..\n");
	msg_handlers[MSG_OPCODE(msg)-SERVER_MSG_MIN]();
    } else {
	printf ("Warning. Client received an ill-formed message (type=%d)\n",
		MSG_OPCODE(msg));
    }
}
Exemplo n.º 2
0
static int setrov_fun( int sockfd, msg_head_t *pMsgHead, char *msg_data )
{
    printf("setrov\n");
    int res = -1;
    char *cmd = "fix none\r\n";

	if ( !pMsgHead )
	{
		return ERR;
	}

	if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,SETROV) )
	{
		logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                    MSG_OPCODE( pMsgHead->msg_type ) );
		return ERR;
	}

      if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
          logi("write error");
          return ERR;
      }
    
//      cmd_response_massage(sockfd,pMsgHead,"ok",strlen("ok"));
#if 0
      printf("setrov successfully\n");
#endif
	return OK;
}
Exemplo n.º 3
0
static int setdir_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1;
    char cmd[1024],basebool;
    utab_t *utab;
    char *mode[] ={
        "snb","swb","dnb","swb"
    };

    if(!msg_data || !pMsgHead) return ERR;
    if(pMsgHead->msg_type != MSG_TYPE(CATEGORY_CONFIG,DIRSET)){
        logi("msg_type(A%d,%d) wrong\n",MSG_CATEGORY(pMsgHead->msg_type),
                MSG_OPCODE(pMsgHead->msg_type));
        return -1;
    }
    utab = (utab_t*)msg_data;
    basebool = utab->baseline == 0.0 ? 0 : 1;
    if(basebool) sprintf(cmd,"set %s %f\r\n",mode[utab->type+basebool],utab->baseline);
    else         sprintf(cmd,"set %s\r\n",mode[utab->type+basebool]);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return -1;
    }
    
    return OK;
}
Exemplo n.º 4
0
static int state_fun( int sockfd, msg_head_t *pMsgHead, char *msg_data )
{
    int res = -1;
    char *cmd = "log oemstatus ontime 1\r\n";
#if 0
    struct tm *timer;
#endif

	if ( !pMsgHead )
	{
		return ERR;
	}

	if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_GUIDE,STATE ) )
	{
		logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                    MSG_OPCODE( pMsgHead->msg_type ) );
		return ERR;
	}

      if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
          logi("write error");
          return ERR;
      }

      pthread_mutex_lock(&lock);
      msg_head[0] = *pMsgHead;
      sock = sockfd;
      pthread_mutex_unlock(&lock);

	return OK;
}
Exemplo n.º 5
0
/* ---------------------------------------------------------------------- *
 * Private Functions
 * ---------------------------------------------------------------------- */
void 
handle_msg_unimplemented (void)
{
    MsgBuf* msg = &recvbuf;
    printf ("Warning. Client received unimplemented message type (type=%d)\n",
	    MSG_OPCODE(msg));
}
Exemplo n.º 6
0
static int action_fun( int sockfd, msg_head_t *pMsgHead, char *msg_data )
{
    int res = -1;
    char *cmd = "log satinfo ontime 1\r\n";

	if ( !pMsgHead )
	{
		return ERR;
	}

	if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_GUIDE,ACTION) )
	{
		logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                    MSG_OPCODE( pMsgHead->msg_type ) );
		return ERR;
	}

      if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
          logi("write error");
          return ERR;
      }

      pthread_mutex_lock(&lock);
      msg_head[1] = *pMsgHead;
      sock = sockfd;
      pthread_mutex_unlock(&lock);

	return OK;
}
Exemplo n.º 7
0
void 
network_do_coal_survey (void)
{
    MsgBuf msg;
    MSG_OPCODE(&msg) = MSG_DO_COAL_SURVEY;
    MSG_LENGTH(&msg) = 0;
    net_send_message (sock, &msg);
}
Exemplo n.º 8
0
void
network_unrequest_mini_screen (void)
{
    MsgBuf msg;
    MSG_OPCODE(&msg) = MSG_MINI_SCRN_END;
    MSG_LENGTH(&msg) = 0;
    net_send_message (sock, &msg);
}
Exemplo n.º 9
0
void
network_unrequest_mappoint_stats (void)
{
    MsgBuf msg;
    MSG_OPCODE(&msg) = MSG_MPS_END;
    MSG_LENGTH(&msg) = 0;
    net_send_message (sock, &msg);
}
Exemplo n.º 10
0
void 
network_new_city (int* originx, int* originy, int random_village)
{
  MsgBuf msg;
  MSG_OPCODE(&msg) = MSG_NEW_CITY;
  MSG_LENGTH(&msg) = 0;
  net_send_message (sock, &msg);
}
Exemplo n.º 11
0
/* ---------------------------------------------------------------------- *
 * Public Functions -- Outgoing messages
 * ---------------------------------------------------------------------- */
void 
network_join_game (void)
{
  MsgBuf msg;
  MSG_OPCODE(&msg) = MSG_JOIN;
  MSG_LENGTH(&msg) = 0;
  net_send_message (sock, &msg);
}
Exemplo n.º 12
0
void
network_request_mini_screen (int mini_type)
{
    MsgBuf msg;
    Int32* msgp = (Int32*) MSG_BODY(&msg);
    MSG_OPCODE(&msg) = MSG_MINI_SCRN_REQ;
    MSG_LENGTH(&msg) = 1 * sizeof(Int32);
    *msgp++ = htonl(mini_type);
    net_send_message (sock, &msg);
}
Exemplo n.º 13
0
static int setio_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){
    
    int res = -1,i,cmdn = 0;
    char cmd[10][1024];
    data_t *data;
    char *raw[4][10] = {
        { "ranged","gpsephemb","bdsephemb","gloephemb"},
        { "rtcm1033","rtcm1005","rtcm1006","rtcm1004b", 
            "rtcm1104b","rtcm1012b" },
        { "rtcm1033","rtcm1005","rtcm1006","rtcm1074b",
            "rtcm1124b","rtcm1084b" },
        { "gpgga","gpgsv","gprmc","gpgsr","gpgsa",
            "gputa","gpgll","gpzda","gpvtg","gpgst"}
    };
#if 0
    char buff[1024]; int len;
#endif

    if(!msg_data || !pMsgHead) return ERR;
    if(pMsgHead->msg_type != MSG_TYPE(CATEGORY_CONFIG,IOSET)){
        logi("msg_type(A%d,%d) wrong\n",MSG_CATEGORY(pMsgHead->msg_type),
                MSG_OPCODE(pMsgHead->msg_type));
        return -1;
    }
    
    data = (data_t*)msg_data;
    if(data->clientbool){
        sprintf(cmd[0],"setclient %s\r\n",data->ipport);
        if((res = write(cmdfd,cmd[0],strlen(cmd[0]))) == -1){
          logi("write error");
          return -1;
        }

    }

    for(i = 0;i < 10;i++) 
        if(data->datatime[i] != 0)
           sprintf(cmd[cmdn++],"log %s ontime %f\r\n",raw[(int)data->datatype][i],
                data->datatime[i]);


   for(i = 0;i < cmdn;i++)
       if((res = write(cmdfd,cmd[i],strlen(cmd[i]))) == -1){
          logi("write error");
          return -1;
       }

#if 0
   while((len=read(profd,buff,1024)) > 0){
       buff[len] = '\0';
       printf("%s\n",buff);
   }
#endif
    return OK;
}
Exemplo n.º 14
0
void
network_request_mappoint_stats (int x, int y)
{
  MsgBuf msg;
  Int32* msgp = (Int32*) MSG_BODY(&msg);
  MSG_OPCODE(&msg) = MSG_MPS_REQ;
  MSG_LENGTH(&msg) = 2 * sizeof(Int32);
  *msgp++ = htonl(x);
  *msgp++ = htonl(y);
  net_send_message (sock, &msg);
}
Exemplo n.º 15
0
void 
network_launch_rocket (int x, int y)
{
    MsgBuf msg;
    Int32* msgp = (Int32*) MSG_BODY(&msg);
    MSG_OPCODE(&msg) = MSG_LAUNCH_ROCKET;
    MSG_LENGTH(&msg) = 2 * sizeof(Int32);
    *msgp++ = htonl(x);
    *msgp++ = htonl(y);
    net_send_message (sock, &msg);
}
Exemplo n.º 16
0
void
network_send_flags (int x, int y)
{
    MsgBuf msg;
    Int32* msgp = (Int32*) MSG_BODY(&msg);
    MSG_OPCODE(&msg) = MSG_SEND_FLAGS;
    MSG_LENGTH(&msg) = 3 * sizeof(Int32);
    *msgp++ = htonl(x);
    *msgp++ = htonl(y);
    *msgp++ = htonl(MP_INFO(x,y).flags);
    net_send_message (sock, &msg);
}
Exemplo n.º 17
0
void
network_bulldoze_item (int x, int y)
{
  MsgBuf msg;
  Int32* msgp = (Int32*) MSG_BODY(&msg);

  MSG_OPCODE(&msg) = MSG_BULLDOZE_ITEM;
  MSG_LENGTH(&msg) = 2 * sizeof(Int32);
  *msgp++ = htonl(x);
  *msgp++ = htonl(y);
  net_send_message (sock, &msg);
}
Exemplo n.º 18
0
void
network_place_item (int x, int y, int selected_type)
{
  MsgBuf msg;
  Int32* msgp = (Int32*) MSG_BODY(&msg);

  MSG_OPCODE(&msg) = MSG_PLACE_ITEM;
  MSG_LENGTH(&msg) = 3 * sizeof(Int32);
  *msgp++ = htonl(x);
  *msgp++ = htonl(y);
  *msgp++ = htonl(selected_type);
  net_send_message (sock, &msg);
}
Exemplo n.º 19
0
void
network_request_main_screen (void)
{
  MsgBuf msg;
  Int32* msgp = (Int32*) MSG_BODY(&msg);
  MSG_OPCODE(&msg) = MSG_MAIN_SCRN_REQ;
  MSG_LENGTH(&msg) = 4 * sizeof(Int32);
  *msgp++ = htonl(main_screen_originx);
  *msgp++ = htonl(main_screen_originy);
#if defined (commentout)
  /* GCS FIX: Need to give server right size of main screen */
  *msgp++ = htonl(MAIN_WIN_W / 16);
  *msgp++ = htonl(MAIN_WIN_H / 16);
#endif
  net_send_message (sock, &msg);
}
Exemplo n.º 20
0
static int setchannel_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1,i;
    char cmd[1024],*s;
    char *fre[8] = {
        "L1","L2","L3","B1","B2","B3","GL1","GL2"
    },*sys[] = {
        "gps","gln","gal","bds","sbas"
    };
    channelset_t *channelset;
    if(!msg_data || !pMsgHead) return ERR;
    if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,CHANNELSET) ){
        logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                       MSG_OPCODE( pMsgHead->msg_type ) );
        return ERR;
    }
    channelset = (channelset_t *)msg_data;
    for(i = 0;i < 5;i++) if(channelset->closesys[i] != 0){
        s = channelset->closesys[i] == 1 ? "closesys" : "unclosesys";
        sprintf(cmd,"%s %s\r\n",s,sys[i]);
        if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
             logi("write error");
             return ERR;
        }
    }
    for(i = 0;i < 8;i++)
        if(channelset->closefre[i] != 0){
            s =channelset->closefre[i] == 1 ? "close" : "unclose";
            sprintf(cmd,"%s %s\r\n",s,fre[i]);
            if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
                 logi("write error");
                 return ERR;
            }
        }
    for(i = 0;i < MAXPIPE;i++)
        if(channelset->channel[i] != 0){
            s =channelset->channel[i] == 1 ? "close" : "unclose";
            sprintf(cmd,"%s %d\r\n",s,i);
            if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
                 logi("write error");
                 return ERR;
            }
        }

    return OK;

}
Exemplo n.º 21
0
int demo_get_password_fun( int sockfd, msg_head_t *pMsgHead, char *msg_data )
{
	if ( !pMsgHead )
	{
		return ERR;
	}

	if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_DEMO, OP_CODE_DEMO__GET_PASSWORD ) )
	{
		logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ),
                    MSG_OPCODE( pMsgHead->msg_type ) );
		return ERR;
	}

	logi( "get user( %s ) password now\n", msg_data );
	cmd_response_massage( sockfd, pMsgHead, "ok", strlen( "ok" ) );

	return OK;
}
Exemplo n.º 22
0
static int setele_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1;
    char cmd[1024];
    float *data;

    if(!msg_data || !pMsgHead) return ERR;
    if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,ELESET) ){
        logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                       MSG_OPCODE( pMsgHead->msg_type ) );
        return ERR;
    }
    data = (float*)msg_data;
    sprintf(cmd,"ecutoff %f\r\n",*data);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return ERR;
    }

    return OK;
}
Exemplo n.º 23
0
static int setan_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){
    
    int res = -1;
    char cmd[1024],*s;

    if(!msg_data || !pMsgHead) return ERR;
    if(pMsgHead->msg_type != MSG_TYPE(CATEGORY_CONFIG,ANTNSET)){
        logi("msg_type(A%d,%d) wrong\n",MSG_CATEGORY(pMsgHead->msg_type),
                MSG_OPCODE(pMsgHead->msg_type));
        return -1;
    }
    
    s = *msg_data == 1 ? "antn1":"antn2";
    sprintf(cmd,"set %s\r\n",s);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return -1;
    }
    
    return OK;
}
Exemplo n.º 24
0
static int setnet_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1;
    char cmd[1024];
    net_t *net;

    if(!msg_data || !pMsgHead) return ERR;
    if(pMsgHead->msg_type != MSG_TYPE(CATEGORY_CONFIG,NETSET)){
        logi("msg_type(A%d,%d) wrong\n",MSG_CATEGORY(pMsgHead->msg_type),
                MSG_OPCODE(pMsgHead->msg_type));
        return -1;
    }
    net = (net_t*)msg_data;
    sprintf(cmd,"setip %s %s %s %s\r\n",net->ip,net->gateway,net->netmask,net->dns);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return -1;
    }
    
    return OK;
}
Exemplo n.º 25
0
static int setsat_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1,i,j;
    char cmd[1024],*s;
    locksat_t *locksat;
    char *sys[] = {
        "gps","gln","gal","bds","sbas"
    };

    if(!msg_data || !pMsgHead) return ERR;
    if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,SATSET) ){
        logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                       MSG_OPCODE( pMsgHead->msg_type ) );
        return ERR;
    }
    locksat = (locksat_t*)msg_data;
    for(i = 0;i < 5;i++) if(locksat->locksys[i] != 0){
        s = locksat->locksys[i] == 1 ? "lockout" : "unlockout";
        sprintf(cmd,"%s %s\r\n",s,sys[i]);
        if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
             logi("write error");
             return ERR;
        }
    }
    for(j = 0;j < 5;j++){
        for(i = 0;i < MAXSAT;i++)
            if(locksat->lockprn[j][i] != 0){
                s = locksat->lockprn[j][i] == 1 ? "lockout" : "unlockout";
                sprintf(cmd,"%s %s %d\r\n",s,sys[j],i);
                if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
                     logi("write error");
                     return ERR;
                }
            }
    }

    return OK;
}
Exemplo n.º 26
0
static int setbasepos_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1;
    char cmd[1024];
    basepos_t *basepos;

    printf("set base pos\n");
    if(!msg_data || !pMsgHead) return ERR;
    if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,SETBASEPOS) ){
        logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                       MSG_OPCODE( pMsgHead->msg_type ) );
        return ERR;
    }

    basepos = (basepos_t*)msg_data;
    sprintf(cmd,"fix position %.9f %.9f %.4f\r\n",basepos->lat,basepos->lon,basepos->hgt);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return ERR;
    }

    return OK;
}
Exemplo n.º 27
0
static int setengine_fun(int sockfd,msg_head_t *pMsgHead,char *msg_data){

    int res = -1;
    char cmd[1024];
    char *postype[] ={
        "single","rtk","sbasspp","sbasppp",
        "ssrspp","ssrppp"
    };

    if(!msg_data || !pMsgHead) return ERR;
    if ( pMsgHead->msg_type != MSG_TYPE( CATEGORY_CONFIG,ENGINESET) ){
        logi( "msg_type( %d, %d ) wrong\n", MSG_CATEGORY( pMsgHead->msg_type ), 
                       MSG_OPCODE( pMsgHead->msg_type ) );
        return ERR;
    }
    sprintf(cmd,"setpvt %s\\n",postype[(int)*msg_data]);
    if((res = write(cmdfd,cmd,strlen(cmd))) == -1){
         logi("write error");
         return ERR;
    }

    return OK;
}