void test_coderate(){ int i,j,next_coderate; sleep(3); for(i=0 ; i < 4 ; i ++){ switch(i){ case 0 : next_coderate=CR_LORA_4_5; break; case 1 : next_coderate=CR_LORA_4_6; break; case 2 : next_coderate=CR_LORA_4_7; break; case 3 : next_coderate=CR_LORA_4_8; break; default : break; } construct_start_msg(join_response.bandwidth, next_coderate,join_response.datarate, 14, join_response.size); lgw_send(join_response); sleep(1); join_response.coderate=next_coderate; for(j=0 ; j < MSG_PER_SETTING ; j++){ sleep(1); construct_msg(); lgw_send(join_response); } sleep(1); } construct_end_msg(); lgw_send(join_response); }
void test_bandwidth(){ int i,j,next_bandwidth; sleep(2); for(i=0 ; i < 2 ; i ++){ sleep(1); switch(i){ case 0 : next_bandwidth=BW_125KHZ; break; case 1 : next_bandwidth=BW_250KHZ; break; default : break; } construct_start_msg(next_bandwidth, join_response.coderate,join_response.datarate, 14, join_response.size); lgw_send(join_response); sleep(1); join_response.bandwidth=next_bandwidth; for(j=0 ; j < MSG_PER_SETTING ; j++){ sleep(1); construct_msg(); lgw_send(join_response); } } construct_end_msg(); lgw_send(join_response); }
void push_paint(string type, string message, long robot_id, string name) { string msg = construct_msg(type, message, robot_id, name); pthread_mutex_lock( &paint_mutex ); if(!msg.empty()) { painter_queue.push( msg ); } else { //cout << "Got empty string" << endl; } pthread_mutex_unlock( &paint_mutex ); }
void test_power(){ int i,j,next_power; sleep(2); for(i=0 ; i < 8 ; i ++){ next_power = 2 + i*2; construct_start_msg(join_response.bandwidth, join_response.coderate,join_response.datarate, next_power, join_response.size); lgw_send(join_response); sleep(1); join_response.rf_power = next_power; for(j=0 ; j < MSG_PER_SETTING; j++){ sleep(1); construct_msg(); lgw_send(join_response); } sleep(1); } construct_end_msg(); lgw_send(join_response); }
int main(int argc, char ** argv) /***************************************************************************** * Input : * Output : * Function : ******************************************************************************/ { exlcm_sync_t my_data; setup(); // setup LCM while(1) { my_data = construct_msg(BEACON_NODE,ALL_NODES,BEACONSENDER,(double)get_localrealtime().tv_sec + (double)(get_localrealtime().tv_usec / (double)1000000) ); // define send struct exlcm_sync_t_publish(lcm, SYNC_CHANNEL, &my_data); // publish the struct printf("--------MESSAGE PUBLISH:-------\n NUMBER OF PACKETS = %lld\n TIMESTAMP IN SEC = %f\n" , my_data.number_of_packets, my_data.timestamp); sleep(5); } lcm_destroy(lcm); // terminate the allocated memory for lcm return 0; };
void test_sf(){ int i,j,next_datarate; sleep(6); for(i=0 ; i < 6 ; i ++){ switch(i){ case 5 : next_datarate=DR_LORA_SF7; break; case 4 : next_datarate=DR_LORA_SF8; break; case 3 : next_datarate=DR_LORA_SF9; break; case 2 : next_datarate=DR_LORA_SF10; break; case 1 : next_datarate=DR_LORA_SF11; break; case 0 : next_datarate=DR_LORA_SF12; break; default : break; } construct_start_msg(join_response.bandwidth, join_response.coderate,next_datarate, 14, join_response.size); lgw_send(join_response); sleep(1); join_response.datarate=next_datarate; for(j=0 ; j < MSG_PER_SETTING ; j++){ sleep(1); construct_msg(); lgw_send(join_response); } sleep(1); } construct_end_msg(); lgw_send(join_response); }
int RBS(const exlcm_sync_t * msg) /***************************************************************************** * Input : * Output : * Function : ******************************************************************************/ { struct timeval tv; // create timestruct exlcm_sync_t my_data; // create a struct to LCM switch(msg->operation) // statemachine of handling LCM packets { case BEACONSENDER: // case when beacon message is recieved tv = get_localrealtime(); // get timestamp for received packets rbs.realtime = (double)tv.tv_sec + (double)tv.tv_usec / (double)1000000; // calculate time in sec my_data = construct_msg(NODE,ALL_NODES,RECIEVER_TO_RECIEVER,rbs.realtime); // define send struct exlcm_sync_t_publish(lcm, SYNC_CHANNEL, &my_data); // publish the struct print_info(msg); // print all approprivately informations break; case RECIEVER_TO_RECIEVER: // case when nodes inform each other if(msg->sender != NODE) // ONly run RBS for others nodes { //printf("---------------- RECEIVER TO REVEVER SENDER ------------------------\n"); handle_linkedlist(msg); // handle list with packets if(inserting(msg, REMOTETIME, sample_remoterealtime(msg))) // inserting time for remote nodes printf("FAILURE IN INSERTING REMOTETIME \n"); if(getting(msg, DATASIZE, ZERO) == ZERO & rbs.nodes[msg->sender].reach_max == ZERO) // this is also run the first time { rbs.realtime_0 = rbs.realtime; // first time for current stored if(inserting(msg, LOCALTIME, 0)) // store realtime in nodes printf("FAILURE IN INSERTING REMOTETIME first run \n"); } else { if(inserting(msg, SCALETIME, rbs.realtime - rbs.realtime_0)) // store scalerealtime in nodes printf("FAILURE IN INSERTING SCALETIME \n"); } if(inserting(msg, LOCALTIME, rbs.realtime)) // store realtime in nodes printf("FAILURE IN INSERTING REALTIME \n"); if(inserting(msg, OFFSET, sample_remoterealtime(msg) - rbs.realtime)) // store offset (remote - current) printf("FAILURE IN INSERTING OFFSET \n"); mean_offset(rbs.nodes[msg->sender].end); // calculate meanoffset if(rbs.nodes[msg->sender].end->next != NULL) // skip first sample leastsquarelinarregression(rbs.nodes[msg->sender].end); // calculate leastsquareregression //printf("----------------END RECEIVER TO REVEVER SENDER ------------------------\n"); print_info(msg); // print all approprivately informations rbs.nodes[msg->sender].n++; // count x increment } break; default: break; } return 0; }
/*************************************************************************** Function: modify_alias Description: read old alias and check, write new alias to alias.conf & push to cloud server Input: cgi_result, the return value of cgiFormString old_alias_str, null terminated, not check yet new_alias_str, null terminated, already check Output: Return: 0 OK, other Error Others: none ***************************************************************************/ int modify_alias(cgiFormResultType cgi_result, const char * old_alias_str, const char * new_alias_str) { int fd_alias; char gateway_alias[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1]; int res; int len, tries = 5; int mqid; struct client_admin_msgbuf mesg; fd_alias = open(FEATURE_GDGL_ALIAS_PATH, O_RDWR, 0777); if (fd_alias < 0) { return clientAdminAliasFileOpenErr; } res = write_lock(fd_alias, 0, SEEK_SET, 0); if (res == -1) { close(fd_alias); return clientAdminAliasFileLockErr; } // Read old alias res = read(fd_alias, gateway_alias, FEATURE_GDGL_ACCOUNT_MAX_LEN); if (res < 0) { close(fd_alias); return clientAdminAliasFileReadErr; } gateway_alias[res] = '\0'; //add yanly150625 if((gateway_alias[res-1] == 0x0a)||(gateway_alias[res-1] == 0x0d)) { //如果最后一个字符等于换行符号或者回车键,就换成结束符 gateway_alias[res-1] = '\0'; } // Check old alias res = check_alias(cgi_result, old_alias_str, gateway_alias); if (res != 0) { close(fd_alias); return res; } // Check if old == new if (strcmp(old_alias_str, new_alias_str) == 0) { close(fd_alias); return clientAdminTwoAliasEqualErr; } // Push to cloud //if push failed, return push error if ( (res = push_to_cloud(modifyAliasType, "modifyalias", old_alias_str, new_alias_str)) < 0 ) { close(fd_alias); return clientAdminPushToCloudErr; } else if (res > 0) { close(fd_alias); return res; } // Write new alias len = strlen(new_alias_str); while (tries > 0) { // seek to beginning of file res = lseek(fd_alias, 0, SEEK_SET); if (res < 0) { close(fd_alias); return clientAdminAliasFileSeekErr; } // truncate the file to 0 byte res = ftruncate(fd_alias, 0); if (res < 0) { close(fd_alias); return clientAdminAliasFileTruncErr; } res = writen(fd_alias, new_alias_str, len); if (res != len) { tries--; } else { break; } } if (tries == 0) { close(fd_alias); return clientAdminAliasFileWriteErr; } close(fd_alias); //also unlock // Send IPC msg mqid = msgget(CLIENTADMIN_MQ_KEY, 0); if (mqid == -1) { CA_DEBUG("msgget error %d:%s\n", mqid, strerror(errno)); } else { len = construct_msg(clientAdmintMsgAlias, new_alias_str, &mesg); if (len > 0) { res = msgsnd(mqid, &mesg, len, 0); if (res == -1) { CA_DEBUG("msgsnd error %s\n", strerror(errno)); } } } return 0; }
/*************************************************************************** Function: modify_password Description: read old password and check, write new password to password.conf & push to cloud server Input: cgi_result, the return value of cgiFormString old_passwd_str, null terminated, not check yet new_passwd_str, null terminated, already check Output: Return: 0 OK, other Error Others: none ***************************************************************************/ int modify_password(cgiFormResultType cgi_result, const char * old_passwd_str, const char * new_passwd_str) { int fd_passwd; char gateway_passwd[FEATURE_GDGL_PASSWD_MAX_LEN + 1]; int res; int len, tries = 5; int mqid; struct client_admin_msgbuf mesg; fd_passwd = open(FEATURE_GDGL_PASSWD_PATH, O_RDWR, 0777); if (fd_passwd < 0) { return clientAdminPasswdFileOpenErr; } res = write_lock(fd_passwd, 0, SEEK_SET, 0); if (res == -1) { close(fd_passwd); return clientAdminPasswdFileLockErr; } // Read old password res = read(fd_passwd, gateway_passwd, FEATURE_GDGL_PASSWD_MAX_LEN); if (res < 0) { close(fd_passwd); return clientAdminPasswdFileReadErr; } gateway_passwd[res] = '\0'; if((gateway_passwd[res-1] == 0x0a)||(gateway_passwd[res-1] == 0x0d)) { //如果最后一个字符等于换行符号或者回车键 gateway_passwd[res-1] = '\0'; } // Check old password res = check_password(cgi_result, old_passwd_str, gateway_passwd); if (res != 0) { close(fd_passwd); return res; } // Check if old == new if (strcmp(old_passwd_str, new_passwd_str) == 0) { close(fd_passwd); return clientAdminTwoPasswdEqualErr; } // Push to cloud //if push failed, return push error if ( (res = push_to_cloud(modifyPasswordType, "modifypassword", old_passwd_str, new_passwd_str)) < 0 ) { close(fd_passwd); return clientAdminPushToCloudErr; } else if (res > 0) { close(fd_passwd); return res; } //debug yan // Write new password len = strlen(new_passwd_str); while (tries > 0) { // seek to beginning of file res = lseek(fd_passwd, 0, SEEK_SET); if (res < 0) { close(fd_passwd); return clientAdminPasswdFileSeekErr; } // truncate the file to 0 byte res = ftruncate(fd_passwd, 0); if (res < 0) { close(fd_passwd); return clientAdminPasswdFileTruncErr; } res = writen(fd_passwd, new_passwd_str, len); if (res != len) { tries--; } else { break; } } // ����ظ���Ȼʧ�ܣ���ʱ�����ϴ洢����Ϣ������ģ�Ӧ����ô����???? if (tries == 0) { close(fd_passwd); return clientAdminPasswdFileWriteErr; } close(fd_passwd); //also unlock // Send IPC msg mqid = msgget(CLIENTADMIN_MQ_KEY, 0); if (mqid == -1) { CA_DEBUG("msgget error %d:%s\n", mqid, strerror(errno)); } else { len = construct_msg(clientAdmintMsgPassword, new_passwd_str, &mesg); if (len > 0) { res = msgsnd(mqid, &mesg, len, 0); if (res == -1) { CA_DEBUG("msgsnd error %s\n", strerror(errno)); } } } return 0; }