(Environment: gcc/g++ 4.6.1 in -std=gnu++0x mode on Linux 3.0 / x86_64...)
#include <stdlib.h>
#include <signal.h>
#include <iostream>
using namespace std;
class SegmentationFault {};
void ThrowSegmentationFault(int)
{
throw SegmentationFault();
}
void ohno(char* x)
{
*x = 42;
}
int main()
{
signal(SIGSEGV, ThrowSegmentationFault);
try
{
ohno(0);
}
catch (const SegmentationFault&)
{
cout << "success" << endl;
}
}
By compiling the above with the -fnon-call-exceptions flag, it allows the SIGSEGV signal handler to throw an exception, and when run it will print "success". The documentation of the -fnon-call-exceptions gcc flag reads as follows:
Generate code that allows trapping instructions to throw
exceptions. Note that this requires platform-specific runtime support
that does not exist everywhere. Moreover, it only allows trapping
instructions to throw exceptions, i.e. memory references or floating
point instructions. It does not allow exceptions to be thrown from
arbitrary signal handlers such as SIGALRM.
My question is which of the signals are trapping instructions and which are not?
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
/*
#define SIGLOST 29
*/
#define SIGPWR 30
#define SIGSYS 31
#define SIGUNUSED 31
SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV, SIGSTKFLT are the most probable synchronous signals (i.e., generated by hardware as consequence of an instruction trying to do something invalid).
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm working on an implementation of an EST(Enrollment over Secure Transport)-client over CoAPs for the OpenThread stack. For this, i want to write a CSR (Certificate Signing Request) by using mbedTLS, which is part of the stack as a third party software. My problem now is that i get some "undefined reference" error from the linker when i build the code (i'm using GCC on an Ubuntu 18.04.2 LTS machine).
As there are multiple functions for which the error occurs, i will provide code for just one example. here is my source file:
openthread/src/core/crypto/ecp.cpp:
#include "ecp.hpp"
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/ecp.h>
#include <mbedtls/pk.h>
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/random.hpp"
#include "openthread/entropy.h"
#include "openthread/random_crypto.h"
namespace ot {
namespace Crypto {
#if OPENTHREAD_ENABLE_EST_CLIENT && OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
otError Ecp::KeyPairGeneration(const uint8_t *aPersonalSeed,
uint32_t aPersonalSeedLength,
uint8_t * aPrivateKey,
uint32_t * aPrivateKeyLength,
uint8_t * aPublicKey,
uint32_t * aPublicKeyLength)
{
otError error = OT_ERROR_NONE;
mbedtls_pk_context keypair;
OT_UNUSED_VARIABLE(aPersonalSeed);
OT_UNUSED_VARIABLE(aPersonalSeedLength);
mbedtls_pk_init(&keypair);
// Generate keypair
VerifyOrExit(mbedtls_pk_setup(&keypair, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)),
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_ecp_group_load(&mbedtls_pk_ec(keypair)->grp, MBEDTLS_ECP_DP_SECP256R1) == 0,
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_ecp_gen_keypair(&mbedtls_pk_ec(keypair)->grp, &mbedtls_pk_ec(keypair)->d,
&mbedtls_pk_ec(keypair)->Q, mbedtls_ctr_drbg_random,
Random::Crypto::MbedTlsContextGet()) == 0,
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_pk_write_pubkey_pem(&keypair, (unsigned char*)aPublicKey,
*aPublicKeyLength) == 0,
error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mbedtls_pk_write_key_pem(&keypair, (unsigned char*)aPrivateKey,
*aPrivateKeyLength) == 0,
error = OT_ERROR_INVALID_ARGS);
exit:
mbedtls_pk_free(&keypair);
return error;
}
#endif // OPENTHREAD_ENABLE_EST_CLIENT
} // namespace Crypto
} // namespace ot
my header file:
openthread/src/core/crypto/ecp.hpp
#ifndef ECP_HPP_
#define ECP_HPP_
#include "openthread-core-config.h"
#include <stdint.h>
#include <stdlib.h>
#include <openthread/error.h>
namespace ot {
namespace Crypto {
/**
* #addtogroup core-security
*
* #{
*
*/
/**
* This class implements elliptic curve key generation.
*
*/
class Ecp
{
public:
/**
* This method generate a Elliptic Curve key pair.
*
* #param[in] aPersonalSeed An additional seed for the entropy. Can be NULL.
* #param[in] aPersonalSeedLengh The length of the #p aPersonalSeed.
* #param[out] aPrivateKey An output buffer where the private key should be stored.
* #param[inout] aPrivateKeyLength The length of the #p aPrivateKey buffer.
* #param[out] aPublicKey An output buffer where the private key should be stored.
* #param[inout] aPublicKeyLength The length of the #p aPublicKey buffer.
*
* #retval OT_ERROR_NONE EC key pairs has been created successfully.
* OT_ERROR_NO_BUFS Key buffers are too small or mbedtls heap too small.
*/
static otError KeyPairGeneration(const uint8_t *aPersonalSeed,
uint32_t aPersonalSeedLength,
uint8_t * aPrivateKey,
uint32_t * aPrivateKeyLength,
uint8_t * aPublicKey,
uint32_t * aPublicKeyLength);
};
/**
* #}
*
*/
} // namespace Crypto
} // namespace ot
#endif // ECP_HPP_
The functions which cause the error are here mbedtls_pk_write_pubkey_pem and mbedtls_pk_write_key_pem.
Here is also a part of the console output:
Making all in apps
Making all in cli
CC ot_cli_ftd-main.o
CC ot_cli_mtd-main.o
CCLD ot-cli-ftd
CCLD ot-cli-mtd
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: ../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-ecp.o): in function `ot::Crypto::Ecp::KeyPairGeneration(unsigned char const*, unsigned long, unsigned char*, unsigned long*, unsigned char*, unsigned long*)':
/home/scnm/eclipse-workspace/openthread/examples/../src/core/crypto/ecp.cpp:79: undefined reference to `mbedtls_pk_write_pubkey_pem'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/scnm/eclipse-workspace/openthread/examples/../src/core/crypto/ecp.cpp:83: undefined reference to `mbedtls_pk_write_key_pem'
collect2: error: ld returned 1 exit status
Makefile:1249: recipe for target 'ot-cli-mtd' failed
make[5]: *** [ot-cli-mtd] Error 1
I first thougth it was because i was missing some #define to actually use these functions, but i compared it with other OpenThread code which uses mbedtls and i can't see what i did wrong. As far as i've understood it, i have to modify the "openthread/third_party/mbedtls/mbedtls-config.h" file so that these funtions are build, so this is what i did:
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <openthread/config.h>
#include <openthread/platform/logging.h>
#include <openthread/platform/memory.h>
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
#define MBEDTLS_AES_C
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CMAC_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ECJPAKE_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
#define MBEDTLS_MD_C
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA256_SMALLER
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_EXPORT_KEYS
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_TLS_C
#if OPENTHREAD_ENABLE_BORDER_AGENT || OPENTHREAD_ENABLE_COMMISSIONER || OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_SRV_C
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#if OPENTHREAD_ENABLE_EST_CLIENT
#define MBEDTLS_PEM_WRITE_C
#define MBEDTLS_PK_WRITE_C
#define MBEDTLS_X509_CSR_WRITE_C
#define MBEDTLS_X509_CREATE_C
#endif
#endif
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_BASE64_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
#endif
#if OPENTHREAD_ENABLE_ECDSA
#define MBEDTLS_BASE64_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#endif
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
#define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
#else
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */
#else
#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */
#endif
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
#if defined(MBEDTLS_USER_CONFIG_FILE)
#include MBEDTLS_USER_CONFIG_FILE
#endif
#if defined(MBEDTLS_ECP_ALT) && !defined(MBEDTLS_ECP_RESTARTABLE)
typedef void mbedtls_ecp_restart_ctx;
#endif
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
It resolved the "not defined in this scope" errors i've had before, but instead i have now the above described errors.
Here is what i've edited in the common-switch file:
openthread/examples/common-switches.mk
ECDSA ?= 0
// my code begin
EST_CLIENT ?= 0
// my code end
JAM_DETECTION ?= 0
ifeq ($(ECDSA),1)
configure_OPTIONS += --enable-ecdsa
endif
// my code begin
ifeq ($(EST_CLIENT),1)
configure_OPTIONS += --enable-est-client --enable-application-coap-secure
endif
// my code end
ifeq ($(JAM_DETECTION),1)
configure_OPTIONS += --enable-jam-detection
endif
and her what i've added to configure:
openthread/configure.ac
#
# EST Client
#
AC_ARG_ENABLE(est_client,
[AS_HELP_STRING([--enable-est-client],[Enable EST client support #<:#default=no#:>#.])],
[
case "${enableval}" in
no|yes)
enable_est_client=${enableval}
;;
*)
AC_MSG_ERROR([Invalid value ${enable_est_client} for --enable-est-client])
;;
esac
],
[enable_est_client=no])
if test "$enable_est_client" = "yes"; then
OPENTHREAD_ENABLE_EST_CLIENT=1
else
OPENTHREAD_ENABLE_EST_CLIENT=0
fi
AC_SUBST(OPENTHREAD_ENABLE_EST_CLIENT)
AM_CONDITIONAL([OPENTHREAD_ENABLE_EST_CLIENT], [test "${enable_est_client}" = "yes"])
AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_EST_CLIENT],[${OPENTHREAD_ENABLE_EST_CLIENT}],[Define to 1 if you want to enable EST Client])
OpenThread DNS Client support : ${enable_dns_client}
// my code begin
OpenThread EST Client support : ${enable_est_client}
// my code end
OpenThread SNTP Client support : ${enable_sntp_client}
I've also edited the makefile:
openthread/src/core/Makefile.am
crypto/ecdsa.hpp \
crypto/ecp.hpp \
crypto/hmac_sha256.hpp \
crypto/ecdsa.cpp \
crypto/ecp.cpp \
crypto/hmac_sha256.cpp \
My build command is "make -f examples/Makefile-nrf52840 EST_CLIENT=1".
I think once this problem is solved, i can solve the others by myself as the root of the problem seems to be the same.
Thanks.
You have an error during the link, the symbol mbedtls_pk_write_pubkey_pem is not defined, that means you missed to specify the lib defining it. Looking on the web it seems you need to link with mbedcrypto, so add libmbedcrypto.a or -lmbedcrypto (and may be use the option -L to specify the path)
It seems you also use X509, if you have missing symbols *X509* link with mbedx509, so add libmbedx509.a or -lmbedx509 (and may be use the option -L to specify the path)
I happened to come across a macro definition as shown below in a c++ code(https://github.com/LairdCP/UwTerminalX).
#define SpeedModeInactive 0b00
#define SpeedModeRecv 0b01
#define SpeedModeSend 0b10
#define SpeedModeSendRecv 0b11
When I tried to compile it using visual studio 2010, it giving me the following error.
Error 14 error C2059: syntax error : ')'
What is the meaning of this macro?
The usage of macro is shown below.
if ((gchSpeedTestMode == SpeedModeSendRecv || gchSpeedTestMode == SpeedModeRecv) && (gintSpeedBytesReceived10s > 0 || ui->edit_SpeedBytesRec10s->text().toInt() > 0))
{
//Data has been received in the past 10 seconds: start a timer before stopping to catch the extra data packets
gchSpeedTestMode = SpeedModeRecv;
gtmrSpeedTestDelayTimer = new QTimer();
gtmrSpeedTestDelayTimer->setSingleShot(true);
connect(gtmrSpeedTestDelayTimer, SIGNAL(timeout()), this, SLOT(SpeedTestStopTimer()));
gtmrSpeedTestDelayTimer->start(5000);
//Show message that test will end soon
ui->statusBar->showMessage("Waiting 5 seconds for packets to be received... Click cancel again to stop instantly.");
}
It is because visual studio doesn't recognize binary values (starting with 0bXXX) but, you can simply define as a hex values just like that:
#define SpeedModeInactive 0x0
#define SpeedModeRecv 0x1
#define SpeedModeSend 0x2
#define SpeedModeSendRecv 0x3
The use of binary literals was first introduced in C++14 which is not supported by VS2010, https://en.wikipedia.org/wiki/C%2B%2B14#Binary_literals
I am trying to create a student response system for a Jeopardy-like game using cheap tv remote controls. They are infrared, NEC protocol. A serial monitor displays button press from students in order they respond.
I'm using a TSOP 4838 receiver connected to an Arduino Uno with a capacitor and so far just the serial monitor that comes with the Arduino IDE software. My code appears below.
All is working well as long as 2 or more students do not press buttons within a half-second of each other. If that happens, I get no output on the serial monitor. I'm hoping there is some change I can make to my sketch or to the IRremote.h or IRremoteInt.h files to discern the signals quicker so my display lists who clicked first.
IRremote.h:
*/
* IRremote v1.1
* By Chris Targett
* November 2011
*
* Based on Ken Shirriff's Version 0.11 of his IR-Remote library August, 2009
* https://github.com/shirriff/Arduino-IRremote
*/
#ifndef IRremote_h
#define IRremote_h
// The following are compile-time library options.
// If you change them, recompile the library.
// If DEBUG is defined, a lot of debugging output will be printed during decoding.
// TEST must be defined for the IRtest unittests to work. It will make some
// methods virtual, which will be slightly slower, which is why it is optional.
// #define DEBUG
// #define TEST
// Results returned from the decoder
class decode_results {
public:
int decode_type; // NEC, SONY, RC5, RC6, DISH, SHARP, SAMSUNG, JVC, UNKNOWN
unsigned long value; // Decoded value
unsigned long address; // address for panasonic codes
int bits; // Number of bits in decoded value
volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
int rawlen; // Number of records in rawbuf.
};
// Values for decode_type
#define NEC 1
#define SONY 2
#define RC5 3
#define RC6 4
#define DISH 5
#define SHARP 6
#define SAMSUNG 7
#define JVC 8
#define PANASONIC 9
#define UNKNOWN -1
// Decoded value for NEC when a repeat code is received
#define REPEAT 0xffffffff
// main class for receiving IR
class IRrecv
{
public:
IRrecv(int recvpin);
void blink13(int blinkflag);
int decode(decode_results *results);
void enableIRIn();
void resume();
private:
// These are called by decode
int getRClevel(decode_results *results, int *offset, int *used, int t1);
long decodeNEC(decode_results *results);
long decodeSony(decode_results *results);
long decodeSamsung(decode_results *results);
long decodeRC5(decode_results *results);
long decodeRC6(decode_results *results);
long decodeJVC(decode_results *results);
long decodeHash(decode_results *results);
long decodePanasonic(decode_results *results);
int compare(unsigned int oldval, unsigned int newval);
}
;
// Only used for testing; can remove virtual for shorter code
#ifdef TEST
#define VIRTUAL virtual
#else
#define VIRTUAL
#endif
class IRsend
{
public:
IRsend() {}
void sendNEC(unsigned long data, int nbits);
void sendSony(unsigned long data, int nbits);
void sendSamsung(unsigned long data, int nbits);
void sendRaw(unsigned int buf[], int len, int hz);
void sendRC5(unsigned long data, int nbits);
void sendRC6(unsigned long long data, int nbits);
void sendDISH(unsigned long data, int nbits);
void sendSharp(unsigned long data, int nbits);
void sendJVC(unsigned long data, int nbits, int repeat);
void sendPanasonic(unsigned long address, unsigned long data);
// private:
void enableIROut(int khz);
VIRTUAL void mark(int usec);
VIRTUAL void space(int usec);
}
;
// Some useful constants
#define USECPERTICK 50
#define RAWBUF 76
// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.
#define MARK_EXCESS 100
#endif
Here is the IRremoteInt.h
/*
* IRremote v1.1
* By Chris Targett
* November 2011
*
* Based on Ken Shirriff's Version 0.11 of his IR-Remote library August, 2009
* https://github.com/shirriff/Arduino-IRremote
*/
#ifndef IRremoteint_h
#define IRremoteint_h
#include <Arduino.h>
#define CLKFUDGE 5 // fudge factor for clock interrupt overhead
#define CLK 256 // max value for clock (timer 2)
#define PRESCALE 8 // timer2 clock prescale
#define SYSCLOCK 16000000 // main Arduino clock
#define CLKSPERUSEC (SYSCLOCK/PRESCALE/1000000) // timer clocks per microsecond
#define ERR 0
#define DECODED 1
#define BLINKLED 13
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// clock timer reset value
#define INIT_TIMER_COUNT2 (CLK - USECPERTICK*CLKSPERUSEC + CLKFUDGE)
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2
// pulse parameters in usec
#define NEC_HDR_MARK 9000
#define NEC_HDR_SPACE 4500
#define NEC_BIT_MARK 560
#define NEC_ONE_SPACE 1600
#define NEC_ZERO_SPACE 560
#define NEC_RPT_SPACE 2250
#define SONY_HDR_MARK 2400
#define SONY_HDR_SPACE 600
#define SONY_ONE_MARK 1200
#define SONY_ZERO_MARK 600
#define SONY_RPT_LENGTH 45000
#define RC5_T1 889
#define RC5_RPT_LENGTH 46000
#define RC6_HDR_MARK 2666
#define RC6_HDR_SPACE 889
#define RC6_T1 444
#define RC6_RPT_LENGTH 46000
#define SAMSUNG_HDR_MARK 4500
#define SAMSUNG_BITS 32
#define SAMSUNG_HDR_SPACE 4500
#define SAMSUNG_BIT_MARK 560
#define SAMSUNG_ONE_SPACE 1600
#define SAMSUNG_ZERO_SPACE 600
#define SHARP_BIT_MARK 245
#define SHARP_ONE_SPACE 1805
#define SHARP_ZERO_SPACE 795
#define SHARP_GAP 600000
#define SHARP_TOGGLE_MASK 0x3FF
#define SHARP_RPT_SPACE 3000
#define DISH_HDR_MARK 400
#define DISH_HDR_SPACE 6100
#define DISH_BIT_MARK 400
#define DISH_ONE_SPACE 1700
#define DISH_ZERO_SPACE 2800
#define DISH_RPT_SPACE 6200
#define DISH_TOP_BIT 0x8000
#define SHARP_BITS 15
#define DISH_BITS 16
#define JVC_HDR_MARK 8000
#define JVC_HDR_SPACE 4000
#define JVC_BIT_MARK 600
#define JVC_ONE_SPACE 1600
#define JVC_ZERO_SPACE 550
#define JVC_RPT_LENGTH 60000
#define PANASONIC_HDR_MARK 3502
#define PANASONIC_HDR_SPACE 1750
#define PANASONIC_BIT_MARK 502
#define PANASONIC_ONE_SPACE 1244
#define PANASONIC_ZERO_SPACE 370
#define TOLERANCE 25 // percent tolerance in measurements
#define LTOL (1.0 - TOLERANCE/100.)
#define UTOL (1.0 + TOLERANCE/100.)
#define _GAP 5000 // Minimum map between transmissions
#define GAP_TICKS (_GAP/USECPERTICK)
#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
#ifndef DEBUG
#define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us))
#define MATCH_MARK(measured_ticks, desired_us) MATCH(measured_ticks, (desired_us) + MARK_EXCESS)
#define MATCH_SPACE(measured_ticks, desired_us) MATCH((measured_ticks), (desired_us) - MARK_EXCESS)
// Debugging versions are in IRremote.cpp
#endif
// receiver states
#define STATE_IDLE 2
#define STATE_MARK 3
#define STATE_SPACE 4
#define STATE_STOP 5
// information for the interrupt handler
typedef struct {
uint8_t recvpin; // pin for IR data from detector
uint8_t rcvstate; // state machine
uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing
unsigned int timer; // state timer, counts 50uS ticks.
unsigned int rawbuf[RAWBUF]; // raw data
uint8_t rawlen; // counter of entries in rawbuf
}
irparams_t;
// Defined in IRremote.cpp
extern volatile irparams_t irparams;
// IR detector output is active low
#define MARK 0
#define SPACE 1
#define TOPBIT 0x80000000
#define NEC_BITS 32
#define SONY_BITS 12
#define JVC_BITS 32
#define MIN_RC5_SAMPLES 11
#define MIN_RC6_SAMPLES 1
#endif
and here's my sketch:
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
if (results.value == 551520375) { //1
Serial.println("Team 1");
}
if (results.value == 551504055) { //2
Serial.println("Team 2");
}
if (results.value == 551536695) { //3
Serial.println("Team 3");
}
if (results.value == 551495895) { //4
Serial.println("Team 4");
}
if (results.value == 551528535) { //5
Serial.println("Team 5");
}
if (results.value == 551512215) { //6
Serial.println("Team 6");
}
if (results.value == 551544855) { //7
Serial.println("Team 7");
}
if (results.value == 551491815) { //8
Serial.println("Team 8");
}
if (results.value == 551524455) { //9
Serial.println("Team 9");
}
if (results.value == 551487735) { //10
Serial.println("Team 10");
}
// Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
}
In short - Not really and not reliably. The problem is that your system is effectively multi-dropped. The receiver is the seeing the sum of both transmitters. Where the modulation and encoded signal are summed up and thus corrupted.
I have IR toy magic wands, for dueling I have a the winner keep transmitting as to JAM the looser latter signal.
You could try to use TWO different modulation frequencies. One remote at 36K and the other at 60K. 38K is typical and there is significant overlap. I have seen 36 and 40 get heard or corrupt 38K. So I would got to the farthest ends of available demodulator chips; being 36K and 60K. However, I suspect you are using provided transmitters which may not be changed. So you will have to find some or build one.
Additionally using pre-built ones, you are at the mercy of its behavior. You stated 1/2 second. That is likely because they are re-transmitting retries and have start delays and pauses beyond that of the NEC frame being sent.
You could also implement RX/TX pairs that are different IR wavelength. However, most purchasable demodulator IC's are on standard wavelength. I also recommend not building a discrete RX when possible, as they integrated RX/Demodulators have Auto GAIN, stuff like that.
i have a problem with resources in my audio plugin
here is my resource file
// Unique IDs for each image resource.
#define BCKG_ID 101
#define CANT_ID 102
#define COM10_ID 103
#define COM20_ID 104
#define COM40_ID 105
#define COM80_ID 106
#define SAVE_ID 107
#define WAIT_ID 108
#define ONOFFBYPASS_ID 109
#define ONOFFPRESSED_ID 110
// Image resource locations for this plug.
#define BCKG_FN "resources/img/background.png"
#define CANT_FN "resources/img/cant.png"
#define COM10_FN "resources/img/combo10.png"
#define COM20_FN "resources/img/combo20.png"
#define COM40_FN "resources/img/combo40.png"
#define COM80_FN "resources/img/combo80.png"
#define SAVE_FN "resources/img/savwav.png"
#define WAIT_FN "resources/img/waiting.png"
#define ONOFFBYPASS_FN "resources/img/onoff-bypass.png"
#define ONOFFPRESSED_FN "resources/img/onoff-pressed.png"
i have an assert issue : "file not found" when using this code :
IBitmap onoff1 = pGraphics->LoadIBitmap(ONOFFBYPASS_ID, ONOFFBYPASS_FN, 1);
if i use WAIT_ID instead of ONOFFBYPASS_ID, everything works
in debug assert this code raises a flag:
IBitmap IGraphics::LoadIBitmap(int ID, const char* name, int nStates, bool framesAreHoriztonal)
{
LICE_IBitmap* lb = s_bitmapCache.Find(ID);
if (!lb)
{
lb = OSLoadBitmap(ID, name);
#ifndef NDEBUG
bool imgResourceFound = lb;
#endif
assert(imgResourceFound); **//imgResourceFound = false**
s_bitmapCache.Add(lb, ID);
}
return IBitmap(lb, lb->getWidth(), lb->getHeight(), nStates, framesAreHoriztonal);
}
i tried to :
switch ID values (109 <-> 108)
change the names
check 10 times the paths
but nothing works
it doesn't makes sense, especially because i have 2 other audio plugins with the same part of code that are working ok...
sorry can't provide sample code as it would mean installing VST SDK, WDL-OK...so a bit too much i guess.
please help anyway
Jeff
oh i made a noob error: i forget to add
ONOFFBYPASS_ID PNG ONOFFBYPASS_FN
ONOFFPRESSED_ID PNG ONOFFPRESSED_FN
to MyProg.rc
now everything works
Jeff
I am fairly new to C++ programming, so please bear with me. I am writing a small application in visual studio that would be used to communicate with an FTDI module (UM232H high speed USB module). FTDI provides the D2XX drivers for this module and is readily available on their website. Right now the program I have is very simple. It is calling a function called FT_Open (ftd2xx.h) to simply open the device and top check to see if the device is connected to the computer.
However right now I keep getting the error LNK2019, unresolved external symbol. Now I did read through the application note provide by Visual Studio website but I still can not seem to resolve my error. I think I am making a silly mistake and would like some guidance from you guys, if you guys could help me out.
I have provide my code as well as the header file (ftd2xx.h) that was provide from the FTDI website.
Main Program:
// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "ftd2xx.h"
#include <iostream>
using namespace std;
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
int main(){
ftStatus = FT_Open(0,&ftHandle);
if (ftStatus == FT_OK) {
cout << "hello world";
// FT_Open OK, use ftHandle to access device
}
else {
// FT_Open failed
}
return 0;
}
ftd2xx.h:
#include "windows.h"
/*#include <stdarg.h>
#include <windef.h>
#include <winnt.h>
#include <winbase.h>*/
/*++
Copyright © 2001-2011 Future Technology Devices International Limited
THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "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
FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED 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.
FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS.
FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED.
IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE
RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL
RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES.
Module Name:
ftd2xx.h
Abstract:
Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices
FTD2XX library definitions
Environment:
kernel & user mode
--*/
#ifndef FTD2XX_H
#define FTD2XX_H
// The following ifdef block is the standard way of creating macros
// which make exporting from a DLL simpler. All files within this DLL
// are compiled with the FTD2XX_EXPORTS symbol defined on the command line.
// This symbol should not be defined on any project that uses this DLL.
// This way any other project whose source files include this file see
// FTD2XX_API functions as being imported from a DLL, whereas this DLL
// sees symbols defined with this macro as being exported.
#ifdef FTD2XX_EXPORTS
#define FTD2XX_API __declspec(dllexport)
#else
#define FTD2XX_API __declspec(dllimport)
#endif
typedef PVOID FT_HANDLE;
typedef ULONG FT_STATUS;
//
// Device status
//
enum {
FT_OK,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_NOT_SUPPORTED,
FT_OTHER_ERROR,
FT_DEVICE_LIST_NOT_READY,
};
#define FT_SUCCESS(status) ((status) == FT_OK)
//
// FT_OpenEx Flags
//
#define FT_OPEN_BY_SERIAL_NUMBER 1
#define FT_OPEN_BY_DESCRIPTION 2
#define FT_OPEN_BY_LOCATION 4
//
// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags
//
#define FT_LIST_NUMBER_ONLY 0x80000000
#define FT_LIST_BY_INDEX 0x40000000
#define FT_LIST_ALL 0x20000000
#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL)
//
// Baud Rates
//
#define FT_BAUD_300 300
#define FT_BAUD_600 600
#define FT_BAUD_1200 1200
#define FT_BAUD_2400 2400
#define FT_BAUD_4800 4800
#define FT_BAUD_9600 9600
#define FT_BAUD_14400 14400
#define FT_BAUD_19200 19200
#define FT_BAUD_38400 38400
#define FT_BAUD_57600 57600
#define FT_BAUD_115200 115200
#define FT_BAUD_230400 230400
#define FT_BAUD_460800 460800
#define FT_BAUD_921600 921600
//
// Word Lengths
//
#define FT_BITS_8 (UCHAR) 8
#define FT_BITS_7 (UCHAR) 7
//
// Stop Bits
//
#define FT_STOP_BITS_1 (UCHAR) 0
#define FT_STOP_BITS_2 (UCHAR) 2
//
// Parity
//
#define FT_PARITY_NONE (UCHAR) 0
#define FT_PARITY_ODD (UCHAR) 1
#define FT_PARITY_EVEN (UCHAR) 2
#define FT_PARITY_MARK (UCHAR) 3
#define FT_PARITY_SPACE (UCHAR) 4
//
// Flow Control
//
#define FT_FLOW_NONE 0x0000
#define FT_FLOW_RTS_CTS 0x0100
#define FT_FLOW_DTR_DSR 0x0200
#define FT_FLOW_XON_XOFF 0x0400
//
// Purge rx and tx buffers
//
#define FT_PURGE_RX 1
#define FT_PURGE_TX 2
//
// Events
//
typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
#define FT_EVENT_RXCHAR 1
#define FT_EVENT_MODEM_STATUS 2
#define FT_EVENT_LINE_STATUS 4
//
// Timeouts
//
#define FT_DEFAULT_RX_TIMEOUT 300
#define FT_DEFAULT_TX_TIMEOUT 300
//
// Device types
//
typedef ULONG FT_DEVICE;
enum {
FT_DEVICE_BM,
FT_DEVICE_AM,
FT_DEVICE_100AX,
FT_DEVICE_UNKNOWN,
FT_DEVICE_2232C,
FT_DEVICE_232R,
FT_DEVICE_2232H,
FT_DEVICE_4232H,
FT_DEVICE_232H,
FT_DEVICE_X_SERIES
};
//
// Bit Modes
//
#define FT_BITMODE_RESET 0x00
#define FT_BITMODE_ASYNC_BITBANG 0x01
#define FT_BITMODE_MPSSE 0x02
#define FT_BITMODE_SYNC_BITBANG 0x04
#define FT_BITMODE_MCU_HOST 0x08
#define FT_BITMODE_FAST_SERIAL 0x10
#define FT_BITMODE_CBUS_BITBANG 0x20
#define FT_BITMODE_SYNC_FIFO 0x40
//
// FT232R CBUS Options EEPROM values
//
#define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable
#define FT_232R_CBUS_PWRON 0x01 // Power On
#define FT_232R_CBUS_RXLED 0x02 // Rx LED
#define FT_232R_CBUS_TXLED 0x03 // Tx LED
#define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED
#define FT_232R_CBUS_SLEEP 0x05 // Sleep
#define FT_232R_CBUS_CLK48 0x06 // 48MHz clock
#define FT_232R_CBUS_CLK24 0x07 // 24MHz clock
#define FT_232R_CBUS_CLK12 0x08 // 12MHz clock
#define FT_232R_CBUS_CLK6 0x09 // 6MHz clock
#define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang
#define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe
#define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe
//
// FT232H CBUS Options EEPROM values
//
#define FT_232H_CBUS_TRISTATE 0x00 // Tristate
#define FT_232H_CBUS_TXLED 0x01 // Tx LED
#define FT_232H_CBUS_RXLED 0x02 // Rx LED
#define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_232H_CBUS_PWREN 0x04 // Power Enable
#define FT_232H_CBUS_SLEEP 0x05 // Sleep
#define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_232H_CBUS_CLK30 0x0A // 30MHz clock
#define FT_232H_CBUS_CLK15 0x0B // 15MHz clock
#define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock
//
// FT X Series CBUS Options EEPROM values
//
#define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate
#define FT_X_SERIES_CBUS_RXLED 0x01 // Tx LED
#define FT_X_SERIES_CBUS_TXLED 0x02 // Rx LED
#define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable
#define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep
#define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock
#define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock
#define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock
#define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected
#define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted
#define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty
#define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full
#define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS
#define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe
#define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe
#define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received
#define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 //
// Driver types
#define FT_DRIVER_TYPE_D2XX 0
#define FT_DRIVER_TYPE_VCP 1
#ifdef __cplusplus
extern "C" {
#endif
FTD2XX_API
FT_STATUS WINAPI FT_Open(
int deviceNumber,
FT_HANDLE *pHandle
);
--Rest of the of the header file was omitted because of the limit to the number of characters I could write.
Sorry for the large amount of code I provided here, I just wanted to be sure that I provided everything that I possibly could. Let me know if I would need to provide the rest of the header file.
Maybe it is bit later for an answer.
I got same error with old outdated ftd2xx.lib file.
Afetr adding new ftd2xx.lib, ftd2xx.dll and ftd2xx.h files, cleaning and rebuilding the project a problem was solved.
Have you made sure to include the .lib your compiler will need to link against? Along with any header files, they probably provided a .lib and/or .dll.
If you use the static version of the .lib, you will have to define FTD2XX_STATIC to the preprocessor, as explained in the documentation (chapter 2.4 of Instructions on Including the D2XX
Driver in a VS Express Project).