예제 #1
0
파일: scanner.c 프로젝트: fanqh/MINIScanner
static void scanner_scanning_state_enter(void) {
	
	Source source;
	
	DEBUG(( "scanner, scanning state enter... \n" ));
	
	update_indication();
	
	/** start scanning timeout timer **/
	MessageSendLater(&scanner.task, SCANNER_SCANNING_TIMEOUT_IND, 0, SCANNER_SCANNING_TIMEOUT);
	
	/** pull-down and start timeout timer **/
	trigger_drive_low();
	
	/** MessageSendLater(&scanner.task, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND, 0, SCANNER_SCANNING_PULLDOWN_TIMEOUT); **/
	
	/** clean-up uart source **/
	source = StreamUartSource();
	if (source && SourceSize(source) > 0) {
		
		SourceDrop(source, SourceSize(source));
	}
	
	/** clear barcode **/
	barcode_clear(&scanner.barcode);
}
예제 #2
0
파일: sink_usb.c 프로젝트: NemProjects/BC
/****************************************************************************
NAME 
    usbFileInfo
    
DESCRIPTION
    Get file info (index and size) for a given file name.
    
RETURNS
    void
*/ 
static void usbFileInfo(const char* name, uint8 size_name, usb_file_info* info)
{
    Source source;
    info->index = FileFind(FILE_ROOT, name, size_name);
    source = StreamFileSource(info->index);
    info->size = SourceSize(source);
    SourceClose(source);
}
예제 #3
0
/****************************************************************************
NAME 
	hidConnectedEnter
DESCRIPTION
	Called whenever the HID instance enters the connected state.
RETURNS
	void
*/
static void hidConnectedEnter(HID *hid)
{
	Source source = StreamSourceFromSink(hid->connection[HID_CON_CONTROL].con.sink);

	HID_PRINT(("hidConnectedEnter\n"));

	/* Send a message to ourselves to handle any waiting control packets*/
	if (SourceSize(source) > 0)
		MessageSend(&hid->task, HID_INTERNAL_CHECK_CONTROL_REQ, 0);
}
/****************************************************************************
NAME	
	hfpHandleReceivedData

DESCRIPTION
	Called when we get an indication from the firmware that there's more data 
	received and waiting in the RFCOMM buffer. Parse it.

RETURNS
	void
*/
void hfpHandleReceivedData(HFP *hfp, Source source)
{
    uint16 len;

    /* Cancel all more data messages as we're about to process the whole buffer */
    (void) MessageCancelAll(&hfp->task, MESSAGE_MORE_DATA);

    len = SourceSize(source);

    /* Only bother parsing if there is something to parse */
    while (len > 0)
    {
		/* Keep parsing while we have data in the buffer */
        if (!parseSource(source, &hfp->task))
            break;

		/* Check we have more data to parse */
        len = SourceSize(source);
    }
}
/*! @brief Discard unread input data
 
    Must be performed before deallocating a channel to allow the firmware
    to free it.
*/
void gaiaTransportFlushInput(gaia_transport *transport)
{
    Source source;
    uint16 unread_count;

    source = gaiaTransportGetSource(transport);
    unread_count = SourceSize(source);

    if (unread_count)
    {
	SourceDrop(source,unread_count);
    }
}
예제 #6
0
파일: scanner.c 프로젝트: fanqh/MINIScanner
static void scanner_scanning_state_exit(void) {
	
	Source source;
	
	DEBUG(( "scanner, scanning state exit... \n" ));
	
	MessageCancelAll(&scanner.task, SCANNER_SCANNING_TIMEOUT_IND);
	
	trigger_pull_up();	/** don't forget this, we may exit when pulling-down triggering line **/
	/** MessageCancelAll(&scanner.task, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND); **/
	
	source = StreamUartSource();
	if (source && SourceSize(source) > 0) {
		
		SourceDrop(source, SourceSize(source));
	}
	
	MessageCancelAll(&scanner.task, MESSAGE_MORE_DATA);
	MessageCancelAll(&scanner.task, MESSAGE_MORE_SPACE);
	
	/** clear barcode **/
	barcode_clear(&scanner.barcode);
}
/*lint -e818 -e830 */
void AvrcpPassthrough(AVRCP *avrcp, avc_subunit_type subunit_type, avc_subunit_id subunit_id, bool state, avc_operation_id opid, uint16 operation_data_length, Source operation_data)
{
    
#ifdef AVRCP_DEBUG_LIB	
	if (subunit_type > 0x1F)
	{
		AVRCP_DEBUG(("Out of range subunit type  0x%x\n", subunit_type));
	}
    if (subunit_id > 0x07)
	{
		AVRCP_DEBUG(("Out of range subunit id  0x%x\n", subunit_id));
	}
    if (opid > 0x7F)
	{
		AVRCP_DEBUG(("Out of range op id  0x%x\n", opid));
	}
#endif
    
	if (avrcp->block_received_data || (avrcp->pending && (avrcp->pending != avrcp_next_group) && (avrcp->pending != avrcp_previous_group)))
		avrcpSendPassthroughCfmToClient(avrcp, avrcp_busy);
	else if (!avrcp->sink)
		/* Immediately reject the request if we have not been passed a valid sink */
		avrcpSendPassthroughCfmToClient(avrcp, avrcp_invalid_sink);
	else
	{
		MAKE_AVRCP_MESSAGE(AVRCP_INTERNAL_PASSTHROUGH_REQ);
		message->subunit_type = subunit_type;
		message->subunit_id = subunit_id;
		message->state = state;
		message->opid = opid;

		if (opid == opid_vendor_unique)
		{
			message->operation_data = operation_data;
			message->operation_data_length = operation_data_length;
		}
		else
		{
            if (SourceSize(operation_data))
                SourceEmpty(operation_data);
			message->operation_data = 0;
			message->operation_data_length = 0;
		}

		MessageSend(&avrcp->task, AVRCP_INTERNAL_PASSTHROUGH_REQ, message);
	}
}
static uint32 read_sectors(FileInfoType *file_info, uint32 logical_address, uint32 transfer_length, uint32 area_start_sector)
{
    uint32 start_sector;
    uint32 end_sector;
    uint32 file_end_sector = file_info->end_sector;
    uint16 i = 0;
    Sink sink = StreamUsbEndPointSink(end_point_bulk_out);
    
    /* correct end sector for FAT2, as it's otherwise treated as FAT1 */
    if (area_start_sector == FAT2_SECTOR)
        file_end_sector += SECTORS_PER_FAT;
    
    /* find the start sector and end sector for this type of data */
    start_sector = logical_address - area_start_sector;
    end_sector = start_sector + transfer_length - 1;
    if (end_sector > (file_end_sector - area_start_sector))
        end_sector = file_end_sector - area_start_sector;

    MS_DEBUG(("FAT16: start %ld end %ld fileend %ld log %ld areastart %ld\n",start_sector,end_sector,file_info->end_sector,logical_address,area_start_sector));
    
    /* check to see if the file read should begin at the start of the file */
    if ((file_info->src == 0) || (start_sector < file_info->current_start_sector))
    {
        if (file_info->params)
            file_info->src = StreamRegionSource(file_info->params, file_info->size);
        else
            file_info->src = StreamFileSource(file_info->index);
        file_info->current_start_sector = 0;
        
        MS_DEBUG(("FAT16: new file\n"));
    }
    
    /* seek through the file until the correct sector is reached */
    while ((start_sector > file_info->current_start_sector) && (file_info->current_start_sector < end_sector))
    {
        SourceDrop(file_info->src, BYTES_PER_SECTOR);
        file_info->current_start_sector++;   
        MS_DEBUG(("FAT16: src drop %ld\n",file_info->current_start_sector));
    }    
    
    /* send the data in the sectors from start_sector to end_sector */
    while (i <= (end_sector - start_sector))
    {
        uint8 *buffer = 0;
        uint16 sink_slack = 0;
        uint16 source_size;
        uint16 blocks_in_sink;
        uint16 blocks_in_source;
        uint16 blocks_to_read;
        uint32 bytes_to_read;
        uint32 remaining_bytes;
        uint16 bytes_to_copy = 0;          
        
        /* wait for free space in Sink */
        Fat16_WaitAvailable(sink, BYTES_PER_SECTOR);
        
        sink_slack = SinkSlack(sink);
        source_size = SourceSize(file_info->src);
        blocks_in_sink = sink_slack / BYTES_PER_SECTOR;
        
        /* find the maximum sectors that can be sent */
        if ((source_size % BYTES_PER_SECTOR) == 0)
            blocks_in_source = source_size / BYTES_PER_SECTOR;
        else
            blocks_in_source = source_size / BYTES_PER_SECTOR + 1;
        blocks_to_read = blocks_in_sink > blocks_in_source ? blocks_in_source : blocks_in_sink;
        if (blocks_to_read > (end_sector - i + 1))
            blocks_to_read = end_sector - i + 1;
        bytes_to_read = blocks_to_read * BYTES_PER_SECTOR;
        remaining_bytes = file_info->size - (file_info->current_start_sector * BYTES_PER_SECTOR);
        
        MS_DEBUG(("FAT16: info sink_slack:%d source_size:%d blocks_to_read:%d\n",sink_slack,source_size,blocks_to_read));
        
        if (blocks_to_read == 0)
            break;
        
        if (remaining_bytes < bytes_to_read)
            bytes_to_copy = remaining_bytes;
        else
            bytes_to_copy = bytes_to_read;
                             
        if ((buffer = claimSink(sink, bytes_to_read)) != 0)
        {            
            const uint8 *data_ptr = SourceMap(file_info->src);
            bool flush;

            if (bytes_to_copy < bytes_to_read)
                memset(buffer + bytes_to_copy, 0, bytes_to_read - bytes_to_copy); 
            memmove(buffer, data_ptr, bytes_to_copy);            
            SinkConfigure(sink, VM_SINK_USB_TRANSFER_LENGTH, bytes_to_read);
            flush = SinkFlush(sink, bytes_to_read);
            SourceDrop(file_info->src, bytes_to_copy);
            file_info->current_start_sector += blocks_to_read;
            i += blocks_to_read;
            MS_DEBUG(("FAT16: send bytes %d pos %ld i %d flush %d\n",bytes_to_copy,file_info->current_start_sector,i,flush));
        }   
        else
        {
            break;
        }
    }
    
    /* return the next logical address to process */
    return logical_address + end_sector - start_sector + 1;
}
/****************************************************************************
DESCRIPTION
    Plays back a voice prompt once DSP has loaded
*/
static Source csrVoicePresencesGetPrompt(voice_prompt* prompt, koovox_phrase_data_T * pData)
{
    const uint8* rx_array;
    Source lSource = NULL;
    uint16 index;

    char file_name[17];

	PRINT(("***check_the_source***\n"));

    if(!pData)
        return NULL;

    /* Must be a prompt, work out the index of the prompt */
    index = pData->prompt_id;
    
    /* Adjust for language */
    index += (pData->language * present_header.no_prompts_per_lang);

	PRINT(("***check prompt id***\n"));
	
    /* Sanity checking */
    if(index >= present_header.no_prompts || !prompt )
        return NULL;
    
    PRINT(("PRESENT: Play prompt %d of %d\n", index+1, present_header.no_prompts));
    
    /* Get the header file name */
    sprintf(file_name, "headers/%d.idx", index);
    lSource = StreamFileSource(FileFind(FILE_ROOT, file_name, strlen(file_name)));

    /* Check source created successfully */
    if(SourceSize(lSource) < SIZE_PROMPT_DATA)
    {
        /* Finished with header source, close it */
        SourceClose(lSource);
        return NULL;
    }
    
    /* Map in header */
    rx_array = SourceMap(lSource);
    
    /* Pack data into result */
    /*    rx_array[0] not used*/
    /*    rx_array[1] index, not used */
    prompt->stereo        = rx_array[4];
    prompt->size          = ((uint32)rx_array[5] << 24) | ((uint32)rx_array[6] << 16) | ((uint16)rx_array[7] << 8) | (rx_array[8]);
    prompt->decompression = rx_array[9];
    prompt->playback_rate = ((uint16)rx_array[10] << 8) | (rx_array[11]);   
    
    /* The size of the prompt must be limited to 16 bits for I2C and SPI as the firmware traps only support a 16 bit size */
    if (prompt->size > PRESENT_MAX_SIZE)
    {
        prompt->size = PRESENT_MAX_SIZE;
        PRINT(("Prompt size adjusted to 16 bit maximum\n"));
    }
    
    /* Get the prompt file name */
    sprintf(file_name, "prompts/%d.prm", index);
    
    PRINT(("File Prompt: %s dec %X rate 0x%x stereo %u size 0x%lx \n", file_name, prompt->decompression,prompt->playback_rate,prompt->stereo,prompt->size));
    
    /* Finished with header source, close it */
    if(!SourceClose(lSource))
        Panic();
    
    return StreamFileSource(FileFind(FILE_ROOT, file_name, strlen(file_name)));
}
void swatHandleSwatSignallingData(Source source)
{
    uint16 packet_size, data_size;
    const uint8 *ptr = SourceMap(source);
    
    /* Get the device that sent the signalling data */
    remoteDevice* device = swatFindDeviceFromSink( StreamSinkFromSource(source) );
    
    packet_size = SourceSize(source);
    
    /* Process each signalling packet in the source (may be more than one signal in the source) */
    while(packet_size >= PKT_PAYLOAD)
    {
        /* calculate size of packet */              
        data_size = ((ptr[PKT_PAYLOAD_LEN] & 0x7f) + 3);
        
        /* Process the signalling data by the remote device */
        switch(ptr[PKT_SIGNAL_ID])
        {
            /*****************************************************************************/
            case SWAT_OPEN:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_OPEN, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_OPEN, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_OPEN_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_OPEN, message, &device->signalling_block);
                }
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_CLOSE:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_CLOSE, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_CLOSE, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_CLOSE_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_CLOSE, message, &device->signalling_block);
                }
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_START:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_START, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_START, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_START_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_START, message, &device->signalling_block);
                }
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_SUSPEND:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SUSPEND, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_SUSPEND, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_SUSPEND_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SUSPEND, message, &device->signalling_block);    
                }
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_SET_VOLUME:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SET_VOLUME, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_SET_VOLUME, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_SET_VOLUME_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SET_VOLUME, message, &device->signalling_block);
                }
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_SAMPLE_RATE:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_SAMPLE_RATE, data_size);
                message->device = device;
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_SAMPLE_RATE, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_SAMPLE_RATE_CMD [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_SAMPLE_RATE, message, &device->signalling_block);
                }
                
                /* Command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* Having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_GET_VERSION:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_GET_VERSION, data_size);
                message->device = device;
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* If message is a response, send immediatley, otherwise add to queue */
                if (ptr[PKT_SIGNAL_TYPE] == SWAT_RSP)
                {
                    MessageSend(&swat->command_task, SWAT_COMMAND_GET_VERSION, message);
                }
                else
                {
                    SWAT_DEBUG(("[SWAT] SWAT_COMMAND_GET_VERSION [%x]\n", device->signalling_block));
                    
                    /* Action the message or add to queue if already handling another message */
                    MessageSendConditionally(&swat->command_task, SWAT_COMMAND_GET_VERSION, message, &device->signalling_block);
                }
                
                /* Command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* Having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            case SWAT_GENERAL_REJECT:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE_WITH_LEN(SWAT_COMMAND_GENERAL_REJECT, data_size);
                message->device = device;                    
                memmove(&message->data[0], &ptr[0], data_size);
                
                /* Handle the GENERAL_REJECT command as it won't affect ongoing operations */
                MessageSend(&swat->command_task, SWAT_COMMAND_GENERAL_REJECT, message);
                
                /* command actioned, discard buffer data leaving any additional data behind */
                SourceDrop(source, data_size);
                /* having removed a packet reset the pointer to the start of any more packets */
                ptr = SourceMap(source);
            }
            break;
            /*****************************************************************************/
            default:
            {
                /* send to command handler, include message payload  */
                MAKE_SWAT_MESSAGE(SWAT_COMMAND_DEFAULT);
                message->device = device;                    
                
                MessageSend(&swat->command_task, SWAT_COMMAND_DEFAULT, message);
                
                /* block any more signalling commands until current process has completed */
                device->signalling_block = DATA_BLOCK;
                
                /* Discard entire buffer as got out of sync */
                SourceDrop(source, packet_size);
            }
        }
        /* recalculate the packet size of any data left in the source */
        packet_size = SourceSize(source);    
    }
}
예제 #11
0
static void handleHidClassRequest(Source source, usb_device_class_type class_type)
{
    static uint8 idle_rate = 0;
    
    {    
        Sink sink = StreamSinkFromSource(source);
        uint16 packet_size;

        while ((packet_size = SourceBoundary(source)) != 0)
        {
            /* Build the respnse. It must contain the original request, so copy 
               from the source header. */
            UsbResponse resp;
            memcpy(&resp.original_request, SourceMapHeader(source), sizeof(UsbRequest));
        
            /* Set the response fields to default values to make the code below simpler */
            resp.success = FALSE;
            resp.data_length = 0;
        
            switch (resp.original_request.bRequest)
            {
                /* GET_REPORT */
                case 0x01:
                {
                    PRINT(("USB: HID Get_Report src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength));
                    break;
                }
            
                /* GET_IDLE */
                case 0x02:
                {
                    uint8 *out;
                    if ((out = claimSink(sink, 1)) != 0)
                    {
                        PRINT(("USB: HID Get_Idle src=0x%X wValue=0x%X wIndex=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex));
                        out[0] = idle_rate;
                        resp.success = TRUE;
                        resp.data_length = 1;                
                    }
                    break;
                }
            
                /* SET_REPORT */
                case 0x09:
                {
                    const uint8 *in = SourceMap(source);                    
                    uint16 size_data = resp.original_request.wLength;                
                    uint8 report_id = resp.original_request.wValue & 0xff;
                    PRINT(("USB: HID Set_Report src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X -> \n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength));
                  
                    resp.success = TRUE;
                                                            
                    if (size_data)
                    {
                        if (class_type == USB_DEVICE_CLASS_TYPE_HID_CONSUMER_TRANSPORT_CONTROL)
                        {
                            USB_DEVICE_CLASS_MSG_REPORT_IND_T *message = PanicUnlessMalloc(sizeof(USB_DEVICE_CLASS_MSG_REPORT_IND_T) + size_data);
                            uint16 source_size = SourceSize(source);
                            
                            PRINT(("    send report ind source_size[0x%x]\n", source_size));
                            
                            message->class_type = class_type;
                            message->report_id = report_id;
                            message->size_report = size_data;
                            
                            in = SourceMap(source);  
                            if (source_size < message->size_report)
                            {
                                message->size_report = source_size;                                    
                            }
                            memmove(message->report, in, message->size_report);
                            MessageSend(device->app_task, USB_DEVICE_CLASS_MSG_REPORT_IND, message);
                            PRINT(("    sent report ind to Task [0x%x]\n", (uint16)device->app_task));
                        }
                    }                                     
                    break;
                }
            
                /* SET_IDLE */
                case 0x0A:    
                {
                    PRINT(("USB: HID Set_Idle src=0x%X wValue=0x%X wIndex=0x%X\n", (uint16)source, resp.original_request.wValue, resp.original_request.wIndex));
                    idle_rate = resp.original_request.wValue >> 8;
                    resp.success = TRUE;
                    break;
                }
            
                default:
                {
                    PRINT(("USB: HID req=0x%X src=0x%X wValue=0x%X wIndex=0x%X wLength=0x%X\n", resp.original_request.bRequest, (uint16)source, resp.original_request.wValue, resp.original_request.wIndex, resp.original_request.wLength));
                    break;            
                }
            }
        
            /* Send response */
            if (resp.data_length)
            {
                (void)SinkFlushHeader(sink, resp.data_length, (uint16 *)&resp, sizeof(UsbResponse));
            }
            else
            {
                   /* Sink packets can never be zero-length, so flush a dummy byte */
                (void) SinkClaim(sink, 1);
                (void) SinkFlushHeader(sink, 1, (uint16 *) &resp, sizeof(UsbResponse));          
            }   

            /* Discard the original request */
              SourceDrop(source, packet_size);
        }
    }
}
예제 #12
0
파일: scanner.c 프로젝트: fanqh/MINIScanner
static void scanner_scanning_state_handler(Task task, MessageId id, Message message) {
	
	switch (id) {
		
		case HAL_MESSAGE_FUNCTION_BUTTON_PRESS:
		
			DEBUG(( "scanner, scanner_scanning_state_handler, FUNCTION_BUTTON_0 arrived... ignored... \n" ));
			
			break;
		
		/** this is something wrong 	
		case SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND:
			
			DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_PULLDOWN_TIMEOUT_IND arrived... \n" ));
			
			trigger_pull_up();
			break;
			
		**/
			
		case SCANNER_SCANNING_TIMEOUT_IND:
			
			DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_TIMEOUT_IND arrived... \n" ));
			
			scanner_scanning_state_exit();
			scanner.on_state = SCANNER_ON_READY;
			scanner_ready_state_enter();
			break;
			
		case MESSAGE_MORE_DATA:
			{
				
				Source source;
				uint16 size;
				const uint8* ptr;
				bool fill_success;
				
				DEBUG(( "scanner, scanner_scanning_state_handler, MESSAGE_MORE_DATA arrived... \n" ));	
				
                
				source = StreamUartSource();
				size = SourceSize(source);
				
				DEBUG(( "    source has %d bytes of data... \n", size ));
				
				ptr = SourceMap(source);
				
				fill_success = barcode_fill_raw_bytes(&scanner.barcode, ptr, size);
				
				SourceDrop(source, size);
				
/*               enable_buzzer();
               MessageSendLater(&scanner.task, SCANNER_SCANNING_BUZZER_TIMEOUT_IND, 0, SCANNER_SCANNING_BUZZER_TIMEOUT);
 */               
				if ( TRUE == fill_success ) {
					
					DEBUG(( "    barcode_fill_raw_bytes succeed... \n" ));
					
					if ( barcode_is_terminated(&scanner.barcode) ) {
						
						barcode_t* result;
						
						DEBUG(( "    barcode is terminated... \n" ));
						DEBUG(( "    %s", scanner.barcode.code ));
					
						result = (barcode_t*)malloc(sizeof(barcode_t));
						if (0 == result) { /** mem fail, then neglect the result **/
							
							DEBUG(( "    mem error, no result sent... \n" ));
							
							scanner_scanning_state_exit();
							scanner.on_state = SCANNER_ON_READY;
							scanner_ready_state_enter();
						}
						else {	/** throw out message to client **/
							
							DEBUG(( "    result sent to client in SCANNER_RESULT_MESSAGE... \n" ));
							
							memcpy(result, &scanner.barcode, sizeof(barcode_t));
							
							MessageSend(scanner.client, SCANNER_RESULT_MESSAGE, result);
							scanner_scanning_state_exit();
							scanner.on_state = SCANNER_ON_READY;
							scanner_ready_state_enter();
						}
					}
					else {
						
						DEBUG(( "    barcode is not terminated... \n" ));
					}
				}
				else {
					
					DEBUG(( "    barcode_fill_raw_bytes failed... \n" ));
					
					scanner_scanning_state_exit();
					scanner.on_state = SCANNER_ON_READY;
					scanner_ready_state_enter();
				}
			}
			break;
/*        case  SCANNER_SCANNING_BUZZER_TIMEOUT_IND:
            
            DEBUG(( "scanner, scanner_scanning_state_handler, SCANNER_SCANNING_BUZZER_TIMEOUT_IND arrived... \n" ));
            disable_buzzer();
            break;
  */          
	}
}