Просмотр исходного кода

allow nrf sniff apps to compile via ufbt on OFW

MX 1 год назад
Родитель
Сommit
9585d727b2
3 измененных файлов с 129 добавлено и 13 удалено
  1. 17 13
      nrfsniff.c
  2. 81 0
      stdstring.c
  3. 31 0
      stdstring.h

+ 17 - 13
nrfsniff.c

@@ -8,15 +8,17 @@
 #include <nrf24.h>
 #include <toolbox/stream/file_stream.h>
 
+#include "stdstring.h"
+
 #define LOGITECH_MAX_CHANNEL 85
-#define COUNT_THRESHOLD 2
-#define DEFAULT_SAMPLE_TIME 8000
-#define MAX_ADDRS 100
-#define MAX_CONFIRMED 32
+#define COUNT_THRESHOLD      2
+#define DEFAULT_SAMPLE_TIME  8000
+#define MAX_ADDRS            100
+#define MAX_CONFIRMED        32
 
 #define NRFSNIFF_APP_PATH_FOLDER STORAGE_APP_DATA_PATH_PREFIX
-#define NRFSNIFF_APP_FILENAME "addresses.txt"
-#define TAG "nrfsniff"
+#define NRFSNIFF_APP_FILENAME    "addresses.txt"
+#define TAG                      "nrfsniff"
 
 typedef enum {
     EventTypeTick,
@@ -159,11 +161,11 @@ static bool save_addr_to_file(
     if(target_rate == 8) rate = 2;
     snprintf(ending, sizeof(ending), ",%d\n", rate);
     hexlify(data, size, addrline);
-    strcat(addrline, ending);
+    nrf_strcat(addrline, ending);
     linesize = strlen(addrline);
     strcpy(filepath, NRFSNIFF_APP_PATH_FOLDER);
-    strcat(filepath, "/");
-    strcat(filepath, NRFSNIFF_APP_FILENAME);
+    nrf_strcat(filepath, "/");
+    nrf_strcat(filepath, NRFSNIFF_APP_FILENAME);
     stream_seek(stream, 0, StreamOffsetFromStart);
 
     // check if address already exists in file
@@ -175,14 +177,14 @@ static bool save_addr_to_file(
             file_contents = malloc(file_size + 1);
             memset(file_contents, 0, file_size + 1);
             if(stream_read(stream, file_contents, file_size) > 0) {
-                char* line = strtok((char*)file_contents, "\n");
+                char* line = nrf_strtok((char*)file_contents, "\n");
 
                 while(line != NULL) {
                     if(!memcmp(line, addrline, 12)) {
                         found = true;
                         break;
                     }
-                    line = strtok(NULL, "\n");
+                    line = nrf_strtok(NULL, "\n");
                 }
             }
             free(file_contents);
@@ -223,7 +225,8 @@ void alt_address(uint8_t* addr, uint8_t* altaddr) {
     uint8_t tmpaddr[5];
 
     // swap bytes
-    for(int i = 0; i < 5; i++) tmpaddr[i] = addr[4 - i];
+    for(int i = 0; i < 5; i++)
+        tmpaddr[i] = addr[4 - i];
 
     // get address into 32-bit and 8-bit variables
     memcpy(macmess_hi_b, tmpaddr, 4);
@@ -241,7 +244,8 @@ void alt_address(uint8_t* addr, uint8_t* altaddr) {
     tmpaddr[4] = macmess_lo;
 
     // swap bytes back
-    for(int i = 0; i < 5; i++) altaddr[i] = tmpaddr[4 - i];
+    for(int i = 0; i < 5; i++)
+        altaddr[i] = tmpaddr[4 - i];
 }
 
 static bool previously_confirmed(uint8_t* addr) {

+ 81 - 0
stdstring.c

@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+char* nrf_strcat(char* s, const char* append) {
+    char* save = s;
+    for(; *s; ++s)
+        ;
+    while((*s++ = *append++) != '\0')
+        ;
+    return (save);
+}
+static char* nrfstrtok_r(char* s, const char* delim, char** last) {
+    char* spanp;
+    int c, sc;
+    char* tok;
+    if(s == NULL && (s = *last) == NULL) return (NULL);
+    /*
+	 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
+	 */
+cont:
+    c = *s++;
+    for(spanp = (char*)delim; (sc = *spanp++) != 0;) {
+        if(c == sc) goto cont;
+    }
+    if(c == 0) { /* no non-delimiter characters */
+        *last = NULL;
+        return (NULL);
+    }
+    tok = s - 1;
+    /*
+	 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
+	 * Note that delim must have one NUL; we stop if we see that, too.
+	 */
+    for(;;) {
+        c = *s++;
+        spanp = (char*)delim;
+        do {
+            if((sc = *spanp++) == c) {
+                if(c == 0)
+                    s = NULL;
+                else
+                    s[-1] = 0;
+                *last = s;
+                return (tok);
+            }
+        } while(sc != 0);
+    }
+    /* NOTREACHED */
+}
+char* nrf_strtok(char* s, const char* delim) {
+    static char* last;
+    return nrfstrtok_r(s, delim, &last);
+}

+ 31 - 0
stdstring.h

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+char* nrf_strcat(char* s, const char* append);
+char* nrf_strtok(char* s, const char* delim);