void buildFileList() { TFileHandle hFileHandle; TFileIOResult nIoResult; string sFileName; short nFileSize; string sFileSearch = "*.rxe"; // Wildcard to search for any executable file FindFirstFile(hFileHandle, nIoResult, sFileSearch, sFileName, nFileSize); nNumbOfFiles = 0; while (nIoResult == ioRsltSuccess) { stringDelete(sFileName, strlen(sFileName) - 4, 4); // Trim File Extension sFileNames[nNumbOfFiles] = sFileName; ++nNumbOfFiles; FindNextFile(hFileHandle, nIoResult, sFileName, nFileSize); } Close(hFileHandle, nIoResult); return; }
void writeOmikujiFile(const gchar *fname, GList *comments, GList *fortunes) { OmikujiHeaderV0 header; for (gint i = 0; i < 7; i++) header.signature.signature[i] = OMIKUJI_SIGNATURE[i]; header.signature.version = OMIKUJI_VERSION; guint32 offset = sizeof(header); if (sort || uniqify) fortunes = g_list_sort(fortunes, (GCompareFunc)stringCmp); if (uniqify) { /* Iterate from back to front and compare two entries, removing the rearmost entry when stringCmp == 0. */ gboolean deleteChars = TRUE; GList *current, *previous; current = g_list_last(fortunes); while (current != NULL) { previous = g_list_previous(current); if (previous != NULL) { if (stringCmp(previous->data, current->data) == 0) { stringDelete(current->data, &deleteChars); fortunes = g_list_delete_link(fortunes, current); } } current = previous; } } if (comments != NULL) { header.comment_table_offset = GUINT32_TO_BE(offset); header.comment_count = GUINT32_TO_BE(g_list_length(comments)); offset += g_list_length(comments) * 8; } else { header.comment_table_offset = 0; header.comment_count = 0; } header.fortune_table_offset = GUINT32_TO_BE(offset); header.fortune_count = GUINT32_TO_BE(g_list_length(fortunes)); offset += g_list_length(fortunes) * 8; /* * Rather than figure out all of the glib io channel stuff, I'm * using stdio for now. */ FILE *out = fopen(fname, "w"); if (out) { gint i, len; guint32 oval; fwrite(&header, sizeof(header), 1, out); // Write comments offset table. if (comments) { len = g_list_length(comments); for (i = 0; i < len; i++) { GString *comment = g_list_nth_data(comments, i); oval = GUINT32_TO_BE(offset); fwrite(&oval, sizeof(oval), 1, out); oval = GUINT32_TO_BE((comment->len - 1)); // we seem to be getting nul on the end fwrite(&oval, sizeof(oval), 1, out); offset += (comment->len - 1); } } // Write fortunes offset table. len = g_list_length(fortunes); for (i = 0; i < len; i++) { GString *fortune = g_list_nth_data(fortunes, i); oval = GUINT32_TO_BE(offset); fwrite(&oval, sizeof(oval), 1, out); oval = GUINT32_TO_BE((fortune->len - 1)); fwrite(&oval, sizeof(oval), 1, out); offset += (fortune->len - 1); } // Write the comments if (comments) { len = g_list_length(comments); for (i = 0; i < len; i++) { GString *comment = g_list_nth_data(comments, i); fwrite(comment->str, sizeof(gchar), (comment->len - 1), out); } } // Write the fortunes len = g_list_length(fortunes); for (i = 0; i < len; i++) { GString *fortune = g_list_nth_data(fortunes, i); fwrite(fortune->str, sizeof(gchar), (fortune->len - 1), out); } fclose(out); } }
void genResponse(short cid) { short power = motor[motorA]; float temp = 0.0; string tmpString; short index = 0; ubyte linebuff[20]; stringFromChars(tmpString, &RS485rxbuffer[0]); index = stringFind(tmpString, "/"); stringDelete(tmpString, 0, index); index = stringFind(tmpString, "HTTP"); stringDelete(tmpString, index, strlen(tmpString)); writeDebugStreamLine("Request:%s", tmpString); displayTextLine(2, "Request: "); displayTextLine(3, tmpString); if (stringFind(tmpString, "MOTA") > 0) { stringDelete(tmpString, 0, 6); index = stringFind(tmpString, " "); if (index > -1) stringDelete(tmpString, index, strlen(tmpString)); //power = RC_atoix(tmpString); power = clip(atoi(tmpString), -100, 100); writeDebugStreamLine("Power:%d", power); } else { writeDebugStreamLine("NO POWER: %s", tmpString); } sendHeader(cid); while(nxtHS_Status == HS_SENDING) sleep(5); sleep(100); index = 0; linebuff[0] = 27; // escape; linebuff[1] = 'S'; // the CID; linebuff[2] = (ubyte)cid + 48; // the CID; index = RS485appendToBuff(RS485txbuffer, index, linebuff, 3); stringFormat(tmpString, "MotorA=%d\n", power); memcpy(linebuff, tmpString, strlen(tmpString)); index = RS485appendToBuff(RS485txbuffer, index, linebuff, strlen(tmpString)); DTMPreadTemp(DTMP, temp); stringFormat(tmpString, "Temp: %2.2f C", temp); memcpy(linebuff, tmpString, strlen(tmpString)); index = RS485appendToBuff(RS485txbuffer, index, linebuff, strlen(tmpString)); linebuff[0] = 27; // escape; linebuff[1] = 'E'; // the CID; index = RS485appendToBuff(RS485txbuffer, index, endmarker, 2); RS485write(RS485txbuffer, index); if (power != 0) nMotorEncoderTarget[motorA] = 2000; motor[motorA] = power; if (power > 0) SensorType[COLOUR] = sensorColorNxtGREEN; else if (power < 0) SensorType[COLOUR] = sensorColorNxtBLUE; else if (nMotorRunState[motorA] == runStateIdle) SensorType[COLOUR] = sensorColorNxtRED; else SensorType[COLOUR] = sensorColorNxtRED; sleep(300); RS485clearRead(); DWIFIClose(1); memset(RS485rxbuffer, 0, sizeof(RS485rxbuffer)); //sleep(100); //RS485read(RS485rxbuffer, sizeof(RS485rxbuffer)); //clear_read_buffer(); RS485clearRead(); }