This question is about zigbee & cc2530 .
I bought 2 CC2530 modules . I connected every module to a micro controller ( uC acronym for micro controller ) .
One of them , is coordinator ( C acronym for coordinator ) & one else is end device ( E acronym for end device ). C initializes the network & E joins to C's network . every things is OK .
First critical issue : POWER SAVING mode . I was able to solve it . POWER SAVING mode is only for E .
Second critical issue : Transmit & receive data in POWER SAVING mode . Receive was solved . ( Receive means : Data stream from C to E ) . BUT TRANSMIT !!! This is the question . ( Transmit means : Data stream from E to C ) . In POWER SAVING mode , E is sleep most of the time . uC intends to send data via E , but E is sleep & does not answer to uC .
uC have to wake E up first & then send it the data , so E can transmit the data .
How to wake E up ?????
In the documents : HAL_SLEEP_TIMER can be woken up by sleep timer interrupt, I/O interrupt and reset.
So I can wake E up by I/O interrupt . How can I do it ??
Nobody answered me !!!!
I found the answer . But I have not tried it yet .
in file ::: hal_board_cfg.h --> set HAL_KEY to TRUE
in file ::: hal_key.c --------> set HAL_KeyIntEnable to TRUE
in file ::: OnBoard.c --------> inside InitBoard() -------> use HalKeyConfig(HAL_KEY_INTERRUPT_ENABLE, OnBoard_KeyCallback);
////\\////\\////\\////\\////\\\//////\\\///////\\\\///////
By making these changes :
P0.1 is external interrupt . falling edge .
SO
Connect CC2530.P0.1 to One of the uC pins . This pin of uC must be high . Before sending data , uC toggles this pin , then uC waits about 1.6 ms , then uC sends uart packet to E , then uC toggles interrupt pin .
Related
I have written a piece of code to parse the action items from a troubleshooting doc.
I want to extract phrases that start with a verb and end with a noun.
It was working as expected earlier (a month ago). But on running against the same input as earlier, its missing some action items that it was catching previously.
I haven't changed the code. Has something changed from nltk or punkt side that may be affecting my results?
Please help me figure what needs to be changed to make it run as earlier.
import re
import nltk
from nltk.tokenize import PunktSentenceTokenizer
from nltk.tokenize import word_tokenize
#One time downloads
#nltk.download('punkt')
#nltk.download('averaged_perceptron_tagger')
#nltk.download('wordnet')
custom_sent_tokenizer = PunktSentenceTokenizer()
def process_content(x):
try:
#sent_tag = []
act_item = []
for i in x:
print('tokenized = ',i)
words = nltk.word_tokenize(i)
print(words)
tagged = nltk.pos_tag(words)
print('tagged = ',tagged)
#sent_tag.append(tagged)
#print('sent= ',sent_tag)
#chunking
chunkGram = r"""ActionItems: {<VB.>+<JJ.|CD|VB.|,|CC|NN.|IN|DT>*<NN|NN.>+}"""
chunkParser = nltk.RegexpParser(chunkGram)
chunked = chunkParser.parse(tagged)
print(chunked)
for subtree in chunked.subtrees(filter=lambda t: t.label() == 'ActionItems'):
print('Filtered chunks= ',subtree)
ActionItems = ' '.join([w for w, t in subtree.leaves()])
act_item.append(ActionItems)
chunked.draw()
return act_item
except Exception as e:
#print(str(e))
return str(e)
res = 'replaced rev 6 aeb with a rev 7 aeb. configured new board and regained activity. tuned, flooded and calibrated camera. scanned fi rst patient with no issues. made new backups. replaced aeb board and completed setup. however, det 2 st ill not showing any counts. performed all necessary tests and the y passed . worked with tech support to try and resolve the issue. we decided to order another board due to lower rev received. camera is st ill down.'
tokenized = custom_sent_tokenizer.tokenize(res)
tag = process_content(tokenized)
With the input as shared in the code, earlier, the following action items were being parsed:
['replaced rev 6 aeb', 'configured new board', 'regained activity', 'tuned , flooded and calibrated camera', 'scanned fi rst patient', 'made new backups', 'replaced aeb board', 'completed setup', 'det 2 st ill', 'showing any counts', 'performed all necessary tests and the y', 'worked with tech support']
But now, only these are coming up:
['regained activity', 'tuned , flooded and calibrated camera', 'completed setup', 'det 2 st ill', 'showing any counts']
I finally resolved this by replacing JJ. with JJ|JJR|JJS
So my chunk is defined as :
chunkGram = r"""ActionItems: {<VB.>+<JJ|JJR|JJS|CD|NN.|CC|IN|VB.|,|DT>*<NN|NN.>+}"""
I dont understand this change in behavior.
Dot (.) was a really good way of using all modifiers on a POS
My program sends almost 50 messages, all with different ID's, on a pcan can-bus. And then loops again continuously, starting with a new data for 1st ID.
I have been able to initialize and send the single ID message, but I'm not able to send any other ID on the bus. I am analyzing the bus signal using an oscilloscope, and therefore I can see what messages are on the bus.
This is a part of code, showing how I'm trying to send 2 consecutive messages on the bus, but it only sends the id=100 message and not the next ones. I'm only importing the python-can library, for this.
for i in range(self.n_param):
if self.headers[i] == 'StoreNo': # ID 100 byte size = 3
to_can_msg = []
byte_size = 3
hex_data = '0x{0:0{1}X}'.format(int(self.row_data[i], 10), byte_size * 2)
to_can_msg = [int(hex_data[2:4], 16), int(hex_data[5:6], 16), int(hex_data[7:8], 16)]
bus_send.send(Message(arbitration_id=100, data=to_can_msg))
elif self.headers[i] == 'Date': # ID 101 byte size = 4
to_can_msg = []
byte_size = 4
date_play = int(self.row_data[i].replace("/", ""), 10)
hex_data = '0x{0:0{1}X}'.format(date_play, byte_size * 2)
to_can_msg = message_array(hex_data)
bus_send.send(Message(arbitration_id=101, data=to_can_msg))
And I'm closing each loop with bus_send.reset() to clear any outstanding message in the queue and begin afresh in the next loop.
Much thanks!
Turns out I missed an important detail in CAN communication,the ACK bit, which needs to be set to recessive by the receiver node. And since I'm only trying to read the CAN bus using one node,that node keeps on transmitting the first message forever in hope to receive the ACK bit.
Loopback could've worked but appears like pcan doesn't support loopback functionality for linux. So would have to use a second CAN node to receive messages.
import sys
import serial
import numpy as np
import matplotlib.pyplot as plt
from collections import deque
port = "COM11"
baud = 9600
timeout=1
ser = serial.Serial()
ser.port = port
ser.baudrate = baud
ser.timeout = timeout
a1 = deque([0.0]*100)
#ax = plt.axes(xlim=(0, 100), ylim=(0, 1000))
line, = plt.plot(a1)
plt.ion()
plt.ylim([0,1000])
try:
ser.open()
except:
sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) )
sys.exit(1)
#ser.setRtsCts(0)
while 1:
# Read from serial port, blocking
data = ser.read(1)
# If there is more than 1 byte, read the rest
n = ser.inWaiting()
data = data + ser.read(n)
#sys.stdout.write(data)
print(a1)
a1.appendleft((data))
datatoplot = a1.pop()
line.set_ydata(a1)
plt.draw()
I am using msp430f5438a board.If I send the data with a new line between each data then I am not able to plot the data because in python the sometimes data gets printed as 78_9, 7_89,_789 where _ means space so python gives me a error cannot convert string to float. But If I say send the data from uart without any new line between them then I get a nice plot but in the plot after some irregular short intervals the plot goes to zero and then becomes fine again although I checked in hyperterminal I am not receiving any zero values
My question is:
Are the two cases I described are related to each other?What can be done to rectify this problem of plot going to zero in between?Because of this I am not getting a smooth wave.
Thanks
The problem might be in the way you handle the serial interface. As you are not parsing the serial input when it comes, it is possible that you receive two messages as follows:
1.23
4.56
7.
and
89
10.11
etc. This is because your code may split the input at any point. It may be so fast that you get one digit at a time, which is probably not what you wanted.
I suggest that if you pad your data with newlines and if the data is good in a terminal program, you use the readline method.
while 1:
# read a line from the input
line = ser.readline()
# try to make a float out of it
try:
a1.appendleft(float(line))
except ValueError:
# in case we got bad input, print it and go to the next line
print "Received an invalid line '{0}'".format(line)
continue
# do the plotting
This most probably fixes your problem.
Reading asynchronous serial line is surprisingly complicated, you usually need to parse the input in-the-fly with timeouts. Fortunately, this is done by pyserial when using readline.
im' having lately a little problem with websockets fin bit and my c++ server. Whenever i try to use FIN = 0, host drops connection with no reason. Here is part of my code to calculate FIN:
string ret
ret += (unsigned char)((fin & 1) << 7) | (opcode & 63);
When i use FIN = 1, my first byte in frame is 129, which is correct and user gets correct answear. With FIN =0 first byte is 1 which also seems to be good and then after sending connection drops. Tried to send the same packets of data with both flags and only FIN =0 fails;
Why i try to use FIN = 0? well i'm trying to make a little three.js + websocket game, i'd like a server to send all the models through the websocket for every player, so i expect a heavy load which i'd like to control.
I'd be happy to provide any additional informations.
Thanks in advance.
I have no idea about C++, but I know a bit about WebSockets.
Which value do you have in the other byte? When you send a FIN=0 frame, you still need to send the frame options in it. Subsequent frames must be of the option "Continuation", and nothing else. As far as I remember, continuation frames cannot even have the RSV bits different than 0.
If you send a frame with FIN=0 without type (text or binary), it will probably fail. If you send a FIN=1 with a type different that "Continuation" after a FIN=0 will fail.
So the key is, what are you sending in the second byte? Also, it would be great if you try with Google Chrome and check in the console why is the connection being shut down.
OPCODE:
|Opcode | Meaning | |
-+--------+-------------------------------------+-----------|
| 0 | Continuation Frame | |
-+--------+-------------------------------------+-----------|
| 1 | Text Frame | |
-+--------+-------------------------------------+-----------|
| 2 | Binary Frame | |
-+--------+-------------------------------------+-----------|
| 8 | Connection Close Frame | |
-+--------+-------------------------------------+-----------|
| 9 | Ping Frame | |
-+--------+-------------------------------------+-----------|
| 10 | Pong Frame | |
-+--------+-------------------------------------+-----------|
Is there any way of matching a regex from right to left? What Im looking for is a regex that gets
MODULE WAS INSERTED EVENT
LOST SIGNAL ON E1/T1 LINK OFF
CRC ERROR EVENT
CLK IS DIFF FROM MASTER CLK SRC OF
from this input
CLI MUX trap received: (022) CL-B MCL-2ETH MODULE WAS INSERTED EVENT 07-05-2010 12:08:40
CLI MUX trap received: (090) IO-2 ML-1E1 EX1 LOST SIGNAL ON E1/T1 LINK OFF 04-06-2010 09:58:58
CLI MUX trap received: (094) IO-2 ML-1E1 EX1 CRC ERROR EVENT 04-06-2010 09:58:59
CLI MUX trap received: (009) CLK IS DIFF FROM MASTER CLK SRC OFF 07-05-2010 12:07:32
If i could have done the matching from right to left I could have written something like everything to right of (EVENT|OFF) until the second appearance of more than one space [ ]+
The best I managed today is to get everything from (022) to EVENT with the regex
CLI MUX trap received: \([0-9]+\)[ ]+(.*[ ]+(EVENT|OFF))
But that is not really what I wanted :)
edit: What language its for? Its actually a config string for a filter we have but my guess it is using standard GNU C Regex library.
edit2: I like the answers about cutting by length but Amarghosh was probably more what I was looking for. Do not really know why I did not think about just cutting on length like:
^.{56}(.{39}).*$
Super thanks for the quick answers...
In .NET you could use the RightToLeft option :
Regex RE = new Regex(Pattern, RegexOptions.RightToLeft);
Match theMatch = RE.Match(Source);
With regex, you could simply replace this:
^.{56}|.{19}$
with the empty string.
But really, you only need to cut out the string from "position 56" to "string-length - 19" with a substring function. That's easier and much faster than regex.
Here's an example in JavaScript, other languages work more or less the same:
var lines = [
'CLI MUX trap received: (022) CL-B MCL-2ETH MODULE WAS INSERTED EVENT 07-05-2010 12:08:40',
'CLI MUX trap received: (090) IO-2 ML-1E1 EX1 LOST SIGNAL ON E1/T1 LINK OFF 04-06-2010 09:58:58',
'CLI MUX trap received: (094) IO-2 ML-1E1 EX1 CRC ERROR EVENT 04-06-2010 09:58:59',
'CLI MUX trap received: (009) CLK IS DIFF FROM MASTER CLK SRC OFF 07-05-2010 12:07:32'
];
for (var i=0; i<lines.length; i++) {
alert( lines[i].substring(56, lines[i].length-19) );
}
If tokens are guaranteed to be separated by more than one space and words within the string before EVENT|OFF are guaranteed to be separated by just one space - only then you can look for single-space-separated words followed by spaces followed by EVENT or OFF
var s = "CLI MUX trap received: (022) CL-B MCL-2ETH MODULE WAS INSERTED EVENT 07-05-2010 12:08:40"
+ "\nCLI MUX trap received: (090) IO-2 ML-1E1 EX1 LOST SIGNAL ON E1/T1 LINK OFF 04-06-2010 09:58:58"
+ "\nCLI MUX trap received: (094) IO-2 ML-1E1 EX1 CRC ERROR EVENT 04-06-2010 09:58:59"
+ "\nCLI MUX trap received: (009) CLK IS DIFF FROM MASTER CLK SRC OFF 07-05-2010 12:07:32"
var r = /\([0-9]+\).+?((?:[^ ]+ )* +(?:EVENT|OFF))/g;
var m;
while((m = r.exec(s)) != null)
console.log(m[1]);
Output:
MODULE WAS INSERTED EVENT
LOST SIGNAL ON E1/T1 LINK OFF
CRC ERROR EVENT
CLK IS DIFF FROM MASTER CLK SRC OFF
Regex: /\([0-9]+\).+?((?:[^ ]+ )* +(?:EVENT|OFF))/g
\([0-9]+\) #digits in parentheses followed by
.+? #some characters - minimum required (non-greedy)
( #start capturing
(?:[^ ]+ )* #non-space characters separated by a space
` +` #more spaces (separating string and event/off -
#backticks added for emphasis), followed by
(?:EVENT|OFF) #EVENT or OFF
) #stop capturing
Does the input file fit nicely into fixed width tabular text like this? Because if it does, then the simplest solution is to just take the right substring of each line, from column 56 to column 94.
In Unix, you can use the cut command:
cut -c56-94 yourfile
See also
Wikipedia/Cut (Unix)
In Java, you can write something like this:
String[] lines = {
"CLI MUX trap received: (022) CL-B MCL-2ETH MODULE WAS INSERTED EVENT 07-05-2010 12:08:40",
"CLI MUX trap received: (090) IO-2 ML-1E1 EX1 LOST SIGNAL ON E1/T1 LINK OFF 04-06-2010 09:58:58",
"CLI MUX trap received: (094) IO-2 ML-1E1 EX1 CRC ERROR EVENT 04-06-2010 09:58:59",
"CLI MUX trap received: (009) CLK IS DIFF FROM MASTER CLK SRC OFF 07-05-2010 12:07:32",
};
for (String line : lines) {
System.out.println(line.substring(56, 94));
}
This prints:
MODULE WAS INSERTED EVENT
LOST SIGNAL ON E1/T1 LINK OFF
CRC ERROR EVENT
CLK IS DIFF FROM MASTER CLK SRC OFF
A regex solution
This is most likely not necessary, but something like this works (as seen on ideone.com):
line.replaceAll(".* \\b(.+ .+) \\S+ \\S+", "$1")
As you can see, it's not very readable, and you have to know your regex to really understand what's going on.
Essentially you match this to each line:
.* \b(.+ .+) \S+ \S+
And you replace it with whatever group 1 matched. This relies on the usage of two consecutive spaces exclusively for separating the columns in this table.
How about
.{56}(.*(EVENT|OFF))
Can you do field-oriented processing, rather than a regex? In awk/sh, this would look like:
< $datafile awk '{ print $(NF-3), $(NF-2) }' | column
which seems rather cleaner than specifying a regex.