2014/12/30

Lamba captures with move semantics in C++ 11

It is possible to move values into lambda's in C++ 11 but it requires a wrapper. Here is what I am using.  It should only be used in this context as when it is copied it acts like a move and sucks the guts out of the source. I needed this where I had to supply a shared_ptr to a class to an async event callback and needed to keep it in scope past the lifetime of the parent. I did not want to store the "global" and copying would keep the lifetime alive well past the end of the callback

Link

2014/12/13

A barebones async server with Boost ASIO

I am writing this partially for my own documentation.  Took me a few to jump through the examples on the Boost site, so I thought I would post a skeleton async server.
There are a couple of things to keep in mind. You own the buffers and must maintain their lifetime. I have done this by passing the connection to the handlers via a iterator/pointer. In the case of the write handler I pass a shared_ptr to the data buffer. Both methods should work. In more complicated servers there will be more than a buffer and socket to maintain in a connection. Also, the ioservice will block until there is no work available. That is it. So here is the Hello World async server
Link

2012/12/07

Arduino Uno on Windows 8 without disabling driver signing

I tried to install my Arduino Uno under Windows 8 today.  The included drivers do not work because they are not signed.  One way people get them to work is to temporarily disable the check on driver signing as seen here.  I was able to do it without rebooting or using unsigned drivers.   Here is how:

  1. First plug in your Uno and let the driver installation fail.  
  2. Open the device manager, click start and then type device manager. 
  3. Right click on the yellow Arduino Uno and choose update driver software. 
  4. Click "Browse my computer for driver software"
  5. Then click "Let me pick from a list of device drivers on my computer"
  6. Click modem and then next.
  7. In the list, under manufactuer, choose Compaq.  Then for model choose "Ricochet Wireless USB Modem"
  8. When Windows complains, it is OK, choose to continue and the close the installer after it completes.
  9. Now under modems, you will see "Ricochet Wireless USB Modem", right click on it and choose properties.
  10. Under modem, set the maximum speed to 9600.
  11. On the advanced tab, click "Advanced Port Settings"
  12. Uncheck use FIFO buffers
  13. Note the COM Port Number, you will need this in the Arduino IDE
  14. Click OK, and click OK.
  15. Done

I was able to figure this out by looking at the existing Arduino Uno drivers and noted that they do not install a driver but provide device id's that use the usbser.sys.  I looked through c:\windows\inf and found this device uses the same driver.  Because it is a modem driver, Windows will treat it exactly like a COM port unless you try to use dialup software.  You most likely will not be dialing up with an Arduino.


2012/01/24

What am I reading about

Currently I am looking into image classification and how it relates to plants.  Whether it be a neural network approach with a human feedback or using a database of known's for training.  Probably a hybrid of the two.  This should allow autonomous devices to classify plants and insects that belong or do not belong or are unknown.

2009/11/03

Quicky: Multiple compilers means less debugging

I've been at the C++ game the past view days and we all have seen those nasty STL errors that don't give you a clue as to what the problem is. Such as

Error 1 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

I have found that compiling under multiple compilers will give you just enough info to actually find the error. In my case I was trying to add a std::fstream to a std::vector. So the error was technically correct, but didn't indicate that you cannot do that.

2009/11/01

Trying to build cross platform software isn't always easy

Trying to build cross platform software isn't always easy. For instance, the truncate function that exists on Linux and part of the unistd.h header does not exist under Windows unless you use cygwin. Windows does have the SetFilePointer to set the position and SetEndOfFile functions. You can now build a truncate function and wrap it in a #ifdef WIN32 ... #endif and it will only be used under windows.

Here is currently what I am using. Needs a bit more error checking but you can get the gist of it:


#ifdef WIN32 // Not defined in windows, translated to use SetEndOfFile function
int truncate( const char *path, const long long &length ) {
HANDLE hFile = CreateFileA( path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
LARGE_INTEGER li;
li.QuadPart = length;
int ret = -1;
if( SetFilePointer( hFile, li.LowPart, &li.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER ) {
SetEndOfFile( hFile );
ret = 0;
}
CloseHandle( hFile );
return ret;
}
#endif