/* * This function sends some data bytes to the destination */ int PozyxClass::sendData(uint16_t destination, uint8_t *pData, int size) { if(size > MAX_BUF_SIZE) return POZYX_FAILURE; // trying to send too much data uint8_t status = 0; uint8_t tmp_data[size+1]; tmp_data[0] = 0; // the first byte is the offset byte. memcpy(tmp_data+1, pData, size); // set the TX buffer status = regFunction(POZYX_TX_DATA, tmp_data, size+1, NULL, 0); // stop if POZYX_TX_DATA returned an error. if(status == POZYX_FAILURE) return status; // send the packet uint8_t params[3]; params[0] = (uint8_t)destination; params[1] = (uint8_t)(destination>>8); params[2] = 0x06; // flag to indicate we're just sending data status = regFunction(POZYX_TX_SEND, (uint8_t *)¶ms, 3, NULL, 0); return status; }
/* * Remotly write to a register of another pozyx device */ int PozyxClass::remoteRegWrite(uint16_t destination, uint8_t reg_address, uint8_t *pData, int size) { // some checks if(!IS_REG_WRITABLE(reg_address)) return POZYX_FAILURE; // the register is not writable if(size > MAX_BUF_SIZE-1) return POZYX_FAILURE; // trying to write too much data int status = 0; // first prepare the packet to send uint8_t tmp_data[size+1]; tmp_data[0] = 0; tmp_data[1] = reg_address; // the first byte is the register address we want to start writing to. memcpy(tmp_data+2, pData, size); // the remaining bytes are the data bytes to be written starting at the register address. status = regFunction(POZYX_TX_DATA, (uint8_t *)&tmp_data, size+2, NULL, 0); // stop if POZYX_TX_DATA returned an error. if(status == POZYX_FAILURE) return status; // send the packet uint8_t params[3]; params[0] = (uint8_t)destination; params[1] = (uint8_t)(destination>>8); params[2] = 0x04; // flag to indicate a register write status = regFunction(POZYX_TX_SEND, (uint8_t *)¶ms, 3, NULL, 0); return status; }
int PozyxClass::writeTXBufferData(uint8_t data[], int size, int offset) { if (offset + size > MAX_BUF_SIZE){ return POZYX_FAILURE; } int i, status = 1; int max_bytes = BUFFER_LENGTH-2; int n_runs = ceil((float)size / max_bytes); uint8_t params[BUFFER_LENGTH]; // read out the received data. for(i=0; i<n_runs; i++) { params[0] = offset + i*max_bytes; // the offset if(i+1 != n_runs){ memcpy(params+1, data+i*max_bytes, max_bytes); status &= regFunction(POZYX_TX_DATA, params, max_bytes + 1, NULL, 0); }else{ memcpy(params+1, data+i*max_bytes, size-i*max_bytes); status &= regFunction(POZYX_TX_DATA, params, size-i*max_bytes+1, NULL, 0); } } return status; }
void enblt_load(EnemyBullet *blt, std::string type, float srcx, float srcy, float tgtx, float tgty) { std::string filename = "enblt_" + type + ".lua"; loadScript(&blt->script, filename); regFunction(&blt->script, "init", enblt_init); regFunction(&blt->script, "updatePos", enblt_getPos); runFunction(&blt->script, "start", srcx, srcy, tgtx, tgty); enblt_loadValues(blt); }
/* * Remotly read from a register of another pozyx device */ int PozyxClass::remoteRegFunction(uint16_t destination, uint8_t reg_address, uint8_t *params, int param_size, uint8_t *pData, int size) { // some checks if(!IS_FUNCTIONCALL(reg_address)) return POZYX_FAILURE; // the register is not a function int status = 0; // first prepare the packet to send uint8_t tmp_data[param_size+2]; tmp_data[0] = 0; tmp_data[1] = reg_address; // the first byte is the function register address we want to call. memcpy(tmp_data+2, params, param_size); // the remaining bytes are the parameter bytes for the function. status = regFunction(POZYX_TX_DATA, tmp_data, param_size+2, NULL, 0); // stop if POZYX_TX_DATA returned an error. if(status == POZYX_FAILURE) return status; // send the packet uint8_t tx_params[3]; tx_params[0] = (uint8_t)destination; tx_params[1] = (uint8_t)(destination>>8); tx_params[2] = 0x08; // flag to indicate a register function call status = regFunction(POZYX_TX_SEND, tx_params, 3, NULL, 0); // stop if POZYX_TX_SEND returned an error. if(status == POZYX_FAILURE) return status; // wait up to x ms to receive a response if(waitForFlag(POZYX_INT_STATUS_RX_DATA, POZYX_DELAY_INTERRUPT)) { // we received a response, now get some information about the response uint8_t rx_info[3]; regRead(POZYX_RX_NETWORK_ID, rx_info, 3); uint16_t remote_network_id = rx_info[0] + ((uint16_t)rx_info[1]<<8); uint8_t data_len = rx_info[2]; if( remote_network_id == destination && data_len == size+1) { uint8_t return_data[size+1]; status = readRXBufferData(return_data, size+1); if(status == POZYX_FAILURE) return status; memcpy(pData, return_data+1, size); return return_data[0]; } }else{ // timeout return POZYX_FAILURE; } }
void plblt_load(PlayerBullet *blt, std::string type, float srcx, float srcy, float tgtx, float tgty) { std::string filename = "plblt_" + type + ".lua"; loadScript(&blt->script, filename); regFunction(&blt->script, "init", plblt_init); regFunction(&blt->script, "updatePos", plblt_getPos); regFunction(&blt->script, "kill", plblt_kill); runFunction(&blt->script, "start", srcx, srcy, tgtx, tgty); plblt_loadValues(blt); }
void reg_mt_image(lua_State *L) { luaL_newmetatable(L, "image"); regFunction(L, "width", luaimage_width); regFunction(L, "height", luaimage_height); regFunction(L, "cut", luaimage_cut); regFunction(L, "__towatch", luaimage_towatch); regIndexMt(L); lua_pop(L, 1); }
void reg_msdp(lua_State *L) { lua_newtable(L); regFunction(L, "list", msdp_list); regFunction(L, "reset", msdp_reset); regFunction(L, "send", msdp_send); regFunction(L, "report", msdp_report); regFunction(L, "unreport", msdp_unreport); lua_setglobal(L, "msdp"); }
void loadMenu(std::string menu) { clearMenu(); danmakux.menuChoice = 0; if (danmakux.level.running) closeScript(&danmakux.level); std::string menufile = menu + ".lua"; loadScript(&danmakux.menu, menufile); regFunction(&danmakux.menu, "addMenuChoice", addMenuItem); regFunction(&danmakux.menu, "setBGM", setBGM); regFunction(&danmakux.menu, "setBG", setBG); runFunction(&danmakux.menu, "start"); }
/* * Remotly read from a register of another pozyx device */ int PozyxClass::remoteRegRead(uint16_t destination, uint8_t reg_address, uint8_t *pData, int size) { // some checks if(!IS_REG_READABLE(reg_address)) return POZYX_FAILURE; // the register is not readable if(size > MAX_BUF_SIZE) return POZYX_FAILURE; // trying to read too much data if(destination == 0) return POZYX_FAILURE; // remote read not allowed in broadcast mode int status = 0; // first prepare the packet to send uint8_t tmp_data[3]; tmp_data[0] = 0; // the offset in the TX buffer tmp_data[1] = reg_address; // the first byte is the register address we want to start reading from tmp_data[2] = size; // the number of bytes to read starting from the register address status = regFunction(POZYX_TX_DATA, (uint8_t *)&tmp_data, 3, NULL, 0); // stop if POZYX_TX_DATA returned an error. if(status == POZYX_FAILURE) return status; // send the packet uint8_t params[3]; params[0] = (uint8_t)destination; params[1] = (uint8_t)(destination>>8); params[2] = 0x02; // flag to indicate a register read status = regFunction(POZYX_TX_SEND, (uint8_t *)¶ms, 3, NULL, 0); // stop if POZYX_TX_SEND returned an error. if(status == POZYX_FAILURE) return status; // wait up to x ms to receive a response if(waitForFlag(POZYX_INT_STATUS_RX_DATA, POZYX_DELAY_INTERRUPT)) { // we received a response, now get some information about the response uint8_t rx_info[3]= {0,0,0}; regRead(POZYX_RX_NETWORK_ID, rx_info, 3); uint16_t remote_network_id = rx_info[0] + ((uint16_t)rx_info[1]<<8); uint8_t data_len = rx_info[2]; if( remote_network_id == destination && data_len == size) { status = readRXBufferData(pData, size); return status; }else{ return POZYX_FAILURE; } }else{ // timeout return POZYX_FAILURE; } }
ImageF distReg_p2(ImageF phi) { ImageF *phi_x=new ImageF(); ImageF *phi_y=new ImageF(); *phi_x=gradientx(phi); *phi_y=gradienty(phi); //ImageF s=ImageFSqrt(((*phi_x)*(*phi_x)) + ((*phi_y)*(*phi_y))); ImageF s=ImageFSqrt(*phi_x,*phi_y); ImageF a=regFunction(s); ImageF b=regFunction(s);//此处的函数需该 ImageF ps= //ImageF b=(s>1); }
int PozyxClass::readRXBufferData(uint8_t* pData, int size) { if (size > MAX_BUF_SIZE){ return POZYX_FAILURE; } int status; int i; uint8_t params[2]; int max_bytes = BUFFER_LENGTH-1; int n_runs = ceil((float)size / max_bytes); // read out the received data. for(i=0; i<n_runs; i++) { params[0] = i*max_bytes; // the offset if(i+1 != n_runs){ params[1] = max_bytes; // the number of bytes to read }else{ params[1] = size - i*max_bytes; // the number of bytes to read } status = regFunction(POZYX_RX_DATA, params, 2, pData+params[0], params[1]); } return status; }
void loadLevel(std::string lvl) { clearMenu(); clearPause(); buildPause(); danmakux.framesPast = 0; if (danmakux.menu.running) closeScript(&danmakux.menu); if (danmakux.level.running) closeScript(&danmakux.level); std::string filename = "lvl_" + lvl + ".lua"; loadScript(&danmakux.level, filename); regFunction(&danmakux.level, "setBGM", setBGM); regFunction(&danmakux.level, "setBG", setBG); regFunction(&danmakux.level, "addEnemy", addEnemy); regFunction(&danmakux.level, "elapsedTime", timePassed); regFunction(&danmakux.level, "win", winLevel); runFunction(&danmakux.level, "start"); al_stop_samples(); al_play_sample(danmakux.bgm, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); }
int PozyxClass::sendTXBufferData(uint16_t destination) { int status; uint8_t params[3]; params[0] = (uint8_t)destination; params[1] = (uint8_t)(destination>>8); params[2] = 0x06; status = regFunction(POZYX_TX_SEND, (uint8_t *)¶ms, 3, NULL, 0); delay(POZYX_DELAY_LOCAL_FUNCTION); return status; }
void enem_load(Enemy *enemy, std::string type, float srcx, float srcy) { enemNewBlt.exists = false; std::string filename = "enem_" + type + ".lua"; loadScript(&enemy->script, filename); regFunction(&enemy->script, "init", enem_init); regFunction(&enemy->script, "updatePos", enem_getPos); regFunction(&enemy->script, "addBullet", enem_recvBullet); regFunction(&enemy->script, "clearBullets", enem_removeBlts); regFunction(&enemy->script, "kill", enem_kill); regFunction(&enemy->script, "timePassed", timePassed); regFunction(&enemy->script, "win", winLevel); regFunction(&enemy->script, "curHealth", enem_sendHealth); runFunction(&enemy->script, "start", srcx, srcy); enem_loadValues(enemy); }