Esempio n. 1
0
// Transfers data from sensor to cloud to notify of threshold crossings.
void threshold_crossing(int sig) {
    event_message_t *msg = (event_message_t *) shared_mem;

    msg->packet.pid = getpid();

    send_fifo(msg, CLOUD_FIFO, O_WRONLY | O_NONBLOCK, sizeof(event_message_t));
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
    event_message_t event_msg;
    shared_mem = (void *) 0;

    event_msg.msg_type = REGISTER_KEY;
    event_msg.packet.pid = getpid();
    send_fifo(&event_msg, CLOUD_FIFO, O_WRONLY | O_NONBLOCK, sizeof(event_message_t));

    // Setup the message queue
    msgid = msgget((key_t) 1234, 0666 | IPC_CREAT);
    if (msgid == -1) {
        fprintf(stderr, "msgget failed with error: %d\n", errno);
        exit(EXIT_FAILURE);
    }

    shmid = shmget((key_t) 4321, sizeof(device_event_t), 0666 | IPC_CREAT);
    if (shmid == -1) {
        fprintf(stderr, "shmget faild!\n");
        exit(EXIT_FAILURE);
    }

    child_pid = fork();

    switch(child_pid) {
    case -1:
        perror("fork failed\n");
        exit(EXIT_FAILURE);
    case 0:
        printf("Child: %d\n", getpid());
        child();
        break;
    default:
        printf("Parent: %d\n", getpid());
        parent();
        break;
    }

    exit(EXIT_SUCCESS);
}
Esempio n. 3
0
void vendor_req( void )
{
	u16 wIndex;
	u16 wValue;
	u16 wLength;
	u8 buf[2];
#ifdef CONFIG_NET2270
//	DISABLE;
#endif

	wIndex = ControlData.DeviceRequest.wIndex;
	wValue = ControlData.DeviceRequest.wValue;
	wLength = ControlData.DeviceRequest.wLength;

//	puts( "vendor_req." );

	if( ControlData.DeviceRequest.bmRequestType & USB_ENDPOINT_DIRECTION_MASK )
	{
		switch( wIndex )
		{
			case GET_FIRMWARE_VERSION:
				puts( "Connected.\n" );
				puts( "Select file in FlashTool and download.\n" );
#ifdef CONFIG_NET2270
				send_fifo(EndPoint0, "\x01", 1 );

				/* why??? */
				if( usb_current_block_size > 0 ) {
					//udelay(10);
					read_main_data(EndPointB);
				}
#endif

#ifdef CONFIG_PDIUSB12
				single_transmit( "x01", 1);
#endif

				break;
			case GET_FLASH_STATUS:
				/*
				 * FIXME!!!
				 * NOT COMPLETED. MAKE ME WORK!!!
				 */
				if(bEPPflags.bits.verbose)
				{
					puts( " get flash status.\n" );
				}

				buf[1] = 0;
				switch( upg_buffer_status )
				{
					case UPGBUF_UNUSED:
						buf[0] = 0x00;
						break;
					default:
						buf[0] = 0x02;
						break;
				}
#ifdef CONFIG_NET2270
				send_fifo(EndPoint0, buf, 2 );
#endif
#ifdef CONFIG_PDIUSB12
				D12_WriteEndpoint(1, buf, 2);
#endif
				break;
			default:
				printf( " unknown index. (0x%04x)\n", wIndex );
#ifdef CONFIG_PDIUSB12
				single_transmit(0, 0);
#endif
				break;
		}
	}
	else
	{
		switch( wIndex )
		{
			case SET_FILE_DOWN_HEADER:
				if(bEPPflags.bits.verbose)
				{
					puts( " set file down header.\n" );
				}
				if( set_file_down_header( (struct _FileDownHeader*)ControlData.dataBuffer, wLength ) )
				{
					puts( "download is not accepted\n" );
				}
#ifdef CONFIG_PDIUSB12
				single_transmit(0, 0);
#endif
				break;
			case SET_FILE_DOWN:
				if(bEPPflags.bits.verbose)
				{
					puts( " set file down.\n" );
				}
				set_file_down( (struct _IO_REQUEST*)ControlData.dataBuffer, wLength );
#ifdef CONFIG_PDIUSB12
				single_transmit(0, 0);
#endif
				break;
			case USB_CMD_END:
				if(bEPPflags.bits.verbose)
				{
					puts( " cmd end\n" );
				}
				download_completed();
#ifdef CONFIG_PDIUSB12
				single_transmit(0, 0);
#endif
				break;
			default:
				printf( " unknown index.(0x%04x)\n", wIndex );
#ifdef CONFIG_PDIUSB12
				single_transmit(0, 0);
#endif
				break;
		}
	}

#ifdef CONFIG_NET2270
//	ENABLE;
#endif
}