Beispiel #1
0
void EngineShoutcast::write(unsigned char *header, unsigned char *body,
                            int headerLen, int bodyLen) {
    int ret;

    if (!m_pShout)
        return;

    if (m_iShoutStatus == SHOUTERR_CONNECTED) {
        // Send header if there is one
        if ( headerLen > 0 ) {
            ret = shout_send(m_pShout, header, headerLen);
            if (ret != SHOUTERR_SUCCESS) {
                qDebug() << "DEBUG: Send error: " << shout_get_error(m_pShout);
                if ( m_iShoutFailures > 3 ){
                    if(!serverConnect())
                        errorDialog(tr("Lost connection to streaming server"), tr("Please check your connection to the Internet and verify that your username and password are correct."));
                }
                else{
                    m_iShoutFailures++;
                }

                return;
            } else {
                //qDebug() << "yea I kinda sent header";
            }
        }

        ret = shout_send(m_pShout, body, bodyLen);
        if (ret != SHOUTERR_SUCCESS) {
            qDebug() << "DEBUG: Send error: " << shout_get_error(m_pShout);
            if ( m_iShoutFailures > 3 ){
                if(!serverConnect())
                    errorDialog(tr("Lost connection to streaming server"), tr("Please check your connection to the Internet and verify that your username and password are correct."));
            }
            else{
                m_iShoutFailures++;
            }

            return;
        } else {
            //qDebug() << "yea I kinda sent footer";
        }
        if (shout_queuelen(m_pShout) > 0) {
            qDebug() << "DEBUG: queue length:" << (int)shout_queuelen(m_pShout);
        }
    } else {
        qDebug() << "Error connecting to Shoutcast server:" << shout_get_error(m_pShout);
        // errorDialog(tr("Shoutcast aborted connect after 3 tries"), tr("Please check your connection to the Internet and verify that your username and password are correct."));
    }
}
Beispiel #2
0
int main(int argc,char *argv[])
{
	char sip[16];
	int cfd;

	char str[STACK_SIZE];
	int x, e;
	char ch;
	long int plaintext, ciphertext, deciphertext;
	//getchar();
	extern int print_flag;
	extern int print_flag1;
	print_flag=print_flag1=0;						//md
	
	printf("******* Generating public and private keys { (e,n) , (d,n) } ***** \n\n");
	while(!KeyGeneration(&pub_key, &pvt_key))
	{
		//if(pub_key.public_key.e==pvt_key.private_key.d)continue;
    /*pub_key.public_key.e=523;
    pub_key.public_key.n=623;
    pvt_key.private_key.n=623;
    pvt_key.private_key.d=211;*/
	}
	
	printf("\n Public Key of Alice is (n,e): (%ld , %ld)\n\r", pub_key.public_key.n, pub_key.public_key.e);
	printf("\n Private key of Alice is (n,d): (%ld , %ld)\n\r", pvt_key.private_key.n,pvt_key.private_key.d);
   
   strcpy(sip, (argc == 2) ? argv[1] : DEFAULT_SERVER);
   cfd = serverConnect(sip);
   Talk_to_server (cfd);
   close(cfd);

return 0;
}
//-------------------------------------------------------------------------
bool CVCRControl::CServerDevice::sendCommand(CVCRCommand command, const t_channel_id channel_id, const event_id_t epgid, const std::string& epgTitle, unsigned char apids)
{
	printf("Send command: %d channel_id: "
	       PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
	       " epg: %s(%llx)\n",
	       command,
	       channel_id,
			 epgTitle.c_str(),
	       epgid);
	if(serverConnect())
	{
		std::string extMessage = getCommandString(command, channel_id, epgid, epgTitle, apids);

		printf("sending to vcr-client:\n\n%s\n", extMessage.c_str());
		write(sock_fd, extMessage.c_str() , extMessage.length() );

		serverDisconnect();

		deviceState = command;
		return true;
	}
	else
		return false;

}
int CommunicationServices::initServer(MessageProcessor *mp_p, 
	int tpProtocol, char* port)
{
	mp = mp_p;	//mp should have its tpm set here
	
	mainSocket = serverConnect(port, tpProtocol);
	
	return 0; //temporary
}
Beispiel #5
0
 // ###############################################
