diff --git a/OneWireIO-tmp.hpp b/OneWireIO-tmp.hpp deleted file mode 100644 index c187bde..0000000 --- a/OneWireIO-tmp.hpp +++ /dev/null @@ -1,434 +0,0 @@ -#include "Arduino.h" -#include "LowLevel.h" -#include "SerialChannel.h" - -#define LEDPin 13 -#define OWPin 2 -#define InterruptNumber 0 // Must correspond to the OWPin to correctly detect state changes. On Arduino Uno, interrupt 0 is for digital pin 2 - -#define ResetMinDuration 480 -#define ResetMaxDuration 900 - -#define PresenceWaitDuration 30 -#define PresenceDuration 300 - -#define ReadBitSamplingTime 13 // the theorical time is about 30us, but given various overhead, this is the empirical delay I've found works best (on Arduino Uno) - -#define SendBitDuration 35 - -const byte InvalidBit = (byte)-1; -const byte IncompleteBit = (byte)-2; - -SerialChannel debug("debug"); - -Pin owPin(OWPin); -Pin owOutTestPin(3); -Pin led(LEDPin); - -enum OwStatus -{ - OS_WaitReset, - OS_Presence, - OS_WaitCommand, - OS_SearchRom, -}; -OwStatus status; - -byte owROM[8] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00 }; -byte searchROMCurrentByte = 0; -byte searchROMCurrentBit = 0; -bool searchROMSendingInverse = false; -bool searchROMReadingMasterResponseBit = false; - -void owPullLow() -{ - owPin.outputMode(); - owPin.writeLow(); - owOutTestPin.writeLow(); -} - -void owRelease() -{ - owPin.inputMode(); - owOutTestPin.writeHigh(); -} - -void onEnterInterrupt() -{ - //owOutTestPin.writeLow(); -} - -void onLeaveInterrupt() -{ - //owOutTestPin.writeHigh(); -} - -volatile unsigned long resetStart = (unsigned long)-1; -unsigned long lastReset = (unsigned long)-1; -unsigned long bitStart = (unsigned long)-1; -byte receivingByte = 0; -byte receivingBitPos = 0; -bool searchRomNextBit = false; -bool searchRomNextBitToSend = false; - -void setup() -{ - owROM[7] = crc8((char*)owROM, 7); - - led.outputMode(); - owPin.inputMode(); - owOutTestPin.outputMode(); - owOutTestPin.writeHigh(); - - led.writeLow(); - - cli(); // disable interrupts - attachInterrupt(InterruptNumber, owWaitResetInterrupt, CHANGE); - - // set timer0 interrupt at 250KHz (actually depends on compare match register OCR0A) - // 4us between each tick - TCCR1A = 0; - TCCR1B = 0; - TCNT1 = 0; // initialize counter value to 0 - //TCCR1B |= (1 << WGM12); // turn on CTC mode - //TCCR1B |= (1 << CS11) | (1 << CS10); // Set 64 prescaler - TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt - sei(); // enable interrupts - - Serial.begin(9600); -} - -int count = 0; -void loop() -{ - if ((count++) % 1000 == 0) - led.write(!led.read()); - cli();//disable interrupts - SerialChannel::swap(); - sei();//enable interrupts - - SerialChannel::flush(); -} - -void(*timerEvent)() = 0; -void setTimerEvent(short microSecondsDelay, void(*event)()) -{ - microSecondsDelay -= 10; // this seems to be the typical time taken to initialize the timer on Arduino Uno - - short skipTicks = (microSecondsDelay - 3) / 4; // round the micro seconds delay to a number of ticks to skip (4us per tick, so 4us must skip 0 tick, 8us must skip 1 tick, etc.) - if (skipTicks < 1) skipTicks = 1; - //debug.SC_APPEND_STR_INT("setTimerEvent", (long)skipTicks); - TCNT1 = 0; - OCR1A = skipTicks; - timerEvent = event; - TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // turn on CTC mode with 64 prescaler -} - -void owError(const char* message) -{ - debug.append(message); - led.writeHigh(); - status = OS_WaitReset; -} - -void owClearError() -{ - led.writeLow(); -} - -void owWaitResetInterrupt() -{ - onEnterInterrupt(); - bool state = owPin.read(); - unsigned long now = micros(); - if (state) - { - if (resetStart == (unsigned int)-1) - { - onLeaveInterrupt(); - return; - } - - unsigned long resetDuration = now - resetStart; - resetStart = (unsigned int)-1; - if (resetDuration >= ResetMinDuration) - { - if (resetDuration > ResetMaxDuration) - { - owError("Reset too long"); - onLeaveInterrupt(); - return; - } - - owClearError(); - lastReset = now; - status = OS_Presence; - setTimerEvent(PresenceWaitDuration - (micros() - now), &beginPresence); - } - } - else - { - resetStart = now; - } - onLeaveInterrupt(); -} - -//bool debugState = false; -volatile unsigned long lastInterrupt = 0; -void owReceiveCommandInterrupt(void) -{ - onEnterInterrupt(); - unsigned long now = micros(); - if (now < lastInterrupt + 20) - { - onLeaveInterrupt(); - return; // don't react to our own actions - } - lastInterrupt = now; - - //debugState = !debugState; - //owOutTestPin.write(debugState); - - //led.write(state); - - bool bit = readBit(); - /*if (bit) - debug.SC_APPEND_STR("received bit 1"); - else - debug.SC_APPEND_STR("received bit 0");*/ - - receivingByte |= ((bit ? 1 : 0) << receivingBitPos); - ++receivingBitPos; - - if (receivingBitPos == 8) - { - byte receivedByte = receivingByte; - receivingBitPos = 0; - receivingByte = 0; - //debug.SC_APPEND_STR_INT("received byte", (long)receivedByte); - - if (status == OS_WaitCommand && receivedByte == 0xF0) - { - status = OS_SearchRom; - searchROMReadingMasterResponseBit = false; - searchROMSendingInverse = false; - searchROMCurrentByte = 0; - searchROMCurrentBit = 0; - byte currentByte = owROM[searchROMCurrentByte]; - searchRomNextBit = bitRead(currentByte, searchROMCurrentBit); - searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit; - //attachInterrupt(InterruptNumber, onewireInterruptSearchROM, FALLING); - setTimerEvent(10, owSearchSendBit); - detachInterrupt(InterruptNumber); - onLeaveInterrupt(); - return; - } - } - - onLeaveInterrupt(); -} - -bool ignoreNextFallingEdge = false; - -void owSearchSendBit() -{ - onEnterInterrupt(); - - // wait for a falling edge (active wait is more reliable than interrupts to send the bit fast enough) - while (!owPin.read()); - while (owPin.read()); - - //sendBit(searchRomNextBitToSend); - if (searchRomNextBitToSend) - { - //delayMicroseconds(SendBitDuration); - ignoreNextFallingEdge = false; - } - else - { - owPullLow(); - //delayMicroseconds(SendBitDuration); - //owRelease(); - ignoreNextFallingEdge = true; - } - - unsigned long sendBitStart = micros(); - - if (searchROMSendingInverse) - { - searchROMSendingInverse = false; - searchROMReadingMasterResponseBit = true; - } - else - { - searchROMSendingInverse = true; - } - - byte currentByte = owROM[searchROMCurrentByte]; - searchRomNextBit = bitRead(currentByte, searchROMCurrentBit); - searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit; - - if (searchROMReadingMasterResponseBit) - { - ignoreNextFallingEdge = true; - attachInterrupt(InterruptNumber, onewireInterruptSearchROM, FALLING); - } - else - { - setTimerEvent(10, owSearchSendBit); - } - - delayMicroseconds(SendBitDuration - (micros() - sendBitStart)); - owRelease(); - - onLeaveInterrupt(); -} - -void onewireInterruptSearchROM() -{ - onEnterInterrupt(); - - if (ignoreNextFallingEdge) - { - ignoreNextFallingEdge = false; - onLeaveInterrupt(); - return; - } - - if (searchROMReadingMasterResponseBit) - { - bool bit = readBit(); - - if (bit != searchRomNextBit) - { - debug.SC_APPEND_STR("Master didn't send our bit, leaving ROM search"); - status = OS_WaitReset; - attachInterrupt(InterruptNumber, owWaitResetInterrupt, CHANGE); - onLeaveInterrupt(); - return; - } - - searchROMReadingMasterResponseBit = false; - ++searchROMCurrentBit; - if (searchROMCurrentBit == 8) - { - ++searchROMCurrentByte; - searchROMCurrentBit = 0; - //debug.SC_APPEND_STR("sent another ROM byte"); - } - - if (searchROMCurrentByte == 8) - { - searchROMCurrentByte = 0; - status = OS_WaitReset; - debug.SC_APPEND_STR("ROM sent entirely"); - attachInterrupt(InterruptNumber, owWaitResetInterrupt, CHANGE); - onLeaveInterrupt(); - return; - } - - byte currentByte = owROM[searchROMCurrentByte]; - searchRomNextBit = bitRead(currentByte, searchROMCurrentBit); - searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit; - - setTimerEvent(10, owSearchSendBit); - detachInterrupt(InterruptNumber); - onLeaveInterrupt(); - return; - } - else - { - sendBit(searchRomNextBitToSend); - /*if (bitToSend) - debug.SC_APPEND_STR("sent ROM search bit : 1"); - else - debug.SC_APPEND_STR("sent ROM search bit : 0");*/ - - if (searchROMSendingInverse) - { - searchROMSendingInverse = false; - searchROMReadingMasterResponseBit = true; - } - else - { - searchROMSendingInverse = true; - } - } - - byte currentByte = owROM[searchROMCurrentByte]; - searchRomNextBit = bitRead(currentByte, searchROMCurrentBit); - searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit; - - onLeaveInterrupt(); -} - -bool readBit() -{ - delayMicroseconds(ReadBitSamplingTime); - bool bit = owPin.read(); - //owOutTestPin.write(!owOutTestPin.read()); - //owOutTestPin.write(!owOutTestPin.read()); - return bit; -} - -void sendBit(bool bit) -{ - if (bit) - { - delayMicroseconds(SendBitDuration); - ignoreNextFallingEdge = false; - } - else - { - owPullLow(); - delayMicroseconds(SendBitDuration); - owRelease(); - ignoreNextFallingEdge = true; - } -} - -void beginPresence() -{ - unsigned long now = micros(); - owPullLow(); - setTimerEvent(PresenceDuration, &endPresence); - debug.SC_APPEND_STR_TIME("reset", lastReset); - debug.SC_APPEND_STR_TIME("beginPresence", now); -} - -void endPresence() -{ - unsigned long now = micros(); - owRelease(); - debug.SC_APPEND_STR_TIME("endPresence", now); - - status = OS_WaitCommand; - attachInterrupt(InterruptNumber, owReceiveCommandInterrupt, FALLING); - receivingByte = 0; - receivingBitPos = 0; - bitStart = (unsigned long)-1; -} - -ISR(TIMER1_COMPA_vect) // timer1 interrupt -{ - TCCR1B = 0; // disable clock - void(*event)() = timerEvent; - timerEvent = 0; - if (event != 0) - event(); -} - -uint8_t crc8(char addr[], uint8_t len) { - uint8_t crc = 0; - - while (len--) { - uint8_t inbyte = *addr++; - for (uint8_t i = 8; i; i--) { - uint8_t mix = (crc ^ inbyte) & 0x01; - crc >>= 1; - if (mix) crc ^= 0x8C; - inbyte >>= 1; - } - } - return crc; -} diff --git a/OneWireIO.ino b/OneWireIO.ino deleted file mode 100644 index 1e65415..0000000 --- a/OneWireIO.ino +++ /dev/null @@ -1,117 +0,0 @@ -#include "Arduino.h" -#include "LowLevel.h" -#include "SerialChannel.h" -#include "OneWireSlave.h" - -#define LEDPin 13 -#define OWPin 2 - -#ifdef ENABLE_SERIAL_CHANNEL -SerialChannel debug("debug"); -#endif - -Pin led(LEDPin); - -byte owROM[7] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; - -byte acknowledge = 0x42; -byte commandCheckError = 0xF1; - -int turnOnTimeoutSeconds = 5 * 60; - -const byte CMD_TurnOn = 0x01; -const byte CMD_TurnOff = 0x02; -const byte CMD_ReadState = 0x03; - -const byte ANS_StateIsOn = 0x01; -const byte ANS_StateIsOff = 0x02; - -volatile byte command = 0x0; -volatile long turnOnStartTime = 0; - -void owReceive(OneWireSlave::ReceiveEvent evt, byte data); - -void setup() -{ - led.outputMode(); - led.writeLow(); - - OneWire.setReceiveCallback(&owReceive); - OneWire.begin(owROM, OWPin); - - Serial.begin(9600); -} - -void loop() -{ - delay(1); - - long now = millis(); - if (now > turnOnStartTime + (long)turnOnTimeoutSeconds * 1000 || now < turnOnStartTime) - { - led.writeLow(); - turnOnStartTime = 0; - } - - cli();//disable interrupts - #ifdef ENABLE_SERIAL_CHANNEL - SerialChannel::swap(); - #endif - sei();//enable interrupts - - #ifdef ENABLE_SERIAL_CHANNEL - SerialChannel::flush(); - #endif -} - -void owReceive(OneWireSlave::ReceiveEvent evt, byte data) -{ - switch (evt) - { - case OneWireSlave::RE_Byte: - if (command == 0x00) - { - command = data; - } - else - { - if (data == (0xFF-command)) // to check there is no communication error, the master must send the command, and then its inverse - { - byte receivedCommand = command; - command = 0x0; - switch (receivedCommand) - { - case CMD_TurnOn: - turnOnStartTime = millis(); - led.writeHigh(); - OneWire.write(&acknowledge, 1, NULL); - break; - case CMD_TurnOff: - led.writeLow(); - turnOnStartTime = 0; - OneWire.write(&acknowledge, 1, NULL); - break; - case CMD_ReadState: - bool state = led.read(); - static byte response[2]; - response[0] = state ? ANS_StateIsOn : ANS_StateIsOff; - response[1] = 0xFF - response[0]; - OneWire.write(response, 2, NULL); - break; - } - } - else - { - command = 0x0; - OneWire.write(&commandCheckError, 1, NULL); - } - } - break; - case OneWireSlave::RE_Reset: - case OneWireSlave::RE_Error: - command = 0x0; - break; - default: - ; - } -} diff --git a/OneWireIO.sln b/OneWireIO.sln index 1efede9..f10e9f5 100644 --- a/OneWireIO.sln +++ b/OneWireIO.sln @@ -5,11 +5,6 @@ VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OneWireIO", "OneWireIO.vcxproj", "{3B500971-1570-460F-81C3-22AC3B7764B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SerialMonitor", "SerialMonitor\SerialMonitor\SerialMonitor.csproj", "{97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}" - ProjectSection(ProjectDependencies) = postProject - {3B500971-1570-460F-81C3-22AC3B7764B9} = {3B500971-1570-460F-81C3-22AC3B7764B9} - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,16 +25,6 @@ Global {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Mixed Platforms.Build.0 = Release|Win32 {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Win32.ActiveCfg = Release|Win32 {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Win32.Build.0 = Release|Win32 - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Win32.ActiveCfg = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Any CPU.Build.0 = Release|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Win32.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OneWireIO.vcxproj b/OneWireIO.vcxproj index 308080d..e27473d 100644 --- a/OneWireIO.vcxproj +++ b/OneWireIO.vcxproj @@ -13,6 +13,7 @@ {3B500971-1570-460F-81C3-22AC3B7764B9} OneWireIO + OneWireIO_Demo @@ -83,7 +84,7 @@ exit /B 1 - + Document false if exist $(ProjectDir)$(IntDir)$(ProjectName).cpp.elf del $(ProjectDir)$(IntDir)$(ProjectName).cpp.elf @@ -99,14 +100,10 @@ D:\Outils\Arduino\arduino.exe --pref build.path=$(ProjectDir)$(IntDir) --upload true - - true - - diff --git a/OneWireIO.vcxproj.filters b/OneWireIO.vcxproj.filters index 22a782b..fbe64d9 100644 --- a/OneWireIO.vcxproj.filters +++ b/OneWireIO.vcxproj.filters @@ -1,15 +1,13 @@  - - - + \ No newline at end of file diff --git a/OneWireIO_Demo.ino b/OneWireIO_Demo.ino new file mode 100644 index 0000000..cc2c9f6 --- /dev/null +++ b/OneWireIO_Demo.ino @@ -0,0 +1,75 @@ +#include "Arduino.h" +#include "LowLevel.h" +#include "OneWireSlave.h" + +#define LEDPin 13 + +// This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support) +// On Arduino Uno, you can use pin 2 or pin 3 +#define OWPin 2 + +Pin led(LEDPin); + +// This is the ROM the arduino will respond to, make sure it doesn't conflict with another device +byte owROM[7] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; + +byte acknowledge = 0x42; + +// This sample implements a simple protocol : sending match ROM, then the ROM, then 0x01 will turn the arduino light on. Sending 0x02 will turn it off. In each case, the byte 0x42 is sent as acknowledgement. +const byte CMD_TurnOn = 0x01; +const byte CMD_TurnOff = 0x02; + +// This function will be called each time the OneWire library has an event to notify (reset, error, byte received) +void owReceive(OneWireSlave::ReceiveEvent evt, byte data); + +void setup() +{ + led.outputMode(); + led.writeLow(); + + // Setup the OneWire library + OneWire.setReceiveCallback(&owReceive); + OneWire.begin(owROM, OWPin); +} + +void loop() +{ + delay(1); + + // You can do anything you want here, the OneWire library works entirely in background, using interrupts. + + cli();//disable interrupts + // Be sure to not block interrupts for too long, OneWire timing is very tight for some operations. 1 or 2 microseconds (yes, microseconds, not milliseconds) can be too much depending on your master controller, but then it's equally unlikely that you block exactly at the moment where it matters. + // This can be mitigated by using error checking and retry in your high-level communication protocol. A good thing to do anyway. + sei();//enable interrupts +} + +void owReceive(OneWireSlave::ReceiveEvent evt, byte data) +{ + switch (evt) + { + case OneWireSlave::RE_Byte: + if (data == CMD_TurnOn) + { + led.writeHigh(); + } + else if (data == CMD_TurnOff) + { + led.writeLow(); + } + else + { + break; + } + + // in this simple example we just reply with one byte to say we've processed the command + // a real application should have a CRC system to ensure messages are not corrupt, for both directions + // you can use the static OneWireSlave::crc8 method to add CRC checks in your communication protocol (it conforms to standard one-wire CRC checks, that is used to compute the ROM last byte for example) + OneWire.write(&acknowledge, 1, NULL); + + break; + + default: + ; // we could also react to reset and error notifications, but not in this sample + } +} diff --git a/OneWireSlave.cpp b/OneWireSlave.cpp index d4d05b5..916ae28 100644 --- a/OneWireSlave.cpp +++ b/OneWireSlave.cpp @@ -1,15 +1,7 @@ #include "OneWireSlave.h" -//#define DEBUG_LOG -#define ERROR_MESSAGES - -#ifdef DEBUG_LOG -#include "SerialChannel.h" -extern SerialChannel debug; -Pin dbgOutput(3); -#else -#undef ERROR_MESSAGES -#endif +// uncomment this line to enable sending messages along with errors (but takes more program memory) +//#define ERROR_MESSAGES #ifdef ERROR_MESSAGES #define ERROR(msg) error_(msg) @@ -77,13 +69,9 @@ void OneWireSlave::begin(byte* rom, byte pinNumber) lastReset_ = 0; memcpy(rom_, rom, 7); - rom_[7] = crc8_(rom_, 7); + rom_[7] = crc8(rom_, 7); - #ifdef DEBUG_LOG - debug.append("Enabling 1-wire library"); - dbgOutput.outputMode(); - dbgOutput.writeHigh(); - #endif + // log("Enabling 1-wire library") cli(); // disable interrupts pin_.inputMode(); @@ -120,7 +108,7 @@ void OneWireSlave::write(byte* bytes, short numBytes, void(*complete)(bool error sei(); } -byte OneWireSlave::crc8_(byte* data, short numBytes) +byte OneWireSlave::crc8(byte* data, short numBytes) { byte crc = 0; @@ -182,17 +170,11 @@ void OneWireSlave::pullLow_() { pin_.outputMode(); pin_.writeLow(); -#ifdef DEBUG_LOG - //dbgOutput.writeLow(); -#endif } void OneWireSlave::releaseBus_() { pin_.inputMode(); -#ifdef DEBUG_LOG - //dbgOutput.writeHigh(); -#endif } void OneWireSlave::beginResetDetection_() @@ -213,9 +195,7 @@ void OneWireSlave::resetCheck_() if (!pin_.read()) { pin_.attachInterrupt(&OneWireSlave::waitReset_, CHANGE); - #ifdef DEBUG_LOG - debug.SC_APPEND_STR("Reset detected during another operation"); - #endif + // log("Reset detected during another operation"); } onLeaveInterrupt_(); } @@ -344,22 +324,13 @@ void OneWireSlave::waitReset_() void OneWireSlave::beginPresence_() { - unsigned long now = micros(); pullLow_(); setTimerEvent_(PresenceDuration, &OneWireSlave::endPresence_); - #ifdef DEBUG_LOG - debug.SC_APPEND_STR_TIME("reset", lastReset_); - debug.SC_APPEND_STR_TIME("beginPresence", now); - #endif } void OneWireSlave::endPresence_() { - unsigned long now = micros(); releaseBus_(); - #ifdef DEBUG_LOG - debug.SC_APPEND_STR_TIME("endPresence", now); - #endif beginWaitCommand_(); } @@ -392,9 +363,8 @@ void OneWireSlave::onBitReceived_(bool bit, bool error) if (bufferBitPos_ == 8) { - #ifdef DEBUG_LOG - debug.SC_APPEND_STR_INT("received byte", (long)receivingByte_); - #endif + // log("received byte", (long)receivingByte_); + if (bufferPos_ == ReceiveCommand) { bufferPos_ = 0; @@ -495,9 +465,8 @@ void OneWireSlave::searchRomOnBitReceived_(bool bit, bool error) if (searchRomBytePos_ == 8) { - #ifdef DEBUG_LOG - debug.SC_APPEND_STR("ROM sent entirely"); - #endif + // log("ROM sent entirely"); + beginWaitReset_(); } else @@ -507,9 +476,7 @@ void OneWireSlave::searchRomOnBitReceived_(bool bit, bool error) } else { - #ifdef DEBUG_LOG - debug.SC_APPEND_STR("Leaving ROM search"); - #endif + // log("Leaving ROM search"); beginWaitReset_(); } } @@ -578,16 +545,14 @@ void OneWireSlave::matchRomBytesReceived_(bool error) if (memcmp(rom_, scratchpad_, 8) == 0) { - #ifdef DEBUG_LOG - debug.SC_APPEND_STR("ROM matched"); - #endif + // log("ROM matched"); + beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_); } else { - #ifdef DEBUG_LOG - debug.SC_APPEND_STR("ROM not matched"); - #endif + // log("ROM not matched"); + beginWaitReset_(); } } diff --git a/OneWireSlave.h b/OneWireSlave.h index b1dbc94..9eb279d 100644 --- a/OneWireSlave.h +++ b/OneWireSlave.h @@ -26,9 +26,9 @@ public: //! Enqueues the specified bytes in the send buffer. They will be sent in the background. The optional callback is used to notify when the bytes are sent, or if an error occured. Callbacks are executed from interrupts and should be as short as possible. void write(byte* bytes, short numBytes, void(*complete)(bool error)); -private: - static byte crc8_(byte* data, short numBytes); + static byte crc8(byte* data, short numBytes); +private: static void setTimerEvent_(short delayMicroSeconds, void(*handler)()); static void disableTimer_(); diff --git a/SerialChannel.cpp b/SerialChannel.cpp deleted file mode 100644 index 951f390..0000000 --- a/SerialChannel.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "Arduino.h" -#include "SerialChannel.h" - -#ifdef ENABLE_SERIAL_CHANNEL - -byte SerialChannel::nextId = 1; -SerialChannel* SerialChannel::first = 0; - -SerialChannel::Message SerialChannel::buffer1[SerialChannel::MaxPendingMessages]; -SerialChannel::Message SerialChannel::buffer2[SerialChannel::MaxPendingMessages]; -volatile SerialChannel::Message* SerialChannel::backBuffer; -volatile byte SerialChannel::backBufferPos; -byte SerialChannel::frontBufferSize; - -SerialChannel::Message dummyMessage; - -SerialChannel::SerialChannel(const char* name_) - : next(0) - , id((byte)-1) - , name(name_) -{ - if(first == 0) - first = this; - else - { - SerialChannel* c = first; - while(c->next != 0) c = c->next; - c->next = this; - } - - id = nextId++; -} - -void SerialChannel::beginWriteInChannel(byte id, short byteCount, unsigned long time) -{ - Serial.write("START"); - Serial.write(id); - writeULong(time); - writeShort(byteCount); -} - -void SerialChannel::write(byte* data, short byteCount, unsigned long time) -{ - beginWrite(byteCount, time); - continueWrite(data, byteCount); -} - -void SerialChannel::beginWrite(short byteCount, unsigned long time) -{ - if (time == (unsigned long)-1) - time = micros(); - - handleConnection(); - - beginWriteInChannel(id, byteCount, time); -} - -void SerialChannel::continueWrite(byte* data, short byteCount) -{ - Serial.write(data, byteCount); -} - -void SerialChannel::write(const char* text, unsigned long time) -{ - write((byte*)text, strlen(text), time); -} - -SerialChannel::Message& SerialChannel::append(byte* data, short byteCount, unsigned long time) -{ - if (time == (unsigned long)-1) - time = micros(); - - if (backBufferPos >= MaxPendingMessages) - { - Message& msg = ((Message*)backBuffer)[MaxPendingMessages-1]; - msg.id = id; - msg.data = (byte*)"OVERFLOW"; - msg.byteCount = 8; - msg.time = time; - msg.longArg0 = 0; - - return dummyMessage; - } - else - { - Message& msg = ((Message*)backBuffer)[backBufferPos++]; - msg.id = id; - msg.data = data; - msg.byteCount = byteCount; - msg.time = time; - msg.longArg0 = 0; - - return msg; - } -} - -void SerialChannel::append(const char* text, unsigned long time) -{ - append((byte*)text, strlen(text), time); -} - -void SerialChannel::appendInt(const char* text, short textLength, int arg0, unsigned long time) -{ - Message& msg = append((byte*)text, textLength, time); - msg.longArg0 = arg0 | 0x40000000; -} - -void SerialChannel::swap() -{ - backBuffer = backBuffer == buffer1 ? buffer2 : buffer1; - frontBufferSize = backBufferPos; - backBufferPos = 0; -} - -void SerialChannel::flush() -{ - handleConnection(); - - Message* frontBuffer = backBuffer == buffer1 ? buffer2 : buffer1; - for (Message* msg = frontBuffer; msg < frontBuffer + frontBufferSize; ++msg) - { - char params[32]; - params[0] = 0; - - if ((msg->longArg0 & 0x40000000) != 0) - sprintf(params, ";arg0=%ld", msg->longArg0 & ~0x40000000); - - short paramsSize = strlen(params); - - beginWriteInChannel(msg->id, msg->byteCount + paramsSize, msg->time); - Serial.write(msg->data, msg->byteCount); - if (paramsSize > 0) - Serial.write(params, paramsSize); - - Serial.flush(); - } -} - -void SerialChannel::writeShort(short num) -{ - Serial.write((byte*)&num, 2); -} - -void SerialChannel::writeULong(unsigned long num) -{ - Serial.write((byte*)&num, 4); -} - -void SerialChannel::handleConnection() -{ - int b = Serial.read(); - if(b == (int)'C') - { - Serial.write("CONNECTION"); - SerialChannel* c = first; - while(c) - { - Serial.write("START"); - Serial.write(0); - Serial.write("ChannelInit"); - Serial.write(c->id); - writeShort(strlen(c->name)); - Serial.write(c->name); - c = c->next; - } - Serial.flush(); - } -} - -#endif //ENABLE_SERIAL_CHANNEL diff --git a/SerialChannel.h b/SerialChannel.h deleted file mode 100644 index 2da7bf1..0000000 --- a/SerialChannel.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SerialChannel_h_ -#define _SerialChannel_h_ - -//#define ENABLE_SERIAL_CHANNEL - -#ifdef ENABLE_SERIAL_CHANNEL -#define SC_APPEND_STR(str) append((byte*)str, sizeof(str)-1) -#define SC_APPEND_STR_INT(str, arg0) appendInt(str, sizeof(str)-1, arg0) - -#define SC_APPEND_STR_TIME(str, time) append((byte*)str, sizeof(str)-1, time) - -class SerialChannel -{ -public: - struct Message - { - unsigned long time; - long longArg0; - byte* data; - short byteCount; - byte id; - }; - -private: - static const byte MaxPendingMessages = 32; - - static SerialChannel* first; - SerialChannel* next; - - static byte nextId; - byte id; - const char* name; - - static Message buffer1[MaxPendingMessages]; - static Message buffer2[MaxPendingMessages]; - static volatile Message* backBuffer; - static volatile byte backBufferPos; - static byte frontBufferSize; - -public: - SerialChannel(const char* name_); - - static void beginWriteInChannel(byte id, short byteCount, unsigned long time); - void write(byte* data, short byteCount, unsigned long time = (unsigned long)-1); - void write(const char* text, unsigned long time = (unsigned long)-1); - - void beginWrite(short byteCount, unsigned long time = (unsigned long)-1); - void continueWrite(byte* data, short byteCount); - - Message& append(byte* data, short byteCount, unsigned long time = (unsigned long)-1); - void append(const char* text, unsigned long time = (unsigned long)-1); - void appendInt(const char* text, short textLength, int arg0, unsigned long time = (unsigned long)-1); - static void swap(); - static void flush(); - -private: - static void handleConnection(); - static void writeShort(short num); - static void writeULong(unsigned long num); -}; -#endif // ENABLE_SERIAL_CHANNEL - -#endif - diff --git a/SerialMonitor/SerialMonitor.sln b/SerialMonitor/SerialMonitor.sln deleted file mode 100644 index f11d68b..0000000 --- a/SerialMonitor/SerialMonitor.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SerialMonitor", "SerialMonitor\SerialMonitor.csproj", "{97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/SerialMonitor/SerialMonitor/App.config b/SerialMonitor/SerialMonitor/App.config deleted file mode 100644 index 8e15646..0000000 --- a/SerialMonitor/SerialMonitor/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SerialMonitor/SerialMonitor/App.xaml b/SerialMonitor/SerialMonitor/App.xaml deleted file mode 100644 index a998b86..0000000 --- a/SerialMonitor/SerialMonitor/App.xaml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - diff --git a/SerialMonitor/SerialMonitor/App.xaml.cs b/SerialMonitor/SerialMonitor/App.xaml.cs deleted file mode 100644 index 3fa11b0..0000000 --- a/SerialMonitor/SerialMonitor/App.xaml.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Diagnostics; -using System.IO.Ports; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Shapes; -using System.Windows.Threading; - -namespace SerialMonitor -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - private SerialPort Serial; - private IDictionary Channels = new Dictionary(); - private bool Connected = false; - - protected override void OnStartup(StartupEventArgs e) - { - base.OnStartup(e); - - Serial = new SerialPort(); - Serial.PortName = "COM4"; - Serial.BaudRate = 9600; - - Serial.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(OnDataReceived); - - Serial.Open(); - Serial.Write("C"); - } - - private void OnDataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) - { - if (!Connected) - { - Serial.ReadTo("CONNECTION"); - Connected = true; - } - - // channel declaration message: byte 0 ; string "ChannelInit" ; byte ; short ; byte[length] - // regular message: byte ; short ; byte[length] - - SerialMessage message = null; - - Serial.ReadTo("START"); - - int id = Serial.ReadByte(); - if (id == 0) - { - string check = Encoding.UTF8.GetString(Serial.ReadBytes(11)); - if (check != "ChannelInit") - throw new Exception("Incorrect data check for channel initialization"); - id = Serial.ReadByte(); - int length = Serial.ReadShort(); - string name = Encoding.UTF8.GetString(Serial.ReadBytes(length)); - Channels[id] = name; - message = new SerialMessage { ChannelName = "debug", StringData = "Channel " + name + " opened", SendTime = 0 }; - } - else - { - ulong sendTime = Serial.ReadULong(); - int length = Serial.ReadShort(); - byte[] data = Serial.ReadBytes(length); - message = new SerialMessage { ChannelName = Channels[id], Data = data, SendTime = sendTime }; - } - - if(message != null) - Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => OnMessageReceived(message))); - } - - private void OnMessageReceived(SerialMessage message) - { - switch (message.ChannelName) - { - case "debug": - string text = ((float)message.SendTime / 1000000).ToString("0.000000") + "s " + message.StringData; - //Debug.WriteLine(text); - MainWindowContext.Get.WriteLine(text); - break; - case "oscilloscope": - byte frequency = message.Data[0]; - MainWindowContext.Get.AddSequence(message.SendTime, frequency, message.Data.Skip(1).ToArray()); - break; - } - } - } -} diff --git a/SerialMonitor/SerialMonitor/MainWindow.xaml b/SerialMonitor/SerialMonitor/MainWindow.xaml deleted file mode 100644 index 7cb7936..0000000 --- a/SerialMonitor/SerialMonitor/MainWindow.xaml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/SerialMonitor/SerialMonitor/MainWindow.xaml.cs b/SerialMonitor/SerialMonitor/MainWindow.xaml.cs deleted file mode 100644 index 82c9d9f..0000000 --- a/SerialMonitor/SerialMonitor/MainWindow.xaml.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SerialMonitor -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - var context = new MainWindowContext(this); - context.WriteLine("Connecting..."); - this.DataContext = context; - - this.MouseWheel += OnMouseWheel; - } - - private void OnMouseWheel(object sender, MouseWheelEventArgs e) - { - MainWindowContext context = (MainWindowContext)this.DataContext; - Point cursorPos = e.GetPosition(context.OscilloscopeCanvas); - if (cursorPos.X < 0 || cursorPos.X > context.OscilloscopeCanvas.ActualWidth || cursorPos.Y < 0 || cursorPos.Y > context.OscilloscopeCanvas.ActualHeight) - return; - - double cursorPosRatio = cursorPos.X / context.OscilloscopeCanvas.ActualWidth; - double cursorTime = context.ViewportStartTime + cursorPosRatio * context.ViewportTimeWidth; - - double newTimeWidth = context.ViewportTimeWidth; - if (e.Delta > 0) - newTimeWidth /= e.Delta * 0.01; - else if (e.Delta < 0) - newTimeWidth *= -e.Delta * 0.01; - - double totalTimeWidth = Math.Max(0.1, context.MaxTime - context.MinTime); - if (newTimeWidth > totalTimeWidth) - newTimeWidth = totalTimeWidth; - - double newStartTime = cursorTime - cursorPosRatio * newTimeWidth; - if (newStartTime < context.MinTime) - newStartTime = context.MinTime; - if (newStartTime + newTimeWidth > context.MaxTime) - newStartTime = context.MaxTime - newTimeWidth; - - context.SetViewport(newStartTime, newTimeWidth); - } - } -} diff --git a/SerialMonitor/SerialMonitor/MainWindowContext.cs b/SerialMonitor/SerialMonitor/MainWindowContext.cs deleted file mode 100644 index 1c34255..0000000 --- a/SerialMonitor/SerialMonitor/MainWindowContext.cs +++ /dev/null @@ -1,222 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Shapes; - -namespace SerialMonitor -{ - public class MainWindowContext : INotifyPropertyChanged - { - private MainWindow Window; - - public MainWindowContext(MainWindow window) - { - Window = window; - Get = this; - } - - public static MainWindowContext Get { get; private set; } - - private List Lines = new List(); - public string ConsoleText { get { return String.Join("\n", Lines); } } - - public void WriteLine(string line) - { - Lines.Add(line); - if (Lines.Count > 100) - Lines.RemoveAt(0); - OnPropertyChanged("ConsoleText"); - } - - public int MaxSequenceSize { get { return 2048; } } - - private class Sequence - { - public ulong StartTime { get; set; } // time in microseconds of the first sample - public byte[] Data { get; set; } - public double Frequency { get; set; } // sampling rate (in samples per second) - - public class Comparer : IComparer - { - public int Compare(Sequence x, Sequence y) - { - return x.StartTime.CompareTo(y.StartTime); - } - } - } - double ValueToHeight(double time, byte value) - { - //value = (byte)(Math.Sin(time * 100.0) * 127.0 + 128.0); - return 256.0 - (double)value + 10; - } - private SortedSet Sequences = new SortedSet(new Sequence.Comparer()); - public IEnumerable Oscilloscope - { - get - { - if(!Sequences.Any()) - yield break; - - foreach (var sequence in Sequences) - { - double seqStartTime = (double)sequence.StartTime/1000000.0; - double sampleDelay = 1.0 / sequence.Frequency; - if (seqStartTime + (double)sequence.Data.Length * sampleDelay > ViewportStartTime && seqStartTime < ViewportStartTime + ViewportTimeWidth) - { - foreach (var line in ConvertToLines(sequence)) - yield return line; - } - } - } - } - - private IEnumerable ConvertToLines(Sequence sequence) - { - double viewportWidth = OscilloscopeCanvas.ActualWidth; - double scale = viewportWidth / ViewportTimeWidth; // in pixels per second - - ulong displayStartTime = (ulong)(viewportStartTime_ * 1000000.0); - double sampleDelay = 1.0 / sequence.Frequency; - - double pos = ((double)sequence.StartTime - (double)displayStartTime) / 1000000.0 * scale; - if (pos > 1000) - yield break; - double prevPos = pos; - byte minValue = sequence.Data[0]; - byte maxValue = minValue; - int prevIdx = 0; - double prevHeight = ValueToHeight(sequence.StartTime / 1000000.0, minValue); - for (int idx = 1; idx < sequence.Data.Length; ++idx) - { - byte value = sequence.Data[idx]; - pos += sampleDelay * scale; - if (value > maxValue) maxValue = value; - if (value < minValue) minValue = value; - - if (pos > 0 && pos < viewportWidth && pos - prevPos >= 5 || idx == sequence.Data.Length - 1) - { - var line = new Line(); - line.Stroke = System.Windows.Media.Brushes.LightSteelBlue; - line.HorizontalAlignment = HorizontalAlignment.Left; - line.VerticalAlignment = VerticalAlignment.Center; - line.StrokeThickness = 1; - - line.X1 = prevPos; - prevPos = pos; - line.X2 = pos; - - double time = (double)sequence.StartTime / 1000000.0 + (double)idx * sampleDelay; - double lastHeight = ValueToHeight(time, value); - - if (idx == prevIdx + 1) - { - line.Y1 = prevHeight; - line.Y2 = lastHeight; - } - else - { - if (value - minValue > maxValue - value) - { - line.Y1 = ValueToHeight(time, minValue); - line.Y2 = ValueToHeight(time, maxValue); - } - else - { - line.Y1 = ValueToHeight(time, maxValue); - line.Y2 = ValueToHeight(time, minValue); - } - } - - prevHeight = lastHeight; - minValue = value; - maxValue = value; - prevIdx = idx; - - yield return line; - } - } - } - - public void AddSequence(ulong startTime, byte frequency, byte[] data) - { - // TODO: merge sequences if total size is lower than MaxSequenceSize - double cpuClock = 16000000.0; - int adsp0 = (frequency & (1 << 0)) != 0 ? 1 : 0; - int adsp1 = (frequency & (1 << 1)) != 0 ? 1 : 0; - int adsp2 = (frequency & (1 << 2)) != 0 ? 1 : 0; - int skipBit0 = (frequency & (1 << 3)) != 0 ? 1 : 0; - int skipBit1 = (frequency & (1 << 4)) != 0 ? 1 : 0; - int skipBit2 = (frequency & (1 << 5)) != 0 ? 1 : 0; - int adcDivider = 1 << Math.Max(1, adsp0 + adsp1*2 + adsp2*4); - int skip = skipBit0 + skipBit1 * 2 + skipBit2 * 4; - double freq = cpuClock / (double)adcDivider / 13.0 / (double)(1 + skip); - var sequence = new Sequence { StartTime = startTime, Frequency = freq, Data = data }; - Sequences.Add(sequence); - OnPropertyChanged("Oscilloscope"); - OnPropertyChanged("MinTime"); - OnPropertyChanged("MaxTime"); - if (Sequences.Count == 1) - { - ViewportStartTime = MinTime; - } - - var canvas = OscilloscopeCanvas; - foreach (var line in ConvertToLines(sequence)) - canvas.Children.Add(line); - } - - void RefreshOscilloscope() - { - var canvas = OscilloscopeCanvas; - canvas.Children.Clear(); - foreach (var line in Oscilloscope) - canvas.Children.Add(line); - } - - private Canvas oscilloscopeCanvas_; - public Canvas OscilloscopeCanvas { get { if (oscilloscopeCanvas_ == null) oscilloscopeCanvas_ = (Canvas)Window.FindName("Oscilloscope"); return oscilloscopeCanvas_; } } - - public double MinTime { get { return Sequences.Any() ? (double)Sequences.First().StartTime / 1000000.0 : 0.0; } } - public double MaxTime { get { return Sequences.Any() ? Math.Max(MinTime + 0.1, (double)Sequences.Last().StartTime / 1000000.0) : 0.1; } } - private double viewportTimeWidth_ = 0.1; - public double ViewportTimeWidth - { - get { return viewportTimeWidth_; } - set { viewportTimeWidth_ = value; OnPropertyChanged("ViewportTimeWidth"); RefreshOscilloscope(); } - } - - private double viewportStartTime_ = 0; - public double ViewportStartTime - { - get { return viewportStartTime_; } - set { viewportStartTime_ = value; OnPropertyChanged("ViewportStartTime"); RefreshOscilloscope(); } - } - public double ScrollValue - { - get { return MathEx.Unproject(MathEx.Project(ViewportStartTime, MinTime, MaxTime - ViewportTimeWidth), MinTime, MaxTime); } - set { ViewportStartTime = MathEx.Unproject(MathEx.Project(value, MinTime, MaxTime), MinTime, MaxTime - ViewportTimeWidth); } - } - - public void SetViewport(double startTime, double timeWidth) - { - viewportStartTime_ = startTime; - ViewportTimeWidth = timeWidth; - } - - public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged(string name) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(name)); - } - } - } -} diff --git a/SerialMonitor/SerialMonitor/MathEx.cs b/SerialMonitor/SerialMonitor/MathEx.cs deleted file mode 100644 index 4d6e1e6..0000000 --- a/SerialMonitor/SerialMonitor/MathEx.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SerialMonitor -{ - public static class MathEx - { - public static double Project(double value, double rangeMin, double rangeMax) - { - return (value - rangeMin) / (rangeMax - rangeMin); - } - - public static double Unproject(double ratio, double rangeMin, double rangeMax) - { - return rangeMin + ratio * (rangeMax - rangeMin); - } - } -} diff --git a/SerialMonitor/SerialMonitor/Properties/AssemblyInfo.cs b/SerialMonitor/SerialMonitor/Properties/AssemblyInfo.cs deleted file mode 100644 index e61c9f3..0000000 --- a/SerialMonitor/SerialMonitor/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SerialMonitor")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("SerialMonitor")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SerialMonitor/SerialMonitor/Properties/Resources.Designer.cs b/SerialMonitor/SerialMonitor/Properties/Resources.Designer.cs deleted file mode 100644 index b6091de..0000000 --- a/SerialMonitor/SerialMonitor/Properties/Resources.Designer.cs +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SerialMonitor.Properties -{ - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SerialMonitor.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/SerialMonitor/SerialMonitor/Properties/Resources.resx b/SerialMonitor/SerialMonitor/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/SerialMonitor/SerialMonitor/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SerialMonitor/SerialMonitor/Properties/Settings.Designer.cs b/SerialMonitor/SerialMonitor/Properties/Settings.Designer.cs deleted file mode 100644 index 098d3a4..0000000 --- a/SerialMonitor/SerialMonitor/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SerialMonitor.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/SerialMonitor/SerialMonitor/Properties/Settings.settings b/SerialMonitor/SerialMonitor/Properties/Settings.settings deleted file mode 100644 index 033d7a5..0000000 --- a/SerialMonitor/SerialMonitor/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/SerialMonitor/SerialMonitor/SerialMessage.cs b/SerialMonitor/SerialMonitor/SerialMessage.cs deleted file mode 100644 index 4e4ed5a..0000000 --- a/SerialMonitor/SerialMonitor/SerialMessage.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SerialMonitor -{ - public class SerialMessage - { - public string ChannelName { get; set; } - - /// - /// Time at which the message was sent, in microseconds since the start of the remote executable - /// - public ulong SendTime { get; set; } - - public byte[] Data { get; set; } - - public string StringData - { - get { return Encoding.UTF8.GetString(Data); } - set { Data = Encoding.UTF8.GetBytes(value); } - } - } -} diff --git a/SerialMonitor/SerialMonitor/SerialMonitor.csproj b/SerialMonitor/SerialMonitor/SerialMonitor.csproj deleted file mode 100644 index 6f58ec6..0000000 --- a/SerialMonitor/SerialMonitor/SerialMonitor.csproj +++ /dev/null @@ -1,108 +0,0 @@ - - - - - Debug - AnyCPU - {97704F53-6CA1-4155-9E8F-AEBFEEC20A8B} - WinExe - Properties - SerialMonitor - SerialMonitor - v4.5 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - - - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - - - - \ No newline at end of file diff --git a/SerialMonitor/SerialMonitor/SerialPortExtensions.cs b/SerialMonitor/SerialMonitor/SerialPortExtensions.cs deleted file mode 100644 index 91e98bc..0000000 --- a/SerialMonitor/SerialMonitor/SerialPortExtensions.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO.Ports; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SerialMonitor -{ - public static class SerialPortExtensions - { - public static int ReadShort(this SerialPort port) - { - int b1 = port.ReadByte(); - int b2 = port.ReadByte(); - return b2 * 256 + b1; - } - - public static ulong ReadULong(this SerialPort port) - { - ulong b1 = (ulong)port.ReadByte(); - ulong b2 = (ulong)port.ReadByte(); - ulong b3 = (ulong)port.ReadByte(); - ulong b4 = (ulong)port.ReadByte(); - return b4 * 256 * 256 * 256 + b3 * 256 * 256 + b2 * 256 + b1; - } - - public static byte[] ReadBytes(this SerialPort port, int numBytes) - { - var bytes = new byte[numBytes]; - int remaining = numBytes; - int pos = 0; - while (remaining > 0) - { - int read = port.Read(bytes, pos, remaining); - if (read < 0) - throw new Exception("Connection closed"); - remaining -= read; - pos += read; - } - return bytes; - } - } -} diff --git a/traces/search-without-arduino.bewf b/traces/search-without-arduino.bewf deleted file mode 100644 index c86be41..0000000 Binary files a/traces/search-without-arduino.bewf and /dev/null differ