static void cmdTxSavedImuData(unsigned char status, unsigned char length, unsigned char *frame) { unsigned int page, byte; unsigned int i, j; Payload pld; //senGetMemLocIndex(&page, &byte); page = 0x0200; byte = 0; LED_RED = 1; dfmemEraseSector(0x0100); // erase Sector 1 (page 256 - 511) for (i = 0x0100; i < 0x0200; ++i) { j = 0; while (j < 512) { pld = payCreateEmpty(18); // data length = 16 dfmemRead(i, j, 16, pld->pld_data); paySetStatus(pld, status); paySetType(pld, CMD_GET_IMU_DATA); while (!radioReceivePayload()); j += 16; } delay_ms(200); } LED_RED = 0; }
void dfmemReadSample(unsigned long sampNum, unsigned int sampLen, unsigned char *data) { unsigned int samplesPerPage = dfmem_bytes_per_page / sampLen; //round DOWN int division unsigned int pagenum = sampNum / samplesPerPage; unsigned int byteOffset = (sampNum - pagenum*samplesPerPage)*sampLen; dfmemRead(pagenum, byteOffset, sampLen, data); }
static void cmdGetMemContents(MacPacket packet) { Payload pld; MacPacket data_packet; unsigned char *frame; DfmemGeometryStruct geo; pld = macGetPayload(packet); frame = payGetData(pld); dfmemGetGeometryParams(&geo); unsigned int start_page = frame[0] + (frame[1] << 8); unsigned int end_page = frame[2] + (frame[3] << 8); unsigned int tx_data_size = frame[4] + (frame[5] << 8); unsigned int page, j; unsigned char count = 0; // Send back memory contents for (page = start_page; page < end_page; ++page) { j = 0; while (j + tx_data_size <= geo.bytes_per_page) { data_packet = NULL; while(data_packet == NULL) { data_packet = radioRequestPacket(tx_data_size); } macSetDestAddr(data_packet, macGetSrcAddr(packet)); macSetDestPan(data_packet, macGetSrcPan(packet)); pld = macGetPayload(data_packet); dfmemRead(page, j, tx_data_size, payGetData(pld)); paySetStatus(pld, count++); paySetType(pld, CMD_RESPONSE_TELEMETRY); while(!radioEnqueueTxPacket(data_packet)); j += tx_data_size; delay_ms(20); } } // Signal end of transfer LED_GREEN = 0; LED_RED = 0; LED_ORANGE = 0; }
/***************************************************************************** * Function Name : test_dflash * Description : Write four different strings to a page in the data flash, * then read them back and send their contents out over the * radio. Bonus points if you can identify the film without * reverting to the internet. * Parameters : type - The type field of the dflash test packet * status - Status field of the dflash test packet (not yet used) * length - The length of the payload data array * data - not used * Return Value : success indicator - 0 for failed, 1 for succeeded *****************************************************************************/ unsigned char test_dflash(unsigned char type, unsigned char status, unsigned char length, unsigned char* data) { MacPacket packet; Payload pld; char mem_data[256] = {}; //char* str1 = "You must be here to fix the cable."; // 38+1 char str1[] = "D"; // 38+1 char str2[] = "Lord. You can imagine where it goes from here."; //46+1 char str3[] = "He fixes the cable?"; //19+1 char str4[] = "Don't be fatuous, Jeffrey."; //26+1 int page = 0x100; strcpy(mem_data, str1); strcpy(mem_data + strlen(str1), str2); strcpy(mem_data + strlen(str1) + strlen(str2), str3); strcpy(mem_data + strlen(str1) + strlen(str2) + strlen(str3), str4); // Write into dfmem dfmemWrite((unsigned char *)(mem_data), sizeof(mem_data), page, 0, 1); // ---------- string 1 ----------------------------------------------------- // Get a new packet from the pool packet = radioRequestPacket(strlen(str1)); if(packet == NULL) return 0; //macSetDestAddr(packet, RADIO_DEST_ADDR); // Prepare the payload pld = packet->payload; paySetStatus(pld, STATUS_UNUSED); paySetType(pld, type); // Read out dfmem into the payload dfmemRead(page, 0, strlen(str1), payGetData(pld)); // Enqueue the packet for broadcast radioEnqueueTxPacket(packet); // ---------- string 2 ----------------------------------------------------- // Get a new packet from the pool packet = radioRequestPacket(strlen(str2)); if(packet == NULL) return 0; //macSetDestAddr(packet, RADIO_DEST_ADDR); // Prepare the payload pld = packet->payload; paySetStatus(pld, STATUS_UNUSED); paySetType(pld, type); // Read out dfmem into the payload dfmemRead(page, strlen(str1), strlen(str2), payGetData(pld)); // Enqueue the packet for broadcast radioEnqueueTxPacket(packet); // ---------- string 3 ----------------------------------------------------- // Get a new packet from the pool packet = radioRequestPacket(strlen(str3)); if(packet == NULL) return 0; //macSetDestAddr(packet, RADIO_DEST_ADDR); // Prepare the payload pld = packet->payload; paySetStatus(pld, STATUS_UNUSED); paySetType(pld, type); // Read out dfmem into the payload dfmemRead(page, strlen(str1) + strlen(str2), strlen(str3), payGetData(pld)); // Enqueue the packet for broadcast radioEnqueueTxPacket(packet); // ---------- string 4 ----------------------------------------------------- // Get a new packet from the pool packet = radioRequestPacket(strlen(str4)); if(packet == NULL) return 0; //macSetDestAddr(packet, RADIO_DEST_ADDR); // Prepare the payload pld = packet->payload; paySetStatus(pld, STATUS_UNUSED); paySetType(pld, type); // Read out dfmem into the payload dfmemRead(page, strlen(str1) + strlen(str2) + strlen(str3), strlen(str4), payGetData(pld)); // Enqueue the packet for broadcast radioEnqueueTxPacket(packet); return 1; //success }