From 5fce7fc94abfc13b0c264364189b7433514cd6ac Mon Sep 17 00:00:00 2001 From: Alberto Morato Date: Sun, 1 Aug 2021 15:17:31 +0200 Subject: [PATCH] Add OOK_PWM and OOK_PPM to sendook --- src/ook/sendook.cpp | 77 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/src/ook/sendook.cpp b/src/ook/sendook.cpp index f962b9b..ebd20ae 100644 --- a/src/ook/sendook.cpp +++ b/src/ook/sendook.cpp @@ -26,8 +26,10 @@ Options:\n\ -f freq : frequency in Hz (default : 433.92MHz)\n\ -0 nb : duration in microsecond of 0 bit (by default : 500us). Use integer only.\n\ -1 nb : duration in microsecond of 1 bit (by default : 250us)\n\ +-g nb : bit gap (by default : 500us)\n\ -r nb : repeat nb times the message (default : 3)\n\ -p nb : pause between each message (default : 1000us=1ms)\n\ +-m nb : modulation type 0=OOK, 1=OOK_PWM, 2=OOK_PPM (default : 0=OOK)\n\ \n\ \"binary code\":\n\ a serie of 0 or 1 char (space allowed and ignored)\n\ @@ -67,9 +69,11 @@ int main(int argc, char *argv[]) uint64_t Freq = 433920000; uint64_t bit0duration = 500; // in microsecond uint64_t bit1duration = 500; + uint64_t bitgap = 500; int nbrepeat = 3; int pause = 1000; // in us int dryrun = 0; // if 1 : hte message is not really transmitted + int modulation = 0; // 0=OOK, 1=OOK_PWM, 2=OOK_PPM char *bits = NULL; for (int i = 0; i < 64; i++) @@ -81,7 +85,7 @@ int main(int argc, char *argv[]) } while(1) { - a = getopt(argc, argv, "f:0:1:r:p:hvd"); + a = getopt(argc, argv, "f:0:1:g:r:p:m:hvd"); if(a == -1) { if(anyargs) break; @@ -99,12 +103,18 @@ int main(int argc, char *argv[]) case '1': // bit 0 duration bit1duration = atouint32_metric(optarg, "Error with -1 : "); break; + case 'g': // bit gap + bitgap = atouint32_metric(optarg, "Error with -g : "); + break; case 'r': nbrepeat = atoi(optarg); break; case 'p': pause = atoi(optarg); break; + case 'm': + modulation = atoi(optarg); + break; case 'h' : print_usage(); exit(0); @@ -128,8 +138,10 @@ int main(int argc, char *argv[]) } bits = argv[optind]; printf("Frequency set to : %" PRIu64 "Hz \n", Freq); + printf("Modulation: %d \n", modulation); printf("Bit duration 0 : %" PRIu64 "us ; 1 : %" PRIu64 "us\n", bit0duration, bit1duration); + printf("Bit gap = %" PRIu64 "us \n", bitgap); printf("Send message %d times with a pause of %dus\n", nbrepeat, pause); if (dryrun) printf("Dry run mode enabled : no message will be sent\n"); @@ -149,6 +161,13 @@ int main(int argc, char *argv[]) nbbits ++; computed_duration += bit1duration; } + + /* OOK_PWM and OOK_PPM requires extra bit */ + if((modulation == 1) || (modulation == 2)) + { + computed_duration += bitgap; + nbbits ++; + } // any other char is ignored (it allows to speparate nibble with a space for example) // improvement : allow "." and "-" or "i" and "a" to create a MORSE sender } @@ -168,15 +187,57 @@ int main(int argc, char *argv[]) for(size_t i = 0; i < strlen(bits); i++) { char c = bits[i]; - if (c == '0') + switch (modulation) { - Message[i].value = 0; - Message[i].duration = bit0duration; - } else if (c == '1') - { - Message[i].value = 1; - Message[i].duration = bit1duration; + case 0: // OOK: + if (c == '0') + { + Message[i].value = 0; + Message[i].duration = bit0duration; + + } else if (c == '1') + { + Message[i].value = 1; + Message[i].duration = bit1duration; + } + break; + + case 1: // OOK_PWM: + if (c == '0') + { + Message[i*2].value = 1; + Message[i*2].duration = bit0duration; + + } else if (c == '1') + { + Message[i*2].value = 1; + Message[i*2].duration = bit1duration; + } + Message[(i*2)+1].value = 0; + Message[(i*2)+1].duration = bitgap; + break; + + case 2: // OOK_PPM: + Message[i*2].value = 1; + Message[i*2].duration = bitgap; + if (c == '0') + { + Message[(i*2)+1].value = 0; + Message[(i*2)+1].duration = bit0duration; + + } else if (c == '1') + { + Message[(i*2)+1].value = 0; + Message[(i*2)+1].duration = bit1duration; + } + break; + + + + default: + break; } + } // Send the message