Sample program that can send the recognition data from HVC-P2 to Fujitsu IoT Platform using REST (HTTP)

Dependencies:   AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP USBHost_custom easy-connect-gr-peach mbed-http picojson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HVCApi.c Source File

HVCApi.c

00001 /*---------------------------------------------------------------------------*/
00002 /* Copyright(C)  2017  OMRON Corporation                                     */
00003 /*                                                                           */
00004 /* Licensed under the Apache License, Version 2.0 (the "License");           */
00005 /* you may not use this file except in compliance with the License.          */
00006 /* You may obtain a copy of the License at                                   */
00007 /*                                                                           */
00008 /*     http://www.apache.org/licenses/LICENSE-2.0                            */
00009 /*                                                                           */
00010 /* Unless required by applicable law or agreed to in writing, software       */
00011 /* distributed under the License is distributed on an "AS IS" BASIS,         */
00012 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  */
00013 /* See the License for the specific language governing permissions and       */
00014 /* limitations under the License.                                            */
00015 /*---------------------------------------------------------------------------*/
00016 
00017 /* 
00018     HVC Sample API
00019 */
00020 
00021 #include <stdlib.h>
00022 #include "HVCApi.h"
00023 #include "HVCExtraUartFunc.h"
00024 
00025 /*----------------------------------------------------------------------------*/
00026 /* Command number                                                             */
00027 /*----------------------------------------------------------------------------*/
00028 #define HVC_COM_GET_VERSION             (UINT8)0x00
00029 #define HVC_COM_SET_CAMERA_ANGLE        (UINT8)0x01
00030 #define HVC_COM_GET_CAMERA_ANGLE        (UINT8)0x02
00031 #define HVC_COM_EXECUTE                 (UINT8)0x03
00032 #define HVC_COM_EXECUTEEX               (UINT8)0x04
00033 #define HVC_COM_SET_THRESHOLD           (UINT8)0x05
00034 #define HVC_COM_GET_THRESHOLD           (UINT8)0x06
00035 #define HVC_COM_SET_SIZE_RANGE          (UINT8)0x07
00036 #define HVC_COM_GET_SIZE_RANGE          (UINT8)0x08
00037 #define HVC_COM_SET_DETECTION_ANGLE     (UINT8)0x09
00038 #define HVC_COM_GET_DETECTION_ANGLE     (UINT8)0x0A
00039 #define HVC_COM_SET_BAUDRATE            (UINT8)0x0E
00040 #define HVC_COM_REGISTRATION            (UINT8)0x10
00041 #define HVC_COM_DELETE_DATA             (UINT8)0x11
00042 #define HVC_COM_DELETE_USER             (UINT8)0x12
00043 #define HVC_COM_DELETE_ALL              (UINT8)0x13
00044 #define HVC_COM_GET_PERSON_DATA         (UINT8)0x15
00045 #define HVC_COM_SAVE_ALBUM              (UINT8)0x20
00046 #define HVC_COM_LOAD_ALBUM              (UINT8)0x21
00047 #define HVC_COM_WRITE_ALBUM             (UINT8)0x22
00048 
00049 /*----------------------------------------------------------------------------*/
00050 /* Header for send signal data */
00051 typedef enum {
00052     SEND_HEAD_SYNCBYTE = 0,
00053     SEND_HEAD_COMMANDNO,
00054     SEND_HEAD_DATALENGTHLSB,
00055     SEND_HEAD_DATALENGTHMSB,
00056     SEND_HEAD_NUM
00057 }SEND_HEADER;
00058 /*----------------------------------------------------------------------------*/
00059 /* Header for receive signal data */
00060 typedef enum {
00061     RECEIVE_HEAD_SYNCBYTE = 0,
00062     RECEIVE_HEAD_STATUS,
00063     RECEIVE_HEAD_DATALENLL,
00064     RECEIVE_HEAD_DATALENLM,
00065     RECEIVE_HEAD_DATALENML,
00066     RECEIVE_HEAD_DATALENMM,
00067     RECEIVE_HEAD_NUM
00068 }RECEIVE_HEADER;
00069 
00070 /*----------------------------------------------------------------------------*/
00071 /* Send command signal                                                        */
00072 /* param    : UINT8         inCommandNo     command number                    */
00073 /*          : INT32         inDataSize      sending signal data size          */
00074 /*          : UINT8         *inData         sending signal data               */
00075 /* return   : INT32                         execution result error code       */
00076 /*          :                               0...normal                        */
00077 /*          :                               -10...timeout error               */
00078 /*----------------------------------------------------------------------------*/
00079 static INT32 HVC_SendCommand(UINT8 inCommandNo, INT32 inDataSize, UINT8 *inData)
00080 {
00081     INT32 i;
00082     INT32 ret = 0;
00083     UINT8 sendData[32];
00084 
00085     /* Create header */
00086     sendData[SEND_HEAD_SYNCBYTE]        = (UINT8)0xFE;
00087     sendData[SEND_HEAD_COMMANDNO]       = (UINT8)inCommandNo;
00088     sendData[SEND_HEAD_DATALENGTHLSB]   = (UINT8)(inDataSize&0xff);
00089     sendData[SEND_HEAD_DATALENGTHMSB]   = (UINT8)((inDataSize>>8)&0xff);
00090 
00091     for(i = 0; i < inDataSize; i++){
00092         sendData[SEND_HEAD_NUM + i] = inData[i];
00093     }
00094 
00095     /* Send command signal */
00096     ret = UART_SendData(SEND_HEAD_NUM+inDataSize, sendData);
00097     if(ret != SEND_HEAD_NUM+inDataSize){
00098         return HVC_ERROR_SEND_DATA;
00099     }
00100     return 0;
00101 }
00102 
00103 /*----------------------------------------------------------------------------*/
00104 /* Send command signal of LoadAlbum                                           */
00105 /* param    : UINT8         inCommandNo     command number                    */
00106 /*          : INT32         inDataSize      sending signal data size          */
00107 /*          : UINT8         *inData         sending signal data               */
00108 /* return   : INT32                         execution result error code       */
00109 /*          :                               0...normal                        */
00110 /*          :                               -10...timeout error               */
00111 /*----------------------------------------------------------------------------*/
00112 static INT32 HVC_SendCommandOfLoadAlbum(UINT8 inCommandNo, INT32 inDataSize, UINT8 *inData)
00113 {   
00114     INT32 i;
00115     INT32 ret = 0;
00116     UINT8 *pSendData = NULL;
00117     
00118     pSendData = (UINT8*)malloc(SEND_HEAD_NUM + 4 + inDataSize);
00119 
00120     /* Create header */
00121     pSendData[SEND_HEAD_SYNCBYTE]       = (UINT8)0xFE;
00122     pSendData[SEND_HEAD_COMMANDNO]      = (UINT8)inCommandNo;
00123     pSendData[SEND_HEAD_DATALENGTHLSB]  = (UINT8)4;
00124     pSendData[SEND_HEAD_DATALENGTHMSB]  = (UINT8)0;
00125 
00126     pSendData[SEND_HEAD_NUM + 0]        = (UINT8)(inDataSize & 0x000000ff);
00127     pSendData[SEND_HEAD_NUM + 1]        = (UINT8)((inDataSize >> 8) & 0x000000ff);
00128     pSendData[SEND_HEAD_NUM + 2]        = (UINT8)((inDataSize >> 16) & 0x000000ff);
00129     pSendData[SEND_HEAD_NUM + 3]        = (UINT8)((inDataSize >> 24) & 0x000000ff);
00130 
00131      for(i = 0; i < inDataSize; i++){
00132         pSendData[SEND_HEAD_NUM + 4 + i] = inData[i];
00133     }
00134      
00135     /* Send command signal */
00136     ret = UART_SendData(SEND_HEAD_NUM+4+inDataSize, pSendData);
00137     if(ret != SEND_HEAD_NUM + 4 + inDataSize){
00138         ret = HVC_ERROR_SEND_DATA;
00139     }
00140     else{
00141         ret = 0;
00142     }
00143     free(pSendData);
00144 
00145     return ret;
00146 }
00147 
00148 /*----------------------------------------------------------------------------*/
00149 /* Receive header                                                             */
00150 /* param    : INT32         inTimeOutTime   timeout time                      */
00151 /*          : INT32         *outDataSize    receive signal data length        */
00152 /*          : UINT8         *outStatus      status                            */
00153 /* return   : INT32                         execution result error code       */
00154 /*          :                               0...normal                        */
00155 /*          :                               -20...timeout error               */
00156 /*          :                               -21...invalid header error        */
00157 /*----------------------------------------------------------------------------*/
00158 static INT32 HVC_ReceiveHeader(INT32 inTimeOutTime, INT32 *outDataSize, UINT8 *outStatus)
00159 {
00160     INT32 ret = 0;
00161     UINT8 headerData[32];
00162 
00163     /* Get header part */
00164     ret = UART_ReceiveData(inTimeOutTime, RECEIVE_HEAD_NUM, headerData);
00165     if(ret != RECEIVE_HEAD_NUM){
00166         return HVC_ERROR_HEADER_TIMEOUT;
00167     }
00168     else if((UINT8)0xFE != headerData[RECEIVE_HEAD_SYNCBYTE]){
00169         /* Different value indicates an invalid result */
00170         return HVC_ERROR_HEADER_INVALID;
00171     }
00172 
00173     /* Get data length */
00174     *outDataSize = headerData[RECEIVE_HEAD_DATALENLL] +
00175                     (headerData[RECEIVE_HEAD_DATALENLM]<<8) +
00176                     (headerData[RECEIVE_HEAD_DATALENML]<<16) +
00177                     (headerData[RECEIVE_HEAD_DATALENMM]<<24);
00178 
00179     /* Get command execution result */
00180     *outStatus  = headerData[RECEIVE_HEAD_STATUS];
00181     return 0;
00182 }
00183 
00184 /*----------------------------------------------------------------------------*/
00185 /* Receive data                                                               */
00186 /* param    : INT32         inTimeOutTime   timeout time                      */
00187 /*          : INT32         inDataSize      receive signal data size          */
00188 /*          : UINT8         *outResult      receive signal data               */
00189 /* return   : INT32                         execution result error code       */
00190 /*          :                               0...normal                        */
00191 /*          :                               -20...timeout error               */
00192 /*----------------------------------------------------------------------------*/
00193 static INT32 HVC_ReceiveData(INT32 inTimeOutTime, INT32 inDataSize, UINT8 *outResult)
00194 {
00195     INT32 ret = 0;
00196 
00197     if ( inDataSize <= 0 ) return 0;
00198 
00199     /* Receive data */
00200     ret = UART_ReceiveData(inTimeOutTime, inDataSize, outResult);
00201     if(ret != inDataSize){
00202         return HVC_ERROR_DATA_TIMEOUT;
00203     }
00204     return 0;
00205 }
00206 
00207 /*----------------------------------------------------------------------------*/
00208 /* HVC_GetVersion                                                             */
00209 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00210 /*          : HVC_VERSION   *outVersion     version data                      */
00211 /*          : UINT8         *outStatus      response code                     */
00212 /* return   : INT32                         execution result error code       */
00213 /*          :                               0...normal                        */
00214 /*          :                               -1...parameter error              */
00215 /*          :                               other...signal error              */
00216 /*----------------------------------------------------------------------------*/
00217 INT32 HVC_GetVersion(INT32 inTimeOutTime, HVC_VERSION *outVersion, UINT8 *outStatus)
00218 {
00219     INT32 ret = 0;
00220     INT32 size = 0;
00221 
00222     if((NULL == outVersion) || (NULL == outStatus)){
00223         return HVC_ERROR_PARAMETER;
00224     }
00225 
00226     /* Send GetVersion command signal */
00227     ret = HVC_SendCommand(HVC_COM_GET_VERSION, 0, NULL);
00228     if ( ret != 0 ) return ret;
00229 
00230     /* Receive header */
00231     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00232     if ( ret != 0 ) return ret;
00233 
00234     if ( size > (INT32)sizeof(HVC_VERSION) ) {
00235         size = sizeof(HVC_VERSION);
00236     }
00237 
00238     /* Receive data */
00239     return HVC_ReceiveData(inTimeOutTime, size, (UINT8*)outVersion);
00240 }
00241 
00242 /*----------------------------------------------------------------------------*/
00243 /* HVC_SetCameraAngle                                                         */
00244 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00245 /*          : INT32         inAngleNo       camera angle number               */
00246 /*          : UINT8         *outStatus      response code                     */
00247 /* return   : INT32                         execution result error code       */
00248 /*          :                               0...normal                        */
00249 /*          :                               -1...parameter error              */
00250 /*          :                               other...signal error              */
00251 /*----------------------------------------------------------------------------*/
00252 INT32 HVC_SetCameraAngle(INT32 inTimeOutTime, INT32 inAngleNo, UINT8 *outStatus)
00253 {
00254     INT32 ret = 0;
00255     INT32 size = 0;
00256     UINT8 sendData[32];
00257 
00258     if(NULL == outStatus){
00259         return HVC_ERROR_PARAMETER;
00260     }
00261 
00262     sendData[0] = (UINT8)(inAngleNo&0xff);
00263     /* Send SetCameraAngle command signal */
00264     ret = HVC_SendCommand(HVC_COM_SET_CAMERA_ANGLE, sizeof(UINT8), sendData);
00265     if ( ret != 0 ) return ret;
00266 
00267     /* Receive header */
00268     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00269     if ( ret != 0 ) return ret;
00270     return 0;
00271 }
00272 
00273 /*----------------------------------------------------------------------------*/
00274 /* HVC_GetCameraAngle                                                         */
00275 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00276 /*          : INT32         *outAngleNo     camera angle number               */
00277 /*          : UINT8         *outStatus      response code                     */
00278 /* return   : INT32                         execution result error code       */
00279 /*          :                               0...normal                        */
00280 /*          :                               -1...parameter error              */
00281 /*          :                               other...signal error              */
00282 /*----------------------------------------------------------------------------*/
00283 INT32 HVC_GetCameraAngle(INT32 inTimeOutTime, INT32 *outAngleNo, UINT8 *outStatus)
00284 {
00285     INT32 ret = 0;
00286     INT32 size = 0;
00287     UINT8 recvData[32];
00288 
00289     if((NULL == outAngleNo) || (NULL == outStatus)){
00290         return HVC_ERROR_PARAMETER;
00291     }
00292 
00293     /* Send GetCameraAngle command signal */
00294     ret = HVC_SendCommand(HVC_COM_GET_CAMERA_ANGLE, 0, NULL);
00295     if ( ret != 0 ) return ret;
00296 
00297     /* Receive header */
00298     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00299     if ( ret != 0 ) return ret;
00300 
00301     if ( size > (INT32)sizeof(UINT8) ) {
00302         size = sizeof(UINT8);
00303     }
00304 
00305     /* Receive data */
00306     ret = HVC_ReceiveData(inTimeOutTime, size, recvData);
00307     *outAngleNo = recvData[0];
00308     return ret;
00309 }
00310 
00311 /*----------------------------------------------------------------------------*/
00312 /* HVC_Execute                                                                */
00313 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00314 /*          : INT32         inExec          executable function               */
00315 /*          : INT32         inImage         image info                        */
00316 /*          : HVC_RESULT    *outHVCResult   result data                       */
00317 /*          : UINT8         *outStatus      response code                     */
00318 /* return   : INT32                         execution result error code       */
00319 /*          :                               0...normal                        */
00320 /*          :                               -1...parameter error              */
00321 /*          :                               other...signal error              */
00322 /*----------------------------------------------------------------------------*/
00323 INT32 HVC_Execute(INT32 inTimeOutTime, INT32 inExec, INT32 inImage, HVC_RESULT *outHVCResult, UINT8 *outStatus)
00324 {
00325     int i;
00326     INT32 ret = 0;
00327     INT32 size = 0;
00328     UINT8 sendData[32];
00329     UINT8 recvData[32];
00330 
00331     if((NULL == outHVCResult) || (NULL == outStatus)){
00332         return HVC_ERROR_PARAMETER;
00333     }
00334 
00335     /* Send Execute command signal */
00336     sendData[0] = (UINT8)(inExec&0xff);
00337     sendData[1] = (UINT8)((inExec>>8)&0xff);
00338     sendData[2] = (UINT8)(inImage&0xff);
00339     ret = HVC_SendCommand(HVC_COM_EXECUTE, sizeof(UINT8)*3, sendData);
00340     if ( ret != 0 ) return ret;
00341 
00342     /* Receive header */
00343     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00344     if ( ret != 0 ) return ret;
00345 
00346     /* Receive result data */
00347     if ( size >= (INT32)sizeof(UINT8)*4 ) {
00348         outHVCResult->executedFunc = inExec;
00349         ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00350         outHVCResult->bdResult.num = recvData[0];
00351         outHVCResult->hdResult.num = recvData[1];
00352         outHVCResult->fdResult.num = recvData[2];
00353         if ( ret != 0 ) return ret;
00354         size -= sizeof(UINT8)*4;
00355     }
00356 
00357     /* Get Human Body Detection result */
00358     for(i = 0; i < outHVCResult->bdResult.num; i++){
00359         if ( size >= (INT32)sizeof(UINT8)*8 ) {
00360             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00361             outHVCResult->bdResult.bdResult[i].posX = (short)(recvData[0] + (recvData[1]<<8));
00362             outHVCResult->bdResult.bdResult[i].posY = (short)(recvData[2] + (recvData[3]<<8));
00363             outHVCResult->bdResult.bdResult[i].size = (short)(recvData[4] + (recvData[5]<<8));
00364             outHVCResult->bdResult.bdResult[i].confidence = (short)(recvData[6] + (recvData[7]<<8));
00365             if ( ret != 0 ) return ret;
00366             size -= sizeof(UINT8)*8;
00367         }
00368     }
00369 
00370     /* Get Hand Detection result */
00371     for(i = 0; i < outHVCResult->hdResult.num; i++){
00372         if ( size >= (INT32)sizeof(UINT8)*8 ) {
00373             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00374             outHVCResult->hdResult.hdResult[i].posX = (short)(recvData[0] + (recvData[1]<<8));
00375             outHVCResult->hdResult.hdResult[i].posY = (short)(recvData[2] + (recvData[3]<<8));
00376             outHVCResult->hdResult.hdResult[i].size = (short)(recvData[4] + (recvData[5]<<8));
00377             outHVCResult->hdResult.hdResult[i].confidence = (short)(recvData[6] + (recvData[7]<<8));
00378             if ( ret != 0 ) return ret;
00379             size -= sizeof(UINT8)*8;
00380         }
00381     }
00382 
00383     /* Face-related results */
00384     for(i = 0; i < outHVCResult->fdResult.num; i++){
00385         /* Face Detection result */
00386         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_DETECTION)){
00387             if ( size >= (INT32)sizeof(UINT8)*8 ) {
00388                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00389                 outHVCResult->fdResult.fcResult[i].dtResult.posX = (short)(recvData[0] + (recvData[1]<<8));
00390                 outHVCResult->fdResult.fcResult[i].dtResult.posY = (short)(recvData[2] + (recvData[3]<<8));
00391                 outHVCResult->fdResult.fcResult[i].dtResult.size = (short)(recvData[4] + (recvData[5]<<8));
00392                 outHVCResult->fdResult.fcResult[i].dtResult.confidence = (short)(recvData[6] + (recvData[7]<<8));
00393                 if ( ret != 0 ) return ret;
00394                 size -= sizeof(UINT8)*8;
00395             }
00396         }
00397 
00398         /* Face direction */
00399         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_DIRECTION)){
00400             if ( size >= (INT32)sizeof(UINT8)*8 ) {
00401                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00402                 outHVCResult->fdResult.fcResult[i].dirResult.yaw = (short)(recvData[0] + (recvData[1]<<8));
00403                 outHVCResult->fdResult.fcResult[i].dirResult.pitch = (short)(recvData[2] + (recvData[3]<<8));
00404                 outHVCResult->fdResult.fcResult[i].dirResult.roll = (short)(recvData[4] + (recvData[5]<<8));
00405                 outHVCResult->fdResult.fcResult[i].dirResult.confidence = (short)(recvData[6] + (recvData[7]<<8));
00406                 if ( ret != 0 ) return ret;
00407                 size -= sizeof(UINT8)*8;
00408             }
00409         }
00410 
00411         /* Age */
00412         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_AGE_ESTIMATION)){
00413             if ( size >= (INT32)sizeof(UINT8)*3 ) {
00414                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*3, recvData);
00415                 outHVCResult->fdResult.fcResult[i].ageResult.age = (char)(recvData[0]);
00416                 outHVCResult->fdResult.fcResult[i].ageResult.confidence = (short)(recvData[1] + (recvData[2]<<8));
00417                 if ( ret != 0 ) return ret;
00418                 size -= sizeof(UINT8)*3;
00419             }
00420         }
00421 
00422         /* Gender */
00423         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_GENDER_ESTIMATION)){
00424             if ( size >= (INT32)sizeof(UINT8)*3 ) {
00425                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*3, recvData);
00426                 outHVCResult->fdResult.fcResult[i].genderResult.gender = (char)(recvData[0]);
00427                 outHVCResult->fdResult.fcResult[i].genderResult.confidence = (short)(recvData[1] + (recvData[2]<<8));
00428                 if ( ret != 0 ) return ret;
00429                 size -= sizeof(UINT8)*3;
00430             }
00431         }
00432 
00433         /* Gaze */
00434         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_GAZE_ESTIMATION)){
00435             if ( size >= (INT32)sizeof(UINT8)*2 ) {
00436                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*2, recvData);
00437                 outHVCResult->fdResult.fcResult[i].gazeResult.gazeLR = (char)(recvData[0]);
00438                 outHVCResult->fdResult.fcResult[i].gazeResult.gazeUD = (char)(recvData[1]);
00439                 if ( ret != 0 ) return ret;
00440                 size -= sizeof(UINT8)*2;
00441             }
00442         }
00443 
00444         /* Blink */
00445         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_BLINK_ESTIMATION)){
00446             if ( size >= (INT32)sizeof(UINT8)*4 ) {
00447                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00448                 outHVCResult->fdResult.fcResult[i].blinkResult.ratioL = (short)(recvData[0] + (recvData[1]<<8));
00449                 outHVCResult->fdResult.fcResult[i].blinkResult.ratioR = (short)(recvData[2] + (recvData[3]<<8));
00450                 if ( ret != 0 ) return ret;
00451                 size -= sizeof(UINT8)*4;
00452             }
00453         }
00454 
00455         /* Expression */
00456         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_EXPRESSION_ESTIMATION)){
00457             if ( size >= (INT32)sizeof(UINT8)*3 ) {
00458                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*3, recvData);
00459                 outHVCResult->fdResult.fcResult[i].expressionResult.topExpression = (char)(recvData[0]);
00460                 outHVCResult->fdResult.fcResult[i].expressionResult.topScore = (char)(recvData[1]);
00461                 outHVCResult->fdResult.fcResult[i].expressionResult.degree = (char)(recvData[2]);
00462                 if ( ret != 0 ) return ret;
00463                 size -= sizeof(UINT8)*3;
00464             }
00465         }
00466 
00467         /* Face Recognition */
00468         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_RECOGNITION)){
00469             if ( size >= (INT32)sizeof(UINT8)*4 ) {
00470                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00471                 outHVCResult->fdResult.fcResult[i].recognitionResult.uid = (short)(recvData[0] + (recvData[1]<<8));
00472                 outHVCResult->fdResult.fcResult[i].recognitionResult.confidence = (short)(recvData[2] + (recvData[3]<<8));
00473                 if ( ret != 0 ) return ret;
00474                 size -= sizeof(UINT8)*4;
00475             }
00476         }
00477     }
00478 
00479     if(HVC_EXECUTE_IMAGE_NONE != inImage){
00480         /* Image data */
00481         if ( size >= (INT32)sizeof(UINT8)*4 ) {
00482             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00483             outHVCResult->image.width = (short)(recvData[0] + (recvData[1]<<8));
00484             outHVCResult->image.height = (short)(recvData[2] + (recvData[3]<<8));
00485             if ( ret != 0 ) return ret;
00486             size -= sizeof(UINT8)*4;
00487         }
00488 
00489         if ( size >= (INT32)sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height ) {
00490             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height, outHVCResult->image.image);
00491             if ( ret != 0 ) return ret;
00492             size -= sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height;
00493         }
00494     }
00495     return 0;
00496 }
00497 
00498 /*----------------------------------------------------------------------------*/
00499 /* HVC_ExecuteEx                                                              */
00500 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00501 /*          : INT32         inExec          executable function               */
00502 /*          : INT32         inImage         image info                        */
00503 /*          : HVC_RESULT    *outHVCResult   result data                       */
00504 /*          : UINT8         *outStatus      response code                     */
00505 /* return   : INT32                         execution result error code       */
00506 /*          :                               0...normal                        */
00507 /*          :                               -1...parameter error              */
00508 /*          :                               other...signal error              */
00509 /*----------------------------------------------------------------------------*/
00510 INT32 HVC_ExecuteEx(INT32 inTimeOutTime, INT32 inExec, INT32 inImage, HVC_RESULT *outHVCResult, UINT8 *outStatus)
00511 {
00512     int i, j;
00513     INT32 ret = 0;
00514     INT32 size = 0;
00515     UINT8 sendData[32];
00516     UINT8 recvData[32];
00517 
00518     if((NULL == outHVCResult) || (NULL == outStatus)){
00519         return HVC_ERROR_PARAMETER;
00520     }
00521 
00522     /* Send Execute command signal */
00523     sendData[0] = (UINT8)(inExec&0xff);
00524     sendData[1] = (UINT8)((inExec>>8)&0xff);
00525     sendData[2] = (UINT8)(inImage&0xff);
00526     ret = HVC_SendCommand(HVC_COM_EXECUTEEX, sizeof(UINT8)*3, sendData);
00527     if ( ret != 0 ) return ret;
00528 
00529     /* Receive header */
00530     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00531     if ( ret != 0 ) return ret;
00532 
00533     /* Receive result data */
00534     if ( size >= (INT32)sizeof(UINT8)*4 ) {
00535         outHVCResult->executedFunc = inExec;
00536         ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00537         outHVCResult->bdResult.num = recvData[0];
00538         outHVCResult->hdResult.num = recvData[1];
00539         outHVCResult->fdResult.num = recvData[2];
00540         if ( ret != 0 ) return ret;
00541         size -= sizeof(UINT8)*4;
00542     }
00543 
00544     /* Get Human Body Detection result */
00545     for(i = 0; i < outHVCResult->bdResult.num; i++){
00546         if ( size >= (INT32)sizeof(UINT8)*8 ) {
00547             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00548             outHVCResult->bdResult.bdResult[i].posX = (short)(recvData[0] + (recvData[1]<<8));
00549             outHVCResult->bdResult.bdResult[i].posY = (short)(recvData[2] + (recvData[3]<<8));
00550             outHVCResult->bdResult.bdResult[i].size = (short)(recvData[4] + (recvData[5]<<8));
00551             outHVCResult->bdResult.bdResult[i].confidence = (short)(recvData[6] + (recvData[7]<<8));
00552             if ( ret != 0 ) return ret;
00553             size -= sizeof(UINT8)*8;
00554         }
00555     }
00556 
00557     /* Get Hand Detection result */
00558     for(i = 0; i < outHVCResult->hdResult.num; i++){
00559         if ( size >= (INT32)sizeof(UINT8)*8 ) {
00560             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00561             outHVCResult->hdResult.hdResult[i].posX = (short)(recvData[0] + (recvData[1]<<8));
00562             outHVCResult->hdResult.hdResult[i].posY = (short)(recvData[2] + (recvData[3]<<8));
00563             outHVCResult->hdResult.hdResult[i].size = (short)(recvData[4] + (recvData[5]<<8));
00564             outHVCResult->hdResult.hdResult[i].confidence = (short)(recvData[6] + (recvData[7]<<8));
00565             if ( ret != 0 ) return ret;
00566             size -= sizeof(UINT8)*8;
00567         }
00568     }
00569 
00570     /* Face-related results */
00571     for(i = 0; i < outHVCResult->fdResult.num; i++){
00572         /* Face Detection result */
00573         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_DETECTION)){
00574             if ( size >= (INT32)sizeof(UINT8)*8 ) {
00575                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00576                 outHVCResult->fdResult.fcResult[i].dtResult.posX = (short)(recvData[0] + (recvData[1]<<8));
00577                 outHVCResult->fdResult.fcResult[i].dtResult.posY = (short)(recvData[2] + (recvData[3]<<8));
00578                 outHVCResult->fdResult.fcResult[i].dtResult.size = (short)(recvData[4] + (recvData[5]<<8));
00579                 outHVCResult->fdResult.fcResult[i].dtResult.confidence = (short)(recvData[6] + (recvData[7]<<8));
00580                 if ( ret != 0 ) return ret;
00581                 size -= sizeof(UINT8)*8;
00582             }
00583         }
00584 
00585         /* Face direction */
00586         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_DIRECTION)){
00587             if ( size >= (INT32)sizeof(UINT8)*8 ) {
00588                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*8, recvData);
00589                 outHVCResult->fdResult.fcResult[i].dirResult.yaw = (short)(recvData[0] + (recvData[1]<<8));
00590                 outHVCResult->fdResult.fcResult[i].dirResult.pitch = (short)(recvData[2] + (recvData[3]<<8));
00591                 outHVCResult->fdResult.fcResult[i].dirResult.roll = (short)(recvData[4] + (recvData[5]<<8));
00592                 outHVCResult->fdResult.fcResult[i].dirResult.confidence = (short)(recvData[6] + (recvData[7]<<8));
00593                 if ( ret != 0 ) return ret;
00594                 size -= sizeof(UINT8)*8;
00595             }
00596         }
00597 
00598         /* Age */
00599         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_AGE_ESTIMATION)){
00600             if ( size >= (INT32)sizeof(UINT8)*3 ) {
00601                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*3, recvData);
00602                 outHVCResult->fdResult.fcResult[i].ageResult.age = (char)(recvData[0]);
00603                 outHVCResult->fdResult.fcResult[i].ageResult.confidence = (short)(recvData[1] + (recvData[2]<<8));
00604                 if ( ret != 0 ) return ret;
00605                 size -= sizeof(UINT8)*3;
00606             }
00607         }
00608 
00609         /* Gender */
00610         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_GENDER_ESTIMATION)){
00611             if ( size >= (INT32)sizeof(UINT8)*3 ) {
00612                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*3, recvData);
00613                 outHVCResult->fdResult.fcResult[i].genderResult.gender = (char)(recvData[0]);
00614                 outHVCResult->fdResult.fcResult[i].genderResult.confidence = (short)(recvData[1] + (recvData[2]<<8));
00615                 if ( ret != 0 ) return ret;
00616                 size -= sizeof(UINT8)*3;
00617             }
00618         }
00619 
00620         /* Gaze */
00621         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_GAZE_ESTIMATION)){
00622             if ( size >= (INT32)sizeof(UINT8)*2 ) {
00623                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*2, recvData);
00624                 outHVCResult->fdResult.fcResult[i].gazeResult.gazeLR = (char)(recvData[0]);
00625                 outHVCResult->fdResult.fcResult[i].gazeResult.gazeUD = (char)(recvData[1]);
00626                 if ( ret != 0 ) return ret;
00627                 size -= sizeof(UINT8)*2;
00628             }
00629         }
00630 
00631         /* Blink */
00632         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_BLINK_ESTIMATION)){
00633             if ( size >= (INT32)sizeof(UINT8)*4 ) {
00634                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00635                 outHVCResult->fdResult.fcResult[i].blinkResult.ratioL = (short)(recvData[0] + (recvData[1]<<8));
00636                 outHVCResult->fdResult.fcResult[i].blinkResult.ratioR = (short)(recvData[2] + (recvData[3]<<8));
00637                 if ( ret != 0 ) return ret;
00638                 size -= sizeof(UINT8)*4;
00639             }
00640         }
00641 
00642         /* Expression */
00643         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_EXPRESSION_ESTIMATION)){
00644             if ( size >= (INT32)sizeof(UINT8)*6 ) {
00645                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*6, recvData);
00646                 outHVCResult->fdResult.fcResult[i].expressionResult.topExpression = -128;
00647                 outHVCResult->fdResult.fcResult[i].expressionResult.topScore = -128;
00648                 for(j = 0; j < 5; j++){
00649                     outHVCResult->fdResult.fcResult[i].expressionResult.score[j] = (char)(recvData[j]);
00650                     if(outHVCResult->fdResult.fcResult[i].expressionResult.topScore < outHVCResult->fdResult.fcResult[i].expressionResult.score[j]){
00651                         outHVCResult->fdResult.fcResult[i].expressionResult.topScore = outHVCResult->fdResult.fcResult[i].expressionResult.score[j];
00652                         outHVCResult->fdResult.fcResult[i].expressionResult.topExpression = j + 1;
00653                     }
00654                 }
00655                 outHVCResult->fdResult.fcResult[i].expressionResult.degree = (char)(recvData[5]);
00656                 if ( ret != 0 ) return ret;
00657                 size -= sizeof(UINT8)*6;
00658             }
00659         }
00660 
00661         /* Face Recognition */
00662         if(0 != (outHVCResult->executedFunc & HVC_ACTIV_FACE_RECOGNITION)){
00663             if ( size >= (INT32)sizeof(UINT8)*4 ) {
00664                 ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00665                 outHVCResult->fdResult.fcResult[i].recognitionResult.uid = (short)(recvData[0] + (recvData[1]<<8));
00666                 outHVCResult->fdResult.fcResult[i].recognitionResult.confidence = (short)(recvData[2] + (recvData[3]<<8));
00667                 if ( ret != 0 ) return ret;
00668                 size -= sizeof(UINT8)*4;
00669             }
00670         }
00671     }
00672 
00673     if(HVC_EXECUTE_IMAGE_NONE != inImage){
00674         /* Image data */
00675         if ( size >= (INT32)sizeof(UINT8)*4 ) {
00676             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00677             outHVCResult->image.width = (short)(recvData[0] + (recvData[1]<<8));
00678             outHVCResult->image.height = (short)(recvData[2] + (recvData[3]<<8));
00679             if ( ret != 0 ) return ret;
00680             size -= sizeof(UINT8)*4;
00681         }
00682 
00683         if ( size >= (INT32)sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height ) {
00684             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height, outHVCResult->image.image);
00685             if ( ret != 0 ) return ret;
00686             size -= sizeof(UINT8)*outHVCResult->image.width*outHVCResult->image.height;
00687         }
00688     }
00689     return 0;
00690 }
00691 
00692 /*----------------------------------------------------------------------------*/
00693 /* HVC_SetThreshold                                                           */
00694 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00695 /*          : HVC_THRESHOLD *inThreshold    threshold values                  */
00696 /*          : UINT8         *outStatus      response code                     */
00697 /* return   : INT32                         execution result error code       */
00698 /*          :                               0...normal                        */
00699 /*          :                               -1...parameter error              */
00700 /*          :                               other...signal error              */
00701 /*----------------------------------------------------------------------------*/
00702 INT32 HVC_SetThreshold(INT32 inTimeOutTime, HVC_THRESHOLD *inThreshold, UINT8 *outStatus)
00703 {
00704     INT32 ret = 0;
00705     INT32 size = 0;
00706     UINT8 sendData[32];
00707 
00708     if((NULL == inThreshold) || (NULL == outStatus)){
00709         return HVC_ERROR_PARAMETER;
00710     }
00711 
00712     sendData[0] = (UINT8)(inThreshold->bdThreshold&0xff);
00713     sendData[1] = (UINT8)((inThreshold->bdThreshold>>8)&0xff);
00714     sendData[2] = (UINT8)(inThreshold->hdThreshold&0xff);
00715     sendData[3] = (UINT8)((inThreshold->hdThreshold>>8)&0xff);
00716     sendData[4] = (UINT8)(inThreshold->dtThreshold&0xff);
00717     sendData[5] = (UINT8)((inThreshold->dtThreshold>>8)&0xff);
00718     sendData[6] = (UINT8)(inThreshold->rsThreshold&0xff);
00719     sendData[7] = (UINT8)((inThreshold->rsThreshold>>8)&0xff);
00720     /* Send SetThreshold command signal */
00721     ret = HVC_SendCommand(HVC_COM_SET_THRESHOLD, sizeof(UINT8)*8, sendData);
00722     if ( ret != 0 ) return ret;
00723 
00724     /* Receive header */
00725     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00726     if ( ret != 0 ) return ret;
00727     return 0;
00728 }
00729 
00730 /*----------------------------------------------------------------------------*/
00731 /* HVC_GetThreshold                                                           */
00732 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00733 /*          : HVC_THRESHOLD *outThreshold   threshold values                  */
00734 /*          : UINT8         *outStatus      response code                     */
00735 /* return   : INT32                         execution result error code       */
00736 /*          :                               0...normal                        */
00737 /*          :                               -1...parameter error              */
00738 /*          :                               other...signal error              */
00739 /*----------------------------------------------------------------------------*/
00740 INT32 HVC_GetThreshold(INT32 inTimeOutTime, HVC_THRESHOLD *outThreshold, UINT8 *outStatus)
00741 {
00742     INT32 ret = 0;
00743     INT32 size = 0;
00744     UINT8 recvData[32];
00745 
00746     if((NULL == outThreshold) || (NULL == outStatus)){
00747         return HVC_ERROR_PARAMETER;
00748     }
00749 
00750     /* Send GetThreshold command signal */
00751     ret = HVC_SendCommand(HVC_COM_GET_THRESHOLD, 0, NULL);
00752     if ( ret != 0 ) return ret;
00753 
00754     /* Receive header */
00755     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00756     if ( ret != 0 ) return ret;
00757 
00758     if ( size > (INT32)sizeof(UINT8)*8 ) {
00759         size = sizeof(UINT8)*8;
00760     }
00761 
00762     /* Receive data */
00763     ret = HVC_ReceiveData(inTimeOutTime, size, recvData);
00764     outThreshold->bdThreshold = recvData[0] + (recvData[1]<<8);
00765     outThreshold->hdThreshold = recvData[2] + (recvData[3]<<8);
00766     outThreshold->dtThreshold = recvData[4] + (recvData[5]<<8);
00767     outThreshold->rsThreshold = recvData[6] + (recvData[7]<<8);
00768     return ret;
00769 }
00770 
00771 /*----------------------------------------------------------------------------*/
00772 /* HVC_SetSizeRange                                                           */
00773 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00774 /*          : HVC_SIZERANGE *inSizeRange    detection sizes                   */
00775 /*          : UINT8         *outStatus      response code                     */
00776 /* return   : INT32                         execution result error code       */
00777 /*          :                               0...normal                        */
00778 /*          :                               -1...parameter error              */
00779 /*          :                               other...signal error              */
00780 /*----------------------------------------------------------------------------*/
00781 INT32 HVC_SetSizeRange(INT32 inTimeOutTime, HVC_SIZERANGE *inSizeRange, UINT8 *outStatus)
00782 {
00783     INT32 ret = 0;
00784     INT32 size = 0;
00785     UINT8 sendData[32];
00786 
00787     if((NULL == inSizeRange) || (NULL == outStatus)){
00788         return HVC_ERROR_PARAMETER;
00789     }
00790 
00791     sendData[0] = (UINT8)(inSizeRange->bdMinSize&0xff);
00792     sendData[1] = (UINT8)((inSizeRange->bdMinSize>>8)&0xff);
00793     sendData[2] = (UINT8)(inSizeRange->bdMaxSize&0xff);
00794     sendData[3] = (UINT8)((inSizeRange->bdMaxSize>>8)&0xff);
00795     sendData[4] = (UINT8)(inSizeRange->hdMinSize&0xff);
00796     sendData[5] = (UINT8)((inSizeRange->hdMinSize>>8)&0xff);
00797     sendData[6] = (UINT8)(inSizeRange->hdMaxSize&0xff);
00798     sendData[7] = (UINT8)((inSizeRange->hdMaxSize>>8)&0xff);
00799     sendData[8] = (UINT8)(inSizeRange->dtMinSize&0xff);
00800     sendData[9] = (UINT8)((inSizeRange->dtMinSize>>8)&0xff);
00801     sendData[10] = (UINT8)(inSizeRange->dtMaxSize&0xff);
00802     sendData[11] = (UINT8)((inSizeRange->dtMaxSize>>8)&0xff);
00803     /* Send SetSizeRange command signal */
00804     ret = HVC_SendCommand(HVC_COM_SET_SIZE_RANGE, sizeof(UINT8)*12, sendData);
00805     if ( ret != 0 ) return ret;
00806 
00807     /* Receive header */
00808     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00809     if ( ret != 0 ) return ret;
00810     return 0;
00811 }
00812 
00813 /*----------------------------------------------------------------------------*/
00814 /* HVC_GetSizeRange                                                           */
00815 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00816 /*          : HVC_SIZERANGE *outSizeRange   detection sizes                   */
00817 /*          : UINT8         *outStatus      response code                     */
00818 /* return   : INT32                         execution result error code       */
00819 /*          :                               0...normal                        */
00820 /*          :                               -1...parameter error              */
00821 /*          :                               other...signal error              */
00822 /*----------------------------------------------------------------------------*/
00823 INT32 HVC_GetSizeRange(INT32 inTimeOutTime, HVC_SIZERANGE *outSizeRange, UINT8 *outStatus)
00824 {
00825     INT32 ret = 0;
00826     INT32 size = 0;
00827     UINT8 recvData[32];
00828 
00829     if((NULL == outSizeRange) || (NULL == outStatus)){
00830         return HVC_ERROR_PARAMETER;
00831     }
00832 
00833     /* Send GetSizeRange command signal */
00834     ret = HVC_SendCommand(HVC_COM_GET_SIZE_RANGE, 0, NULL);
00835     if ( ret != 0 ) return ret;
00836 
00837     /* Receive header */
00838     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00839     if ( ret != 0 ) return ret;
00840 
00841     if ( size > (INT32)sizeof(UINT8)*12 ) {
00842         size = sizeof(UINT8)*12;
00843     }
00844 
00845     /* Receive data */
00846     ret = HVC_ReceiveData(inTimeOutTime, size, recvData);
00847     outSizeRange->bdMinSize = recvData[0] + (recvData[1]<<8);
00848     outSizeRange->bdMaxSize = recvData[2] + (recvData[3]<<8);
00849     outSizeRange->hdMinSize = recvData[4] + (recvData[5]<<8);
00850     outSizeRange->hdMaxSize = recvData[6] + (recvData[7]<<8);
00851     outSizeRange->dtMinSize = recvData[8] + (recvData[9]<<8);
00852     outSizeRange->dtMaxSize = recvData[10] + (recvData[11]<<8);
00853     return ret;
00854 }
00855 
00856 /*----------------------------------------------------------------------------*/
00857 /* HVC_SetFaceDetectionAngle                                                  */
00858 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00859 /*          : INT32         inPose          Yaw angle range                   */
00860 /*          : INT32         inAngle         Roll angle range                  */
00861 /*          : UINT8         *outStatus      response code                     */
00862 /* return   : INT32                         execution result error code       */
00863 /*          :                               0...normal                        */
00864 /*          :                               -1...parameter error              */
00865 /*          :                               other...signal error              */
00866 /*----------------------------------------------------------------------------*/
00867 INT32 HVC_SetFaceDetectionAngle(INT32 inTimeOutTime, INT32 inPose, INT32 inAngle, UINT8 *outStatus)
00868 {
00869     INT32 ret = 0;
00870     INT32 size = 0;
00871     UINT8 sendData[32];
00872 
00873     if(NULL == outStatus){
00874         return HVC_ERROR_PARAMETER;
00875     }
00876 
00877     sendData[0] = (UINT8)(inPose&0xff);
00878     sendData[1] = (UINT8)(inAngle&0xff);
00879     /* Send SetFaceDetectionAngle command signal */
00880     ret = HVC_SendCommand(HVC_COM_SET_DETECTION_ANGLE, sizeof(UINT8)*2, sendData);
00881     if ( ret != 0 ) return ret;
00882 
00883     /* Receive header */
00884     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00885     if ( ret != 0 ) return ret;
00886     return 0;
00887 }
00888 
00889 /*----------------------------------------------------------------------------*/
00890 /* HVC_GetFaceDetectionAngle                                                  */
00891 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00892 /*          : INT32         *outPose        Yaw angle range                   */
00893 /*          : INT32         *outAngle       Roll angle range                  */
00894 /*          : UINT8         *outStatus      response code                     */
00895 /* return   : INT32                         execution result error code       */
00896 /*          :                               0...normal                        */
00897 /*          :                               -1...parameter error              */
00898 /*          :                               other...signal error              */
00899 /*----------------------------------------------------------------------------*/
00900 INT32 HVC_GetFaceDetectionAngle(INT32 inTimeOutTime, INT32 *outPose, INT32 *outAngle, UINT8 *outStatus)
00901 {
00902     INT32 ret = 0;
00903     INT32 size = 0;
00904     UINT8 recvData[32];
00905 
00906     if((NULL == outPose) || (NULL == outAngle) || (NULL == outStatus)){
00907         return HVC_ERROR_PARAMETER;
00908     }
00909 
00910     /* Send GetFaceDetectionAngle signal command */
00911     ret = HVC_SendCommand(HVC_COM_GET_DETECTION_ANGLE, 0, NULL);
00912     if ( ret != 0 ) return ret;
00913 
00914     /* Receive header */
00915     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00916     if ( ret != 0 ) return ret;
00917 
00918     if ( size > (INT32)sizeof(UINT8)*2 ) {
00919         size = sizeof(UINT8)*2;
00920     }
00921 
00922     /* Receive data */
00923     ret = HVC_ReceiveData(inTimeOutTime, size, recvData);
00924     *outPose = recvData[0];
00925     *outAngle = recvData[1];
00926     return ret;
00927 }
00928 
00929 /*----------------------------------------------------------------------------*/
00930 /* HVC_SetBaudRate                                                            */
00931 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00932 /*          : INT32         inRate          Baudrate                          */
00933 /*          : UINT8         *outStatus      response code                     */
00934 /* return   : INT32                         execution result error code       */
00935 /*          :                               0...normal                        */
00936 /*          :                               -1...parameter error              */
00937 /*          :                               other...signal error              */
00938 /*----------------------------------------------------------------------------*/
00939 INT32 HVC_SetBaudRate(INT32 inTimeOutTime, INT32 inRate, UINT8 *outStatus)
00940 {
00941     INT32 ret = 0;
00942     INT32 size = 0;
00943     UINT8 sendData[32];
00944 
00945     if(NULL == outStatus){
00946         return HVC_ERROR_PARAMETER;
00947     }
00948 
00949     sendData[0] = (UINT8)(inRate&0xff);
00950     /* Send SetBaudRate command signal */
00951     ret = HVC_SendCommand(HVC_COM_SET_BAUDRATE, sizeof(UINT8), sendData);
00952     if ( ret != 0 ) return ret;
00953 
00954     /* Receive header */
00955     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00956     if ( ret != 0 ) return ret;
00957     return 0;
00958 }
00959 
00960 /*----------------------------------------------------------------------------*/
00961 /* HVC_Registration                                                           */
00962 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
00963 /*          : INT32         inUserID        User ID (0-499)                   */
00964 /*          : INT32         inDataID        Data ID (0-9)                     */
00965 /*          : HVC_IMAGE     *outImage       image info                        */
00966 /*          : UINT8         *outStatus      response code                     */
00967 /* return   : INT32                         execution result error code       */
00968 /*          :                               0...normal                        */
00969 /*          :                               -1...parameter error              */
00970 /*          :                               other...signal error              */
00971 /*----------------------------------------------------------------------------*/
00972 INT32 HVC_Registration(INT32 inTimeOutTime, INT32 inUserID, INT32 inDataID, HVC_IMAGE *outImage, UINT8 *outStatus)
00973 {
00974     INT32 ret = 0;
00975     INT32 size = 0;
00976     UINT8 sendData[32];
00977     UINT8 recvData[32];
00978 
00979     if((NULL == outImage) || (NULL == outStatus)){
00980         return HVC_ERROR_PARAMETER;
00981     }
00982 
00983     /* Send Registration signal command */
00984     sendData[0] = (UINT8)(inUserID&0xff);
00985     sendData[1] = (UINT8)((inUserID>>8)&0xff);
00986     sendData[2] = (UINT8)(inDataID&0xff);
00987     ret = HVC_SendCommand(HVC_COM_REGISTRATION, sizeof(UINT8)*3, sendData);
00988     if ( ret != 0 ) return ret;
00989 
00990     /* Receive header */
00991     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
00992     if ( ret != 0 ) return ret;
00993 
00994     /* Receive data */
00995     if ( size >= (INT32)sizeof(UINT8)*4 ) {
00996         ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, recvData);
00997         outImage->width = recvData[0] + (recvData[1]<<8);
00998         outImage->height = recvData[2] + (recvData[3]<<8);
00999         if ( ret != 0 ) return ret;
01000         size -= sizeof(UINT8)*4;
01001     }
01002 
01003     /* Image data */
01004     if ( size >= (INT32)sizeof(UINT8)*64*64 ) {
01005         ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*64*64, outImage->image);
01006         if ( ret != 0 ) return ret;
01007         size -= sizeof(UINT8)*64*64;
01008     }
01009     return 0;
01010 }
01011 
01012 /*----------------------------------------------------------------------------*/
01013 /* HVC_DeleteData                                                             */
01014 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01015 /*          : INT32         inUserID        User ID (0-499)                   */
01016 /*          : INT32         inDataID        Data ID (0-9)                     */
01017 /*          : UINT8         *outStatus      response code                     */
01018 /* return   : INT32                         execution result error code       */
01019 /*          :                               0...normal                        */
01020 /*          :                               -1...parameter error              */
01021 /*          :                               other...signal error              */
01022 /*----------------------------------------------------------------------------*/
01023 INT32 HVC_DeleteData(INT32 inTimeOutTime, INT32 inUserID, INT32 inDataID, UINT8 *outStatus)
01024 {
01025     INT32 ret = 0;
01026     INT32 size = 0;
01027     UINT8 sendData[32];
01028 
01029     if(NULL == outStatus){
01030         return HVC_ERROR_PARAMETER;
01031     }
01032 
01033     /* Send Delete Data signal command */
01034     sendData[0] = (UINT8)(inUserID&0xff);
01035     sendData[1] = (UINT8)((inUserID>>8)&0xff);
01036     sendData[2] = (UINT8)(inDataID&0xff);
01037     ret = HVC_SendCommand(HVC_COM_DELETE_DATA, sizeof(UINT8)*3, sendData);
01038     if ( ret != 0 ) return ret;
01039 
01040     /* Receive header */
01041     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01042     if ( ret != 0 ) return ret;
01043     return 0;
01044 }
01045 
01046 /*----------------------------------------------------------------------------*/
01047 /* HVC_DeleteUser                                                             */
01048 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01049 /*          : INT32         inUserID        User ID (0-499)                   */
01050 /*          : UINT8         *outStatus      response code                     */
01051 /* return   : INT32                         execution result error code       */
01052 /*          :                               0...normal                        */
01053 /*          :                               -1...parameter error              */
01054 /*          :                               other...signal error              */
01055 /*----------------------------------------------------------------------------*/
01056 INT32 HVC_DeleteUser(INT32 inTimeOutTime, INT32 inUserID, UINT8 *outStatus)
01057 {
01058     INT32 ret = 0;
01059     INT32 size = 0;
01060     UINT8 sendData[32];
01061 
01062     if(NULL == outStatus){
01063         return HVC_ERROR_PARAMETER;
01064     }
01065 
01066     /* Send Delete User signal command */
01067     sendData[0] = (UINT8)(inUserID&0xff);
01068     sendData[1] = (UINT8)((inUserID>>8)&0xff);
01069     ret = HVC_SendCommand(HVC_COM_DELETE_USER, sizeof(UINT8)*2, sendData);
01070     if ( ret != 0 ) return ret;
01071 
01072     /* Receive header */
01073     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01074     if ( ret != 0 ) return ret;
01075     return 0;
01076 }
01077 
01078 /*----------------------------------------------------------------------------*/
01079 /* HVC_DeleteAll                                                              */
01080 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01081 /*          : UINT8         *outStatus      response code                     */
01082 /* return   : INT32                         execution result error code       */
01083 /*          :                               0...normal                        */
01084 /*          :                               -1...parameter error              */
01085 /*          :                               other...signal error              */
01086 /*----------------------------------------------------------------------------*/
01087 INT32 HVC_DeleteAll(INT32 inTimeOutTime, UINT8 *outStatus)
01088 {
01089     INT32 ret = 0;
01090     INT32 size = 0;
01091 
01092     if(NULL == outStatus){
01093         return HVC_ERROR_PARAMETER;
01094     }
01095 
01096     /* Send Delete All signal command */
01097     ret = HVC_SendCommand(HVC_COM_DELETE_ALL, 0, NULL);
01098     if ( ret != 0 ) return ret;
01099 
01100     /* Receive header */
01101     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01102     if ( ret != 0 ) return ret;
01103     return 0;
01104 }
01105 
01106 /*----------------------------------------------------------------------------*/
01107 /* HVC_GetUserData                                                            */
01108 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01109 /*          : INT32         inUserID        User ID (0-499)                   */
01110 /*          : INT32         *outDataNo      Registration Info                 */
01111 /*          : UINT8         *outStatus      response code                     */
01112 /* return   : INT32                         execution result error code       */
01113 /*          :                               0...normal                        */
01114 /*          :                               -1...parameter error              */
01115 /*          :                               other...signal error              */
01116 /*----------------------------------------------------------------------------*/
01117 INT32 HVC_GetUserData(INT32 inTimeOutTime, INT32 inUserID, INT32 *outDataNo, UINT8 *outStatus)
01118 {
01119     INT32 ret = 0;
01120     INT32 size = 0;
01121     UINT8 sendData[8];
01122     UINT8 recvData[8];
01123 
01124     if((NULL == outDataNo) || (NULL == outStatus)){
01125         return HVC_ERROR_PARAMETER;
01126     }
01127 
01128     /* Send Get Registration Info signal command */
01129     sendData[0] = (UINT8)(inUserID&0xff);
01130     sendData[1] = (UINT8)((inUserID>>8)&0xff);
01131     ret = HVC_SendCommand(HVC_COM_GET_PERSON_DATA, sizeof(UINT8)*2, sendData);
01132     if ( ret != 0 ) return ret;
01133 
01134     /* Receive header */
01135     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01136     if ( ret != 0 ) return ret;
01137 
01138     if ( size > (INT32)sizeof(UINT8)*2 ) {
01139         size = sizeof(UINT8)*2;
01140     }
01141 
01142     /* Receive data */
01143     ret = HVC_ReceiveData(inTimeOutTime, size, recvData);
01144     *outDataNo = recvData[0] + (recvData[1]<<8);
01145     return ret;
01146 }
01147 
01148 /*----------------------------------------------------------------------------*/
01149 /* HVC_SaveAlbum                                                              */
01150 /* param    : INT32         inTimeOutTime       timeout time (ms)             */
01151 /*          : UINT8         *outAlbumData       Album data                    */
01152 /*          : INT32         *outAlbumDataSize   Album data size               */
01153 /*          : UINT8         *outStatus          response code                 */
01154 /* return   : INT32                             execution result error code   */
01155 /*          :                                   0...normal                    */
01156 /*          :                                   -1...parameter error          */
01157 /*          :                                   other...signal error          */
01158 /*----------------------------------------------------------------------------*/
01159 INT32 HVC_SaveAlbum(INT32 inTimeOutTime, UINT8 *outAlbumData, INT32 *outAlbumDataSize, UINT8 *outStatus)
01160 {
01161     INT32 ret = 0;
01162     INT32 size = 0;
01163 
01164     UINT8 *tmpAlbumData = NULL;;
01165     
01166     if((NULL == outAlbumData) || (NULL == outAlbumDataSize) || (NULL == outStatus)){
01167         return HVC_ERROR_PARAMETER;
01168     }
01169         
01170     /* Send Save Album signal command */
01171     ret = HVC_SendCommand(HVC_COM_SAVE_ALBUM, 0, NULL);
01172     if ( ret != 0 ) return ret;
01173 
01174     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01175     if ( ret != 0 ) return ret;
01176 
01177     if ( size >= (INT32)sizeof(UINT8)*8 + HVC_ALBUM_SIZE_MIN ) {
01178         *outAlbumDataSize = size;
01179         tmpAlbumData = outAlbumData;
01180 
01181         do{
01182             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, tmpAlbumData);
01183             if ( ret != 0 ) return ret;
01184             tmpAlbumData += sizeof(UINT8)*4;
01185 
01186             ret = HVC_ReceiveData(inTimeOutTime, sizeof(UINT8)*4, tmpAlbumData);
01187             if ( ret != 0 ) return ret;
01188             tmpAlbumData += sizeof(UINT8)*4;
01189 
01190             ret = HVC_ReceiveData(inTimeOutTime, size - sizeof(UINT8)*8, tmpAlbumData);
01191             if ( ret != 0 ) return ret;
01192         }while(0);
01193     }
01194     return ret;
01195 }
01196 
01197 
01198 /*----------------------------------------------------------------------------*/
01199 /* HVC_LoadAlbum                                                              */
01200 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01201 /*          : UINT8         *inAlbumData    Album data                        */
01202 /*          : INT32         inAlbumDataSize Album data size                   */
01203 /*          : UINT8         *outStatus      response code                     */
01204 /* return   : INT32                         execution result error code       */
01205 /*          :                               0...normal                        */
01206 /*          :                               -1...parameter error              */
01207 /*          :                               other...signal error              */
01208 /*----------------------------------------------------------------------------*/
01209 INT32 HVC_LoadAlbum(INT32 inTimeOutTime, UINT8 *inAlbumData, INT32 inAlbumDataSize, UINT8 *outStatus)
01210 {
01211     INT32 ret = 0;
01212     INT32 size = 0;
01213         
01214     if((NULL == inAlbumData) || (NULL == outStatus)){
01215         return HVC_ERROR_PARAMETER;
01216     }
01217         
01218     /* Send Save Album signal command */
01219     ret = HVC_SendCommandOfLoadAlbum(HVC_COM_LOAD_ALBUM, inAlbumDataSize, inAlbumData);
01220     if ( ret != 0 ) return ret;
01221     
01222     /* Receive header */
01223     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01224     if ( ret != 0 ) return ret;
01225 
01226     return ret;
01227 }
01228 
01229 /*----------------------------------------------------------------------------*/
01230 /* HVC_WriteAlbum                                                             */
01231 /* param    : INT32         inTimeOutTime   timeout time (ms)                 */
01232 /*          : UINT8         *outStatus      response code                     */
01233 /* return   : INT32                         execution result error code       */
01234 /*          :                               0...normal                        */
01235 /*          :                               -1...parameter error              */
01236 /*          :                               other...signal error              */
01237 /*----------------------------------------------------------------------------*/
01238 INT32 HVC_WriteAlbum(INT32 inTimeOutTime, UINT8 *outStatus)
01239 {
01240     INT32 ret = 0;
01241     INT32 size = 0;
01242 
01243     if(NULL == outStatus){
01244         return HVC_ERROR_PARAMETER;
01245     }
01246 
01247     /* Send Write Album signal command */
01248     ret = HVC_SendCommand(HVC_COM_WRITE_ALBUM, 0, NULL);
01249     if ( ret != 0 ) return ret;
01250 
01251     /* Receive header */
01252     ret = HVC_ReceiveHeader(inTimeOutTime, &size, outStatus);
01253     if ( ret != 0 ) return ret;
01254 
01255     return ret;
01256 }
01257 
01258