/* write attribute: string */ static void wr_ch_str(struct iio_channel *chn, const char* what, const char* str) { errchk(iio_channel_attr_write(chn, what, str), what); }
/** * @brief This functions manage the anticollision * @param *pDataRead : Pointer to the PCD response * @param CascadeLevel : information on the current cascade level * @return ISO14443A_SUCCESSCODE the function is succesful * @return ISO14443A_ERRORCODE_DEFAULT : an error occured */ static int8_t ISO14443A_AC( uint8_t *pDataRead, u8 CascadeLevel ) { u8 AnticolParameter [7] = {0x00, ISO14443A_NVM_20, 0x08,0x00,0x00,0x00,0x00}; u8 NbResponseByte = 0; u8 NbResponseByteOrigin = 0; u8 Collision = 0; u8 ByteCollisionIndex = 0; u8 BitCollisionIndex = 0; u8 RemainingBit = 0; u8 NewByteCollisionIndex = 0; u8 NewBitCollisionIndex = 0; u8 UID[4] = {0x00,0x00,0x00,0x00}; int8_t status; /* prepare command regarding cascade level on-going */ AnticolParameter[0] = CascadeLevel; /* sends the command to the PCD device*/ errchk(PCD_SendRecv(0x03,AnticolParameter,pDataRead)); NbResponseByte = pDataRead[1]; NbResponseByteOrigin = NbResponseByte; Collision = (pDataRead[NbResponseByte-1] & 0x80); ByteCollisionIndex = pDataRead[NbResponseByte]; BitCollisionIndex = pDataRead[NbResponseByte+1]; /* case that should not happend, as occurs because we have miss another collision */ if( BitCollisionIndex == 8) { return ISO14443A_ERRORCODE_DEFAULT; } /* check for collision (Tag of different UID length at the same time not managed so far) */ while( Collision == 0x80) { /* clear collision detection */ Collision = 0x00; /* send the command to the PCD device*/ AnticolParameter[1] = ISO14443A_NVM_20 + ((ByteCollisionIndex) <<4) + (BitCollisionIndex+1); if( ByteCollisionIndex == 0) { AnticolParameter[2] = pDataRead[2] & ((u8)(~(0xFF<<(BitCollisionIndex+1)))); /* ISO said it's better to put collision bit to value 1 */ AnticolParameter[3] = (BitCollisionIndex+1) | 0x40; /* add split frame bit */ UID [0] = AnticolParameter[2]; } else if( ByteCollisionIndex == 1) { AnticolParameter[2] = pDataRead[2]; AnticolParameter[3] = pDataRead[3] & ((u8)(~(0xFF<<(BitCollisionIndex+1)))); /* ISO said it's better to put collision bit to value 1 */ AnticolParameter[4] = (BitCollisionIndex+1) | 0x40; /* add split frame bit */ UID [0] = AnticolParameter[2]; UID [1] = AnticolParameter[3]; } else if( ByteCollisionIndex == 2) { AnticolParameter[2] = pDataRead[2]; AnticolParameter[3] = pDataRead[3]; AnticolParameter[4] = pDataRead[4] & ((u8)(~(0xFF<<(BitCollisionIndex+1)))); /* ISO said it's better to put collision bit to value 1 */ AnticolParameter[5] = (BitCollisionIndex+1) | 0x40; /* add split frame bit */; UID [0] = AnticolParameter[2]; UID [1] = AnticolParameter[3]; UID [2] = AnticolParameter[4]; } else if( ByteCollisionIndex == 3) { AnticolParameter[2] = pDataRead[2]; AnticolParameter[3] = pDataRead[3]; AnticolParameter[4] = pDataRead[4]; AnticolParameter[5] = pDataRead[5] & ((u8)(~(0xFF<<(BitCollisionIndex+1)))); /* ISO said it's better to put collision bit to value 1 */ AnticolParameter[6] = (BitCollisionIndex+1) | 0x40; /* add split frame bit */; UID [0] = AnticolParameter[2]; UID [1] = AnticolParameter[3]; UID [2] = AnticolParameter[4]; UID [3] = AnticolParameter[5]; } else return ISO14443A_ERRORCODE_DEFAULT; /* send part of the UID */ PCD_SendRecv((0x03+ByteCollisionIndex+1),AnticolParameter,pDataRead); if(pDataRead[0] != 0x80) return ISO14443A_ERRORCODE_DEFAULT; /* check if there is another collision to take into account*/ NbResponseByte = pDataRead[1]; Collision = (pDataRead[NbResponseByte-1]) & 0x80; if ( Collision == 0x80) { NewByteCollisionIndex = pDataRead[NbResponseByte]; NewBitCollisionIndex = pDataRead[NbResponseByte+1]; } /* we can check that non-alignement is the one expected */ RemainingBit = 8 - (0x0F & (pDataRead[2+(NbResponseByte-2)-1])); if( RemainingBit == BitCollisionIndex+1) { /* recreate the good UID */ if( ByteCollisionIndex == 0) { UID [0] = ((~(0xFF << (BitCollisionIndex+1))) & AnticolParameter[2]) | pDataRead[2] ; UID [1] = pDataRead[3]; UID [2] = pDataRead[4]; UID [3] = pDataRead[5]; } else if( ByteCollisionIndex == 1) { UID [1] = ((~(0xFF << (BitCollisionIndex+1))) & AnticolParameter[3]) | pDataRead[2] ; UID [2] = pDataRead[3]; UID [3] = pDataRead[4]; } else if( ByteCollisionIndex == 2) { UID [2] = ((~(0xFF << (BitCollisionIndex+1))) & AnticolParameter[4]) | pDataRead[2] ; UID [3] = pDataRead[3]; } else if( ByteCollisionIndex == 3) { UID [3] = ((~(0xFF << (BitCollisionIndex+1))) & AnticolParameter[5]) | pDataRead[2] ; } else return ISO14443A_ERRORCODE_DEFAULT; } else return ISO14443A_ERRORCODE_DEFAULT; /* prepare the buffer expected by the caller */ pDataRead[0] = 0x80; pDataRead[1] = NbResponseByteOrigin; pDataRead[2] = UID [0]; pDataRead[3] = UID [1]; pDataRead[4] = UID [2]; pDataRead[5] = UID [3]; pDataRead[6] = UID[0]^UID[1]^UID[2]^UID[3]; /* if collision was detected restart anticol */ if ( Collision == 0x80) { if( ByteCollisionIndex != NewByteCollisionIndex ) { ByteCollisionIndex += NewByteCollisionIndex; BitCollisionIndex = NewBitCollisionIndex; } else { ByteCollisionIndex += NewByteCollisionIndex; BitCollisionIndex += (NewBitCollisionIndex+1); } } } return ISO14443A_SUCCESSCODE; Error: return ISO14443A_ERRORCODE_DEFAULT; }
/* write attribute: long long int */ static void wr_ch_lli(struct iio_channel *chn, const char* what, long long val) { errchk(iio_channel_attr_write_longlong(chn, what, val), what); }
//********************// //Engine Display Class// //********************// void Engine_Init::RunDisplay() { //GLFW Initiate errchk(glfwInit()); cout << glfwGetVersionString() << endl; //GLFW Set Window Properties glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_SAMPLES, props.MSAA); props.init(); //Initialize the engine properties from the properties input file "Settings." camera.init(props); //Initialize the camera class. //Initialize Window switch(props.FullScreen) { case 0: {window = glfwCreateWindow(props.WinWidth, props.WinHeight, "GameEngine Test", nullptr, nullptr);break;} case 1: {window = glfwCreateWindow(props.WinWidth, props.WinHeight, "GameEngine Test", glfwGetPrimaryMonitor(), nullptr);break;} } if( window == NULL ){ fprintf( stderr, "Failed to open GLFW window.\n" ); glfwTerminate(); } glfwMakeContextCurrent(window); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); //Set the call back functions setEventHandling(); glfwSetKeyCallback(window, StateBase::keycallback_dispatch); glfwSetCursorPosCallback(window, StateBase::mousecallback_dispatch); glfwSetScrollCallback(window, StateBase::scrollcallback_dispatch); //Initialize Glew glewExperimental = GL_TRUE; glewInit(); //Set view port dimensions glViewport(0, 0, props.WinWidth, props.WinHeight); //Setup OpenGL Options glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Poly Fill Mode glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); //System Processors int NProc = sysconf( _SC_NPROCESSORS_ONLN ); cout << "Number of System Processors: " << NProc << endl; //Max Number of Attributes GLint nrAttributes; glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes); cout << "Maximum nr of vertex attributes supported: " << nrAttributes << std::endl; GLErrorCatch("GL Preamble"); //Set the frames per second timer fpsTimer ft; //This sets the View and Projection "Matrices" Uniform Buffer Object at global location 0; //TM.SetViewUniformBufferObject(); //Setup screen text writing SW.Setup("bin/fonts/FreeSans.ttf",props.WinWidth,props.WinHeight);//Setup screen font GLErrorCatch("Screen Writer Setup"); //Initialize Shaders SCC.ShaderLoader(); GLErrorCatch("Shader Handling"); //Initialize SolarSystem double TIMECHECK = glfwGetTime(); solarsystem.SetupClass(OPC); cout << "SolarSys CLASS SETUP TIME: " << glfwGetTime() - TIMECHECK << "\n"; cout << "SolarSystem class Setup...\n"; solarsystem.GenerateSolarSystem(OPC,0,0); cout << "SolarSystem Generated...\n"; GLErrorCatch("SolarSystem Generation"); //Setup Global Uniform Handler GGUBO.SetGlobalUBO(SCC); camera.SetProjViewUBO(SCC); GLErrorCatch("Uniform Handling"); //Setup Timing Stats TimingStats TS(SW,props); TS.SetObject("Preamble"); TS.SetObject("camera.PrepareCameraData"); TS.SetObject("GGUBO.UpdateGlobalUBO"); TS.SetObject("solarsystem.PrepareData"); TS.SetObject("ProcessDrawArray"); TS.SetObject("PrintScreenTimers"); TS.SetObject("Screen_Console"); TS.SetObject("glfwSwapBuffers"); TS.SetObject("drawArray.ClearDrawArrays"); TS.SetObject("EventPolling"); TS.SetObject("Skybox Drawing"); while(!glfwWindowShouldClose(window)) { //********************* //Frame Timer //********************* TS.TS(0); dt.SetTime(); //************************* //Sets the background color //************************* glClearColor(Env.bgColor.x, Env.bgColor.y, Env.bgColor.z, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); TS.TE(0); //*************** //Setup Scene //*************** //Prepare the camera class for the frame //cout << "***TEST1***" << endl; TS.TS(1); camera.PrepareCameraData(); TS.TE(1); //Update the global uniform buffer objects TS.TS(2); GGUBO.UpdateGlobalUBO(camera); TS.TE(2); //Prepare the solarsystem data //cout << "***TEST2***" << endl; TS.TS(3); solarsystem.PrepareData(OPC,drawArray,drawInstArray,camera,dt,false); TS.TE(3); //*************** //Scene Rendering //*************** //cout << "***TEST3***" << endl; //Draw all objects TS.TS(10); skybox.DrawSkybox(camera,props); TS.TE(10); TS.TS(4); ProcessDrawArray(); TS.TE(4); //******************* //Interface Rendering //******************* //Render Frame Timer TS.TS(5); PrintScreenTimers(SW,ft); TS.TE(5); //cout << "***TEST4***" << endl; //Console Functions TS.TS(6); Screen_Console(SW); TS.TE(6); //Statistics Rendering TS.CalcAndRenderStats(); //************* //Swap Buffers //************* TS.TS(7); //glfwSwapInterval(1); //Seems to slow the program to 30fps glfwSwapBuffers(window);//Something is wrong here, SUPER expensive TS.TE(7); //********************* //Check and call events //********************* TS.TS(9); glfwPollEvents(); //glfwWaitEvents(); Do_Movement(); TS.TE(9); //************* //Frame Cleanup //************* TS.TS(8); drawArray.DrawArrayReset(); drawInstArray.ClearInstDrawArrays(); TS.TE(8); //cout << "FRAME END\n"; //GLErrorCatch("MainLoop"); } drawArray.ClearDrawArrays(); glfwTerminate(); }
void SongPlayback::startPlayback() { result_ = system_->playSound(FMOD_CHANNEL_FREE, stream1_, false, &channel_); errchk(result_); result_ = channel_->getFrequency(&defreq_); errchk(result_); result_ = pitch_->setParameter(FMOD_DSP_PITCHSHIFT_FFTSIZE, 4096); errchk(result_); result_ = lowpass_->setParameter(FMOD_DSP_LOWPASS_CUTOFF, 20000.0); errchk(result_); result_ = highpass_->setParameter(FMOD_DSP_HIGHPASS_CUTOFF, 20.0); errchk(result_); result_ = flange_->setParameter(FMOD_DSP_FLANGE_RATE, 2); errchk(result_); result_ = echo_->setParameter(FMOD_DSP_ECHO_DRYMIX, 1); errchk(result_); result_ = echo_->setParameter(FMOD_DSP_ECHO_WETMIX, 0); errchk(result_); result_ = system_->addDSP(pitch_,0); errchk(result_); result_ = system_->addDSP(lowpass_,0); errchk(result_); result_ = system_->addDSP(highpass_,0); errchk(result_); result_ = system_->addDSP(flange_,0); errchk(result_); result_ = system_->addDSP(tremolo_,0); errchk(result_); result_ = system_->addDSP(echo_,0); errchk(result_); result_ = pitch_->setActive(active_); errchk(result_); result_ = lowpass_->setActive(active_); errchk(result_); setFlangeActive(false); setTremoloActive(false); streamState_ = eStreamPlaying; }
int SongPlayback::initialize() { result_ = FMOD::System_Create(&system_); errchk(result_); result_ = system_->getVersion(&version_); errchk(result_); if(version_ < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. Required: %08x.", version_, FMOD_VERSION); return 1; } result_ = system_->init(1, FMOD_INIT_NORMAL, 0); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitch_); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &lowpass_); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &highpass_); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_ECHO, &echo_); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_FLANGE, &flange_); errchk(result_); result_ = system_->createDSPByType(FMOD_DSP_TYPE_TREMOLO, &tremolo_); errchk(result_); result_ = system_->createStream(path_.c_str(), FMOD_HARDWARE | FMOD_LOOP_NORMAL| FMOD_2D, 0, &stream1_); errchk(result_); result_ = stream1_->getLength(&songLength_, FMOD_TIMEUNIT_MS); errchk(result_); setLoop(); return 0; }
int main(int argc, char **argv) { int c, i, j, got, args, jsonlen, istart; int odim1, odim2, blen, pad; int idim1=0, idim2=0, bitpix=0, ncard=0; int verbose=0; size_t totbytes, dlen; char tbuf[SZ_LINE]; char *buf=NULL; char *jsonheader=NULL; char *iname=NULL, *oname=NULL; FILE *ofp=NULL; Optinfo optinfo; #if HAVE_CFITSIO int status = 0; int n; int hdutype; int maxcard, morekeys; int dims[2] = {0, 0}; int block = 1; void *dbuf; double d1, d2, d3, d4; double cens[2] = {0.0, 0.0}; char *s; char *filter=NULL; char *evtlist = DEF_EVTLIST; char card[81]; char s1[BUFLEN], s2[BUFLEN], s3[BUFLEN], s4[BUFLEN]; fitsfile *fptr=NULL, *ofptr=NULL; #elif HAVE_FUNTOOLS char *s=NULL; int dtype; Fun ifun=NULL, tfun=NULL; #endif /* we want the args in the same order in which they arrived, and gnu getopt sometimes changes things without this */ putenv("POSIXLY_CORRECT=true"); /* process switch arguments */ while ((c = getopt(argc, argv, "b:e:f:s:v")) != -1){ switch(c){ case 'b': #if HAVE_CFITSIO block = atoi(optarg); #else fprintf(stderr, "warning: -b switch only for cfitsio (ignoring)\n"); #endif break; case 'e': #if HAVE_CFITSIO evtlist = optarg; #else fprintf(stderr, "warning: -e switch only for cfitsio (ignoring)\n"); #endif break; case 'f': #if HAVE_CFITSIO filter = optarg; #else fprintf(stderr, "warning: -f switch only for cfitsio (ignoring)\n"); #endif break; case 's': #if HAVE_CFITSIO s = strdup(optarg); if( strlen(s) > BUFLEN ) s[BUFLEN-1] = '\0'; if( sscanf(s, "%[0-9.*] @ %[-0-9.*] , %[0-9.*] @ %[-0-9.*]%n", s1, s2, s3, s4, &n) == 4){ dims[0] = atof(s1); cens[0] = atof(s2); dims[1] = atof(s3); cens[1] = atof(s4); } else if(sscanf(s, "%[-0-9.*] : %[-0-9.*] , %[-0-9.*] : %[-0-9.*]%n", s1, s2, s3, s4, &n) == 4){ d1 = atof(s1); d2 = atof(s2); d3 = atof(s3); d4 = atof(s4); dims[0] = d2 - d1 + 1; cens[0] = dims[0] / 2; dims[1] = d4 - d3 + 1; cens[1] = dims[1] / 2; } else { fprintf(stderr, "warning: unknown arg for -s switch (ignoring)\n"); } if( s ) free(s); #else fprintf(stderr, "warning: -s switch only for cfitsio (ignoring)\n"); #endif break; case 'v': verbose++; break; } } /* check for required arguments */ args = argc - optind; if( args < 2 ){ fprintf(stderr, "usage: %s iname oname\n", argv[0]); exit(1); } iname = argv[optind++]; oname = argv[optind++]; /* optional info */ if( !(optinfo = (Optinfo)calloc(sizeof(OptinfoRec), 1)) ){ fprintf(stderr, "ERROR: can't allocate optional info rec\n"); exit(1); } /* open the input FITS file */ #if HAVE_CFITSIO fptr = openFITSFile(iname, evtlist, &hdutype, &status); errchk(status); #elif HAVE_FUNTOOLS if( !(ifun = FunOpen(iname, "r", NULL)) ){ fprintf(stderr, "ERROR could not open input FITS file: %s (%s)\n", iname, strerror(errno)); exit(1); } #endif /* save the input filename in the png file */ optinfo->fitsname = iname; /* open the output PGN file */ if( !strcmp(oname, "-") || !strcmp(oname, "stdout") ){ ofp = stdout; } else if( !(ofp = fopen(oname, "w")) ){ fprintf(stderr, "ERROR: could not create output PNG file: %s (%s)\n", oname, strerror(errno)); exit(1); } #if HAVE_CFITSIO switch(hdutype){ case IMAGE_HDU: // get image array dbuf = getImageToArray(fptr, NULL, NULL, &idim1, &idim2, &bitpix, &status); errchk(status); fits_get_hdrspace(fptr, &maxcard, &morekeys, &status); errchk(status); ofptr = fptr; break; default: ofptr = filterTableToImage(fptr, filter, NULL, dims, cens, block, &status); errchk(status); // get image array dbuf = getImageToArray(ofptr, NULL, NULL, &idim1, &idim2, &bitpix, &status); errchk(status); // get number of keys fits_get_hdrspace(ofptr, &maxcard, &morekeys, &status); errchk(status); break; } #elif HAVE_FUNTOOLS /* copy the input fits header into a FITS image header */ if( !(tfun = (Fun)calloc(1, sizeof(FunRec))) ){ fprintf(stderr, "ERROR: could not create tfun struct\n"); exit(1); } _FunCopy2ImageHeader(ifun, tfun); /* and save for storage in the png file */ optinfo->fitsheader = (char *)tfun->header->cards; /* get image parameters. its safe to do this before calling image get so long as we don't change bitpix before that call */ FunInfoGet(ifun, FUN_SECT_BITPIX, &bitpix, FUN_SECT_DIM1, &idim1, FUN_SECT_DIM2, &idim2, 0); #endif /* convert FITS header into a json string */ snprintf(tbuf, SZ_LINE-1, "{\"js9Protocol\": %s, ", JS9_PROTOCOL); scat(tbuf, &jsonheader); snprintf(tbuf, SZ_LINE-1, "\"js9Endian\": \"%s\", ", JS9_ENDIAN); scat(tbuf, &jsonheader); snprintf(tbuf, SZ_LINE-1, "\"cardstr\": \""); scat(tbuf, &jsonheader); // concat header cards into a single string #if HAVE_CFITSIO while( ++ncard <= maxcard ){ fits_read_record(ofptr, ncard, card, &status); errchk(status); // change " to ' for(i=0; i<80; i++){ if( card[i] == '"' ){ card[i] = '\''; } } snprintf(tbuf, SZ_LINE-1, "%-80s", card); scat(tbuf, &jsonheader); } #elif HAVE_FUNTOOLS while( (s = FunParamGets(tfun, NULL, ++ncard, NULL, &dtype)) ){ for(i=0; i<80; i++){ if( s[i] == '"' ){ s[i] = '\''; } } scat(s, &jsonheader); if( s ) free(s); } #endif // end with the number of cards snprintf(tbuf, SZ_LINE-1, "\", \"ncard\": %d}", ncard); scat(tbuf, &jsonheader); /* we want the image buffer to start on an 8-byte boundary, so make jsonheader + null byte end on one */ pad = 8 - (strlen(jsonheader) % 8) - 1; for(i=0; i<pad; i++){ strcat(jsonheader, " "); } /* get final length of json header */ jsonlen = strlen(jsonheader); /* total length of the header + null + image we are storing */ blen = ABS(bitpix/8); dlen = (size_t)idim1 * (size_t)idim2 * blen; totbytes = jsonlen + 1 + dlen; /* all of this should now fit into the png image */ /* somewhat arbitrarily, we use idim1 for odim1, and adjust odim2 to fit */ odim1 = idim1; odim2 = (int)(((totbytes + odim1 - 1) / odim1) + (COLOR_CHANNELS-1)) / COLOR_CHANNELS; /* allocate buf to hold json header + null byte + RGB image */ if( !(buf=calloc(COLOR_CHANNELS, odim1 * odim2)) ){ fprintf(stderr, "ERROR: can't allocate image buf\n"); exit(1); } /* move the json header into the output buffer */ memmove(buf, jsonheader, jsonlen); /* add a null byte to signify end of json header */ buf[jsonlen] = '\0'; /* offset into image buffer where image starts, past header and null byte */ istart = jsonlen + 1; /* debug output */ if( verbose ){ fprintf(stderr, "idim=%d,%d (bitpix=%d jsonlen=%d istart=%d endian=%s) [%ld] -> odim=%d,%d [%d]\n", idim1, idim2, bitpix, jsonlen, istart, JS9_ENDIAN, totbytes, odim1, odim2, odim1 * odim2 * COLOR_CHANNELS); } #if HAVE_CFITSIO /* move the json header into the output buffer */ memmove(&buf[istart], dbuf, dlen); #elif HAVE_FUNTOOLS /* extract and bin the data section into an image buffer */ if( !FunImageGet(ifun, &buf[istart], NULL) ){ fprintf(stderr, "ERROR: could not FunImageGet: %s\n", iname); exit(1); } #endif /* debugging output to check against javascript input */ if( verbose > 1 ){ fprintf(stderr, "jsonheader: %s\n", jsonheader); for(j=0; j<idim2; j++){ fprintf(stderr, "data #%d: ", j); for(i=0; i<idim1; i++){ switch(bitpix){ case 8: fprintf(stderr, "%d ", *(unsigned char *)(buf + istart + ((j * idim1) + i) * blen)); break; case 16: fprintf(stderr, "%d ", *(short *)(buf + istart + ((j * idim1) + i) * blen)); break; case -16: fprintf(stderr, "%d ", *(unsigned short *)(buf + istart + ((j * idim1) + i) * blen)); break; case 32: fprintf(stderr, "%d ", *(int *)(buf + istart + ((j * idim1) + i) * blen)); break; case -32: fprintf(stderr, "%.3f ", *(float *)(buf + istart + ((j * idim1) + i) * blen)); break; case -64: fprintf(stderr, "%.3f ", *(double *)(buf + istart + ((j * idim1) + i) * blen)); break; } } fprintf(stderr, "\n"); } fprintf(stderr, "\n"); } /* might have to swap to preferred endian for png creation */ if( (!strncmp(JS9_ENDIAN, "l", 1) && is_bigendian()) || (!strncmp(JS9_ENDIAN, "b", 1) && !is_bigendian()) ){ swap_data(&buf[istart], idim1 * idim2, bitpix/8); } /* write the PNG file */ got = writePNG(ofp, buf, odim1, odim2, optinfo); /* free up space */ if( buf ) free(buf); if( optinfo ) free(optinfo); if( jsonheader ) free(jsonheader); /* close files */ #if HAVE_CFITSIO status = 0; if( ofptr && (ofptr != fptr) ) closeFITSFile(ofptr, &status); if( fptr ) closeFITSFile(fptr, &status); if( dbuf ) free(dbuf); #elif HAVE_FUNTOOLS if( ifun ) FunClose(ifun); if( tfun ){ FunClose(tfun); free(tfun); } #endif if( ofp) fclose(ofp); /* return the news */ return got; }
/** * @brief this function decodes the updatebinary commands and emits the response to the PCD * @param pData : RF command received by the PICC * @param FileSelected : the Id of the file selected by the Select command * @retval PICCNFCT4_SUCCESSCODE : the receiving command is a Select CC file * @retval PICCNFCT4_ERRORCODE_COMMANDUNKNOWN : the command byte is unknown * @retval PICCNFCT4_ERRORCODE_PARAMETER : one parameter is erroneous * @retval PICCNFCT4_ERRORCODE_GENERIC : the function is not succesful */ int8_t PICCNFCT4_UpdateBinary (uc8 *pData ) { uint16_t FileOffset = (pData[5]<<8 & 0xFF00) | pData[6]; uint8_t *pFile, NbByteToUpdate = pData[7]; int8_t status; if (FileSelected == NDEFFILE_SELECTED_NONE) return PICCNFCT4_ERRORCODE_COMMANDUNKNOWN; /* fgr to change error when State Machine will be added */ if (pData[PICC_DATA_OFFSET+2] != PICCNFCT4_UPDATECMD) return PICCNFCT4_ERRORCODE_COMMANDUNKNOWN; /* according to the Application selected by the SelectApplication command */ if( ApplicationSelected == PICCNFCT4_APPLI_FWU ) { return RFT_ReceiveFile (); } /* check the parameter of the read binary command */ errchk(PICCNFCT4_IsReadWriteParametersOk (FileSelected , FileOffset , NbByteToUpdate )); /* Check the file offset and Number of byte to read parameters. */ switch (FileSelected) { case NDEFFILE_SELECTED_CCFILE: pFile = CardCCfile; if (FileOffset + NbByteToUpdate > NFCT4_MAX_CCMEMORY) { PICC7816_SendAStatusCode( pData, PICCNFCT4_STATUS_WRONGP1P2PARAMETERS ); return PICCNFCT4_ERRORCODE_GENERIC ; } break; case NDEFFILE_SELECTED_NDEFFILE1: if (nfc_tagtype == TT4A) pFile = CardNDEFfileT4A; if (FileOffset + NbByteToUpdate > NFCT4_MAX_NDEFMEMORY) { PICC7816_SendAStatusCode( pData, PICCNFCT4_STATUS_WRONGP1P2PARAMETERS ); return PICCNFCT4_ERRORCODE_GENERIC ; } break; default: PICC7816_SendAStatusCode( pData, PICCNFCT4_STATUS_FILENNOTFOUND ); return PICCNFCT4_SUCCESSCODE; } /* update the NDEF file */ memcpy(&(pFile[FileOffset]),&(pData [8]), NbByteToUpdate); /* Send the response */ PICC7816_SendBuffer(pData,NULL,0,PICCNFCT4_STATUS_STATUSOK); #ifdef TAG_MANAGEMENT /* Write to flash only when the size is written (last updatebinary command)*/ if (FileOffset == 0 && !(pData[8] == 0 && pData[9] == 0)) { /* Write into flash */ if (FileSelected == NDEFFILE_SELECTED_NDEFFILE1) { updateFlash = true; } } #endif /* TAG_MANAGEMENT */ return PICCNFCT4_SUCCESSCODE ; Error : PICC7816_SendAStatusCode( pData, PICCNFCT4_STATUS_WRONGP1P2PARAMETERS ); return PICCNFCT4_ERRORCODE_PARAMETER ; }