00001 /* 00002 * VrMagicHandlercamhost.cpp 00003 * 00004 * Created on: 29.07.2014 00005 * Author: m1ch1 00006 */ 00007 00008 #include "VrMagicHandler_camhost.h" 00009 00010 namespace ohm 00011 { 00012 00013 VrMagicHandler_camhost::VrMagicHandler_camhost(unsigned int port_smartcam) 00014 { 00015 _port = port_smartcam; 00016 00017 _tcpServer = new apps::TCP(_port); 00018 00019 _imgHeader = new OHM_HEADER_TYPE[ohm::HEADER_SIZE]; 00020 } 00021 00022 VrMagicHandler_camhost::~VrMagicHandler_camhost() 00023 { 00024 delete _tcpServer; 00025 delete _imgHeader; 00026 } 00027 00028 void VrMagicHandler_camhost::connect() 00029 { 00030 _tcpServer->connectOnce(); 00031 } 00032 00033 int VrMagicHandler_camhost::writeImage(ohm::ImageType& image) 00034 { 00035 //fill Header 00036 _imgHeader[ohm::ID] = image.id; 00037 _imgHeader[ohm::DATA_SIZE] = image.dataSize; 00038 _imgHeader[ohm::DATA_TYPE] = image.dataType; 00039 _imgHeader[ohm::COMPRESSION_TYPE] = image.compressionType; 00040 _imgHeader[ohm::WIDTH] = image.width; 00041 _imgHeader[ohm::HEIGHT] = image.height; 00042 _imgHeader[ohm::CHANNELS] = image.channels; 00043 _imgHeader[ohm::BYTE_PER_PIXEL] = image.bytePerPixel; 00044 00045 //write img-Header 00046 if(_tcpServer->write(_imgHeader,(unsigned int)ohm::HEADER_SIZE * sizeof(OHM_HEADER_TYPE)) < 0) 00047 { 00048 return -1; 00049 } 00050 00051 //write img-data 00052 if(_tcpServer->write(image.data, image.dataSize) < 0) 00053 { 00054 return -1; 00055 } 00056 00057 return 0; 00058 } 00059 00060 //int VrMagicHandler_camhost::wait() 00061 //{ 00062 // OHM_TRIGGER_TYPE trigger; 00063 // if(_tcpServer->readAll(&trigger, sizeof(OHM_TRIGGER_TYPE)) != 0) 00064 // { 00065 // return -1; 00066 // } 00067 // if(!trigger == ohm::IMAGE_REQUEST) 00068 // { 00069 // return -2; 00070 // } 00071 // return 0; 00072 //} 00073 00074 unsigned int VrMagicHandler_camhost::getPort() const 00075 { 00076 return _port; 00077 } 00078 00079 } /* namespace ohm */ 00080 00081