Bluetooth "extras"
Re: Bluetooth "extras"
hi,
thank you, I'll try it out asap, maybe already this weekend.
how would you propose to write the slave's routines?
In the moment there are endless loops in the send-string sub for the sensor+variable values.
Should it stay as it is or would you install a hand-shake like
master sends 0xff to the slaves as a request (one after the other)
slaves: wait until 0xff is in their specified INBOX - if 0xff found then put string with the sensor+variable values into OUTBOX
master receives remote string from all slaves (one after the other)
how would you write the slave routine "if 0xff found in INBOX"
how could one be sure that the INBOX would be cleared after that and all pending messages in the queue as well so that there won't be any redundand reading/sending?
thank you, I'll try it out asap, maybe already this weekend.
how would you propose to write the slave's routines?
In the moment there are endless loops in the send-string sub for the sensor+variable values.
Should it stay as it is or would you install a hand-shake like
master sends 0xff to the slaves as a request (one after the other)
slaves: wait until 0xff is in their specified INBOX - if 0xff found then put string with the sensor+variable values into OUTBOX
master receives remote string from all slaves (one after the other)
how would you write the slave routine "if 0xff found in INBOX"
how could one be sure that the INBOX would be cleared after that and all pending messages in the queue as well so that there won't be any redundand reading/sending?
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth "extras"
What I have running in the slave of my remote control car is:
- Master does a JHSSendRemoteNumber to MailBox10 and the specific connection for that slave with a specified value (to indicate "send values").
- Master then starts looking for a response in MailBox10 by using "JHSReceiveRemoteStruct, no wait".
- Slave has one thread hanging on a JHSReceiveRemoteNumber on MailBox10.
- Slave looks at value received and, based on the value, puts the requested information into a struct.
- Slave then does a JHSSendResponseStruct on MailBox10.
- Master gets the response in MailBox10, in the struct expected.
If you have your data in a string, you could use the ...String calls instead of the ...Struct calls.
This brings all the data from the slave back to the master in one set of messages.
- Master does a JHSSendRemoteNumber to MailBox10 and the specific connection for that slave with a specified value (to indicate "send values").
- Master then starts looking for a response in MailBox10 by using "JHSReceiveRemoteStruct, no wait".
- Slave has one thread hanging on a JHSReceiveRemoteNumber on MailBox10.
- Slave looks at value received and, based on the value, puts the requested information into a struct.
- Slave then does a JHSSendResponseStruct on MailBox10.
- Master gets the response in MailBox10, in the struct expected.
If you have your data in a string, you could use the ...String calls instead of the ...Struct calls.
This brings all the data from the slave back to the master in one set of messages.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth "extras"
yes that is just like I thought a "handshake" would work...
how exactly does your slave check if there is a request currently pending?
how exactly does your slave check if there is a request currently pending?
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth "extras"
Here is the master code:
Here is the slave code:
In this case, I only have one type of data to send back, so I am using a Boolean to signal the slave that data is needed.
Code: Select all
task tGetData()
{
struct Car {
long lSteer;
long lPower;
long lBattery;
};
Car CarData;
until (bBT_Stop)
{
JHSSendRemoteBool( CONNECTION_NUMBER, MAILBOX9, true); // Poke the Car that I want data.
JHSReceiveRemoteStruct( CONNECTION_NUMBER, MAILBOX9, CarData);
lLeftRight = -CarData.lSteer;
lUpDown = CarData.lPower;
lBatteryStateNow = CarData.lBattery;
DashBoard(false);
Wait(200);
}
}
Code: Select all
task tSendData()
{
bool bResult;
struct Car {
long lSteer;
long lPower;
long lBattery;
};
Car CarData;
until (bBT_Stop)
{
JHSReceiveRemoteBool( CONNECTION_NUMBER, MAILBOX9, true, bResult);
// A Poll request came down.
CarData.lSteer = (MotorRotationCount(OUT_A) *100)/lSteeringNormalization;
CarData.lPower = MotorPower(OUT_B);
CarData.lBattery = BatteryLevel();
JHSSendResponseStruct( CONNECTION_NUMBER, MAILBOX9, CarData);
}
}
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth "extras"
thanks again,
so your
JHSReceiveRemoteBool( CONNECTION_NUMBER, MAILBOX9, true, bResult);
keeps this loop waiting (idle) until a msg will come in...
that looks pretty easy to copy for my purposes, I'll gladly try it, asap!
so your
JHSReceiveRemoteBool( CONNECTION_NUMBER, MAILBOX9, true, bResult);
keeps this loop waiting (idle) until a msg will come in...
that looks pretty easy to copy for my purposes, I'll gladly try it, asap!
Re: Bluetooth "extras"
hi JHS,
just another couple of questions:
1st, in your slave's code
what is CONNECTION_NUMBER for the slave ?
AFAIK any slave always uses "0" as his CONNECTION_NUMBER - is this true also for you code or is this the corresponding CONNECTION_NUMBER of the master to this slave (1, 2, or 3 )?
2nd,
what is
bResult
for and where has it been declared?
3rd,
while the master is running the BT-setup procedure
what is the slave's routine for BT-Setup to wait until the connection has been established?
I currently use
just another couple of questions:
1st, in your slave's code
Code: Select all
until (bBT_Stop)
{
JHSReceiveRemoteBool( CONNECTION_NUMBER, MAILBOX9, true, bResult);
// A Poll request came down.
CarData.lSteer = (MotorRotationCount(OUT_A) *100)/lSteeringNormalization;
CarData.lPower = MotorPower(OUT_B);
CarData.lBattery = BatteryLevel();
JHSSendResponseStruct( CONNECTION_NUMBER, MAILBOX9, CarData);
}
AFAIK any slave always uses "0" as his CONNECTION_NUMBER - is this true also for you code or is this the corresponding CONNECTION_NUMBER of the master to this slave (1, 2, or 3 )?
2nd,
what is
bResult
for and where has it been declared?
3rd,
while the master is running the BT-setup procedure
Code: Select all
bool Init_BT(char max_conn)
{
int iResult;
bool bSlave1Ready;
char conn;
_NOS_ = max_conn;
// In case it is already connected to something.
for ( conn=1; conn<=_NOS_; ++conn) {
DisconnectBT(conn);
}
PlayTone(TONE_C4, 200); Wait(1000);
for ( conn=1; conn<=_NOS_; ++conn) {
until (ConnectBT(conn, SLAVE[conn])) ;
PlayTone(TONE[conn], 200); Wait(200);
}
}
what is the slave's routine for BT-Setup to wait until the connection has been established?
I currently use
Code: Select all
void BT_SlaveCheck()
{
do {
printf("%s", "search: BTmaster");
Wait(50);
} while (BluetoothStatus(0)!=NO_ERR)
printf("%s", "BTmaster connected");
}
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth "extras"
1) I put "connection number" in the slave routines to be consistent. In the slave, it is "0".
2) bResult was declared earlier in that task.
3) When my slave has completed whatever setup/initialization it needs, it sends a "true" back to the master in MailBox10 to indicate it is ready for commands from the master.
2) bResult was declared earlier in that task.
3) When my slave has completed whatever setup/initialization it needs, it sends a "true" back to the master in MailBox10 to indicate it is ready for commands from the master.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth "extras"
2) what is bResult as default? 1 or 0? And what is it for? I don't see any variable assignment...?
3) but how does your slave know if BT has been established correctly? How does slave's BT-setup actually look like?
3) but how does your slave know if BT has been established correctly? How does slave's BT-setup actually look like?
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth "extras"
2) bResult is the output from the JHSReceiveRemoteBool( CONNECTION_NUMBER, MAILBOX9, true, bResult); statement.
3) Because the slave is started from the master, the BT connection must have been established properly; therefore, it doesn't need to do anything to verify it. Remember, the master does all the work. The fact the slave code is running indicates the BT connection is alive and working.
3) Because the slave is started from the master, the BT connection must have been established properly; therefore, it doesn't need to do anything to verify it. Remember, the master does all the work. The fact the slave code is running indicates the BT connection is alive and working.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth "extras"
i have to start the master manually and all slaves manually, too.
it is not intended and not possible to start a slave by the master:
one or more of the 3 slave's program names change from time to time, depending on updated versions,
so the master is not able to know all current slaves' program names.
it is not intended and not possible to start a slave by the master:
one or more of the 3 slave's program names change from time to time, depending on updated versions,
so the master is not able to know all current slaves' program names.
Who is online
Users browsing this forum: No registered users and 0 guests