int main(int argc, char **argv) {
    int clientfd;
    
    usage(argc);
    
    printf("\n Attempting to establish connection with database server\n");
    clientfd = serverConnect(argv[1]);
    printf("\n Connection established\n");
    
} // End main
int main ( int argc, char *argv[] )
{
   char sip[16];
   int cfd;
   
   make_table();
   strcpy(sip, (argc == 2) ? argv[1] : DEFAULT_SERVER);
   cfd = serverConnect(sip);
   Talk_to_server (cfd);
   close(cfd);
   return 0;
}
int main ( int argc, char *argv[] )
{
   char sip[16];
   int cfd;
   

   printf("******* This is demo program using sockets ***** \n\n");
   
   strcpy(sip, (argc == 2) ? argv[1] : DEFAULT_SERVER);
   cfd = serverConnect(sip);
   Talk_to_server (cfd,argv[2]);
   close(cfd);
}
Beispiel #8
0
void workerFunc()
{
    std::cout << "Worker: running" << std::endl;

    int res;

    MoveStateDeferred *move_state_deferred;
    MoveServerPacket *move_server_packet;
    MoveServerCameraFrameSlicePacket *move_server_camera_frame_slice_packet;

    move_state_deferred = (MoveStateDeferred *)malloc(sizeof(MoveStateDeferred));
    move_server_packet = (MoveServerPacket *)malloc(sizeof(MoveServerPacket));
    move_server_camera_frame_slice_packet = (MoveServerCameraFrameSlicePacket *)malloc(sizeof(MoveServerCameraFrameSlicePacket));

    move_state_deferred->update_success = updateSuccess;
    move_state_deferred->update_failure = updateFailure;
    move_state_deferred->update_camera_success = updateCameraSuccess;
    move_state_deferred->update_camera_failure = updateCameraFailure;
    move_state_deferred->move_server_packet = move_server_packet;
    move_state_deferred->move_server_camera_frame_slice_packet = move_server_camera_frame_slice_packet;

    // Connect
    res = serverConnect("192.168.1.14", "7899", move_state_deferred);
    ROS_ERROR("connect: %d", res);

    while(1)
    {
        io_mutex.lock();
        if(ros_down)
            break;
        io_mutex.unlock();

        boost::posix_time::millisec workTime(3);

        // Pretend to do something useful...
        boost::this_thread::sleep(workTime);
    }

    io_mutex.unlock();

    // Disconnect
    res = serverDisconnect();
    ROS_ERROR("disconnect: %d", res);

    // Free heap
    free(move_state_deferred);
    free(move_server_packet);
    free(move_server_camera_frame_slice_packet);

    std::cout << "Worker: finished" << std::endl;
}
Beispiel #9
0
void EngineShoutcast::process(const CSAMPLE* pBuffer, const int iBufferSize) {
    //Check to see if Shoutcast is enabled, and pass the samples off to be broadcast if necessary.
    bool prefEnabled = (m_pConfig->getValueString(ConfigKey(SHOUTCAST_PREF_KEY,"enabled")).toInt() == 1);

    if (!prefEnabled) {
        if (isConnected()) {
            // We are conneced but shoutcast is disabled. Disconnect.
            serverDisconnect();
            infoDialog(tr("Mixxx has successfully disconnected from the shoutcast server"), "");
        }
        return;
    }

    // If we are here then the user wants to be connected (shoutcast is enabled
    // in the preferences).

    bool connected = isConnected();

    // If we aren't connected or the user has changed their preferences,
    // disconnect, update from prefs, and reconnect.
    if (!connected || m_pUpdateShoutcastFromPrefs->get() > 0.0f) {
        if (connected) {
            serverDisconnect();
        }

        // Initialize/update the encoder and libshout setup.
        updateFromPreferences();

        if (serverConnect()) {
            infoDialog(tr("Mixxx has successfully connected to the shoutcast server"), "");
        } else {
            errorDialog(tr("Mixxx could not connect to streaming server"),
                        tr("Please check your connection to the Internet and verify that your username and password are correct."));
        }
    }

    // If we aren't connected, bail.
    if (m_iShoutStatus != SHOUTERR_CONNECTED)
        return;

    // If we are connected, encode the samples.
    if (iBufferSize > 0 && m_encoder){
        m_encoder->encodeBuffer(pBuffer, iBufferSize);
    }

    // Check if track metadata has changed and if so, update.
    if (metaDataHasChanged()) {
        updateMetaData();
    }
}
Beispiel #10
0
int
main(int argc, char *argv[]) {
    char *me, *server=NULL;
    int opt; /* current option being parsed */
    unsigned short port=0;

    me = argv[0];
    while ((opt = getopt(argc, argv, "qs:p:")) != -1)
        switch (opt) {
        case 'q':
            quiet = 1;
            break;
        case 's':
            server = optarg;
            break;
        case 'p':
            if (1 != sscanf(optarg, "%hu", &port)) {
                fprintf(stderr, "%s: couldn't parse \"%s\" as port for -p\n",
                        me, optarg);
                break;
            }
            break;
        default:
            usage(me);
        }
    if (!( server && port )) {
        usage(me);
    }

    /* gets the socket for the connection with the server */
    connfd = serverConnect(server, port);
    if (-1 == connfd) {
        fprintf(stderr, "%s: Couldn't connect to server %s:%u\n",
                me, server, port);
        exit(1);
    }

    textInit();

    exit(0);
}
Beispiel #11
0
//-------------------------------------------------------------------------
bool CVCRControl::CServerDevice::sendCommand(CVCRCommand command, const t_channel_id channel_id, unsigned long long epgid, uint apid)
{
	printf("Send command: %d channel_id: %x epgid: %llx\n",command, channel_id, epgid);
	if(serverConnect())
	{
		char tmp[40];
		string extCommand="unknown";
		string ext_channel_id = "error";
		string ext_channel_name = "unknown";
		string extEpgid="error";
		string extVideoPID="error";
		string extAudioPID="error";
		string extEPGTitle="not available";
		sprintf(tmp,"%u", channel_id);
		ext_channel_id = tmp;
		sprintf(tmp,"%llu", epgid);
		extEpgid = tmp;
//		sprintf(tmp,"%u", g_RemoteControl->current_PIDs.PIDs.vpid );
		CZapitClient::responseGetPIDs pids;
		g_Zapit->getPIDS (pids);
 		CZapitClient::CCurrentServiceInfo si = g_Zapit->getCurrentServiceInfo ();
		sprintf(tmp,"%u", si.vdid );
		extVideoPID = tmp;
//		sprintf(tmp,"%u", g_RemoteControl->current_PIDs.APIDs[g_RemoteControl->current_PIDs.PIDs.selected_apid].pid);
		if(apid==0)
			apid=(uint)si.apid;
		sprintf(tmp,"%u", apid);
		extAudioPID = tmp;

		CZapitClient::BouquetChannelList channellist;     
		g_Zapit->getChannels(channellist);
		CZapitClient::BouquetChannelList::iterator channel = channellist.begin();
		for(; channel != channellist.end();channel++)
		{
			if(channel->channel_id==channel_id)
			{
				ext_channel_name=channel->name;
				break;
			}
		}

		CSectionsdClient sections;
		CSectionsdClient::responseGetCurrentNextInfoChannelID current_next;
		if(sections.getCurrentNextServiceKey(channel_id, current_next))
		{
			extEPGTitle=current_next.current_name;
		}

		switch(command)
		{
			case CMD_VCR_RECORD: extCommand="record";
				break;
			case CMD_VCR_STOP: extCommand="stop";
				break;
			case CMD_VCR_PAUSE: extCommand="pause";
				break;
			case CMD_VCR_RESUME: extCommand="resume";
				break;
			case CMD_VCR_AVAILABLE: extCommand="available";
				break;
			case CMD_VCR_UNKNOWN:
			default:
				printf("CVCRControl: Unknown Command\n");
		}

		string extMessage = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n\n";
		extMessage +="<neutrino commandversion=\"1\">\n";
		extMessage +="    <record command=\"" + extCommand + "\">\n";
		extMessage +="        <channelname>" + ext_channel_name + "</channelname>\n";
		extMessage +="        <epgtitle>" + extEPGTitle + "</epgtitle>\n";
		extMessage +="        <onidsid>" + ext_channel_id + "</onidsid>\n";
		extMessage +="        <epgid>" + extEpgid + "</epgid>\n";
		extMessage +="        <videopid>" + extVideoPID + "</videopid>\n";
		extMessage +="        <audiopids selected=\"" + extAudioPID + "\">\n";
		// super hack :-), der einfachste weg an die apid descriptions ranzukommen
		g_RemoteControl->current_PIDs = pids;
		g_RemoteControl->processAPIDnames();
		bool apidFound=false;
		for(unsigned int i= 0; i< pids.APIDs.size(); i++)
		{
			sprintf(tmp, "%u",  pids.APIDs[i].pid );
			extMessage +="            <audio pid=\"" + string(tmp) + "\" name=\"" + string(g_RemoteControl->current_PIDs.APIDs[i].desc)  + "\">\n";
			if(pids.APIDs[i].pid==apid)
				apidFound=true;
		}
		if(!apidFound)
		{
			// add spec apid to available
			extMessage +="            <audio pid=\"" + extAudioPID + "\" name=\"" + extAudioPID  + "\"/>\n";
		}
		extMessage +="        </audiopids>\n";
		extMessage +="    </record>\n";
		extMessage +="</neutrino>\n";

		printf("sending to vcr-client:\n\n%s\n", extMessage.c_str());
		write(sock_fd, extMessage.c_str() , extMessage.length() );

		serverDisconnect();

		deviceState = command;
		return true;
	}
	else
		return false;

}
Beispiel #12
0
int main(){
    init(0);
    
    serverConnect();
    Sleep(1, 0);
    set_motor(1, 50);
    set_motor(2, 50);
    Sleep(2, 0);
    
    
    int initSpeed = 30; // was 30
    float kP = 0.01; // was 0.012 / was 0.0115 / was 0.01 / was 0.008
    float kD = 0.000; // was 0.006
    int prevError = 0;
    //int speedRatio = (int)((255-initSpeed)/1360); // This wont give a nice round number but we need an int.
    // int kI - not nessecary as of

    int threshold = 130;//90; was 120
    int D = 0;
    
    while(true){
        take_picture();
        int P = 0;
        
       // int count = 0;
        
        int blackCheck = 0;
        int blackThreshold = 90;

        int eTotal = 0;
        for(int i = 0; i <= 320; i++){
            int value = get_pixel(i, 60, 3);
            printf("camera value %d\n", value);
            if(value > threshold){
                value = 1 * (i - 160); 
                
                blackCheck++;
                //count++;// 160 being the center line and causing a larger error if the white is detected the furthest away.
            } else {
                //blackCheck++;
                value = 0;
            }
            P += value;
        }
        D = P - prevError;
        prevError = P;
        

        int dSignal = (int) D*kD;
        int pSignal = (int) P*kP;
        //printf("dSig: %d\n", dSignal);
        //printf("pSig: %d\n", pSignal);
        int error = pSignal + dSignal;
        
        
        
        
        if(blackCheck < blackThreshold){
            //do a 180 turn
            
            set_motor(1,-1*50);
            set_motor(2,-1*50);
            //Sleep(0,5000); // was 8000
//
        }
        
       
        
        //printf("dSignal: %d\n", dSignal);
        //printf("pSignal: %d\n", pSignal);
        if (error < 0) { //if left of line
            set_motor(1, initSpeed + (-1*error)); //left motor
            set_motor(2, initSpeed);
            //printf("left: %d\n", initSpeed + (-1*error));
            //printf("right: %d\n", initSpeed);
            Sleep(0,5000);//right motor
        } else if (error > 0) { //if right of line
            set_motor(1, initSpeed); //left motor
            set_motor(2, initSpeed + error);
            //printf("right: %d\n", initSpeed + error);
            //printf("left: %d\n", initSpeed);
            Sleep(0,5000);//right motor
        }/* else { //if on the line
            set_motor(2, initSpeed); //left motor
            set_motor(1, initSpeed); //right motor
        }*/
        //printf("left motor: %d\n", e);
        
    }

    set_motor(1, 0);
    set_motor(2, 0);
    return 0;
}