/* ---------------------------------------------------------------------- * * 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)); } }
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; }
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; }
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; }
/* ---------------------------------------------------------------------- * * Private Functions * ---------------------------------------------------------------------- */ void handle_msg_unimplemented (void) { MsgBuf* msg = &recvbuf; printf ("Warning. Client received unimplemented message type (type=%d)\n", MSG_OPCODE(msg)); }
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; }
void network_do_coal_survey (void) { MsgBuf msg; MSG_OPCODE(&msg) = MSG_DO_COAL_SURVEY; MSG_LENGTH(&msg) = 0; net_send_message (sock, &msg); }
void network_unrequest_mini_screen (void) { MsgBuf msg; MSG_OPCODE(&msg) = MSG_MINI_SCRN_END; MSG_LENGTH(&msg) = 0; net_send_message (sock, &msg); }
void network_unrequest_mappoint_stats (void) { MsgBuf msg; MSG_OPCODE(&msg) = MSG_MPS_END; MSG_LENGTH(&msg) = 0; net_send_message (sock, &msg); }
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); }
/* ---------------------------------------------------------------------- * * 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); }
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); }
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; }
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); }
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); }
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); }
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); }
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); }
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); }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }