|
Good answer!
I would change 1 thing - use those unused upper 4 bits instead of reusing the lower 4
int8 n4bit = ((num >> 12) & 7) * ((num & 8) ? -1 : 1);
(per the OPs spec )
Cheers!
Mark
|
|
|
|
|
int8 n4bit = ((num >> 12) & 7) * (((num >> 12) & 8) ? -1 : 1); Good catch! I also fixed your code a little (you forgot to shift for getting the sign bit)
|
|
|
|
|
Thanks!
|
|
|
|
|
|
You can also use a union to extract the components
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: You can also use a union to extract the components
Going for extra credit - Yeah!
|
|
|
|
|
thanks
|
|
|
|
|
One thing that hasn't been suggested yet is to use bitfields:
USHORT twelvebitnum :12;
USHORT fourbitnum :4;
Now you can generate your 12-bit number and your 4-bit number and simply
twelvebitnum = 3500;
fourbitnum = 5;
These two values are actually stored in a single 16-bit USHORT. The location of these within the USHORT are insignificant since you access them by the variable name, but the first one defined starts with the lowest x-number of bits, then the next one takes the next y-number of bits, and so on.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi,
I've written a small command line program to send AT modem commands to a USB-connected GSM modem (in fact it's an old Nokia telephone). We use at work it to send SMS reports. Currently the program is still very much experimental, but has been working well. I followed Allen Denver's MSDN article "Serial Communications in Win32"
So, in my program I would open a handle to the com port to which the modem is connected. Then, I would write each of the following strings in turn, separated by a 2.5 second pause.
1) "AT+CMGF=1\x0D" to indicate SMS mode.
2) "AT+CMGS=\"+44NNNNNNNNNN\"\x0D" to indicated the destination phone number.
3) "SMS Text\x1A\x0D" to indicate the text to send in the message and terminate the message.
Each of these strings is written to the previous file handle within a function I wrote and the return value from this function indicates the success or not of writing the string.
I'm not very experienced in serial comms programming. My question is, how do you tell in code that the modem is ready for input? For example, in HyperTerminal you get the "OK" prompt back. Is this just a feature of HyperTerminal? Am I already doing enough by checking that the string was written successfully? What is the "proper" thing to do after writing the string to the com port to check that the modem is ready for more input?
I am using C++ to write the program under Windows 2000 and XP.
Originally, I posted this in the Hardware forum, but I've not have many responses.
Thanks in advance.
|
|
|
|
|
|
The "OK" response is being sent by the phone. It is not part of HyperTerminal's behavior.
The way to handle this is:
1. Send command.
2. Read command echo, if the phone 'echo's what you sent it. If, when you are using HyperTerminal, you see the characters you send, then the phone is echoing.
3. Read response to command.
Software Zen: delete this;
|
|
|
|
|
I need help in grabbing frames form a webcam stream.
I have used the ISampleGrabber filter and added it in but i cant work out how to grab the frames. I have managed to grab them via setting the filter to buffer the samples but i dont need this i just need to grab a single frame on request. Im using C++ in VS2005.
Any help would be great.
|
|
|
|
|
On the ISampleGrabber interface you can use GetCurrentBuffer() or SetCallback().
Which method are you trying to use?
Mark
|
|
|
|
|
I have used the GetCurentBuffer() but i think i need to use the SetCallBack() method because setting the filter to buffer the frames and using GetCurentBuffer just keeps increasing the buffer size with every frame. I need to grab around 10 frames a second.
|
|
|
|
|
What other filters are in the graph? And in what order?
Mark
|
|
|
|
|
Capture, Garbber ,Renderer.
|
|
|
|
|
hmmm I wouldn't expect the buffer size to keep increasing.
Anyway, I dug up an article in my bookmarks that may help:
How To Get Data from a Microsoft DirectShow Filter Graph[^]
The docs for the samplegrabber filter don't really explain the buffered mode in any detail and
I've never used it (I have used the callback however). At the bottom of the article is this:
Buffered mode
The buffered mode of the Sample Grabber is not particularly useful. If the application needs to
copy samples to a buffer, it can do so in the callback.
I chose to write a simple renderer filter for grabbing frames instead of an in-place filter and
it works well.
Mark
|
|
|
|
|
How do you use the callback method? What is the process?
|
|
|
|
|
1) Create an instance of the sample grabber filter
2) Obtain a pointer to its ISampleGrabber interface
3) Implement ISampleGrabberCB interface (see below)
4) Create an instance of your ISampleGrabberCB interface
5) Use ISampleGrabber::SetCallback() to set the filter to use your callback
I was going to post code but to save typing I'll post a link (yeah, I'm lazy )
In this link is one way of implementing the ISampleGrabberCB interface. You don't really need
to do anything COM related with it so it's pretty simple. The point is to expose the two callback
methods to the ISampleGrabber interface, which expects a ISampleGrabberCB interface.
Capturing an Image From a Still Image Pin[^]
This code demonstrates using the BufferCB callback but you may find the SampleCB callback is
more appropriate for what you are doing.
Since you want 10 frames a second the easiest way to implement the callback is to run the
stream at 10fps. Then you just grab every frame. For smoother rendering (if you are rendering
while capturing) then maybe set up the video for 20fps and grab every other frame.
Hopefully this will help get you started
Mark
|
|
|
|
|
Thanks Mark i have now managed to get the frames i need via CallBack. Do you know any method of resizing these frames at the moment they are just being displayed at the size they are captured. No worrys if your dont know how to im sure ill be able to figure it out, you've already help me out loads.
|
|
|
|
|
ceejeeb wrote: Do you know any method of resizing these frames at the moment they are just being displayed at the size they are captured.
I'm not sure I understand the question. You want to resize the displayed (preview) frames
a different size than the capture size? If so, which renderer filter are you using?
Mark
|
|
|
|
|
I want to work directly with modem(no with COM port). I want to send AT command and get replay from modem directly in mfc
|
|
|
|
|
not sure, but check TAPI.. maybe there's a way to send at commands.
Don't try it, just do it!
|
|
|
|
|
I am a beginner in MFC. I wanna know if we can know if a remote system has logged in.Could we get the time of login.
I humbly request the one who has some idea about it to kindly respond me!
Thanks in advance!
|
|
|
|
|
see if this[^] helps
If you think you can than you can, if you think you can't you are right.
|
|
|
|