//get patch request void reply_fromNodeToPC_type2(uint8_t * receivebuffer) { uint16_t pos; //disabletracingfunction(); pos = ((uint16_t) receivebuffer[4]) * 256 + receivebuffer[5]; reply[0] = 26; reply[1] = 125; reply[2] = nodeid; reply[3] = pos / 256; reply[4] = pos % 256; fseek2(fp, (int32_t) pos, 0); fread2(fp, &reply[6], 20); StandardSocketSend(0xefef, 0xffff, 32, reply); // enabletracingfunction(); }
//------------------------------------------------------------------------- static void thread_state_snapshot(uint8_t index, uint8_t * filename) { MYFILE *fp; uint8_t threadsize; uint16_t threadramsize; uint8_t *internal_ram_start; threadsize = sizeof(struct thread); threadramsize = (uint16_t) ((uint8_t *) thread_table[index].ramend - (uint8_t *) thread_table[index].ramstart + 1); internal_ram_start = (uint8_t *) thread_table[index].ramstart; fp = fsopen((char *)filename, "w"); fwrite2(fp, &thread_table[index], threadsize); fseek2(fp, threadsize, 1); fwrite2(fp, internal_ram_start, threadramsize); fclose2(fp); }
//------------------------------------------------------------------------- void reply_cp_fromPCtoNode_type2(uint8_t * receivebuffer) { uint16_t SyncNum; if (receivebuffer[3] == 0xff) { //now this is a sync SyncNum = ((uint16_t) receivebuffer[4]) * 256 + receivebuffer[5]; if (SyncNum > expectNextNum - 1) { reply[0] = 7; reply[1] = 122; reply[2] = nodeid; reply[3] = 15; reply[4] = 15; reply[5] = (expectNextNum - 1) / 256; reply[6] = (expectNextNum - 1) % 256; StandardSocketSend(0xefef, 0xffff, 32, reply); } else { reply[0] = 7; reply[1] = 122; reply[2] = nodeid; reply[3] = 15; reply[4] = 15; reply[5] = 0; reply[6] = 0; StandardSocketSend(0xefef, 0xffff, 32, reply); } return; } chunksequencenum = ((uint16_t) receivebuffer[4]) * 256 + receivebuffer[5]; if (chunksequencenum != expectNextNum) { return; } fwrite2(openedfile, &receivebuffer[7], receivebuffer[6]); fseek2(openedfile, receivebuffer[6], 1); expectNextNum++; // printStringN(reply,32); //StandardSocketSend(0xefef, 0xffff, 32, reply); }
//------------------------------------------------------------------------- void reply_fromNodeToPC_type1(uint8_t * receivebuffer) { uint8_t blockid; char filename[13]; int fid; uint16_t filesize; uint16_t round; uint16_t remain; uint16_t i; uint8_t newblockid; uint8_t temp1, temp2; blockid = receivebuffer[3]; mystrncpy(filename, (char *)&receivebuffer[4], receivebuffer[0] - 4); filename[receivebuffer[0] - 4] = '\0'; newblockid = existBlockAddr(filename, (int)blockid); reply[1] = 124; reply[2] = nodeid; fid = getFreeFid(); openFile(newblockid, fid, 1); fp = &fidtable[fid]; filesize = fp->size; temp1 = filesize / 256; temp2 = filesize % 256; reply[3] = temp1; reply[4] = temp2; //disabletracingfunction(); //send out the size StandardSocketSend(0xefef, 0xffff, 32, reply); // StandardSocketSend(0xefef, 0xffff, 32, reply); //sleepThread( 100 ); reply[3] = newblockid; round = filesize / 20; remain = filesize % 20; for (i = 0; i < round; i++) { fread2(fp, &reply[6], 20); fseek2(fp, 20, 1); reply[0] = 26; temp1 = i / 256; temp2 = i % 256; reply[4] = temp1; reply[5] = temp2; //printStringN(reply,32); // sleepThread( 100 ); StandardSocketSend(0xefef, 0xffff, 32, reply); } if (remain > 0) { fread2(fp, &reply[6], remain); reply[0] = (uint8_t) remain + 6; reply[4] = round / 256; reply[5] = round % 256; round++; //printStringN(reply,32); //sleepThread( 25 ); StandardSocketSend(0xefef, 0xffff, 32, reply); } temp1 = round / 256; temp2 = round % 256; //terminate signal is here! reply[0] = 7; reply[3] = 0xef; reply[4] = 0xef; reply[5] = temp1; reply[6] = temp2; //ephread( 100 ); StandardSocketSend(0xefef, 0xffff, 32, reply); //sleepThread( 100 ); StandardSocketSend(0xefef, 0xffff, 32, reply); //sleepThread( 100 ); StandardSocketSend(0xefef, 0xffff, 32, reply); //sleepThread( 100 ); StandardSocketSend(0xefef, 0xffff, 32, reply); //do not close now! // fclose2(fp); //enabletracingfunction(); }
void rewind2 (FILE *file) { fseek2 (file, 0, SEEK_SET); }